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