forked from qt-creator/qt-creator
Refactor Locator filter settings saving
Unify setting saving. Do not write settings that stay at the default, so defaults could change and take effect. For this we explicitly differentiate between default and user settings. Make QJsonDocument the basis for saving settings, because QDataStream cannot really handle structured data where parts could be missing. Write locator settings to a different settings group, so we do not destroy reading older settings from older Qt Creator versions. Task-number: QTCREATORBUG-24762 Change-Id: I5909e2d79313f6fc26159bb644fdfb43781b6c38 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -44,6 +44,12 @@ public:
|
||||
|
||||
void setValue(const QString &key, const QVariant &value);
|
||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||
|
||||
template<typename T>
|
||||
void setValueWithDefault(const QString &key, const T &val, const T &defaultValue);
|
||||
template<typename T>
|
||||
void setValueWithDefault(const QString &key, const T &val);
|
||||
|
||||
bool contains(const QString &key) const;
|
||||
void remove(const QString &key);
|
||||
|
||||
@@ -61,4 +67,22 @@ private:
|
||||
Internal::SettingsDatabasePrivate *d;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
void SettingsDatabase::setValueWithDefault(const QString &key, const T &val, const T &defaultValue)
|
||||
{
|
||||
if (val == defaultValue)
|
||||
remove(key);
|
||||
else
|
||||
setValue(key, QVariant::fromValue(val));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void SettingsDatabase::setValueWithDefault(const QString &key, const T &val)
|
||||
{
|
||||
if (val == T())
|
||||
remove(key);
|
||||
else
|
||||
setValue(key, QVariant::fromValue(val));
|
||||
}
|
||||
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user