1.1 --- a/mapeditor.cpp Mon May 30 05:39:10 2005 +0000
1.2 +++ b/mapeditor.cpp Mon Jun 06 20:27:42 2005 +0000
1.3 @@ -22,6 +22,7 @@
1.4
1.5 #include "version.h"
1.6
1.7 +#include "api.h"
1.8 #include "xml.h"
1.9 #include "texteditor.h"
1.10 #include "linkablemapobj.h"
1.11 @@ -571,6 +572,11 @@
1.12
1.13 void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
1.14 {
1.15 + saveState (mode,part,"");
1.16 +}
1.17 +
1.18 +void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part, const QString &undoCom)
1.19 +{
1.20 // all binary data is saved in bakMapDir (created in Constructor)
1.21 // the xml data itself is kept in memory in backupXML
1.22 //
1.23 @@ -580,11 +586,20 @@
1.24
1.25 if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) )
1.26 {
1.27 - // Writing a vympart only is useful for BranchObj
1.28 - undoSelection=part;
1.29 - backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
1.30 + // So far we only test undoCommands for BranchObjs
1.31 + undoCommand=undoCom;
1.32 + if (undoCommand!="")
1.33 + {
1.34 + undoSelection=part;
1.35 + } else
1.36 + {
1.37 + // Writing a vympart only is useful for BranchObj
1.38 + undoSelection=part;
1.39 + backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
1.40 + }
1.41 } else
1.42 {
1.43 + undoCommand="";
1.44 undoSelection=NULL;
1.45 backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
1.46 }
1.47 @@ -1105,37 +1120,50 @@
1.48 selection=NULL;
1.49 }
1.50
1.51 - mapBuilderHandler handler;
1.52 - QXmlInputSource source;
1.53 - source.setData(backupXML);
1.54 - QXmlSimpleReader reader;
1.55 - reader.setContentHandler( &handler );
1.56 - reader.setErrorHandler( &handler );
1.57 - handler.setMapEditor( this );
1.58 - handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1.59 - if (undoSelection)
1.60 + if (undoCommand!="" && undoSelection)
1.61 {
1.62 + // We don't need to parse XML backup, but
1.63 + // do the undoCommand
1.64 selection=undoSelection;
1.65 selection->select();
1.66 - handler.setLoadMode (ImportReplace);
1.67 -
1.68 - } else
1.69 + parseTest (undoCommand);
1.70 +
1.71 + } else
1.72 {
1.73 - mapCenter->clear();
1.74 - handler.setLoadMode (NewMap);
1.75 - }
1.76 - blockreposition=true;
1.77 - bool ok = reader.parse( source );
1.78 - blockreposition=false;
1.79 - if ( ok )
1.80 - mapCenter->reposition();
1.81 -
1.82 - else
1.83 - {
1.84 - // This should never ever happen
1.85 - QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1.86 - tr( handler.errorProtocol() )+" in "+backupXML );
1.87 - }
1.88 + // We need to parse saved XML data
1.89 + mapBuilderHandler handler;
1.90 + QXmlInputSource source;
1.91 + source.setData(backupXML);
1.92 + QXmlSimpleReader reader;
1.93 + reader.setContentHandler( &handler );
1.94 + reader.setErrorHandler( &handler );
1.95 + handler.setMapEditor( this );
1.96 + handler.setTmpDir ( bakMapDir ); // needed to load files with rel. path
1.97 + if (undoSelection)
1.98 + {
1.99 + selection=undoSelection;
1.100 + selection->select();
1.101 + handler.setLoadMode (ImportReplace);
1.102 +
1.103 + } else
1.104 + {
1.105 + mapCenter->clear();
1.106 + handler.setLoadMode (NewMap);
1.107 + }
1.108 + blockreposition=true;
1.109 + bool ok = reader.parse( source );
1.110 + blockreposition=false;
1.111 + if ( ok )
1.112 + mapCenter->reposition();
1.113 +
1.114 + else
1.115 + {
1.116 + // This should never ever happen
1.117 + QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
1.118 + tr( handler.errorProtocol() )+" in "+backupXML );
1.119 + }
1.120 + } // restoring saved version
1.121 +
1.122 // Undo not longer available now
1.123 actionEditUndo->setEnabled (false);
1.124 undoSelection=false;
1.125 @@ -1307,7 +1335,7 @@
1.126 if (typeid(*selection) == typeid(BranchObj) )
1.127 {
1.128 setChanged();
1.129 - saveState(PartOfMap,selection->getParObj());
1.130 + saveState(PartOfMap,selection,"moveBranchDown ()");
1.131 bo=(BranchObj*)(selection);
1.132 par=(BranchObj*)(bo->getParObj());
1.133 selection->unselect();
1.134 @@ -1328,7 +1356,7 @@
1.135 if (typeid(*selection) == typeid(BranchObj) )
1.136 {
1.137 setChanged();
1.138 - saveState(PartOfMap,selection->getParObj());
1.139 + saveState(PartOfMap,selection,"moveBranchUp ()");
1.140 bo=(BranchObj*)(selection);
1.141 par=(BranchObj*)(bo->getParObj());
1.142 selection->unselect();
1.143 @@ -2779,9 +2807,32 @@
1.144 }
1.145 }
1.146
1.147 +#include "api.h"
1.148 +
1.149 void MapEditor::testFunction()
1.150 {
1.151 cout << "MapEditor::testFunction() called\n";
1.152 + if (selection &&
1.153 + (typeid(*selection) == typeid(BranchObj)) )
1.154 + {
1.155 + QString s=((BranchObj*)(selection))->getHeading();
1.156 + parseTest (s);
1.157 + }
1.158 +}
1.159 +
1.160 +void MapEditor::parseTest(const QString &s)
1.161 +{
1.162 + API api;
1.163 + QString c,p,p0;
1.164 + api.parseCommand (s,c,p);
1.165 + if (c==QString("moveBranchUp"))
1.166 + moveBranchUp();
1.167 + else if (c=="moveBranchDown")
1.168 + moveBranchDown();
1.169 + else if (c=="select")
1.170 + select (p);
1.171 + else
1.172 + cout << "Don't know about command \""<<s<<"\".\n";
1.173 }
1.174
1.175 void MapEditor::ensureSelectionVisible()