diff -r ac4be290c750 -r 84ae10f6e3a3 vymmodel.cpp --- a/vymmodel.cpp Thu Jan 15 00:52:35 2009 +0000 +++ b/vymmodel.cpp Tue Jan 20 15:23:16 2009 +0000 @@ -67,7 +67,7 @@ void VymModel::clear() { cout << "VymModel::clear rows="<clearSelection(); // Remove stuff while (!mapCenters.isEmpty()) // FIXME VM needs to be in treemodel only... @@ -123,8 +123,6 @@ // selections selModel=NULL; - selection.setModel (this); - selection.unselect(); // find routine itFind=NULL; @@ -342,12 +340,12 @@ if (lmode==NewMap) { - selection.clear(); + selModel->clearSelection(); // FIXME VM not needed??? model->setMapEditor(this); // (map state is set later at end of load...) } else { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (!bo) return aborted; if (lmode==ImportAdd) saveStateChangingPart( @@ -589,10 +587,10 @@ else { // Save part of map - if (selection.type()==Selection::FloatImage) + if (selectionType()==TreeItem::Image) saveFloatImage(); else - saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),selection.getBranch()); + saveFile=saveToDir (fileDir,mapName+"-",true,QPointF(),getSelectedBranch()); // TODO take care of multiselections } @@ -660,7 +658,7 @@ void VymModel::addMapInsertInt (const QString &path, int pos) { - BranchObj *sel=selection.getBranch(); + BranchObj *sel=getSelectedBranch(); if (sel) { QString pathDir=path.left(path.findRev("/")); @@ -696,7 +694,7 @@ FloatImageObj* VymModel::loadFloatImageInt (QString fn) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { FloatImageObj *fio; @@ -712,7 +710,7 @@ void VymModel::loadFloatImage () { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { @@ -810,7 +808,7 @@ void VymModel::importDirInt(BranchObj *dst, QDir d) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { // Traverse directories @@ -857,7 +855,7 @@ void VymModel::importDirInt (const QString &s) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveStateChangingPart (bo,bo,QString ("importDir (\"%1\")").arg(s),QString("Import directory structure from %1").arg(s)); @@ -869,7 +867,7 @@ void VymModel::importDir() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QStringList filters; @@ -1490,7 +1488,7 @@ void VymModel::setHeading(const QString &s) { - BranchObj *sel=selection.getBranch(); + BranchObj *sel=getSelectedBranch(); if (sel) { saveState( @@ -1500,7 +1498,8 @@ "setHeading (\""+s+"\")", QString("Set heading of %1 to \"%2\"").arg(getObjectName(sel)).arg(s) ); sel->setHeading(s ); - TreeItem *ti=selection.getBranchItem(); + /* FIXME testing only + TreeItem *ti=getSelectedBranchItem(); if (ti) { ti->setHeading (s); @@ -1517,6 +1516,7 @@ //cout <<" (r,c)=("<setHeading(s); @@ -1556,9 +1556,9 @@ // Searching in Note if (itFind->getNote().contains(s,cs)) { - if (selection.single()!=itFind) + if (getSelectedBranch()!=itFind) { - selection.select(itFind); + select(itFind); ensureSelectionVisible(); } if (textEditor->findText(s,flags)) @@ -1570,7 +1570,7 @@ // Searching in Heading if (searching && itFind->getHeading().contains (s,cs) ) { - selection.select(itFind); + select(itFind); ensureSelectionVisible(); searching=false; } @@ -1583,7 +1583,7 @@ //cout <<"still searching... "<getHeading())<getURL(); @@ -1627,7 +1627,7 @@ QString VymModel::getURL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) return bo->getURL(); else @@ -1637,7 +1637,7 @@ QStringList VymModel::getURLs() { QStringList urls; - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo=bo->first(); @@ -1683,7 +1683,7 @@ void VymModel::setFrameType(const FrameObj::FrameType &t) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString s=bo->getFrameTypeName(); @@ -1697,7 +1697,7 @@ void VymModel::setFrameType(const QString &s) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState (bo, QString("setFrameType (\"%1\")").arg(bo->getFrameTypeName()), @@ -1710,7 +1710,7 @@ void VymModel::setFramePenColor(const QColor &c) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState (bo, QString("setFramePenColor (\"%1\")").arg(bo->getFramePenColor().name() ), @@ -1721,7 +1721,7 @@ void VymModel::setFrameBrushColor(const QColor &c) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState (bo, QString("setFrameBrushColor (\"%1\")").arg(bo->getFrameBrushColor().name() ), @@ -1732,7 +1732,7 @@ void VymModel::setFramePadding (const int &i) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState (bo, QString("setFramePadding (\"%1\")").arg(bo->getFramePadding() ), @@ -1745,7 +1745,7 @@ void VymModel::setFrameBorderWidth(const int &i) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState (bo, QString("setFrameBorderWidth (\"%1\")").arg(bo->getFrameBorderWidth() ), @@ -1758,7 +1758,7 @@ void VymModel::setIncludeImagesVer(bool b) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString u= b ? "false" : "true"; @@ -1778,7 +1778,7 @@ void VymModel::setIncludeImagesHor(bool b) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString u= b ? "false" : "true"; @@ -1798,11 +1798,11 @@ void VymModel::setHideLinkUnselected (bool b) { - LinkableMapObj *sel=selection.single(); + LinkableMapObj *sel=getSelectedLMO(); if (sel && - (selection.type() == Selection::Branch || - selection.type() == Selection::MapCenter || - selection.type() == Selection::FloatImage )) + (selectionType() == TreeItem::Branch || + selectionType() == TreeItem::MapCenter || + selectionType() == TreeItem::Image )) { QString u= b ? "false" : "true"; QString r=!b ? "false" : "true"; @@ -1820,7 +1820,7 @@ void VymModel::setHideExport(bool b) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo->setHideInExport (b); @@ -1843,7 +1843,7 @@ void VymModel::toggleHideExport() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) setHideExport ( !bo->hideInExport() ); } @@ -1851,8 +1851,11 @@ void VymModel::copy() { - LinkableMapObj *sel=selection.single(); - if (sel) + LinkableMapObj *sel=getSelectedLMO(); + if (sel && + (selectionType() == TreeItem::Branch || + selectionType() == TreeItem::MapCenter || + selectionType() == TreeItem::Image )) { if (redosAvail == 0) { @@ -1893,7 +1896,7 @@ void VymModel::paste() { - BranchObj *sel=selection.getBranch(); + BranchObj *sel=getSelectedBranch(); if (sel) { saveStateChangingPart( @@ -1909,10 +1912,10 @@ void VymModel::cut() { - LinkableMapObj *sel=selection.single(); - if ( sel && (selection.type() == Selection::Branch || - selection.type()==Selection::MapCenter || - selection.type()==Selection::FloatImage)) + LinkableMapObj *sel=getSelectedLMO(); + if ( sel && (selectionType() == TreeItem::Branch || + selectionType()==TreeItem::MapCenter || + selectionType()==TreeItem::Image)) { /* No savestate! savestate is called in cutNoSave saveStateChangingPart( @@ -1930,7 +1933,7 @@ void VymModel::moveBranchUp() { - BranchObj* bo=selection.getBranch(); + BranchObj* bo=getSelectedBranch(); BranchObj* par; if (bo) { @@ -1947,7 +1950,7 @@ void VymModel::moveBranchDown() { - BranchObj* bo=selection.getBranch(); + BranchObj* bo=getSelectedBranch(); BranchObj* par; if (bo) { @@ -1964,7 +1967,7 @@ void VymModel::sortChildren() { - BranchObj* bo=selection.getBranch(); + BranchObj* bo=getSelectedBranch(); if (bo) { if(bo->countBranches()>1) @@ -1980,12 +1983,12 @@ void VymModel::createMapCenter() { MapCenterObj *mco=addMapCenter (QPointF (0,0) ); - selection.select (mco); + select (mco); } void VymModel::createBranch() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { BranchObj *newbo=addNewBranchInt (-2); // FIXME VM Old model, merge with below @@ -2002,7 +2005,7 @@ if (newbo) { newbo->setTreeItem (ti); - selection.select (newbo); // FIXME VM really needed here? + select (newbo); // FIXME VM really needed here? } } } @@ -2075,7 +2078,7 @@ // -1 insert in children of parent below selection // 0..n insert in children of parent at pos BranchObj *newbo=NULL; - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { if (num==-2) @@ -2106,7 +2109,7 @@ // -1 add above // 0 add as child // +1 add below - BranchObj *bo = selection.getBranch(); + BranchObj *bo = getSelectedBranch(); BranchObj *newbo=NULL; if (bo) @@ -2143,8 +2146,8 @@ BranchObj* VymModel::addNewBranchBefore() { BranchObj *newbo=NULL; - BranchObj *bo = selection.getBranch(); - if (bo && selection.type()==Selection::Branch) + BranchObj *bo = getSelectedBranch(); + if (bo && selectionType()==TreeItem::Branch) // We accept no MapCenterObj here, so we _have_ a parent { QPointF p=bo->getRelPos(); @@ -2174,9 +2177,9 @@ void VymModel::deleteSelection() { - BranchObj *bo = selection.getBranch(); + BranchObj *bo = getSelectedBranch(); - if (bo && selection.type()==Selection::MapCenter) + if (bo && selectionType()==TreeItem::MapCenter) { // BranchObj* par=(BranchObj*)(bo->getParObj()); selection.unselect(); @@ -2193,15 +2196,15 @@ reposition(); return; } - if (bo && selection.type()==Selection::Branch) + if (bo && selectionType()==TreeItem::Branch) { - QModelIndex ix=selection.getBranchIndex(); + QModelIndex ix=getSelectedIndex(); BranchObj* par=(BranchObj*)bo->getParObj(); - selection.unselect(); + unselect(); saveStateRemovingPart (bo, QString ("Delete %1").arg(getObjectName(bo))); par->removeBranch(bo); - selection.select (par); + select (par); ensureSelectionVisible(); reposition(); selection.update(); @@ -2217,9 +2220,9 @@ "delete ()", QString("Delete %1").arg(getObjectName(fio)) ); - selection.unselect(); + unselect(); par->removeFloatImage(fio); - selection.select (par); + select (par); reposition(); selection.update(); ensureSelectionVisible(); @@ -2229,7 +2232,7 @@ void VymModel::deleteKeepChildren() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); BranchObj *par; if (bo) { @@ -2258,14 +2261,14 @@ par->removeBranchHere(bo); reposition(); select (sel); - selection.getBranch()->move2RelPos (p); + getSelectedBranch()->move2RelPos (p); reposition(); } } void VymModel::deleteChildren() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveStateChangingPart( @@ -2332,8 +2335,8 @@ void VymModel::toggleScroll() { - BranchObj *bo=selection.getBranch(); - if (selection.type()==Selection::Branch ) + BranchObj *bo=getSelectedBranch(); + if (selectionType()==TreeItem::Branch ) { if (bo->isScrolled()) unscrollBranch (bo); @@ -2344,7 +2347,7 @@ void VymModel::unscrollChildren() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo->first(); @@ -2357,7 +2360,7 @@ } void VymModel::addFloatImage (const QPixmap &img) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { FloatImageObj *fio=bo->addFloatImage(); @@ -2374,7 +2377,7 @@ void VymModel::colorBranch (QColor c) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState( @@ -2390,7 +2393,7 @@ void VymModel::colorSubtree (QColor c) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveStateChangingPart( @@ -2405,7 +2408,7 @@ QColor VymModel::getCurrentHeadingColor() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) return bo->getColor(); QMessageBox::warning(0,"Warning","Can't get color of heading,\nthere's no branch selected"); @@ -2416,7 +2419,7 @@ void VymModel::editURL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bool ok; @@ -2431,7 +2434,7 @@ void VymModel::editLocalURL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QStringList filters; @@ -2459,14 +2462,14 @@ void VymModel::editHeading2URL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) setURL (bo->getHeading()); } void VymModel::editBugzilla2URL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString url= "https://bugzilla.novell.com/show_bug.cgi?id="+bo->getHeading(); @@ -2476,7 +2479,7 @@ void VymModel::editFATE2URL() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString url= "http://keeper.suse.de:8080/webfate/match/id?value=ID"+bo->getHeading(); @@ -2494,7 +2497,7 @@ void VymModel::editVymLink() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QStringList filters; @@ -2526,7 +2529,7 @@ void VymModel::setVymLink (const QString &s) { // Internal function, no saveState needed - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo->setVymLink(s); @@ -2539,7 +2542,7 @@ void VymModel::deleteVymLink() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { saveState( @@ -2558,7 +2561,7 @@ QString VymModel::getVymLink() { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) return bo->getVymLink(); else @@ -2569,7 +2572,7 @@ QStringList VymModel::getVymLinks() { QStringList links; - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo=bo->first(); @@ -2585,7 +2588,7 @@ void VymModel::followXLink(int i) { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo=bo->XLinkTargetAt(i); @@ -2599,7 +2602,7 @@ void VymModel::editXLink(int i) // FIXME VM missing saveState { - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { XLinkObj *xlo=bo->XLinkAt(i); @@ -2632,7 +2635,7 @@ void VymModel::parseAtom(const QString &atom) { - BranchObj *selb=selection.getBranch(); + BranchObj *selb=getSelectedBranch(); QString s,t; double x,y; int n; @@ -2791,9 +2794,9 @@ if (selection.isEmpty()) { parser.setError (Aborted,"Nothing selected"); - } else if ( selection.type()!=Selection::Branch && - selection.type()!=Selection::MapCenter && - selection.type()!=Selection::FloatImage ) + } else if ( selectionType()!=TreeItem::Branch && + selectionType()!=TreeItem::MapCenter && + selectionType()!=TreeItem::Image ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); } else if (parser.checkParCount(0)) @@ -2807,7 +2810,7 @@ { parser.setError (Aborted,"Nothing selected"); } - /*else if (selection.type() != Selection::Branch && selection.type() != Selection::FloatImage ) + /*else if (selectionType() != TreeItem::Branch && selectionType() != TreeItem::Image ) { parser.setError (Aborted,"Type of selection is wrong."); } @@ -2964,7 +2967,7 @@ } } } - } else if ( selection.type() == Selection::FloatImage) + } else if ( selectionType() == TreeItem::Image) { if (parser.checkParCount(1)) { @@ -3027,9 +3030,9 @@ if (selection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if ( selection.type()!=Selection::Branch && - selection.type()!=Selection::MapCenter && - selection.type()!=Selection::FloatImage ) + } else if ( selectionType()!=TreeItem::Branch && + selectionType()!=TreeItem::MapCenter && + selectionType()!=TreeItem::Image ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); } else if (parser.checkParCount(2)) @@ -3047,9 +3050,9 @@ if (selection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if ( selection.type()!=Selection::Branch && - selection.type()!=Selection::MapCenter && - selection.type()!=Selection::FloatImage ) + } else if ( selectionType()!=TreeItem::Branch && + selectionType()!=TreeItem::MapCenter && + selectionType()!=TreeItem::Image ) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); } else if (parser.checkParCount(2)) @@ -3230,7 +3233,7 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameType") { - if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow setting frame type"); } @@ -3242,7 +3245,7 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="setFramePenColor") { - if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow setting of pen color"); } @@ -3254,7 +3257,7 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameBrushColor") { - if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow setting brush color"); } @@ -3266,7 +3269,7 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="setFramePadding") { - if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow setting frame padding"); } @@ -3278,7 +3281,7 @@ ///////////////////////////////////////////////////////////////////// } else if (com=="setFrameBorderWidth") { - if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow setting frame border width"); } @@ -3309,7 +3312,7 @@ if (selection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if (! selection.getBranch() ) + } else if (! getSelectedBranch() ) { parser.setError (Aborted,"Type of selection is not a branch"); } else if (parser.checkParCount(1)) @@ -3360,7 +3363,7 @@ if (selection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if (selection.type()!=Selection::Branch && selection.type() != Selection::MapCenter &&selection.type()!=Selection::FloatImage) + } else if (selectionType()!=TreeItem::Branch && selectionType() != TreeItem::MapCenter &&selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection is not a branch or floatimage"); } else if (parser.checkParCount(1)) @@ -3402,7 +3405,7 @@ if (selection.isEmpty() ) { parser.setError (Aborted,"Nothing selected"); - } else if ( selection.type()!=Selection::Branch && selection.type()!= Selection::MapCenter && selection.type()!=Selection::FloatImage) + } else if ( selectionType()!=TreeItem::Branch && selectionType()!= TreeItem::MapCenter && selectionType()!=TreeItem::Image) { parser.setError (Aborted,"Type of selection does not allow hiding the link"); } else if (parser.checkParCount(1)) @@ -3772,7 +3775,7 @@ void VymModel::updateNoteFlag() { setChanged(); - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { bo->updateNoteFlag(); @@ -4077,20 +4080,24 @@ void VymModel::move(const double &x, const double &y) { - LinkableMapObj *sel=selection.single(); - if (sel) + BranchObj *bo = getSelectedBranch(); + if (bo && + (selectionType()==TreeItem::Branch || + selectionType()==TreeItem::MapCenter || + selectionType()==TreeItem::Image + )) { - QPointF ap(sel->getAbsPos()); + QPointF ap(bo->getAbsPos()); QPointF to(x, y); if (ap != to) { QString ps=qpointfToString(ap); - QString s=selection.getSelectString(); + QString s=getSelectString(); saveState( s, "move "+ps, s, "move "+qpointfToString(to), - QString("Move %1 to %2").arg(getObjectName(sel)).arg(ps)); - sel->move(x,y); + QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps)); + bo->move(x,y); reposition(); selection.update(); } @@ -4099,22 +4106,27 @@ void VymModel::moveRel (const double &x, const double &y) { - LinkableMapObj *sel=selection.single(); - if (sel) + BranchObj *bo = getSelectedBranch(); + if (bo && + (selectionType()==TreeItem::Branch || + selectionType()==TreeItem::MapCenter || + selectionType()==TreeItem::Image + )) + if (bo) { - QPointF rp(sel->getRelPos()); + QPointF rp(bo->getRelPos()); QPointF to(x, y); if (rp != to) { - QString ps=qpointfToString (sel->getRelPos()); - QString s=getSelectString(sel); + QString ps=qpointfToString (bo->getRelPos()); + QString s=getSelectString(bo); saveState( s, "moveRel "+ps, s, "moveRel "+qpointfToString(to), - QString("Move %1 to relative position %2").arg(getObjectName(sel)).arg(ps)); - ((OrnamentedObj*)sel)->move2RelPos (x,y); + QString("Move %1 to relative position %2").arg(getObjectName(bo)).arg(ps)); + ((OrnamentedObj*)bo)->move2RelPos (x,y); reposition(); - sel->updateLink(); + bo->updateLink(); selection.update(); } } @@ -4140,7 +4152,9 @@ bo->reposition(); i++; } - emit (selectionChanged(selModel->selection(), selModel->selection()) ); + QItemSelection sel=selModel->selection(); + emit (selectionChanged(sel,sel)); + mapScene->update(); if (!animObjList.isEmpty()) animationTimer->start(); } @@ -4324,7 +4338,24 @@ void VymModel::updateSelection() { - selection.update(); + cout << "VM::updateSelection ()\n"; + QItemSelection newsel=selModel->selection(); + updateSelection (newsel); +} + +void VymModel::updateSelection(const QItemSelection &oldsel) +{ + QItemSelection newsel=selModel->selection(); + cout << "VM::updateSelection new="; + if (!newsel.indexes().isEmpty() ) + cout << newsel.indexes().first().row()<<"," << newsel.indexes().first().column(); + cout << " old="; + if (!oldsel.indexes().isEmpty() ) + cout << oldsel.indexes().first().row()<<"," << oldsel.indexes().first().column(); + cout <selection(); + + if (lmo) { - selection.update(); - ensureSelectionVisible(); - sendSelection (); + TreeItem *ti=lmo->getTreeItem(); + QModelIndex ix=index(ti); + selModel->select (ix,QItemSelectionModel::ClearAndSelect ); + //updateSelection(oldsel); return true; } return false; @@ -4424,7 +4459,7 @@ void VymModel::unselect() { - selection.unselect(); + selModel->clearSelection(); } void VymModel::reselect() @@ -4434,7 +4469,7 @@ void VymModel::ensureSelectionVisible() { - LinkableMapObj *lmo=selection.single(); + LinkableMapObj *lmo=getSelectedLMO(); if (lmo &&mapEditor) mapEditor->ensureVisible (lmo->getBBox() ); } @@ -4452,10 +4487,10 @@ void VymModel::selectNextBranchInt() { // Increase number of branch - LinkableMapObj *sel=selection.single(); + LinkableMapObj *sel=getSelectedBranch(); if (sel) { - QString s=selection.getSelectString(); + QString s=getSelectString(); QString part; QString typ; QString num; @@ -4479,7 +4514,7 @@ // try to increase the parental number in order to // find a successor with same depth - int d=selection.single()->getDepth(); + int d=getSelectedLMO()->getDepth(); int oldDepth=d; int i; bool found=false; @@ -4500,7 +4535,7 @@ } else { // Special case, look at orientation - if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter) + if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) num=QString ("%1").arg(num.toUInt()+1); else num=QString ("%1").arg(num.toUInt()-1); @@ -4514,7 +4549,7 @@ b=select (s); if (b) { - if ( selection.getBranch()->countBranches()>0) + if ( getSelectedBranch()->countBranches()>0) s+=",bo:0"; else break; @@ -4533,7 +4568,7 @@ void VymModel::selectPrevBranchInt() { // Decrease number of branch - BranchObj *bo=selection.getBranch(); + BranchObj *bo=getSelectedBranch(); if (bo) { QString s=selection.getSelectString(); @@ -4561,7 +4596,7 @@ // try to decrease the parental number in order to // find a precessor with same depth - int d=selection.single()->getDepth(); + int d=getSelectedLMO()->getDepth(); int oldDepth=d; int i; bool found=false; @@ -4582,7 +4617,7 @@ } else { // Special case, look at orientation - if (selection.single()->getOrientation()==LinkableMapObj::RightOfCenter) + if (getSelectedLMO()->getOrientation()==LinkableMapObj::RightOfCenter) num=QString ("%1").arg(num.toInt()-1); else num=QString ("%1").arg(num.toInt()+1); @@ -4595,8 +4630,8 @@ { b=select (s); if (b) - if ( selection.getBranch()->countBranches()>0) - s+=",bo:"+ QString ("%1").arg( selection.getBranch()->countBranches()-1 ); + if ( getSelectedBranch()->countBranches()>0) + s+=",bo:"+ QString ("%1").arg( getSelectedBranch()->countBranches()-1 ); else break; else @@ -4615,8 +4650,8 @@ { if (selection.isBlocked() ) return; - BranchObj *bo=selection.getBranch(); - if (bo && selection.type()==Selection::Branch) + BranchObj *bo=getSelectedBranch(); + if (bo && selectionType()==TreeItem::Branch) { if (bo->getOrientation()==LinkableMapObj::RightOfCenter) selectPrevBranchInt(); @@ -4632,8 +4667,8 @@ { if (selection.isBlocked() ) return; - BranchObj *bo=selection.getBranch(); - if (bo && selection.type()==Selection::Branch) + BranchObj *bo=getSelectedBranch(); + if (bo && selectionType()==TreeItem::Branch) { if (bo->getOrientation()==LinkableMapObj::RightOfCenter) selectNextBranchInt(); @@ -4650,57 +4685,40 @@ { if (selection.isBlocked() ) return; - BranchObj* bo; + QItemSelection oldsel=selModel->selection(); + BranchObj* par; - LinkableMapObj *sel=selection.single(); + LinkableMapObj *sel=getSelectedBranch(); if (sel) { - if (selection.type()== Selection::MapCenter) + if (selectionType()== TreeItem::MapCenter) { - par=selection.getBranch(); - bo=par->getLastSelectedBranch(); - if (bo) - { - // Workaround for reselecting on left and right side - if (bo->getOrientation()==LinkableMapObj::RightOfCenter) - bo=par->getLastBranch(); - if (bo) - { - bo=par->getLastBranch(); - selection.select(bo); - selection.update(); - ensureSelectionVisible(); - sendSelection(); - } - } + QModelIndex ix=getSelectedIndex(); + selModel->select (index (rowCount(ix)-1,0,ix),QItemSelectionModel::ClearAndSelect ); } else { par=(BranchObj*)(sel->getParObj()); if (sel->getOrientation()==LinkableMapObj::RightOfCenter) { - if (selection.type() == Selection::Branch || - selection.type() == Selection::FloatImage) + // right of center + if (selectionType() == TreeItem::Branch || + selectionType() == TreeItem::Image) { - selection.select(par); - selection.update(); - ensureSelectionVisible(); - sendSelection(); + QModelIndex ix=getSelectedIndex(); + ix=parent(ix); + selModel->select (ix,QItemSelectionModel::ClearAndSelect ); } } else { - if (selection.type() == Selection::Branch ) + // left of center + if (selectionType() == TreeItem::Branch ) { - bo=selection.getBranch()->getLastSelectedBranch(); - if (bo) - { - selection.select(bo); - selection.update(); - ensureSelectionVisible(); - sendSelection(); - } + selectLastSelectedBranch(); + return; } } } + updateSelection (oldsel); } } @@ -4708,14 +4726,16 @@ { if (selection.isBlocked() ) return; + QItemSelection oldsel=selModel->selection(); + BranchObj* bo; BranchObj* par; - LinkableMapObj *sel=selection.single(); + LinkableMapObj *sel=getSelectedBranch(); if (sel) { - if (selection.type()==Selection::MapCenter) + if (selectionType()==TreeItem::MapCenter) { - par=selection.getBranch(); + par=getSelectedBranch(); bo=par->getLastSelectedBranch(); if (bo) { @@ -4725,45 +4745,48 @@ if (bo) { selection.select(bo); - selection.update(); - ensureSelectionVisible(); - sendSelection(); + //selection.update(); + //ensureSelectionVisible(); + //sendSelection(); } } } else { - par=(BranchObj*)(selection.single()->getParObj()); - if (selection.single()->getOrientation()==LinkableMapObj::LeftOfCenter) + par=(BranchObj*)(getSelectedLMO()->getParObj()); + if (getSelectedLMO()->getOrientation()==LinkableMapObj::LeftOfCenter) { - if (selection.type() == Selection::Branch || - selection.type() == Selection::FloatImage) + if (selectionType() == TreeItem::Branch || + selectionType() == TreeItem::Image) { - selection.select(par); - selection.update(); - ensureSelectionVisible(); - sendSelection(); + QModelIndex ix=getSelectedIndex(); + ix=parent(ix); + selModel->select (ix,QItemSelectionModel::ClearAndSelect ); } } else { - if (selection.type() == Selection::Branch) + if (selectionType() == TreeItem::Branch) { - bo=selection.getBranch()->getLastSelectedBranch(); + bo=getSelectedBranch()->getLastSelectedBranch(); if (bo) { selection.select(bo); - selection.update(); - ensureSelectionVisible(); - sendSelection(); + //selection.update(); + //ensureSelectionVisible(); + //sendSelection(); } } } } + QItemSelection newsel=selModel->selection(); + emit (selectionChanged(newsel,oldsel)); + ensureSelectionVisible(); + sendSelection(); } } void VymModel::selectFirstBranch() { - BranchObj *bo1=selection.getBranch(); + BranchObj *bo1=getSelectedBranch(); BranchObj *bo2; BranchObj* par; if (bo1) @@ -4782,7 +4805,7 @@ void VymModel::selectLastBranch() { - BranchObj *bo1=selection.getBranch(); + BranchObj *bo1=getSelectedBranch(); BranchObj *bo2; BranchObj* par; if (bo1) @@ -4800,33 +4823,94 @@ } } +void VymModel::selectLastSelectedBranch() +{ + QItemSelection oldsel=selModel->selection(); + + BranchObj *bo1=getSelectedBranch(); + BranchObj *bo2; + if (bo1) + { + cout << "bo1="<getHeading().toStdString()<getLastSelectedBranch(); + if (bo2) + { + cout << "bo2="<getHeading().toStdString()<getParObj()); if (!par) return; - selection.select(par); + select(par); selection.update(); ensureSelectionVisible(); sendSelection(); } } -Selection::Type VymModel::selectionType() +TreeItem::Type VymModel::selectionType() { - return selection.type(); + QModelIndexList list=selModel->selectedIndexes(); + if (list.isEmpty()) return TreeItem::Undefined; + TreeItem *ti = static_cast(list.first().internalPointer()); + return ti->getType(); + } -LinkableMapObj* VymModel::getSelection() +LinkableMapObj* VymModel::getSelectedLMO() { - return selection.single(); + QModelIndexList list=selModel->selectedIndexes(); + if (!list.isEmpty() ) + { + TreeItem *ti = static_cast(list.first().internalPointer()); + TreeItem::Type type=ti->getType(); + if (type ==TreeItem::Branch || type==TreeItem::MapCenter || type==TreeItem::Image) + { + return ti->getLMO(); + } + } + return NULL; } + BranchObj* VymModel::getSelectedBranch() { - return selection.getBranch(); + QModelIndexList list=selModel->selectedIndexes(); + if (!list.isEmpty() ) + { + TreeItem *ti = static_cast(list.first().internalPointer()); + TreeItem::Type type=ti->getType(); + if (type ==TreeItem::Branch || type==TreeItem::MapCenter) + { + return (BranchObj*)ti->getLMO(); + } + } + return NULL; + +} + +TreeItem* VymModel::getSelectedTreeItem() +{ + // FIXME this may not only be branch, but also float etc... + BranchObj* bo=getSelectedBranch(); + if (bo) return bo->getTreeItem(); // FIXME VM get directly from treemodl + return NULL; +} + +QModelIndex VymModel::getSelectedIndex() +{ + QModelIndexList list=selModel->selectedIndexes(); + if (list.isEmpty() ) + return QModelIndex(); + else + return list.first(); } FloatImageObj* VymModel::getSelectedFloatImage() @@ -4854,7 +4938,7 @@ s= "bo:" + QString("%1").arg(((BranchObj*)lmo)->getNum()); else { - //cout << "VM::getSelectString lmo="<getNum()); }