diff -r 2f002657dada -r 6e4b586aa88a vymmodel.cpp --- a/vymmodel.cpp Tue May 26 11:24:51 2009 +0000 +++ b/vymmodel.cpp Wed Jun 03 20:37:17 2009 +0000 @@ -11,7 +11,6 @@ #include "file.h" #include "geometry.h" // for addBBox #include "mainwindow.h" -#include "mapcenterobj.h" #include "misc.h" #include "parser.h" @@ -463,7 +462,7 @@ if ( ok ) { reposition(); // FIXME-2 VM reposition the view instead... - updateSelection(); + emitSelectionChanged(); if (lmode==NewMap) { mapDefault=false; @@ -701,9 +700,9 @@ */ } -FloatImageObj* VymModel::loadFloatImageInt (QString fn) -{ - TreeItem *fi=createImage(); +FloatImageObj* VymModel::loadFloatImageInt (BranchItem *dst,QString fn) +{ + TreeItem *fi=createImage(dst); if (fi) { FloatImageObj *fio= ((FloatImageObj*)fi->getLMO()); @@ -714,14 +713,13 @@ return NULL; } -void VymModel::loadFloatImage () // FIXME-2 -{ -/* - BranchObj *bo=getSelectedBranch(); - if (bo) +void VymModel::loadFloatImage () +{ + BranchItem *selbi=getSelectedBranchItem(); + if (selbi) { - Q3FileDialog *fd=new Q3FileDialog( NULL); + Q3FileDialog *fd=new Q3FileDialog( NULL); // FIXME-4 get rid of Q3FileDialog fd->setMode (Q3FileDialog::ExistingFiles); fd->addFilter (QString (tr("Images") + " (*.png *.bmp *.xbm *.jpg *.png *.xpm *.gif *.pnm)")); ImagePreview *p =new ImagePreview (fd); @@ -741,24 +739,26 @@ for (int j=0; jselectedFiles().count(); j++) { s=fd->selectedFiles().at(j); - fio=loadFloatImageInt (s); + fio=loadFloatImageInt (selbi,s); + //FIXME-1 savestate for loadImage missing + /* if (fio) saveState( (LinkableMapObj*)fio, "delete ()", - bo, + selbi, QString ("loadImage (%1)").arg(s ), - QString("Add image %1 to %2").arg(s).arg(getObjectName(bo)) + QString("Add image %1 to %2").arg(s).arg(getObjectName(selbi)) ); else // TODO loadFIO error handling qWarning ("Failed to load "+s); + */ } } delete (p); delete (fd); } -*/ } void VymModel::saveFloatImageInt (FloatImageObj *fio, const QString &type, const QString &fn) @@ -1179,7 +1179,7 @@ mainWindow->updateHistory (undoSet); updateActions(); - updateSelection(); + emitSelectionChanged(); } bool VymModel::isUndoAvailable() @@ -1509,7 +1509,7 @@ emitDataHasChanged ( selbi); //FIXME-3 maybe emit signal from TreeItem? reposition(); - updateSelection(); + emitSelectionChanged(); } } @@ -1829,7 +1829,7 @@ ); updateActions(); reposition(); - // updateSelection(); + // emitSelectionChanged(); // FIXME-3 VM needed? scene()->update(); } } @@ -1960,25 +1960,22 @@ BranchItem* VymModel::createMapCenter() { BranchItem *newbi=addMapCenter (QPointF (0,0) ); - select (newbi); return newbi; } -BranchItem* VymModel::createBranch() -{ - BranchItem *selbi=getSelectedBranchItem(); - if (selbi) - return addNewBranchInt (selbi,-2); +BranchItem* VymModel::createBranch(BranchItem *dst) +{ + if (dst) + return addNewBranchInt (dst,-2); else return NULL; } -TreeItem* VymModel::createImage() //FIXME-1 +TreeItem* VymModel::createImage(BranchItem *dst) //FIXME-1 { return NULL; /* - BranchObj *bo=getSelectedBranch(); - if (bo) + if (dst) { FloatImageObj *newfio=bo->addFloatImage(); // FIXME-1 VM Old model, merge with below @@ -2017,6 +2014,7 @@ } BranchItem* VymModel::addMapCenter(QPointF absPos) //FIXME-2 absPos not used in context menu?! +// createMapCenter could then probably be merged with createBranch { // Create TreeItem @@ -2037,12 +2035,13 @@ emit (layoutChanged() ); // Create MapObj + newbi->setPositionMode (MapItem::Absolute); newbi->createMapObj(mapScene); return newbi; } -BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) //FIXME-4 simplify... +BranchItem* VymModel::addNewBranchInt(BranchItem *dst,int num) { // Depending on pos: // -3 insert in children of parent above selection @@ -2086,7 +2085,6 @@ // new branch in order to tmp unscroll parent... newbi->createMapObj(mapScene); reposition(); - select (newbi); return newbi; } @@ -2103,7 +2101,6 @@ { // FIXME-3 setCursor (Qt::ArrowCursor); //Still needed? - newbi=addNewBranchInt (selbi,pos-2); if (newbi) @@ -2116,7 +2113,7 @@ QString ("Add new branch to %1").arg(getObjectName(selbi))); reposition(); - // updateSelection(); FIXME-3 + // emitSelectionChanged(); 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. @@ -2156,10 +2153,9 @@ QString ("Add branch before %1").arg(getObjectName(selbi))); // FIXME-3 needed? reposition(); - // updateSelection(); FIXME-3 + // emitSelectionChanged(); FIXME-3 } } - //FIXME-3 needed? latestSelectionString=selection.getSelectString(); return newbi; } @@ -2250,43 +2246,46 @@ */ } -void VymModel::deleteKeepChildren() //FIXME-2 VM still missing - -{ -/* - BranchObj *bo=getSelectedBranch(); - BranchObj *par; - if (bo) +void VymModel::deleteKeepChildren() + +{ + BranchItem *selbi=getSelectedBranchItem(); + BranchItem *pi; + if (selbi) { - par=(BranchObj*)(bo->getParObj()); - // Don't use this on mapcenter - if (!par) return; - + if (selbi->depth()<2) return; + + pi=(BranchItem*)(selbi->parent()); // Check if we have childs at all to keep - if (bo->getTreeItem()->branchCount()==0) + if (selbi->branchCount()==0) { deleteSelection(); return; } - QPointF p=bo->getRelPos(); + QPointF p; + if (selbi->getLMO()) p=selbi->getLMO()->getRelPos(); saveStateChangingPart( - bo->getParObj(), - bo, + pi, + selbi, "deleteKeepChildren ()", - QString("Remove %1 and keep its children").arg(getObjectName(bo)) + QString("Remove %1 and keep its children").arg(getObjectName(selbi)) ); - QString sel=getSelectString(bo); + QString sel=getSelectString(selbi); unselect(); - par->removeBranchHere(bo); + //FIXME-0 missing in VM pi->removeBranchHere(selbi); reposition(); select (sel); - getSelectedBranch()->move2RelPos (p); - reposition(); + BranchObj *bo=getSelectedBranchObj(); + if (bo) + { + bo->move2RelPos (p); + reposition(); + } } -*/} +} void VymModel::deleteChildren() @@ -2332,7 +2331,7 @@ QString ("%1 %2").arg(r).arg(getObjectName(bi)) ); emitDataHasChanged(bi); - updateSelection(); + emitSelectionChanged(); mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal... return true; } @@ -2360,7 +2359,7 @@ ); bi->toggleScroll(); emitDataHasChanged(bi); - updateSelection(); + emitSelectionChanged(); mapScene->update(); //Needed for _quick_ update, even in 1.13.x //FIXME-3 force update via signal... return true; @@ -2427,7 +2426,7 @@ QString("Toggling standard flag \"%1\" of %2").arg(name).arg(getObjectName(bi))); bi->toggleStandardFlag (name, master); reposition(); - updateSelection(); + emitSelectionChanged(); } } @@ -2617,7 +2616,7 @@ bi->setVymLink(s); reposition(); updateActions(); - //updateSelection(); + //emitSelectionChanged(); } } @@ -3034,7 +3033,7 @@ if (ok) { selb->linkTo ((BranchObj*)(dst),n); - updateSelection(); + emitSelectionChanged(); } } else if (typid(*dst) == typid(MapCenterObj) ) { @@ -3047,7 +3046,7 @@ if (ok) { selbi->move (x,y); - updateSelection(); + emitSelectionChanged(); } } } @@ -3082,7 +3081,7 @@ } else if (parser.checkParCount(1)) { s=parser.parString(ok,0); - if (ok) loadFloatImageInt (s); + if (ok) loadFloatImageInt (selbi,s); } ///////////////////////////////////////////////////////////////////// } else if (com=="moveUp") @@ -3859,16 +3858,36 @@ else selti->setNote (textEditor->getText()); emitDataHasChanged(selti); - updateSelection(); + emitSelectionChanged(); } } void VymModel::updateRelPositions() //FIXME-3 VM should have no need to updateRelPos { - //cout << "VM::updateRelPos...\n"; + cout << "VM::updateRelPos...\n"; + /* FIXME-3 ??? for (int i=0; ibranchCount(); i++) ((MapCenterObj*)rootItem->getBranchObjNum(i))->updateRelPositions(); + */ + /* + void MapCenterObj::updateRelPositions() + { + if (repositionRequest) unsetAllRepositionRequests(); + + // update relative Positions of branches and floats + for (int i=0; ibranchCount(); ++i) + { + treeItem->getBranchObjNum(i)->setRelPos(); + treeItem->getBranchObjNum(i)->setOrientation(); + } + + for (int i=0; isetRelPos(); + + if (repositionRequest) reposition(); + } + */ } void VymModel::reposition() //FIXME-3 VM should have no need to reposition, this is done in views??? @@ -4201,7 +4220,7 @@ QString("Move %1 to %2").arg(getObjectName(bo)).arg(ps)); bo->move(x,y); reposition(); - updateSelection(); + emitSelectionChanged(); } } */ @@ -4232,7 +4251,7 @@ ((OrnamentedObj*)bo)->move2RelPos (x,y); reposition(); bo->updateLink(); - updateSelection(); + emitSelectionChanged(); } } */ @@ -4455,17 +4474,21 @@ } */ -void VymModel::updateSelection(const QItemSelection &newsel) +void VymModel::updateSelection (const QItemSelection &newsel,const QItemSelection &oldsel) //FIXME-4 connected but not used so far +{ +} + +void VymModel::emitSelectionChanged(const QItemSelection &newsel) { emit (selectionChanged(newsel,newsel)); // needed e.g. to update geometry in editor emitShowSelection(); sendSelection(); } -void VymModel::updateSelection() +void VymModel::emitSelectionChanged() { QItemSelection newsel=selModel->selection(); - updateSelection (newsel); + emitSelectionChanged (newsel); } void VymModel::setSelectionColor(QColor col) @@ -4610,7 +4633,7 @@ { if (selection.select(lmo)) { - //updateSelection(); + //emitSelectionChanged(); } } @@ -4618,7 +4641,7 @@ { if (selection.select(lmo)) { - //updateSelection(); + //emitSelectionChanged(); } } */ @@ -4840,7 +4863,7 @@ TreeItem *ti2=par->getFirstBranch(); if (ti2) { select(ti2); - updateSelection(); + emitSelectionChanged(); } } } @@ -4855,7 +4878,7 @@ TreeItem *ti2=par->getLastBranch(); if (ti2) { select(ti2); - updateSelection(); + emitSelectionChanged(); } } } @@ -4879,7 +4902,7 @@ par=ti->parent(); if (!par) return; select(par); - updateSelection(); + emitSelectionChanged(); } } @@ -4955,11 +4978,7 @@ QString VymModel::getSelectString () { - LinkableMapObj *lmo=getSelectedLMO(); - if (lmo) - return getSelectString(lmo); - else - return QString(); + return getSelectString (getSelectedItem()); } QString VymModel::getSelectString (LinkableMapObj *lmo) // FIXME-2 VM needs to use TreeModel. Port all calls to this funtion to the one using TreeItem below...