QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Properties | List of all members
QtMvvm::DataSyncViewModel Class Reference

A viewmodel to show a overview of the datasync status and account. More...

#include <datasyncviewmodel.h>

+ Inheritance diagram for QtMvvm::DataSyncViewModel:

Public Types

using ColorMap = QMap< QtDataSync::SyncManager::SyncState, QColor >
 A mapping from sync states to a text color.
 

Public Slots

void syncOrConnect ()
 Synchronizes or reconnects with the server.
 
void showDeviceInfo ()
 Show and edit information about this current device.
 
void startExport ()
 Start an export to a file.
 
void startImport ()
 Start an import from a file.
 
void performReset ()
 Show a confirmation dialog to reset the account (and then reset)
 
void changeRemote ()
 Show a dialog to change the remote server connected to.
 
void startNetworkExchange ()
 Start a network exchange by showing the NetworkExchangeViewModel.
 
void removeDevice (int sortedIndex)
 Remove the with the given index in the sorted model from the account. More...
 
void setColorMap (ColorMap colorMap)
 WRITE accessor for DataSyncViewModel::colorMap.
 
void resetColorMap ()
 RESET accessor for DataSyncViewModel::colorMap.
 
- Public Slots inherited from QtMvvm::ViewModel

Signals

void syncManagerChanged (QtDataSync::SyncManager *syncManager, QPrivateSignal)
 NOTIFY accessor for DataSyncViewModel::syncManager.
 
void accountManagerChanged (QtDataSync::AccountManager *accountManager, QPrivateSignal)
 NOTIFY accessor for DataSyncViewModel::accountManager.
 
void colorMapChanged (ColorMap colorMap, QPrivateSignal)
 NOTIFY accessor for DataSyncViewModel::colorMap.
 
void statusStringChanged (QPrivateSignal)
 NOTIFY accessor for DataSyncViewModel::statusString.
 
void ready (QPrivateSignal)
 Is emitted as soon as all the datasync managers have been initialized.
 
- Signals inherited from QtMvvm::ViewModel
void resultReady (const QVariant &result)
 Should be emitted when the viewmodels result is ready. More...
 
QTMVVM_REVISION_1 void instanceInvoked (const QVariantHash &params, QPrivateSignal)
 Is emitted on single instance viewmodels when they get shown again. More...
 

Public Member Functions

Q_INVOKABLE DataSyncViewModel (QObject *parent=nullptr)
 Invokable constructor.
 
QtDataSync::SyncManagersyncManager () const
 READ accessor for DataSyncViewModel::syncManager.
 
QtDataSync::AccountManageraccountManager () const
 READ accessor for DataSyncViewModel::accountManager.
 
ColorMap colorMap () const
 READ accessor for DataSyncViewModel::colorMap.
 
QString statusString () const
 READ accessor for DataSyncViewModel::statusString.
 
AccountModelaccountModel () const
 READ accessor for DataSyncViewModel::accountModel.
 
QSortFilterProxyModelsortedModel () const
 READ accessor for DataSyncViewModel::sortedModel.
 
- Public Member Functions inherited from QtMvvm::ViewModel
 ViewModel (QObject *parent=nullptr)
 Default constructor with parent.
 
- 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 QVariantHash showParams (const QString &setup)
 Generates show parameter to show a datasync viewmodel via ViewModel::show. More...
 
static QVariantHash showParams (QRemoteObjectNode *node)
 Generates show parameter to show a datasync viewmodel via ViewModel::show. More...
 
static Q_INVOKABLE QString formatFingerPrint (const QByteArray &fingerPrint)
 Converts a binary fingerprint to a human readable string. 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)
 

Static Public Attributes

static const QString paramSetup
 The parameter for a setup name for the onInit() method. More...
 
static const QString paramReplicaNode
 The parameter for a QRemoteObjectNode for the onInit() method. More...
 

Protected Member Functions

void onInit (const QVariantHash &params) override
 Called by the presenter to initialize the viewmodel. More...
 
void onResult (quint32 requestCode, const QVariant &result) override
 Called by the presenter when a result of a showed viewmodel is ready. More...
 
- Protected Member Functions inherited from QtMvvm::ViewModel
template<typename TViewModel >
void show (const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
void show (const char *viewModelName, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
void show (const QMetaObject *viewMetaObject, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one. More...
 
template<typename TViewModel >
void showForResult (quint32 requestCode, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. More...
 
void showForResult (quint32 requestCode, const char *viewModelName, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. More...
 
void showForResult (quint32 requestCode, const QMetaObject *viewMetaObject, const QVariantHash &params={}) const
 Show another viewmodel as a child of this one and expect its result. 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

QtDataSync::SyncManager syncManager
 The sync manager the viewmodel operates on. More...
 
QtDataSync::AccountManager accountManager
 The account manager the viewmodel operates on. More...
 
ColorMap colorMap
 A mapping of sync states to text colors. More...
 
QString statusString
 A styles string describing the current sync status. More...
 
QtMvvm::AccountModel accountModel
 The account model to be used to display account devices. More...
 
QSortFilterProxyModel sortedModel
 A sorted version of the account model. More...
 
- Properties inherited from QObject
 objectName
 

Detailed Description

A viewmodel to show a overview of the datasync status and account.

The viewmodel provides data to show a ui that gives access to all of the important datasync account features and the synchronization status. The uis should show:

See also
QtDataSync, NetworkExchangeViewModel

Definition at line 22 of file datasyncviewmodel.h.

Member Function Documentation

◆ formatFingerPrint()

QtMvvm::DataSyncViewModel::formatFingerPrint ( const QByteArray fingerPrint)
static

Converts a binary fingerprint to a human readable string.

Parameters
fingerPrintThe fingerprint as a binary string
Returns
A human readable string in hex format

The returned string will be of the format:

AB:CD:EF:01:02:03:...
See also
QtDataSync::AccountManager::deviceFingerprint, QtDataSync::DeviceInfo::fingerprint

◆ onInit()

void QtMvvm::DataSyncViewModel::onInit ( const QVariantHash &  params)
overrideprotectedvirtual

Called by the presenter to initialize the viewmodel.

Parameters
paramsThe parameters to initialize the viewmodel with

This method is called by the presenter right after creating the view and reparenting the viewmodel to the view. The parameters are the ones that have been passed to the show method called to show this viewmodel instance. Reimplement this method if you need to perform initializations after beeing assigned to a viewmodel or if you want to support a parametrized viewmodel.

See also
ViewModel::show, ViewModel::showForResult, CoreApp::show

Reimplemented from QtMvvm::ViewModel.

◆ onResult()

void QtMvvm::DataSyncViewModel::onResult ( quint32  requestCode,
const QVariant result 
)
overrideprotectedvirtual

Called by the presenter when a result of a showed viewmodel is ready.

Parameters
requestCodeThe request code of the show request for the viewmodel that triggered the result
resultThe result passed from the viewmodel

When showing a child viewmodel via showForResult(), then the result of that show request is reported back via this function. The requestCode is the one that was passed to the showForResult() method, and the result what the viewmodel reported back. If the showed viewmodel emitted resultReady() before beeing destroyed, this value passed to that signal is whats reported as result. If the child viewmodel gets destroyed without ever emitting that signal, this method is still called, but with an invalid QVariant as result.

See also
ViewModel::showForResult, ViewModel::resultReady

Reimplemented from QtMvvm::ViewModel.

◆ removeDevice

QtMvvm::DataSyncViewModel::removeDevice ( int  sortedIndex)
slot

Remove the with the given index in the sorted model from the account.

Parameters
sortedIndexThe index in the sorted model to be removed
Warning
The passed index must be an index from the DataSyncViewModel::sortedModel! It is translated to an account model index and the passed to AccountModel::removeDevice. If you do not use the sorted model, use the account model remove directly. If you use the sorted model (as recommended) use this method.
See also
AccountModel::removeDevice, DataSyncViewModel::sortedModel

◆ showParams() [1/2]

QtMvvm::DataSyncViewModel::showParams ( const QString setup)
static

Generates show parameter to show a datasync viewmodel via ViewModel::show.

Parameters
setupThe name of the QtDataSync::Setup to create the viewmodel for
Returns
A paramater hash to be passed to ViewModel::show

It's a shortcut to generate parameters for the show methods to show a datasync viewmodel. Use them as:

show<QtMvvm::DataSyncViewModel>(QtMvvm::DataSyncViewModel::showParams(...));
Note
Unless you need to explicitly set the setup or node a normal show without any parameters will just do fine.
See also
ViewModel::show, DataSyncViewModel::paramSetup

◆ showParams() [2/2]

QtMvvm::DataSyncViewModel::showParams ( QRemoteObjectNode node)
static

Generates show parameter to show a datasync viewmodel via ViewModel::show.

Parameters
nodeThe node to use to get the replicas for the managers
Returns
A paramater hash to be passed to ViewModel::show

It's a shortcut to generate parameters for the show methods to show a datasync viewmodel. Use them as:

show<QtMvvm::DataSyncViewModel>(QtMvvm::DataSyncViewModel::showParams(...));
Note
Unless you need to explicitly set the setup or node a normal show without any parameters will just do fine.
See also
ViewModel::show, DataSyncViewModel::paramReplicaNode

Member Data Documentation

◆ paramReplicaNode

QtMvvm::DataSyncViewModel::paramReplicaNode
static

The parameter for a QRemoteObjectNode for the onInit() method.

Value: "node"

See also
DataSyncViewModel::showParams

Definition at line 48 of file datasyncviewmodel.h.

◆ paramSetup

QtMvvm::DataSyncViewModel::paramSetup
static

The parameter for a setup name for the onInit() method.

Value: "setup"

See also
DataSyncViewModel::showParams

Definition at line 46 of file datasyncviewmodel.h.

Property Documentation

◆ accountManager

QtMvvm::DataSyncViewModel::accountManager
read

The account manager the viewmodel operates on.

Default: nullptr (Is initialized by onInit())

A reference to the account manager the view model internally uses. Is owned by the viewmodel, but can be used to get properties for the ui.

Accessors
READaccountManager()
NOTIFYaccountManagerChanged()
See also
DataSyncViewModel::syncManager

Definition at line 29 of file datasyncviewmodel.h.

◆ accountModel

QtMvvm::DataSyncViewModel::accountModel
read

The account model to be used to display account devices.

Default: An account model

An unsorted model with all the devices of the current account. Automatically initialized and managed by the viewmodel.

Note
You should use the DataSyncViewModel::sortedModel property when creating views. It is a sorted version of this model, which is better for users.
Accessors
READaccountModel()
CONSTANT
See also
DataSyncViewModel::sortedModel

Definition at line 37 of file datasyncviewmodel.h.

◆ colorMap

QtMvvm::DataSyncViewModel::colorMap
readwrite

A mapping of sync states to text colors.

Default: A map inizialized as:

Key Value
QtDataSync::SyncManager::Initializing Qt::darkCyan
QtDataSync::SyncManager::Downloading Qt::darkCyan
QtDataSync::SyncManager::Uploading Qt::darkCyan
QtDataSync::SyncManager::Synchronized Qt::darkGreen
QtDataSync::SyncManager::Error Qt::darkRed
QtDataSync::SyncManager::Disconnected Qt::darkYellow

This map is used by the DataSyncViewModel::statusString property to determine the color of the status string, based of the state itself. You can change this property if you need different colors for your theme.

Accessors
READcolorMap()
WRITEsetColorMap()
RESETresetColorMap()
NOTIFYcolorMapChanged()
See also
DataSyncViewModel::statusString, DataSyncViewModel::ColorMap

Definition at line 32 of file datasyncviewmodel.h.

◆ sortedModel

QtMvvm::DataSyncViewModel::sortedModel
read

A sorted version of the account model.

Default: The accountModel, sorted

A sorted proxy to the DataSyncViewModel::accountModel. You should prefer this sorted version when binding views to the viewmodel.

Accessors
READsortedModel()
CONSTANT
See also
DataSyncViewModel::accountModel

Definition at line 39 of file datasyncviewmodel.h.

◆ statusString

QtMvvm::DataSyncViewModel::statusString
read

A styles string describing the current sync status.

Default: Disconnected

A localized string to display the sync state as a single, simple string. The string is styled with different colors based of the DataSyncViewModel::colorMap property.

Accessors
READstatusString()
NOTIFYstatusStringChanged()
See also
DataSyncViewModel::colorMap, QtDataSync::SyncManager::syncState

Definition at line 34 of file datasyncviewmodel.h.

◆ syncManager

QtMvvm::DataSyncViewModel::syncManager
read

The sync manager the viewmodel operates on.

Default: nullptr (Is initialized by onInit())

A reference to the sync manager the view model internally uses. Is owned by the viewmodel, but can be used to get properties for the ui.

Accessors
READsyncManager()
NOTIFYsyncManagerChanged()
See also
DataSyncViewModel::accountManager

Definition at line 27 of file datasyncviewmodel.h.


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