attribute.h
author insilmaril
Mon Jul 27 12:53:17 2009 +0000 (2009-07-27)
changeset 782 ffb02a9bb508
parent 671 367d875453ed
permissions -rw-r--r--
Playing with dbus, fixed name of TW translation file
     1 #ifndef ATTRIBUTE_H
     2 #define ATTRIBUTE_H
     3 
     4 #include <QStringList>
     5 #include <QVariant>
     6 
     7 #include "xmlobj.h"
     8 
     9 class AttributeTable;	//FIXME-3 remove from CVS
    10 class AttributeDef;		//FIXME-3 remove from CVS
    11 
    12 enum AttributeType {
    13 	Undefined,	//!< Undefined type
    14 	IntList,	//!< Free integer
    15 	FreeInt,	//!< Free integer
    16 	StringList, //!< List of strings, one can be attribute value
    17 	FreeString,	//!< Any string can be attribute value, not unique
    18 	UniqueString//!< UniqueString, e.g. for IDs
    19 };
    20 
    21 /*! \brief A key and a value 
    22     The data itself is stored in Attribute Definitions (AttributeDef). 
    23 	A list of these tables AttributeTable is maintained for every MapEditor.
    24 */
    25 class Attribute:public XMLObj {
    26 public:
    27 	Attribute();
    28 	void setKey (const QString &k, const AttributeType &t);
    29 	QString getKey ();
    30 	void setValue (const QString &v);
    31 	QVariant getValue ();
    32 	void setType (const AttributeType &t);
    33 	AttributeType getType ();
    34 	QString getTypeString ();
    35 	void setTable (AttributeTable *at);
    36 	AttributeTable* getTable();
    37 	QString getDataXML();
    38 protected:
    39 	AttributeTable *table;
    40 	AttributeDef *definition;
    41 	QString freeString;		//!< String value for type FreeString
    42 };
    43 
    44 
    45 /*! \brief 
    46 	Attribute definition, defines possible values and type of attribute.
    47 */
    48 class AttributeDef {
    49 public:
    50 	AttributeDef();
    51 	~AttributeDef();
    52 	void setType (const AttributeType &t);
    53 	AttributeType getType();
    54 	QString getTypeString ();
    55 	void setKey (const QString &k);
    56 	QString getKey ();
    57 	void setValue (const QString &v);
    58 	void setValue (const QVariant &v);
    59 	QVariant getValue ();
    60 private:
    61 	QString key;
    62 	AttributeType type;
    63 
    64 	QVariant value;				//!< value (except FreeString, FreeInt ...
    65 };
    66 
    67 /*! \brief A table containing a list of keys and each of these keys has
    68    a list of default values. The keys and the values for each key are
    69    unique.
    70 */
    71 
    72 class AttributeTable:public XMLObj{
    73 public:
    74 	AttributeTable();
    75 	~AttributeTable();
    76 	void clear();
    77 	AttributeDef* addKey (const QString &k, const AttributeType &t);	//!< Adds a key to the table
    78 	void removeKey (const QString &k);	//!< Removes key and its default values
    79 	AttributeDef* getDef(const QString &k);	//!< Get defintion of attribute
    80 	int countKeys();					//!< Return number of keys
    81 	QStringList getKeys ();
    82 	QStringList getTypes();
    83 	QString getDataXML();
    84 
    85 protected:
    86 	QList <AttributeDef*> attdefs;
    87 	QStringList typeList;
    88 };
    89 
    90 
    91 
    92 #endif
    93