diff -r 7ea31701156e -r 7f43b93242aa vymmodel.cpp --- a/vymmodel.cpp Tue Aug 05 07:36:53 2008 +0000 +++ b/vymmodel.cpp Mon Oct 06 11:10:20 2008 +0000 @@ -17,6 +17,7 @@ #include "warningdialog.h" #include "xml-freemind.h" +#include "xmlobj.h" #include "xml-vym.h" @@ -118,9 +119,6 @@ itFind=NULL; EOFind=false; - // TreeModel - treeModel=new TreeModel; - // animations animationUse=settings.readBoolEntry("/animation/use",false); animationTicks=settings.readNumEntry("/animation/ticks",10); @@ -164,11 +162,6 @@ return mapEditor; } -TreeModel* VymModel::getTreeModel() -{ - return treeModel; -} - bool VymModel::isRepositionBlocked() { return blockReposition; @@ -190,6 +183,9 @@ // offset offset of bbox of whole map in scene. // Needed for XML export + + XMLObj xml; + // Save Header QString ls; switch (linkstyle) @@ -211,22 +207,22 @@ QString s="\n"; QString colhint=""; if (linkcolorhint==LinkableMapObj::HeadingColor) - colhint=attribut("linkColorHint","HeadingColor"); - - QString mapAttr=attribut("version",vymVersion); + colhint=xml.attribut("linkColorHint","HeadingColor"); + + QString mapAttr=xml.attribut("version",vymVersion); if (!saveSel) - mapAttr+= attribut("author",author) + - attribut("comment",comment) + - attribut("date",getDate()) + - attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + - attribut("selectionColor", selection.getColor().name() ) + - attribut("linkStyle", ls ) + - attribut("linkColor", defLinkColor.name() ) + - attribut("defXLinkColor", defXLinkColor.name() ) + - attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + + mapAttr+= xml.attribut("author",author) + + xml.attribut("comment",comment) + + xml.attribut("date",getDate()) + + xml.attribut("backgroundColor", mapScene->backgroundBrush().color().name() ) + + xml.attribut("selectionColor", selection.getColor().name() ) + + xml.attribut("linkStyle", ls ) + + xml.attribut("linkColor", defLinkColor.name() ) + + xml.attribut("defXLinkColor", defXLinkColor.name() ) + + xml.attribut("defXLinkWidth", QString().setNum(defXLinkWidth,10) ) + colhint; - s+=beginElement("vymmap",mapAttr); - incIndent(); + s+=xml.beginElement("vymmap",mapAttr); + xml.incIndent(); // Find the used flags while traversing the tree standardFlagsDefault->resetUsedCounter(); @@ -254,10 +250,10 @@ // Save selection if (!selection.isEmpty() && !saveSel ) - s+=valueElement("select",selection.getSelectString()); - - decIndent(); - s+=endElement("vymmap"); + s+=xml.valueElement("select",selection.getSelectString()); + + xml.decIndent(); + s+=xml.endElement("vymmap"); if (writeflags) standardFlagsDefault->saveToDir (tmpdir+"/flags/","",writeflags); @@ -1488,27 +1484,33 @@ "setHeading (\""+s+"\")", QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) ); sel->setHeading(s ); + TreeItem *ti=selection.getBranchItem(); + if (ti) ti->setHeading (s); + //FIXME ix is wrong ModelIndex below, ix2 is (hopefully) correct: + QModelIndex ix=index( ti->row(), ti->column(), index (0,0,QModelIndex()) ); + cout <<"VM::setHeading s="<row()<<","<column()<<")"<selectionModel(); + selectionModel->clear(); + QItemSelection sel (ix2,ix2); + selectionModel->select (sel, QItemSelectionModel::Select); + } + reposition(); selection.update(); ensureSelectionVisible(); } } -/* FIXME delete this -QString VymModel::getHeading(bool &ok, QPoint &p) -{ - BranchObj *bo=selection.getBranch(); - if (bo) - { - ok=true; - //p=scene->mapFromScene(bo->getAbsPos()); // FIXME this is view-dependant!!! - return bo->getHeading(); - } - ok=false; - return QString(); -} -*/ - void VymModel::setHeadingInt(const QString &s) { BranchObj *bo=selection.getBranch(); @@ -1962,6 +1964,36 @@ } } +void VymModel::createMapCenter() +{ + MapCenterObj *mco=addMapCenter (QPointF (0,0) ); + selection.select (mco); +} + +void VymModel::createBranch() +{ + BranchObj *bo=selection.getBranch(); + if (bo) + { + BranchObj *newbo=addNewBranchInt (-2); // FIXME Old model, merge with below + + // Create TreeItem + QList cData; + cData << "VM:createBranch" << "undef"<<"undef"; + TreeItem *parti=bo->getTreeItem(); + TreeItem *ti=new TreeItem (cData,parti); + ti->setLMO (newbo); + ti->setType (TreeItem::Branch); + parti->appendChild (ti); + + if (newbo) + { + newbo->setTreeItem (ti); + selection.select (newbo); + } + } +} + MapCenterObj* VymModel::addMapCenter () { MapCenterObj *mco=addMapCenter (contextPos); @@ -1986,6 +2018,16 @@ mapCenter->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); mapCenter->setMapEditor(mapEditor); //FIXME needed to get defLinkStyle, mapLinkColorHint ... for later added objects mapCenters.append(mapCenter); + + // Create TreeItem + QList cData; + cData << "VM:addMapCenter" << "undef"<<"undef"; + TreeItem *ti=new TreeItem (cData,rootItem); + ti->setLMO (mapCenter); + ti->setType (TreeItem::MapCenter); + mapCenter->setTreeItem (ti); + rootItem->appendChild (ti); + return mapCenter; } @@ -2180,6 +2222,17 @@ if (bo) { par=(BranchObj*)(bo->getParObj()); + + // Don't use this on mapcenter + if (!par) return; + + // Check if we have childs at all to keep + if (bo->countBranches()==0) + { + deleteSelection(); + return; + } + QPointF p=bo->getRelPos(); saveStateChangingPart( bo->getParObj(), @@ -4704,6 +4757,21 @@ } } +void VymModel::selectParent() +{ + LinkableMapObj *lmo=selection.first(); + BranchObj* par; + if (lmo) + { + par=(BranchObj*)(lmo->getParObj()); + if (!par) return; + selection.select(par); + selection.update(); + ensureSelectionVisible(); + sendSelection(); + } +} + Selection::Type VymModel::selectionType() { return selection.type();