From 1a5eaecd97d573371079f326ed38547398ffeaa8 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Tue, 26 Sep 2017 18:34:38 +0200 Subject: [PATCH] Project: Avoid unnecessary activeTargetChanged signal Make sure to create the active target first when reading a project for the user data. This implicitly sets this target to the active one, avoiding one spurious activeTargetChanged signal. Change-Id: Iff9b19ed25bac9809ae75489ae159ffb66e71cb4 Reviewed-by: Tim Jenssen --- src/plugins/projectexplorer/project.cpp | 29 ++++++++++++++++--------- src/plugins/projectexplorer/project.h | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/plugins/projectexplorer/project.cpp b/src/plugins/projectexplorer/project.cpp index 7215b28eb8a..4c6efdae195 100644 --- a/src/plugins/projectexplorer/project.cpp +++ b/src/plugins/projectexplorer/project.cpp @@ -665,24 +665,33 @@ Project::RestoreResult Project::fromMap(const QVariantMap &map, QString *errorMe if (!ok || active < 0 || active >= maxI) active = 0; + if (active >= 0 && active < maxI) + createTargetFromMap(map, active); // sets activeTarget since it is the first target created! + for (int i = 0; i < maxI; ++i) { - const QString key(QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(i)); - if (!map.contains(key)) - continue; - QVariantMap targetMap = map.value(key).toMap(); - - Target *t = restoreTarget(targetMap); - if (!t) + if (i == active) // already covered! continue; - addTarget(t); - if (i == active) - setActiveTarget(t); + createTargetFromMap(map, i); } return RestoreResult::Ok; } +void Project::createTargetFromMap(const QVariantMap &map, int index) +{ + const QString key = QString::fromLatin1(TARGET_KEY_PREFIX) + QString::number(index); + if (!map.contains(key)) + return; + QVariantMap targetMap = map.value(key).toMap(); + + Target *t = restoreTarget(targetMap); + if (!t) + return; + + addTarget(t); +} + EditorConfiguration *Project::editorConfiguration() const { return &d->m_editorConfiguration; diff --git a/src/plugins/projectexplorer/project.h b/src/plugins/projectexplorer/project.h index 9329fc3c437..1c832578593 100644 --- a/src/plugins/projectexplorer/project.h +++ b/src/plugins/projectexplorer/project.h @@ -218,6 +218,7 @@ signals: protected: virtual RestoreResult fromMap(const QVariantMap &map, QString *errorMessage); + void createTargetFromMap(const QVariantMap &map, int index); virtual bool setupTarget(Target *t); // Helper methods to manage parsing state and signalling