attribute.cpp
author insilmaril
Thu, 08 Nov 2007 15:28:03 +0000
changeset 617 7ee5bf3647d3
parent 616 16d63fc9ae42
child 626 96c8e6860e0c
permissions -rw-r--r--
1.11.2 split up of xml helper functions. started to work on attributes
     1 #include "attribute.h"
     2 
     3 Attribute::Attribute()
     4 {
     5 	key="";
     6 	value="";
     7 }
     8 
     9 void Attribute::setKey (const QString &k)
    10 {
    11 	key=k;
    12 }
    13 
    14 QString Attribute::getKey ()
    15 {
    16 	return key;
    17 }
    18 
    19 void Attribute::setValue(const QString &v)
    20 {
    21 	value=v;
    22 }
    23 
    24 QString Attribute::getValue()
    25 {
    26 	return value;
    27 }
    28 
    29 QString Attribute::getDataXML()
    30 {
    31 	return valueElement ("attribute",key,value);
    32 }
    33 
    34 
    35 ///////////////////////////////////////////////////////////////
    36 AttributeTable::AttributeTable()
    37 {
    38 	clear();
    39 }
    40 
    41 AttributeTable::~AttributeTable()
    42 {
    43 }
    44 
    45 void AttributeTable::clear ()
    46 {
    47 	keys.clear();
    48 	values.clear();
    49 }
    50 
    51 void AttributeTable::addKey (const QString &k)
    52 {
    53 	if (!keys.contains (k) )
    54 	{
    55 		keys.append (k);
    56 		values.append (QStringList() );
    57 	}
    58 }
    59 
    60 void AttributeTable::removeKey (const QString &k)
    61 {
    62 	int i=keys.indexOf (k);
    63 	if (i>=0)
    64 	{
    65 		keys.removeAt(i);
    66 		values.removeAt(i);
    67 	}
    68 }
    69 
    70 void AttributeTable::addValue (const QString &k, const QString &v)
    71 {
    72 	int i=keys.indexOf (k);
    73 	if (i<0)
    74 	{
    75 		keys.append (k);
    76 		values.append (QStringList (v));
    77 	} else
    78 	{
    79 		int j=values.at(i).indexOf(k);
    80 		if (j<0) values[i].append (QString(v));
    81 	}
    82 }
    83 
    84 QStringList AttributeTable::getKeys ()
    85 {
    86 	return keys;
    87 }
    88 
    89 QStringList AttributeTable::getValues(const QString &k)
    90 {
    91 	int i=keys.indexOf (k);
    92 	if (i>=0)
    93 		return values.at(i);
    94 	else
    95 		return QStringList();
    96 }
    97 
    98 QString AttributeTable::getDataXML()
    99 {
   100 	return valueElement ("attributeList","key","value");
   101 }