-
Notifications
You must be signed in to change notification settings - Fork 0
/
point.cpp
129 lines (110 loc) · 3.65 KB
/
point.cpp
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
121
122
123
124
125
126
127
128
129
#include "point.h"
#include <QVariant>
#include <QMetaEnum>
#include <QString>
QString PointInfo::toString(const PointInfo::Type& type) {
return QVariant::fromValue(type).toString();
}
PointInfo::Type PointInfo::typeFromString(const QString& type) {
auto e = QMetaEnum::fromType<PointInfo::Type>();
return static_cast<PointInfo::Type>(e.keyToValue(qUtf8Printable(type)));
}
const QVector<PointInfo::Type> PointInfo::point_types = []() {
auto e = QMetaEnum::fromType<PointInfo::Type>();
QVector<PointInfo::Type> result;
for (int i = 0; i < e.keyCount(); ++i) {
result.append(static_cast<PointInfo::Type>(e.value(i)));
}
return result;
}();
QString PointInfo::toString(const PointInfo::Parameter& parameter) {
return QVariant::fromValue(parameter).toString();
}
PointInfo::Parameter PointInfo::parameterFromString(const QString& parameter) {
auto e = QMetaEnum::fromType<PointInfo::Parameter>();
return static_cast<PointInfo::Parameter>(e.keyToValue(qUtf8Printable(parameter)));
}
const QVector<PointInfo::Parameter> PointInfo::point_parameters = []() {
auto e = QMetaEnum::fromType<PointInfo::Parameter>();
QVector<PointInfo::Parameter> result;
for (int i = 0; i < e.keyCount(); ++i) {
result.append(static_cast<PointInfo::Parameter>(e.value(i)));
}
return result;
}();
Point::Point(QHash<PointInfo::Parameter, QString> parameters)
: parameters_(parameters) {
const auto& appear_in_file = parameters[PointInfo::Parameter::APPEAR_IN_FILES];
if (!appear_in_file.isEmpty()) {
addToAppearInFiles(appear_in_file);
}
}
const bool& Point::isInDBID() const {
return is_in_dbid;
}
const bool& Point::isInSRC() const {
return is_in_src;
}
const bool& Point::isInXML() const {
return is_in_xml;
}
const bool& Point::isInOPHXML() const {
return is_in_ophxml;
}
const QString Point::operator[](const PointInfo::Parameter& parameter) const {
return parameters_[parameter];
}
QString& Point::operator[](const PointInfo::Parameter& parameter) {
return parameters_[parameter];
}
void Point::addParameters(QHash<PointInfo::Parameter, QString> parameters) {
auto kks = parameters[PointInfo::Parameter::KKS];
if (!kks.isEmpty() && parameters_[PointInfo::Parameter::KKS] == kks) {
for (auto it = parameters.keyValueBegin();
it != parameters.keyValueEnd(); ++it) {
auto parameter = (*it).first;
if (parameter != PointInfo::Parameter::KKS) {
auto value = (*it).second;
if (parameter == PointInfo::Parameter::APPEAR_IN_FILES) {
addToAppearInFiles(value);
} else {
parameters_[parameter] = value;
}
}
}
}
}
void Point::addToAppearInFiles(const QString& appear_in_file) {
if (!appear_in_files_.contains(appear_in_file)) {
if (!is_in_dbid && appear_in_file == "DBID.imp") {
is_in_dbid = true;
} else if (!is_in_src
&& QStringRef(&appear_in_file, appear_in_file.length() - 3, 3)
== "src") {
is_in_src = true;
} else if (!is_in_xml
&& QStringRef(&appear_in_file, appear_in_file.length() - 3, 3)
== "xml") {
is_in_xml = true;
} else if (!is_in_ophxml && appear_in_file == "HistorianConfig.xml") {
is_in_ophxml = true;
}
appear_in_files_.append(appear_in_file);
appear_in_files_.sort();
auto& file_list = parameters_[PointInfo::Parameter::APPEAR_IN_FILES];
if (is_in_dbid) {
file_list = "DBID.imp";
} else {
file_list = "";
}
for (const auto& file : appear_in_files_) {
if (file != "DBID.imp") {
if (!file_list.isEmpty()) {
file_list += ", " + file;
} else {
file_list = file;
}
}
}
}
}