1.1 --- a/mapeditor.cpp Tue Apr 08 08:28:37 2008 +0000
1.2 +++ b/mapeditor.cpp Tue Apr 08 08:28:37 2008 +0000
1.3 @@ -429,7 +429,7 @@
1.4 cout << " undoSel="<<undoSelection.toStdString()<<endl;
1.5 cout << " redoCom="<<redoCom.toStdString()<<endl;
1.6 cout << " redoSel="<<redoSelection.toStdString()<<endl;
1.7 - if (saveSel) cout << " saveSel="<<qPrintable (saveSel->getSelectString())<<endl;
1.8 + if (saveSel) cout << " saveSel="<<qPrintable (model->getSelectString(saveSel))<<endl;
1.9 cout << " ---------------------------"<<endl;
1.10 }
1.11
1.12 @@ -444,12 +444,12 @@
1.13 // save the selected part of the map, Undo will replace part of map
1.14 QString undoSelection="";
1.15 if (undoSel)
1.16 - undoSelection=undoSel->getSelectString();
1.17 + undoSelection=model->getSelectString(undoSel);
1.18 else
1.19 qWarning ("MapEditor::saveStateChangingPart no undoSel given!");
1.20 QString redoSelection="";
1.21 if (redoSel)
1.22 - redoSelection=undoSel->getSelectString();
1.23 + redoSelection=model->getSelectString(undoSel);
1.24 else
1.25 qWarning ("MapEditor::saveStateChangingPart no redoSel given!");
1.26
1.27 @@ -468,8 +468,8 @@
1.28 qWarning ("MapEditor::saveStateRemovingPart no redoSel given!");
1.29 return;
1.30 }
1.31 - QString undoSelection=redoSel->getParObj()->getSelectString();
1.32 - QString redoSelection=redoSel->getSelectString();
1.33 + QString undoSelection=model->getSelectString (redoSel->getParObj());
1.34 + QString redoSelection=model->getSelectString(redoSel);
1.35 if (typeid(*redoSel) == typeid(BranchObj) )
1.36 {
1.37 // save the selected branch of the map, Undo will insert part of map
1.38 @@ -489,9 +489,9 @@
1.39 // and use current selection
1.40
1.41 QString redoSelection="";
1.42 - if (redoSel) redoSelection=redoSel->getSelectString();
1.43 + if (redoSel) redoSelection=model->getSelectString(redoSel);
1.44 QString undoSelection="";
1.45 - if (undoSel) undoSelection=undoSel->getSelectString();
1.46 + if (undoSel) undoSelection=model->getSelectString(undoSel);
1.47
1.48 saveState (UndoCommand,
1.49 undoSelection, uc,
1.50 @@ -578,6 +578,18 @@
1.51 }
1.52 }
1.53 /////////////////////////////////////////////////////////////////////
1.54 + } else if (com==QString("addMapCenter"))
1.55 + {
1.56 + if (parser.checkParCount(2))
1.57 + {
1.58 + x=parser.parDouble (ok,0);
1.59 + if (ok)
1.60 + {
1.61 + y=parser.parDouble (ok,1);
1.62 + if (ok) model->addMapCenter (QPointF(x,y));
1.63 + }
1.64 + }
1.65 + /////////////////////////////////////////////////////////////////////
1.66 } else if (com==QString("addMapReplace"))
1.67 {
1.68 if (xelection.isEmpty())
1.69 @@ -591,7 +603,7 @@
1.70 //s=parser.parString (ok,0); // selection
1.71 t=parser.parString (ok,0); // path to map
1.72 if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
1.73 - addMapReplaceInt(selb->getSelectString(),t);
1.74 + addMapReplaceInt(model->getSelectString(selb),t);
1.75 }
1.76 /////////////////////////////////////////////////////////////////////
1.77 } else if (com==QString("addMapInsert"))
1.78 @@ -688,10 +700,13 @@
1.79 if (xelection.isEmpty())
1.80 {
1.81 parser.setError (Aborted,"Nothing selected");
1.82 - } else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
1.83 + }
1.84 + /*else if (xelection.type() != Selection::Branch && xelection.type() != Selection::FloatImage )
1.85 {
1.86 parser.setError (Aborted,"Type of selection is wrong.");
1.87 - } else if (parser.checkParCount(0))
1.88 + }
1.89 + */
1.90 + else if (parser.checkParCount(0))
1.91 {
1.92 deleteSelection();
1.93 }
1.94 @@ -854,7 +869,7 @@
1.95 {
1.96 if (typeid(*dst) == typeid(BranchObj) ||
1.97 typeid(*dst) == typeid(MapCenterObj))
1.98 - linkTo (dst->getSelectString());
1.99 + linkTo (model->getSelectString(dst));
1.100 } else
1.101 parser.setError (Aborted,"Destination is not a branch");
1.102 }
1.103 @@ -2145,7 +2160,7 @@
1.104 if (redosAvail == 0)
1.105 {
1.106 // Copy to history
1.107 - QString s=sel->getSelectString();
1.108 + QString s=model->getSelectString(sel);
1.109 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy selection to clipboard",sel );
1.110 curClipboard=curStep;
1.111 }
1.112 @@ -2487,7 +2502,7 @@
1.113 if (ap != to)
1.114 {
1.115 QString ps=qpointfToString(ap);
1.116 - QString s=xelection.single()->getSelectString();
1.117 + QString s=xelection.getSelectString();
1.118 saveState(
1.119 s, "move "+ps,
1.120 s, "move "+qpointfToString(to),
1.121 @@ -2509,7 +2524,7 @@
1.122 if (rp != to)
1.123 {
1.124 QString ps=qpointfToString (sel->getRelPos());
1.125 - QString s=sel->getSelectString();
1.126 + QString s=model->getSelectString(sel);
1.127 saveState(
1.128 s, "moveRel "+ps,
1.129 s, "moveRel "+qpointfToString(to),
1.130 @@ -2531,7 +2546,7 @@
1.131 if (!bo->canMoveBranchUp()) return;
1.132 par=(BranchObj*)(bo->getParObj());
1.133 BranchObj *obo=par->moveBranchUp (bo); // bo will be the one below selection
1.134 - saveState (bo->getSelectString(),"moveBranchDown ()",obo->getSelectString(),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1.135 + saveState (model->getSelectString(bo),"moveBranchDown ()",model->getSelectString(obo),"moveBranchUp ()",QString("Move up %1").arg(getName(bo)));
1.136 model->reposition();
1.137 scene()->update();
1.138 xelection.update();
1.139 @@ -2548,7 +2563,7 @@
1.140 if (!bo->canMoveBranchDown()) return;
1.141 par=(BranchObj*)(bo->getParObj());
1.142 BranchObj *obo=par->moveBranchDown(bo); // bo will be the one above selection
1.143 - saveState(bo->getSelectString(),"moveBranchUp ()",obo->getSelectString(),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1.144 + saveState(model->getSelectString(bo),"moveBranchUp ()",model->getSelectString(obo),"moveBranchDown ()",QString("Move down %1").arg(getName(bo)));
1.145 model->reposition();
1.146 scene()->update();
1.147 xelection.update();
1.148 @@ -2581,9 +2596,9 @@
1.149 typeid(*dst)==typeid (MapCenterObj)))
1.150 {
1.151 LinkableMapObj *dstPar=dst->getParObj();
1.152 - QString parString=dstPar->getSelectString();
1.153 - QString fioPreSelectString=fio->getSelectString();
1.154 - QString fioPreParentSelectString=fio->getParObj()->getSelectString();
1.155 + QString parString=model->getSelectString(dstPar);
1.156 + QString fioPreSelectString=model->getSelectString(fio);
1.157 + QString fioPreParentSelectString=model->getSelectString (fio->getParObj());
1.158 ((BranchObj*)(dst))->addFloatImage (fio);
1.159 xelection.unselect();
1.160 ((BranchObj*)(fio->getParObj()))->removeFloatImage (fio);
1.161 @@ -2592,7 +2607,7 @@
1.162 fio->reposition();
1.163 xelection.select(fio);
1.164 saveState(
1.165 - fio->getSelectString(),
1.166 + model->getSelectString(fio),
1.167 QString("linkTo (\"%1\")").arg(fioPreParentSelectString),
1.168 fioPreSelectString,
1.169 QString ("linkTo (\"%1\")").arg(dstString),
1.170 @@ -2658,6 +2673,22 @@
1.171 }
1.172 }
1.173
1.174 +BranchObj* MapEditor::addMapCenter ()
1.175 +{
1.176 + MapCenterObj *mco= model->addMapCenter(contextMenuPos);
1.177 + xelection.select (mco);
1.178 + updateActions();
1.179 + ensureSelectionVisible();
1.180 + saveState (
1.181 + mco,
1.182 + "delete()",
1.183 + NULL,
1.184 + QString ("addMapCenter (%1,%2)").arg (contextMenuPos.x()).arg(contextMenuPos.y()),
1.185 + QString ("Adding MapCenter to (%1,%2").arg (contextMenuPos.x()).arg(contextMenuPos.y())
1.186 + );
1.187 + return mco;
1.188 +}
1.189 +
1.190 BranchObj* MapEditor::addNewBranchInt(int num)
1.191 {
1.192 // Depending on pos:
1.193 @@ -2717,7 +2748,7 @@
1.194
1.195 model->reposition();
1.196 xelection.update();
1.197 - latestSelection=newbo->getSelectString();
1.198 + latestSelection=model->getSelectString(newbo);
1.199 // In Network mode, the client needs to know where the new branch is,
1.200 // so we have to pass on this information via saveState.
1.201 // TODO: Get rid of this positioning workaround
1.202 @@ -2853,6 +2884,18 @@
1.203 return false;
1.204 }
1.205
1.206 +bool MapEditor::select (LinkableMapObj *lmo)
1.207 +{
1.208 + if (xelection.select(lmo))
1.209 + {
1.210 + xelection.update();
1.211 + ensureSelectionVisible();
1.212 + sendSelection ();
1.213 + return true;
1.214 + }
1.215 + return false;
1.216 +}
1.217 +
1.218 QString MapEditor::getSelectString()
1.219 {
1.220 return xelection.getSelectString();
1.221 @@ -2874,7 +2917,7 @@
1.222 LinkableMapObj *sel=xelection.single();
1.223 if (sel)
1.224 {
1.225 - QString s=sel->getSelectString();
1.226 + QString s=xelection.getSelectString();
1.227 QString part;
1.228 QString typ;
1.229 QString num;
1.230 @@ -2955,7 +2998,7 @@
1.231 BranchObj *bo=xelection.getBranch();
1.232 if (bo)
1.233 {
1.234 - QString s=bo->getSelectString();
1.235 + QString s=xelection.getSelectString();
1.236 QString part;
1.237 QString typ;
1.238 QString num;
1.239 @@ -3391,6 +3434,7 @@
1.240 itFind=model->next(itFind);
1.241 if (!itFind) EOFind=true;
1.242 }
1.243 + //cout <<"still searching... "<<qPrintable( itFind->getHeading())<<endl;
1.244 }
1.245 if (!searching)
1.246 return xelection.getBranch();
1.247 @@ -3649,7 +3693,7 @@
1.248 QString("Remove %1 and keep its childs").arg(getName(bo))
1.249 );
1.250
1.251 - QString sel=bo->getSelectString();
1.252 + QString sel=model->getSelectString(bo);
1.253 unselect();
1.254 par->removeBranchHere(bo);
1.255 model->reposition();
1.256 @@ -4417,16 +4461,11 @@
1.257 void MapEditor::testFunction2()
1.258 {
1.259
1.260 - xelection.select (model->addMapCenter());
1.261 - ensureSelectionVisible();
1.262 -
1.263 -/*
1.264 // Toggle hidemode
1.265 if (hidemode==HideExport)
1.266 setHideTmpMode (HideNone);
1.267 else
1.268 setHideTmpMode (HideExport);
1.269 -*/
1.270 }
1.271
1.272 void MapEditor::contextMenuEvent ( QContextMenuEvent * e )
1.273 @@ -4463,6 +4502,7 @@
1.274 { // No MapObj found, we are on the Canvas itself
1.275 // Context Menu on scene
1.276 updateActions();
1.277 + contextMenuPos=p;
1.278 canvasContextMenu->popup(e->globalPos() );
1.279 }
1.280 e->accept();
1.281 @@ -4697,7 +4737,7 @@
1.282 fio->getParObj()->requestReposition();
1.283 model->reposition();
1.284
1.285 - linkTo (lmo->getSelectString());
1.286 + linkTo (model->getSelectString(lmo));
1.287 //movingObj=lmosel;
1.288 //movingObj_orgRelPos=lmosel->getRelPos();
1.289
1.290 @@ -4876,7 +4916,7 @@
1.291 lmosel->unsetParObjTmp();
1.292
1.293 // For Redo we may need to save original selection
1.294 - QString preSelStr=lmosel->getSelectString();
1.295 + QString preSelStr=model->getSelectString(lmosel);
1.296
1.297 copyingObj=false;
1.298 if (dst )
1.299 @@ -4884,27 +4924,27 @@
1.300 BranchObj* bsel=xelection.getBranch();
1.301 BranchObj* bdst=(BranchObj*)dst;
1.302
1.303 - QString preParStr=(bsel->getParObj())->getSelectString();
1.304 + QString preParStr=model->getSelectString (bsel->getParObj());
1.305 QString preNum=QString::number (bsel->getNum(),10);
1.306 QString preDstParStr;
1.307
1.308 if (e->state() & Qt::ShiftModifier && dst->getParObj())
1.309 { // Link above dst
1.310 - preDstParStr=dst->getParObj()->getSelectString();
1.311 + preDstParStr=model->getSelectString (dst->getParObj());
1.312 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum());
1.313 } else
1.314 if (e->state() & Qt::ControlModifier && dst->getParObj())
1.315 {
1.316 // Link below dst
1.317 - preDstParStr=dst->getParObj()->getSelectString();
1.318 + preDstParStr=model->getSelectString (dst->getParObj());
1.319 bsel->linkTo ( (BranchObj*)(bdst->getParObj()), bdst->getNum()+1);
1.320 } else
1.321 { // Append to dst
1.322 - preDstParStr=dst->getSelectString();
1.323 + preDstParStr=model->getSelectString(dst);
1.324 bsel->linkTo (bdst,-1);
1.325 if (dst->getDepth()==0) bsel->move (savePos);
1.326 }
1.327 - QString postSelStr=lmosel->getSelectString();
1.328 + QString postSelStr=model->getSelectString(lmosel);
1.329 QString postNum=QString::number (bsel->getNum(),10);
1.330
1.331 QString undoCom="linkTo (\""+
1.332 @@ -4931,7 +4971,7 @@
1.333 {
1.334 QString ps=qpointfToString(rp);
1.335 saveState(
1.336 - lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos),
1.337 + model->getSelectString(lmosel), "moveRel "+qpointfToString(movingObj_orgRelPos),
1.338 preSelStr, "moveRel "+ps,
1.339 QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
1.340 }
1.341 @@ -5342,7 +5382,7 @@
1.342 FloatImageObj *fio=bo->addFloatImage();
1.343 fio->load(img);
1.344 fio->setOriginalFilename("No original filename (image added by dropevent)");
1.345 - QString s=bo->getSelectString();
1.346 + QString s=model->getSelectString(bo);
1.347 saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy dropped image to clipboard",fio );
1.348 saveState (fio,"delete ()", bo,QString("paste(%1)").arg(curStep),"Pasting dropped image");
1.349 model->reposition();