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