diff -r 7ea31701156e -r 7f43b93242aa treemodel.cpp --- a/treemodel.cpp Tue Aug 05 07:36:53 2008 +0000 +++ b/treemodel.cpp Mon Oct 06 11:10:20 2008 +0000 @@ -3,13 +3,16 @@ #include "treeitem.h" #include "treemodel.h" +TreeItem* TreeModel::itFirst=NULL; +TreeItem* TreeModel::itCur=NULL; + TreeModel::TreeModel(QObject *parent) : QAbstractItemModel(parent) { QList rootData; rootData << "Heading" << "Type" <<"Note"; rootItem = new TreeItem(rootData); - setupModelData(rootItem); + // setupModelData(rootItem); } TreeModel::~TreeModel() @@ -98,7 +101,158 @@ return parentItem->childCount(); } -void TreeModel::setupModelData(TreeItem *root) +TreeItem* TreeModel::first() +{ + itCur=NULL; + itFirst=rootItem; + return rootItem; +} + +TreeItem* TreeModel::next() +{ +/* + BranchObj *bo; + BranchObj *lmo; + BranchObj *po=(BranchObj*)parObj; + + if (branch.isEmpty()) + bo=NULL; + else + bo=branch.first(); + + 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; + } + } + */ +} + +QModelIndex TreeModel::index (TreeItem* ti) +{ + return createIndex (ti->row(),ti->column(),ti); +} + +TreeItem* TreeModel::LMOToItem (LinkableMapObj *lmo)// FIXME not used so far!!! +{ + TreeItem *ti=rootItem; +} + +void TreeModel::setupModelData(TreeItem *root) // FIXME not needed anymore { QList cData; @@ -125,6 +279,4 @@ cData.clear(); cData << "Main B"<<"Branch" <<"Data 3"; mco->appendChild(new TreeItem(cData, mco)); - - //QModelIndex ix=index (0,0,QModelIndex() ); }