From 1d6c960f05029c3820179fed415bc8c812ca21ae Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 7 Jan 2016 17:30:49 +0100 Subject: [PATCH] CMake: Avoid passing CMakeManager around Change-Id: I96d7f3785767d1d56ca27a2d0af778edf98d63e1 Reviewed-by: Tim Jenssen --- .../cmakebuildsettingswidget.cpp | 16 ++++++------ .../cmakeopenprojectwizard.cpp | 25 +++++++------------ .../cmakeopenprojectwizard.h | 5 +--- .../cmakeprojectmanager/cmakeproject.cpp | 4 +-- .../cmakeprojectmanager.cpp | 12 ++++----- .../cmakeprojectmanager/cmakeprojectmanager.h | 14 ++++------- 6 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp index 5dc08ebe458..5f53ca9f1d5 100644 --- a/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp +++ b/src/plugins/cmakeprojectmanager/cmakebuildsettingswidget.cpp @@ -91,13 +91,11 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildConfiguration *bc) void CMakeBuildSettingsWidget::openChangeBuildDirectoryDialog() { - auto project = static_cast(m_buildConfiguration->target()->project()); - auto manager = static_cast(project->projectManager()); CMakeBuildInfo info(m_buildConfiguration); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), - manager, CMakeOpenProjectWizard::ChangeDirectory, + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), CMakeOpenProjectWizard::ChangeDirectory, &info); if (copw.exec() == QDialog::Accepted) { + auto project = static_cast(m_buildConfiguration->target()->project()); project->changeBuildDirectory(m_buildConfiguration, copw.buildDirectory()); m_pathLineEdit->setText(m_buildConfiguration->rawBuildDirectory().toString()); } @@ -107,13 +105,13 @@ void CMakeBuildSettingsWidget::runCMake() { if (!ProjectExplorer::ProjectExplorerPlugin::saveModifiedFiles()) return; - auto project = static_cast(m_buildConfiguration->target()->project()); - auto manager = static_cast(project->projectManager()); CMakeBuildInfo info(m_buildConfiguration); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), manager, - CMakeOpenProjectWizard::WantToUpdate, &info); - if (copw.exec() == QDialog::Accepted) + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), CMakeOpenProjectWizard::WantToUpdate, + &info); + if (copw.exec() == QDialog::Accepted) { + auto project = static_cast(m_buildConfiguration->target()->project()); project->parseCMakeLists(); + } } } // namespace Internal } // namespace CMakeProjectManager diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp index 8ac01e1941d..478503d2b0e 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.cpp @@ -82,14 +82,13 @@ using namespace ProjectExplorer; ////////////// /// CMakeOpenProjectWizard ////////////// -CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, +CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeOpenProjectWizard::Mode mode, - const CMakeBuildInfo *info) - : Utils::Wizard(parent), - m_cmakeManager(cmakeManager), - m_sourceDirectory(info->sourceDirectory), - m_environment(info->environment), - m_kit(KitManager::find(info->kitId)) + const CMakeBuildInfo *info) : + Utils::Wizard(parent), + m_sourceDirectory(info->sourceDirectory), + m_environment(info->environment), + m_kit(KitManager::find(info->kitId)) { CMakeRunPage::Mode rmode; if (mode == CMakeOpenProjectWizard::NeedToCreate) @@ -115,11 +114,6 @@ CMakeOpenProjectWizard::CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cm setWindowTitle(tr("CMake Wizard")); } -CMakeManager *CMakeOpenProjectWizard::cmakeManager() const -{ - return m_cmakeManager; -} - bool CMakeOpenProjectWizard::hasInSourceBuild() const { return QFileInfo::exists(m_sourceDirectory + QLatin1String("/CMakeCache.txt")); @@ -127,7 +121,7 @@ bool CMakeOpenProjectWizard::hasInSourceBuild() const bool CMakeOpenProjectWizard::compatibleKitExist() const { - bool preferNinja = m_cmakeManager->preferNinja(); + bool preferNinja = CMakeManager::preferNinja(); const QList kitList = KitManager::kits(); foreach (Kit *k, kitList) { @@ -493,7 +487,7 @@ void CMakeRunPage::initializePage() // Build the list of generators/toolchains we want to offer m_generatorComboBox->clear(); - bool preferNinja = m_cmakeWizard->cmakeManager()->preferNinja(); + bool preferNinja = CMakeManager::preferNinja(); QList infos; CMakeTool *cmake = CMakeKitInformation::cmakeTool(m_cmakeWizard->kit()); @@ -539,7 +533,6 @@ void CMakeRunPage::runCMake() m_output->clear(); CMakeTool *cmake = CMakeKitInformation::cmakeTool(generatorInfo.kit()); - CMakeManager *cmakeManager = m_cmakeWizard->cmakeManager(); if (cmake && cmake->isValid()) { m_cmakeProcess = new Utils::QtcProcess(); connect(m_cmakeProcess, &QProcess::readyReadStandardOutput, @@ -555,7 +548,7 @@ void CMakeRunPage::runCMake() .arg(cmake->cmakeExecutable().toUserOutput()) .arg(arguments) .arg(QDir::toNativeSeparators(m_buildDirectory))); - cmakeManager->createXmlFile(m_cmakeProcess, cmake->cmakeExecutable().toString(), + CMakeManager::createXmlFile(m_cmakeProcess, cmake->cmakeExecutable().toString(), arguments, m_cmakeWizard->sourceDirectory(), m_buildDirectory, env, QString::fromLatin1(generatorInfo.generatorArgument()), diff --git a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h index 631163ffea0..98ecea0a2ce 100644 --- a/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h +++ b/src/plugins/cmakeprojectmanager/cmakeopenprojectwizard.h @@ -77,13 +77,11 @@ public: /// used to update if we have already a .user file /// recreates or updates the cbp file /// Also used to change the build directory of one buildconfiguration or create a new buildconfiguration - CMakeOpenProjectWizard(QWidget *parent, CMakeManager *cmakeManager, Mode mode, - const CMakeBuildInfo *info); + CMakeOpenProjectWizard(QWidget *parent, Mode mode, const CMakeBuildInfo *info); QString buildDirectory() const; QString sourceDirectory() const; void setBuildDirectory(const QString &directory); - CMakeManager *cmakeManager() const; QString arguments() const; void setArguments(const QString &args); Utils::Environment environment() const; @@ -94,7 +92,6 @@ public: private: bool hasInSourceBuild() const; - CMakeManager *m_cmakeManager; QString m_buildDirectory; QString m_sourceDirectory; QString m_arguments; diff --git a/src/plugins/cmakeprojectmanager/cmakeproject.cpp b/src/plugins/cmakeprojectmanager/cmakeproject.cpp index 7fd9e27f69f..441427866a7 100644 --- a/src/plugins/cmakeprojectmanager/cmakeproject.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeproject.cpp @@ -145,7 +145,7 @@ void CMakeProject::changeActiveBuildConfiguration(ProjectExplorer::BuildConfigur if (mode != CMakeOpenProjectWizard::Nothing) { CMakeBuildInfo info(cmakebc); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info); + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), mode, &info); if (copw.exec() == QDialog::Accepted) cmakebc->setInitialArguments(QString()); } @@ -565,7 +565,7 @@ Project::RestoreResult CMakeProject::fromMap(const QVariantMap &map, QString *er if (mode != CMakeOpenProjectWizard::Nothing) { CMakeBuildInfo info(activeBC); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), m_manager, mode, &info); + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), mode, &info); if (copw.exec() != QDialog::Accepted) return RestoreResult::UserAbort; else diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp index f0bf3ba54af..3e7573c96c4 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.cpp @@ -112,8 +112,7 @@ void CMakeManager::runCMake(ProjectExplorer::Project *project) CMakeBuildInfo info(bc); - CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), this, CMakeOpenProjectWizard::WantToUpdate, - &info); + CMakeOpenProjectWizard copw(Core::ICore::mainWindow(), CMakeOpenProjectWizard::WantToUpdate, &info); if (copw.exec() == QDialog::Accepted) cmakeProject->parseCMakeLists(); } @@ -136,7 +135,7 @@ QString CMakeManager::mimeType() const return QLatin1String(Constants::CMAKEPROJECTMIMETYPE); } -bool CMakeManager::preferNinja() const +bool CMakeManager::preferNinja() { return CMakeToolManager::preferNinja(); } @@ -145,9 +144,10 @@ bool CMakeManager::preferNinja() const // we probably want the process instead of this function // cmakeproject then could even run the cmake process in the background, adding the files afterwards // sounds like a plan -void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &executable, const QString &arguments, - const QString &sourceDirectory, const QDir &buildDirectory, - const Utils::Environment &env, const QString &generator, const QString &preloadCache) +void CMakeManager::createXmlFile(Utils::QtcProcess *proc, const QString &executable, + const QString &arguments, const QString &sourceDirectory, + const QDir &buildDirectory, const Utils::Environment &env, + const QString &generator, const QString &preloadCache) { QString buildDirectoryPath = buildDirectory.absolutePath(); buildDirectory.mkpath(buildDirectoryPath); diff --git a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h index 817841bb992..5d3440858e4 100644 --- a/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h +++ b/src/plugins/cmakeprojectmanager/cmakeprojectmanager.h @@ -58,15 +58,11 @@ public: ProjectExplorer::Project *openProject(const QString &fileName, QString *errorString) override; QString mimeType() const override; - void createXmlFile(Utils::QtcProcess *process, - const QString &executable, - const QString &arguments, - const QString &sourceDirectory, - const QDir &buildDirectory, - const Utils::Environment &env, - const QString &generator, - const QString &preloadCache); - bool preferNinja() const; + static void createXmlFile(Utils::QtcProcess *process, const QString &executable, + const QString &arguments, const QString &sourceDirectory, + const QDir &buildDirectory, const Utils::Environment &env, + const QString &generator, const QString &preloadCache); + static bool preferNinja(); static QString findCbpFile(const QDir &); private: