treemodel.cpp
changeset 740 6dc0a20031f7
parent 727 96402b172173
child 741 1b4d1ea6ea8c
     1.1 --- a/treemodel.cpp	Wed Feb 04 11:52:52 2009 +0000
     1.2 +++ b/treemodel.cpp	Wed Feb 04 16:33:16 2009 +0000
     1.3 @@ -3,8 +3,8 @@
     1.4  #include "treeitem.h"
     1.5  #include "treemodel.h"
     1.6  
     1.7 -TreeItem* TreeModel::itFirst=NULL;
     1.8 -TreeItem* TreeModel::itCur=NULL;
     1.9 +QModelIndex TreeModel::ixCur=QModelIndex();
    1.10 +TreeItem* TreeModel::itStartParent=NULL;
    1.11  
    1.12  TreeModel::TreeModel(QObject *parent)
    1.13      : QAbstractItemModel(parent)
    1.14 @@ -102,143 +102,25 @@
    1.15  
    1.16  TreeItem* TreeModel::first()
    1.17  {
    1.18 -	itCur=NULL;	
    1.19 -	itFirst=rootItem;
    1.20 -	return rootItem; 
    1.21 +	if (rootItem->childCount()  ==0)
    1.22 +	{
    1.23 +		ixCur=QModelIndex();
    1.24 +		return NULL;
    1.25 +	} 
    1.26 +	ixCur=index (0,0);
    1.27 +	return 	static_cast<TreeItem*>(ixCur.internalPointer());
    1.28  }
    1.29  	
    1.30  TreeItem* TreeModel::next()
    1.31  {
    1.32 -/*
    1.33 -	BranchObj *bo;
    1.34 -	BranchObj *lmo;
    1.35 -	BranchObj *po=(BranchObj*)parObj;
    1.36 +	if (!ixCur.isValid() )
    1.37 +		return NULL;
    1.38  
    1.39 -	if (branch.isEmpty())
    1.40 -		bo=NULL;
    1.41 -	else
    1.42 -		bo=branch.first();
    1.43 +	ixCur=index (ixCur.row()+1,0);
    1.44 +	if (ixCur.isValid())
    1.45 +		return 	static_cast<TreeItem*>(ixCur.internalPointer());
    1.46 +	return NULL;	
    1.47  
    1.48 -	if (!itCur)
    1.49 -	{
    1.50 -		// no itCur, we are just beginning
    1.51 -		if (bo) 
    1.52 -		{
    1.53 -			// we have children, return first one
    1.54 -			itCur=this;
    1.55 -			return bo;
    1.56 -		}	
    1.57 -		else
    1.58 -		{
    1.59 -			// No children, so there is no next
    1.60 -			itCur=this;
    1.61 -			return NULL;
    1.62 -		}	
    1.63 -	}
    1.64 -
    1.65 -	// We have an itCur
    1.66 -	if (itCur==po)
    1.67 -	{	// We come from parent
    1.68 -		if (bo)
    1.69 -		{
    1.70 -			// there are children, go there
    1.71 -			itCur=this;
    1.72 -			return bo;
    1.73 -		}	
    1.74 -		else
    1.75 -		{	// no children, try to go up again
    1.76 -			if (po)
    1.77 -			{
    1.78 -				// go back to parent and try to find next there
    1.79 -				itCur=this;
    1.80 -				lmo=po->next();
    1.81 -				itCur=this;
    1.82 -				return lmo;
    1.83 -
    1.84 -			}	
    1.85 -			else
    1.86 -			{
    1.87 -				// can't go up, I am mapCenter, no next
    1.88 -				itCur=NULL;
    1.89 -				return NULL;
    1.90 -			}	
    1.91 -		}
    1.92 -	}
    1.93 -
    1.94 -	// We don't come from parent, but from brother or children
    1.95 -
    1.96 -	// Try to find last child, where we came from, in my own children
    1.97 -	bool searching=true;
    1.98 -	int i=0;
    1.99 -	while (i<branch.size())
   1.100 -	{
   1.101 -		// Try to find itCur in my own children
   1.102 -		if (itCur==branch.at(i))
   1.103 -		{
   1.104 -			// ok, we come from my own children
   1.105 -			if (i<branch.size()-1)
   1.106 -				bo=branch.at(i+1);
   1.107 -			 else
   1.108 -				bo=NULL;
   1.109 -			searching=false;
   1.110 -			i=branch.size();
   1.111 -		} 	
   1.112 -		++i;	
   1.113 -	}
   1.114 -	if (!searching)
   1.115 -	{	// found itCur in my children
   1.116 -		if (bo)
   1.117 -		{
   1.118 -			// found a brother of lastLMO 
   1.119 -			itCur=this;
   1.120 -			return bo;
   1.121 -		}	
   1.122 -		else
   1.123 -		{
   1.124 -			if (po)
   1.125 -			{
   1.126 -				if (this==itFirst) return NULL;	// Stop at starting point
   1.127 -				// go up
   1.128 -				itCur=this;
   1.129 -				lmo=po->next();
   1.130 -				itCur=this;
   1.131 -				return lmo;
   1.132 -			}
   1.133 -			else
   1.134 -			{
   1.135 -				// can't go up, I am mapCenter
   1.136 -				itCur=NULL;
   1.137 -				return NULL;
   1.138 -			}	
   1.139 -		}
   1.140 -	}
   1.141 -
   1.142 -	// couldn't find last child, it must be a nephew of mine
   1.143 -	if (branch.size()>0)
   1.144 -	{
   1.145 -		// proceed with my first child
   1.146 -		itCur=this;	
   1.147 -		return branch.first();
   1.148 -	}	
   1.149 -	else
   1.150 -	{
   1.151 -		// or go back to my parents
   1.152 -		if (po)
   1.153 -		{
   1.154 -			// go up
   1.155 -			itCur=this;
   1.156 -			lmo=po->next();
   1.157 -			itCur=this;
   1.158 -			return lmo;
   1.159 -		}	
   1.160 -		else
   1.161 -		{
   1.162 -			// can't go up, I am mapCenter
   1.163 -			itCur=NULL;
   1.164 -			return NULL;
   1.165 -		}	
   1.166 -	}	
   1.167 -	*/
   1.168  }
   1.169  
   1.170  #include <iostream>
   1.171 @@ -248,7 +130,6 @@
   1.172  	beginRemoveRows (parent,row,last);
   1.173  
   1.174      TreeItem *pi= static_cast<TreeItem*>(parent.internalPointer());
   1.175 -    TreeItem *ti;
   1.176  	for (int i=row; i<=last; i++)
   1.177  	{
   1.178  		std::cout << "TreeModel::removeRows removing i="<<i<<std::endl;