diff options
author | Christian Kandeler <[email protected]> | 2025-01-21 13:50:38 +0100 |
---|---|---|
committer | Christian Kandeler <[email protected]> | 2025-01-23 08:31:29 +0000 |
commit | 2bac487904d030fee3cb6b9d053cef86ac320304 (patch) | |
tree | 01f7024d75effadb0b2239774858aa01168ae27c /src/plugins/debugger | |
parent | ca561567c4f13f30f8ee5add7dba84b9481a7ebe (diff) |
ProjectExplorer: Add convenience accessors to some classes
Namely, Kit, BuildConfiguration, BuildSystem and RunConfiguration get
functions to retrieve the active instance for a given project as well as
the one for the current and active projects, respectively.
This saves a ton of annoying null pointer checks.
Some of these functions replace existing ones with the same purpose that
were scattered around the code base.
Change-Id: I18247061229bbeb8b8ad1e15a2bd7a6626438bc0
Reviewed-by: hjk <[email protected]>
Diffstat (limited to 'src/plugins/debugger')
-rw-r--r-- | src/plugins/debugger/dap/cmakedapengine.cpp | 6 | ||||
-rw-r--r-- | src/plugins/debugger/debuggerplugin.cpp | 4 | ||||
-rw-r--r-- | src/plugins/debugger/debuggertest.cpp | 2 | ||||
-rw-r--r-- | src/plugins/debugger/unstartedappwatcherdialog.cpp | 20 |
4 files changed, 14 insertions, 18 deletions
diff --git a/src/plugins/debugger/dap/cmakedapengine.cpp b/src/plugins/debugger/dap/cmakedapengine.cpp index 8567c06e727..aef187eda14 100644 --- a/src/plugins/debugger/dap/cmakedapengine.cpp +++ b/src/plugins/debugger/dap/cmakedapengine.cpp @@ -114,7 +114,7 @@ void CMakeDapEngine::setupEngine() QTC_ASSERT(state() == EngineSetupRequested, qCDebug(logCategory()) << state()); qCDebug(logCategory()) << "build system name" - << ProjectExplorer::ProjectTree::currentBuildSystem()->name(); + << ProjectExplorer::activeBuildSystemForCurrentProject()->name(); IDataProvider *dataProvider; if (TemporaryDirectory::masterDirectoryFilePath().osType() == Utils::OsType::OsTypeWindows) { @@ -127,12 +127,12 @@ void CMakeDapEngine::setupEngine() m_dapClient = new CMakeDapClient(dataProvider, this); connectDataGeneratorSignals(); - connect(ProjectExplorer::ProjectTree::currentBuildSystem(), + connect(ProjectExplorer::activeBuildSystemForCurrentProject(), &ProjectExplorer::BuildSystem::debuggingStarted, this, [this] { m_dapClient->dataProvider()->start(); }); - ProjectExplorer::ProjectTree::currentBuildSystem()->requestDebugging(); + ProjectExplorer::activeBuildSystemForCurrentProject()->requestDebugging(); QTimer::singleShot(5000, this, [this] { if (!m_dapClient->dataProvider()->isRunning()) { diff --git a/src/plugins/debugger/debuggerplugin.cpp b/src/plugins/debugger/debuggerplugin.cpp index 0497655e46e..0697a603aab 100644 --- a/src/plugins/debugger/debuggerplugin.cpp +++ b/src/plugins/debugger/debuggerplugin.cpp @@ -1487,7 +1487,7 @@ void DebuggerPluginPrivate::updatePresetState() return; Project *startupProject = ProjectManager::startupProject(); - RunConfiguration *startupRunConfig = ProjectManager::startupRunConfiguration(); + RunConfiguration *startupRunConfig = activeRunConfigForActiveProject(); DebuggerEngine *currentEngine = EngineManager::currentEngine(); const auto canRun = ProjectExplorerPlugin::canRunStartupProject( @@ -2134,7 +2134,7 @@ static bool buildTypeAccepted(QFlags<ToolMode> toolMode, BuildConfiguration::Bui static BuildConfiguration::BuildType startupBuildType() { BuildConfiguration::BuildType buildType = BuildConfiguration::Unknown; - if (RunConfiguration *runConfig = ProjectManager::startupRunConfiguration()) { + if (RunConfiguration *runConfig = activeRunConfigForActiveProject()) { if (const BuildConfiguration *buildConfig = runConfig->target()->activeBuildConfiguration()) buildType = buildConfig->buildType(); } diff --git a/src/plugins/debugger/debuggertest.cpp b/src/plugins/debugger/debuggertest.cpp index c52cad86306..87b269d9142 100644 --- a/src/plugins/debugger/debuggertest.cpp +++ b/src/plugins/debugger/debuggertest.cpp @@ -101,7 +101,7 @@ void DebuggerUnitTests::testStateMachine() const QScopeGuard cleanup([] { EditorManager::closeAllEditors(false); }); - RunConfiguration *rc = ProjectManager::startupRunConfiguration(); + RunConfiguration *rc = activeRunConfigForActiveProject(); QVERIFY(rc); auto runControl = new RunControl(ProjectExplorer::Constants::DEBUG_RUN_MODE); diff --git a/src/plugins/debugger/unstartedappwatcherdialog.cpp b/src/plugins/debugger/unstartedappwatcherdialog.cpp index 3509ab2e02b..dd8e8e5bcb2 100644 --- a/src/plugins/debugger/unstartedappwatcherdialog.cpp +++ b/src/plugins/debugger/unstartedappwatcherdialog.cpp @@ -81,9 +81,7 @@ UnstartedAppWatcherDialog::UnstartedAppWatcherDialog(std::optional<QPoint> pos, m_kitChooser->populate(); m_kitChooser->setVisible(true); - Project *project = ProjectTree::currentProject(); - Kit *kit = project ? project->activeKit() : nullptr; - + Kit *kit = activeKitForCurrentProject(); if (kit) m_kitChooser->setCurrentKitId(kit->id()); else if (KitManager::waitForLoaded() && KitManager::defaultKit()) @@ -99,7 +97,7 @@ UnstartedAppWatcherDialog::UnstartedAppWatcherDialog(std::optional<QPoint> pos, resetExecutable->setEnabled(false); pathLayout->addWidget(m_pathChooser); pathLayout->addWidget(resetExecutable); - if (RunConfiguration *runConfig = project->activeRunConfiguration()) { + if (RunConfiguration *runConfig = activeRunConfigForCurrentProject()) { const ProcessRunData runnable = runConfig->runnable(); if (isLocal(runConfig)) { resetExecutable->setEnabled(true); @@ -176,17 +174,15 @@ void UnstartedAppWatcherDialog::selectExecutable() Utils::FilePath path; Project *project = ProjectTree::currentProject(); - if (project) { - if (RunConfiguration *runConfig = project->activeRunConfiguration()) { - const ProcessRunData runnable = runConfig->runnable(); - if (isLocal(runConfig)) - path = runnable.command.executable().parentDir(); - } + if (RunConfiguration *runConfig = activeRunConfig(project)) { + const ProcessRunData runnable = runConfig->runnable(); + if (isLocal(runConfig)) + path = runnable.command.executable().parentDir(); } if (path.isEmpty()) { - if (project && project->activeBuildConfiguration()) - path = project->activeBuildConfiguration()->buildDirectory(); + if (const BuildConfiguration * const bc = activeBuildConfig(project)) + path = bc->buildDirectory(); else if (project) path = project->projectDirectory(); } |