diff -r 96c8e6860e0c -r a7db20d79c32 attribute.h --- a/attribute.h Tue Dec 04 12:32:56 2007 +0000 +++ b/attribute.h Fri Feb 01 15:28:35 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; };