1.1 --- a/attribute.h Tue Dec 04 12:32:56 2007 +0000
1.2 +++ b/attribute.h Mon Feb 11 12:44:00 2008 +0000
1.3 @@ -2,50 +2,85 @@
1.4 #define ATTRIBUTE_H
1.5
1.6 #include <QStringList>
1.7 +#include <QVariant>
1.8
1.9 #include "xmlobj.h"
1.10
1.11 class AttributeTable;
1.12 +class AttributeDef;
1.13
1.14 -/*! \brief A key and a value
1.15 +enum AttributeType {
1.16 + Undefined, //!< Undefined type
1.17 + StringList, //!< List of strings, one can be attribute value
1.18 + FreeString, //!< Any string can be attribute value, not unique
1.19 + UniqueString//!< UniqueString, e.g. for IDs
1.20 +};
1.21 +
1.22 +/*! \brief A key and a value
1.23 + The data itself is stored in Attribute Definitions (AttributeDef). A list of these tables
1.24 + AttributeTable is maintained for every MapEditor.
1.25 */
1.26 -
1.27 class Attribute:public XMLObj {
1.28 public:
1.29 Attribute();
1.30 - void setKey (const QString &k);
1.31 + void setKey (const QString &k, const AttributeType &t);
1.32 QString getKey ();
1.33 void setValue (const QString &v);
1.34 - QString getValue();
1.35 + QVariant getValue ();
1.36 + void setType (const AttributeType &t);
1.37 + AttributeType getType ();
1.38 + QString getTypeString ();
1.39 void setTable (AttributeTable *at);
1.40 AttributeTable* getTable();
1.41 QString getDataXML();
1.42 protected:
1.43 + AttributeTable *table;
1.44 + AttributeDef *definition;
1.45 + QString freeString; //!< String value for type FreeString
1.46 +};
1.47 +
1.48 +
1.49 +/*! \brief
1.50 + Attribute definition, defines possible values and type of attribute.
1.51 +*/
1.52 +class AttributeDef {
1.53 +public:
1.54 + AttributeDef();
1.55 + ~AttributeDef();
1.56 + void setType (const AttributeType &t);
1.57 + AttributeType getType();
1.58 + QString getTypeString ();
1.59 + void setKey (const QString &k);
1.60 + QString getKey ();
1.61 + void setValue (const QString &v);
1.62 + void setValue (const QVariant &v);
1.63 + QVariant getValue ();
1.64 +private:
1.65 QString key;
1.66 - QString value;
1.67 - AttributeTable *table;
1.68 + AttributeType type;
1.69 +
1.70 + QVariant value; //!< value (except FreeString, FreeInt ...
1.71 };
1.72
1.73 /*! \brief A table containing a list of keys and each of these keys has
1.74 a list of default values. The keys and the values for each key are
1.75 unique.
1.76 */
1.77 +
1.78 class AttributeTable:public XMLObj{
1.79 public:
1.80 AttributeTable();
1.81 ~AttributeTable();
1.82 void clear();
1.83 - void addKey (const QString &k); //!< Adds a key to the table
1.84 + AttributeDef* addKey (const QString &k, const AttributeType &t); //!< Adds a key to the table
1.85 void removeKey (const QString &k); //!< Removes key and its default values
1.86 + AttributeDef* getDef(const QString &k); //!< Get defintion of attribute
1.87 int countKeys(); //!< Return number of keys
1.88 - void addValue (const QString &k, const QString &v); //!< Adds key and value
1.89 QStringList getKeys ();
1.90 - QStringList getValues(const QString &k);
1.91 QString getDataXML();
1.92
1.93 protected:
1.94 - QStringList keys;
1.95 - QList <QStringList> values;
1.96 + QList <AttributeDef*> attdefs;
1.97 };
1.98
1.99