1.1 --- a/treemodel.cpp Tue Aug 05 07:36:53 2008 +0000
1.2 +++ b/treemodel.cpp Mon Oct 06 11:10:20 2008 +0000
1.3 @@ -3,13 +3,16 @@
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 +
1.10 TreeModel::TreeModel(QObject *parent)
1.11 : QAbstractItemModel(parent)
1.12 {
1.13 QList<QVariant> rootData;
1.14 rootData << "Heading" << "Type" <<"Note";
1.15 rootItem = new TreeItem(rootData);
1.16 - setupModelData(rootItem);
1.17 + // setupModelData(rootItem);
1.18 }
1.19
1.20 TreeModel::~TreeModel()
1.21 @@ -98,7 +101,158 @@
1.22 return parentItem->childCount();
1.23 }
1.24
1.25 -void TreeModel::setupModelData(TreeItem *root)
1.26 +TreeItem* TreeModel::first()
1.27 +{
1.28 + itCur=NULL;
1.29 + itFirst=rootItem;
1.30 + return rootItem;
1.31 +}
1.32 +
1.33 +TreeItem* TreeModel::next()
1.34 +{
1.35 +/*
1.36 + BranchObj *bo;
1.37 + BranchObj *lmo;
1.38 + BranchObj *po=(BranchObj*)parObj;
1.39 +
1.40 + if (branch.isEmpty())
1.41 + bo=NULL;
1.42 + else
1.43 + bo=branch.first();
1.44 +
1.45 + if (!itCur)
1.46 + {
1.47 + // no itCur, we are just beginning
1.48 + if (bo)
1.49 + {
1.50 + // we have children, return first one
1.51 + itCur=this;
1.52 + return bo;
1.53 + }
1.54 + else
1.55 + {
1.56 + // No children, so there is no next
1.57 + itCur=this;
1.58 + return NULL;
1.59 + }
1.60 + }
1.61 +
1.62 + // We have an itCur
1.63 + if (itCur==po)
1.64 + { // We come from parent
1.65 + if (bo)
1.66 + {
1.67 + // there are children, go there
1.68 + itCur=this;
1.69 + return bo;
1.70 + }
1.71 + else
1.72 + { // no children, try to go up again
1.73 + if (po)
1.74 + {
1.75 + // go back to parent and try to find next there
1.76 + itCur=this;
1.77 + lmo=po->next();
1.78 + itCur=this;
1.79 + return lmo;
1.80 +
1.81 + }
1.82 + else
1.83 + {
1.84 + // can't go up, I am mapCenter, no next
1.85 + itCur=NULL;
1.86 + return NULL;
1.87 + }
1.88 + }
1.89 + }
1.90 +
1.91 + // We don't come from parent, but from brother or children
1.92 +
1.93 + // Try to find last child, where we came from, in my own children
1.94 + bool searching=true;
1.95 + int i=0;
1.96 + while (i<branch.size())
1.97 + {
1.98 + // Try to find itCur in my own children
1.99 + if (itCur==branch.at(i))
1.100 + {
1.101 + // ok, we come from my own children
1.102 + if (i<branch.size()-1)
1.103 + bo=branch.at(i+1);
1.104 + else
1.105 + bo=NULL;
1.106 + searching=false;
1.107 + i=branch.size();
1.108 + }
1.109 + ++i;
1.110 + }
1.111 + if (!searching)
1.112 + { // found itCur in my children
1.113 + if (bo)
1.114 + {
1.115 + // found a brother of lastLMO
1.116 + itCur=this;
1.117 + return bo;
1.118 + }
1.119 + else
1.120 + {
1.121 + if (po)
1.122 + {
1.123 + if (this==itFirst) return NULL; // Stop at starting point
1.124 + // go up
1.125 + itCur=this;
1.126 + lmo=po->next();
1.127 + itCur=this;
1.128 + return lmo;
1.129 + }
1.130 + else
1.131 + {
1.132 + // can't go up, I am mapCenter
1.133 + itCur=NULL;
1.134 + return NULL;
1.135 + }
1.136 + }
1.137 + }
1.138 +
1.139 + // couldn't find last child, it must be a nephew of mine
1.140 + if (branch.size()>0)
1.141 + {
1.142 + // proceed with my first child
1.143 + itCur=this;
1.144 + return branch.first();
1.145 + }
1.146 + else
1.147 + {
1.148 + // or go back to my parents
1.149 + if (po)
1.150 + {
1.151 + // go up
1.152 + itCur=this;
1.153 + lmo=po->next();
1.154 + itCur=this;
1.155 + return lmo;
1.156 + }
1.157 + else
1.158 + {
1.159 + // can't go up, I am mapCenter
1.160 + itCur=NULL;
1.161 + return NULL;
1.162 + }
1.163 + }
1.164 + */
1.165 +}
1.166 +
1.167 +QModelIndex TreeModel::index (TreeItem* ti)
1.168 +{
1.169 + return createIndex (ti->row(),ti->column(),ti);
1.170 +}
1.171 +
1.172 +TreeItem* TreeModel::LMOToItem (LinkableMapObj *lmo)// FIXME not used so far!!!
1.173 +{
1.174 + TreeItem *ti=rootItem;
1.175 +}
1.176 +
1.177 +void TreeModel::setupModelData(TreeItem *root) // FIXME not needed anymore
1.178 {
1.179 QList<QVariant> cData;
1.180
1.181 @@ -125,6 +279,4 @@
1.182 cData.clear();
1.183 cData << "Main B"<<"Branch" <<"Data 3";
1.184 mco->appendChild(new TreeItem(cData, mco));
1.185 -
1.186 - //QModelIndex ix=index (0,0,QModelIndex() );
1.187 }