QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qqmldatastore.h
1 #ifndef QQMLDATASTORE_H
2 #define QQMLDATASTORE_H
3 
4 #include <QtCore/QObject>
5 
6 #include <QtQml/QQmlParserStatus>
7 
8 #include <QtDataSync/datastore.h>
9 
10 #ifdef DOXYGEN_RUN
12 
20 #else
21 namespace QtDataSync {
22 
23 class QQmlDataStore : public DataStore, public QQmlParserStatus
24 #endif
25 {
26  Q_OBJECT
27  Q_DISABLE_COPY(QQmlDataStore)
28  Q_INTERFACES(QQmlParserStatus)
29 
30 
46  Q_PROPERTY(QString setupName READ setupName WRITE setSetupName NOTIFY setupNameChanged)
62  Q_PROPERTY(bool valid READ valid NOTIFY validChanged)
63 
64 public:
66  explicit QQmlDataStore(QObject *parent = nullptr);
67 
69  void classBegin() override;
71  void componentComplete() override;
72 
74  QString setupName() const;
76  bool valid() const;
77 
85  Q_INVOKABLE qint64 count(const QString &typeName) const;
93  Q_INVOKABLE QStringList keys(const QString &typeName) const;
101  Q_INVOKABLE QVariantList loadAll(const QString &typeName) const;
110  Q_INVOKABLE QT_DATASYNC_REVISION_2 bool contains(const QString &typeName, const QString &key) const;
119  Q_INVOKABLE QVariant load(const QString &typeName, const QString &key) const;
127  Q_INVOKABLE void save(const QString &typeName, const QVariant &value);
136  Q_INVOKABLE bool remove(const QString &typeName, const QString &key);
146  Q_INVOKABLE QVariantList search(const QString &typeName, const QString &query, DataStore::SearchMode mode = DataStore::RegexpMode) const;
153  Q_INVOKABLE void clear(const QString &typeName);
154 
160  Q_INVOKABLE QString typeName(int typeId) const;
161 
162 public Q_SLOTS:
164  void setSetupName(QString setupName);
165 
166 Q_SIGNALS:
168  void setupNameChanged(const QString &setupName);
170  void validChanged(bool valid);
171 
172 private:
173  QString _setupName;
174  bool _valid;
175 };
176 
177 }
178 
179 #endif // QQMLDATASTORE_H
Q_INVOKABLE QT_DATASYNC_REVISION_2 bool contains(const QString &typeName, const QString &key) const
Checks if a dataset exists in the store for the given key.
Q_INVOKABLE void save(const QString &typeName, const QVariant &value)
Saves the given dataset in the store.
QStringList keys() const
Returns all saved keys for the given type.
Definition: datastore.h:250
Q_INVOKABLE QVariant load(const QString &typeName, const QString &key) const
Loads the dataset with the given key for the given type.
The QML import for the QtDataSync QML module.
void setupNameChanged(const QString &setupName)
NOTIFY accessor for AccountManager::setupName.
void clear()
Removes all datasets of the given type from the store.
Definition: datastore.h:352
The primary namespace of the QtDataSync library.
Q_INVOKABLE QString typeName(int typeId) const
Returns the name of the type identified by the given type id.
quint64 count() const
Counts the number of datasets for the given type.
Definition: datastore.h:243
Q_INVOKABLE bool remove(const QString &typeName, const QString &key)
Removes the dataset with the given key for the given type.
The QML binding of QtDataSync::DataStore.
Definition: qqmldatastore.h:19
void validChanged(bool valid)
NOTIFY accessor for AccountManager::valid.
SearchMode
Possible pattern modes for the search mechanism.
Definition: datastore.h:28
Q_INVOKABLE QVariantList search(const QString &typeName, const QString &query, DataStore::SearchMode mode=DataStore::RegexpMode) const
Searches the store for datasets of the given type where the key matches the query.
QList< T > loadAll() const
Loads all existing datasets for the given type.
Definition: datastore.h:267
Interpret the search string as a regular expression. See QRegularExpression.
Definition: datastore.h:30
QObject * parent() const const