diff -r 96c8e6860e0c -r 6a5e2c27f8a4 attribute.cpp --- a/attribute.cpp Tue Dec 04 12:32:56 2007 +0000 +++ b/attribute.cpp Fri Feb 01 15:28:35 2008 +0000 @@ -1,34 +1,135 @@ +#include + #include "attribute.h" +using namespace std; + +extern bool debug; + Attribute::Attribute() { - key=""; - value=""; + table=NULL; + definition=NULL; } -void Attribute::setKey (const QString &k) +void Attribute::setKey (const QString &k, const AttributeType &t) { - key=k; + if (!table) + { + qWarning (QString("Attribute::setKey (%1) No table defined!\n").arg(k).ascii()); + 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).ascii()); } QString Attribute::getKey () { - return key; + 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) { - value=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); } -QString Attribute::getValue() +QVariant Attribute::getValue() { - return value; + 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) { - table=at; + if (at) + table=at; + else + qWarning ("Attribute::setTable table==NULL"); + } AttributeTable* Attribute::getTable() @@ -38,76 +139,142 @@ QString Attribute::getDataXML() { - return valueElement ("attribute",key,value); + 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 &v) +{ +} + +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() { - clear(); } AttributeTable::~AttributeTable() { + clear(); } void AttributeTable::clear () { - keys.clear(); - values.clear(); + attdefs.clear(); } -void AttributeTable::addKey (const QString &k) +AttributeDef* AttributeTable::addKey (const QString &k, const AttributeType &t) { - if (!keys.contains (k) ) + for (int i=0; igetKey()==k ) + { + qWarning (QString ("AttributeTable::addKey (%1) already in table\n").arg(k).ascii()); + return NULL; + } } + AttributeDef *ad=new AttributeDef; + ad->setKey (k); + ad->setType (t); + attdefs.append (ad); + return ad; } void AttributeTable::removeKey (const QString &k) { - int i=keys.indexOf (k); - if (i>=0) + for (int i=0; igetKey()==k ) + { + + delete (attdefs.at(i)); + attdefs.removeAt (i); + return ; + } } + qWarning (QString ("AttributeTable::removeKey (%1) key not in table\n").arg(k).ascii()); +} + +AttributeDef* AttributeTable::getDef(const QString &k) +{ + for (int i=0; igetKey()==k ) return attdefs.at(i); + qWarning (QString ("AttributeTable::getDef (%1) key not in table\n").arg(k).ascii()); + return NULL; } int AttributeTable::countKeys() { - return keys.count(); -} - -void AttributeTable::addValue (const QString &k, const QString &v) -{ - int i=keys.indexOf (k); - if (i<0) - { - keys.append (k); - values.append (QStringList (v)); - } else - { - int j=values.at(i).indexOf(k); - if (j<0) values[i].append (QString(v)); - } + return attdefs.count(); } QStringList AttributeTable::getKeys () { - return keys; -} - -QStringList AttributeTable::getValues(const QString &k) -{ - int i=keys.indexOf (k); - if (i>=0) - return values.at(i); - else - return QStringList(); + QStringList kl; + for (int i=0; igetKey()); + return kl; } QString AttributeTable::getDataXML()