#pragma once #include #include #include namespace AppSettingsTypes { enum Timezone {LOCALTIME = 0, UTC}; enum InstanceType {MASTODON = 0}; } // Declare metatypes for use with QVariant Q_DECLARE_METATYPE(AppSettingsTypes::Timezone); Q_DECLARE_METATYPE(AppSettingsTypes::InstanceType); class SettingsInterface { public: ~SettingsInterface(); const QVariant 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(); bool commit(); bool is_default(const QString &key); bool is_uncommited(const QString &key); private: QSettings qt_settings; QHash* modified = nullptr; // Optimization to commit a clear_all() faster bool must_clear_all = false; // 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(); }