-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobaldata.h
52 lines (41 loc) · 1.1 KB
/
globaldata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include <QDebug>
#include <QObject>
#include <QVariantList>
class GlobalData : public QObject {
Q_OBJECT
Q_PROPERTY(QVariantList deviceList READ deviceList WRITE setDeviceList NOTIFY deviceListChanged)
public:
using QObject::QObject;
QVariantList deviceList() const {
return m_deviceList;
}
void setDeviceList(QVariantList val) {
m_deviceList = qMove(val);
emit deviceListChanged();
}
Q_INVOKABLE QVariantMap device(QString uid) const {
for (const auto &dev : m_deviceList) {
if (dev.toMap()["uid"].toString() == uid) {
return dev.toMap();
}
}
return QVariantMap();
}
void setDevice(QString uid, QVariantMap val) {
for (auto &dev : m_deviceList) {
if (dev.toMap()["uid"] == uid) {
dev = qMove(val);
emit deviceListChanged();
break;
}
}
}
signals:
void deviceListChanged();
private:
// TODO
QString m_username;
QString m_token;
QVariantList m_deviceList;
};