QtMvvm  1.0.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 
13 namespace QtMvvm {
14 
15 class SettingsViewModelPrivate;
17 class Q_MVVMCORE_EXPORT SettingsViewModel : public ViewModel
18 {
19  Q_OBJECT
20 
22  Q_PROPERTY(bool canRestoreDefaults READ canRestoreDefaults CONSTANT)
24  Q_PROPERTY(QtMvvm::MessageConfig restoreConfig READ restoreConfig CONSTANT)
25 
27  Q_PROPERTY(QtMvvm::ISettingsSetupLoader* settingsSetupLoader READ settingsSetupLoader WRITE setSettingsSetupLoader NOTIFY settingsSetupLoaderChanged)
28  QTMVVM_INJECT(QtMvvm::ISettingsSetupLoader*, settingsSetupLoader)
29 
30 public:
32  static const QString paramSettings;
34  static const QString paramSetupFile;
35 
37  static QVariantHash showParams(QSettings *settings, const QString &setupFile = {});
38 
40  Q_INVOKABLE explicit SettingsViewModel(QObject *parent = nullptr);
42 
44  virtual bool canRestoreDefaults() const;
46  virtual QtMvvm::MessageConfig restoreConfig() const;
48  ISettingsSetupLoader* settingsSetupLoader() const;
49 
51  SettingsElements::Setup loadSetup(const QString &frontend) const;
52 
54  QSettings *settings() const;
55 
57  Q_INVOKABLE virtual QVariant loadValue(const QString &key, const QVariant &defaultValue = {}) const;
59  Q_INVOKABLE virtual void saveValue(const QString &key, const QVariant &value);
61  Q_INVOKABLE virtual void resetValue(const QString &key);
62 
63 public Q_SLOTS:
65  virtual void callAction(const QString &key, const QVariantMap &parameters);
66 
68  void setSettingsSetupLoader(QtMvvm::ISettingsSetupLoader* settingsSetupLoader);
69 
70 Q_SIGNALS:
72  void settingsSetupLoaderChanged(QtMvvm::ISettingsSetupLoader* settingsSetupLoader, QPrivateSignal);
73 
75  void beginLoadSetup();
76 
77 protected:
78  void onInit(const QVariantHash &params) override;
79 
80 private:
82 };
83 
84 }
85 
86 #endif // QTMVVM_SETTINGSVIEWMODEL_H
A ViewModel for a generic settings dialog based of an XML settings file.
A configuration for a simple dialog to be shown from the core code.
Definition: message.h:18
#define QTMVVM_INJECT(classType, name)
Mark a property for injection.
The base class for all viewmodels.
Definition: viewmodel.h:20
An interface for a generic settings setup loader.
The whole settings setup.
Definition: settingssetup.h:98
The primary namespace of the QtMvvm library.
Definition: binding.h:10