insilmaril@795
|
1 |
|
insilmaril@795
|
2 |
#include "attributeitem.h"
|
insilmaril@795
|
3 |
|
insilmaril@795
|
4 |
#include <iostream>
|
insilmaril@795
|
5 |
using namespace std;
|
insilmaril@795
|
6 |
|
insilmaril@795
|
7 |
extern bool debug;
|
insilmaril@795
|
8 |
|
insilmaril@822
|
9 |
AttributeItem::AttributeItem(const QList<QVariant> &data, TreeItem *parent):BranchItem (data,parent)
|
insilmaril@795
|
10 |
{
|
insilmaril@795
|
11 |
TreeItem::setType (Attribute);
|
insilmaril@795
|
12 |
internal=false;
|
insilmaril@795
|
13 |
}
|
insilmaril@795
|
14 |
|
insilmaril@795
|
15 |
AttributeItem::~AttributeItem()
|
insilmaril@795
|
16 |
{
|
insilmaril@795
|
17 |
}
|
insilmaril@795
|
18 |
|
insilmaril@823
|
19 |
void AttributeItem::set (const QString &k, const QString &v, const Type &t)
|
insilmaril@823
|
20 |
{
|
insilmaril@823
|
21 |
key=k;
|
insilmaril@823
|
22 |
value=QVariant (v);
|
insilmaril@823
|
23 |
setHeading (QString ("K: %1 | V: %2").arg(key).arg(value.toString()));
|
insilmaril@823
|
24 |
}
|
insilmaril@823
|
25 |
|
insilmaril@823
|
26 |
void AttributeItem::get (QString &k, QString &v, Type &t)
|
insilmaril@823
|
27 |
{
|
insilmaril@823
|
28 |
k=key;
|
insilmaril@823
|
29 |
v=value.toString();
|
insilmaril@823
|
30 |
t=attrType;
|
insilmaril@823
|
31 |
}
|
insilmaril@823
|
32 |
|
insilmaril@795
|
33 |
void AttributeItem::setKey (const QString &k, const Type &t)
|
insilmaril@795
|
34 |
{
|
insilmaril@795
|
35 |
/*
|
insilmaril@795
|
36 |
if (!table)
|
insilmaril@795
|
37 |
{
|
insilmaril@795
|
38 |
qWarning (QString("AttributeItem::setKey (%1) No table defined!\n").arg(k).ascii());
|
insilmaril@795
|
39 |
return;
|
insilmaril@795
|
40 |
}
|
insilmaril@795
|
41 |
|
insilmaril@795
|
42 |
if (!definition)
|
insilmaril@795
|
43 |
{
|
insilmaril@795
|
44 |
definition=table->getDef(k);
|
insilmaril@795
|
45 |
if (!definition)
|
insilmaril@795
|
46 |
{
|
insilmaril@795
|
47 |
table->addKey (k,t);
|
insilmaril@795
|
48 |
return;
|
insilmaril@795
|
49 |
}
|
insilmaril@795
|
50 |
}
|
insilmaril@795
|
51 |
qWarning (QString("AttributeItem::setKey (%1) attribute already defined!\n").arg(k).ascii());
|
insilmaril@795
|
52 |
*/
|
insilmaril@795
|
53 |
}
|
insilmaril@795
|
54 |
|
insilmaril@795
|
55 |
QString AttributeItem::getKey ()
|
insilmaril@795
|
56 |
{
|
insilmaril@795
|
57 |
/*
|
insilmaril@795
|
58 |
if (!table)
|
insilmaril@795
|
59 |
{
|
insilmaril@795
|
60 |
qWarning ("AttributeItem::getKey () No table defined!");
|
insilmaril@795
|
61 |
return QString();
|
insilmaril@795
|
62 |
}
|
insilmaril@795
|
63 |
if (!definition)
|
insilmaril@795
|
64 |
{
|
insilmaril@795
|
65 |
qWarning ("AttributeItem::getKey () No attribute defined!");
|
insilmaril@795
|
66 |
return QString ();
|
insilmaril@795
|
67 |
}
|
insilmaril@795
|
68 |
return definition->getKey();
|
insilmaril@795
|
69 |
*/
|
insilmaril@795
|
70 |
}
|
insilmaril@795
|
71 |
|
insilmaril@795
|
72 |
void AttributeItem::setValue(const QString &v)
|
insilmaril@795
|
73 |
{
|
insilmaril@795
|
74 |
/*
|
insilmaril@795
|
75 |
if (!table)
|
insilmaril@795
|
76 |
{
|
insilmaril@795
|
77 |
qWarning (QString ("AttributeItem::setValue (%1) No table defined!").arg(v));
|
insilmaril@795
|
78 |
return;
|
insilmaril@795
|
79 |
}
|
insilmaril@795
|
80 |
if (!definition)
|
insilmaril@795
|
81 |
{
|
insilmaril@795
|
82 |
qWarning (QString ("AttributeItem::setValue (%1) No attribute defined!").arg(v));
|
insilmaril@795
|
83 |
return;
|
insilmaril@795
|
84 |
}
|
insilmaril@795
|
85 |
definition->setValue (v);
|
insilmaril@795
|
86 |
*/
|
insilmaril@795
|
87 |
}
|
insilmaril@795
|
88 |
|
insilmaril@795
|
89 |
QVariant AttributeItem::getValue()
|
insilmaril@795
|
90 |
{
|
insilmaril@795
|
91 |
/*
|
insilmaril@795
|
92 |
if (!table)
|
insilmaril@795
|
93 |
{
|
insilmaril@795
|
94 |
qWarning ("AttributeItem::getValue No table defined!");
|
insilmaril@795
|
95 |
return QString();
|
insilmaril@795
|
96 |
}
|
insilmaril@795
|
97 |
if (!definition)
|
insilmaril@795
|
98 |
{
|
insilmaril@795
|
99 |
qWarning ("AttributeItem::getValue No attribute defined!");
|
insilmaril@795
|
100 |
return QString();
|
insilmaril@795
|
101 |
}
|
insilmaril@795
|
102 |
QVariant v= definition->getValue();
|
insilmaril@795
|
103 |
return v;
|
insilmaril@795
|
104 |
*/
|
insilmaril@795
|
105 |
}
|
insilmaril@795
|
106 |
|
insilmaril@795
|
107 |
void AttributeItem::setType (const Type &t)
|
insilmaril@795
|
108 |
{
|
insilmaril@795
|
109 |
/*
|
insilmaril@795
|
110 |
if (!table)
|
insilmaril@795
|
111 |
{
|
insilmaril@795
|
112 |
qWarning ("AttributeItem::setType No table defined!");
|
insilmaril@795
|
113 |
return;
|
insilmaril@795
|
114 |
}
|
insilmaril@795
|
115 |
if (!definition)
|
insilmaril@795
|
116 |
{
|
insilmaril@795
|
117 |
qWarning ("Attribute::setType No attribute defined!");
|
insilmaril@795
|
118 |
return;
|
insilmaril@795
|
119 |
}
|
insilmaril@795
|
120 |
definition->setType (t);
|
insilmaril@795
|
121 |
*/
|
insilmaril@795
|
122 |
}
|
insilmaril@795
|
123 |
|
insilmaril@795
|
124 |
AttributeItem::Type AttributeItem::getAttributeType()
|
insilmaril@795
|
125 |
{
|
insilmaril@795
|
126 |
/*
|
insilmaril@795
|
127 |
if (!table)
|
insilmaril@795
|
128 |
{
|
insilmaril@795
|
129 |
qWarning ("AttributeItem::getType No table defined!");
|
insilmaril@795
|
130 |
return Undefined;
|
insilmaril@795
|
131 |
}
|
insilmaril@795
|
132 |
if (!definition)
|
insilmaril@795
|
133 |
{
|
insilmaril@795
|
134 |
qWarning ("AttributeItem::getType No attribute defined!");
|
insilmaril@795
|
135 |
return Undefined;
|
insilmaril@795
|
136 |
}
|
insilmaril@795
|
137 |
return definition->getType();
|
insilmaril@795
|
138 |
*/
|
insilmaril@795
|
139 |
}
|
insilmaril@795
|
140 |
|
insilmaril@795
|
141 |
QString AttributeItem::getTypeString()
|
insilmaril@795
|
142 |
{
|
insilmaril@795
|
143 |
/*
|
insilmaril@795
|
144 |
if (!table)
|
insilmaril@795
|
145 |
{
|
insilmaril@795
|
146 |
qWarning ("AttributeItem::getTypeString No table defined!");
|
insilmaril@795
|
147 |
return "Undefined";
|
insilmaril@795
|
148 |
}
|
insilmaril@795
|
149 |
if (!definition)
|
insilmaril@795
|
150 |
{
|
insilmaril@795
|
151 |
qWarning ("Attribute::getTypeString No AttributeItem defined!");
|
insilmaril@795
|
152 |
return "Undefined";
|
insilmaril@795
|
153 |
}
|
insilmaril@795
|
154 |
return definition->getTypeString();
|
insilmaril@795
|
155 |
*/
|
insilmaril@795
|
156 |
}
|
insilmaril@795
|
157 |
|
insilmaril@823
|
158 |
void AttributeItem::setInternal(bool b)
|
insilmaril@823
|
159 |
{
|
insilmaril@823
|
160 |
internal=b;
|
insilmaril@823
|
161 |
}
|
insilmaril@823
|
162 |
|
insilmaril@823
|
163 |
bool AttributeItem::isInternal()
|
insilmaril@823
|
164 |
{
|
insilmaril@823
|
165 |
return internal;
|
insilmaril@823
|
166 |
}
|
insilmaril@823
|
167 |
|
insilmaril@795
|
168 |
QString AttributeItem::getDataXML()
|
insilmaril@795
|
169 |
{
|
insilmaril@795
|
170 |
QString a=beginElement ("attribute");
|
insilmaril@795
|
171 |
a+=attribut ("key",getKey());
|
insilmaril@795
|
172 |
a+=attribut ("value",getValue().toString() );
|
insilmaril@795
|
173 |
a+=attribut ("type",getTypeString () );
|
insilmaril@795
|
174 |
return a;
|
insilmaril@795
|
175 |
}
|
insilmaril@795
|
176 |
|