mirror of
https://github.com/QuasarApp/QuasarAppLib.git
synced 2025-04-26 09:44:38 +00:00
fix settings (stil has a bug with boolean variables )
This commit is contained in:
parent
ea4f1cda31
commit
093ea662ee
@ -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;
|
||||
|
@ -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.
|
||||
|
38
settings.cpp
38
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user