diff -r e3f722759c7e -r 340bc29da9a0 vymmodel.cpp --- a/vymmodel.cpp Wed May 20 15:40:14 2009 +0000 +++ b/vymmodel.cpp Tue May 26 11:23:44 2009 +0000 @@ -5,7 +5,6 @@ #include "treeitem.h" #include "branchitem.h" -#include "mapcenteritem.h" #include "editxlinkdialog.h" #include "exports.h" #include "exportxhtmldialog.h" @@ -15,8 +14,6 @@ #include "mapcenterobj.h" #include "misc.h" #include "parser.h" -#include "selection.h" - #include "warningdialog.h" #include "xml-freemind.h" @@ -121,6 +118,7 @@ // selections selModel=NULL; + selectionBlocked=false; // find routine findCurrent=NULL; @@ -245,9 +243,9 @@ s+=saveTreeToDir(tmpdir,prefix,writeflags,offset); else { - if (saveSel->getType()==TreeItem::Branch) + if (saveSel->isBranchLikeType()) // Save Subtree - s+=saveSel->saveToDir(tmpdir,prefix,offset); + s+=((BranchItem*)saveSel)->saveToDir(tmpdir,prefix,offset); //FIXME-2 else if (saveSel->getType()==TreeItem::Image) // Save image //s+=((FloatImageObj*)(saveSel))->saveToDir(tmpdir,prefix); @@ -272,7 +270,7 @@ QString s; for (int i=0; ibranchCount(); i++) - s+=((MapCenterItem*)rootItem->getBranchNum(i))->saveToDir (tmpdir,prefix,offset); + s+=rootItem->getBranchNum(i)->saveToDir (tmpdir,prefix,offset); return s; } @@ -465,7 +463,7 @@ if ( ok ) { reposition(); // FIXME-2 VM reposition the view instead... - selection.update(); + updateSelection(); if (lmode==NewMap) { mapDefault=false; @@ -585,7 +583,7 @@ makeSubDirs (fileDir); QString saveFile; - if (savemode==CompleteMap || selection.isEmpty()) + if (savemode==CompleteMap || selModel->selection().isEmpty()) { // Save complete map saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),NULL); @@ -770,7 +768,8 @@ void VymModel::saveFloatImage () { - FloatImageObj *fio=selection.getFloatImage(); + //FIXME-1 FloatImageObj *fio=selection.getFloatImage(); + FloatImageObj *fio=NULL; if (fio) { QFileDialog *fd=new QFileDialog( NULL); @@ -998,15 +997,15 @@ QString s; if (!lmo) return QString("Error: NULL has no name!"); - if ((typeid(*lmo) == typeid(BranchObj) || - typeid(*lmo) == typeid(MapCenterObj))) + TreeItem *ti=lmo->getTreeItem(); + if (ti->isBranchLikeType() ) { s=lmo->getTreeItem()->getHeading(); if (s=="") s="unnamed"; return QString("branch (%1)").arg(s); } - if ((typeid(*lmo) == typeid(FloatImageObj) )) + if (ti->getType()==TreeItem::Image) return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename()); return QString("Unknown type has no name!"); } @@ -1180,8 +1179,7 @@ mainWindow->updateHistory (undoSet); updateActions(); - selection.update(); - emitShowSelection(); + updateSelection(); } bool VymModel::isUndoAvailable() @@ -1487,12 +1485,11 @@ int c=0; BranchItem *cur=NULL; BranchItem *prev=NULL; - int d; - next(cur,prev,d); + next(cur,prev); while (cur) { c++; - next(cur,prev,d); + next(cur,prev); } return c; } @@ -1512,14 +1509,12 @@ emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem? reposition(); -// selection.update(); //FIXME-4 updateSelection(); } } BranchItem* VymModel::findText (QString s, bool cs) { - int d=0; QTextDocument::FindFlags flags=0; if (cs) flags=QTextDocument::FindCaseSensitively; @@ -1530,7 +1525,7 @@ EOFind=false; findCurrent=NULL; findPrevious=NULL; - next (findCurrent,findPrevious,d); + next (findCurrent,findPrevious); } bool searching=true; bool foundNote=false; @@ -1564,7 +1559,7 @@ } if (!foundNote) { - if (!next(findCurrent,findPrevious,d) ) + if (!next(findCurrent,findPrevious) ) EOFind=true; } //cout <<"still searching... "<getHeading())<getURL().isEmpty()) urls.append( cur->getURL()); - cur=next (cur,prev,d); + cur=next (cur,prev,selbi); } return urls; } -void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-2 -{ - FloatImageObj *fio=selection.getFloatImage(); +void VymModel::linkFloatImageTo(const QString &dstString) // FIXME-1 +{ + //FIXME-1 FloatImageObj *fio=selection.getFloatImage(); + FloatImageObj *fio=NULL; if (fio) { TreeItem *dst=findBySelectString (dstString); @@ -1645,7 +1640,7 @@ QString parString=getSelectString(dstPar); QString fioPreSelectString=getSelectString(fio); QString fioPreParentSelectString=getSelectString (fio->getParObj()); - // FIXME-2 ((BranchObj*)dst)->addFloatImage (fio); + // FIXME-1 ((BranchObj*)dst)->addFloatImage (fio); unselect(); // ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio); fio=((BranchObj*)dst)->getLastFloatImage(); @@ -1834,7 +1829,7 @@ ); updateActions(); reposition(); - // selection.update(); + // updateSelection(); // FIXME-3 VM needed? scene()->update(); } } @@ -1962,11 +1957,11 @@ */ } -MapCenterItem* VymModel::createMapCenter() -{ - MapCenterItem *mci=addMapCenter (QPointF (0,0) ); - select (mci); - return mci; +BranchItem* VymModel::createMapCenter() +{ + BranchItem *newbi=addMapCenter (QPointF (0,0) ); + select (newbi); + return newbi; } BranchItem* VymModel::createBranch() @@ -1978,8 +1973,9 @@ return NULL; } -TreeItem* VymModel::createImage() //FIXME-2 -{ +TreeItem* VymModel::createImage() //FIXME-1 +{ + return NULL; /* BranchObj *bo=getSelectedBranch(); if (bo) @@ -2002,26 +1998,25 @@ return ti; } } - return NULL; */ } -MapCenterItem* VymModel::addMapCenter () -{ - MapCenterItem *mci=addMapCenter (contextPos); +BranchItem* VymModel::addMapCenter () +{ + BranchItem *bi=addMapCenter (contextPos); updateActions(); emitShowSelection(); saveState ( - mci, + bi, "delete()", NULL, QString ("addMapCenter (%1,%2)").arg (contextPos.x()).arg(contextPos.y()), QString ("Adding MapCenter to (%1,%2)").arg (contextPos.x()).arg(contextPos.y()) ); - return mci; + return bi; } -MapCenterItem* VymModel::addMapCenter(QPointF absPos) +BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?! { // Create TreeItem @@ -2034,17 +2029,17 @@ QList cData; cData << "VM:addMapCenter" << "undef"<<"undef"; - MapCenterItem *mci=new MapCenterItem (cData); - mci->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); - rootItem->appendChild (mci); + BranchItem *newbi=new BranchItem (cData); + newbi->setHeading (QApplication::translate("Heading of mapcenter in new map", "New map")); + rootItem->appendChild (newbi); endInsertRows(); emit (layoutChanged() ); // Create MapObj - BranchObj *newbo=mci->createMapObj(mapScene); + newbi->createMapObj(mapScene); - return mci; + return newbi; } BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) //FIXME-4 simplify... @@ -2121,7 +2116,7 @@ QString ("Add new branch to %1").arg(getObjectName(selbi))); reposition(); - // selection.update(); FIXME-3 + // updateSelection(); FIXME-3 latestAddedItem=newbi; // In Network mode, the client needs to know where the new branch is, // so we have to pass on this information via saveState. @@ -2161,7 +2156,7 @@ QString ("Add branch before %1").arg(getObjectName(selbi))); // FIXME-3 needed? reposition(); - // selection.update(); FIXME-3 + // updateSelection(); FIXME-3 } } //FIXME-3 needed? latestSelectionString=selection.getSelectString(); @@ -2172,6 +2167,10 @@ { if (branch && dst) { + if (branch->depth()==0) + { + cout <<"VM::relinkBranch d=0 for "<getHeadingStd()<parent(); // Remove at current position @@ -2191,7 +2190,9 @@ dst->insertBranch (pos,branch); endInsertRows(); - branch->getLMO()->setParObj(dst->getLMO()); //FIXME-5 update parObj in View + // reset parObj, fonts, frame, etc in related LMO or other view-objects + branch->updateStyles(); + emit (layoutChanged() ); reposition(); // both for moveUp/Down and relinking select (branch); @@ -2449,49 +2450,50 @@ } -void VymModel::colorBranch (QColor c) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::colorBranch (QColor c) +{ + BranchItem *selbi=getSelectedBranchItem(); + if (selbi) { saveState( - bo, - QString ("colorBranch (\"%1\")").arg(bo->getColor().name()), - bo, + selbi, + QString ("colorBranch (\"%1\")").arg(selbi->getHeadingColor().name()), + selbi, QString ("colorBranch (\"%1\")").arg(c.name()), - QString("Set color of %1 to %2").arg(getObjectName(bo)).arg(c.name()) + QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name()) ); - bo->setColor(c); // color branch + selbi->setHeadingColor(c); // color branch } -*/ } -void VymModel::colorSubtree (QColor c) //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::colorSubtree (QColor c) +{ + BranchItem *selbi=getSelectedBranchItem(); + if (selbi) { saveStateChangingPart( - bo, - bo, + selbi, + selbi, QString ("colorSubtree (\"%1\")").arg(c.name()), - QString ("Set color of %1 and children to %2").arg(getObjectName(bo)).arg(c.name()) + QString ("Set color of %1 and children to %2").arg(getObjectName(selbi)).arg(c.name()) ); - bo->setColorSubtree (c); // color links, color children + BranchItem *prev=NULL; + BranchItem *cur=selbi; + while (cur) + { + cur->setHeadingColor(c); // color links, color children + cur=next (cur,prev,selbi); + } + } -*/ } -QColor VymModel::getCurrentHeadingColor() //FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) return bo->getColor(); - +QColor VymModel::getCurrentHeadingColor() +{ + BranchItem *selbi=getSelectedBranchItem(); + if (selbi) return selbi->getHeadingColor(); + QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected"); - */ return Qt::black; } @@ -2615,8 +2617,7 @@ bi->setVymLink(s); reposition(); updateActions(); - //selection.update(); - emitShowSelection(); + //updateSelection(); } } @@ -2651,14 +2652,13 @@ QStringList VymModel::getVymLinks() { QStringList links; - BranchItem *cur=getSelectedBranchItem(); + BranchItem *selbi=getSelectedBranchItem(); + BranchItem *cur=selbi; BranchItem *prev=NULL; - int d=0; - next (cur,prev,d); while (cur) { if (!cur->getVymLink().isEmpty()) links.append( cur->getVymLink()); - cur=next (cur,prev,d); + cur=next (cur,prev,selbi); } return links; } @@ -3027,16 +3027,16 @@ LinkableMapObj *dst=findObjBySelect (s); if (dst) { - if (typeid(*dst) == typeid(BranchObj) ) + if (typid(*dst) == typid(BranchObj) ) { // Get number in parent n=parser.parInt (ok,1); if (ok) { selb->linkTo ((BranchObj*)(dst),n); - selection.update(); + updateSelection(); } - } else if (typeid(*dst) == typeid(MapCenterObj) ) + } else if (typid(*dst) == typid(MapCenterObj) ) { selb->linkTo ((BranchObj*)(dst),-1); // Get coordinates of mainbranch @@ -3047,7 +3047,7 @@ if (ok) { selbi->move (x,y); - selection.update(); + updateSelection(); } } } @@ -3062,8 +3062,8 @@ LinkableMapObj *dst=findObjBySelect (s); if (dst) { - if (typeid(*dst) == typeid(BranchObj) || - typeid(*dst) == typeid(MapCenterObj)) + if (typid(*dst) == typid(BranchObj) || + typid(*dst) == typid(MapCenterObj)) linkFloatImageTo (getSelectString(dst)); } else parser.setError (Aborted,"Destination is not a branch"); @@ -3236,7 +3236,8 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="saveImage") { - FloatImageObj *fio=selection.getFloatImage(); + //FIXME-2 FloatImageObj *fio=selection.getFloatImage(); + FloatImageObj* fio=NULL; if (!fio) { parser.setError (Aborted,"Type of selection is not an image"); @@ -3879,9 +3880,10 @@ rootItem->getBranchObjNum(i)->reposition(); // for positioning heading } +/* QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4 { -/* + return QPolygonF (); // Creating (arbitrary) shapes QPolygonF p; @@ -3911,9 +3913,10 @@ <move(x,y); reposition(); - selection.update(); + updateSelection(); } } */ @@ -4234,7 +4232,7 @@ ((OrnamentedObj*)bo)->move2RelPos (x,y); reposition(); bo->updateLink(); - selection.update(); + updateSelection(); } } */ @@ -4294,7 +4292,7 @@ void VymModel::sendSelection() { if (netstate!=Server) return; - sendData (QString("select (\"%1\")").arg(selection.getSelectString()) ); + sendData (QString("select (\"%1\")").arg(getSelectString()) ); } void VymModel::newServer() @@ -4522,15 +4520,12 @@ void VymModel::setSelectionBlocked (bool b) { - if (b) - selection.block(); - else - selection.unblock(); + selectionBlocked=b; } bool VymModel::isSelectionBlocked() { - return selection.isBlocked(); + return selectionBlocked; } bool VymModel::select () @@ -4582,12 +4577,13 @@ void VymModel::unselect() { + lastSelectString=getSelectString(); selModel->clearSelection(); } void VymModel::reselect() { - selection.reselect(); + select (lastSelectString); } void VymModel::emitShowSelection() @@ -4614,8 +4610,7 @@ { if (selection.select(lmo)) { - //selection.update(); - sendSelection (); // FIXME-4 VM use signal + //updateSelection(); } } @@ -4623,8 +4618,7 @@ { if (selection.select(lmo)) { - //selection.update(); - sendSelection (); // FIXME-4 VM use signal + //updateSelection(); } } */ @@ -4747,8 +4741,6 @@ void VymModel::selectUpperBranch() { - if (selection.isBlocked() ) return; - BranchItem *bi=getSelectedBranchItem(); if (bi && bi->isBranchLikeType()) selectAboveBranchInt(); @@ -4756,8 +4748,6 @@ void VymModel::selectLowerBranch() { - if (selection.isBlocked() ) return; - BranchItem *bi=getSelectedBranchItem(); if (bi && bi->isBranchLikeType()) selectBelowBranchInt(); @@ -4766,8 +4756,6 @@ void VymModel::selectLeftBranch() { - if (selection.isBlocked() ) return; - QItemSelection oldsel=selModel->selection(); BranchItem* par; @@ -4806,8 +4794,6 @@ void VymModel::selectRightBranch() { - if (selection.isBlocked() ) return; - QItemSelection oldsel=selModel->selection(); BranchItem* par; @@ -4854,9 +4840,7 @@ TreeItem *ti2=par->getFirstBranch(); if (ti2) { select(ti2); - selection.update(); - emitShowSelection(); - sendSelection(); + updateSelection(); } } } @@ -4871,9 +4855,7 @@ TreeItem *ti2=par->getLastBranch(); if (ti2) { select(ti2); - selection.update(); - emitShowSelection(); - sendSelection(); + updateSelection(); } } } @@ -4897,9 +4879,7 @@ par=ti->parent(); if (!par) return; select(par); - selection.update(); - emitShowSelection(); - sendSelection(); + updateSelection(); } } @@ -4969,7 +4949,8 @@ FloatImageObj* VymModel::getSelectedFloatImage() { - return selection.getFloatImage(); + //FIXME-2 return selection.getFloatImage(); + return NULL; } QString VymModel::getSelectString ()