-
Notifications
You must be signed in to change notification settings - Fork 104
/
qscadaconfig.h
120 lines (98 loc) · 2.98 KB
/
qscadaconfig.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef CONFIG_H
#define CONFIG_H
#include <QList>
#include <QStringList>
#include <QDirIterator>
#include <QDebug>
#define DEFAULT_QML_PATH ":/com/indeema/eeiot/EEIoT/"
struct QMLInfo {
QString groupTitle = "";
QString groupPath = "";
};
Q_DECLARE_METATYPE(QMLInfo)
struct QMLWidgetsConfig {
QMLInfo info;
bool isValid = false;
QStringList widgets() {
return mQMLWidgets;
}
QMLWidgetsConfig() {}
QMLWidgetsConfig(QString path) {
if (!path.isEmpty()) {
QDir directory(path);
// Load all files with the *.PNG extension
// (you can modify this to suit your needs.
QStringList lQMLList = directory.entryList(QStringList("*.qml"));
if (lQMLList.count() > 0) {
mQMLWidgets = lQMLList;
info.groupPath = path;
isValid = true;
QString lTmpTitle = path.split('/').last();
//let secure from having / at end or not having
if (lTmpTitle.isEmpty()) {
info.groupTitle = path.split('/').at(path.split('/').count()-2);
} else {
info.groupTitle = lTmpTitle;
}
}
}
}
private:
QStringList mQMLWidgets;
};
Q_DECLARE_METATYPE(QMLWidgetsConfig)
class QMLConfig
{
private:
QMLConfig() {
appendQMLPath(DEFAULT_QML_PATH);
}
QMLConfig(const QMLConfig&) {}
QMLConfig& instance(const QMLConfig&) {
return *this;
}
public:
static QMLConfig & instance() {
static QMLConfig * _instance = nullptr;
if (_instance == nullptr) {
_instance = new QMLConfig();
}
return *_instance;
}
void appendQMLPath(QString path) {
QMLWidgetsConfig lConf(path);
if (lConf.isValid) {
//check if QML group is unique.
//if it's already in list, it will be replaced with new
for (int i=0; i < mQMLWidgets.count(); i++) {
QMLWidgetsConfig tmpConf = mQMLWidgets.at(i);
if (tmpConf.info.groupTitle == lConf.info.groupTitle) {
mQMLWidgets.removeAt(i);
}
}
mQMLWidgets.append(lConf);
}
}
QMLWidgetsConfig qmlWidgetConfForGroup(QString qmlGroupTitle) {
QMLWidgetsConfig rConf;
for (QMLWidgetsConfig tmpConf : mQMLWidgets) {
if (qmlGroupTitle == tmpConf.info.groupTitle) {
rConf = tmpConf;
}
}
return rConf;
}
QList<QMLWidgetsConfig> QMLWidgets(){
return mQMLWidgets;
}
private:
QList<QMLWidgetsConfig> mQMLWidgets;
};
enum QScadaStatus {
QScadaStatusDefault,
QScadaStatusGray,
QScadaStatusGreen,
QScadaStatusYellow,
QScadaStatusRed
};
#endif // CONFIG_H