QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
isettingsaccessor.h
Go to the documentation of this file.
1 #ifndef QTMVVM_ISETTINGSACCESSOR_H
2 #define QTMVVM_ISETTINGSACCESSOR_H
3 
4 #include <type_traits>
5 
6 #include <QtCore/qobject.h>
7 #include <QtCore/qstring.h>
8 #include <QtCore/qvariant.h>
9 
10 #include "QtMvvmCore/qtmvvmcore_global.h"
11 
12 namespace QtMvvm {
13 
15 class Q_MVVMCORE_EXPORT ISettingsAccessor : public QObject
16 {
17  Q_OBJECT
18  Q_DISABLE_COPY(ISettingsAccessor)
19 
20 public:
21  // Set the default accessor type to be used by generated settings if none was specified
22  template <typename T>
23  static void setDefaultAccessor();
25  static void setDefaultAccessor(int typeId);
26 
28  static ISettingsAccessor *createDefaultAccessor(QObject *parent = nullptr);
29 
31  ISettingsAccessor(QObject *parent = nullptr);
32 
34  virtual bool contains(const QString &key) const = 0;
36  virtual QVariant load(const QString &key, const QVariant &defaultValue = {}) const = 0;
38  virtual void save(const QString &key, const QVariant &value) = 0;
40  virtual void remove(const QString &key) = 0;
41 
42 public Q_SLOTS:
44  virtual void sync() = 0;
45 
46 Q_SIGNALS:
48  void entryChanged(const QString &key, const QVariant &value);
50  void entryRemoved(const QString &key);
51 
52 private:
53  static int _DefaultAccessorType;
54 };
55 
56 template<typename T>
58 {
59  static_assert(std::is_base_of<T, ISettingsAccessor>::value, "T must implement the QtMvvm::ISettingsAccessor interface");
60  setDefaultAccessor(qMetaTypeId<T*>());
61 }
62 
63 }
64 
66 #define QtMvvm_ISettingsAccessorIID "de.skycoder42.qtmvvm.core.ISettingsAccessor"
68 Q_DECLARE_METATYPE(QtMvvm::ISettingsAccessor*)
69 
70 #endif // QTMVVM_ISETTINGSACCESSOR_H
An interface to provide a generic way to access settings of any origin.
#define QtMvvm_ISettingsAccessorIID
The IID of the QtMvvm::IPresenter class.
The primary namespace of the QtMvvm library.