From f6d5ba9b1a66dda3b1e19a03d7e3b2da4f0642be Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Tue, 16 Oct 2012 17:19:59 +0200 Subject: [PATCH] CMake: Reparse .cbp files on swtiching targets Also fix the code to not reparse the wrong file if the bc for a non active target would be changed. Task-number: QTCREATORBUG-8063 Change-Id: I40be4bbb1a5ef6ccc78515f153534a7304cae0e1 Reviewed-by: Tobias Hunger --- .../cmakeprojectmanager/cmakeproject.cpp | 30 ++++++++++++++----- .../cmakeprojectmanager/cmakeproject.h | 5 +++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index e141fcbb224..386c27cd65e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -98,6 +98,7 @@ static inline QString formWindowEditorContents(const QObject *editor) */ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName) : m_manager(manager), + m_activeTarget(0), m_fileName(fileName), m_rootNode(new CMakeProjectNode(m_fileName)), m_lastEditor(0) @@ -107,8 +108,6 @@ CMakeProject::CMakeProject(CMakeManager *manager, const QString &fileName) m_file = new CMakeFile(this, fileName); - connect(this, SIGNAL(addedTarget(ProjectExplorer::Target*)), - SLOT(targetAdded(ProjectExplorer::Target*))); connect(this, SIGNAL(buildTargetsChanged()), this, SLOT(updateRunConfigurations())); } @@ -139,7 +138,7 @@ void CMakeProject::fileChanged(const QString &fileName) void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration *bc) { - if (!bc || bc->target() != activeTarget()) + if (!bc) return; CMakeBuildConfiguration *cmakebc = static_cast(bc); @@ -170,13 +169,22 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur parseCMakeLists(); } -void CMakeProject::targetAdded(ProjectExplorer::Target *t) +void CMakeProject::activeTargetWasChanged(Target *target) { - if (!t) + if (m_activeTarget) { + disconnect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), + this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*))); + } + + m_activeTarget = target; + + if (!m_activeTarget) return; - connect(t, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), - SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*))); + connect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), + this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*))); + + changeActiveBuildConfiguration(m_activeTarget->activeBuildConfiguration()); } void CMakeProject::changeBuildDirectory(CMakeBuildConfiguration *bc, const QString &newBuildDirectory) @@ -604,6 +612,14 @@ bool CMakeProject::fromMap(const QVariantMap &map) connect(ProjectExplorer::ProjectExplorerPlugin::instance()->buildManager(), SIGNAL(buildStateChanged(ProjectExplorer::Project*)), this, SLOT(buildStateChanged(ProjectExplorer::Project*))); + m_activeTarget = activeTarget(); + if (m_activeTarget) + connect(m_activeTarget, SIGNAL(activeBuildConfigurationChanged(ProjectExplorer::BuildConfiguration*)), + this, SLOT(changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*))); + + connect(this, SIGNAL(activeTargetChanged(ProjectExplorer::Target*)), + this, SLOT(activeTargetWasChanged(ProjectExplorer::Target*))); + return true; } diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.h b/src/plugins/cmakeprojectmanager/cmakeproject.h index 775b67ed8a6..a68596c170e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.h +++ b/src/plugins/cmakeprojectmanager/cmakeproject.h @@ -51,6 +51,8 @@ QT_BEGIN_NAMESPACE class QFileSystemWatcher; QT_END_NAMESPACE +namespace ProjectExplorer { class Target; } + namespace CMakeProjectManager { namespace Internal { @@ -116,8 +118,8 @@ protected: private slots: void fileChanged(const QString &fileName); + void activeTargetWasChanged(ProjectExplorer::Target *target); void changeActiveBuildConfiguration(ProjectExplorer::BuildConfiguration*); - void targetAdded(ProjectExplorer::Target *); void editorChanged(Core::IEditor *editor); void editorAboutToClose(Core::IEditor *editor); @@ -135,6 +137,7 @@ private: void updateRunConfigurations(ProjectExplorer::Target *t); CMakeManager *m_manager; + ProjectExplorer::Target *m_activeTarget; QString m_fileName; CMakeFile *m_file; QString m_projectName;