1.1 --- a/exports.cpp Wed Feb 04 11:52:52 2009 +0000
1.2 +++ b/exports.cpp Wed Feb 04 16:33:16 2009 +0000
1.3 @@ -143,51 +143,57 @@
1.4 QString s;
1.5 QString curIndent;
1.6 int i;
1.7 + TreeItem *ti;
1.8 + ti=model->first();
1.9 BranchObj *bo;
1.10 - bo=model->first();
1.11 - while (bo)
1.12 + while (ti)
1.13 {
1.14 - // Make indentstring
1.15 - curIndent="";
1.16 - for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
1.17 + if (ti->getType()==TreeItem::Branch || ti->getType()==TreeItem::MapCenter)
1.18 + {
1.19 + bo=(BranchObj*)(ti->getLMO());
1.20
1.21 - if (!bo->hasHiddenExportParent() )
1.22 - {
1.23 - switch (bo->getDepth())
1.24 + // Make indentstring
1.25 + curIndent="";
1.26 + for (i=0;i<ti->depth()-1;i++) curIndent+= indentPerDepth;
1.27 +
1.28 + if (!bo->hasHiddenExportParent() )
1.29 {
1.30 - case 0:
1.31 - ts << underline (bo->getHeading(),QString("="));
1.32 - ts << "\n";
1.33 - break;
1.34 - case 1:
1.35 - ts << "\n";
1.36 - ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
1.37 - ts << "\n";
1.38 - break;
1.39 - case 2:
1.40 - ts << "\n";
1.41 - ts << (curIndent + "* " + bo->getHeading());
1.42 - ts << "\n";
1.43 - break;
1.44 - case 3:
1.45 - ts << (curIndent + "- " + bo->getHeading());
1.46 - ts << "\n";
1.47 - break;
1.48 - default:
1.49 - ts << (curIndent + "- " + bo->getHeading());
1.50 - ts << "\n";
1.51 - break;
1.52 - }
1.53 + switch (ti->depth())
1.54 + {
1.55 + case 0:
1.56 + ts << underline (ti->getHeading(),QString("="));
1.57 + ts << "\n";
1.58 + break;
1.59 + case 1:
1.60 + ts << "\n";
1.61 + ts << (underline (getSectionString(bo) + ti->getHeading(), QString("-") ) );
1.62 + ts << "\n";
1.63 + break;
1.64 + case 2:
1.65 + ts << "\n";
1.66 + ts << (curIndent + "* " + ti->getHeading());
1.67 + ts << "\n";
1.68 + break;
1.69 + case 3:
1.70 + ts << (curIndent + "- " + ti->getHeading());
1.71 + ts << "\n";
1.72 + break;
1.73 + default:
1.74 + ts << (curIndent + "- " + ti->getHeading());
1.75 + ts << "\n";
1.76 + break;
1.77 + }
1.78
1.79 - // If necessary, write note
1.80 - if (!bo->getNote().isEmpty())
1.81 - {
1.82 - curIndent +=" | ";
1.83 - s=bo->getNoteASCII( curIndent, 80);
1.84 - ts << s;
1.85 + // If necessary, write note
1.86 + if (!bo->getNote().isEmpty())
1.87 + {
1.88 + curIndent +=" | ";
1.89 + s=bo->getNoteASCII( curIndent, 80);
1.90 + ts << s;
1.91 + }
1.92 }
1.93 }
1.94 - bo=model->next(bo);
1.95 + ti=model->next();
1.96 }
1.97 file.close();
1.98 }
1.99 @@ -219,9 +225,11 @@
1.100 QString curIndent("");
1.101 int i;
1.102 BranchObj *bo;
1.103 - bo=model->first();
1.104 - while (bo)
1.105 + TreeItem *ti=model->first();
1.106 + while (ti)
1.107 {
1.108 + bo=(BranchObj*)(ti->getLMO());
1.109 +
1.110 if (!bo->hasHiddenExportParent() )
1.111 {
1.112 // If necessary, write note
1.113 @@ -234,13 +242,13 @@
1.114 ts <<"\"\",";
1.115
1.116 // Make indentstring
1.117 - for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
1.118 + for (i=0;i<ti->depth();i++) curIndent+= "\"\",";
1.119
1.120 // Write heading
1.121 - ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
1.122 + ts << curIndent << "\"" << ti->getHeading()<<"\""<<endl;
1.123 }
1.124
1.125 - bo=model->next(bo);
1.126 + ti=model->next();
1.127 curIndent="";
1.128 }
1.129 file.close();
1.130 @@ -344,34 +352,39 @@
1.131 // QString curIndent("");
1.132 // int i;
1.133 BranchObj *bo;
1.134 - bo=model->first();
1.135 - while (bo) {
1.136 + TreeItem *ti=model->first();
1.137 + while (ti)
1.138 + {
1.139 + bo=(BranchObj*)(ti->getLMO());
1.140 +
1.141 if (!bo->hasHiddenExportParent() )
1.142 {
1.143 - if (bo->getDepth()==0);
1.144 - else if (bo->getDepth()==1) {
1.145 - ts << ("\\chapter{" + bo->getHeading()+ "}\n");
1.146 + switch (ti->depth() )
1.147 + {
1.148 + case 0: break;
1.149 + case 1:
1.150 + ts << ("\\chapter{" + bo->getHeading()+ "}\n");
1.151 + break;
1.152 + case 2:
1.153 + ts << ("\\section{" + bo->getHeading()+ "}\n");
1.154 + break;
1.155 + case 3:
1.156 + ts << ("\\subsection{" + bo->getHeading()+ "}\n");
1.157 + break;
1.158 + case 4:
1.159 + ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
1.160 + break;
1.161 + default:
1.162 + ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
1.163 +
1.164 }
1.165 - else if (bo->getDepth()==2) {
1.166 - ts << ("\\section{" + bo->getHeading()+ "}\n");
1.167 - }
1.168 - else if (bo->getDepth()==3) {
1.169 - ts << ("\\subsection{" + bo->getHeading()+ "}\n");
1.170 - }
1.171 - else if (bo->getDepth()==4) {
1.172 - ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
1.173 - }
1.174 - else {
1.175 - ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
1.176 - }
1.177 -
1.178 // If necessary, write note
1.179 if (!bo->getNote().isEmpty()) {
1.180 ts << (bo->getNoteASCII());
1.181 ts << ("\n");
1.182 }
1.183 }
1.184 - bo=model->next(bo);
1.185 + ti=model->next();
1.186 }
1.187 file.close();
1.188 }
2.1 --- a/mapeditor.cpp Wed Feb 04 11:52:52 2009 +0000
2.2 +++ b/mapeditor.cpp Wed Feb 04 16:33:16 2009 +0000
2.3 @@ -291,17 +291,19 @@
2.4 QPointF p;
2.5 QPointF q;
2.6 BranchObj *bo;
2.7 - bo=model->first();
2.8 - while (bo)
2.9 + TreeItem *ti=model->first();
2.10 + while (ti)
2.11 {
2.12 - if (bo->getDepth() >0 && !bo->hasScrolledParent(bo) )
2.13 + bo=(BranchObj*)(ti->getLMO());
2.14 +
2.15 + if (ti->depth() >0 && !bo->hasScrolledParent(bo) )
2.16 {
2.17 p=QPointF (qrand() %600-300, qrand () %600-300);
2.18 bo->setRelPos();
2.19 q=bo->getRelPos();
2.20 model->startAnimation (bo,p, q);
2.21 }
2.22 - bo=model->next(bo);
2.23 + ti=model->next();
2.24 }
2.25
2.26
3.1 --- a/treeitem.cpp Wed Feb 04 11:52:52 2009 +0000
3.2 +++ b/treeitem.cpp Wed Feb 04 16:33:16 2009 +0000
3.3 @@ -66,6 +66,18 @@
3.4 return 0;
3.5 }
3.6
3.7 +int TreeItem::depth()
3.8 +{
3.9 + int d=-1;
3.10 + TreeItem *ti=this;
3.11 + while (ti!=NULL)
3.12 + {
3.13 + ti=ti->parent();
3.14 + d++;
3.15 + }
3.16 + return d;
3.17 +}
3.18 +
3.19 TreeItem *TreeItem::parent()
3.20 {
3.21 return parentItem;
4.1 --- a/treeitem.h Wed Feb 04 11:52:52 2009 +0000
4.2 +++ b/treeitem.h Wed Feb 04 16:33:16 2009 +0000
4.3 @@ -23,6 +23,7 @@
4.4
4.5 int row() const;
4.6 int column() const;
4.7 + int depth() ;
4.8 TreeItem *parent();
4.9
4.10 // Accessing data
5.1 --- a/treemodel.cpp Wed Feb 04 11:52:52 2009 +0000
5.2 +++ b/treemodel.cpp Wed Feb 04 16:33:16 2009 +0000
5.3 @@ -3,8 +3,8 @@
5.4 #include "treeitem.h"
5.5 #include "treemodel.h"
5.6
5.7 -TreeItem* TreeModel::itFirst=NULL;
5.8 -TreeItem* TreeModel::itCur=NULL;
5.9 +QModelIndex TreeModel::ixCur=QModelIndex();
5.10 +TreeItem* TreeModel::itStartParent=NULL;
5.11
5.12 TreeModel::TreeModel(QObject *parent)
5.13 : QAbstractItemModel(parent)
5.14 @@ -102,143 +102,25 @@
5.15
5.16 TreeItem* TreeModel::first()
5.17 {
5.18 - itCur=NULL;
5.19 - itFirst=rootItem;
5.20 - return rootItem;
5.21 + if (rootItem->childCount() ==0)
5.22 + {
5.23 + ixCur=QModelIndex();
5.24 + return NULL;
5.25 + }
5.26 + ixCur=index (0,0);
5.27 + return static_cast<TreeItem*>(ixCur.internalPointer());
5.28 }
5.29
5.30 TreeItem* TreeModel::next()
5.31 {
5.32 -/*
5.33 - BranchObj *bo;
5.34 - BranchObj *lmo;
5.35 - BranchObj *po=(BranchObj*)parObj;
5.36 + if (!ixCur.isValid() )
5.37 + return NULL;
5.38
5.39 - if (branch.isEmpty())
5.40 - bo=NULL;
5.41 - else
5.42 - bo=branch.first();
5.43 + ixCur=index (ixCur.row()+1,0);
5.44 + if (ixCur.isValid())
5.45 + return static_cast<TreeItem*>(ixCur.internalPointer());
5.46 + return NULL;
5.47
5.48 - if (!itCur)
5.49 - {
5.50 - // no itCur, we are just beginning
5.51 - if (bo)
5.52 - {
5.53 - // we have children, return first one
5.54 - itCur=this;
5.55 - return bo;
5.56 - }
5.57 - else
5.58 - {
5.59 - // No children, so there is no next
5.60 - itCur=this;
5.61 - return NULL;
5.62 - }
5.63 - }
5.64 -
5.65 - // We have an itCur
5.66 - if (itCur==po)
5.67 - { // We come from parent
5.68 - if (bo)
5.69 - {
5.70 - // there are children, go there
5.71 - itCur=this;
5.72 - return bo;
5.73 - }
5.74 - else
5.75 - { // no children, try to go up again
5.76 - if (po)
5.77 - {
5.78 - // go back to parent and try to find next there
5.79 - itCur=this;
5.80 - lmo=po->next();
5.81 - itCur=this;
5.82 - return lmo;
5.83 -
5.84 - }
5.85 - else
5.86 - {
5.87 - // can't go up, I am mapCenter, no next
5.88 - itCur=NULL;
5.89 - return NULL;
5.90 - }
5.91 - }
5.92 - }
5.93 -
5.94 - // We don't come from parent, but from brother or children
5.95 -
5.96 - // Try to find last child, where we came from, in my own children
5.97 - bool searching=true;
5.98 - int i=0;
5.99 - while (i<branch.size())
5.100 - {
5.101 - // Try to find itCur in my own children
5.102 - if (itCur==branch.at(i))
5.103 - {
5.104 - // ok, we come from my own children
5.105 - if (i<branch.size()-1)
5.106 - bo=branch.at(i+1);
5.107 - else
5.108 - bo=NULL;
5.109 - searching=false;
5.110 - i=branch.size();
5.111 - }
5.112 - ++i;
5.113 - }
5.114 - if (!searching)
5.115 - { // found itCur in my children
5.116 - if (bo)
5.117 - {
5.118 - // found a brother of lastLMO
5.119 - itCur=this;
5.120 - return bo;
5.121 - }
5.122 - else
5.123 - {
5.124 - if (po)
5.125 - {
5.126 - if (this==itFirst) return NULL; // Stop at starting point
5.127 - // go up
5.128 - itCur=this;
5.129 - lmo=po->next();
5.130 - itCur=this;
5.131 - return lmo;
5.132 - }
5.133 - else
5.134 - {
5.135 - // can't go up, I am mapCenter
5.136 - itCur=NULL;
5.137 - return NULL;
5.138 - }
5.139 - }
5.140 - }
5.141 -
5.142 - // couldn't find last child, it must be a nephew of mine
5.143 - if (branch.size()>0)
5.144 - {
5.145 - // proceed with my first child
5.146 - itCur=this;
5.147 - return branch.first();
5.148 - }
5.149 - else
5.150 - {
5.151 - // or go back to my parents
5.152 - if (po)
5.153 - {
5.154 - // go up
5.155 - itCur=this;
5.156 - lmo=po->next();
5.157 - itCur=this;
5.158 - return lmo;
5.159 - }
5.160 - else
5.161 - {
5.162 - // can't go up, I am mapCenter
5.163 - itCur=NULL;
5.164 - return NULL;
5.165 - }
5.166 - }
5.167 - */
5.168 }
5.169
5.170 #include <iostream>
5.171 @@ -248,7 +130,6 @@
5.172 beginRemoveRows (parent,row,last);
5.173
5.174 TreeItem *pi= static_cast<TreeItem*>(parent.internalPointer());
5.175 - TreeItem *ti;
5.176 for (int i=row; i<=last; i++)
5.177 {
5.178 std::cout << "TreeModel::removeRows removing i="<<i<<std::endl;
6.1 --- a/treemodel.h Wed Feb 04 11:52:52 2009 +0000
6.2 +++ b/treemodel.h Wed Feb 04 16:33:16 2009 +0000
6.3 @@ -37,8 +37,8 @@
6.4
6.5 protected:
6.6 TreeItem *rootItem;
6.7 - static TreeItem* itFirst;
6.8 - static TreeItem* itCur;
6.9 + static QModelIndex ixCur;
6.10 + static TreeItem *itStartParent;
6.11 };
6.12
6.13 #endif
7.1 --- a/vymmodel.cpp Wed Feb 04 11:52:52 2009 +0000
7.2 +++ b/vymmodel.cpp Wed Feb 04 16:33:16 2009 +0000
7.3 @@ -703,7 +703,7 @@
7.4 return fio;
7.5 }
7.6 return NULL;
7.7 - }
7.8 +}
7.9
7.10 void VymModel::loadFloatImage ()
7.11 {
7.12 @@ -1353,36 +1353,6 @@
7.13 return mapScene;
7.14 }
7.15
7.16 -BranchObj* VymModel::first()
7.17 -{
7.18 - if (mapCenters.count()>0)
7.19 - return mapCenters.first();
7.20 - else
7.21 - return NULL;
7.22 -}
7.23 -
7.24 -BranchObj* VymModel::next(BranchObj *bo_start)
7.25 -{
7.26 - BranchObj *rbo;
7.27 - BranchObj *bo=bo_start;
7.28 - if (bo)
7.29 - {
7.30 - // Try to find next branch in current MapCenter
7.31 - rbo=bo->next();
7.32 - if (rbo) return rbo;
7.33 -
7.34 - // Try to find MapCenter of bo
7.35 - while (bo->getDepth()>0) bo=(BranchObj*)bo->getParObj();
7.36 -
7.37 - // Try to find next MapCenter
7.38 - int i=mapCenters.indexOf ((MapCenterObj*)bo);
7.39 - if (i+2 > mapCenters.count() || i<0) return NULL;
7.40 - if (mapCenters.at(i+1)!=bo_start)
7.41 - return mapCenters.at(i+1);
7.42 - }
7.43 - return NULL;
7.44 -}
7.45 -
7.46 LinkableMapObj* VymModel::findMapObj(QPointF p, LinkableMapObj *excludeLMO)
7.47 {
7.48 LinkableMapObj *lmo;
7.49 @@ -1520,8 +1490,9 @@
7.50 }
7.51 }
7.52
7.53 -BranchObj* VymModel::findText (QString s, bool cs)
7.54 +BranchObj* VymModel::findText (QString s, bool cs) // FIXME needs to converted to first() next() next (ti)
7.55 {
7.56 + /*
7.57 QTextDocument::FindFlags flags=0;
7.58 if (cs) flags=QTextDocument::FindCaseSensitively;
7.59
7.60 @@ -1571,6 +1542,7 @@
7.61 return getSelectedBranch();
7.62 else
7.63 return NULL;
7.64 + */
7.65 }
7.66
7.67 void VymModel::findReset()
7.68 @@ -3925,13 +3897,13 @@
7.69 else
7.70 linkstyle=LinkableMapObj::UndefinedStyle;
7.71
7.72 + TreeItem *ti=first();
7.73 BranchObj *bo;
7.74 - bo=first();
7.75 - bo=next(bo);
7.76 - while (bo)
7.77 + while (ti)
7.78 {
7.79 + bo=(BranchObj*)(ti->getLMO() );
7.80 bo->setLinkStyle(bo->getDefLinkStyle());
7.81 - bo=next(bo);
7.82 + ti=next();
7.83 }
7.84 reposition();
7.85 }
7.86 @@ -3951,12 +3923,14 @@
7.87 );
7.88
7.89 defLinkColor=col;
7.90 + TreeItem *ti;
7.91 BranchObj *bo;
7.92 - bo=first();
7.93 - while (bo)
7.94 + ti=first();
7.95 + while (ti)
7.96 {
7.97 + bo=(BranchObj*)(ti->getLMO() );
7.98 bo->setLinkColor();
7.99 - bo=next(bo);
7.100 + ti=next();
7.101 }
7.102 updateActions();
7.103 }
7.104 @@ -3964,12 +3938,14 @@
7.105 void VymModel::setMapLinkColorHintInt()
7.106 {
7.107 // called from setMapLinkColorHint(lch) or at end of parse
7.108 + TreeItem *ti;
7.109 BranchObj *bo;
7.110 - bo=first();
7.111 - while (bo)
7.112 + ti=first();
7.113 + while (ti)
7.114 {
7.115 + bo=(BranchObj*)(ti->getLMO() );
7.116 bo->setLinkColor();
7.117 - bo=next(bo);
7.118 + ti=next();
7.119 }
7.120 }
7.121
7.122 @@ -3985,12 +3961,14 @@
7.123 linkcolorhint=LinkableMapObj::DefaultColor;
7.124 else
7.125 linkcolorhint=LinkableMapObj::HeadingColor;
7.126 + TreeItem *ti;
7.127 BranchObj *bo;
7.128 - bo=first();
7.129 + ti=first();
7.130 while (bo)
7.131 {
7.132 + bo=(BranchObj*)(ti->getLMO() );
7.133 bo->setLinkColor();
7.134 - bo=next(bo);
7.135 + ti=next();
7.136 }
7.137 }
7.138
8.1 --- a/vymmodel.h Wed Feb 04 11:52:52 2009 +0000
8.2 +++ b/vymmodel.h Wed Feb 04 16:33:16 2009 +0000
8.3 @@ -212,9 +212,6 @@
8.4 void setScene(QGraphicsScene *s);
8.5 QGraphicsScene *getScene();
8.6
8.7 - BranchObj* first();
8.8 - BranchObj* next(BranchObj *bo);
8.9 -
8.10 LinkableMapObj* findMapObj(QPointF,LinkableMapObj*); // find MapObj
8.11 LinkableMapObj* findObjBySelect (const QString &s); // find MapObj by select string
8.12 LinkableMapObj* findID (const QString &s); // find MapObj by previously set ID
9.1 --- a/xml-freemind.cpp Wed Feb 04 11:52:52 2009 +0000
9.2 +++ b/xml-freemind.cpp Wed Feb 04 16:33:16 2009 +0000
9.3 @@ -67,16 +67,23 @@
9.4 "saved using freemind " +atts.value("version")+". "
9.5 "The version of this vym can parse freemind " + v +".");
9.6 }
9.7 + TreeItem *ti=model->first(); // FIXME this will be NULL !!!
9.8 + BranchObj *bo;
9.9 + if (ti->getType()==TreeItem::MapCenter)
9.10 + bo=(BranchObj*)(ti->getLMO());
9.11 + else
9.12 + qWarning ("parseFreeMindHandler::startElement no mapCenter!!");
9.13 +
9.14 cout <<"model="<<model<<" first="<<model->first()<<endl;
9.15 - model->first()->addBranch();
9.16 - lastBranch=model->first()->getLastBranch();
9.17 +
9.18 + lastBranch=bo->addBranch();
9.19 +
9.20 lastBranch->move2RelPos (200,0);
9.21 lastBranch->setHeading (" ");
9.22 - model->first()->addBranch();
9.23 - lastBranch=model->first()->getLastBranch();
9.24 + lastBranch=bo->addBranch();
9.25 lastBranch->move2RelPos (-200,0);
9.26 lastBranch->setHeading (" ");
9.27 - lastBranch=model->first();
9.28 + lastBranch=bo;
9.29
9.30 } else if ( eName == "node" && (state == StateMap || state == StateNode ))
9.31 {
10.1 --- a/xml-vym.cpp Wed Feb 04 11:52:52 2009 +0000
10.2 +++ b/xml-vym.cpp Wed Feb 04 16:33:16 2009 +0000
10.3 @@ -51,7 +51,7 @@
10.4 {
10.5 // Create mapCenter
10.6 model->clear();
10.7 - lastBranch=model->first(); // avoid empty pointer
10.8 + lastBranch=NULL;
10.9
10.10 if (!atts.value( "author").isEmpty() )
10.11 model->setAuthor(atts.value( "author" ) );
10.12 @@ -182,7 +182,7 @@
10.13 // selection==lmo==NULL
10.14 // Treat it like ImportAdd then...
10.15 loadMode=ImportAdd;
10.16 - lmo=model->first();
10.17 + lmo=model->first()->getLMO();
10.18 }
10.19 if (lmo && ( (typeid(*lmo) == typeid(BranchObj) )
10.20 || (typeid(*lmo) == typeid(MapCenterObj) ) ) )