1.1 --- a/mapeditor.cpp Wed Jun 03 20:37:17 2009 +0000
1.2 +++ b/mapeditor.cpp Mon Jun 08 11:36:56 2009 +0000
1.3 @@ -186,7 +186,10 @@
1.4 {
1.5 if (index.isValid())
1.6 {
1.7 - LinkableMapObj* lmo=(static_cast<TreeItem*>(index.internalPointer()))->getLMO();
1.8 + LinkableMapObj* lmo=NULL;
1.9 + TreeItem *ti= static_cast<TreeItem*>(index.internalPointer());
1.10 + if (ti->getType()==TreeItem::Image ||ti->isBranchLikeType() )
1.11 + lmo=((MapItem*)ti)->getLMO();
1.12 if (lmo) setScrollBarPosTarget (lmo->getBBox() );
1.13 }
1.14 }
1.15 @@ -596,7 +599,7 @@
1.16 QPointF p = mapToScene(e->pos());
1.17 TreeItem *ti=findMapItem (p, NULL);
1.18 LinkableMapObj* lmo=NULL;
1.19 - if (ti) lmo=ti->getLMO(); //FIXME-2 get rid of lmo...
1.20 + if (ti) lmo=((MapItem*)ti)->getLMO();
1.21
1.22 if (lmo)
1.23 { // MapObj was found
1.24 @@ -613,7 +616,7 @@
1.25 branchContextMenu->popup(e->globalPos() );
1.26 } else
1.27 {
1.28 - if (model->getSelectedFloatImage() )
1.29 + if (model->getSelectedImageItem() )
1.30 {
1.31 // Context Menu on floatimage
1.32 // model->updateActions(); FIXME-3 needed?
1.33 @@ -680,7 +683,7 @@
1.34 QPointF p = mapToScene(e->pos());
1.35 TreeItem *ti=findMapItem (p, NULL);
1.36 LinkableMapObj* lmo=NULL;
1.37 - if (ti) lmo=ti->getLMO(); //FIXME-3 get rid of lmo...
1.38 + if (ti) lmo=((MapItem*)ti)->getLMO();
1.39
1.40 e->accept();
1.41
1.42 @@ -750,18 +753,11 @@
1.43 /*
1.44 cout << "ME::mouse pressed\n";
1.45 cout << " lmo="<<lmo<<endl;
1.46 - cout << " h="<<((BranchObj*)lmo)->getHeading().toStdString()<<endl;
1.47 + cout << " ti="<<ti->getHeadingStd()<<endl;
1.48 */
1.49 // Select the clicked object
1.50
1.51 - // FIXME-2 VM better let "find" return an index instead of lmo...
1.52 - // Get index of clicked LMO
1.53 - TreeItem *ti=lmo->getTreeItem();
1.54 - /*
1.55 - cout << " lmo="<<lmo<<" lmo(ti)="<<ti->getLMO()<<endl;
1.56 - cout << " ti ("<<ti->row()<<","<<ti->column()<<") = "<<ti<<endl;
1.57 - */
1.58 - //QModelIndex ix=model->index( ti->row(), ti->column(), model->index (0,0,QModelIndex()) );
1.59 + // Get clicked LMO
1.60 model->select (ti);
1.61
1.62 // Left Button Move Branches
1.63 @@ -823,8 +819,8 @@
1.64 QPointF p = mapToScene(e->pos());
1.65 TreeItem *seli=model->getSelectedItem();
1.66 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1.67 - if (seli)
1.68 - lmosel=seli->getLMO();
1.69 + if (seli && (seli->isBranchLikeType() ||seli->getType()==TreeItem::Image))
1.70 + lmosel=((MapItem*)seli)->getLMO();
1.71
1.72 // Move the selected MapObj
1.73 if ( lmosel && movingObj)
1.74 @@ -847,14 +843,14 @@
1.75 TreeItem *dsti=findMapItem (p, seli);
1.76 LinkableMapObj* dst=NULL;
1.77 if (dsti && dsti!=seli && dsti->isBranchLikeType())
1.78 - dst=dsti->getLMO(); //FIXME-2 get rid of lmo...
1.79 + dst=((MapItem*)dsti)->getLMO();
1.80 else
1.81 dsti=NULL;
1.82
1.83
1.84 - FloatObj *fio=model->getSelectedFloatImage();
1.85 - if (fio)
1.86 + if (lmosel && seli->getType()==TreeItem::Image)
1.87 {
1.88 + FloatObj *fio=(FloatImageObj*)lmosel;
1.89 fio->move (p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );
1.90 fio->setRelPos();
1.91 fio->updateLink(); //no need for reposition, if we update link here
1.92 @@ -971,7 +967,7 @@
1.93 if (seli) dsti=findMapItem(p, seli);
1.94 LinkableMapObj* dst=NULL;
1.95 if (dsti && dsti->isBranchLikeType ())
1.96 - dst=dsti->getLMO(); //FIXME-2 get rid of dst...
1.97 + dst=((MapItem*)dsti)->getLMO();
1.98 else
1.99 dsti=NULL;
1.100
1.101 @@ -1014,22 +1010,25 @@
1.102 // Have we been moving something?
1.103 if ( seli && movingObj )
1.104 {
1.105 - FloatImageObj *fo=model->getSelectedFloatImage();
1.106 - if(fo)
1.107 + if (seli->getType()==TreeItem::Image)
1.108 {
1.109 - // Moved FloatObj. Maybe we need to reposition
1.110 - QString pold=qpointfToString(movingObj_orgRelPos);
1.111 - QString pnow=qpointfToString(fo->getRelPos());
1.112 - model->saveState(
1.113 - fo->getTreeItem(), // FIXME-3
1.114 - "moveRel "+pold,
1.115 - fo->getTreeItem(), // FIXME-3
1.116 - "moveRel "+pnow,
1.117 - QString("Move %1 to relative position %2").arg(model->getObjectName(fo)).arg(pnow));
1.118 + FloatImageObj *fio=(FloatImageObj*)(((MapItem*)seli)->getLMO());
1.119 + if(fio)
1.120 + {
1.121 + // Moved FloatObj. Maybe we need to reposition
1.122 + QString pold=qpointfToString(movingObj_orgRelPos);
1.123 + QString pnow=qpointfToString(fio->getRelPos());
1.124 + model->saveState(
1.125 + seli,
1.126 + "moveRel "+pold,
1.127 + seli,
1.128 + "moveRel "+pnow,
1.129 + QString("Move %1 to relative position %2").arg(model->getObjectName(seli)).arg(pnow));
1.130
1.131 - fo->getParObj()->requestReposition();
1.132 - model->reposition();
1.133 - }
1.134 + fio->getParObj()->requestReposition();
1.135 + model->reposition();
1.136 + }
1.137 + }
1.138
1.139 BranchItem *bi=model->getSelectedBranchItem();
1.140 if (bi && bi->depth()==0)
1.141 @@ -1051,7 +1050,7 @@
1.142 if (seli->isBranchLikeType() ) //(seli->getType() == TreeItem::Branch )
1.143 { // A branch was moved
1.144 LinkableMapObj* lmosel=NULL; //FIXME-2 get rid of lmosel
1.145 - lmosel=seli->getLMO();
1.146 + lmosel=((MapItem*)seli)->getLMO();
1.147
1.148 // save the position in case we link to mapcenter
1.149 QPointF savePos=QPointF (lmosel->getAbsPos() );
1.150 @@ -1095,11 +1094,11 @@
1.151 QString postSelStr=model->getSelectString(lmosel);
1.152 QString postNum=QString::number (seli->num(),10);
1.153
1.154 - QString undoCom="linkTo (\""+
1.155 + QString undoCom="relinkTo (\""+
1.156 preParStr+ "\"," + preNum +"," +
1.157 QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ ")";
1.158
1.159 - QString redoCom="linkTo (\""+
1.160 + QString redoCom="relinkTo (\""+
1.161 preDstParStr + "\"," + postNum + "," +
1.162 QString ("%1,%2").arg(savePos.x()).arg(savePos.y())+ ")";
1.163
1.164 @@ -1270,8 +1269,20 @@
1.165 event->acceptProposedAction();
1.166 }
1.167
1.168 -void MapEditor::updateSelection(const QItemSelection &newsel,const QItemSelection &oldsel)
1.169 +void MapEditor::updateSelection(QItemSelection newsel,QItemSelection oldsel)
1.170 {
1.171 + // Here in MapEditor we can only select Branches and Images
1.172 + QModelIndex ix;
1.173 + foreach (ix,newsel.indexes() )
1.174 + {
1.175 + TreeItem *ti= static_cast<TreeItem*>(ix.internalPointer());
1.176 + if (ti->getType()!=TreeItem::Branch && ti->getType()!=TreeItem::Image )
1.177 + newsel.indexes().removeOne (ix);
1.178 + }
1.179 +
1.180 + while (newsel.indexes().count() < selboxList.count() )
1.181 + delete selboxList.takeFirst();
1.182 +
1.183 // Take care to tmp scroll/unscroll
1.184 if (!oldsel.isEmpty())
1.185 {
1.186 @@ -1332,7 +1343,7 @@
1.187 {
1.188 index=newsel.indexes().at(i);
1.189 ti= static_cast<TreeItem*>(index.internalPointer());
1.190 - lmo=ti->getLMO();
1.191 + lmo=((MapItem*)ti)->getLMO();
1.192 bbox=lmo->getBBox();
1.193 sb->setRect (
1.194 bbox.x(),bbox.y(),
1.195 @@ -1358,7 +1369,7 @@
1.196
1.197 if (ti->isBranchLikeType())
1.198 {
1.199 - BranchObj *bo=(BranchObj*)ti->getLMO();
1.200 + BranchObj *bo=(BranchObj*) ((MapItem*)ti)->getLMO();
1.201 bo->updateData();
1.202 }
1.203