diff -r 338ebdc9b947 -r 14f2b1b15242 treemodel.cpp --- a/treemodel.cpp Fri Oct 02 14:31:03 2009 +0000 +++ b/treemodel.cpp Fri Nov 13 08:32:03 2009 +0000 @@ -146,14 +146,8 @@ return c; } -BranchItem* TreeModel::next(BranchItem* ¤t, BranchItem* &previous, BranchItem* start) // FIXME-3 change this to nextBranch and use "next" for all TIs +BranchItem* TreeModel::nextBranch (BranchItem* ¤t, BranchItem* &previous, bool deepLevelsFirst, BranchItem *start) { -/*FIXME-3 cout << "TM::next \n"; - std::string ch="()"; if (current) ch=current->getHeadingStd(); - std::string ph="()"; if (previous) ph=previous->getHeadingStd(); - cout << " cur="<branchCount() >0 ) - { -// cout << " yes, going deeper\n"; + // Coming from below + // Trying to go down again to siblings + + BranchItem *sibling=current->getBranchNum (previous->num()+1); + + if (sibling) + { + // Found sibling of previous, go there previous=current; - current=current->getFirstBranch(); + current=sibling; return current; - } - // turn around and go up again -// cout << " sorry, turn around\n"; - BranchItem *bi=current; - current=previous; - previous=bi; - } + } -/* - cout << " coming from below\n"; - ch="()"; if (current) ch=current->getHeadingStd(); - ph="()"; if (previous) ph=previous->getHeadingStd(); - cout << " cur="<num()="<num()<parent(); - if (sibling) - { - // Found sibling of previous, go there -// cout << " sib=cur="<getHeadingStd()<depth() < previous->depth() ) + current=nextBranch (current,previous,true,start); + return current; - } - // If we only needed to go through subtree, we are done now - if (start==current) return NULL; + } else + { +/*FIXME-3 + cout << "TM::nextBranch shallow\n"; + std::string ch="()"; if (current) ch=current->getHeadingStd(); + std::string ph="()"; if (previous) ph=previous->getHeadingStd(); + cout << " cur="<parent(); + // Try to find sibling with same depth + BranchItem *sibling=current->parent()->getBranchNum (current->num()+1); + if (sibling) + { + // Found sibling of previous, go there + previous=current; + current=sibling; + return current; + } else + { + // Try to find next branch with same depth or greater + - // Check if we still can go somewhere - if (!current) return current; - - while (current && current->depth() < previous->depth() ) - current=next (current,previous,start); - - return current; + current=NULL; + return current; + } + + + /* + while (ix.isValid()) + { + TreeItem *ti=model->getItem (ix); + cout << " level="<