Browse Source

completed datasync core doc

pull/2/head
Skycoder42 7 years ago
parent
commit
4f627c733d
No known key found for this signature in database GPG Key ID: 8E01AD9EF0578D2B
  1. 216
      doc/datasyncviewmodel.dox
  2. 174
      doc/networkexchangeviewmodel.dox
  3. 9
      doc/qtmvvm.dox
  4. 14
      src/imports/mvvmdatasynccore/plugins.qmltypes
  5. 16
      src/mvvmdatasynccore/accountmodel.h
  6. 48
      src/mvvmdatasynccore/datasyncviewmodel.h
  7. 20
      src/mvvmdatasynccore/exchangedevicesmodel.h
  8. 6
      src/mvvmdatasynccore/networkexchangeviewmodel.cpp
  9. 30
      src/mvvmdatasynccore/networkexchangeviewmodel.h

216
doc/datasyncviewmodel.dox

@ -0,0 +1,216 @@
/*!
@class QtMvvm::DataSyncViewModel
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:
- The sync status as string (DataSyncViewModel::statusString)
- A sync progress when actively syncing (QtDataSync::SyncManager::syncProgress)
- A possible error string, if an error occurs (QtDataSync::SyncManager::lastError)
- A list of all devices of the account (DataSyncViewModel::sortedModel)
- Actions to:
- Synchronize (syncOrConnect())
- Toggle synchronization (QtDataSync::SyncManager::syncEnabled)
- Edit the identity (showDeviceInfo())
- Reload the list of devices (QtDataSync::AccountManager::listDevices)
- Remove devices (removeDevice())
- Update the exchange key (QtDataSync::AccountManager::updateExchangeKey)
- Change the remote server (changeRemote())
- Reset the account (performReset())
- Export the account data (startExport())
- Import the account data (startImport())
- Show the exchange viewmodel (startNetworkExchange())
@sa QtDataSync, NetworkExchangeViewModel
*/
/*!
@property QtMvvm::DataSyncViewModel::syncManager
@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{
@readAc{syncManager()}
@notifyAc{syncManagerChanged()}
}
@sa DataSyncViewModel::accountManager
*/
/*!
@property QtMvvm::DataSyncViewModel::accountManager
@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{
@readAc{accountManager()}
@notifyAc{accountManagerChanged()}
}
@sa DataSyncViewModel::syncManager
*/
/*!
@property QtMvvm::DataSyncViewModel::colorMap
@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{
@readAc{colorMap()}
@writeAc{setColorMap()}
@resetAc{resetColorMap()}
@notifyAc{colorMapChanged()}
}
@sa DataSyncViewModel::statusString, DataSyncViewModel::ColorMap
*/
/*!
@property QtMvvm::DataSyncViewModel::statusString
@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{
@readAc{statusString()}
@notifyAc{statusStringChanged()}
}
@sa DataSyncViewModel::colorMap, QtDataSync::SyncManager::syncState
*/
/*!
@property QtMvvm::DataSyncViewModel::accountModel
@default{<i>An account model</i>}
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{
@readAc{accountModel()}
@constantAc
}
@sa DataSyncViewModel::sortedModel
*/
/*!
@property QtMvvm::DataSyncViewModel::sortedModel
@default{<i>The accountModel, sorted</i>}
A sorted proxy to the DataSyncViewModel::accountModel. You should prefer this sorted version
when binding views to the viewmodel.
@accessors{
@readAc{sortedModel()}
@constantAc
}
@sa DataSyncViewModel::accountModel
*/
/*!
@var QtMvvm::DataSyncViewModel::paramSetup
<b>Value:</b> `"setup"`
@sa DataSyncViewModel::showParams
*/
/*!
@var QtMvvm::DataSyncViewModel::paramReplicaNode
<b>Value:</b> `"node"`
@sa DataSyncViewModel::showParams
*/
/*!
@fn QtMvvm::DataSyncViewModel::showParams(const QString &)
@param setup The name of the QtDataSync::Setup to create the viewmodel for
@return 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:
@code{.cpp}
show<QtMvvm::DataSyncViewModel>(QtMvvm::DataSyncViewModel::showParams(...));
@endcode
@note Unless you need to explicitly set the setup or node a normal show without any parameters
will just do fine.
@sa ViewModel::show, DataSyncViewModel::paramSetup
*/
/*!
@fn QtMvvm::DataSyncViewModel::showParams(QRemoteObjectNode*)
@param node The node to use to get the replicas for the managers
@return 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:
@code{.cpp}
show<QtMvvm::DataSyncViewModel>(QtMvvm::DataSyncViewModel::showParams(...));
@endcode
@note Unless you need to explicitly set the setup or node a normal show without any parameters
will just do fine.
@sa ViewModel::show, DataSyncViewModel::paramReplicaNode
*/
/*!
@fn QtMvvm::DataSyncViewModel::formatFingerPrint
@param fingerPrint The fingerprint as a binary string
@return A human readable string in hex format
The returned string will be of the format:
@code
AB:CD:EF:01:02:03:...
@endcode
@sa QtDataSync::AccountManager::deviceFingerprint, QtDataSync::DeviceInfo::fingerprint
*/
/*!
@fn QtMvvm::DataSyncViewModel::removeDevice
@param sortedIndex The 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.
@sa AccountModel::removeDevice, DataSyncViewModel::sortedModel
*/

174
doc/networkexchangeviewmodel.dox

@ -0,0 +1,174 @@
/*!
@class QtMvvm::NetworkExchangeViewModel
The viewmodel provides data to show a ui that allows you to exchange your user data with
another device in the same local network.
@sa QtDataSync::UserExchangeManager, DataSyncViewModel
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::userExchangeManager
@default{`nullptr` (Is initialized by onInit())}
A reference to the user exchange manager the view model internally uses. Is owned by the
viewmodel, but can be used to get properties for the ui.
@accessors{
@readAc{userExchangeManager()}
@notifyAc{userExchangeManagerChanged()}
}
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::port
@default{`QtDataSync::UserExchangeManager::DataExchangePort`}
This port is passed to the exchange manager when activated to set the port.
@accessors{
@readAc{port()}
@writeAc{setPort()}
@notifyAc{portChanged()}
}
@sa NetworkExchangeViewModel::active, QtDataSync::UserExchangeManager::startExchange,
QtDataSync::UserExchangeManager::port
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::deviceName
@default{`QtDataSync::AccountManager::deviceName`}
This property is simply a forwarding of the QtDataSync::AccountManager::deviceName property.
@accessors{
@readAc{deviceName()}
@writeAc{setDeviceName()}
@notifyAc{deviceNameChanged()}
}
@sa QtDataSync::AccountManager::deviceName
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::active
@default{`false`}
Changing this property will trigger start and stop actions on the underlying manager, using
the other information provided from this viewmodel.
@accessors{
@readAc{active()}
@writeAc{setActive()}
@notifyAc{activeChanged()}
}
@sa QtDataSync::AccountManager::startExchange, QtDataSync::AccountManager::stopExchange,
NetworkExchangeViewModel::port
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::deviceModel
@default{<i>An exchange device model</i>}
An unsorted model with all the devices available for exchange. Automatically initialized and
managed by the viewmodel.
@note You should use the NetworkExchangeViewModel::sortedModel property when creating views.
It is a sorted version of this model, which is better for users.
@accessors{
@readAc{deviceModel()}
@constantAc
}
@sa NetworkExchangeViewModel::sortedModel
*/
/*!
@property QtMvvm::NetworkExchangeViewModel::sortedModel
@default{<i>The deviceModel, sorted</i>}
A sorted proxy to the NetworkExchangeViewModel::deviceModel. You should prefer this sorted
version when binding views to the viewmodel.
@accessors{
@readAc{sortedModel()}
@constantAc
}
@sa NetworkExchangeViewModel::deviceModel
*/
/*!
@var QtMvvm::NetworkExchangeViewModel::paramSetup
<b>Value:</b> `"setup"`
@sa NetworkExchangeViewModel::showParams
*/
/*!
@var QtMvvm::NetworkExchangeViewModel::paramAccountManager
<b>Value:</b> `"accountManager"`
@sa NetworkExchangeViewModel::showParams
*/
/*!
@fn QtMvvm::NetworkExchangeViewModel::showParams(const QString &)
@param setup The name of the QtDataSync::Setup to create the viewmodel for
@return A paramater hash to be passed to ViewModel::show
It's a shortcut to generate parameters for the show methods to show an exchange viewmodel. Use
them as:
@code{.cpp}
show<QtMvvm::NetworkExchangeViewModel>(QtMvvm::NetworkExchangeViewModel::showParams(...));
@endcode
@note Unless you need to explicitly set the setup or node a normal show without any parameters
will just do fine.
@sa ViewModel::show, NetworkExchangeViewModel::paramSetup
*/
/*!
@fn QtMvvm::NetworkExchangeViewModel::showParams(QtDataSync::AccountManager*)
@param accountManager The account manager to create the exchange manager of
@return A paramater hash to be passed to ViewModel::show
It's a shortcut to generate parameters for the show methods to show an exchange viewmodel. Use
them as:
@code{.cpp}
show<QtMvvm::NetworkExchangeViewModel>(QtMvvm::NetworkExchangeViewModel::showParams(...));
@endcode
@note Unless you need to explicitly set the setup or node a normal show without any parameters
will just do fine.
@sa ViewModel::show, NetworkExchangeViewModel::paramAccountManager
*/
/*!
@fn QtMvvm::NetworkExchangeViewModel::exportTo
@param sortedIndex The index in the sorted model of the device to export to
@warning The passed index **must** be an index from the NetworkExchangeViewModel::sortedModel!
It is translated to an exchange model index and the passed to ExchangeDevicesModel::infoAt to
get the user info of the device to export the data to.
@sa ExchangeDevicesModel::infoAt, NetworkExchangeViewModel::sortedModel
*/

9
doc/qtmvvm.dox

@ -94,6 +94,15 @@ The following list shows which classes belong to which Qt module, in alphabetica
<b>Current Version</b><br/> <b>Current Version</b><br/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.0 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1.0
<b>Available Types</b>
- @ref QtMvvm::AccountModel "AccountModel"
- @ref QtMvvm::ExchangeDevicesModel "ExchangeDevicesModel"
- @ref QtMvvm::DataSyncViewModel "DataSyncViewModel" (uncreatable)
- @ref QtMvvm::NetworkExchangeViewModel "NetworkExchangeViewModel" (uncreatable)
- PChangeRemoteViewModel (uncreatable, internal)
- PExportSetupViewModel (uncreatable, internal)
- PIdentityEditViewModel (uncreatable, internal)
*/ */
/*! /*!

14
src/imports/mvvmdatasynccore/plugins.qmltypes

@ -265,12 +265,26 @@ Module {
] ]
isCreatable: false isCreatable: false
exportMetaObjectRevisions: [0] exportMetaObjectRevisions: [0]
Property {
name: "userExchangeManager"
type: "QtDataSync::UserExchangeManager"
isReadonly: true
isPointer: true
}
Property { name: "port"; type: "ushort" } Property { name: "port"; type: "ushort" }
Property { name: "deviceName"; type: "string" } Property { name: "deviceName"; type: "string" }
Property { name: "active"; type: "bool" } Property { name: "active"; type: "bool" }
Property { name: "deviceModel"; type: "ExchangeDevicesModel"; isReadonly: true; isPointer: true } Property { name: "deviceModel"; type: "ExchangeDevicesModel"; isReadonly: true; isPointer: true }
Property { name: "sortedModel"; type: "QSortFilterProxyModel"; isReadonly: true; isPointer: true } Property { name: "sortedModel"; type: "QSortFilterProxyModel"; isReadonly: true; isPointer: true }
Signal { name: "ready" } Signal { name: "ready" }
Signal {
name: "userExchangeManagerChanged"
Parameter {
name: "userExchangeManager"
type: "QtDataSync::UserExchangeManager"
isPointer: true
}
}
Signal { Signal {
name: "portChanged" name: "portChanged"
Parameter { name: "port"; type: "ushort" } Parameter { name: "port"; type: "ushort" }

16
src/mvvmdatasynccore/accountmodel.h

@ -12,35 +12,47 @@
namespace QtMvvm { namespace QtMvvm {
class AccountModelPrivate; class AccountModelPrivate;
//! A list model implementation for QtDataSync::DeviceInfo via a QtDataSync::AccountManager
class Q_MVVMDATASYNCCORE_EXPORT AccountModel : public QAbstractListModel class Q_MVVMDATASYNCCORE_EXPORT AccountModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
//! The model roles this model provides
enum Roles { enum Roles {
NameRole = Qt::DisplayRole, NameRole = Qt::DisplayRole, //!< The users name. The role name is `name`
FingerPrintRole = Qt::UserRole + 1 FingerPrintRole = Qt::UserRole + 1 //!< The cryptopgraphic fingerprint of the users keys. The role name is `fingerPrint`
}; };
Q_ENUM(Roles) Q_ENUM(Roles)
//! Default constructor
explicit AccountModel(QObject *parent = nullptr); explicit AccountModel(QObject *parent = nullptr);
~AccountModel(); ~AccountModel();
//! Setups up the model to use the account and a sync manager. Automatically loads devices
Q_INVOKABLE void setup(QtDataSync::AccountManager *accountManager, Q_INVOKABLE void setup(QtDataSync::AccountManager *accountManager,
QtDataSync::SyncManager *syncManager); QtDataSync::SyncManager *syncManager);
//! @inherit{QAbstractListModel::headerData}
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
//! @inherit{QAbstractListModel::rowCount}
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
//! @inherit{QAbstractListModel::columnCount}
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
//! @inherit{QAbstractListModel::data}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
//! @inherit{QAbstractListModel::roleNames}
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
//! Removes the device with the given index from the account
Q_INVOKABLE bool removeDevice(const QModelIndex &index); Q_INVOKABLE bool removeDevice(const QModelIndex &index);
//! @copybrief removeDevice(const QModelIndex &)
Q_INVOKABLE inline bool removeDevice(int row) { Q_INVOKABLE inline bool removeDevice(int row) {
return removeDevice(index(row)); return removeDevice(index(row));
} }
public Q_SLOTS: public Q_SLOTS:
//! Reload the device list
void reload(); void reload();
private Q_SLOTS: private Q_SLOTS:

48
src/mvvmdatasynccore/datasyncviewmodel.h

@ -18,73 +18,107 @@
namespace QtMvvm { namespace QtMvvm {
class DataSyncViewModelPrivate; class DataSyncViewModelPrivate;
//! A viewmodel to show a overview of the datasync status and account
class Q_MVVMDATASYNCCORE_EXPORT DataSyncViewModel : public ViewModel class Q_MVVMDATASYNCCORE_EXPORT DataSyncViewModel : public ViewModel
{ {
Q_OBJECT Q_OBJECT
//! The sync manager the viewmodel operates on
Q_PROPERTY(QtDataSync::SyncManager* syncManager READ syncManager NOTIFY syncManagerChanged) Q_PROPERTY(QtDataSync::SyncManager* syncManager READ syncManager NOTIFY syncManagerChanged)
//! The account manager the viewmodel operates on
Q_PROPERTY(QtDataSync::AccountManager* accountManager READ accountManager NOTIFY accountManagerChanged) Q_PROPERTY(QtDataSync::AccountManager* accountManager READ accountManager NOTIFY accountManagerChanged)
//! A mapping of sync states to text colors
Q_PROPERTY(ColorMap colorMap READ colorMap WRITE setColorMap RESET resetColorMap NOTIFY colorMapChanged) Q_PROPERTY(ColorMap colorMap READ colorMap WRITE setColorMap RESET resetColorMap NOTIFY colorMapChanged)
//! A styles string describing the current sync status
Q_PROPERTY(QString statusString READ statusString NOTIFY statusStringChanged) Q_PROPERTY(QString statusString READ statusString NOTIFY statusStringChanged)
//! The account model to be used to display account devices
Q_PROPERTY(QtMvvm::AccountModel* accountModel READ accountModel CONSTANT) Q_PROPERTY(QtMvvm::AccountModel* accountModel READ accountModel CONSTANT)
//! A sorted version of the account model
Q_PROPERTY(QSortFilterProxyModel* sortedModel READ sortedModel CONSTANT) Q_PROPERTY(QSortFilterProxyModel* sortedModel READ sortedModel CONSTANT)
public: public:
//! A mapping from sync states to a text color
typedef QMap<QtDataSync::SyncManager::SyncState, QColor> ColorMap; typedef QMap<QtDataSync::SyncManager::SyncState, QColor> ColorMap;
//! The parameter for a setup name for the onInit() method
static const QString paramSetup; static const QString paramSetup;
//! The parameter for a QRemoteObjectNode for the onInit() method
static const QString paramReplicaNode; static const QString paramReplicaNode;
//! Generates show parameter to show a datasync viewmodel via ViewModel::show
static QVariantHash showParams(const QString &setup); static QVariantHash showParams(const QString &setup);
//! @copybrief showParams(const QString &)
static QVariantHash showParams(QRemoteObjectNode *node); static QVariantHash showParams(QRemoteObjectNode *node);
//! Invokable constructor
Q_INVOKABLE explicit DataSyncViewModel(QObject *parent = nullptr); Q_INVOKABLE explicit DataSyncViewModel(QObject *parent = nullptr);
~DataSyncViewModel(); ~DataSyncViewModel();
//! @readAcFn{DataSyncViewModel::syncManager}
QtDataSync::SyncManager* syncManager() const; QtDataSync::SyncManager* syncManager() const;
//! @readAcFn{DataSyncViewModel::accountManager}
QtDataSync::AccountManager* accountManager() const; QtDataSync::AccountManager* accountManager() const;
//! @readAcFn{DataSyncViewModel::colorMap}
ColorMap colorMap() const; ColorMap colorMap() const;
//! @readAcFn{DataSyncViewModel::statusString}
QString statusString() const; QString statusString() const;
//! @readAcFn{DataSyncViewModel::accountModel}
AccountModel *accountModel() const; AccountModel *accountModel() const;
//! @readAcFn{DataSyncViewModel::sortedModel}
QSortFilterProxyModel* sortedModel() const; QSortFilterProxyModel* sortedModel() const;
//! Converts a binary fingerprint to a human readable string
Q_INVOKABLE static QString formatFingerPrint(const QByteArray &fingerPrint); Q_INVOKABLE static QString formatFingerPrint(const QByteArray &fingerPrint);
public Q_SLOTS: public Q_SLOTS:
//! Synchronizes or reconnects with the server
void syncOrConnect(); void syncOrConnect();
//! Show and edit information about this current device
void showDeviceInfo(); void showDeviceInfo();
//! Start an export to a file
void startExport(); void startExport();
//! Start an import from a file
void startImport(); void startImport();
//! Show a confirmation dialog to reset the account (and then reset)
void performReset(); void performReset();
//! Show a dialog to change the remote server connected to
void changeRemote(); void changeRemote();
//! Start a network exchange by showing the NetworkExchangeViewModel
void startNetworkExchange(); void startNetworkExchange();
//! Remove the with the given index in the sorted model from the account
void removeDevice(int sortedIndex); void removeDevice(int sortedIndex);
//! @writeAcFn{DataSyncViewModel::colorMap}
void setColorMap(ColorMap colorMap); void setColorMap(ColorMap colorMap);
//! @resetAcFn{DataSyncViewModel::colorMap}
void resetColorMap(); void resetColorMap();
private Q_SLOTS:
void showImportDialog(QtDataSync::LoginRequest request);
void showImportAccepted();
void showAccessGranted(const QUuid &id);
void triggerGranted(const QList<QtDataSync::DeviceInfo> &devices);
Q_SIGNALS: Q_SIGNALS:
//! @notifyAcFn{DataSyncViewModel::syncManager}
void syncManagerChanged(QtDataSync::SyncManager* syncManager); void syncManagerChanged(QtDataSync::SyncManager* syncManager);
//! @notifyAcFn{DataSyncViewModel::accountManager}
void accountManagerChanged(QtDataSync::AccountManager* accountManager); void accountManagerChanged(QtDataSync::AccountManager* accountManager);
//! @notifyAcFn{DataSyncViewModel::colorMap}
void colorMapChanged(ColorMap colorMap); void colorMapChanged(ColorMap colorMap);
//! @notifyAcFn{DataSyncViewModel::statusString}
void statusStringChanged(); void statusStringChanged();
//! Is emitted as soon as all the datasync managers have been initialized
void ready(); void ready();
protected: protected:
void onInit(const QVariantHash &params) override; void onInit(const QVariantHash &params) override;
void onResult(quint32 requestCode, const QVariant &result) override; void onResult(quint32 requestCode, const QVariant &result) override;
private Q_SLOTS:
void showImportDialog(QtDataSync::LoginRequest request);
void showImportAccepted();
void showAccessGranted(const QUuid &id);
void triggerGranted(const QList<QtDataSync::DeviceInfo> &devices);
private: private:
QScopedPointer<DataSyncViewModelPrivate> d; QScopedPointer<DataSyncViewModelPrivate> d;
}; };

20
src/mvvmdatasynccore/exchangedevicesmodel.h

@ -11,35 +11,47 @@
namespace QtMvvm { namespace QtMvvm {
class ExchangeDevicesModelPrivate; class ExchangeDevicesModelPrivate;
//! A list model implementation to show all devices available by the QtDataSync::UserExchangeManager
class Q_MVVMDATASYNCCORE_EXPORT ExchangeDevicesModel : public QAbstractListModel class Q_MVVMDATASYNCCORE_EXPORT ExchangeDevicesModel : public QAbstractListModel
{ {
Q_OBJECT Q_OBJECT
public: public:
//! The model roles this model provides
enum Roles { enum Roles {
NameRole = Qt::DisplayRole, NameRole = Qt::DisplayRole, //!< The local name of the device. The role name is `name`
HostRole = Qt::UserRole + 1, HostRole = Qt::UserRole + 1, //!< The host name (IP address) of the device. The role name is `host`
PortRole, PortRole, //!< The port the device is bound to. The role name is `port`
AddressRole AddressRole //!< A full, readable address of the device (Host+Port). The role name is `address`
}; };
Q_ENUM(Roles) Q_ENUM(Roles)
//! Default constructor
explicit ExchangeDevicesModel(QObject *parent = nullptr); explicit ExchangeDevicesModel(QObject *parent = nullptr);
~ExchangeDevicesModel(); ~ExchangeDevicesModel();
//! Setups up the model to use the exchange manager. Automatically displays all devices of the manager
Q_INVOKABLE void setup(QtDataSync::UserExchangeManager *exchangeManager); Q_INVOKABLE void setup(QtDataSync::UserExchangeManager *exchangeManager);
//! Returns the user info at the given index
Q_INVOKABLE QtDataSync::UserInfo infoAt(const QModelIndex &index) const; Q_INVOKABLE QtDataSync::UserInfo infoAt(const QModelIndex &index) const;
//! @copybrief infoAt(const QModelIndex &) const
Q_INVOKABLE inline QtDataSync::UserInfo infoAt(int row) const { Q_INVOKABLE inline QtDataSync::UserInfo infoAt(int row) const {
return infoAt(index(row)); return infoAt(index(row));
} }
//! @inherit{QAbstractListModel::headerData}
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
//! @inherit{QAbstractListModel::rowCount}
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
//! @inherit{QAbstractListModel::columnCount}
int columnCount(const QModelIndex &parent) const override; int columnCount(const QModelIndex &parent) const override;
//! @inherit{QAbstractListModel::data}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
//! @inherit{QAbstractListModel::roleNames}
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
//! returns a localized string of the user infos address and port, combined to one
static QString fullAddress(const QtDataSync::UserInfo &userInfo); static QString fullAddress(const QtDataSync::UserInfo &userInfo);
private Q_SLOTS: private Q_SLOTS:

6
src/mvvmdatasynccore/networkexchangeviewmodel.cpp

@ -43,6 +43,11 @@ NetworkExchangeViewModel::NetworkExchangeViewModel(QObject *parent) :
NetworkExchangeViewModel::~NetworkExchangeViewModel() {} NetworkExchangeViewModel::~NetworkExchangeViewModel() {}
UserExchangeManager *NetworkExchangeViewModel::userExchangeManager() const
{
return d->exchangeManager;
}
quint16 NetworkExchangeViewModel::port() const quint16 NetworkExchangeViewModel::port() const
{ {
return d->port; return d->port;
@ -135,6 +140,7 @@ void NetworkExchangeViewModel::onInit(const QVariantHash &params)
connect(d->exchangeManager, &UserExchangeManager::activeChanged, connect(d->exchangeManager, &UserExchangeManager::activeChanged,
this, &NetworkExchangeViewModel::activeChanged); this, &NetworkExchangeViewModel::activeChanged);
emit userExchangeManagerChanged(d->exchangeManager);
emit deviceNameChanged(deviceName()); emit deviceNameChanged(deviceName());
d->deviceModel->setup(d->exchangeManager); d->deviceModel->setup(d->exchangeManager);

30
src/mvvmdatasynccore/networkexchangeviewmodel.h

@ -14,45 +14,75 @@
namespace QtMvvm { namespace QtMvvm {
class NetworkExchangeViewModelPrivate; class NetworkExchangeViewModelPrivate;
//! A viewmodel to show a dialog to exchange account data via the QtDataSync::UserExchangeManager
class Q_MVVMDATASYNCCORE_EXPORT NetworkExchangeViewModel : public ViewModel class Q_MVVMDATASYNCCORE_EXPORT NetworkExchangeViewModel : public ViewModel
{ {
Q_OBJECT Q_OBJECT
//! The user exchange manager the viewmodel operates on
Q_PROPERTY(QtDataSync::UserExchangeManager* userExchangeManager READ userExchangeManager NOTIFY userExchangeManagerChanged)
//! The port to run the exchange on
Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged) Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged)
//! The name of your current device
Q_PROPERTY(QString deviceName READ deviceName WRITE setDeviceName NOTIFY deviceNameChanged) Q_PROPERTY(QString deviceName READ deviceName WRITE setDeviceName NOTIFY deviceNameChanged)
//! Start or stop the network exchange
Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged)
//! The devices model to be used to display found exchange devices
Q_PROPERTY(ExchangeDevicesModel* deviceModel READ deviceModel CONSTANT) Q_PROPERTY(ExchangeDevicesModel* deviceModel READ deviceModel CONSTANT)
//! A sorted version of the devices model
Q_PROPERTY(QSortFilterProxyModel* sortedModel READ sortedModel CONSTANT) Q_PROPERTY(QSortFilterProxyModel* sortedModel READ sortedModel CONSTANT)
public: public:
//! The parameter for a setup name for the onInit() method
static const QString paramSetup; static const QString paramSetup;
//! The parameter for an QtDataSync::AccountManager for the onInit() method
static const QString paramAccountManager; static const QString paramAccountManager;
//! Generates show parameter to show a network exchange viewmodel via ViewModel::show
static QVariantHash showParams(const QString &setup); static QVariantHash showParams(const QString &setup);
//! @copybrief showParams(const QString &)
static QVariantHash showParams(QtDataSync::AccountManager *accountManager); static QVariantHash showParams(QtDataSync::AccountManager *accountManager);
//! Invokable constructor
Q_INVOKABLE explicit NetworkExchangeViewModel(QObject *parent = nullptr); Q_INVOKABLE explicit NetworkExchangeViewModel(QObject *parent = nullptr);
~NetworkExchangeViewModel(); ~NetworkExchangeViewModel();
//! @readAcFn{NetworkExchangeViewModel::userExchangeManager}
QtDataSync::UserExchangeManager* userExchangeManager() const;
//! @readAcFn{NetworkExchangeViewModel::port}
quint16 port() const; quint16 port() const;
//! @readAcFn{NetworkExchangeViewModel::deviceName}
QString deviceName() const; QString deviceName() const;
//! @readAcFn{NetworkExchangeViewModel::active}
bool active() const; bool active() const;
//! @readAcFn{NetworkExchangeViewModel::deviceModel}
ExchangeDevicesModel* deviceModel() const; ExchangeDevicesModel* deviceModel() const;
//! @readAcFn{NetworkExchangeViewModel::sortedModel}
QSortFilterProxyModel* sortedModel() const; QSortFilterProxyModel* sortedModel() const;
public Q_SLOTS: public Q_SLOTS:
//! Start en export of user data to the device with the given index in the sorted model
void exportTo(int sortedIndex); void exportTo(int sortedIndex);
//! @writeAcFn{NetworkExchangeViewModel::port}
void setPort(quint16 port); void setPort(quint16 port);
//! @writeAcFn{NetworkExchangeViewModel::deviceName}
void setDeviceName(QString deviceName); void setDeviceName(QString deviceName);
//! @writeAcFn{NetworkExchangeViewModel::active}
void setActive(bool active); void setActive(bool active);
Q_SIGNALS: Q_SIGNALS:
//! Is emitted as soon as all the user exchange manager has been initialized
void ready(); void ready();
//! @notifyAcFn{NetworkExchangeViewModel::userExchangeManager}
void userExchangeManagerChanged(QtDataSync::UserExchangeManager* userExchangeManager);
//! @notifyAcFn{NetworkExchangeViewModel::port}
void portChanged(quint16 port); void portChanged(quint16 port);
//! @notifyAcFn{NetworkExchangeViewModel::deviceName}
void deviceNameChanged(QString deviceName); void deviceNameChanged(QString deviceName);
//! @notifyAcFn{NetworkExchangeViewModel::active}
void activeChanged(bool active); void activeChanged(bool active);
protected: protected:

Loading…
Cancel
Save