X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsettings.h;h=64bc46209286c020cf5913934f990c14d1d5b10f;hp=48dfafddc521c6d0c88280c67ef0d0bd34d050bd;hb=2c8434f74c68194d56f2084f637419123e61d18b;hpb=61f33c7895e324f6e95034d86897ad2e963653f1 diff --git a/src/common/settings.h b/src/common/settings.h index 48dfafdd..64bc4620 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -23,6 +23,7 @@ #include "common-export.h" #include +#include #include #include @@ -51,11 +52,22 @@ public: enum Mode { Default, Custom }; public: - //! Call the given slot on change of the given key - void notify(const QString &key, QObject *receiver, const char *slot) const; + //! Calls the given slot on change of the given key + template + void notify(const QString &key, const Receiver *receiver, Slot slot) const + { + static_assert(!std::is_same::value, "Old-style slots not supported"); + QObject::connect(notifier(normalizedKey(_group, keyForNotify(key))), &SettingsChangeNotifier::valueChanged, receiver, slot); + } //! Sets up notification and calls the given slot to set the initial value - void initAndNotify(const QString &key, QObject *receiver, const char *slot, const QVariant &defaultValue = QVariant()) const; + template + void initAndNotify(const QString &key, const Receiver *receiver, Slot slot, const QVariant &defaultValue = {}) const + { + notify(key, receiver, std::move(slot)); + auto notifyKey = keyForNotify(key); + emit notifier(normalizedKey(_group, notifyKey))->valueChanged(localValue(notifyKey, defaultValue)); + } /** * Get the major configuration version @@ -107,6 +119,16 @@ protected: void setGroup(QString group); + /** + * Allows subclasses to transform the key given to notify(). + * + * Default implementation just returns the given key. + * + * @param key Key given to notify() + * @returns Key that should be used for notfication + */ + virtual QString keyForNotify(const QString &key) const; + virtual QStringList allLocalKeys() const; virtual QStringList localChildKeys(const QString &rootkey = QString()) const; virtual QStringList localChildGroups(const QString &rootkey = QString()) const;