QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
settingsviewmodel.h
1 #ifndef QTMVVM_SETTINGSVIEWMODEL_H
2 #define QTMVVM_SETTINGSVIEWMODEL_H
3 
4 #include <QtCore/qsettings.h>
5 #include <QtCore/qscopedpointer.h>
6 
7 #include <QtMvvmCore/viewmodel.h>
8 #include <QtMvvmCore/message.h>
9 
10 #include "QtMvvmCore/qtmvvmcore_global.h"
11 #include "QtMvvmCore/settingssetup.h"
12 #include "QtMvvmCore/isettingsaccessor.h"
13 
14 namespace QtMvvm {
15 
16 class SettingsViewModelPrivate;
18 class Q_MVVMCORE_EXPORT SettingsViewModel : public ViewModel
19 {
20  Q_OBJECT
21 
23  Q_PROPERTY(QtMvvm::ISettingsAccessor* accessor READ accessor WRITE setAccessor NOTIFY accessorChanged REVISION 1)
24 
25 
26  Q_PROPERTY(bool canRestoreDefaults READ canRestoreDefaults CONSTANT)
28  Q_PROPERTY(QtMvvm::MessageConfig restoreConfig READ restoreConfig CONSTANT)
29 
31  Q_PROPERTY(QtMvvm::ISettingsSetupLoader* settingsSetupLoader READ settingsSetupLoader WRITE setSettingsSetupLoader NOTIFY settingsSetupLoaderChanged)
32  QTMVVM_INJECT(QtMvvm::ISettingsSetupLoader*, settingsSetupLoader)
33 
34 public:
36  static const QString paramAccessor;
38  static const QString paramSettings;
40  static const QString paramSetupFile;
41 
43  static QVariantHash showParams(ISettingsAccessor *accessor, const QString &setupFile = {});
45  static QVariantHash showParams(QSettings *settings, const QString &setupFile = {});
46 
48  Q_INVOKABLE explicit SettingsViewModel(QObject *parent = nullptr);
49  ~SettingsViewModel() override;
50 
52  QtMvvm::ISettingsAccessor* accessor() const;
54  virtual bool canRestoreDefaults() const;
56  virtual QtMvvm::MessageConfig restoreConfig() const;
58  ISettingsSetupLoader* settingsSetupLoader() const;
59 
61  SettingsElements::Setup loadSetup(const QString &frontend) const;
62 
64  QSettings *settings() const;
65 
67  Q_INVOKABLE virtual QVariant loadValue(const QString &key, const QVariant &defaultValue = {}) const;
69  Q_INVOKABLE virtual void saveValue(const QString &key, const QVariant &value);
71  Q_INVOKABLE virtual void resetValue(const QString &key);
73  QTMVVM_REVISION_1 Q_INVOKABLE void resetAll(const SettingsElements::Setup &setup);
74 
75 public Q_SLOTS:
77  virtual void callAction(const QString &key, const QVariantMap &parameters);
78 
80  QTMVVM_REVISION_1 void setAccessor(QtMvvm::ISettingsAccessor* accessor);
82  void setSettingsSetupLoader(QtMvvm::ISettingsSetupLoader* settingsSetupLoader);
83 
84 Q_SIGNALS:
86  QTMVVM_REVISION_1 void accessorChanged(QtMvvm::ISettingsAccessor* accessor);
88  void settingsSetupLoaderChanged(QtMvvm::ISettingsSetupLoader* settingsSetupLoader, QPrivateSignal);
89 
91  void beginLoadSetup();
92 
94  QTMVVM_REVISION_1 void valueChanged(const QString &key);
96  QTMVVM_REVISION_1 void resetAccepted(QPrivateSignal);
97 
98 protected:
99  void onInit(const QVariantHash &params) override;
100 
101 private:
103 };
104 
105 }
106 
107 #endif // QTMVVM_SETTINGSVIEWMODEL_H
A ViewModel for a generic settings dialog based of an XML settings file.
An interface to provide a generic way to access settings of any origin.
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:20
#define QTMVVM_INJECT(classType, name)
Mark a property for injection.
The base class for all viewmodels.
Definition: viewmodel.h:21
An interface for a generic settings setup loader.
The primary namespace of the QtMvvm library.