make UNSET_VALUE still work while still returning and empty string value for undefined keys

This commit is contained in:
Seth Alves 2016-08-04 13:37:08 -07:00
parent 2ac0a0d343
commit 45c21ca523
3 changed files with 11 additions and 5 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -28,6 +28,7 @@ namespace Setting {
public:
void customDeleter() override;
QVariant unsetValue() { return UNSET_VALUE; }
protected:
~Manager();