From c45f6501f501a65f753604bfd2341035ae12fd30 Mon Sep 17 00:00:00 2001 From: ConfuSomu Date: Wed, 16 Aug 2023 12:49:23 -0400 Subject: Make quick_read_setting() a templated method This allows terser usage and removes the need for manually invoking QVariant's .value() method. --- src/settings_interface.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/settings_interface.h') 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 + 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 +const T SettingsInterface::quick_read_setting(const QString &key) { + static SettingsInterface settings; + return settings.read_setting(key).value(); +} -- cgit v1.2.3-54-g00ecf