diff options
author | ConfuSomu | 2023-08-16 12:49:23 -0400 |
---|---|---|
committer | ConfuSomu | 2023-08-16 14:38:17 -0400 |
commit | c45f6501f501a65f753604bfd2341035ae12fd30 (patch) | |
tree | 3bb37bb6adae850ddb91baffa01a957576615e41 /src/settings_interface.h | |
parent | 52add29e0a380618a358fdbaddb612703d36eb90 (diff) | |
download | ActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.tar ActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.tar.gz ActorViewer-c45f6501f501a65f753604bfd2341035ae12fd30.zip |
Make quick_read_setting() a templated method
This allows terser usage and removes the need for manually invoking
QVariant's .value<T>() method.
Diffstat (limited to 'src/settings_interface.h')
-rw-r--r-- | src/settings_interface.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/settings_interface.h b/src/settings_interface.h index e290125..09c309b 100644 --- a/src/settings_interface.h +++ b/src/settings_interface.h @@ -16,7 +16,8 @@ class SettingsInterface { public: ~SettingsInterface(); const QVariant read_setting(const QString &key); - static const QVariant quick_read_setting(const QString &key); + template<typename T> + static const T quick_read_setting(const QString &key); void write_setting(const QString &key, const QVariant &value); void clear_setting(const QString &key); void clear_all(); @@ -33,3 +34,10 @@ private: // List of keys to remove from the QSettings QStringList must_clear; }; + +// Template code implementations have to be "seen" at the same time as the declaration +template<typename T> +const T SettingsInterface::quick_read_setting(const QString &key) { + static SettingsInterface settings; + return settings.read_setting(key).value<T>(); +} |