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);
|
aspect->toMap(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::readSettings(const QSettings *settings)
|
void AspectContainer::readSettings(QSettings *settings)
|
||||||
{
|
{
|
||||||
if (d->m_settingsGroup.isEmpty()) {
|
if (!d->m_settingsGroup.isEmpty())
|
||||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
settings->beginGroup(d->m_settingsGroup);
|
||||||
aspect->readSettings(settings);
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
} else {
|
aspect->readSettings(settings);
|
||||||
const QString keyRoot = d->m_settingsGroup + '/';
|
if (!d->m_settingsGroup.isEmpty())
|
||||||
forEachAspect([settings, keyRoot](BaseAspect *aspect) {
|
settings->endGroup();
|
||||||
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()) {
|
if (!d->m_settingsGroup.isEmpty())
|
||||||
for (BaseAspect *aspect : qAsConst(d->m_items))
|
|
||||||
aspect->writeSettings(settings);
|
|
||||||
} else {
|
|
||||||
settings->remove(d->m_settingsGroup);
|
|
||||||
settings->beginGroup(d->m_settingsGroup);
|
settings->beginGroup(d->m_settingsGroup);
|
||||||
forEachAspect([settings](BaseAspect *aspect) {
|
for (BaseAspect *aspect : qAsConst(d->m_items))
|
||||||
QtcSettings::setValueWithDefault(settings, aspect->settingsKey(),
|
aspect->writeSettings(settings);
|
||||||
aspect->value(), aspect->defaultValue());
|
if (!d->m_settingsGroup.isEmpty())
|
||||||
});
|
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AspectContainer::setSettingsGroup(const QString &key)
|
void AspectContainer::setSettingsGroup(const QString &key)
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ public:
|
|||||||
void fromMap(const QVariantMap &map);
|
void fromMap(const QVariantMap &map);
|
||||||
void toMap(QVariantMap &map) const;
|
void toMap(QVariantMap &map) const;
|
||||||
|
|
||||||
void readSettings(const QSettings *settings);
|
void readSettings(QSettings *settings);
|
||||||
void writeSettings(QSettings *settings) const;
|
void writeSettings(QSettings *settings) const;
|
||||||
|
|
||||||
void setSettingsGroup(const QString &key);
|
void setSettingsGroup(const QString &key);
|
||||||
|
|||||||
Reference in New Issue
Block a user