treeitem.cpp
author insilmaril
Mon, 05 Jan 2009 16:31:38 +0000
changeset 732 b77b56f707f1
parent 727 96402b172173
child 738 716a777c1c98
permissions -rw-r--r--
deleting works - partially.
     1 #include <QStringList>
     2 
     3 #include "treeitem.h"
     4 
     5 TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
     6 {
     7     parentItem = parent;
     8     itemData = data;
     9 	lmo=NULL;
    10 }
    11 
    12 TreeItem::~TreeItem()
    13 {
    14     qDeleteAll(childItems);
    15 }
    16 
    17 void TreeItem::appendChild(TreeItem *item)
    18 {
    19     childItems.append(item);
    20 }
    21 
    22 void TreeItem::removeChild(int row)
    23 {
    24     if (row>=0)
    25 	{
    26 		delete (childItems.at(row) );
    27 		childItems.removeAt (row);
    28 	} else
    29 		qWarning ("TreeItem::removeChild tried to remove non existing item?!\n");
    30 }
    31 
    32 TreeItem *TreeItem::child(int row)
    33 {
    34     return childItems.value(row);
    35 }
    36 
    37 int TreeItem::childCount() const
    38 {
    39     return childItems.count();
    40 }
    41 
    42 int TreeItem::columnCount() const
    43 {
    44     return itemData.count();
    45 }
    46 int TreeItem::row() const
    47 {
    48     if (parentItem)
    49         return parentItem->childItems.indexOf(const_cast<TreeItem*>(this));
    50 
    51     return 0;
    52 }
    53 
    54 int TreeItem::column() const
    55 {
    56     return 0;
    57 }
    58 
    59 TreeItem *TreeItem::parent()
    60 {
    61     return parentItem;
    62 }
    63 
    64 
    65 QVariant TreeItem::data(int column) const
    66 {
    67     return itemData.value(column);
    68 }
    69 
    70 void TreeItem::setHeading (const QString s)
    71 {
    72 	itemData[0]=s;
    73 }
    74 
    75 QString TreeItem::getHeading ()
    76 {
    77 	return itemData[0].toString();
    78 }
    79 
    80 void TreeItem::setType(const Type t)
    81 {
    82 	type=t;
    83 	itemData[1]=getTypeName();
    84 }
    85 
    86 TreeItem::Type TreeItem::getType()
    87 {
    88 	return type;
    89 }
    90 
    91 QString TreeItem::getTypeName()
    92 {
    93 	switch (type)
    94 	{
    95 		case Undefined: return QString ("Undefined");
    96 		case MapCenter: return QString ("MapCenter");
    97 		case Branch: return QString ("Branch");
    98 		default: return QString ("TreeItem::getTypeName no typename defined?!");
    99 	}
   100 }
   101 
   102 LinkableMapObj* TreeItem::getLMO()	// FIXME VM should be unnecessary in the end
   103 {
   104 	return lmo;
   105 }
   106 
   107 void TreeItem::setLMO(LinkableMapObj *l)
   108 {
   109 	lmo=l;
   110 }
   111