# HG changeset patch # User insilmaril # Date 1199717569 0 # Node ID f83abc1f75b4f96de740e78dc9e643b98604028a # Parent 459f0a2d5485482a0e8e39ea4a2fa6602be0923d Included french in vym.pro diff -r 459f0a2d5485 -r f83abc1f75b4 aboutdialog.cpp --- a/aboutdialog.cpp Mon Dec 17 15:40:14 2007 +0000 +++ b/aboutdialog.cpp Mon Jan 07 14:52:49 2008 +0000 @@ -39,19 +39,44 @@ "" "" "
  • Credits " "" "
  • "); credits->setFrameStyle( QFrame::Panel | QFrame::Plain ); diff -r 459f0a2d5485 -r f83abc1f75b4 attribute.cpp --- a/attribute.cpp Mon Dec 17 15:40:14 2007 +0000 +++ b/attribute.cpp Mon Jan 07 14:52:49 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() diff -r 459f0a2d5485 -r f83abc1f75b4 attribute.h --- a/attribute.h Mon Dec 17 15:40:14 2007 +0000 +++ b/attribute.h Mon Jan 07 14:52:49 2008 +0000 @@ -2,50 +2,85 @@ #define ATTRIBUTE_H #include +#include #include "xmlobj.h" class AttributeTable; +class AttributeDef; -/*! \brief A key and a value +enum AttributeType { + Undefined, //!< Undefined type + StringList, //!< List of strings, one can be attribute value + FreeString, //!< Any string can be attribute value, not unique + UniqueString//!< UniqueString, e.g. for IDs +}; + +/*! \brief A key and a value + The data itself is stored in Attribute Definitions (AttributeDef). A list of these tables + AttributeTable is maintained for every MapEditor. */ - class Attribute:public XMLObj { public: Attribute(); - void setKey (const QString &k); + void setKey (const QString &k, const AttributeType &t); QString getKey (); void setValue (const QString &v); - QString getValue(); + QVariant getValue (); + void setType (const AttributeType &t); + AttributeType getType (); + QString getTypeString (); void setTable (AttributeTable *at); AttributeTable* getTable(); QString getDataXML(); protected: + AttributeTable *table; + AttributeDef *definition; + QString freeString; //!< String value for type FreeString +}; + + +/*! \brief + Attribute definition, defines possible values and type of attribute. +*/ +class AttributeDef { +public: + AttributeDef(); + ~AttributeDef(); + void setType (const AttributeType &t); + AttributeType getType(); + QString getTypeString (); + void setKey (const QString &k); + QString getKey (); + void setValue (const QString &v); + void setValue (const QVariant &v); + QVariant getValue (); +private: QString key; - QString value; - AttributeTable *table; + AttributeType type; + + QVariant value; //!< value (except FreeString, FreeInt ... }; /*! \brief A table containing a list of keys and each of these keys has a list of default values. The keys and the values for each key are unique. */ + class AttributeTable:public XMLObj{ public: AttributeTable(); ~AttributeTable(); void clear(); - void addKey (const QString &k); //!< Adds a key to the table + AttributeDef* addKey (const QString &k, const AttributeType &t); //!< Adds a key to the table void removeKey (const QString &k); //!< Removes key and its default values + AttributeDef* getDef(const QString &k); //!< Get defintion of attribute int countKeys(); //!< Return number of keys - void addValue (const QString &k, const QString &v); //!< Adds key and value QStringList getKeys (); - QStringList getValues(const QString &k); QString getDataXML(); protected: - QStringList keys; - QList values; + QList attdefs; };