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@838
|
70 |
return QString();
|
insilmaril@795
|
71 |
}
|
insilmaril@795
|
72 |
|
insilmaril@795
|
73 |
void AttributeItem::setValue(const QString &v)
|
insilmaril@795
|
74 |
{
|
insilmaril@795
|
75 |
/*
|
insilmaril@795
|
76 |
if (!table)
|
insilmaril@795
|
77 |
{
|
insilmaril@795
|
78 |
qWarning (QString ("AttributeItem::setValue (%1) No table defined!").arg(v));
|
insilmaril@795
|
79 |
return;
|
insilmaril@795
|
80 |
}
|
insilmaril@795
|
81 |
if (!definition)
|
insilmaril@795
|
82 |
{
|
insilmaril@795
|
83 |
qWarning (QString ("AttributeItem::setValue (%1) No attribute defined!").arg(v));
|
insilmaril@795
|
84 |
return;
|
insilmaril@795
|
85 |
}
|
insilmaril@795
|
86 |
definition->setValue (v);
|
insilmaril@795
|
87 |
*/
|
insilmaril@795
|
88 |
}
|
insilmaril@795
|
89 |
|
insilmaril@795
|
90 |
QVariant AttributeItem::getValue()
|
insilmaril@795
|
91 |
{
|
insilmaril@795
|
92 |
/*
|
insilmaril@795
|
93 |
if (!table)
|
insilmaril@795
|
94 |
{
|
insilmaril@795
|
95 |
qWarning ("AttributeItem::getValue No table defined!");
|
insilmaril@795
|
96 |
return QString();
|
insilmaril@795
|
97 |
}
|
insilmaril@795
|
98 |
if (!definition)
|
insilmaril@795
|
99 |
{
|
insilmaril@795
|
100 |
qWarning ("AttributeItem::getValue No attribute defined!");
|
insilmaril@795
|
101 |
return QString();
|
insilmaril@795
|
102 |
}
|
insilmaril@795
|
103 |
QVariant v= definition->getValue();
|
insilmaril@795
|
104 |
return v;
|
insilmaril@795
|
105 |
*/
|
insilmaril@838
|
106 |
return QString();
|
insilmaril@795
|
107 |
}
|
insilmaril@795
|
108 |
|
insilmaril@795
|
109 |
void AttributeItem::setType (const Type &t)
|
insilmaril@795
|
110 |
{
|
insilmaril@795
|
111 |
/*
|
insilmaril@795
|
112 |
if (!table)
|
insilmaril@795
|
113 |
{
|
insilmaril@795
|
114 |
qWarning ("AttributeItem::setType No table defined!");
|
insilmaril@795
|
115 |
return;
|
insilmaril@795
|
116 |
}
|
insilmaril@795
|
117 |
if (!definition)
|
insilmaril@795
|
118 |
{
|
insilmaril@795
|
119 |
qWarning ("Attribute::setType No attribute defined!");
|
insilmaril@795
|
120 |
return;
|
insilmaril@795
|
121 |
}
|
insilmaril@795
|
122 |
definition->setType (t);
|
insilmaril@795
|
123 |
*/
|
insilmaril@795
|
124 |
}
|
insilmaril@795
|
125 |
|
insilmaril@795
|
126 |
AttributeItem::Type AttributeItem::getAttributeType()
|
insilmaril@795
|
127 |
{
|
insilmaril@795
|
128 |
/*
|
insilmaril@795
|
129 |
if (!table)
|
insilmaril@795
|
130 |
{
|
insilmaril@795
|
131 |
qWarning ("AttributeItem::getType No table defined!");
|
insilmaril@795
|
132 |
return Undefined;
|
insilmaril@795
|
133 |
}
|
insilmaril@795
|
134 |
if (!definition)
|
insilmaril@795
|
135 |
{
|
insilmaril@795
|
136 |
qWarning ("AttributeItem::getType No attribute defined!");
|
insilmaril@795
|
137 |
return Undefined;
|
insilmaril@795
|
138 |
}
|
insilmaril@795
|
139 |
return definition->getType();
|
insilmaril@795
|
140 |
*/
|
insilmaril@840
|
141 |
return AttributeItem::Undefined;
|
insilmaril@795
|
142 |
}
|
insilmaril@795
|
143 |
|
insilmaril@795
|
144 |
QString AttributeItem::getTypeString()
|
insilmaril@795
|
145 |
{
|
insilmaril@795
|
146 |
/*
|
insilmaril@795
|
147 |
if (!table)
|
insilmaril@795
|
148 |
{
|
insilmaril@795
|
149 |
qWarning ("AttributeItem::getTypeString No table defined!");
|
insilmaril@795
|
150 |
return "Undefined";
|
insilmaril@795
|
151 |
}
|
insilmaril@795
|
152 |
if (!definition)
|
insilmaril@795
|
153 |
{
|
insilmaril@795
|
154 |
qWarning ("Attribute::getTypeString No AttributeItem defined!");
|
insilmaril@795
|
155 |
return "Undefined";
|
insilmaril@795
|
156 |
}
|
insilmaril@795
|
157 |
return definition->getTypeString();
|
insilmaril@795
|
158 |
*/
|
insilmaril@838
|
159 |
return QString();
|
insilmaril@795
|
160 |
}
|
insilmaril@795
|
161 |
|
insilmaril@823
|
162 |
void AttributeItem::setInternal(bool b)
|
insilmaril@823
|
163 |
{
|
insilmaril@823
|
164 |
internal=b;
|
insilmaril@823
|
165 |
}
|
insilmaril@823
|
166 |
|
insilmaril@823
|
167 |
bool AttributeItem::isInternal()
|
insilmaril@823
|
168 |
{
|
insilmaril@823
|
169 |
return internal;
|
insilmaril@823
|
170 |
}
|
insilmaril@823
|
171 |
|
insilmaril@795
|
172 |
QString AttributeItem::getDataXML()
|
insilmaril@795
|
173 |
{
|
insilmaril@795
|
174 |
QString a=beginElement ("attribute");
|
insilmaril@795
|
175 |
a+=attribut ("key",getKey());
|
insilmaril@795
|
176 |
a+=attribut ("value",getValue().toString() );
|
insilmaril@795
|
177 |
a+=attribut ("type",getTypeString () );
|
insilmaril@795
|
178 |
return a;
|
insilmaril@795
|
179 |
}
|
insilmaril@795
|
180 |
|