QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Member Functions | Static Public Member Functions | List of all members
QtDataSync::DataTypeStore< TType, TKey > Class Template Reference

A wrapper around the DataStore limited to one type to make access simpler. More...

#include <datatypestore.h>

+ Inheritance diagram for QtDataSync::DataTypeStore< TType, TKey >:

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...
 
DataStorestore () 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 QMetaObjectmetaObject () 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)
 
QThreadthread () 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)
 
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 &regExp, 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< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () 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
QObjectsender () 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
 

Detailed Description

template<typename TType, typename TKey = QString>
class QtDataSync::DataTypeStore< TType, TKey >

A wrapper around the DataStore limited to one type to make access simpler.

Template Parameters
TTypeThe type of datasets this store should handle
TKeyThe 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

See also
DataStore, CachingDataTypeStore

Definition at line 37 of file datatypestore.h.

Constructor & Destructor Documentation

◆ DataTypeStore() [1/3]

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::DataTypeStore ( QObject parent = nullptr)
explicit

Constructs a store for the default setup.

Parameters
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the default setup was not created yet

Definition at line 199 of file datatypestore.h.

◆ DataTypeStore() [2/3]

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::DataTypeStore ( const QString setupName,
QObject parent = nullptr 
)
explicit

Constructs a store for the given setup.

Parameters
setupNameThe name of the setup to connect to
parentThe parent object
Exceptions
SetupDoesNotExistExceptionThrown if the given setup was not created yet

Definition at line 204 of file datatypestore.h.

◆ DataTypeStore() [3/3]

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::DataTypeStore ( DataStore store,
QObject parent = nullptr 
)
explicit

Constructs a store for the given setup.

Parameters
storeThe store to be used by the model
parentThe parent object
Attention
The type store does not take ownership of the passed store. Thus, the store must stay valid as long as the model exists.

Definition at line 211 of file datatypestore.h.

Member Function Documentation

◆ clear()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::clear ( )

Removes all datasets of the given type from the store.

Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::dataResetted, DataTypeStore::remove

Definition at line 289 of file datatypestore.h.

◆ contains()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::contains ( const TKey &  key) const

Checks if a dataset exists in the store for the given key.

Parameters
keyThe key of the dataset to be checked for existance
Returns
true if the dataset exists, false if not
Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::keys, DataTypeStore::load

Definition at line 246 of file datatypestore.h.

◆ count()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::count ( ) const

Counts the number of datasets for the given type.

Returns
The number of datasets of the given type stored
Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::keys

Definition at line 228 of file datatypestore.h.

◆ iterate()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::iterate ( const std::function< bool(TType)> &  iterator,
bool  skipBroken = false 
)

Iterates over all existing datasets of the given types.

Parameters
iteratorAn iterator function that is called for every dataset of the given type
skipBrokenSkip datasets that fail to load instead of thrown the exception
Exceptions
LocalStoreExceptionIn case of an internal error

Semantics of the iterator:

  • Parameter 1: The loaded dataset
  • Returns: true to continue the iteration, false to prematurely abort it
See also
DataTypeStore::search, DataTypeStore::keys, DataTypeStore::loadAll

Definition at line 283 of file datatypestore.h.

◆ keys()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::keys ( ) const

Returns all saved keys for the given type.

Returns
A list of all keys stored for the given type
Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::count, DataTypeStore::loadAll, DataTypeStore::search, DataTypeStore::load

Definition at line 234 of file datatypestore.h.

◆ load()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::load ( const TKey &  key) const

Loads the dataset with the given key for the given type.

Parameters
keyThe key of the dataset to be loaded
Returns
The dataset that was found for the given type and key
Exceptions
NoDataExceptionIn case no dataset for the given type and key was found
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::loadAll, DataTypeStore::keys, DataTypeStore::iterate

Definition at line 252 of file datatypestore.h.

◆ loadAll()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::loadAll ( ) const

Loads all existing datasets for the given type.

Returns
A list of all datasets stored for the given type
Exceptions
LocalStoreExceptionIn case of an internal error
Attention
Depending on how many data is stored for a given type, this method can take long to return and cosume very much memory. For most situations however, this is not the case
See also
DataTypeStore::iterate, DataTypeStore::search, DataTypeStore::load, DataTypeStore::keys

Definition at line 240 of file datatypestore.h.

◆ remove()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::remove ( const TKey &  key)

Removes the dataset with the given key for the given type.

Parameters
keyThe key of the dataset to be removed
Returns
true in case the dataset was removed, false if it did not exist
Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::save, DataTypeStore::clear, DataTypeStore::load, DataTypeStore::dataChanged

Definition at line 264 of file datatypestore.h.

◆ save()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::save ( const TType &  value)

Saves the given dataset in the store.

Parameters
valueThe dataset to be stored
Exceptions
InvalidDataExceptionIn case the given type cannot be stored
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::remove, DataTypeStore::load, DataTypeStore::dataChanged

Definition at line 258 of file datatypestore.h.

◆ search()

template<typename TType , typename TKey >
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.

Parameters
queryA search query to be used to find fitting datasets. Format depends on mode
modeSpecifies how to interpret the search query See DataStore::SearchMode documentation
Returns
A list with all datasets that keys matched the search query for the given type
Exceptions
LocalStoreExceptionIn case of an internal error
See also
DataTypeStore::SearchMode, DataTypeStore::load, DataTypeStore::keys, DataTypeStore::loadAll

Definition at line 277 of file datatypestore.h.

◆ store()

template<typename TType , typename TKey >
DataStore * QtDataSync::DataTypeStore< TType, TKey >::store ( ) const
overridevirtual

Returns a reference to the internally used DataStore.

Returns
A reference to the internally used store
Note
Most models do own their own datastore (only not the case if the store was passed via the constructor). The most returned stores are thus deleted as soon as the model gets destroyed.

Implements QtDataSync::DataTypeStoreBase.

Definition at line 222 of file datatypestore.h.

◆ toKey()

template<typename TType , typename TKey >
QtDataSync::DataTypeStore< TType, TKey >::toKey ( const QString key)
static

Shortcut to convert a string to the stores key type.

Parameters
keyThe key as a string
Returns
The key as a TKey type

The conversion is performed by using QVariant::convert

Definition at line 295 of file datatypestore.h.

◆ update()

template<typename TType , typename TKey >
template<typename TX >
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.

Template Parameters
TXMust be the same as TType. Required for the enable if statement
Parameters
objectA pointer to the object to load the data into
Exceptions
NoDataExceptionIn case no dataset for the given type and key was found
InvalidDataExceptionIn case the given type cannot be stored
LocalStoreExceptionIn case of an internal error
Note
This method is only defined if TType is a pointer to a class that extends QObject

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.

See also
DataTypeStore::load, DataTypeStore::save, DataTypeStore::dataChanged

Definition at line 271 of file datatypestore.h.


The documentation for this class was generated from the following files: