attribute.cpp
changeset 616 16d63fc9ae42
child 626 96c8e6860e0c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/attribute.cpp	Thu Nov 08 15:28:03 2007 +0000
     1.3 @@ -0,0 +1,101 @@
     1.4 +#include "attribute.h"
     1.5 +
     1.6 +Attribute::Attribute()
     1.7 +{
     1.8 +	key="";
     1.9 +	value="";
    1.10 +}
    1.11 +
    1.12 +void Attribute::setKey (const QString &k)
    1.13 +{
    1.14 +	key=k;
    1.15 +}
    1.16 +
    1.17 +QString Attribute::getKey ()
    1.18 +{
    1.19 +	return key;
    1.20 +}
    1.21 +
    1.22 +void Attribute::setValue(const QString &v)
    1.23 +{
    1.24 +	value=v;
    1.25 +}
    1.26 +
    1.27 +QString Attribute::getValue()
    1.28 +{
    1.29 +	return value;
    1.30 +}
    1.31 +
    1.32 +QString Attribute::getDataXML()
    1.33 +{
    1.34 +	return valueElement ("attribute",key,value);
    1.35 +}
    1.36 +
    1.37 +
    1.38 +///////////////////////////////////////////////////////////////
    1.39 +AttributeTable::AttributeTable()
    1.40 +{
    1.41 +	clear();
    1.42 +}
    1.43 +
    1.44 +AttributeTable::~AttributeTable()
    1.45 +{
    1.46 +}
    1.47 +
    1.48 +void AttributeTable::clear ()
    1.49 +{
    1.50 +	keys.clear();
    1.51 +	values.clear();
    1.52 +}
    1.53 +
    1.54 +void AttributeTable::addKey (const QString &k)
    1.55 +{
    1.56 +	if (!keys.contains (k) )
    1.57 +	{
    1.58 +		keys.append (k);
    1.59 +		values.append (QStringList() );
    1.60 +	}
    1.61 +}
    1.62 +
    1.63 +void AttributeTable::removeKey (const QString &k)
    1.64 +{
    1.65 +	int i=keys.indexOf (k);
    1.66 +	if (i>=0)
    1.67 +	{
    1.68 +		keys.removeAt(i);
    1.69 +		values.removeAt(i);
    1.70 +	}
    1.71 +}
    1.72 +
    1.73 +void AttributeTable::addValue (const QString &k, const QString &v)
    1.74 +{
    1.75 +	int i=keys.indexOf (k);
    1.76 +	if (i<0)
    1.77 +	{
    1.78 +		keys.append (k);
    1.79 +		values.append (QStringList (v));
    1.80 +	} else
    1.81 +	{
    1.82 +		int j=values.at(i).indexOf(k);
    1.83 +		if (j<0) values[i].append (QString(v));
    1.84 +	}
    1.85 +}
    1.86 +
    1.87 +QStringList AttributeTable::getKeys ()
    1.88 +{
    1.89 +	return keys;
    1.90 +}
    1.91 +
    1.92 +QStringList AttributeTable::getValues(const QString &k)
    1.93 +{
    1.94 +	int i=keys.indexOf (k);
    1.95 +	if (i>=0)
    1.96 +		return values.at(i);
    1.97 +	else
    1.98 +		return QStringList();
    1.99 +}
   1.100 +
   1.101 +QString AttributeTable::getDataXML()
   1.102 +{
   1.103 +	return valueElement ("attributeList","key","value");
   1.104 +}