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);
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,

View File

@@ -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));

View File

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

View File

@@ -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);
theSettings = this;
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 "
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"));
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."));
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 "
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(&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, "
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);
setLayouter([this](QWidget *widget) {
using namespace Layouting;
Column {
warnAgainstUnalignedBuildDir,
alwaysRunQmake,
ignoreSystemFunction,
st
}.attachTo(widget);
});
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();
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
} // QmakeProjectManager::Internal

View File

@@ -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(); }
Utils::BoolAspect warnAgainstUnalignedBuildDir;
Utils::BoolAspect alwaysRunQmake;
Utils::BoolAspect ignoreSystemFunction;
};
class QmakeSettingsPage final : public Core::IOptionsPage
{
public:
QmakeSettingsPage();
};
QmakeSettings &settings();
} // namespace Internal
} // namespace QmakeProjectManager
} // QmakeProjectManager::Internal

View File

@@ -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;
}