From: APTX Date: Thu, 25 Apr 2013 14:18:37 +0000 (+0200) Subject: Make the template version of Settings::get more predictable. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=a40ef7fa01c5aa43530632ff83739f15e2ea3a2e;p=localmylist.git Make the template version of Settings::get more predictable. --- diff --git a/localmylist/settings.h b/localmylist/settings.h index c26cfcf..b1017ec 100644 --- a/localmylist/settings.h +++ b/localmylist/settings.h @@ -16,8 +16,16 @@ public: explicit Settings(Database *db = 0, QObject *parent = 0); Database *database() const; void setDatabase(Database *db); - - template void get(const QString &key, T& value) const { value = get(key).value();} + + template T get(const QString &key, const T &defaultValue) const + { + QVariant value = get(key); + + if (!value.isValid() || !value.canConvert()) + return defaultValue; + + return value.value(); + } signals: void settingsChanged(); @@ -28,7 +36,7 @@ public slots: void commit(); void rollback(); - + void settingsChangedInDatabase(); private: