diff -r 3d43b46a8564 -r 6dc0a20031f7 treemodel.cpp --- a/treemodel.cpp Wed Feb 04 11:52:52 2009 +0000 +++ b/treemodel.cpp Wed Feb 04 16:33:16 2009 +0000 @@ -3,8 +3,8 @@ #include "treeitem.h" #include "treemodel.h" -TreeItem* TreeModel::itFirst=NULL; -TreeItem* TreeModel::itCur=NULL; +QModelIndex TreeModel::ixCur=QModelIndex(); +TreeItem* TreeModel::itStartParent=NULL; TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) @@ -102,143 +102,25 @@ TreeItem* TreeModel::first() { - itCur=NULL; - itFirst=rootItem; - return rootItem; + if (rootItem->childCount() ==0) + { + ixCur=QModelIndex(); + return NULL; + } + ixCur=index (0,0); + return static_cast(ixCur.internalPointer()); } TreeItem* TreeModel::next() { -/* - BranchObj *bo; - BranchObj *lmo; - BranchObj *po=(BranchObj*)parObj; + if (!ixCur.isValid() ) + return NULL; - if (branch.isEmpty()) - bo=NULL; - else - bo=branch.first(); + ixCur=index (ixCur.row()+1,0); + if (ixCur.isValid()) + return static_cast(ixCur.internalPointer()); + return NULL; - if (!itCur) - { - // no itCur, we are just beginning - if (bo) - { - // we have children, return first one - itCur=this; - return bo; - } - else - { - // No children, so there is no next - itCur=this; - return NULL; - } - } - - // We have an itCur - if (itCur==po) - { // We come from parent - if (bo) - { - // there are children, go there - itCur=this; - return bo; - } - else - { // no children, try to go up again - if (po) - { - // go back to parent and try to find next there - itCur=this; - lmo=po->next(); - itCur=this; - return lmo; - - } - else - { - // can't go up, I am mapCenter, no next - itCur=NULL; - return NULL; - } - } - } - - // We don't come from parent, but from brother or children - - // Try to find last child, where we came from, in my own children - bool searching=true; - int i=0; - while (inext(); - itCur=this; - return lmo; - } - else - { - // can't go up, I am mapCenter - itCur=NULL; - return NULL; - } - } - } - - // couldn't find last child, it must be a nephew of mine - if (branch.size()>0) - { - // proceed with my first child - itCur=this; - return branch.first(); - } - else - { - // or go back to my parents - if (po) - { - // go up - itCur=this; - lmo=po->next(); - itCur=this; - return lmo; - } - else - { - // can't go up, I am mapCenter - itCur=NULL; - return NULL; - } - } - */ } #include @@ -248,7 +130,6 @@ beginRemoveRows (parent,row,last); TreeItem *pi= static_cast(parent.internalPointer()); - TreeItem *ti; for (int i=row; i<=last; i++) { std::cout << "TreeModel::removeRows removing i="<