QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
A wrapper around the DataStore limited to one type to make access simpler. More...
#include <datatypestore.h>
Public Member Functions | |
DataTypeStore (QObject *parent=nullptr) | |
Constructs a store for the default setup. More... | |
DataTypeStore (const QString &setupName, QObject *parent=nullptr) | |
Constructs a store for the given setup. More... | |
DataTypeStore (DataStore *store, QObject *parent=nullptr) | |
Constructs a store for the given setup. More... | |
DataStore * | store () const override |
Returns a reference to the internally used DataStore. More... | |
qint64 | count () const |
Counts the number of datasets for the given type. More... | |
QList< TKey > | keys () const |
Returns all saved keys for the given type. More... | |
QList< TType > | loadAll () const |
Loads all existing datasets for the given type. More... | |
bool | contains (const TKey &key) const |
Checks if a dataset exists in the store for the given key. More... | |
TType | load (const TKey &key) const |
Loads the dataset with the given key for the given type. More... | |
void | save (const TType &value) |
Saves the given dataset in the store. More... | |
bool | remove (const TKey &key) |
Removes the dataset with the given key for the given type. More... | |
template<typename TX = TType> | |
void | update (std::enable_if_t< __helpertypes::is_object< TX >::value, TX > object) const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties. More... | |
QList< TType > | search (const QString &query, DataStore::SearchMode mode=DataStore::RegexpMode) |
Searches the store for datasets of the given type where the key matches the query. More... | |
void | iterate (const std::function< bool(TType)> &iterator, bool skipBroken=false) |
Iterates over all existing datasets of the given types. More... | |
void | clear () |
Removes all datasets of the given type from the store. More... | |
Public Member Functions inherited from QtDataSync::DataTypeStoreBase | |
DataTypeStoreBase (QObject *parent=nullptr) | |
Default constructor. | |
QString | setupName () const |
Returns the name of the setup this class operates on. 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 () |
Static Public Member Functions | |
static TKey | toKey (const QString &key) |
Shortcut to convert a string to the stores key type. More... | |
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) |
Additional Inherited Members | |
Signals inherited from QtDataSync::DataTypeStoreBase | |
void | dataChanged (const QString &key, const QVariant &value) |
Will be emitted when a dataset in the store has changed. More... | |
void | dataResetted () |
Will be emitted when the store was reset or cleared. More... | |
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 | |
A wrapper around the DataStore limited to one type to make access simpler.
TType | The type of datasets this store should handle |
TKey | The type of the user property of the TType datatype. Must be convertible from and to QString |
This class simplifies the API of the DataStore by allowing access to just one specific datatype. This way the type does not have to be specified for every method call, and it's generally cleaner to use. As long as you only need a single type, you should prefer this class over the DataStore
Definition at line 37 of file datatypestore.h.
|
explicit |
Constructs a store for the default setup.
parent | The parent object |
SetupDoesNotExistException | Thrown if the default setup was not created yet |
Definition at line 199 of file datatypestore.h.
|
explicit |
Constructs a store for the given setup.
setupName | The name of the setup to connect to |
parent | The parent object |
SetupDoesNotExistException | Thrown if the given setup was not created yet |
Definition at line 204 of file datatypestore.h.
|
explicit |
Constructs a store for the given setup.
store | The store to be used by the model |
parent | The parent object |
Definition at line 211 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::clear | ( | ) |
Removes all datasets of the given type from the store.
LocalStoreException | In case of an internal error |
Definition at line 289 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::contains | ( | const TKey & | key | ) | const |
Checks if a dataset exists in the store for the given key.
key | The key of the dataset to be checked for existance |
LocalStoreException | In case of an internal error |
Definition at line 246 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::count | ( | ) | const |
Counts the number of datasets for the given type.
LocalStoreException | In case of an internal error |
Definition at line 228 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::iterate | ( | const std::function< bool(TType)> & | iterator, |
bool | skipBroken = false |
||
) |
Iterates over all existing datasets of the given types.
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 283 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::keys | ( | ) | const |
Returns all saved keys for the given type.
LocalStoreException | In case of an internal error |
Definition at line 234 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::load | ( | const TKey & | key | ) | const |
Loads the dataset with the given key for the given 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 252 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::loadAll | ( | ) | const |
Loads all existing datasets for the given type.
LocalStoreException | In case of an internal error |
Definition at line 240 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::remove | ( | const TKey & | key | ) |
Removes the dataset with the given key for the given 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 264 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::save | ( | const TType & | value | ) |
Saves the given dataset in the store.
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 258 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::search | ( | const QString & | query, |
DataStore::SearchMode | mode = DataStore::RegexpMode |
||
) |
Searches the store for datasets of the given type where the key matches the query.
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 277 of file datatypestore.h.
|
overridevirtual |
Returns a reference to the internally used DataStore.
Implements QtDataSync::DataTypeStoreBase.
Definition at line 222 of file datatypestore.h.
|
static |
Shortcut to convert a string to the stores key type.
key | The key as a string |
The conversion is performed by using QVariant::convert
Definition at line 295 of file datatypestore.h.
QtDataSync::DataTypeStore< TType, TKey >::update | ( | std::enable_if_t< __helpertypes::is_object< TX >::value, TX > | object | ) | const |
Loads the dataset with the given key for the given type into the existing object by updating it's properties.
TX | Must be the same as TType. Required for the enable if statement |
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 271 of file datatypestore.h.