QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
A DataTypeStore that caches all loaded data internally for faster access. More...
#include <datatypestore.h>
Public Types | |
using | const_iterator = typename QHash< TKey, TType >::const_iterator |
Typedef for QHash::const_iterator. | |
using | iterator = const_iterator |
Typedef for QHash::const_iterator. | |
Public Member Functions | |
CachingDataTypeStore (QObject *parent=nullptr) | |
Constructs a store for the default setup. More... | |
CachingDataTypeStore (const QString &setupName, QObject *parent=nullptr) | |
Constructs a store for the given setup. More... | |
CachingDataTypeStore (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... | |
bool | contains (const TKey &key) const |
Checks if a dataset exists in the store for the given key. | |
QList< TType > | loadAll () const |
Loads all existing datasets for the given type. More... | |
TType | load (const TKey &key) const |
Loads the dataset with the given key for the given type. | |
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... | |
TType | take (const TKey &key) |
Returns the dataset for the given key and removes it from the store. More... | |
void | clear () |
Removes all datasets of the given type from the store. More... | |
const_iterator | begin () const |
Returns the begin iterator of the internal hash. | |
const_iterator | end () const |
Returns the end iterator of the internal hash. | |
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 DataTypeStore that caches all loaded data internally for faster access.
The caching store is an extension to the DataTypeStore. Instead of making requests to the store for any operation, the caching store loads all datasets for one type once on it's creation. All changes you make are directly passed to the store, which means they can trigger exceptions and are permanent, if successful. Changes in the main store are automatically detected and applied to the cached data. If a change operation fails, the cache will not be changed as well.
The main advantage here is that read operations won't access the store but instead used the cached data and thus are much faster and cannot fail. This store is most useful when doing much work with the data with frequent accesses.
One additional feature of the store is that it provides read-only STL iterators for easy access. Using it with for/foreach however is currently not possible, as the store is not a value type.
Definition at line 86 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 319 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 324 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 331 of file datatypestore.h.
void QtDataSync::CachingDataTypeStore< TType, TKey >::clear | ( | ) |
Removes all datasets of the given type from the store.
LocalStoreException | In case of an internal error |
Definition at line 406 of file datatypestore.h.
QtDataSync::CachingDataTypeStore< TType, TKey >::count | ( | ) | const |
Counts the number of datasets for the given type.
Definition at line 354 of file datatypestore.h.
QtDataSync::CachingDataTypeStore< TType, TKey >::keys | ( | ) | const |
Returns all saved keys for the given type.
Definition at line 360 of file datatypestore.h.
QtDataSync::CachingDataTypeStore< TType, TKey >::loadAll | ( | ) | const |
Loads all existing datasets for the given type.
Unlike with the DataStore or DataTypeStore, this method will not take extremly long blocking the store, as it only needs to pass the cached values.
Definition at line 372 of file datatypestore.h.
bool QtDataSync::CachingDataTypeStore< 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 390 of file datatypestore.h.
void QtDataSync::CachingDataTypeStore< 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 384 of file datatypestore.h.
|
overridevirtual |
Returns a reference to the internally used DataStore.
Implements QtDataSync::DataTypeStoreBase.
Definition at line 348 of file datatypestore.h.
QtDataSync::CachingDataTypeStore< TType, TKey >::take | ( | const TKey & | key | ) |
Returns the dataset for the given key and removes it from the store.
key | The key of the dataset to be taken |
LocalStoreException | In case of an internal error |
Definition at line 396 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 424 of file datatypestore.h.