QmakeProjectManager: Aspectify settings page

Change-Id: I97630d9c63d6629e89ada46a1c05b8d820bd72fb
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2021-03-23 15:01:37 +01:00
parent b7b41f7cc3
commit b569258748
2 changed files with 56 additions and 124 deletions

View File

@@ -26,44 +26,56 @@
#include "qmakesettings.h" #include "qmakesettings.h"
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <utils/hostosinfo.h>
#include <QCheckBox> #include <projectexplorer/projectexplorerconstants.h>
#include <QCoreApplication>
#include <QVBoxLayout> #include <utils/layoutbuilder.h>
using namespace Utils;
namespace QmakeProjectManager { namespace QmakeProjectManager {
namespace Internal { namespace Internal {
const char BUILD_DIR_WARNING_KEY[] = "QmakeProjectManager/WarnAgainstUnalignedBuildDir"; QmakeSettings::QmakeSettings()
const char ALWAYS_RUN_QMAKE_KEY[] = "QmakeProjectManager/AlwaysRunQmake"; {
const char RUN_SYSTEM_KEY[] = "QmakeProjectManager/RunSystemFunction"; setAutoApply(false);
static bool operator==(const QmakeSettingsData &s1, const QmakeSettingsData &s2) registerAspect(&m_warnAgainstUnalignedBuildDir);
{ m_warnAgainstUnalignedBuildDir.setSettingsKey("QmakeProjectManager/WarnAgainstUnalignedBuildDir");
return s1.warnAgainstUnalignedBuildDir == s2.warnAgainstUnalignedBuildDir m_warnAgainstUnalignedBuildDir.setLabelText(tr("Warn if a project's source and "
&& s1.alwaysRunQmake == s2.alwaysRunQmake "build directories are not at the same level"));
&& s1.runSystemFunction == s2.runSystemFunction; m_warnAgainstUnalignedBuildDir.setToolTip(tr("Qmake has subtle bugs that "
} "can be triggered if source and build directory are not at the same level."));
static bool operator!=(const QmakeSettingsData &s1, const QmakeSettingsData &s2)
{ registerAspect(&m_alwaysRunQmake);
return !(s1 == s2); m_alwaysRunQmake.setSettingsKey("QmakeProjectManager/AlwaysRunQmake");
m_alwaysRunQmake.setLabelText(tr("Run qmake on every build"));
m_alwaysRunQmake.setToolTip(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.setDefaultValue(true);
m_ignoreSystemFunction.setLabelText(tr("Ignore qmake's system() function when parsing a project"));
m_ignoreSystemFunction.setToolTip(tr("Checking this option avoids unwanted side effects, "
"but may result in inexact parsing results."));
readSettings(Core::ICore::settings());
} }
bool QmakeSettings::warnAgainstUnalignedBuildDir() bool QmakeSettings::warnAgainstUnalignedBuildDir()
{ {
return instance().m_settings.warnAgainstUnalignedBuildDir; return instance().m_warnAgainstUnalignedBuildDir.value();
} }
bool QmakeSettings::alwaysRunQmake() bool QmakeSettings::alwaysRunQmake()
{ {
return instance().m_settings.alwaysRunQmake; return instance().m_alwaysRunQmake.value();
} }
bool QmakeSettings::runSystemFunction() bool QmakeSettings::runSystemFunction()
{ {
return instance().m_settings.runSystemFunction; return !instance().m_ignoreSystemFunction.value(); // Note: negated.
} }
QmakeSettings &QmakeSettings::instance() QmakeSettings &QmakeSettings::instance()
@@ -72,78 +84,31 @@ QmakeSettings &QmakeSettings::instance()
return theSettings; return theSettings;
} }
void QmakeSettings::setSettingsData(const QmakeSettingsData &settings) class SettingsWidget final : public Core::IOptionsPageWidget
{
if (instance().m_settings != settings) {
instance().m_settings = settings;
instance().storeSettings();
emit instance().settingsChanged();
}
}
QmakeSettings::QmakeSettings()
{
loadSettings();
}
void QmakeSettings::loadSettings()
{
QSettings * const s = Core::ICore::settings();
m_settings.warnAgainstUnalignedBuildDir = s->value(
BUILD_DIR_WARNING_KEY, Utils::HostOsInfo::isWindowsHost()).toBool();
m_settings.alwaysRunQmake = s->value(ALWAYS_RUN_QMAKE_KEY, false).toBool();
m_settings.runSystemFunction = s->value(RUN_SYSTEM_KEY, true).toBool();
}
void QmakeSettings::storeSettings() const
{
QSettings * const s = Core::ICore::settings();
s->setValue(BUILD_DIR_WARNING_KEY, warnAgainstUnalignedBuildDir());
s->setValue(ALWAYS_RUN_QMAKE_KEY, alwaysRunQmake());
s->setValue(RUN_SYSTEM_KEY, runSystemFunction());
}
class QmakeSettingsPage::SettingsWidget : public QWidget
{ {
Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeSettingsPage) Q_DECLARE_TR_FUNCTIONS(QmakeProjectManager::Internal::QmakeSettingsPage)
public: public:
SettingsWidget() SettingsWidget()
{ {
m_warnAgainstUnalignedBuildDirCheckbox.setText(tr("Warn if a project's source and " auto &s = QmakeSettings::instance();
"build directories are not at the same level")); using namespace Layouting;
m_warnAgainstUnalignedBuildDirCheckbox.setToolTip(tr("Qmake has subtle bugs that " Column {
"can be triggered if source and build directory are not at the same level.")); s.m_warnAgainstUnalignedBuildDir,
m_warnAgainstUnalignedBuildDirCheckbox.setChecked( s.m_alwaysRunQmake,
QmakeSettings::warnAgainstUnalignedBuildDir()); s.m_ignoreSystemFunction,
m_alwaysRunQmakeCheckbox.setText(tr("Run qmake on every build")); Stretch()
m_alwaysRunQmakeCheckbox.setToolTip(tr("This option can help to prevent failures on " }.attachTo(this);
"incremental builds, but might slow them down unnecessarily in the general case."));
m_alwaysRunQmakeCheckbox.setChecked(QmakeSettings::alwaysRunQmake());
m_ignoreSystemCheckbox.setText(tr("Ignore qmake's system() function "
"when parsing a project"));
m_ignoreSystemCheckbox.setToolTip(tr("Checking this option avoids unwanted side effects, "
"but may result in inexact parsing results."));
m_ignoreSystemCheckbox.setChecked(!QmakeSettings::runSystemFunction());
const auto layout = new QVBoxLayout(this);
layout->addWidget(&m_warnAgainstUnalignedBuildDirCheckbox);
layout->addWidget(&m_alwaysRunQmakeCheckbox);
layout->addWidget(&m_ignoreSystemCheckbox);
layout->addStretch(1);
} }
void apply() void apply() final
{ {
QmakeSettingsData settings; auto &s = QmakeSettings::instance();
settings.warnAgainstUnalignedBuildDir = m_warnAgainstUnalignedBuildDirCheckbox.isChecked(); if (s.isDirty()) {
settings.alwaysRunQmake = m_alwaysRunQmakeCheckbox.isChecked(); s.apply();
settings.runSystemFunction = !m_ignoreSystemCheckbox.isChecked(); s.writeSettings(Core::ICore::settings());
QmakeSettings::setSettingsData(settings); }
} }
private:
QCheckBox m_warnAgainstUnalignedBuildDirCheckbox;
QCheckBox m_alwaysRunQmakeCheckbox;
QCheckBox m_ignoreSystemCheckbox;
}; };
QmakeSettingsPage::QmakeSettingsPage() QmakeSettingsPage::QmakeSettingsPage()
@@ -151,25 +116,7 @@ QmakeSettingsPage::QmakeSettingsPage()
setId("K.QmakeProjectManager.QmakeSettings"); setId("K.QmakeProjectManager.QmakeSettings");
setDisplayName(SettingsWidget::tr("Qmake")); setDisplayName(SettingsWidget::tr("Qmake"));
setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY); setCategory(ProjectExplorer::Constants::BUILD_AND_RUN_SETTINGS_CATEGORY);
} setWidgetCreator([] { return new SettingsWidget; });
QWidget *QmakeSettingsPage::widget()
{
if (!m_widget)
m_widget = new SettingsWidget;
return m_widget;
}
void QmakeSettingsPage::apply()
{
if (m_widget)
m_widget->apply();
}
void QmakeSettingsPage::finish()
{
delete m_widget;
} }
} // namespace Internal } // namespace Internal

View File

@@ -27,52 +27,37 @@
#include <coreplugin/dialogs/ioptionspage.h> #include <coreplugin/dialogs/ioptionspage.h>
#include <QObject> #include <utils/aspects.h>
#include <QPointer>
namespace QmakeProjectManager { namespace QmakeProjectManager {
namespace Internal { namespace Internal {
class QmakeSettingsData { class QmakeSettings : public QObject, public Utils::AspectContainer
public:
bool warnAgainstUnalignedBuildDir = false;
bool alwaysRunQmake = false;
bool runSystemFunction = true;
};
class QmakeSettings : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
static QmakeSettings &instance(); static QmakeSettings &instance();
static bool warnAgainstUnalignedBuildDir(); static bool warnAgainstUnalignedBuildDir();
static bool alwaysRunQmake(); static bool alwaysRunQmake();
static bool runSystemFunction(); static bool runSystemFunction();
static void setSettingsData(const QmakeSettingsData &settings);
signals: signals:
void settingsChanged(); void settingsChanged();
private: private:
QmakeSettings(); QmakeSettings();
void loadSettings(); friend class SettingsWidget;
void storeSettings() const;
QmakeSettingsData m_settings; Utils::BoolAspect m_warnAgainstUnalignedBuildDir;
Utils::BoolAspect m_alwaysRunQmake;
Utils::BoolAspect m_ignoreSystemFunction;
}; };
class QmakeSettingsPage final : public Core::IOptionsPage class QmakeSettingsPage final : public Core::IOptionsPage
{ {
public: public:
QmakeSettingsPage(); QmakeSettingsPage();
private:
QWidget *widget() override;
void apply() override;
void finish() override;
class SettingsWidget;
QPointer<SettingsWidget> m_widget;
}; };
} // namespace Internal } // namespace Internal