-
Notifications
You must be signed in to change notification settings - Fork 0
/
EREssenceData.cpp
180 lines (122 loc) · 2.3 KB
/
EREssenceData.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "EREssenceData.h"
EREssenceData::EREssenceData(QString id, int type)
{
this->id = id;
this->type = type;
}
void EREssenceData::print()
{
qDebug() << "Essence: " << id;
qDebug() << "\tType: " << Support::typeToString(getType());
qDebug() << "\tkeys: " << keys;
qDebug() << "\tattributes: " << attributes;
}
QString EREssenceData::getId() const
{
return id;
}
QString &EREssenceData::getNonConstId()
{
return id;
}
void EREssenceData::setId(const QString & value)
{
id = value;
}
int EREssenceData::getType() const
{
return type;
}
void EREssenceData::setType(const int value)
{
type = value;
}
QList<QString> & EREssenceData::getAttributes()
{
return attributes;
}
void EREssenceData::setAttributes(const QList<QString> & value)
{
this->attributes = value;
}
QList<QString> & EREssenceData::getKeys()
{
return this->keys;
}
void EREssenceData::setKeys(const QList<QString> & value)
{
this->keys = value;
}
bool EREssenceData::addAtribute(QString attr)
{
this->attributes.append(attr);
}
bool EREssenceData::addKey(QString key)
{
if(keys.contains(key) == true)
{
return false;
}
if(attributes.contains(key) == true)
{
return false;
}
keys.append(key);
return true;
}
void EREssenceData::removeKey(QString key)
{
keys.removeOne(key);
}
bool EREssenceData::removeAttributeWithSubStr(QString attr)
{
foreach (QString a, attributes)
{
if(a.lastIndexOf(attr) != -1)
{
attributes.removeOne(a);
return true;
}
}
return false;
}
QList<QString> EREssenceData::getKeysConst()
{
return this->keys;
}
QList<QString> EREssenceData::getAttrsConst()
{
return this->attributes;
}
void EREssenceData::read(const QJsonObject &json)
{
type = json["type"].toInt();
id = json["id"].toString();
QJsonArray jattrs = json["attrs"].toArray();
QJsonArray jkeys = json["keys"].toArray();
for(int i = 0; i < jattrs.size(); i++)
{
attributes.append(jattrs[i].toString());
}
for(int i = 0; i < jkeys.size(); i++)
{
keys.append(jkeys[i].toString());
}
}
void EREssenceData::write(QJsonObject &json) const
{
QJsonArray jattrs;
QJsonArray jkeys;
json["id"] = id;
json["type"] = type;
foreach (QString key, keys)
{
jkeys.append(key);
}
foreach (QString attr, attributes)
{
jattrs.append(attr);
}
json["keys"] = jkeys;
json["attrs"] = jattrs;
}