QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
datasyncsettingsentry.h
1 #ifndef QTMVVM_DATASYNCSETTINGSENTRY_H
2 #define QTMVVM_DATASYNCSETTINGSENTRY_H
3 
4 #include <QtCore/qobject.h>
5 #include <QtCore/qvariant.h>
6 #include <QtCore/qshareddata.h>
7 
8 #include "QtMvvmDataSyncCore/qtmvvmdatasynccore_global.h"
9 
10 namespace QtMvvm {
11 
12 class DataSyncSettingsEntryData;
14 struct Q_MVVMDATASYNCCORE_EXPORT DataSyncSettingsEntry
15 {
16  Q_GADGET
17 
19  Q_PROPERTY(QString key READ key WRITE setKey USER true)
21  Q_PROPERTY(int dataVersion READ dataVersion WRITE setDataVersion)
23  Q_PROPERTY(QVariant value READ value WRITE setValue STORED false)
24 
26  Q_PROPERTY(QByteArray valueData READ valueData WRITE setValueData)
27 
28 public:
36  DataSyncSettingsEntry &operator=(const DataSyncSettingsEntry &other);
38  DataSyncSettingsEntry &operator=(DataSyncSettingsEntry &&other) noexcept;
39 
43  template <typename T>
44  DataSyncSettingsEntry(QString key, const T &value);
45 
47  QString key() const;
49  int dataVersion() const;
50 
52  QVariant value() const;
54  template <typename T>
55  T value() const;
56 
58  void setKey(QString key);
60  void setDataVersion(int dataVersion);
62  void setValue(QVariant value);
63 
64 private:
65  QByteArray valueData() const;
66  void setValueData(QByteArray value);
67 
68  QSharedDataPointer<DataSyncSettingsEntryData> d;
69 };
70 
71 // ------------- Generic Implementation -------------
72 
73 template<typename T>
75  DataSyncSettingsEntry{std::move(key), QVariant::fromValue(value)}
76 {}
77 
78 template<typename T>
80 {
81  return value().template value<T>();
82 }
83 
84 }
85 
86 Q_DECLARE_METATYPE(QtMvvm::DataSyncSettingsEntry)
87 
88 #endif // QTMVVM_DATASYNCSETTINGSENTRY_H
QVariant value() const
READ accessor for variantValue.
QVariant fromValue(const T &value)
A class used with the DataSyncSettingsAccessor to store and sync generic settings.
The primary namespace of the QtMvvm library.