-
Notifications
You must be signed in to change notification settings - Fork 6
/
attribute.cpp
296 lines (257 loc) · 5.42 KB
/
attribute.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
#include <iostream>
#include <QDebug>
#include "attribute.h"
using namespace std;
extern bool debug;
Attribute::Attribute()
{
table=NULL;
definition=NULL;
}
void Attribute::setKey (const QString &k, const AttributeType &t)
{
if (!table)
{
qWarning ()<< QString("Attribute::setKey (%1) No table defined!\n").arg(k).toUtf8();
return;
}
if (!definition)
{
definition=table->getDef(k);
if (!definition)
{
table->addKey (k,t);
return;
}
}
qWarning ()<< QString("Attribute::setKey (%1) attribute already defined!\n").arg(k).toUtf8();
}
QString Attribute::getKey ()
{
if (!table)
{
qWarning ("Attribute::getKey () No table defined!");
return QString();
}
if (!definition)
{
qWarning ("Attribute::getKey () No attribute defined!");
return QString ();
}
return definition->getKey();
}
void Attribute::setValue(const QString &v)
{
if (!table)
{
qWarning ()<<QString ("Attribute::setValue (%1) No table defined!").arg(v);
return;
}
if (!definition)
{
qWarning ()<<QString ("Attribute::setValue (%1) No attribute defined!").arg(v);
return;
}
definition->setValue (v);
}
QVariant Attribute::getValue()
{
if (!table)
{
qWarning ("Attribute::getValue No table defined!");
return QString();
}
if (!definition)
{
qWarning()<<"Attribute::getValue No attribute defined!";
return QString();
}
QVariant v= definition->getValue();
return v;
}
void Attribute::setType (const AttributeType &t)
{
if (!table)
{
qWarning ()<<"Attribute::setType No table defined!";
return;
}
if (!definition)
{
qWarning()<<"Attribute::setType No attribute defined!";
return;
}
definition->setType (t);
}
AttributeType Attribute::getType()
{
if (!table)
{
qWarning ()<<"Attribute::getType No table defined!";
return Undefined;
}
if (!definition)
{
qWarning ()<<"Attribute::getType No attribute defined!";
return Undefined;
}
return definition->getType();
}
QString Attribute::getTypeString()
{
if (!table)
{
qWarning ()<<"Attribute::getTypeString No table defined!";
return "Undefined";
}
if (!definition)
{
qWarning ()<<"Attribute::getTypeString No attribute defined!";
return "Undefined";
}
return definition->getTypeString();
}
void Attribute::setTable (AttributeTable *at)
{
if (at)
table=at;
else
qWarning ()<<"Attribute::setTable table==NULL";
}
AttributeTable* Attribute::getTable()
{
return table;
}
QString Attribute::getDataXML()
{
QString a=beginElement ("attribute");
a+=attribut ("key",getKey());
a+=attribut ("value",getValue().toString() );
a+=attribut ("type",getTypeString () );
return a;
}
///////////////////////////////////////////////////////////////
AttributeDef::AttributeDef()
{
}
AttributeDef::~AttributeDef()
{
}
void AttributeDef::setType (const AttributeType &t)
{
type=t;
}
AttributeType AttributeDef::getType ()
{
return type;
}
QString AttributeDef::getTypeString ()
{
if (type==StringList)
return "StringList";
else if (type==FreeString)
return "FreeString";
else if (type==UniqueString)
return "UniqueString";
return "Undefined";
}
void AttributeDef::setKey (const QString &k)
{
key=k;
}
void AttributeDef::setValue (const QString &)
{
}
void AttributeDef::setValue (const QVariant &v)
{
if (type==Undefined)
qWarning ()<<"AttributeDef::setValue No type defined!";
else if (type==StringList)
value=v;
else if (type==UniqueString)
value=v;
else
qWarning ()<<"AttributeDef::setValue Unknown type???";
}
QVariant AttributeDef::getValue ()
{
return QVariant ();
}
QString AttributeDef::getKey ()
{
return key;
}
///////////////////////////////////////////////////////////////
AttributeTable::AttributeTable()
{
typeList
<< "Undefined"
<< "IntList"
<< "FreeInt"
<< "StringList"
<< "FreeString"
<< "UniqueString";
}
AttributeTable::~AttributeTable()
{
clear();
}
void AttributeTable::clear ()
{
attdefs.clear();
}
AttributeDef* AttributeTable::addKey (const QString &k, const AttributeType &t)
{
for (int i=0; i<attdefs.count();++i)
{
if (attdefs.at(i)->getKey()==k )
{
qWarning () << QString ("AttributeTable::addKey (%1) already in table\n").arg(k).toUtf8();
return NULL;
}
}
AttributeDef *ad=new AttributeDef;
ad->setKey (k);
ad->setType (t);
attdefs.append (ad);
return ad;
}
void AttributeTable::removeKey (const QString &k)
{
for (int i=0; i<attdefs.count();++i)
{
if (attdefs.at(i)->getKey()==k )
{
delete (attdefs.at(i));
attdefs.removeAt (i);
return ;
}
}
qWarning () << QString ("AttributeTable::removeKey (%1) key not in table\n").arg(k).toUtf8();
}
AttributeDef* AttributeTable::getDef(const QString &key)
{
for (int i=0; i<attdefs.count();++i)
if (attdefs.at(i)->getKey()==key ) return attdefs.at(i);
qWarning () << QString ("AttributeTable::getDef (%1) key not in table\n").arg(key).toUtf8();
return NULL;
}
int AttributeTable::countKeys()
{
return attdefs.count();
}
QStringList AttributeTable::getKeys ()
{
QStringList kl;
for (int i=0; i<attdefs.count();i++)
kl.append (attdefs.at(i)->getKey());
return kl;
}
QStringList AttributeTable::getTypes ()
{
return typeList;
}
QString AttributeTable::getDataXML()
{
return valueElement ("attributeList","key","value");
}