forked from qt-creator/qt-creator
Utils/VcsBase: Move ability to specify group settings keys to base
Merge it with the read/writeSettings implementation that was already there. Change-Id: I25dfbdf6fd1cf122b17f89eae82cb2598d8470c8 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -2019,6 +2019,7 @@ class AspectContainerPrivate
|
|||||||
public:
|
public:
|
||||||
QList<BaseAspect *> m_items; // Not owned
|
QList<BaseAspect *> m_items; // Not owned
|
||||||
bool m_autoApply = true;
|
bool m_autoApply = true;
|
||||||
|
QString m_settingsGroup;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // Internal
|
} // Internal
|
||||||
@@ -2061,14 +2062,38 @@ void AspectContainer::toMap(QVariantMap &map) const
|
|||||||
|
|
||||||
void AspectContainer::readSettings(const QSettings *settings)
|
void AspectContainer::readSettings(const QSettings *settings)
|
||||||
{
|
{
|
||||||
|
if (d->m_settingsGroup.isEmpty()) {
|
||||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
aspect->readSettings(settings);
|
aspect->readSettings(settings);
|
||||||
|
} else {
|
||||||
|
const QString keyRoot = d->m_settingsGroup + '/';
|
||||||
|
forEachAspect([settings, keyRoot](BaseAspect *aspect) {
|
||||||
|
QString key = aspect->settingsKey();
|
||||||
|
const QVariant value = settings->value(keyRoot + key, aspect->defaultValue());
|
||||||
|
aspect->setValue(value);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::writeSettings(QSettings *settings) const
|
void AspectContainer::writeSettings(QSettings *settings) const
|
||||||
{
|
{
|
||||||
|
if (d->m_settingsGroup.isEmpty()) {
|
||||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
aspect->writeSettings(settings);
|
aspect->writeSettings(settings);
|
||||||
|
} else {
|
||||||
|
settings->remove(d->m_settingsGroup);
|
||||||
|
settings->beginGroup(d->m_settingsGroup);
|
||||||
|
forEachAspect([settings](BaseAspect *aspect) {
|
||||||
|
QtcSettings::setValueWithDefault(settings, aspect->settingsKey(),
|
||||||
|
aspect->value(), aspect->defaultValue());
|
||||||
|
});
|
||||||
|
settings->endGroup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AspectContainer::setSettingsGroup(const QString &key)
|
||||||
|
{
|
||||||
|
d->m_settingsGroup = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::apply()
|
void AspectContainer::apply()
|
||||||
|
|||||||
@@ -523,6 +523,8 @@ public:
|
|||||||
void readSettings(const QSettings *settings);
|
void readSettings(const QSettings *settings);
|
||||||
void writeSettings(QSettings *settings) const;
|
void writeSettings(QSettings *settings) const;
|
||||||
|
|
||||||
|
void setSettingsGroup(const QString &key);
|
||||||
|
|
||||||
void apply();
|
void apply();
|
||||||
void cancel();
|
void cancel();
|
||||||
void finish();
|
void finish();
|
||||||
|
|||||||
@@ -80,32 +80,4 @@ QStringList VcsBaseSettings::searchPathList() const
|
|||||||
return path.value().split(HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts);
|
return path.value().split(HostOsInfo::pathListSeparator(), Qt::SkipEmptyParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseSettings::setSettingsGroup(const QString &key)
|
|
||||||
{
|
|
||||||
m_settingsGroup = key;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseSettings::writeSettings(QSettings *settings) const
|
|
||||||
{
|
|
||||||
QTC_ASSERT(!m_settingsGroup.isEmpty(), return);
|
|
||||||
|
|
||||||
settings->remove(m_settingsGroup);
|
|
||||||
settings->beginGroup(m_settingsGroup);
|
|
||||||
forEachAspect([settings](BaseAspect *aspect) {
|
|
||||||
QtcSettings::setValueWithDefault(settings, aspect->settingsKey(),
|
|
||||||
aspect->value(), aspect->defaultValue());
|
|
||||||
});
|
|
||||||
settings->endGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseSettings::readSettings(const QSettings *settings)
|
|
||||||
{
|
|
||||||
const QString keyRoot = m_settingsGroup + '/';
|
|
||||||
forEachAspect([settings, keyRoot](BaseAspect *aspect) {
|
|
||||||
QString key = aspect->settingsKey();
|
|
||||||
const QVariant value = settings->value(keyRoot + key, aspect->defaultValue());
|
|
||||||
aspect->setValue(value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace VcsBase
|
} // namespace VcsBase
|
||||||
|
|||||||
@@ -48,11 +48,6 @@ public:
|
|||||||
|
|
||||||
QStringList searchPathList() const;
|
QStringList searchPathList() const;
|
||||||
|
|
||||||
void writeSettings(QSettings *settings) const;
|
|
||||||
void readSettings(const QSettings *settings);
|
|
||||||
|
|
||||||
void setSettingsGroup(const QString &key);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_settingsGroup;
|
QString m_settingsGroup;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user