mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-26 17:54:40 +00:00
fix default settings implementation
All checks were successful
buildbot/IOSCMakeBuilder Build finished.
All checks were successful
buildbot/IOSCMakeBuilder Build finished.
This commit is contained in:
parent
99473b2167
commit
ea4f1cda31
@ -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()));
|
||||
}
|
||||
}
|
||||
|
35
settings.cpp
35
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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user