diff --git a/isettings.cpp b/isettings.cpp index 123bb84..ea72120 100644 --- a/isettings.cpp +++ b/isettings.cpp @@ -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())); } } diff --git a/settings.cpp b/settings.cpp index 65cc2af..f9294b5 100644 --- a/settings.cpp +++ b/settings.cpp @@ -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); } diff --git a/settings.h b/settings.h index 0ab3384..8d90cdd 100644 --- a/settings.h +++ b/settings.h @@ -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;