QtDataSync
4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
|
A helper class to perform background synchronization on Ios. More...
#include <iossyncdelegate.h>
Public Types | |
enum | SyncResult { SyncResult::NewData, SyncResult::NoData, SyncResult::Error } |
The possible results of a synchronization attempt. More... | |
Public Slots | |
void | setInterval (qint64 interval) |
WRITE accessor for IosSyncDelegate::interval. | |
void | setEnabled (bool enabled) |
WRITE accessor for IosSyncDelegate::enabled. | |
void | setWaitFullSync (bool waitFullSync) |
WRITE accessor for IosSyncDelegate::waitFullSync. | |
Signals | |
void | intervalChanged (qint64 interval, QPrivateSignal) |
NOTIFY accessor for IosSyncDelegate::interval. | |
void | enabledChanged (bool enabled, QPrivateSignal) |
NOTIFY accessor for IosSyncDelegate::enabled. | |
void | waitFullSyncChanged (bool waitFullSync, QPrivateSignal) |
NOTIFY accessor for IosSyncDelegate::waitFullSync. | |
Public Member Functions | |
IosSyncDelegate (QObject *parent=nullptr) | |
Default constructor. | |
IosSyncDelegate (QSettings *settings, QObject *parent=nullptr) | |
Default constructor with settings to use for state restoration. | |
qint64 | interval () const |
READ accessor for IosSyncDelegate::interval. | |
std::chrono::minutes | intervalMinutes () const |
READ accessor for IosSyncDelegate::interval. | |
bool | isEnabled () const |
READ accessor for IosSyncDelegate::enabled. | |
bool | waitFullSync () const |
READ accessor for IosSyncDelegate::waitFullSync. | |
virtual bool | persistState () const |
READ accessor for IosSyncDelegate::persistState. | |
template<typename TRep , typename TPeriod > | |
void | setInterval (const std::chrono::duration< TRep, TPeriod > &interval) |
WRITE accessor for IosSyncDelegate::interval. | |
void | setInterval (std::chrono::minutes interval) |
WRITE accessor for IosSyncDelegate::interval. | |
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 void | init (IosSyncDelegate *delegate=nullptr) |
Registers a sync delegate to let it perform synchronization if needed. More... | |
static IosSyncDelegate * | currentDelegate () |
Returns the currently registered sync delegate. 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) |
Protected Member Functions | |
virtual QString | setupName () const |
Returns the name of the setup to be synchronized. More... | |
virtual void | prepareSetup (Setup &setup) |
Prepares the setup to be synchronized. More... | |
virtual SyncResult | onSyncCompleted (SyncManager::SyncState state) |
Is called by the service as soon the the synchronization has been completed. More... | |
virtual void | performSync (std::function< void(QtDataSync::IosSyncDelegate::SyncResult)> callback) |
Is called by Ios to start the background synchronization. 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 | |
qint64 | interval |
The interval in minutes between synchronizations. More... | |
bool | enabled |
Specify if background synchronization is enabled or not. More... | |
bool | waitFullSync |
Specify whether the service should wait for a full synchronization or only the download. More... | |
bool | persistState |
Persist the state of properties so that on a restart of the application they can be restored. More... | |
Properties inherited from QObject | |
objectName | |
A helper class to perform background synchronization on Ios.
This class is part of the QtDataSyncIos
module, which is only available on the ios platform. It can be used to configure and run background synchronization so that your application is able to update it's internal data periodically in the background, even if your app is not actively used.
Definition at line 20 of file iossyncdelegate.h.
|
strong |
The possible results of a synchronization attempt.
Enumerator | |
---|---|
NewData | Synchronization was successful and new data was downloaded. |
NoData | Synchronization was successful but no new data was downloaded. |
Error | Synchronization failed. |
Definition at line 36 of file iossyncdelegate.h.
|
static |
Returns the currently registered sync delegate.
nullptr
, if no delegate was set
|
static |
Registers a sync delegate to let it perform synchronization if needed.
delegate | The delegate to be set as sync delegate |
You must call this method after creating the core app (but before executing it) to register a delegate as "active" delegate. This delegate will then control whether sync is enabled and handle the sync requests if your application is in the background.
|
protectedvirtual |
Is called by the service as soon the the synchronization has been completed.
state | The state in which the synchronization finished |
This method is called as soon as the datasync instance has finished the data synchronization. You can override it to perform additional operations with the data before quitting the service.
The default implementation only returns a sync result based on the sync state. You must do the same in your implementation. If you do not want to return synchronously, you must override the performSync() method instead.
Possible states that are typically passed to the method can be:
The default return value mapping is this method does is:
SyncState | SyncResult |
---|---|
Downloading | NewData |
Uploading | NewData |
Synchronized | NewData |
Disconnected | NoData |
Error | Error |
|
protectedvirtual |
Is called by Ios to start the background synchronization.
callback | A callback to be called with the sync result once the sync is done |
This method is called by the operating system and contains the actual code to synchronize the data. If you want to reimplement this method, you should always call the base implementation as well to make shure synchronization works as expected.
In case you want to override this method to allow asynchronous sync result handling, you can use the following pattern. Simpyl impelement onSyncCompleted() as usual, but always return NewData (ignored). Instead add a signal with the SyncResult as parameter and emit this once the async sync operation has finished. Now implement this method and call the base implementation as usual, but pass an empty, self constructed callback to it that does nothing. Instead connect the actual callback to the previously declared signal (before calling the base impl.)
|
protectedvirtual |
Prepares the setup to be synchronized.
setup | The setup to be prepared |
You should override this method to configure the setup before creation (i.e. set properties on it). The default implementation does nothing.
|
protectedvirtual |
Returns the name of the setup to be synchronized.
The default implementation returns QtDataSync::DefaultSetup
. You can override the method if you need the delegate to create the setup under a different name.
|
readwrite |
Specify if background synchronization is enabled or not.
Default: false
These property directly communicates with the OS and schedules (or unschedules) the task to run the sync task. This means you must always set the interval first before enabling a task.
Accessors | |
---|---|
READ | isEnabled() |
WRITE | setEnabled() |
NOTIFY | enabledChanged() |
Definition at line 27 of file iossyncdelegate.h.
|
readwrite |
The interval in minutes between synchronizations.
Default: 60
(minutes)
This value is passed to the operating system to schedule the background synchronization. There is no guarantee of exact delivery of those background synchronizations. For ios, this is only a minimal wait time, i.e. it is guaranteed that the synchronization will not be started before that time has passed.
Accessors | |
---|---|
READ | interval() |
READ | intervalMinutes() |
WRITE | setInterval() |
NOTIFY | intervalChanged() |
Definition at line 25 of file iossyncdelegate.h.
|
read |
Persist the state of properties so that on a restart of the application they can be restored.
Default: true
If set to true, the delegate will store it's current state whenver the interval or the enabled properties are changed. The that will be automatically reloaded when passed to init().
For the default implementation of the delegate, persistance is always enabled. You can override this method in a custom class to deactivate it.
Properties that are stored are:
Accessors | |
---|---|
READ | persistState() |
CONSTANT |
Definition at line 32 of file iossyncdelegate.h.
|
readwrite |
Specify whether the service should wait for a full synchronization or only the download.
Default: true
If set to true, the delegate will internally call SyncManager::runOnSynchronized() with the onSyncCompleted() as handler. If disable, SyncManager::runOnDownloaded() is used instead. Check the documentation of these two methods.
Accessors | |
---|---|
READ | waitFullSync() |
WRITE | setWaitFullSync() |
NOTIFY | waitFullSyncChanged() |
Definition at line 30 of file iossyncdelegate.h.