mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 18:50:00 +02:00
Got rid of SettingHandle::type
This commit is contained in:
parent
23bab601c5
commit
4f2fa227b2
2 changed files with 11 additions and 20 deletions
|
@ -12,10 +12,14 @@
|
||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
namespace SettingHandles {
|
||||||
|
|
||||||
QVariant SettingsBridge::getFromSettings(const QString& key, const QVariant& defaultValue) {
|
QVariant SettingsBridge::getFromSettings(const QString& key, const QVariant& defaultValue) {
|
||||||
return QSettings().value(key, defaultValue);
|
return QSettings().value(key, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsBridge::setInSettings(const QString& key, const QVariant& value) {
|
void SettingsBridge::setInSettings(const QString& key, const QVariant& value) {
|
||||||
QSettings().setValue(key, value);
|
QSettings().setValue(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,6 +21,8 @@ class Settings : public QSettings {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
namespace SettingHandles {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class SettingHandle {
|
class SettingHandle {
|
||||||
public:
|
public:
|
||||||
|
@ -33,8 +35,6 @@ public:
|
||||||
void set(const T& value) const;
|
void set(const T& value) const;
|
||||||
void reset() const;
|
void reset() const;
|
||||||
|
|
||||||
static const QVariant::Type type;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QString _key;
|
const QString _key;
|
||||||
const QVariant _defaultValue;
|
const QVariant _defaultValue;
|
||||||
|
@ -48,25 +48,15 @@ private:
|
||||||
template<typename T>
|
template<typename T>
|
||||||
friend class SettingHandle;
|
friend class SettingHandle;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specialize template here for types used in Setting
|
|
||||||
template<typename T> const QVariant::Type SettingHandle<T>::type = QVariant::Invalid;
|
|
||||||
template<> const QVariant::Type SettingHandle<int>::type = QVariant::Int;
|
|
||||||
template<> const QVariant::Type SettingHandle<bool>::type = QVariant::Bool;
|
|
||||||
template<> const QVariant::Type SettingHandle<float>::type = QVariant::Double;
|
|
||||||
template<> const QVariant::Type SettingHandle<double>::type = QVariant::Double;
|
|
||||||
template<> const QVariant::Type SettingHandle<QString>::type = QVariant::String;
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
SettingHandle<T>::SettingHandle(const QString& key, const T& defaultValue) : _key(key), _defaultValue(defaultValue) {
|
SettingHandle<T>::SettingHandle(const QString& key, const T& defaultValue) : _key(key), _defaultValue(defaultValue) {
|
||||||
// Will fire if template not specialized for that type below
|
|
||||||
Q_STATIC_ASSERT_X(SettingHandle<T>::type != QVariant::Invalid, "SettingHandle: Invalid type");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T SettingHandle<T>::get() const {
|
T SettingHandle<T>::get() const {
|
||||||
QVariant variant = SettingsBridge::getFromSettings(_key, _defaultValue);
|
QVariant variant = SettingsBridge::getFromSettings(_key, _defaultValue);
|
||||||
if (variant.type() == type) {
|
if (variant.canConvert<T>()) {
|
||||||
return variant.value<T>();
|
return variant.value<T>();
|
||||||
}
|
}
|
||||||
return _defaultValue.value<T>();
|
return _defaultValue.value<T>();
|
||||||
|
@ -74,8 +64,8 @@ T SettingHandle<T>::get() const {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T SettingHandle<T>::get(const T& other) const {
|
T SettingHandle<T>::get(const T& other) const {
|
||||||
QVariant variant = SettingsBridge::getFromSettings(_key, _defaultValue);
|
QVariant variant = SettingsBridge::getFromSettings(_key, QVariant(other));
|
||||||
if (variant.type() == type) {
|
if (variant.canConvert<T>()) {
|
||||||
return variant.value<T>();
|
return variant.value<T>();
|
||||||
}
|
}
|
||||||
return other;
|
return other;
|
||||||
|
@ -95,10 +85,7 @@ template <typename T> inline
|
||||||
void SettingHandle<T>::reset() const {
|
void SettingHandle<T>::reset() const {
|
||||||
setInSettings(_key, _defaultValue);
|
setInSettings(_key, _defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Put applicationwide settings here
|
|
||||||
namespace SettingHandles {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // hifi_Settings_h
|
#endif // hifi_Settings_h
|
Loading…
Reference in a new issue