added cahce tot settings class

This commit is contained in:
Andrei Yankovich 2021-11-18 15:01:53 +03:00
parent 165e61a86d
commit d7e11e644c
2 changed files with 15 additions and 2 deletions

View File

@ -30,7 +30,12 @@ ISettings *ISettings::instance(){
}
QVariant ISettings::getValue(const QString &key, const QVariant &def) {
return getValueImplementation(key, def);
if (!_cache.contains(key)) {
_cache[key] = getValueImplementation(key, def);
}
return _cache.value(key, def);
}
QString ISettings::getStrValue(const QString &key, const QString &def) {
@ -38,11 +43,16 @@ QString ISettings::getStrValue(const QString &key, const QString &def) {
}
void ISettings::sync() {
for (auto it = _cache.begin(); it != _cache.end(); ++it) {
setValueImplementation(it.key(), it.value());
}
return syncImplementation();
}
void ISettings::setValue(const QString key, const QVariant &value) {
return setValueImplementation(key, value);
_cache[key] = value;
emit valueChanged(key, value);
emit valueStrChanged(key, value.toString());

View File

@ -153,6 +153,9 @@ protected:
private:
SettingsSaveMode _mode = SettingsSaveMode::Auto;
QHash<QString, QVariant> _cache;
static ISettings* _settings;
};
} ;