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>
This commit is contained in:
hjk
2023-05-15 12:42:08 +02:00
parent bc11440256
commit 318ac76339
6 changed files with 57 additions and 114 deletions

View File

@@ -160,7 +160,7 @@ QmakeBuildConfiguration::QmakeBuildConfiguration(Target *target, Id id)
this, &QmakeBuildConfiguration::updateProblemLabel); this, &QmakeBuildConfiguration::updateProblemLabel);
connect(this, &QmakeBuildConfiguration::qmakeBuildConfigurationChanged, connect(this, &QmakeBuildConfiguration::qmakeBuildConfigurationChanged,
this, &QmakeBuildConfiguration::updateProblemLabel); this, &QmakeBuildConfiguration::updateProblemLabel);
connect(&QmakeSettings::instance(), &QmakeSettings::settingsChanged, connect(&settings(), &AspectContainer::changed,
this, &QmakeBuildConfiguration::updateProblemLabel); this, &QmakeBuildConfiguration::updateProblemLabel);
connect(target, &Target::parsingFinished, this, &QmakeBuildConfiguration::updateProblemLabel); connect(target, &Target::parsingFinished, this, &QmakeBuildConfiguration::updateProblemLabel);
connect(target, &Target::kitChanged, 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(); && !isBuildDirAtSafeLocation();
if (unalignedBuildDir) if (unalignedBuildDir)
allGood = false; allGood = false;
@@ -426,7 +426,7 @@ bool QmakeBuildConfiguration::runSystemFunction() const
return true; return true;
if (runSystem == TriState::Disabled) if (runSystem == TriState::Disabled)
return false; return false;
return QmakeSettings::runSystemFunction(); return settings().runSystemFunction();
} }
QStringList QmakeBuildConfiguration::configCommandLineArguments() const QStringList QmakeBuildConfiguration::configCommandLineArguments() const
@@ -753,7 +753,7 @@ QmakeBuildConfigurationFactory::QmakeBuildConfigurationFactory()
Tasks issues; Tasks issues;
if (version) if (version)
issues << version->reportIssues(projectPath, buildDir); issues << version->reportIssues(projectPath, buildDir);
if (QmakeSettings::warnAgainstUnalignedBuildDir() if (settings().warnAgainstUnalignedBuildDir()
&& !QmakeBuildConfiguration::isBuildDirAtSafeLocation( && !QmakeBuildConfiguration::isBuildDirAtSafeLocation(
projectPath.absolutePath(), buildDir.absoluteFilePath())) { projectPath.absolutePath(), buildDir.absoluteFilePath())) {
issues.append(BuildSystemTask(Task::Warning, issues.append(BuildSystemTask(Task::Warning,

View File

@@ -222,7 +222,7 @@ void QmakeMakeStep::doRun()
void QmakeMakeStep::finish(ProcessResult result) void QmakeMakeStep::finish(ProcessResult result)
{ {
if (!isSuccess(result) && !isCanceled() && m_unalignedBuildDir 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 " 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."); "directory, which could be the reason for the build failure.");
emit addTask(BuildSystemTask(Task::Warning, msg)); emit addTask(BuildSystemTask(Task::Warning, msg));

View File

@@ -80,7 +80,7 @@ public:
ProFileEditorFactory profileEditorFactory; ProFileEditorFactory profileEditorFactory;
QmakeSettingsPage settingsPage; QmakeSettings settings;
QmakeProject *m_previousStartupProject = nullptr; QmakeProject *m_previousStartupProject = nullptr;
Target *m_previousTarget = nullptr; Target *m_previousTarget = nullptr;

View File

@@ -11,98 +11,59 @@
#include <utils/hostosinfo.h> #include <utils/hostosinfo.h>
#include <utils/layoutbuilder.h> #include <utils/layoutbuilder.h>
#include <QXmlStreamWriter>
using namespace Utils; using namespace Utils;
namespace QmakeProjectManager { namespace QmakeProjectManager::Internal {
namespace Internal {
static QmakeSettings *theSettings;
QmakeSettings &settings() { return *theSettings; }
QmakeSettings::QmakeSettings() QmakeSettings::QmakeSettings()
{ {
setAutoApply(false); theSettings = this;
registerAspect(&m_warnAgainstUnalignedBuildDir); setId("K.QmakeProjectManager.QmakeSettings");
m_warnAgainstUnalignedBuildDir.setSettingsKey("QmakeProjectManager/WarnAgainstUnalignedBuildDir"); setDisplayName(Tr::tr("Qmake"));
m_warnAgainstUnalignedBuildDir.setDefaultValue(HostOsInfo::isWindowsHost()); setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
m_warnAgainstUnalignedBuildDir.setLabelText(Tr::tr("Warn if a project's source and " 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")); "build directories are not at the same level"));
m_warnAgainstUnalignedBuildDir.setToolTip(Tr::tr("Qmake has subtle bugs that " warnAgainstUnalignedBuildDir.setToolTip(Tr::tr("Qmake has subtle bugs that "
"can be triggered if source and build directory are not at the same level.")); "can be triggered if source and build directory are not at the same level."));
registerAspect(&m_alwaysRunQmake); registerAspect(&alwaysRunQmake);
m_alwaysRunQmake.setSettingsKey("QmakeProjectManager/AlwaysRunQmake"); alwaysRunQmake.setSettingsKey("AlwaysRunQmake");
m_alwaysRunQmake.setLabelText(Tr::tr("Run qmake on every build")); alwaysRunQmake.setLabelText(Tr::tr("Run qmake on every build"));
m_alwaysRunQmake.setToolTip(Tr::tr("This option can help to prevent failures on " alwaysRunQmake.setToolTip(Tr::tr("This option can help to prevent failures on "
"incremental builds, but might slow them down unnecessarily in the general case.")); "incremental builds, but might slow them down unnecessarily in the general case."));
registerAspect(&m_ignoreSystemFunction); registerAspect(&ignoreSystemFunction);
m_ignoreSystemFunction.setSettingsKey("QmakeProjectManager/RunSystemFunction"); ignoreSystemFunction.setSettingsKey("RunSystemFunction");
m_ignoreSystemFunction.setLabelText(Tr::tr("Ignore qmake's system() function when parsing a project")); 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, " ignoreSystemFunction.setToolTip(Tr::tr("Checking this option avoids unwanted side effects, "
"but may result in inexact parsing results.")); "but may result in inexact parsing results."));
// The settings value has been stored with the opposite meaning for a while. // The settings value has been stored with the opposite meaning for a while.
// Avoid changing the stored value, but flip it on read/write: // Avoid changing the stored value, but flip it on read/write:
const auto invertBoolVariant = [](const QVariant &v) { return QVariant(!v.toBool()); }; const auto invertBoolVariant = [](const QVariant &v) { return QVariant(!v.toBool()); };
m_ignoreSystemFunction.setFromSettingsTransformation(invertBoolVariant); ignoreSystemFunction.setFromSettingsTransformation(invertBoolVariant);
m_ignoreSystemFunction.setToSettingsTransformation(invertBoolVariant); ignoreSystemFunction.setToSettingsTransformation(invertBoolVariant);
setLayouter([this](QWidget *widget) {
using namespace Layouting;
Column {
warnAgainstUnalignedBuildDir,
alwaysRunQmake,
ignoreSystemFunction,
st
}.attachTo(widget);
});
readSettings(Core::ICore::settings()); readSettings(Core::ICore::settings());
} }
bool QmakeSettings::warnAgainstUnalignedBuildDir() } // QmakeProjectManager::Internal
{
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();
using namespace Layouting;
Column {
s.m_warnAgainstUnalignedBuildDir,
s.m_alwaysRunQmake,
s.m_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; });
}
} // namespace Internal
} // namespace QmakeProjectManager

View File

@@ -5,38 +5,20 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <utils/aspects.h> namespace QmakeProjectManager::Internal {
namespace QmakeProjectManager { class QmakeSettings : public Core::PagedSettings
namespace Internal {
class QmakeSettings : public Utils::AspectContainer
{ {
Q_OBJECT
public: public:
static QmakeSettings &instance();
static bool warnAgainstUnalignedBuildDir();
static bool alwaysRunQmake();
static bool runSystemFunction();
signals:
void settingsChanged();
private:
QmakeSettings(); QmakeSettings();
friend class SettingsWidget;
Utils::BoolAspect m_warnAgainstUnalignedBuildDir; bool runSystemFunction() { return !ignoreSystemFunction(); }
Utils::BoolAspect m_alwaysRunQmake;
Utils::BoolAspect m_ignoreSystemFunction; Utils::BoolAspect warnAgainstUnalignedBuildDir;
Utils::BoolAspect alwaysRunQmake;
Utils::BoolAspect ignoreSystemFunction;
}; };
class QmakeSettingsPage final : public Core::IOptionsPage QmakeSettings &settings();
{
public:
QmakeSettingsPage();
};
} // namespace Internal } // QmakeProjectManager::Internal
} // namespace QmakeProjectManager

View File

@@ -225,7 +225,7 @@ bool QMakeStep::init()
} }
// Check whether we need to run qmake // Check whether we need to run qmake
if (m_forced || QmakeSettings::alwaysRunQmake() if (m_forced || settings().alwaysRunQmake()
|| qmakeBc->compareToImportFrom(makeFile) != QmakeBuildConfiguration::MakefileMatches) { || qmakeBc->compareToImportFrom(makeFile) != QmakeBuildConfiguration::MakefileMatches) {
m_needToRunQMake = true; m_needToRunQMake = true;
} }