diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c treemodel.cpp --- a/treemodel.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/treemodel.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -1,11 +1,11 @@ #include +#include +using namespace std; + #include "treeitem.h" #include "treemodel.h" -QModelIndex TreeModel::ixCur=QModelIndex(); -TreeItem* TreeModel::itStartParent=NULL; - TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) { @@ -19,14 +19,6 @@ delete rootItem; } -int TreeModel::columnCount(const QModelIndex &parent) const -{ - if (parent.isValid()) - return static_cast(parent.internalPointer())->columnCount(); - else - return rootItem->columnCount(); -} - QVariant TreeModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -100,30 +92,72 @@ return parentItem->childCount(); } -TreeItem* TreeModel::first() +int TreeModel::columnCount(const QModelIndex &parent) const { - if (rootItem->childCount() ==0) - { - ixCur=QModelIndex(); - return NULL; - } - ixCur=index (0,0); - return static_cast(ixCur.internalPointer()); -} - -TreeItem* TreeModel::next() -{ - if (!ixCur.isValid() ) - return NULL; - - ixCur=index (ixCur.row()+1,0); - if (ixCur.isValid()) - return static_cast(ixCur.internalPointer()); - return NULL; - + if (parent.isValid()) + return static_cast(parent.internalPointer())->columnCount(); + else + return rootItem->columnCount(); } -#include +TreeItem* TreeModel::next(TreeItem* ¤t, TreeItem* &previous, int &d0) +{ + // Walk through map beginning at current with previous==0 + // Start at root, if current==NULL + if (!current) current=rootItem; + + // Are we just beginning to walk the map? + if (!previous) + { + previous=current; + d0=current->depth(); + current=current->getFirstBranch(); + return current; + } + + //std::cout << " cur="<getHeading().toStdString(); + //std::cout << " prev="<getHeading().toStdString()<depth() > previous->depth() ) + { + // Coming from above + // Trying to go down deeper + if (current->branchCount() >0 ) + { + previous=current; + current=current->getFirstBranch(); + return current; + } + // turn around and go up again + } + + // Coming from below, + // Trying to go down again to siblings + + TreeItem *sibling=current->getBranchNum (previous->num()+1); + + if (sibling) + { + // Found sibling of previous, go there + previous=current; + current=sibling; + return current; + } + + // Go up and try to find siblings of current + previous=current; + current=current->parent(); + + // Check if we still can go somewhere + if (!current) return current; + + while (current && current->depth() < previous->depth() ) + next (current,previous,d0); + + return current; +} + bool TreeModel::removeRows ( int row, int count, const QModelIndex & parent) { int last=row+count-1;