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