# HG changeset patch # User insilmaril # Date 1236351778 0 # Node ID 1b4d1ea6ea8cb83f1aaa199f07ce5ef0fa7d942a # Parent 6dc0a20031f74cd4106e4263ac7cefdb97a47c67 Iteration over map works now (again) diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c editxlinkdialog.cpp --- a/editxlinkdialog.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/editxlinkdialog.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -62,8 +62,8 @@ if (xlo) { if (selection && - (typeid(*selection) == typeid(BranchObj)) || - (typeid(*selection) == typeid(MapCenterObj)) ) + (typeid(*selection) == typeid(BranchObj) || + typeid(*selection) == typeid(MapCenterObj)) ) { QColor col=((BranchObj*)(selection))->getColor(); xlo->setColor(col); diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c exports.cpp --- a/exports.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/exports.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -143,43 +143,47 @@ QString s; QString curIndent; int i; - TreeItem *ti; - ti=model->first(); + TreeItem *cur=NULL; + TreeItem *prev=NULL; + int d; + BranchObj *bo; - while (ti) + cur=model->next (cur,prev,d); + while (cur) { - if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::MapCenter) + if (cur->getType()==TreeItem::Branch || cur->getType()==TreeItem::MapCenter) { - bo=(BranchObj*)(ti->getLMO()); + bo=(BranchObj*)(cur->getLMO()); + std::cout << "ExportASCII:: "<getHeading().toStdString()<depth()-1;i++) curIndent+= indentPerDepth; + for (i=0;idepth()-1;i++) curIndent+= indentPerDepth; if (!bo->hasHiddenExportParent() ) { - switch (ti->depth()) + switch (cur->depth()) { case 0: - ts << underline (ti->getHeading(),QString("=")); + ts << underline (cur->getHeading(),QString("=")); ts << "\n"; break; case 1: ts << "\n"; - ts << (underline (getSectionString(bo) + ti->getHeading(), QString("-") ) ); + ts << (underline (getSectionString(bo) + cur->getHeading(), QString("-") ) ); ts << "\n"; break; case 2: ts << "\n"; - ts << (curIndent + "* " + ti->getHeading()); + ts << (curIndent + "* " + cur->getHeading()); ts << "\n"; break; case 3: - ts << (curIndent + "- " + ti->getHeading()); + ts << (curIndent + "- " + cur->getHeading()); ts << "\n"; break; default: - ts << (curIndent + "- " + ti->getHeading()); + ts << (curIndent + "- " + cur->getHeading()); ts << "\n"; break; } @@ -193,7 +197,7 @@ } } } - ti=model->next(); + cur=model->next(cur,prev,d); } file.close(); } @@ -225,10 +229,13 @@ QString curIndent(""); int i; BranchObj *bo; - TreeItem *ti=model->first(); - while (ti) + TreeItem *cur=NULL; + TreeItem *prev=NULL; + int d; + cur=model->next (cur,prev,d); + while (cur) { - bo=(BranchObj*)(ti->getLMO()); + bo=(BranchObj*)(cur->getLMO()); if (!bo->hasHiddenExportParent() ) { @@ -242,13 +249,13 @@ ts <<"\"\","; // Make indentstring - for (i=0;idepth();i++) curIndent+= "\"\","; + for (i=0;idepth();i++) curIndent+= "\"\","; // Write heading - ts << curIndent << "\"" << ti->getHeading()<<"\""<getHeading()<<"\""<next(); + cur=model->next(cur,prev,d); curIndent=""; } file.close(); @@ -352,14 +359,17 @@ // QString curIndent(""); // int i; BranchObj *bo; - TreeItem *ti=model->first(); - while (ti) + TreeItem *cur=NULL; + TreeItem *prev=NULL; + int d; + model->next(cur,prev,d); + while (cur) { - bo=(BranchObj*)(ti->getLMO()); + bo=(BranchObj*)(cur->getLMO()); if (!bo->hasHiddenExportParent() ) { - switch (ti->depth() ) + switch (cur->depth() ) { case 0: break; case 1: @@ -384,7 +394,7 @@ ts << ("\n"); } } - ti=model->next(); + cur=model->next(cur,prev,d); } file.close(); } diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c mapeditor.cpp --- a/mapeditor.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/mapeditor.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -282,30 +282,41 @@ void MapEditor::testFunction1() { + TreeItem *cur=NULL; + TreeItem *prev=NULL; + int d; + cout << "ME::testFunction1 starting to walk the map...\n"; + while (model->next (cur,prev,d) ) + cout << "*** " <getHeading().toStdString()<getSelectedBranch(); //if (bo) model->moveAway (bo); //if (bo) bo->setLinkStyle (LinkableMapObj::Line); +/* // Displacement and animation of all non-mainbranches QPointF p; QPointF q; BranchObj *bo; - TreeItem *ti=model->first(); - while (ti) + TreeItem *cur=NULL; + TreeItem *prev=NULL; + int d; + while (cur) { - bo=(BranchObj*)(ti->getLMO()); + bo=(BranchObj*)(cur->getLMO()); - if (ti->depth() >0 && !bo->hasScrolledParent(bo) ) + if (cur->depth() >0 && !bo->hasScrolledParent(bo) ) { p=QPointF (qrand() %600-300, qrand () %600-300); bo->setRelPos(); q=bo->getRelPos(); model->startAnimation (bo,p, q); } - ti=model->next(); + model->next(cur,prev,d); } - +*/ /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c treeitem.cpp --- a/treeitem.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/treeitem.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -1,5 +1,6 @@ #include +#include "branchobj.h" #include "treeitem.h" TreeItem::TreeItem(const QList &data, TreeItem *parent) @@ -9,7 +10,7 @@ lmo=NULL; branchOffset=0; - branchCount=0; + branchCounter=0; lastSelectedBranchNum=-1; } @@ -18,14 +19,17 @@ qDeleteAll(childItems); } + void TreeItem::appendChild(TreeItem *item) { childItems.append(item); - if (item->type == Branch) + + + if (item->type == Branch || item->type ==MapCenter) { - if (branchCount==0) + if (branchCounter==0) branchOffset=childItems.count()-1; - branchCount++; + branchCounter++; } } @@ -53,6 +57,11 @@ { return itemData.count(); } + +int TreeItem::branchCount() const +{ + return branchCounter; +} int TreeItem::row() const { if (parentItem) @@ -83,6 +92,18 @@ return parentItem; } +int TreeItem::num() +{ + switch (type) + { + case Undefined: return -1; + case MapCenter: return parentItem->childItems.indexOf (this) - branchOffset; + case Branch: return parentItem->childItems.indexOf (this) - branchOffset; + case Image: return -1; // FIXME + default: return -1; + } + +} QVariant TreeItem::data(int column) const { @@ -99,6 +120,30 @@ return itemData[0].toString(); } +void TreeItem::setNote(const QString s) +{ + switch (type) + { + case MapCenter: + ((BranchObj*)lmo)->setNote(s); + break; + case Branch: + ((BranchObj*)lmo)->setNote(s); + break; + default: ; + } +} + +QString TreeItem::getNote() +{ + switch (type) + { + case MapCenter: return ((BranchObj*)lmo)->getNote(); + case Branch: return ((BranchObj*)lmo)->getNote(); + default: return QString (); + } +} + void TreeItem::setType(const Type t) { type=t; @@ -132,7 +177,7 @@ TreeItem* TreeItem::getFirstBranch() { - if (branchCount>0) + if (branchCounter>0) return getBranchNum (branchOffset); else return NULL; @@ -140,8 +185,8 @@ TreeItem* TreeItem::getLastBranch() { - if (branchCount>0) - return getBranchNum (branchOffset + branchCount-1); + if (branchCounter>0) + return getBranchNum (branchOffset + branchCounter-1); else return NULL; } @@ -149,7 +194,7 @@ TreeItem* TreeItem::getBranchNum(const int &n) { - if (branchCount>0) + if (branchCounter>0) return getChildNum (branchOffset + n); else return NULL; diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c treeitem.h --- a/treeitem.h Wed Feb 04 16:33:16 2009 +0000 +++ b/treeitem.h Fri Mar 06 15:02:58 2009 +0000 @@ -20,16 +20,20 @@ TreeItem *child(int row); int childCount() const; int columnCount() const; + int branchCount() const; int row() const; int column() const; int depth() ; TreeItem *parent(); + int num(); // object index, e.g. branch number // Accessing data QVariant data(int column) const; void setHeading (const QString s); QString getHeading(); + void setNote(const QString s); + QString getNote(); void setType (const Type t); Type getType (); QString getTypeName (); @@ -47,7 +51,7 @@ LinkableMapObj* getLMO(); void setLMO (LinkableMapObj*); -private: +protected: QList childItems; QList itemData; TreeItem *parentItem; @@ -56,7 +60,7 @@ LinkableMapObj *lmo; int branchOffset; - int branchCount; + int branchCounter; int lastSelectedBranchNum; }; 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; diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c treemodel.h --- a/treemodel.h Wed Feb 04 16:33:16 2009 +0000 +++ b/treemodel.h Fri Mar 06 15:02:58 2009 +0000 @@ -27,8 +27,7 @@ int rowCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const; - TreeItem *first(); - TreeItem *next(); + TreeItem* next(TreeItem* ¤t, TreeItem* &previous, int &d0); bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() ); @@ -37,8 +36,6 @@ protected: TreeItem *rootItem; - static QModelIndex ixCur; - static TreeItem *itStartParent; }; #endif diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c version.h --- a/version.h Wed Feb 04 16:33:16 2009 +0000 +++ b/version.h Fri Mar 06 15:02:58 2009 +0000 @@ -7,7 +7,7 @@ #define __VYM_VERSION "1.13.0" //#define __VYM_CODENAME "Codename: RC-1" #define __VYM_CODENAME "Codename: development version" -#define __VYM_BUILD_DATE "2009-02-04" +#define __VYM_BUILD_DATE "2009-03-06" bool checkVersion(const QString &); diff -r 6dc0a20031f7 -r 1b4d1ea6ea8c vymmodel.cpp --- a/vymmodel.cpp Wed Feb 04 16:33:16 2009 +0000 +++ b/vymmodel.cpp Fri Mar 06 15:02:58 2009 +0000 @@ -125,7 +125,8 @@ selModel=NULL; // find routine - itFind=NULL; + findCurrent=NULL; + findPrevious=NULL; EOFind=false; // animations @@ -1490,33 +1491,38 @@ } } -BranchObj* VymModel::findText (QString s, bool cs) // FIXME needs to converted to first() next() next (ti) +BranchObj* VymModel::findText (QString s, bool cs) { - /* + int d=0; QTextDocument::FindFlags flags=0; if (cs) flags=QTextDocument::FindCaseSensitively; - if (!itFind) + if (!findCurrent) { // Nothing found or new find process if (EOFind) // nothing found, start again EOFind=false; - itFind=first(); + findCurrent=NULL; + findPrevious=NULL; + next (findCurrent,findPrevious,d); } bool searching=true; bool foundNote=false; while (searching && !EOFind) { - if (itFind) + if (findCurrent) { // Searching in Note - if (itFind->getNote().contains(s,cs)) + if (findCurrent->getNote().contains(s,cs)) { + select (findCurrent); + /* if (getSelectedBranch()!=itFind) { select(itFind); ensureSelectionVisible(); } + */ if (textEditor->findText(s,flags)) { searching=false; @@ -1524,17 +1530,16 @@ } } // Searching in Heading - if (searching && itFind->getHeading().contains (s,cs) ) + if (searching && findCurrent->getHeading().contains (s,cs) ) { - select(itFind); - ensureSelectionVisible(); + select(findCurrent); searching=false; } } if (!foundNote) { - itFind=next(itFind); - if (!itFind) EOFind=true; + if (!next(findCurrent,findPrevious,d) ) + EOFind=true; } //cout <<"still searching... "<getHeading())<first(); // FIXME this will be NULL !!! + //FIXME TreeItem *ti=model->first(); // FIXME this will be NULL !!! + TreeItem *ti=NULL; // FIXME + BranchObj *bo; if (ti->getType()==TreeItem::MapCenter) bo=(BranchObj*)(ti->getLMO()); else qWarning ("parseFreeMindHandler::startElement no mapCenter!!"); - cout <<"model="<