CMake: Use current pattern to access main settings page

Change-Id: I95c556bebe1d583879b6702f727d9a859b9a4bcb
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-07-06 17:06:20 +02:00
parent 0822f28998
commit 3e155919eb
12 changed files with 43 additions and 48 deletions

View File

@@ -299,9 +299,7 @@ CMakeBuildSettingsWidget::CMakeBuildSettingsWidget(CMakeBuildSystem *bs) :
m_batchEditButton->setToolTip(Tr::tr("Set or reset multiple values in the CMake configuration.")); m_batchEditButton->setToolTip(Tr::tr("Set or reset multiple values in the CMake configuration."));
m_showAdvancedCheckBox = new QCheckBox(Tr::tr("Advanced")); m_showAdvancedCheckBox = new QCheckBox(Tr::tr("Advanced"));
m_showAdvancedCheckBox->setChecked(settings().showAdvancedOptionsByDefault());
auto settings = CMakeSpecificSettings::instance();
m_showAdvancedCheckBox->setChecked(settings->showAdvancedOptionsByDefault.value());
connect(m_configView->selectionModel(), &QItemSelectionModel::selectionChanged, connect(m_configView->selectionModel(), &QItemSelectionModel::selectionChanged,
this, [this](const QItemSelection &, const QItemSelection &) { this, [this](const QItemSelection &, const QItemSelection &) {
@@ -589,20 +587,18 @@ void CMakeBuildSettingsWidget::batchEditConfiguration()
void CMakeBuildSettingsWidget::reconfigureWithInitialParameters() void CMakeBuildSettingsWidget::reconfigureWithInitialParameters()
{ {
auto settings = CMakeSpecificSettings::instance();
QMessageBox::StandardButton reply = CheckableMessageBox::question( QMessageBox::StandardButton reply = CheckableMessageBox::question(
Core::ICore::dialogParent(), Core::ICore::dialogParent(),
Tr::tr("Re-configure with Initial Parameters"), Tr::tr("Re-configure with Initial Parameters"),
Tr::tr("Clear CMake configuration and configure with initial parameters?"), Tr::tr("Clear CMake configuration and configure with initial parameters?"),
settings->askBeforeReConfigureInitialParams.askAgainCheckableDecider(), settings().askBeforeReConfigureInitialParams.askAgainCheckableDecider(),
QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes); QMessageBox::Yes);
settings->writeSettings(); settings().writeSettings();
if (reply != QMessageBox::Yes) { if (reply != QMessageBox::Yes)
return; return;
}
m_buildSystem->clearCMakeCache(); m_buildSystem->clearCMakeCache();
@@ -1135,7 +1131,7 @@ static CommandLine defaultInitialCMakeCommand(const Kit *k, const QString buildT
cmd.addArg("-DCMAKE_BUILD_TYPE:STRING=" + buildType); cmd.addArg("-DCMAKE_BUILD_TYPE:STRING=" + buildType);
// Package manager auto setup // Package manager auto setup
if (Internal::CMakeSpecificSettings::instance()->packageManagerAutoSetup.value()) { if (settings().packageManagerAutoSetup()) {
cmd.addArg(QString("-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=" cmd.addArg(QString("-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH="
"%{BuildConfig:BuildDirectory:NativeFilePath}/%1/auto-setup.cmake") "%{BuildConfig:BuildDirectory:NativeFilePath}/%1/auto-setup.cmake")
.arg(Constants::PACKAGE_MANAGER_DIR)); .arg(Constants::PACKAGE_MANAGER_DIR));
@@ -2059,12 +2055,10 @@ void CMakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const
if (tool && tool->cmakeExecutable().needsDevice()) if (tool && tool->cmakeExecutable().needsDevice())
return; return;
auto settings = CMakeSpecificSettings::instance(); const FilePath ninja = settings().ninjaPath();
if (!settings->ninjaPath().isEmpty()) { if (!ninja.isEmpty())
const Utils::FilePath ninja = settings->ninjaPath();
env.appendOrSetPath(ninja.isFile() ? ninja.parentDir() : ninja); env.appendOrSetPath(ninja.isFile() ? ninja.parentDir() : ninja);
} }
}
Environment CMakeBuildConfiguration::configureEnvironment() const Environment CMakeBuildConfiguration::configureEnvironment() const
{ {

View File

@@ -1190,8 +1190,7 @@ void CMakeBuildSystem::wireUpConnections()
connect(project(), &Project::projectFileIsDirty, this, [this] { connect(project(), &Project::projectFileIsDirty, this, [this] {
if (buildConfiguration()->isActive() && !isParsing()) { if (buildConfiguration()->isActive() && !isParsing()) {
auto settings = CMakeSpecificSettings::instance(); if (settings().autorunCMake()) {
if (settings->autorunCMake.value()) {
qCDebug(cmakeBuildSystemLog) << "Requesting parse due to dirty project file"; qCDebug(cmakeBuildSystemLog) << "Requesting parse due to dirty project file";
reparse(CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN); reparse(CMakeBuildSystem::REPARSE_FORCE_CMAKE_RUN);
} }

View File

@@ -648,8 +648,7 @@ QVariant CMakeGeneratorKitAspect::defaultValue(const Kit *k) const
}); });
if (it != known.constEnd()) { if (it != known.constEnd()) {
const bool hasNinja = [k, tool] { const bool hasNinja = [k, tool] {
auto settings = Internal::CMakeSpecificSettings::instance(); if (Internal::settings().ninjaPath().isEmpty()) {
if (settings->ninjaPath().isEmpty()) {
auto findNinja = [](const Environment &env) -> bool { auto findNinja = [](const Environment &env) -> bool {
return !env.searchInPath("ninja").isEmpty(); return !env.searchInPath("ninja").isEmpty();
}; };

View File

@@ -101,7 +101,7 @@ void CMakeProcess::run(const BuildDirParameters &parameters, const QStringList &
} }
// Copy the "package-manager" CMake code from the ${IDE:ResourcePath} to the build directory // Copy the "package-manager" CMake code from the ${IDE:ResourcePath} to the build directory
if (Internal::CMakeSpecificSettings::instance()->packageManagerAutoSetup.value()) { if (settings().packageManagerAutoSetup()) {
const FilePath localPackageManagerDir = buildDirectory.pathAppended(Constants::PACKAGE_MANAGER_DIR); const FilePath localPackageManagerDir = buildDirectory.pathAppended(Constants::PACKAGE_MANAGER_DIR);
const FilePath idePackageManagerDir = FilePath::fromString( const FilePath idePackageManagerDir = FilePath::fromString(
parameters.expander->expand(QStringLiteral("%{IDE:ResourcePath}/package-manager"))); parameters.expander->expand(QStringLiteral("%{IDE:ResourcePath}/package-manager")));

View File

@@ -231,14 +231,12 @@ void CMakeManager::enableBuildFileMenus(Node *node)
void CMakeManager::reloadCMakePresets() void CMakeManager::reloadCMakePresets()
{ {
auto settings = CMakeSpecificSettings::instance();
QMessageBox::StandardButton clickedButton = CheckableMessageBox::question( QMessageBox::StandardButton clickedButton = CheckableMessageBox::question(
Core::ICore::dialogParent(), Core::ICore::dialogParent(),
Tr::tr("Reload CMake Presets"), Tr::tr("Reload CMake Presets"),
Tr::tr("Re-generates the kits that were created for CMake presets. All manual " Tr::tr("Re-generates the kits that were created for CMake presets. All manual "
"modifications to the CMake project settings will be lost."), "modifications to the CMake project settings will be lost."),
settings->askBeforePresetsReload.askAgainCheckableDecider(), settings().askBeforePresetsReload.askAgainCheckableDecider(),
QMessageBox::Yes | QMessageBox::Cancel, QMessageBox::Yes | QMessageBox::Cancel,
QMessageBox::Yes, QMessageBox::Yes,
QMessageBox::Yes, QMessageBox::Yes,

View File

@@ -17,7 +17,6 @@
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include "cmakeprojectnodes.h" #include "cmakeprojectnodes.h"
#include "cmakesettingspage.h" #include "cmakesettingspage.h"
#include "cmakespecificsettings.h"
#include "cmaketoolmanager.h" #include "cmaketoolmanager.h"
#include <coreplugin/actionmanager/actioncontainer.h> #include <coreplugin/actionmanager/actioncontainer.h>
@@ -54,7 +53,6 @@ public:
}; };
CMakeSettingsPage settingsPage; CMakeSettingsPage settingsPage;
CMakeSpecificSettings specificSettings;
CMakeManager manager; CMakeManager manager;
CMakeBuildStepFactory buildStepFactory; CMakeBuildStepFactory buildStepFactory;

View File

@@ -7,6 +7,8 @@
#include "cmakeprojectmanagertr.h" #include "cmakeprojectmanagertr.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/dialogs/ioptionspage.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/layoutbuilder.h> #include <utils/layoutbuilder.h>
@@ -15,23 +17,14 @@ using namespace Utils;
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
static CMakeSpecificSettings *theSettings; CMakeSpecificSettings &settings()
CMakeSpecificSettings *CMakeSpecificSettings::instance()
{ {
static CMakeSpecificSettings theSettings;
return theSettings; return theSettings;
} }
CMakeSpecificSettings::CMakeSpecificSettings() CMakeSpecificSettings::CMakeSpecificSettings()
{ {
theSettings = this;
setId(Constants::Settings::GENERAL_ID);
setDisplayName(::CMakeProjectManager::Tr::tr("General"));
setDisplayCategory("CMake");
setCategory(Constants::Settings::CATEGORY);
setCategoryIconPath(Constants::Icons::SETTINGS_CATEGORY);
setLayouter([this] { setLayouter([this] {
using namespace Layouting; using namespace Layouting;
return Column { return Column {
@@ -91,4 +84,20 @@ CMakeSpecificSettings::CMakeSpecificSettings()
readSettings(); readSettings();
} }
class CMakeSpecificSettingsPage final : public Core::IOptionsPage
{
public:
CMakeSpecificSettingsPage()
{
setId(Constants::Settings::GENERAL_ID);
setDisplayName(::CMakeProjectManager::Tr::tr("General"));
setDisplayCategory("CMake");
setCategory(Constants::Settings::CATEGORY);
setCategoryIconPath(Constants::Icons::SETTINGS_CATEGORY);
setSettingsProvider([] { return &settings(); });
}
};
const CMakeSpecificSettingsPage settingsPage;
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -3,17 +3,15 @@
#pragma once #pragma once
#include <coreplugin/dialogs/ioptionspage.h> #include <utils/aspects.h>
namespace CMakeProjectManager::Internal { namespace CMakeProjectManager::Internal {
class CMakeSpecificSettings final : public Core::PagedSettings class CMakeSpecificSettings final : public Utils::AspectContainer
{ {
public: public:
CMakeSpecificSettings(); CMakeSpecificSettings();
static CMakeSpecificSettings *instance();
Utils::BoolAspect autorunCMake{this}; Utils::BoolAspect autorunCMake{this};
Utils::FilePathAspect ninjaPath{this}; Utils::FilePathAspect ninjaPath{this};
Utils::BoolAspect packageManagerAutoSetup{this}; Utils::BoolAspect packageManagerAutoSetup{this};
@@ -23,4 +21,6 @@ public:
Utils::BoolAspect showAdvancedOptionsByDefault{this}; Utils::BoolAspect showAdvancedOptionsByDefault{this};
}; };
CMakeSpecificSettings &settings();
} // CMakeProjectManager::Internal } // CMakeProjectManager::Internal

View File

@@ -142,11 +142,11 @@ void CMakeToolManager::restoreCMakeTools()
// Store the default CMake tool "Autorun CMake" value globally // Store the default CMake tool "Autorun CMake" value globally
// TODO: Remove in Qt Creator 13 // TODO: Remove in Qt Creator 13
auto settings = Internal::CMakeSpecificSettings::instance(); Internal::CMakeSpecificSettings &s = Internal::settings();
if (settings->autorunCMake.value() == settings->autorunCMake.defaultValue()) { if (s.autorunCMake() == s.autorunCMake.defaultValue()) {
CMakeTool *cmake = defaultCMakeTool(); CMakeTool *cmake = defaultCMakeTool();
settings->autorunCMake.setValue(cmake ? cmake->isAutoRun() : true); s.autorunCMake.setValue(cmake ? cmake->isAutoRun() : true);
settings->writeSettings(); s.writeSettings();
} }
} }

View File

@@ -174,13 +174,13 @@ void CMakeToolSettingsAccessor::saveCMakeTools(const QList<CMakeTool *> &cmakeTo
data.insert(QLatin1String(CMAKE_TOOL_DEFAULT_KEY), defaultId.toSetting()); data.insert(QLatin1String(CMAKE_TOOL_DEFAULT_KEY), defaultId.toSetting());
int count = 0; int count = 0;
const bool autoRun = settings().autorunCMake();
for (CMakeTool *item : cmakeTools) { for (CMakeTool *item : cmakeTools) {
Utils::FilePath fi = item->cmakeExecutable(); Utils::FilePath fi = item->cmakeExecutable();
// Gobal Autorun value will be set for all tools // Gobal Autorun value will be set for all tools
// TODO: Remove in Qt Creator 13 // TODO: Remove in Qt Creator 13
const auto settings = CMakeSpecificSettings::instance(); item->setAutorun(autoRun);
item->setAutorun(settings->autorunCMake.value());
if (fi.needsDevice() || fi.isExecutableFile()) { // be graceful for device related stuff if (fi.needsDevice() || fi.isExecutableFile()) { // be graceful for device related stuff
QVariantMap tmp = item->toMap(); QVariantMap tmp = item->toMap();

View File

@@ -540,10 +540,9 @@ void addCompileGroups(ProjectNode *targetRoot,
const Utils::FilePath &buildDirectory, const Utils::FilePath &buildDirectory,
const TargetDetails &td) const TargetDetails &td)
{ {
const bool showSourceFolders = CMakeSpecificSettings::instance()->showSourceSubFolders.value(); const bool showSourceFolders = settings().showSourceSubFolders();
const bool inSourceBuild = (sourceDirectory == buildDirectory); const bool inSourceBuild = (sourceDirectory == buildDirectory);
std::vector<std::unique_ptr<FileNode>> toList;
QSet<Utils::FilePath> alreadyListed; QSet<Utils::FilePath> alreadyListed;
// Files already added by other configurations: // Files already added by other configurations:

View File

@@ -107,8 +107,7 @@ void FileApiReader::parse(bool forceCMakeRun,
// * A query file is newer than the reply file // * A query file is newer than the reply file
const bool hasArguments = !args.isEmpty(); const bool hasArguments = !args.isEmpty();
const bool replyFileMissing = !replyFile.exists(); const bool replyFileMissing = !replyFile.exists();
const auto settings = CMakeSpecificSettings::instance(); const bool cmakeFilesChanged = m_parameters.cmakeTool() && settings().autorunCMake()
const bool cmakeFilesChanged = m_parameters.cmakeTool() && settings->autorunCMake.value()
&& anyOf(m_cmakeFiles, [&replyFile](const CMakeFileInfo &info) { && anyOf(m_cmakeFiles, [&replyFile](const CMakeFileInfo &info) {
return !info.isGenerated return !info.isGenerated
&& info.path.lastModified() > replyFile.lastModified(); && info.path.lastModified() > replyFile.lastModified();