diff -r 9079931da6c3 -r 087e60400acc mapeditor.cpp --- a/mapeditor.cpp Wed Jul 27 18:56:32 2005 +0000 +++ b/mapeditor.cpp Wed Jul 27 18:56:35 2005 +0000 @@ -360,7 +360,8 @@ printFrame=true; printFooter=true; - blockreposition=false; + blockReposition=false; + blockSaveState=false; isInteractive=interactive; if (isInteractive) // Create temporary files @@ -468,9 +469,9 @@ } } -bool MapEditor::blockReposition() +bool MapEditor::isRepositionBlocked() { - return blockreposition; + return blockReposition; } void MapEditor::makeTmpDirs() @@ -564,7 +565,7 @@ s+=settings.getXMLData (destPath); // Save selection - if (selection && !saveSelection) + if (selection && !saveSelection ) s+=valueElement("select",selection->getSelectString()); decIndent(); @@ -577,29 +578,38 @@ void MapEditor::saveState() { - saveState (CompleteMap,NULL,""); + saveState (CompleteMap,NULL,"",""); } void MapEditor::saveState(LinkableMapObj *undoSel) { - saveState (PartOfMap,undoSel,""); + saveState (PartOfMap,undoSel,"",""); } -void MapEditor::saveState(const QString & c) +void MapEditor::saveState(const QString & uc, const QString &rc) { LinkableMapObj *undoSel; if (selection) undoSel=selection; else undoSel=NULL; - saveState (UndoCommand,undoSel,c); + saveState (UndoCommand,undoSel,uc,rc); } -void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom) +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom) { + if (blockSaveState) return; + setChanged(); - // Save what is selected now + // Save current selection + redoCommand=redoCom; + if (selection) + redoSelection=selection->getSelectString(); + else + redoSelection=""; + + // Save the object, which should be undone if (undoSel) undoSelection=undoSel->getSelectString(); else @@ -619,10 +629,15 @@ { undoCommand="undoMap ()"; backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL); + undoSelection=""; } /* FIXME testing cout << "ME::saveState()\n"; cout << " undoCom="<moveBranchTo ((BranchObj*)(dst),-1); - if (typeid(*dst) == typeid(MapCenterObj) ) + { + // Get number in parent + x=api.parInt (ok,1); + if (ok) + ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x); + } else if (typeid(*dst) == typeid(MapCenterObj) ) { ((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1); + // Get coordinates of mainbranch x=api.parInt (ok,2); if (ok) { @@ -690,8 +709,10 @@ } // Internal commands, used for undo etc. else if (com==QString("undoMap")) - undoXML(""); - else if (com==QString("undoPart")) + { + if (api.checkParamCount(0)) + undoXML(""); + } else if (com==QString("undoPart")) { if (api.checkParamCount(1)) { @@ -862,7 +883,7 @@ returnCode=1; } else { - blockreposition=true; + blockReposition=true; QXmlInputSource source( file); QXmlSimpleReader reader; reader.setContentHandler( &handler ); @@ -871,7 +892,7 @@ handler.setTmpDir (filePath.left(filePath.findRev("/",-1))); // needed to load files with rel. path handler.setLoadMode (lmode); bool ok = reader.parse( source ); - blockreposition=false; + blockReposition=false; file.close(); if ( ok ) { @@ -1308,6 +1329,8 @@ actionEditUndo->setEnabled (false); mapChanged=false; + if (!redoSelection.isEmpty()) + select (redoSelection); } void MapEditor::undoXML(const QString &undoSel) @@ -1327,6 +1350,7 @@ handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path if (undoSel.isEmpty()) { + unselect(); mapCenter->clear(); handler.setLoadMode (NewMap); } else @@ -1334,9 +1358,11 @@ select (undoSel); handler.setLoadMode (ImportReplace); } - blockreposition=true; + blockReposition=true; + blockSaveState=true; bool ok = reader.parse( source ); - blockreposition=false; + blockReposition=false; + blockSaveState=false; if (! ok ) { // This should never ever happen @@ -1450,12 +1476,12 @@ BranchObj* par; if (typeid(*selection) == typeid(BranchObj) ) { - saveState("moveBranchDown ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); selection=par->moveBranchUp (bo); selection->select(); + saveState("moveBranchDown ()",bo->getSelectString()); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1470,12 +1496,12 @@ BranchObj* par; if (typeid(*selection) == typeid(BranchObj) ) { - saveState("moveBranchUp ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); selection=par->moveBranchDown(bo); selection->select(); + saveState("moveBranchUp ()",bo->getSelectString()); mapCenter->reposition(); ensureSelectionVisible(); } @@ -1490,10 +1516,10 @@ (typeid(*selection) == typeid(BranchObj) || typeid(*selection) == typeid(MapCenterObj) ) ) { - saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")"); + editingBO=(BranchObj*)(selection); + saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() ); ensureSelectionVisible(); - editingBO=(BranchObj*)(selection); QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y())); lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25); QString s=editingBO->getHeading(); @@ -1644,7 +1670,14 @@ if (selection && typeid(*selection) ==typeid(BranchObj) ) { - saveState(selection->getParObj()); + if (selection->getDepth()>1) + // Normal branch, save parent with childs + saveState(selection->getParObj()); + else + // Mainbranch, save whole map + // FIXME Better would be to insert mainbranch again at pos + // But undoCommand is missing right now + saveState(); BranchObj* bo=dynamic_cast (selection); BranchObj* par=(BranchObj*)(bo->getParObj()); bo->unselect(); @@ -1690,8 +1723,8 @@ adjustCanvasSize(); ensureSelectionVisible(); return true; - } else - return false; + } + return false; } void MapEditor::unselect() @@ -2353,10 +2386,13 @@ { if (selection && (typeid(*selection) == typeid(BranchObj) )) { - saveState(selection->getParObj()); - QString sel=selection->getSelectString(); BranchObj* bo=(BranchObj*)(selection); BranchObj* par=(BranchObj*)(bo->getParObj()); + if (bo->getDepth()==1) + saveState(); + else + saveState(selection->getParObj()); // FIXME undoCommand + QString sel=selection->getSelectString(); unselect(); par->removeBranchHere(bo); mapCenter->reposition(); @@ -2412,9 +2448,9 @@ // Finally show dialog if (dia.exec() == QDialog::Accepted) { + saveState(); //FIXME undoCommand mapCenter->setAuthor (dia.getAuthor() ); mapCenter->setComment (dia.getComment() ); - saveState(); //FIXME undoCommand } } @@ -2567,7 +2603,7 @@ { linkstyle=ls; - saveState(); + saveState(); // FIXME undoCommand BranchObj *bo; bo=mapCenter->first(); bo=bo->next(); @@ -3151,8 +3187,8 @@ if (typeid(*selection) == typeid(FloatImageObj)) { - saveState("move "+qpointToString(movingObj_orgPos)); FloatObj *fo=(FloatObj*)(selection); + saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() ); if (fo->getLinkStyle()==StyleUndef) { fo->setLinkStyle(fo->getDefLinkStyle()); @@ -3203,7 +3239,7 @@ if (lmosel->getDepth()==1) { // depth==1, mainbranch - saveState("move "+qpointToString(movingObj_orgPos)); + saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() ); lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() ); } else { @@ -3348,30 +3384,31 @@ if (dst ) { BranchObj* bs=((BranchObj*)(selection)); - saveState ("linkBranchToPos (\""+ + QString undoCom="linkBranchToPos (\""+ (bs->getParObj())->getSelectString()+ "\","+ QString("%1").arg(bs->getNum())+ ","+ QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+ - ")"); + ")"; // TODO we also could check, if dest and src are on same branch, // then it would be sufficient to saveState of this branch // Modifiers allow to insert above/below dst if (e->state() & QMouseEvent::ShiftButton) { - bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()); + bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()); } else if (e->state() & QMouseEvent::ControlButton) { - bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1); + bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1); } else { bs->moveBranchTo ((BranchObj*)(dst),-1); if (dst->getDepth()==0) bs->move (savePos); } + saveState (undoCom,bs->getSelectString() ); } // Draw the original link, before selection was moved around mapCenter->reposition();