diff -r 270593ab83b2 -r 67a91e28b30f mapeditor.cpp --- a/mapeditor.cpp Mon May 30 05:39:10 2005 +0000 +++ b/mapeditor.cpp Mon Jun 06 20:27:42 2005 +0000 @@ -22,6 +22,7 @@ #include "version.h" +#include "api.h" #include "xml.h" #include "texteditor.h" #include "linkablemapobj.h" @@ -571,6 +572,11 @@ void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part) { + saveState (mode,part,""); +} + +void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part, const QString &undoCom) +{ // all binary data is saved in bakMapDir (created in Constructor) // the xml data itself is kept in memory in backupXML // @@ -580,11 +586,20 @@ if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) ) { - // Writing a vympart only is useful for BranchObj - undoSelection=part; - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap); + // So far we only test undoCommands for BranchObjs + undoCommand=undoCom; + if (undoCommand!="") + { + undoSelection=part; + } else + { + // Writing a vympart only is useful for BranchObj + undoSelection=part; + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap); + } } else { + undoCommand=""; undoSelection=NULL; backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap); } @@ -1105,37 +1120,50 @@ selection=NULL; } - mapBuilderHandler handler; - QXmlInputSource source; - source.setData(backupXML); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); - handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path - if (undoSelection) + if (undoCommand!="" && undoSelection) { + // We don't need to parse XML backup, but + // do the undoCommand selection=undoSelection; selection->select(); - handler.setLoadMode (ImportReplace); - - } else + parseTest (undoCommand); + + } else { - mapCenter->clear(); - handler.setLoadMode (NewMap); - } - blockreposition=true; - bool ok = reader.parse( source ); - blockreposition=false; - if ( ok ) - mapCenter->reposition(); - - else - { - // This should never ever happen - QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), - tr( handler.errorProtocol() )+" in "+backupXML ); - } + // We need to parse saved XML data + mapBuilderHandler handler; + QXmlInputSource source; + source.setData(backupXML); + QXmlSimpleReader reader; + reader.setContentHandler( &handler ); + reader.setErrorHandler( &handler ); + handler.setMapEditor( this ); + handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path + if (undoSelection) + { + selection=undoSelection; + selection->select(); + handler.setLoadMode (ImportReplace); + + } else + { + mapCenter->clear(); + handler.setLoadMode (NewMap); + } + blockreposition=true; + bool ok = reader.parse( source ); + blockreposition=false; + if ( ok ) + mapCenter->reposition(); + + else + { + // This should never ever happen + QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ), + tr( handler.errorProtocol() )+" in "+backupXML ); + } + } // restoring saved version + // Undo not longer available now actionEditUndo->setEnabled (false); undoSelection=false; @@ -1307,7 +1335,7 @@ if (typeid(*selection) == typeid(BranchObj) ) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(PartOfMap,selection,"moveBranchDown ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); @@ -1328,7 +1356,7 @@ if (typeid(*selection) == typeid(BranchObj) ) { setChanged(); - saveState(PartOfMap,selection->getParObj()); + saveState(PartOfMap,selection,"moveBranchUp ()"); bo=(BranchObj*)(selection); par=(BranchObj*)(bo->getParObj()); selection->unselect(); @@ -2779,9 +2807,32 @@ } } +#include "api.h" + void MapEditor::testFunction() { cout << "MapEditor::testFunction() called\n"; + if (selection && + (typeid(*selection) == typeid(BranchObj)) ) + { + QString s=((BranchObj*)(selection))->getHeading(); + parseTest (s); + } +} + +void MapEditor::parseTest(const QString &s) +{ + API api; + QString c,p,p0; + api.parseCommand (s,c,p); + if (c==QString("moveBranchUp")) + moveBranchUp(); + else if (c=="moveBranchDown") + moveBranchDown(); + else if (c=="select") + select (p); + else + cout << "Don't know about command \""<