forked from qt-creator/qt-creator
Utils: simplify loading/saving grouped settings
Change-Id: I8e06fb301eab193137f3e77d841698b9f4881deb Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -2060,35 +2060,24 @@ void AspectContainer::toMap(QVariantMap &map) const
|
||||
aspect->toMap(map);
|
||||
}
|
||||
|
||||
void AspectContainer::readSettings(const QSettings *settings)
|
||||
void AspectContainer::readSettings(QSettings *settings)
|
||||
{
|
||||
if (d->m_settingsGroup.isEmpty()) {
|
||||
if (!d->m_settingsGroup.isEmpty())
|
||||
settings->beginGroup(d->m_settingsGroup);
|
||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||
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);
|
||||
});
|
||||
}
|
||||
if (!d->m_settingsGroup.isEmpty())
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void AspectContainer::writeSettings(QSettings *settings) const
|
||||
{
|
||||
if (d->m_settingsGroup.isEmpty()) {
|
||||
if (!d->m_settingsGroup.isEmpty())
|
||||
settings->beginGroup(d->m_settingsGroup);
|
||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||
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());
|
||||
});
|
||||
if (!d->m_settingsGroup.isEmpty())
|
||||
settings->endGroup();
|
||||
}
|
||||
}
|
||||
|
||||
void AspectContainer::setSettingsGroup(const QString &key)
|
||||
|
||||
@@ -520,7 +520,7 @@ public:
|
||||
void fromMap(const QVariantMap &map);
|
||||
void toMap(QVariantMap &map) const;
|
||||
|
||||
void readSettings(const QSettings *settings);
|
||||
void readSettings(QSettings *settings);
|
||||
void writeSettings(QSettings *settings) const;
|
||||
|
||||
void setSettingsGroup(const QString &key);
|
||||
|
||||
Reference in New Issue
Block a user