mirror of
https://github.com/lubosz/overte.git
synced 2025-04-24 16:43:33 +02:00
make UNSET_VALUE still work while still returning and empty string value for undefined keys
This commit is contained in:
parent
2ac0a0d343
commit
45c21ca523
3 changed files with 11 additions and 5 deletions
|
@ -89,7 +89,11 @@ void Settings::setValue(const QString& name, const QVariant& value) {
|
|||
}
|
||||
|
||||
QVariant Settings::value(const QString& name, const QVariant& defaultValue) const {
|
||||
return _manager->value(name, defaultValue);
|
||||
QVariant result = _manager->value(name, defaultValue);
|
||||
if (result == _manager->unsetValue()) {
|
||||
return QVariant(QString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ namespace Setting {
|
|||
const auto& key = handle->getKey();
|
||||
withWriteLock([&] {
|
||||
QVariant loadedValue;
|
||||
if (_pendingChanges.contains(key)) {
|
||||
if (_pendingChanges.contains(key) && _pendingChanges[key] != UNSET_VALUE) {
|
||||
loadedValue = _pendingChanges[key];
|
||||
} else {
|
||||
loadedValue = value(key);
|
||||
|
@ -70,10 +70,11 @@ namespace Setting {
|
|||
QVariant handleValue = UNSET_VALUE;
|
||||
if (handle->isSet()) {
|
||||
handleValue = handle->getVariant();
|
||||
withWriteLock([&] {
|
||||
_pendingChanges[key] = handleValue;
|
||||
});
|
||||
}
|
||||
|
||||
withWriteLock([&] {
|
||||
_pendingChanges[key] = handleValue;
|
||||
});
|
||||
}
|
||||
|
||||
static const int SAVE_INTERVAL_MSEC = 5 * 1000; // 5 sec
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace Setting {
|
|||
|
||||
public:
|
||||
void customDeleter() override;
|
||||
QVariant unsetValue() { return UNSET_VALUE; }
|
||||
|
||||
protected:
|
||||
~Manager();
|
||||
|
|
Loading…
Reference in a new issue