attribute.h
author insilmaril
Mon Aug 04 10:43:06 2008 +0000 (2008-08-04)
changeset 723 11f9124c1cca
parent 636 f83abc1f75b4
child 767 6d2b32f305f9
permissions -rw-r--r--
Adding/moving MCO works again
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@671
    14
	IntList,	//!< Free integer
insilmaril@671
    15
	FreeInt,	//!< Free integer
insilmaril@636
    16
	StringList, //!< List of strings, one can be attribute value
insilmaril@636
    17
	FreeString,	//!< Any string can be attribute value, not unique
insilmaril@636
    18
	UniqueString//!< UniqueString, e.g. for IDs
insilmaril@636
    19
};
insilmaril@636
    20
insilmaril@636
    21
/*! \brief A key and a value 
insilmaril@671
    22
    The data itself is stored in Attribute Definitions (AttributeDef). 
insilmaril@671
    23
	A list of these tables AttributeTable is maintained for every MapEditor.
insilmaril@616
    24
*/
insilmaril@616
    25
class Attribute:public XMLObj {
insilmaril@616
    26
public:
insilmaril@616
    27
	Attribute();
insilmaril@636
    28
	void setKey (const QString &k, const AttributeType &t);
insilmaril@626
    29
	QString getKey ();
insilmaril@626
    30
	void setValue (const QString &v);
insilmaril@636
    31
	QVariant getValue ();
insilmaril@636
    32
	void setType (const AttributeType &t);
insilmaril@636
    33
	AttributeType getType ();
insilmaril@636
    34
	QString getTypeString ();
insilmaril@626
    35
	void setTable (AttributeTable *at);
insilmaril@626
    36
	AttributeTable* getTable();
insilmaril@626
    37
	QString getDataXML();
insilmaril@616
    38
protected:
insilmaril@636
    39
	AttributeTable *table;
insilmaril@636
    40
	AttributeDef *definition;
insilmaril@636
    41
	QString freeString;		//!< String value for type FreeString
insilmaril@636
    42
};
insilmaril@636
    43
insilmaril@636
    44
insilmaril@636
    45
/*! \brief 
insilmaril@636
    46
	Attribute definition, defines possible values and type of attribute.
insilmaril@636
    47
*/
insilmaril@636
    48
class AttributeDef {
insilmaril@636
    49
public:
insilmaril@636
    50
	AttributeDef();
insilmaril@636
    51
	~AttributeDef();
insilmaril@636
    52
	void setType (const AttributeType &t);
insilmaril@636
    53
	AttributeType getType();
insilmaril@636
    54
	QString getTypeString ();
insilmaril@636
    55
	void setKey (const QString &k);
insilmaril@636
    56
	QString getKey ();
insilmaril@636
    57
	void setValue (const QString &v);
insilmaril@636
    58
	void setValue (const QVariant &v);
insilmaril@636
    59
	QVariant getValue ();
insilmaril@636
    60
private:
insilmaril@616
    61
	QString key;
insilmaril@636
    62
	AttributeType type;
insilmaril@636
    63
insilmaril@636
    64
	QVariant value;				//!< value (except FreeString, FreeInt ...
insilmaril@616
    65
};
insilmaril@616
    66
insilmaril@616
    67
/*! \brief A table containing a list of keys and each of these keys has
insilmaril@616
    68
   a list of default values. The keys and the values for each key are
insilmaril@616
    69
   unique.
insilmaril@616
    70
*/
insilmaril@636
    71
insilmaril@616
    72
class AttributeTable:public XMLObj{
insilmaril@616
    73
public:
insilmaril@616
    74
	AttributeTable();
insilmaril@626
    75
	~AttributeTable();
insilmaril@626
    76
	void clear();
insilmaril@636
    77
	AttributeDef* addKey (const QString &k, const AttributeType &t);	//!< Adds a key to the table
insilmaril@626
    78
	void removeKey (const QString &k);	//!< Removes key and its default values
insilmaril@636
    79
	AttributeDef* getDef(const QString &k);	//!< Get defintion of attribute
insilmaril@626
    80
	int countKeys();					//!< Return number of keys
insilmaril@626
    81
	QStringList getKeys ();
insilmaril@671
    82
	QStringList getTypes();
insilmaril@626
    83
	QString getDataXML();
insilmaril@616
    84
insilmaril@616
    85
protected:
insilmaril@636
    86
	QList <AttributeDef*> attdefs;
insilmaril@671
    87
	QStringList typeList;
insilmaril@616
    88
};
insilmaril@616
    89
insilmaril@616
    90
insilmaril@616
    91
insilmaril@616
    92
#endif
insilmaril@616
    93