forked from qt-creator/qt-creator
Utils: Base AspectContainer on BaseAspect
Change-Id: I78b11727af6e465da5731ba36bbae476d11d11ee Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -655,7 +655,7 @@ int main(int argc, char **argv)
|
|||||||
PluginManager::setInstallSettings(installSettings);
|
PluginManager::setInstallSettings(installSettings);
|
||||||
PluginManager::setSettings(settings);
|
PluginManager::setSettings(settings);
|
||||||
|
|
||||||
Utils::BaseAspect::setSettings(settings);
|
Utils::BaseAspect::setQtcSettings(settings);
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
Utils::AppInfo info;
|
Utils::AppInfo info;
|
||||||
|
@@ -37,12 +37,12 @@ namespace Utils {
|
|||||||
|
|
||||||
static QSettings *theSettings = nullptr;
|
static QSettings *theSettings = nullptr;
|
||||||
|
|
||||||
void BaseAspect::setSettings(QSettings *settings)
|
void BaseAspect::setQtcSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
theSettings = settings;
|
theSettings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings *BaseAspect::settings()
|
QSettings *BaseAspect::qtcSettings()
|
||||||
{
|
{
|
||||||
return theSettings;
|
return theSettings;
|
||||||
}
|
}
|
||||||
@@ -591,7 +591,8 @@ void BaseAspect::readSettings()
|
|||||||
{
|
{
|
||||||
if (settingsKey().isEmpty())
|
if (settingsKey().isEmpty())
|
||||||
return;
|
return;
|
||||||
const QVariant val = settings()->value(settingsKey());
|
QTC_ASSERT(theSettings, return);
|
||||||
|
const QVariant val = theSettings->value(settingsKey());
|
||||||
setVariantValue(val.isValid() ? fromSettingsValue(val) : defaultVariantValue(), BeQuiet);
|
setVariantValue(val.isValid() ? fromSettingsValue(val) : defaultVariantValue(), BeQuiet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -599,7 +600,8 @@ void BaseAspect::writeSettings() const
|
|||||||
{
|
{
|
||||||
if (settingsKey().isEmpty())
|
if (settingsKey().isEmpty())
|
||||||
return;
|
return;
|
||||||
QtcSettings::setValueWithDefault(settings(),
|
QTC_ASSERT(theSettings, return);
|
||||||
|
QtcSettings::setValueWithDefault(theSettings,
|
||||||
settingsKey(),
|
settingsKey(),
|
||||||
toSettingsValue(variantValue()),
|
toSettingsValue(variantValue()),
|
||||||
toSettingsValue(defaultVariantValue()));
|
toSettingsValue(defaultVariantValue()));
|
||||||
@@ -2562,7 +2564,7 @@ void AspectContainer::setAutoApply(bool on)
|
|||||||
aspect->setAutoApply(on);
|
aspect->setAutoApply(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AspectContainer::isDirty() const
|
bool AspectContainer::isDirty()
|
||||||
{
|
{
|
||||||
for (BaseAspect *aspect : std::as_const(d->m_items)) {
|
for (BaseAspect *aspect : std::as_const(d->m_items)) {
|
||||||
if (aspect->isDirty())
|
if (aspect->isDirty())
|
||||||
|
@@ -176,8 +176,8 @@ public:
|
|||||||
|
|
||||||
Data::Ptr extractData() const;
|
Data::Ptr extractData() const;
|
||||||
|
|
||||||
static void setSettings(QSettings *settings);
|
static void setQtcSettings(QSettings *settings);
|
||||||
static QSettings *settings();
|
static QSettings *qtcSettings();
|
||||||
|
|
||||||
// This is expensive. Do not use without good reason
|
// This is expensive. Do not use without good reason
|
||||||
void writeToSettingsImmediatly() const;
|
void writeToSettingsImmediatly() const;
|
||||||
@@ -809,7 +809,7 @@ private:
|
|||||||
const int m_groupCount;
|
const int m_groupCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT AspectContainer : public QObject
|
class QTCREATOR_UTILS_EXPORT AspectContainer : public BaseAspect
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@@ -823,25 +823,25 @@ public:
|
|||||||
void registerAspect(BaseAspect *aspect, bool takeOwnership = false);
|
void registerAspect(BaseAspect *aspect, bool takeOwnership = false);
|
||||||
void registerAspects(const AspectContainer &aspects);
|
void registerAspects(const AspectContainer &aspects);
|
||||||
|
|
||||||
void fromMap(const QVariantMap &map);
|
void fromMap(const QVariantMap &map) override;
|
||||||
void toMap(QVariantMap &map) const;
|
void toMap(QVariantMap &map) const override;
|
||||||
|
|
||||||
void readSettings();
|
void readSettings() override;
|
||||||
void writeSettings() const;
|
void writeSettings() const override;
|
||||||
|
|
||||||
void setSettingsGroup(const QString &groupKey);
|
void setSettingsGroup(const QString &groupKey);
|
||||||
void setSettingsGroups(const QString &groupKey, const QString &subGroupKey);
|
void setSettingsGroups(const QString &groupKey, const QString &subGroupKey);
|
||||||
QStringList settingsGroups() const;
|
QStringList settingsGroups() const;
|
||||||
|
|
||||||
void apply();
|
void apply() override;
|
||||||
void cancel();
|
void cancel() override;
|
||||||
void finish();
|
void finish() override;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
bool equals(const AspectContainer &other) const;
|
bool equals(const AspectContainer &other) const;
|
||||||
void copyFrom(const AspectContainer &other);
|
void copyFrom(const AspectContainer &other);
|
||||||
void setAutoApply(bool on);
|
void setAutoApply(bool on);
|
||||||
bool isDirty() const;
|
bool isDirty() override;
|
||||||
|
|
||||||
template <typename T> T *aspect() const
|
template <typename T> T *aspect() const
|
||||||
{
|
{
|
||||||
|
@@ -109,7 +109,7 @@ void TestSettings::toSettings() const
|
|||||||
{
|
{
|
||||||
AspectContainer::writeSettings();
|
AspectContainer::writeSettings();
|
||||||
|
|
||||||
QSettings *s = Utils::BaseAspect::settings();
|
QSettings *s = Utils::BaseAspect::qtcSettings();
|
||||||
s->beginGroup(Constants::SETTINGSGROUP);
|
s->beginGroup(Constants::SETTINGSGROUP);
|
||||||
|
|
||||||
// store frameworks and their current active and grouping state
|
// store frameworks and their current active and grouping state
|
||||||
@@ -128,7 +128,7 @@ void TestSettings::fromSettings()
|
|||||||
{
|
{
|
||||||
AspectContainer::readSettings();
|
AspectContainer::readSettings();
|
||||||
|
|
||||||
QSettings *s = Utils::BaseAspect::settings();
|
QSettings *s = Utils::BaseAspect::qtcSettings();
|
||||||
s->beginGroup(Constants::SETTINGSGROUP);
|
s->beginGroup(Constants::SETTINGSGROUP);
|
||||||
|
|
||||||
// try to get settings for registered frameworks
|
// try to get settings for registered frameworks
|
||||||
|
@@ -176,7 +176,7 @@ void ClangToolsSettings::readSettings()
|
|||||||
writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClangToolsSettings::writeSettings()
|
void ClangToolsSettings::writeSettings() const
|
||||||
{
|
{
|
||||||
AspectContainer::writeSettings();
|
AspectContainer::writeSettings();
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ void ClangToolsSettings::writeSettings()
|
|||||||
|
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
|
|
||||||
emit changed();
|
emit const_cast<ClangToolsSettings *>(this)->changed(); // FIXME: This is the wrong place
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePath ClangToolsSettings::executable(ClangToolType tool) const
|
FilePath ClangToolsSettings::executable(ClangToolType tool) const
|
||||||
|
@@ -58,12 +58,11 @@ private:
|
|||||||
|
|
||||||
class ClangToolsSettings : public Utils::AspectContainer
|
class ClangToolsSettings : public Utils::AspectContainer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
ClangToolsSettings();
|
ClangToolsSettings();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static ClangToolsSettings *instance();
|
static ClangToolsSettings *instance();
|
||||||
void writeSettings();
|
void writeSettings() const override;
|
||||||
|
|
||||||
// Executables
|
// Executables
|
||||||
Utils::FilePathAspect clangTidyExecutable{this};
|
Utils::FilePathAspect clangTidyExecutable{this};
|
||||||
@@ -82,11 +81,8 @@ public:
|
|||||||
static VersionAndSuffix clangTidyVersion();
|
static VersionAndSuffix clangTidyVersion();
|
||||||
static QVersionNumber clazyVersion();
|
static QVersionNumber clazyVersion();
|
||||||
|
|
||||||
signals:
|
|
||||||
void changed();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void readSettings();
|
void readSettings() override;
|
||||||
|
|
||||||
// Diagnostic Configs
|
// Diagnostic Configs
|
||||||
CppEditor::ClangDiagnosticConfigs m_diagnosticConfigs;
|
CppEditor::ClangDiagnosticConfigs m_diagnosticConfigs;
|
||||||
|
@@ -491,7 +491,7 @@ const char sourcePathMappingTargetKeyC[] = "Target";
|
|||||||
void SourcePathMapAspect::writeSettings() const
|
void SourcePathMapAspect::writeSettings() const
|
||||||
{
|
{
|
||||||
const SourcePathMap sourcePathMap = value();
|
const SourcePathMap sourcePathMap = value();
|
||||||
QSettings *s = settings();
|
QSettings *s = qtcSettings();
|
||||||
s->beginWriteArray(sourcePathMappingArrayNameC);
|
s->beginWriteArray(sourcePathMappingArrayNameC);
|
||||||
if (!sourcePathMap.isEmpty()) {
|
if (!sourcePathMap.isEmpty()) {
|
||||||
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
||||||
@@ -510,7 +510,7 @@ void SourcePathMapAspect::writeSettings() const
|
|||||||
|
|
||||||
void SourcePathMapAspect::readSettings()
|
void SourcePathMapAspect::readSettings()
|
||||||
{
|
{
|
||||||
QSettings *s = settings();
|
QSettings *s = qtcSettings();
|
||||||
SourcePathMap sourcePathMap;
|
SourcePathMap sourcePathMap;
|
||||||
if (const int count = s->beginReadArray(sourcePathMappingArrayNameC)) {
|
if (const int count = s->beginReadArray(sourcePathMappingArrayNameC)) {
|
||||||
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
const QString sourcePathMappingSourceKey(sourcePathMappingSourceKeyC);
|
||||||
|
@@ -47,9 +47,9 @@ public:
|
|||||||
bool hasError() const { return m_hasError; }
|
bool hasError() const { return m_hasError; }
|
||||||
|
|
||||||
// Note: Make sure subclasses call the superclasses' fromMap() function!
|
// Note: Make sure subclasses call the superclasses' fromMap() function!
|
||||||
virtual void fromMap(const QVariantMap &map);
|
virtual void fromMap(const QVariantMap &map) override;
|
||||||
// Note: Make sure subclasses call the superclasses' toMap() function!
|
// Note: Make sure subclasses call the superclasses' toMap() function!
|
||||||
virtual void toMap(QVariantMap &map) const;
|
virtual void toMap(QVariantMap &map) const override;
|
||||||
|
|
||||||
Target *target() const;
|
Target *target() const;
|
||||||
Project *project() const;
|
Project *project() const;
|
||||||
|
Reference in New Issue
Block a user