QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
Main store to generically access all stored data synchronously. More...
#include <datastore.h>
Public Types | |
enum | SearchMode { RegexpMode, WildcardMode, ContainsMode, StartsWithMode, EndsWithMode } |
Possible pattern modes for the search mechanism. More... | |
Signals | |
void | dataChanged (int metaTypeId, const QString &key, bool deleted, QPrivateSignal) |
Is emitted whenever a dataset has been changed. More... | |
Q_DECL_DEPRECATED void | dataCleared (int metaTypeId, QPrivateSignal) |
Is emitted when a datatypes has been cleared. More... | |
void | dataResetted (QPrivateSignal) |
Is emitted when the store is resetted due to an account reset. More... | |
Public Member Functions | |
DataStore (QObject *parent=nullptr) | |
Default constructor, uses the default setup. More... | |
DataStore (const QString &setupName, QObject *parent=nullptr) | |
Constructor with an explicit setup. More... | |
QString | setupName () const |
Returns the name of the setup this class operates on. More... | |
qint64 | count (int metaTypeId) const |
Counts the number of datasets for the given type. More... | |
QStringList | keys (int metaTypeId) const |
Returns all saved keys for the given type. More... | |
QVariantList | loadAll (int metaTypeId) const |
Loads all existing datasets for the given type. More... | |
bool | contains (int metaTypeId, const QString &key) const |
Checks if a dataset exists in the store for the given key. More... | |
bool | contains (int metaTypeId, const QVariant &key) const |
Checks if a dataset exists in the store for the given key. More... | |
QVariant | load (int metaTypeId, const QString &key) const |
Loads the dataset with the given key for the given type. More... | |
QVariant | load (int metaTypeId, const QVariant &key) const |
Loads the dataset with the given key for the given type. More... | |
void | save (int metaTypeId, QVariant value) |
Saves the given dataset in the store. More... | |
bool | remove (int metaTypeId, const QString &key) |
Removes the dataset with the given key for the given type. More... | |
bool | remove (int metaTypeId, const QVariant &key) |
Removes the dataset with the given key for the given type. More... | |
void | update (int metaTypeId, QObject *object) const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties. More... | |
QVariantList | search (int metaTypeId, const QString &query, SearchMode mode=RegexpMode) const |
Searches the store for datasets of the given type where the key matches the query. More... | |
void | iterate (int metaTypeId, const std::function< bool(QVariant)> &iterator) const |
Iterates over all existing datasets of the given types. More... | |
void | iterate (int metaTypeId, const std::function< bool(QVariant)> &iterator, bool skipBroken) const |
Iterates over all existing datasets of the given types. More... | |
void | clear (int metaTypeId) |
Removes all datasets of the given type from the store. More... | |
template<typename T > | |
quint64 | count () const |
Counts the number of datasets for the given type. More... | |
template<typename T > | |
QStringList | keys () const |
Returns all saved keys for the given type. More... | |
template<typename T , typename K > | |
QList< K > | keys () const |
Returns all saved keys for the given type. More... | |
template<typename T > | |
QList< T > | loadAll () const |
Loads all existing datasets for the given type. More... | |
template<typename T > | |
bool | contains (const QString &key) const |
Checks if a dataset exists in the store for the given key. More... | |
template<typename T , typename K > | |
bool | contains (const K &key) const |
Checks if a dataset exists in the store for the given key. More... | |
template<typename T > | |
T | load (const QString &key) const |
Loads the dataset with the given key for the given type. More... | |
template<typename T , typename K > | |
T | load (const K &key) const |
Loads the dataset with the given key for the given type. More... | |
template<typename T > | |
void | save (const T &value) |
Saves the given dataset in the store. More... | |
template<typename T > | |
bool | remove (const QString &key) |
Removes the dataset with the given key for the given type. More... | |
template<typename T , typename K > | |
bool | remove (const K &key) |
Removes the dataset with the given key for the given type. More... | |
template<typename T > | |
void | update (T object) const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties. More... | |
template<typename T > | |
QList< T > | search (const QString &query, SearchMode mode=RegexpMode) const |
Searches the store for datasets of the given type where the key matches the query. More... | |
template<typename T > | |
void | iterate (const std::function< bool(T)> &iterator, bool skipBroken=false) const |
Iterates over all existing datasets of the given types. More... | |
template<typename T > | |
void | clear () |
Removes all datasets of the given type from the store. More... | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Properties inherited from QObject | |
objectName | |
Main store to generically access all stored data synchronously.
The class is used as base for all other stores. It provides a generic API to access the store that is simple to use, as well as a the same API for use with metatype ids and qvariant to access the store non generically. All access is atomic and synchronous. A single store can only be used from within one thread, but you can create a store on any thread. It also provides change signals to notify you in case a dataset has been changed.
Definition at line 21 of file datastore.h.
Possible pattern modes for the search mechanism.
Enumerator | |
---|---|
RegexpMode | Interpret the search string as a regular expression. See QRegularExpression. |
WildcardMode | Interpret the search string as a wildcard string (with * and ?) |
ContainsMode | The data key must contain the search string. |
StartsWithMode | The data key must start with the search string. |
EndsWithMode | The data key must end with the search string. |
Definition at line 28 of file datastore.h.
|
explicit |
Default constructor, uses the default setup.
parent | The parent object |
SetupDoesNotExistException | Thrown if the default setup was not created yet |
Constructor with an explicit setup.
setupName | The name of the setup to connect to |
parent | The parent object |
SetupDoesNotExistException | Thrown if the given setup was not created yet |
QtDataSync::DataStore::clear | ( | int | metaTypeId | ) |
Removes all datasets of the given type from the store.
metaTypeId | The QMetaType type id of the type |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::clear | ( | ) |
Removes all datasets of the given type from the store.
T | The type to be cleard |
LocalStoreException | In case of an internal error |
Definition at line 352 of file datastore.h.
QtDataSync::DataStore::contains | ( | int | metaTypeId, |
const QString & | key | ||
) | const |
Checks if a dataset exists in the store for the given key.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be checked for existance |
LocalStoreException | In case of an internal error |
|
inline |
Checks if a dataset exists in the store for the given key.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be checked for existance |
LocalStoreException | In case of an internal error |
Definition at line 56 of file datastore.h.
QtDataSync::DataStore::contains | ( | const QString & | key | ) | const |
Checks if a dataset exists in the store for the given key.
T | The type of the dataset to check for |
key | The key of the dataset to be checked for existance |
LocalStoreException | In case of an internal error |
Definition at line 277 of file datastore.h.
QtDataSync::DataStore::contains | ( | const K & | key | ) | const |
Checks if a dataset exists in the store for the given key.
K | The type of the key to be returned as list |
T | The type of the dataset to check for |
key | The key of the dataset to be checked for existance |
LocalStoreException | In case of an internal error |
Definition at line 284 of file datastore.h.
QtDataSync::DataStore::count | ( | int | metaTypeId | ) | const |
Counts the number of datasets for the given type.
metaTypeId | The QMetaType type id of the type |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::count | ( | ) | const |
Counts the number of datasets for the given type.
T | The type to be counted |
LocalStoreException | In case of an internal error |
Definition at line 243 of file datastore.h.
|
signal |
Is emitted whenever a dataset has been changed.
metaTypeId | The QMetaType type id of the dataset that was changed |
key | The key of the dataset that was changed |
deleted | true if the dataset was deleted, false if it was created or changed |
Is emitted for any local or remote data change. For local changes, it is emitted from within the method that performs the changed. For passive setups or remote changes, it is emitted as queued signal instead.
|
signal |
Is emitted when a datatypes has been cleared.
metaTypeId | The QMetaType type id of the type that was cleard |
This signal is only emitted when a type was completly removed locally. If data was removed by a remote, dataChanged() will instead be called for every single remove dataset. Locally, only this signal will be emitted.
|
signal |
Is emitted when the store is resetted due to an account reset.
This one is only emitted on account resets where the whole store (i.e. all types in it) have been deleted. It indicates a total reset of the store.
QtDataSync::DataStore::iterate | ( | int | metaTypeId, |
const std::function< bool(QVariant)> & | iterator | ||
) | const |
Iterates over all existing datasets of the given types.
metaTypeId | The QMetaType type id of the type |
iterator | An iterator function that is called for every dataset of the given type |
LocalStoreException | In case of an internal error |
Semantics of the iterator
:
true
to continue the iteration, false
to prematurely abort itQtDataSync::DataStore::iterate | ( | int | metaTypeId, |
const std::function< bool(QVariant)> & | iterator, | ||
bool | skipBroken | ||
) | const |
Iterates over all existing datasets of the given types.
skipBroken | Skip datasets that fail to load instead of thrown the exception |
metaTypeId | The QMetaType type id of the type |
iterator | An iterator function that is called for every dataset of the given type |
LocalStoreException | In case of an internal error |
Semantics of the iterator
:
true
to continue the iteration, false
to prematurely abort itQtDataSync::DataStore::iterate | ( | const std::function< bool(T)> & | iterator, |
bool | skipBroken = false |
||
) | const |
Iterates over all existing datasets of the given types.
T | The type to be iterated over |
iterator | An iterator function that is called for every dataset of the given type |
skipBroken | Skip datasets that fail to load instead of thrown the exception |
LocalStoreException | In case of an internal error |
Semantics of the iterator
:
true
to continue the iteration, false
to prematurely abort itDefinition at line 343 of file datastore.h.
QtDataSync::DataStore::keys | ( | int | metaTypeId | ) | const |
Returns all saved keys for the given type.
metaTypeId | The QMetaType type id of the type |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::keys | ( | ) | const |
Returns all saved keys for the given type.
T | The type to load keys for |
LocalStoreException | In case of an internal error |
Definition at line 250 of file datastore.h.
QList< K > QtDataSync::DataStore::keys | ( | ) | const |
Returns all saved keys for the given type.
K | The type of the key to be returned as list |
T | The type to load keys for |
LocalStoreException | In case of an internal error |
Definition at line 257 of file datastore.h.
QtDataSync::DataStore::load | ( | int | metaTypeId, |
const QString & | key | ||
) | const |
Loads the dataset with the given key for the given type.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be loaded |
NoDataException | In case no dataset for the given type and key was found |
LocalStoreException | In case of an internal error |
|
inline |
Loads the dataset with the given key for the given type.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be loaded |
NoDataException | In case no dataset for the given type and key was found |
LocalStoreException | In case of an internal error |
Definition at line 62 of file datastore.h.
QtDataSync::DataStore::load | ( | const QString & | key | ) | const |
Loads the dataset with the given key for the given type.
T | The type to load the dataset for |
key | The key of the dataset to be loaded |
NoDataException | In case no dataset for the given type and key was found |
LocalStoreException | In case of an internal error |
Definition at line 291 of file datastore.h.
QtDataSync::DataStore::load | ( | const K & | key | ) | const |
Loads the dataset with the given key for the given type.
K | The type of the key to be returned as list |
T | The type to load the dataset for |
key | The key of the dataset to be loaded |
NoDataException | In case no dataset for the given type and key was found |
LocalStoreException | In case of an internal error |
Definition at line 298 of file datastore.h.
QtDataSync::DataStore::loadAll | ( | int | metaTypeId | ) | const |
Loads all existing datasets for the given type.
metaTypeId | The QMetaType type id of the type |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::loadAll | ( | ) | const |
Loads all existing datasets for the given type.
T | The type to load the datasets for |
LocalStoreException | In case of an internal error |
Definition at line 267 of file datastore.h.
QtDataSync::DataStore::remove | ( | int | metaTypeId, |
const QString & | key | ||
) |
Removes the dataset with the given key for the given type.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be removed |
true
in case the dataset was removed, false
if it did not exist LocalStoreException | In case of an internal error |
|
inline |
Removes the dataset with the given key for the given type.
metaTypeId | The QMetaType type id of the type |
key | The key of the dataset to be removed |
true
in case the dataset was removed, false
if it did not exist LocalStoreException | In case of an internal error |
Definition at line 70 of file datastore.h.
QtDataSync::DataStore::remove | ( | const QString & | key | ) |
Removes the dataset with the given key for the given type.
T | The type to remove the dataset from |
key | The key of the dataset to be removed |
true
in case the dataset was removed, false
if it did not exist LocalStoreException | In case of an internal error |
Definition at line 312 of file datastore.h.
QtDataSync::DataStore::remove | ( | const K & | key | ) |
Removes the dataset with the given key for the given type.
K | The type of the key of the dataset to be removed |
T | The type to remove the dataset from |
key | The key of the dataset to be removed |
true
in case the dataset was removed, false
if it did not exist LocalStoreException | In case of an internal error |
Definition at line 319 of file datastore.h.
QtDataSync::DataStore::save | ( | int | metaTypeId, |
QVariant | value | ||
) |
Saves the given dataset in the store.
metaTypeId | The QMetaType type id of the type |
value | The dataset to be stored |
InvalidDataException | In case the given type cannot be stored |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::save | ( | const T & | value | ) |
Saves the given dataset in the store.
T | The type to load the dataset for |
value | The dataset to be stored |
InvalidDataException | In case the given type cannot be stored |
LocalStoreException | In case of an internal error |
Definition at line 305 of file datastore.h.
QtDataSync::DataStore::search | ( | int | metaTypeId, |
const QString & | query, | ||
SearchMode | mode = RegexpMode |
||
) | const |
Searches the store for datasets of the given type where the key matches the query.
metaTypeId | The QMetaType type id of the type |
query | A search query to be used to find fitting datasets. Format depends on mode |
mode | Specifies how to interpret the search query See DataStore::SearchMode documentation |
LocalStoreException | In case of an internal error |
QtDataSync::DataStore::search | ( | const QString & | query, |
SearchMode | mode = RegexpMode |
||
) | const |
Searches the store for datasets of the given type where the key matches the query.
T | The type to be searched for datasets |
query | A search query to be used to find fitting datasets. Format depends on mode |
mode | Specifies how to interpret the search query See DataStore::SearchMode documentation |
LocalStoreException | In case of an internal error |
Definition at line 333 of file datastore.h.
QtDataSync::DataStore::setupName | ( | ) | const |
Returns the name of the setup this class operates on.
QtDataSync::DataStore::update | ( | int | metaTypeId, |
QObject * | object | ||
) | const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties.
metaTypeId | The QMetaType type id of the type. Must be the id of a type that extends QObject and is a pointer |
object | A pointer to the object to load the data into |
NoDataException | In case no dataset for the given type and key was found |
InvalidDataException | In case the given type cannot be stored |
LocalStoreException | In case of an internal error |
This method extracts the key from the passed object and uses load() to load the data. Then it simply updates all the objects properties to the values that have been loaded. This way you can load changes for an object from the store without having to exchange the pointer. In addition, all change signals for updated properties will be emitted.
QtDataSync::DataStore::update | ( | T | object | ) | const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties.
T | The type to load the dataset for. Must extend QObject and be a pointer |
object | A pointer to the object to load the data into |
NoDataException | In case no dataset for the given type and key was found |
InvalidDataException | In case the given type cannot be stored |
LocalStoreException | In case of an internal error |
This method extracts the key from the passed object and uses load() to load the data. Then it simply updates all the objects properties to the values that have been loaded. This way you can load changes for an object from the store without having to exchange the pointer. In addition, all change signals for updated properties will be emitted.
Definition at line 326 of file datastore.h.