diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c treeitem.cpp --- a/treeitem.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/treeitem.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -1,5 +1,6 @@ #include +#include "branchobj.h" #include "treeitem.h" TreeItem::TreeItem(const QList &data, TreeItem *parent) @@ -9,7 +10,7 @@ lmo=NULL; branchOffset=0; - branchCount=0; + branchCounter=0; lastSelectedBranchNum=-1; } @@ -18,14 +19,17 @@ qDeleteAll(childItems); } + void TreeItem::appendChild(TreeItem *item) { childItems.append(item); - if (item->type == Branch) + + + if (item->type == Branch || item->type ==MapCenter) { - if (branchCount==0) + if (branchCounter==0) branchOffset=childItems.count()-1; - branchCount++; + branchCounter++; } } @@ -53,6 +57,11 @@ { return itemData.count(); } + +int TreeItem::branchCount() const +{ + return branchCounter; +} int TreeItem::row() const { if (parentItem) @@ -83,6 +92,18 @@ return parentItem; } +int TreeItem::num() +{ + switch (type) + { + case Undefined: return -1; + case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset; + case Branch: return parentItem->childItems.indexOf (this) - branchOffset; + case Image: return -1; // FIXME + default: return -1; + } + +} QVariant TreeItem::data(int column) const { @@ -99,6 +120,30 @@ return itemData[0].toString(); } +void TreeItem::setNote(const QString s) +{ + switch (type) + { + case MapCenter: + ((BranchObj*)lmo)->setNote(s); + break; + case Branch: + ((BranchObj*)lmo)->setNote(s); + break; + default: ; + } +} + +QString TreeItem::getNote() +{ + switch (type) + { + case MapCenter: return ((BranchObj*)lmo)->getNote(); + case Branch: return ((BranchObj*)lmo)->getNote(); + default: return QString (); + } +} + void TreeItem::setType(const Type t) { type=t; @@ -132,7 +177,7 @@ TreeItem* TreeItem::getFirstBranch() { - if (branchCount>0) + if (branchCounter>0) return getBranchNum (branchOffset); else return NULL; @@ -140,8 +185,8 @@ TreeItem* TreeItem::getLastBranch() { - if (branchCount>0) - return getBranchNum (branchOffset + branchCount-1); + if (branchCounter>0) + return getBranchNum (branchOffset + branchCounter-1); else return NULL; } @@ -149,7 +194,7 @@ TreeItem* TreeItem::getBranchNum(const int &n) { - if (branchCount>0) + if (branchCounter>0) return getChildNum (branchOffset + n); else return NULL;