diff options
author | hjk <hjk@qt.io> | 2023-05-15 12:42:08 +0200 |
---|---|---|
committer | hjk <hjk@qt.io> | 2023-05-16 08:10:08 +0000 |
commit | 318ac763392edf37bd2e18b15efebc7274f222b5 (patch) | |
tree | 1a61eb7887afedd1799e07971a33a7c378875248 | |
parent | bc1144025631bd609cf3a16281e22962cb165cc7 (diff) | |
download | qt-creator-318ac763392edf37bd2e18b15efebc7274f222b5.tar.gz |
QMakeProject: Use PagedSettings page for options
Also adapt to a few recent usage changes.
Change-Id: I33f45fe7c2b8738280a7c81ddb9110cb8714c45a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
6 files changed, 58 insertions, 115 deletions
diff --git a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp index ce64ecd2d9..173443958d 100644 --- a/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp +++ b/src/plugins/qmakeprojectmanager/qmakebuildconfiguration.cpp @@ -160,7 +160,7 @@ QmakeBuildConfiguration::QmakeBuildConfiguration(Target *target, Id id) this, &QmakeBuildConfiguration::updateProblemLabel); connect(this, &QmakeBuildConfiguration::qmakeBuildConfigurationChanged, this, &QmakeBuildConfiguration::updateProblemLabel); - connect(&QmakeSettings::instance(), &QmakeSettings::settingsChanged, + connect(&settings(), &AspectContainer::changed, this, &QmakeBuildConfiguration::updateProblemLabel); connect(target, &Target::parsingFinished, this, &QmakeBuildConfiguration::updateProblemLabel); connect(target, &Target::kitChanged, this, &QmakeBuildConfiguration::updateProblemLabel); @@ -267,7 +267,7 @@ void QmakeBuildConfiguration::updateProblemLabel() } } - const bool unalignedBuildDir = QmakeSettings::warnAgainstUnalignedBuildDir() + const bool unalignedBuildDir = settings().warnAgainstUnalignedBuildDir() && !isBuildDirAtSafeLocation(); if (unalignedBuildDir) allGood = false; @@ -426,7 +426,7 @@ bool QmakeBuildConfiguration::runSystemFunction() const return true; if (runSystem == TriState::Disabled) return false; - return QmakeSettings::runSystemFunction(); + return settings().runSystemFunction(); } QStringList QmakeBuildConfiguration::configCommandLineArguments() const @@ -753,7 +753,7 @@ QmakeBuildConfigurationFactory::QmakeBuildConfigurationFactory() Tasks issues; if (version) issues << version->reportIssues(projectPath, buildDir); - if (QmakeSettings::warnAgainstUnalignedBuildDir() + if (settings().warnAgainstUnalignedBuildDir() && !QmakeBuildConfiguration::isBuildDirAtSafeLocation( projectPath.absolutePath(), buildDir.absoluteFilePath())) { issues.append(BuildSystemTask(Task::Warning, diff --git a/src/plugins/qmakeprojectmanager/qmakemakestep.cpp b/src/plugins/qmakeprojectmanager/qmakemakestep.cpp index ae35a9dc76..e72d346758 100644 --- a/src/plugins/qmakeprojectmanager/qmakemakestep.cpp +++ b/src/plugins/qmakeprojectmanager/qmakemakestep.cpp @@ -222,7 +222,7 @@ void QmakeMakeStep::doRun() void QmakeMakeStep::finish(ProcessResult result) { if (!isSuccess(result) && !isCanceled() && m_unalignedBuildDir - && QmakeSettings::warnAgainstUnalignedBuildDir()) { + && settings().warnAgainstUnalignedBuildDir()) { const QString msg = Tr::tr("The build directory is not at the same level as the source " "directory, which could be the reason for the build failure."); emit addTask(BuildSystemTask(Task::Warning, msg)); diff --git a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp index 67d450b56f..d89393909b 100644 --- a/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp +++ b/src/plugins/qmakeprojectmanager/qmakeprojectmanagerplugin.cpp @@ -80,7 +80,7 @@ public: ProFileEditorFactory profileEditorFactory; - QmakeSettingsPage settingsPage; + QmakeSettings settings; QmakeProject *m_previousStartupProject = nullptr; Target *m_previousTarget = nullptr; diff --git a/src/plugins/qmakeprojectmanager/qmakesettings.cpp b/src/plugins/qmakeprojectmanager/qmakesettings.cpp index a9e1de07c3..5a05e5904d 100644 --- a/src/plugins/qmakeprojectmanager/qmakesettings.cpp +++ b/src/plugins/qmakeprojectmanager/qmakesettings.cpp @@ -11,98 +11,59 @@ #include <utils/hostosinfo.h> #include <utils/layoutbuilder.h> -#include <QXmlStreamWriter> - using namespace Utils; -namespace QmakeProjectManager { -namespace Internal { +namespace QmakeProjectManager::Internal { + +static QmakeSettings *theSettings; + +QmakeSettings &settings() { return *theSettings; } QmakeSettings::QmakeSettings() { - setAutoApply(false); - - registerAspect(&m_warnAgainstUnalignedBuildDir); - m_warnAgainstUnalignedBuildDir.setSettingsKey("QmakeProjectManager/WarnAgainstUnalignedBuildDir"); - m_warnAgainstUnalignedBuildDir.setDefaultValue(HostOsInfo::isWindowsHost()); - m_warnAgainstUnalignedBuildDir.setLabelText(Tr::tr("Warn if a project's source and " - "build directories are not at the same level")); - m_warnAgainstUnalignedBuildDir.setToolTip(Tr::tr("Qmake has subtle bugs that " - "can be triggered if source and build directory are not at the same level.")); - - registerAspect(&m_alwaysRunQmake); - m_alwaysRunQmake.setSettingsKey("QmakeProjectManager/AlwaysRunQmake"); - m_alwaysRunQmake.setLabelText(Tr::tr("Run qmake on every build")); - m_alwaysRunQmake.setToolTip(Tr::tr("This option can help to prevent failures on " - "incremental builds, but might slow them down unnecessarily in the general case.")); - - registerAspect(&m_ignoreSystemFunction); - m_ignoreSystemFunction.setSettingsKey("QmakeProjectManager/RunSystemFunction"); - m_ignoreSystemFunction.setLabelText(Tr::tr("Ignore qmake's system() function when parsing a project")); - m_ignoreSystemFunction.setToolTip(Tr::tr("Checking this option avoids unwanted side effects, " - "but may result in inexact parsing results.")); + theSettings = this; + + setId("K.QmakeProjectManager.QmakeSettings"); + setDisplayName(Tr::tr("Qmake")); + setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY); + setSettingsGroup("QmakeProjectManager"); + + registerAspect(&warnAgainstUnalignedBuildDir); + warnAgainstUnalignedBuildDir.setSettingsKey("WarnAgainstUnalignedBuildDir"); + warnAgainstUnalignedBuildDir.setDefaultValue(HostOsInfo::isWindowsHost()); + warnAgainstUnalignedBuildDir.setLabelText(Tr::tr("Warn if a project's source and " + "build directories are not at the same level")); + warnAgainstUnalignedBuildDir.setToolTip(Tr::tr("Qmake has subtle bugs that " + "can be triggered if source and build directory are not at the same level.")); + + registerAspect(&alwaysRunQmake); + alwaysRunQmake.setSettingsKey("AlwaysRunQmake"); + alwaysRunQmake.setLabelText(Tr::tr("Run qmake on every build")); + alwaysRunQmake.setToolTip(Tr::tr("This option can help to prevent failures on " + "incremental builds, but might slow them down unnecessarily in the general case.")); + + registerAspect(&ignoreSystemFunction); + ignoreSystemFunction.setSettingsKey("RunSystemFunction"); + ignoreSystemFunction.setLabelText(Tr::tr("Ignore qmake's system() function when parsing a project")); + ignoreSystemFunction.setToolTip(Tr::tr("Checking this option avoids unwanted side effects, " + "but may result in inexact parsing results.")); // The settings value has been stored with the opposite meaning for a while. // Avoid changing the stored value, but flip it on read/write: const auto invertBoolVariant = [](const QVariant &v) { return QVariant(!v.toBool()); }; - m_ignoreSystemFunction.setFromSettingsTransformation(invertBoolVariant); - m_ignoreSystemFunction.setToSettingsTransformation(invertBoolVariant); + ignoreSystemFunction.setFromSettingsTransformation(invertBoolVariant); + ignoreSystemFunction.setToSettingsTransformation(invertBoolVariant); - readSettings(Core::ICore::settings()); -} - -bool QmakeSettings::warnAgainstUnalignedBuildDir() -{ - return instance().m_warnAgainstUnalignedBuildDir.value(); -} - -bool QmakeSettings::alwaysRunQmake() -{ - return instance().m_alwaysRunQmake.value(); -} - -bool QmakeSettings::runSystemFunction() -{ - return !instance().m_ignoreSystemFunction.value(); // Note: negated. -} - -QmakeSettings &QmakeSettings::instance() -{ - static QmakeSettings theSettings; - return theSettings; -} - -class SettingsWidget final : public Core::IOptionsPageWidget -{ -public: - SettingsWidget() - { - auto &s = QmakeSettings::instance(); + setLayouter([this](QWidget *widget) { using namespace Layouting; Column { - s.m_warnAgainstUnalignedBuildDir, - s.m_alwaysRunQmake, - s.m_ignoreSystemFunction, + warnAgainstUnalignedBuildDir, + alwaysRunQmake, + ignoreSystemFunction, st - }.attachTo(this); - } - - void apply() final - { - auto &s = QmakeSettings::instance(); - if (s.isDirty()) { - s.apply(); - s.writeSettings(Core::ICore::settings()); - } - } -}; - -QmakeSettingsPage::QmakeSettingsPage() -{ - setId("K.QmakeProjectManager.QmakeSettings"); - setDisplayName(Tr::tr("Qmake")); - setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY); - setWidgetCreator([] { return new SettingsWidget; }); + }.attachTo(widget); + }); + + readSettings(Core::ICore::settings()); } -} // namespace Internal -} // namespace QmakeProjectManager +} // QmakeProjectManager::Internal diff --git a/src/plugins/qmakeprojectmanager/qmakesettings.h b/src/plugins/qmakeprojectmanager/qmakesettings.h index 242f6601e2..de9a9ec0d3 100644 --- a/src/plugins/qmakeprojectmanager/qmakesettings.h +++ b/src/plugins/qmakeprojectmanager/qmakesettings.h @@ -5,38 +5,20 @@ #include <coreplugin/dialogs/ioptionspage.h> -#include <utils/aspects.h> +namespace QmakeProjectManager::Internal { -namespace QmakeProjectManager { -namespace Internal { - -class QmakeSettings : public Utils::AspectContainer +class QmakeSettings : public Core::PagedSettings { - Q_OBJECT - public: - static QmakeSettings &instance(); - static bool warnAgainstUnalignedBuildDir(); - static bool alwaysRunQmake(); - static bool runSystemFunction(); - -signals: - void settingsChanged(); - -private: QmakeSettings(); - friend class SettingsWidget; - Utils::BoolAspect m_warnAgainstUnalignedBuildDir; - Utils::BoolAspect m_alwaysRunQmake; - Utils::BoolAspect m_ignoreSystemFunction; -}; + bool runSystemFunction() { return !ignoreSystemFunction(); } -class QmakeSettingsPage final : public Core::IOptionsPage -{ -public: - QmakeSettingsPage(); + Utils::BoolAspect warnAgainstUnalignedBuildDir; + Utils::BoolAspect alwaysRunQmake; + Utils::BoolAspect ignoreSystemFunction; }; -} // namespace Internal -} // namespace QmakeProjectManager +QmakeSettings &settings(); + +} // QmakeProjectManager::Internal diff --git a/src/plugins/qmakeprojectmanager/qmakestep.cpp b/src/plugins/qmakeprojectmanager/qmakestep.cpp index edcc0e40bb..010d160823 100644 --- a/src/plugins/qmakeprojectmanager/qmakestep.cpp +++ b/src/plugins/qmakeprojectmanager/qmakestep.cpp @@ -225,7 +225,7 @@ bool QMakeStep::init() } // Check whether we need to run qmake - if (m_forced || QmakeSettings::alwaysRunQmake() + if (m_forced || settings().alwaysRunQmake() || qmakeBc->compareToImportFrom(makeFile) != QmakeBuildConfiguration::MakefileMatches) { m_needToRunQMake = true; } |