diff -r 6e4b586aa88a -r 25e634a7e1dc mapeditor.cpp --- a/mapeditor.cpp Wed Jun 03 20:37:17 2009 +0000 +++ b/mapeditor.cpp Mon Jun 08 11:36:56 2009 +0000 @@ -186,7 +186,10 @@ { if (index.isValid()) { - LinkableMapObj* lmo=(static_cast(index.internalPointer()))->getLMO(); + LinkableMapObj* lmo=NULL; + TreeItem *ti= static_cast(index.internalPointer()); + if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() ) + lmo=((MapItem*)ti)->getLMO(); if (lmo) setScrollBarPosTarget (lmo->getBBox() ); } } @@ -596,7 +599,7 @@ QPointF p = mapToScene(e->pos()); TreeItem *ti=findMapItem (p, NULL); LinkableMapObj* lmo=NULL; - if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo... + if (ti) lmo=((MapItem*)ti)->getLMO(); if (lmo) { // MapObj was found @@ -613,7 +616,7 @@ branchContextMenu->popup(e->globalPos() ); } else { - if (model->getSelectedFloatImage() ) + if (model->getSelectedImageItem() ) { // Context Menu on floatimage // model->updateActions(); FIXME-3 needed? @@ -680,7 +683,7 @@ QPointF p = mapToScene(e->pos()); TreeItem *ti=findMapItem (p, NULL); LinkableMapObj* lmo=NULL; - if (ti) lmo=ti->getLMO(); //FIXME-3 get rid of lmo... + if (ti) lmo=((MapItem*)ti)->getLMO(); e->accept(); @@ -750,18 +753,11 @@ /* cout << "ME::mouse pressed\n"; cout << " lmo="<getTreeItem(); - /* - cout << " lmo="<row()<<","<column()<<") = "<index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) ); + // Get clicked LMO model->select (ti); // Left Button Move Branches @@ -823,8 +819,8 @@ QPointF p = mapToScene(e->pos()); TreeItem *seli=model->getSelectedItem(); LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel - if (seli) - lmosel=seli->getLMO(); + if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image)) + lmosel=((MapItem*)seli)->getLMO(); // Move the selected MapObj if ( lmosel && movingObj) @@ -847,14 +843,14 @@ TreeItem *dsti=findMapItem (p, seli); LinkableMapObj* dst=NULL; if (dsti && dsti!=seli && dsti->isBranchLikeType()) - dst=dsti->getLMO(); //FIXME-2 get rid of lmo... + dst=((MapItem*)dsti)->getLMO(); else dsti=NULL; - FloatObj *fio=model->getSelectedFloatImage(); - if (fio) + if (lmosel && seli->getType()==TreeItem::Image) { + FloatObj *fio=(FloatImageObj*)lmosel; fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); fio->setRelPos(); fio->updateLink(); //no need for reposition, if we update link here @@ -971,7 +967,7 @@ if (seli) dsti=findMapItem(p, seli); LinkableMapObj* dst=NULL; if (dsti && dsti->isBranchLikeType ()) - dst=dsti->getLMO(); //FIXME-2 get rid of dst... + dst=((MapItem*)dsti)->getLMO(); else dsti=NULL; @@ -1014,22 +1010,25 @@ // Have we been moving something? if ( seli && movingObj ) { - FloatImageObj *fo=model->getSelectedFloatImage(); - if(fo) + if (seli->getType()==TreeItem::Image) { - // Moved FloatObj. Maybe we need to reposition - QString pold=qpointfToString(movingObj_orgRelPos); - QString pnow=qpointfToString(fo->getRelPos()); - model->saveState( - fo->getTreeItem(), // FIXME-3 - "moveRel "+pold, - fo->getTreeItem(), // FIXME-3 - "moveRel "+pnow, - QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow)); + FloatImageObj *fio=(FloatImageObj*)(((MapItem*)seli)->getLMO()); + if(fio) + { + // Moved FloatObj. Maybe we need to reposition + QString pold=qpointfToString(movingObj_orgRelPos); + QString pnow=qpointfToString(fio->getRelPos()); + model->saveState( + seli, + "moveRel "+pold, + seli, + "moveRel "+pnow, + QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow)); - fo->getParObj()->requestReposition(); - model->reposition(); - } + fio->getParObj()->requestReposition(); + model->reposition(); + } + } BranchItem *bi=model->getSelectedBranchItem(); if (bi && bi->depth()==0) @@ -1051,7 +1050,7 @@ if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch ) { // A branch was moved LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel - lmosel=seli->getLMO(); + lmosel=((MapItem*)seli)->getLMO(); // save the position in case we link to mapcenter QPointF savePos=QPointF (lmosel->getAbsPos() ); @@ -1095,11 +1094,11 @@ QString postSelStr=model->getSelectString(lmosel); QString postNum=QString::number (seli->num(),10); - QString undoCom="linkTo (\""+ + QString undoCom="relinkTo (\""+ preParStr+ "\"," + preNum +"," + QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")"; - QString redoCom="linkTo (\""+ + QString redoCom="relinkTo (\""+ preDstParStr + "\"," + postNum + "," + QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")"; @@ -1270,8 +1269,20 @@ event->acceptProposedAction(); } -void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &oldsel) +void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel) { + // Here in MapEditor we can only select Branches and Images + QModelIndex ix; + foreach (ix,newsel.indexes() ) + { + TreeItem *ti= static_cast(ix.internalPointer()); + if (ti->getType()!=TreeItem::Branch && ti->getType()!=TreeItem::Image ) + newsel.indexes().removeOne (ix); + } + + while (newsel.indexes().count() < selboxList.count() ) + delete selboxList.takeFirst(); + // Take care to tmp scroll/unscroll if (!oldsel.isEmpty()) { @@ -1332,7 +1343,7 @@ { index=newsel.indexes().at(i); ti= static_cast(index.internalPointer()); - lmo=ti->getLMO(); + lmo=((MapItem*)ti)->getLMO(); bbox=lmo->getBBox(); sb->setRect ( bbox.x(),bbox.y(), @@ -1358,7 +1369,7 @@ if (ti->isBranchLikeType()) { - BranchObj *bo=(BranchObj*)ti->getLMO(); + BranchObj *bo=(BranchObj*) ((MapItem*)ti)->getLMO(); bo->updateData(); }