Various fixes, also from 1.12. branch
6 TreeItem* TreeModel::itFirst=NULL;
7 TreeItem* TreeModel::itCur=NULL;
9 TreeModel::TreeModel(QObject *parent)
10 : QAbstractItemModel(parent)
12 QList<QVariant> rootData;
13 rootData << "Heading" << "Type" <<"Note";
14 rootItem = new TreeItem(rootData);
15 // setupModelData(rootItem);
18 TreeModel::~TreeModel()
23 int TreeModel::columnCount(const QModelIndex &parent) const
26 return static_cast<TreeItem*>(parent.internalPointer())->columnCount();
28 return rootItem->columnCount();
31 QVariant TreeModel::data(const QModelIndex &index, int role) const
36 if (role != Qt::DisplayRole)
39 TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
41 return item->data(index.column());
44 Qt::ItemFlags TreeModel::flags(const QModelIndex &index) const
47 return Qt::ItemIsEnabled;
49 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
52 QVariant TreeModel::headerData(int section, Qt::Orientation orientation,
55 if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
56 return rootItem->data(section);
61 QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
66 if (!parent.isValid())
67 parentItem = rootItem;
69 parentItem = static_cast<TreeItem*>(parent.internalPointer());
71 TreeItem *childItem = parentItem->child(row);
73 return createIndex(row, column, childItem);
78 QModelIndex TreeModel::parent(const QModelIndex &index) const
83 TreeItem *childItem = static_cast<TreeItem*>(index.internalPointer());
84 TreeItem *parentItem = childItem->parent();
86 if (parentItem == rootItem)
89 return createIndex(parentItem->row(), 0, parentItem);
92 int TreeModel::rowCount(const QModelIndex &parent) const
96 if (!parent.isValid())
97 parentItem = rootItem;
99 parentItem = static_cast<TreeItem*>(parent.internalPointer());
101 return parentItem->childCount();
104 TreeItem* TreeModel::first()
111 TreeItem* TreeModel::next()
116 BranchObj *po=(BranchObj*)parObj;
118 if (branch.isEmpty())
125 // no itCur, we are just beginning
128 // we have children, return first one
134 // No children, so there is no next
142 { // We come from parent
145 // there are children, go there
150 { // no children, try to go up again
153 // go back to parent and try to find next there
162 // can't go up, I am mapCenter, no next
169 // We don't come from parent, but from brother or children
171 // Try to find last child, where we came from, in my own children
174 while (i<branch.size())
176 // Try to find itCur in my own children
177 if (itCur==branch.at(i))
179 // ok, we come from my own children
180 if (i<branch.size()-1)
190 { // found itCur in my children
193 // found a brother of lastLMO
201 if (this==itFirst) return NULL; // Stop at starting point
210 // can't go up, I am mapCenter
217 // couldn't find last child, it must be a nephew of mine
220 // proceed with my first child
222 return branch.first();
226 // or go back to my parents
237 // can't go up, I am mapCenter
245 QModelIndex TreeModel::index (TreeItem* ti)
247 return createIndex (ti->row(),ti->column(),ti);
250 TreeItem* TreeModel::LMOToItem (LinkableMapObj *lmo)// FIXME not used so far!!!
252 TreeItem *ti=rootItem;
255 void TreeModel::setupModelData(TreeItem *root) // FIXME not needed anymore
257 QList<QVariant> cData;
259 cData << "Center of map" << "MapCenter"<<"Data 1";
260 TreeItem *mco=new TreeItem (cData,root);
261 root->appendChild (mco);
264 cData << "Main A" << "Branch"<<"Data 2";
265 TreeItem *bo=new TreeItem (cData,mco);
266 mco->appendChild (bo);
270 cData << "Sub a" << "Branch"<<"Data";
271 bo=new TreeItem (cData,mainA);
272 mainA->appendChild (bo);
275 cData << "Sub b" << "Branch"<<"Data";
276 bo=new TreeItem (cData,mainA);
277 mainA->appendChild (bo);
280 cData << "Main B"<<"Branch" <<"Data 3";
281 mco->appendChild(new TreeItem(cData, mco));