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