From 093ea662ee6402d81caea48def18f21c55d29fc4 Mon Sep 17 00:00:00 2001 From: EndrII <EndrIIMail@gmail.com> Date: Fri, 24 Jun 2022 17:36:22 +0300 Subject: [PATCH] fix settings (stil has a bug with boolean variables ) --- isettings.cpp | 25 ++++++++++++------------- isettings.h | 2 +- settings.cpp | 38 +++----------------------------------- 3 files changed, 16 insertions(+), 49 deletions(-) diff --git a/isettings.cpp b/isettings.cpp index ea72120..b3e7679 100644 --- a/isettings.cpp +++ b/isettings.cpp @@ -8,6 +8,7 @@ #include "isettings.h" #include <QSettings> #include <QCoreApplication> +#include "qaglobalutils.h"" namespace QuasarAppUtils { @@ -46,23 +47,19 @@ ISettings *ISettings::instance(){ } QVariant ISettings::getValue(const QString &key, const QVariant &def) { + debug_assert(key.size(), "You can't use the empty key value!"); if (!_cache.contains(key)) { + + QVariant defVal = def; + if (defVal.isNull()) { + defVal = settingsMap().value(key); + } + _cache[key] = getValueImplementation(key, def); } - QVariant defVal = def; - if (defVal.isNull()) { - defVal = settingsMap().value(key); - } - - auto result = _cache.value(key, defVal); - - if (result.isNull()) { - return defVal; - } - - return result; + return _cache[key]; } QString ISettings::getStrValue(const QString &key, const QString &def) { @@ -98,7 +95,9 @@ void ISettings::forceReloadCache() { } } -void ISettings::setValue(const QString key, const QVariant &value) { +void ISettings::setValue(const QString &key, const QVariant &value) { + + debug_assert(key.size(), "You can't use the empty key value!"); if (_cache.contains(key) && _cache.value(key) == value) { return; diff --git a/isettings.h b/isettings.h index cedcb52..f3f1207 100644 --- a/isettings.h +++ b/isettings.h @@ -127,7 +127,7 @@ public slots: * @param key This is name of the changed setting. * @param value This is a new value of the setting */ - void setValue(const QString key, const QVariant& value); + void setValue(const QString &key, const QVariant& value); /** * @brief setStrValue This is some as setValue but working with the QString type. diff --git a/settings.cpp b/settings.cpp index f9294b5..5e461c5 100644 --- a/settings.cpp +++ b/settings.cpp @@ -9,6 +9,7 @@ #include "settings.h" #include <QSettings> #include <QCoreApplication> +#include <QDebug> namespace QuasarAppUtils { @@ -23,7 +24,7 @@ Settings::Settings() { company = "QuasarApp"; } - _settings = new QSettings(QSettings::IniFormat, QSettings::Scope::UserScope, company, name); + _settings = new QSettings(QSettings::NativeFormat, QSettings::Scope::UserScope, company, name); } void Settings::syncImplementation() { @@ -31,43 +32,10 @@ void Settings::syncImplementation() { } QVariant Settings::getValueImplementation(const QString &key, const QVariant &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); - - } - + 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); }