treeitem.cpp
changeset 741 1b4d1ea6ea8c
parent 740 6dc0a20031f7
child 745 2d4cc445a86a
     1.1 --- a/treeitem.cpp	Wed Feb 04 16:33:16 2009 +0000
     1.2 +++ b/treeitem.cpp	Fri Mar 06 15:02:58 2009 +0000
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <QStringList>
     1.5  
     1.6 +#include "branchobj.h"
     1.7  #include "treeitem.h"
     1.8  
     1.9  TreeItem::TreeItem(const QList<QVariant> &data, TreeItem *parent)
    1.10 @@ -9,7 +10,7 @@
    1.11  	lmo=NULL;
    1.12  
    1.13  	branchOffset=0;
    1.14 -	branchCount=0;
    1.15 +	branchCounter=0;
    1.16  	lastSelectedBranchNum=-1;
    1.17  }
    1.18  
    1.19 @@ -18,14 +19,17 @@
    1.20      qDeleteAll(childItems);
    1.21  }
    1.22  
    1.23 +
    1.24  void TreeItem::appendChild(TreeItem *item)
    1.25  {
    1.26      childItems.append(item);
    1.27 -	if (item->type == Branch)
    1.28 +	
    1.29 +
    1.30 +	if (item->type == Branch || item->type ==MapCenter)
    1.31  	{
    1.32 -		if (branchCount==0)
    1.33 +		if (branchCounter==0)
    1.34  			branchOffset=childItems.count()-1;
    1.35 -		branchCount++;
    1.36 +		branchCounter++;
    1.37  	}
    1.38  }
    1.39  
    1.40 @@ -53,6 +57,11 @@
    1.41  {
    1.42      return itemData.count();
    1.43  }
    1.44 +
    1.45 +int TreeItem::branchCount() const
    1.46 +{
    1.47 +    return branchCounter;
    1.48 +}
    1.49  int TreeItem::row() const
    1.50  {
    1.51      if (parentItem)
    1.52 @@ -83,6 +92,18 @@
    1.53      return parentItem;
    1.54  }
    1.55  
    1.56 +int TreeItem::num()
    1.57 +{
    1.58 +	switch (type)
    1.59 +	{
    1.60 +		case Undefined: return -1;
    1.61 +		case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset;
    1.62 +		case Branch: return parentItem->childItems.indexOf (this) - branchOffset;
    1.63 +		case Image: return -1; // FIXME
    1.64 +		default: return -1;
    1.65 +	}
    1.66 +	
    1.67 +}
    1.68  
    1.69  QVariant TreeItem::data(int column) const
    1.70  {
    1.71 @@ -99,6 +120,30 @@
    1.72  	return itemData[0].toString();
    1.73  }
    1.74  
    1.75 +void TreeItem::setNote(const QString s)
    1.76 +{
    1.77 +	switch (type)
    1.78 +	{
    1.79 +		case MapCenter: 
    1.80 +			((BranchObj*)lmo)->setNote(s);
    1.81 +			break;
    1.82 +		case Branch: 
    1.83 +			((BranchObj*)lmo)->setNote(s);
    1.84 +			break;
    1.85 +		default: ;
    1.86 +	}
    1.87 +}
    1.88 +
    1.89 +QString TreeItem::getNote()
    1.90 +{
    1.91 +	switch (type)
    1.92 +	{
    1.93 +		case MapCenter: return ((BranchObj*)lmo)->getNote();
    1.94 +		case Branch: return ((BranchObj*)lmo)->getNote();
    1.95 +		default: return QString ();
    1.96 +	}
    1.97 +}
    1.98 +
    1.99  void TreeItem::setType(const Type t)
   1.100  {
   1.101  	type=t;
   1.102 @@ -132,7 +177,7 @@
   1.103  
   1.104  TreeItem* TreeItem::getFirstBranch()
   1.105  {
   1.106 -	if (branchCount>0)
   1.107 +	if (branchCounter>0)
   1.108  		return getBranchNum (branchOffset);
   1.109  	else
   1.110  		return NULL;
   1.111 @@ -140,8 +185,8 @@
   1.112  
   1.113  TreeItem* TreeItem::getLastBranch()
   1.114  {
   1.115 -	if (branchCount>0)
   1.116 -		return getBranchNum (branchOffset + branchCount-1);
   1.117 +	if (branchCounter>0)
   1.118 +		return getBranchNum (branchOffset + branchCounter-1);
   1.119  	else
   1.120  		return NULL;
   1.121  }
   1.122 @@ -149,7 +194,7 @@
   1.123  
   1.124  TreeItem* TreeItem::getBranchNum(const int &n)
   1.125  {
   1.126 -	if (branchCount>0)
   1.127 +	if (branchCounter>0)
   1.128  		return getChildNum (branchOffset + n);
   1.129  	else
   1.130  		return NULL;