From 49871ea23657e5bf45a550cd7e595ac7bb4d6f49 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Fri, 18 Oct 2013 17:46:40 +0200 Subject: [PATCH] Target: Avoid needless switching of active RunConfigurations. Together with the previous patch this avoids recreating RunConfiguration widgets for RCs which are about to be removed because they are no longer valid. Task-number: QTCREATORBUG-10248 Change-Id: Ia8e394175c1cdef469faa8d117a2736500d928e4 Reviewed-by: Daniel Teske --- src/plugins/projectexplorer/target.cpp | 40 +++++++++++++++++--------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/plugins/projectexplorer/target.cpp b/src/plugins/projectexplorer/target.cpp index e32c68b1692..d04a58b9938 100644 --- a/src/plugins/projectexplorer/target.cpp +++ b/src/plugins/projectexplorer/target.cpp @@ -656,24 +656,26 @@ void Target::updateDefaultRunConfigurations() } // Do actual changes: - foreach (RunConfiguration *rc, toRemove) { - removeRunConfiguration(rc); - existingConfigured.removeOne(rc); // make sure to also remove them from existingConfigured! - } - - if (removeExistingUnconfigured) { - foreach (RunConfiguration *rc, existingUnconfigured) - removeRunConfiguration(rc); - existingUnconfigured.clear(); - } - foreach (RunConfiguration *rc, newConfigured) addRunConfiguration(rc); foreach (RunConfiguration *rc, newUnconfigured) addRunConfiguration(rc); - // Make sure a configured RC is active: - if (activeRunConfiguration() && !activeRunConfiguration()->isConfigured()) { + // Generate complete list of RCs to remove later: + QList removalList; + foreach (RunConfiguration *rc, toRemove) { + removalList << rc; + existingConfigured.removeOne(rc); // make sure to also remove them from existingConfigured! + } + + if (removeExistingUnconfigured) { + removalList.append(existingUnconfigured); + existingUnconfigured.clear(); + } + + // Make sure a configured RC will be active after we delete the RCs: + RunConfiguration *active = activeRunConfiguration(); + if (removalList.contains(active)) { if (!existingConfigured.isEmpty()) { setActiveRunConfiguration(existingConfigured.at(0)); } else if (!newConfigured.isEmpty()) { @@ -687,8 +689,20 @@ void Target::updateDefaultRunConfigurations() } } setActiveRunConfiguration(selected); + } else if (!newUnconfigured.isEmpty()){ + setActiveRunConfiguration(newUnconfigured.at(0)); + } else { + if (!removalList.isEmpty()) + setActiveRunConfiguration(removalList.last()); + // Nothing will be left after removal: We set this to the last of in the removal list + // since that gives us the minimum number of signals (one signal for the change here and + // one more when the last RC is removed and the active RC becomes 0). } } + + // Remove the RCs that are no longer needed: + foreach (RunConfiguration *rc, removalList) + removeRunConfiguration(rc); } QVariant Target::namedSettings(const QString &name) const