1.1 --- a/vymmodel.cpp Tue Aug 05 07:36:53 2008 +0000
1.2 +++ b/vymmodel.cpp Mon Oct 06 11:10:20 2008 +0000
1.3 @@ -17,6 +17,7 @@
1.4
1.5 #include "warningdialog.h"
1.6 #include "xml-freemind.h"
1.7 +#include "xmlobj.h"
1.8 #include "xml-vym.h"
1.9
1.10
1.11 @@ -118,9 +119,6 @@
1.12 itFind=NULL;
1.13 EOFind=false;
1.14
1.15 - // TreeModel
1.16 - treeModel=new TreeModel;
1.17 -
1.18 // animations
1.19 animationUse=settings.readBoolEntry("/animation/use",false);
1.20 animationTicks=settings.readNumEntry("/animation/ticks",10);
1.21 @@ -164,11 +162,6 @@
1.22 return mapEditor;
1.23 }
1.24
1.25 -TreeModel* VymModel::getTreeModel()
1.26 -{
1.27 - return treeModel;
1.28 -}
1.29 -
1.30 bool VymModel::isRepositionBlocked()
1.31 {
1.32 return blockReposition;
1.33 @@ -190,6 +183,9 @@
1.34 // offset offset of bbox of whole map in scene.
1.35 // Needed for XML export
1.36
1.37 +
1.38 + XMLObj xml;
1.39 +
1.40 // Save Header
1.41 QString ls;
1.42 switch (linkstyle)
1.43 @@ -211,22 +207,22 @@
1.44 QString s="<?xml version=\"1.0\" encoding=\"utf-8\"?><!DOCTYPE vymmap>\n";
1.45 QString colhint="";
1.46 if (linkcolorhint==LinkableMapObj::HeadingColor)
1.47 - colhint=attribut("linkColorHint","HeadingColor");
1.48 -
1.49 - QString mapAttr=attribut("version",vymVersion);
1.50 + colhint=xml.attribut("linkColorHint","HeadingColor");
1.51 +
1.52 + QString mapAttr=xml.attribut("version",vymVersion);
1.53 if (!saveSel)
1.54 - mapAttr+= attribut("author",author) +
1.55 - attribut("comment",comment) +
1.56 - attribut("date",getDate()) +
1.57 - attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
1.58 - attribut("selectionColor", selection.getColor().name() ) +
1.59 - attribut("linkStyle", ls ) +
1.60 - attribut("linkColor", defLinkColor.name() ) +
1.61 - attribut("defXLinkColor", defXLinkColor.name() ) +
1.62 - attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
1.63 + mapAttr+= xml.attribut("author",author) +
1.64 + xml.attribut("comment",comment) +
1.65 + xml.attribut("date",getDate()) +
1.66 + xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) +
1.67 + xml.attribut("selectionColor", selection.getColor().name() ) +
1.68 + xml.attribut("linkStyle", ls ) +
1.69 + xml.attribut("linkColor", defLinkColor.name() ) +
1.70 + xml.attribut("defXLinkColor", defXLinkColor.name() ) +
1.71 + xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) +
1.72 colhint;
1.73 - s+=beginElement("vymmap",mapAttr);
1.74 - incIndent();
1.75 + s+=xml.beginElement("vymmap",mapAttr);
1.76 + xml.incIndent();
1.77
1.78 // Find the used flags while traversing the tree
1.79 standardFlagsDefault->resetUsedCounter();
1.80 @@ -254,10 +250,10 @@
1.81
1.82 // Save selection
1.83 if (!selection.isEmpty() && !saveSel )
1.84 - s+=valueElement("select",selection.getSelectString());
1.85 -
1.86 - decIndent();
1.87 - s+=endElement("vymmap");
1.88 + s+=xml.valueElement("select",selection.getSelectString());
1.89 +
1.90 + xml.decIndent();
1.91 + s+=xml.endElement("vymmap");
1.92
1.93 if (writeflags)
1.94 standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags);
1.95 @@ -1488,27 +1484,33 @@
1.96 "setHeading (\""+s+"\")",
1.97 QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) );
1.98 sel->setHeading(s );
1.99 + TreeItem *ti=selection.getBranchItem();
1.100 + if (ti) ti->setHeading (s);
1.101 + //FIXME ix is wrong ModelIndex below, ix2 is (hopefully) correct:
1.102 + QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) );
1.103 + cout <<"VM::setHeading s="<<s.toStdString()<<" ti="<<ti<<" r,c=("<<ti->row()<<","<<ti->column()<<")"<<endl;
1.104 + QModelIndex ix2=index (ti);
1.105 + emit (dataChanged ( ix2,ix2));
1.106 + cout <<" (r,c)=("<<ix2.row()<<","<<ix2.column()<<")"<<endl;
1.107 +
1.108 + // FIXME playing around with selections:
1.109 + // but somehow not all mco are visible in tree then???
1.110 +// if (mapEditor)
1.111 + if (NULL)
1.112 + {
1.113 +
1.114 + QItemSelectionModel *selectionModel=mapEditor->selectionModel();
1.115 + selectionModel->clear();
1.116 + QItemSelection sel (ix2,ix2);
1.117 + selectionModel->select (sel, QItemSelectionModel::Select);
1.118 + }
1.119 +
1.120 reposition();
1.121 selection.update();
1.122 ensureSelectionVisible();
1.123 }
1.124 }
1.125
1.126 -/* FIXME delete this
1.127 -QString VymModel::getHeading(bool &ok, QPoint &p)
1.128 -{
1.129 - BranchObj *bo=selection.getBranch();
1.130 - if (bo)
1.131 - {
1.132 - ok=true;
1.133 - //p=scene->mapFromScene(bo->getAbsPos()); // FIXME this is view-dependant!!!
1.134 - return bo->getHeading();
1.135 - }
1.136 - ok=false;
1.137 - return QString();
1.138 -}
1.139 -*/
1.140 -
1.141 void VymModel::setHeadingInt(const QString &s)
1.142 {
1.143 BranchObj *bo=selection.getBranch();
1.144 @@ -1962,6 +1964,36 @@
1.145 }
1.146 }
1.147
1.148 +void VymModel::createMapCenter()
1.149 +{
1.150 + MapCenterObj *mco=addMapCenter (QPointF (0,0) );
1.151 + selection.select (mco);
1.152 +}
1.153 +
1.154 +void VymModel::createBranch()
1.155 +{
1.156 + BranchObj *bo=selection.getBranch();
1.157 + if (bo)
1.158 + {
1.159 + BranchObj *newbo=addNewBranchInt (-2); // FIXME Old model, merge with below
1.160 +
1.161 + // Create TreeItem
1.162 + QList<QVariant> cData;
1.163 + cData << "VM:createBranch" << "undef"<<"undef";
1.164 + TreeItem *parti=bo->getTreeItem();
1.165 + TreeItem *ti=new TreeItem (cData,parti);
1.166 + ti->setLMO (newbo);
1.167 + ti->setType (TreeItem::Branch);
1.168 + parti->appendChild (ti);
1.169 +
1.170 + if (newbo)
1.171 + {
1.172 + newbo->setTreeItem (ti);
1.173 + selection.select (newbo);
1.174 + }
1.175 + }
1.176 +}
1.177 +
1.178 MapCenterObj* VymModel::addMapCenter ()
1.179 {
1.180 MapCenterObj *mco=addMapCenter (contextPos);
1.181 @@ -1986,6 +2018,16 @@
1.182 mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map"));
1.183 mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects
1.184 mapCenters.append(mapCenter);
1.185 +
1.186 + // Create TreeItem
1.187 + QList<QVariant> cData;
1.188 + cData << "VM:addMapCenter" << "undef"<<"undef";
1.189 + TreeItem *ti=new TreeItem (cData,rootItem);
1.190 + ti->setLMO (mapCenter);
1.191 + ti->setType (TreeItem::MapCenter);
1.192 + mapCenter->setTreeItem (ti);
1.193 + rootItem->appendChild (ti);
1.194 +
1.195 return mapCenter;
1.196 }
1.197
1.198 @@ -2180,6 +2222,17 @@
1.199 if (bo)
1.200 {
1.201 par=(BranchObj*)(bo->getParObj());
1.202 +
1.203 + // Don't use this on mapcenter
1.204 + if (!par) return;
1.205 +
1.206 + // Check if we have childs at all to keep
1.207 + if (bo->countBranches()==0)
1.208 + {
1.209 + deleteSelection();
1.210 + return;
1.211 + }
1.212 +
1.213 QPointF p=bo->getRelPos();
1.214 saveStateChangingPart(
1.215 bo->getParObj(),
1.216 @@ -4704,6 +4757,21 @@
1.217 }
1.218 }
1.219
1.220 +void VymModel::selectParent()
1.221 +{
1.222 + LinkableMapObj *lmo=selection.first();
1.223 + BranchObj* par;
1.224 + if (lmo)
1.225 + {
1.226 + par=(BranchObj*)(lmo->getParObj());
1.227 + if (!par) return;
1.228 + selection.select(par);
1.229 + selection.update();
1.230 + ensureSelectionVisible();
1.231 + sendSelection();
1.232 + }
1.233 +}
1.234 +
1.235 Selection::Type VymModel::selectionType()
1.236 {
1.237 return selection.type();