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