QtMvvm  1.1.0
A mvvm oriented library for Qt, to create Projects for Widgets and Quick in parallel
datasyncviewmodel.h
1 #ifndef QTMVVM_DATASYNCVIEWMODEL_H
2 #define QTMVVM_DATASYNCVIEWMODEL_H
3 
4 #include <QtCore/qmap.h>
5 #include <QtCore/qscopedpointer.h>
6 #include <QtCore/qsortfilterproxymodel.h>
7 
8 #include <QtGui/qcolor.h>
9 
10 #include <QtMvvmCore/viewmodel.h>
11 
12 #include <QtDataSync/syncmanager.h>
13 #include <QtDataSync/accountmanager.h>
14 
15 #include "QtMvvmDataSyncCore/qtmvvmdatasynccore_global.h"
16 #include "QtMvvmDataSyncCore/accountmodel.h"
17 
18 namespace QtMvvm {
19 
20 class DataSyncViewModelPrivate;
22 class Q_MVVMDATASYNCCORE_EXPORT DataSyncViewModel : public ViewModel
23 {
24  Q_OBJECT
25 
27  Q_PROPERTY(QtDataSync::SyncManager* syncManager READ syncManager NOTIFY syncManagerChanged)
29  Q_PROPERTY(QtDataSync::AccountManager* accountManager READ accountManager NOTIFY accountManagerChanged)
30 
32  Q_PROPERTY(ColorMap colorMap READ colorMap WRITE setColorMap RESET resetColorMap NOTIFY colorMapChanged)
34  Q_PROPERTY(QString statusString READ statusString NOTIFY statusStringChanged)
35 
37  Q_PROPERTY(QtMvvm::AccountModel* accountModel READ accountModel CONSTANT)
39  Q_PROPERTY(QSortFilterProxyModel* sortedModel READ sortedModel CONSTANT)
40 
41 public:
43  using ColorMap = QMap<QtDataSync::SyncManager::SyncState, QColor>;
44 
46  static const QString paramSetup;
48  static const QString paramReplicaNode;
49 
51  static QVariantHash showParams(const QString &setup);
53  static QVariantHash showParams(QRemoteObjectNode *node);
54 
56  Q_INVOKABLE explicit DataSyncViewModel(QObject *parent = nullptr);
57  ~DataSyncViewModel() override;
58 
60  QtDataSync::SyncManager* syncManager() const;
62  QtDataSync::AccountManager* accountManager() const;
64  ColorMap colorMap() const;
66  QString statusString() const;
68  AccountModel *accountModel() const;
70  QSortFilterProxyModel* sortedModel() const;
71 
73  Q_INVOKABLE static QString formatFingerPrint(const QByteArray &fingerPrint);
74 
75 public Q_SLOTS:
77  void syncOrConnect();
79  void showDeviceInfo();
81  void startExport();
83  void startImport();
85  void performReset();
87  void changeRemote();
89  void startNetworkExchange();
90 
92  void removeDevice(int sortedIndex);
93 
95  void setColorMap(ColorMap colorMap);
97  void resetColorMap();
98 
99 Q_SIGNALS:
101  void syncManagerChanged(QtDataSync::SyncManager* syncManager, QPrivateSignal);
103  void accountManagerChanged(QtDataSync::AccountManager* accountManager, QPrivateSignal);
105  void colorMapChanged(ColorMap colorMap, QPrivateSignal);
107  void statusStringChanged(QPrivateSignal);
108 
110  void ready(QPrivateSignal);
111 
112 protected:
113  void onInit(const QVariantHash &params) override;
114  void onResult(quint32 requestCode, const QVariant &result) override;
115 
116 private Q_SLOTS:
117  void showImportDialog(QtDataSync::LoginRequest request);
118  void showImportAccepted();
119  void showAccessGranted(const QUuid &id);
120  void triggerGranted(const QList<QtDataSync::DeviceInfo> &devices);
121 
122 private:
123  QScopedPointer<DataSyncViewModelPrivate> d;
124 };
125 
126 }
127 
128 #endif // QTMVVM_DATASYNCVIEWMODEL_H
A list model implementation for QtDataSync::DeviceInfo via a QtDataSync::AccountManager.
Definition: accountmodel.h:16
The base class for all viewmodels.
Definition: viewmodel.h:21
A viewmodel to show a overview of the datasync status and account.
The primary namespace of the QtMvvm library.