diff -r d922fb6ea482 -r 6b0a5f4923d3 vymmodel.cpp --- a/vymmodel.cpp Fri Sep 11 12:56:15 2009 +0000 +++ b/vymmodel.cpp Thu Sep 17 09:41:09 2009 +0000 @@ -640,7 +640,7 @@ return err; } -void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) // FIXME-1 test e.g. with undo color subtree +void VymModel::addMapReplaceInt(const QString &undoSel, const QString &path) { QString pathDir=path.left(path.findRev("/")); QDir d(pathDir); @@ -1077,7 +1077,6 @@ parseAtom (redoCommand); - reposition(); blockSaveState=blockSaveStateOrg; @@ -1156,7 +1155,6 @@ cout << " ---------------------------"<updateHistory (undoSet); updateActions(); - emitSelectionChanged(); + //emitSelectionChanged(); } bool VymModel::isUndoAvailable() @@ -1439,7 +1437,7 @@ return ti; } -TreeItem* VymModel::findID (const QString &s) +TreeItem* VymModel::findID (const QString &s) //FIXME-4 Search also other types... { BranchItem *cur=NULL; BranchItem *prev=NULL; @@ -1602,9 +1600,7 @@ void VymModel::setScene (QGraphicsScene *s) { - mapScene=s; // FIXME-2 VM should not be necessary anymore, move all occurences to MapEditor - //init(); // Here we have a mapScene set, - // which is (still) needed to create MapCenters + mapScene=s; } void VymModel::setURL(const QString &url) @@ -1918,47 +1914,80 @@ } } -void VymModel::moveUp() //FIXME-2 crashes if trying to move MCO +bool VymModel::moveUp(BranchItem *bi) //FIXME-2 crashes if trying to move MCO +{ + if (bi && bi->canMoveUp()) + return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()-1); + else + return false; +} + +void VymModel::moveUp() { BranchItem *selbi=getSelectedBranch(); if (selbi) { - if (!selbi->canMoveUp()) return; QString oldsel=getSelectString(); - if (relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()-1) ) - - saveState (getSelectString(),"moveDown ()",oldsel,"moveUp ()",QString("Move up %1").arg(getObjectName(selbi))); + if (moveUp (selbi)) + saveState ( + getSelectString(),"moveDown ()", + oldsel,"moveUp ()", + QString("Move up %1").arg(getObjectName(selbi))); } } +bool VymModel::moveDown(BranchItem *bi) +{ + if (bi && bi->canMoveDown()) + return relinkBranch (bi,(BranchItem*)bi->parent(),bi->num()+1); + else + return false; +} + void VymModel::moveDown() { BranchItem *selbi=getSelectedBranch(); if (selbi) { - if (!selbi->canMoveDown()) return; QString oldsel=getSelectString(); - if ( relinkBranch (selbi,(BranchItem*)selbi->parent(),selbi->num()+1) ) - - saveState (getSelectString(),"moveUp ()",oldsel,"moveDown ()",QString("Move down %1").arg(getObjectName(selbi))); + if ( moveDown(selbi)) + saveState ( + getSelectString(),"moveUp ()", + oldsel,"moveDown ()", + QString("Move down %1").arg(getObjectName(selbi))); } } -void VymModel::sortChildren() // FIXME-2 not implemented yet -{ -/* - BranchObj* bo=getSelectedBranch(); - if (bo) +void VymModel::detach() +{ + BranchItem *selbi=getSelectedBranch(); + if (selbi && selbi->depth()>0) { - if(treeItem->branchCount()>1) + //QString oldsel=getSelectString(); + if ( relinkBranch (selbi,rootItem,-1) ) + saveState ( + selbi,QString("relink()"), //FIXME-1 add paramters + selbi,"detach ()", + QString("Detach %1").arg(getObjectName(selbi)) + ); + } +} + +void VymModel::sortChildren() +{ + BranchItem* selbi=getSelectedBranch(); + if (selbi) + { + if(selbi->branchCount()>1) { - saveStateChangingPart(bo,bo, "sortChildren ()",QString("Sort children of %1").arg(getObjectName(bo))); - bo->sortChildren(); + saveStateChangingPart( + selbi,selbi, "sortChildren ()", + QString("Sort children of %1").arg(getObjectName(selbi))); + selbi->sortChildren(); reposition(); emitShowSelection(); } } -*/ } BranchItem* VymModel::createMapCenter() @@ -2437,7 +2466,6 @@ TreeItem* VymModel::deleteItem (TreeItem *ti) { - cout << "VM::deleteItem "<parent(); @@ -2457,6 +2485,29 @@ return NULL; } +void VymModel::clearItem (TreeItem *ti) +{ + if (ti) + { + QModelIndex parentIndex=index(ti); + if (!parentIndex.isValid()) return; + + int n=ti->childCount(); + if (n==0) return; + + emit (layoutAboutToBeChanged() ); + + beginRemoveRows (parentIndex,0,n-1); + removeRows (0,n,parentIndex); + endRemoveRows(); + reposition(); + + emit (layoutChanged() ); + + } + return ; +} + bool VymModel::scrollBranch(BranchItem *bi) { if (bi) @@ -2478,7 +2529,7 @@ ); emitDataHasChanged(bi); emitSelectionChanged(); - mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal... + mapScene->update(); //Needed for _quick_ update, even in 1.13.x return true; } } @@ -2492,7 +2543,9 @@ if (!bi->isScrolled()) return false; if (bi->branchCount()==0) return false; if (bi->depth()==0) return false; - + if (bi->toggleScroll()) + { + reposition(); QString u,r; u="scroll"; r="unscroll"; @@ -2503,13 +2556,12 @@ QString ("%1 ()").arg(r), QString ("%1 %2").arg(r).arg(getObjectName(bi)) ); - bi->toggleScroll(); emitDataHasChanged(bi); emitSelectionChanged(); - - mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal... + mapScene->update(); //Needed for _quick_ update, even in 1.13.x return true; } + } return false; } @@ -2523,24 +2575,34 @@ else scrollBranch (bi); } - // saveState is called in above functions + // saveState & reposition are called in above functions } -void VymModel::unscrollChildren() // FIXME-2 first, next moved to vymmodel - -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::unscrollChildren() //FIXME-2 does not update flag yet, possible segfault +{ + BranchItem *selbi=getSelectedBranch(); + BranchItem *prev=NULL; + BranchItem *cur=selbi; + if (selbi) { - bo->first(); - while (bo) + saveStateChangingPart( + selbi, + selbi, + QString ("unscrollChildren ()"), + QString ("unscroll all children of %1").arg(getObjectName(selbi)) + ); + while (cur) { - if (bo->isScrolled()) unscrollBranch (bo); - bo=bo->next(); + if (cur->isScrolled()) + { + cur->toggleScroll(); + emitDataHasChanged (cur); } + cur=next (cur,prev,selbi); + } + updateActions(); + reposition(); } -*/ } void VymModel::emitExpandAll() @@ -2606,6 +2668,7 @@ QString("Set color of %1 to %2").arg(getObjectName(selbi)).arg(c.name()) ); selbi->setHeadingColor(c); // color branch + mapScene->update(); } } @@ -2627,7 +2690,7 @@ cur->setHeadingColor(c); // color links, color children cur=next (cur,prev,selbi); } - + mapScene->update(); } } @@ -4057,82 +4120,16 @@ */ } -void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views??? +void VymModel::reposition() //FIXME-4 VM should have no need to reposition, but the views... { //cout << "VM::reposition blocked="<branchCount(); i++) rootItem->getBranchObjNum(i)->reposition(); // for positioning heading - emitSelectionChanged(); + //emitSelectionChanged(); } -/* -QPolygonF VymModel::shape(BranchObj *bo) //FIXME-4 -{ - return QPolygonF (); - // Creating (arbitrary) shapes - - QPolygonF p; - QRectF rb=bo->getBBox(); - if (bo->getDepth()==0) - { - // Just take BBox of this mapCenter - p<getTotalBBox(); - if (bo->getOrientation()==LinkableMapObj::LeftOfCenter) - p <branchCount(); i++) - { - boB=rootItem->getBranchNum(i); - pA=shape (boA); - pB=shape (boB); - PolygonCollisionResult r = PolygonCollision(pA, pB, QPoint(0,0)); - cout <<"------->" - <<"="<getHeading() )<<")" - <<" with ("<< qPrintable (boB->getHeading() ) - <<") willIntersect" - <