fix default settings implementation
All checks were successful
buildbot/IOSCMakeBuilder Build finished.

This commit is contained in:
Andrei Yankovich 2022-06-24 00:29:23 +03:00
parent 99473b2167
commit ea4f1cda31
3 changed files with 41 additions and 6 deletions

View File

@ -75,9 +75,10 @@ QString ISettings::getStrValue(const QString &key, const QString &def) {
}
void ISettings::resetToDefault() {
auto &defaultConfig = settingsMap();
for (auto it = _defaultConfig->begin(); it != _defaultConfig->end(); ++it) {
setValue(it.key(), settingsMap().value(it.key()));
for (auto it = defaultConfig.begin(); it != defaultConfig.end(); ++it) {
setValue(it.key(), defaultConfig.value(it.key()));
}
}
@ -90,7 +91,9 @@ void ISettings::sync() {
}
void ISettings::forceReloadCache() {
for (auto it = _cache.begin(); it != _cache.end(); ++it) {
auto &defaultConfig = settingsMap();
for (auto it = defaultConfig.begin(); it != defaultConfig.end(); ++it) {
setValue(it.key(), getValueImplementation(it.key(), it.value()));
}
}

View File

@ -31,10 +31,43 @@ void Settings::syncImplementation() {
}
QVariant Settings::getValueImplementation(const QString &key, const QVariant &def) {
return _settings->value(key, def);
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
switch (def.type()) {
#else
switch (def.type()) {
#endif
case QVariant::Type::Bool: {
return _settings->value(key, def).toBool();
}
case QVariant::Type::ULongLong: {
return _settings->value(key, def).toULongLong();
}
case QVariant::Type::LongLong: {
return _settings->value(key, def).toLongLong();
}
case QVariant::Type::UInt: {
return _settings->value(key, def).toUInt();
}
case QVariant::Type::Int: {
return _settings->value(key, def).toInt();
}
default:
return _settings->value(key, def);
}
}
void Settings::setValueImplementation(const QString key, const QVariant &value) {
if (value.type() == QVariant::Bool) {
_settings->setValue(key, value.toInt());
}
return _settings->setValue(key, value);
}

View File

@ -34,12 +34,11 @@ public:
// ISettings interface
protected:
void syncImplementation();
QVariant getValueImplementation(const QString &key, const QVariant &def);
void setValueImplementation(const QString key, const QVariant &value);
void setGroup(const QString&);
private:
QSettings *_settings = nullptr;