1.7.2 fixed undo to select the right object before undoCommand
authorinsilmaril
Wed, 27 Jul 2005 18:56:35 +0000
changeset 139087e60400acc
parent 138 9079931da6c3
child 140 cf1e44192f1e
1.7.2 fixed undo to select the right object before undoCommand
branchobj.cpp
branchobj.h
linkablemapobj.cpp
mapeditor.cpp
mapeditor.h
misc.cpp
tex/vym.changelog
version.h
     1.1 --- a/branchobj.cpp	Wed Jul 27 18:56:32 2005 +0000
     1.2 +++ b/branchobj.cpp	Wed Jul 27 18:56:35 2005 +0000
     1.3 @@ -661,17 +661,22 @@
     1.4      return NULL;
     1.5  }
     1.6  
     1.7 +int BranchObj::getDefHeadingSize()
     1.8 +{
     1.9 +	if (depth==0)
    1.10 +		return 16;
    1.11 +	else	
    1.12 +		if (depth==1) 
    1.13 +			return 12;
    1.14 +		else
    1.15 +			return 10;
    1.16 +}
    1.17 +
    1.18  void BranchObj::setHeading(QString s)
    1.19  {
    1.20      // Adjusting font size
    1.21      QFont font=heading->getFont();
    1.22 -	if (depth==0)
    1.23 -		font.setPointSize(16);
    1.24 -	else	
    1.25 -		if (depth>1) 
    1.26 -			font.setPointSize(10);
    1.27 -		else
    1.28 -			font.setPointSize(12);
    1.29 +	font.setPointSize(getDefHeadingSize() );
    1.30      heading->setFont(font);
    1.31      heading->setText(s);	// set new heading
    1.32  	calcBBoxSize();			// recalculate bbox
    1.33 @@ -995,9 +1000,10 @@
    1.34  	// inserts its childs at the place of bo
    1.35  	BranchObj *bo;
    1.36  	bo=borem->getLastBranch();
    1.37 +	int pos=borem->getNum();
    1.38  	while (bo)
    1.39  	{
    1.40 -		bo->moveBranchTo (borem,1);
    1.41 +		bo->moveBranchTo (this,pos+1);
    1.42  		bo=borem->getLastBranch();
    1.43  	}	
    1.44  	removeBranch (borem);
    1.45 @@ -1107,10 +1113,13 @@
    1.46  	} else
    1.47  	{
    1.48  		// inserts me at pos in parent of dst
    1.49 -		par=(BranchObj*)(dst->getParObj());
    1.50  		if (par)
    1.51 -			return par->insertBranchPtr (this,pos);
    1.52 -		else
    1.53 +		{
    1.54 +			BranchObj *bo=dst->insertBranchPtr (this,pos);
    1.55 +			bo->setHeading (bo->getHeading());
    1.56 +			return bo;
    1.57 +
    1.58 +		} else
    1.59  			return NULL;
    1.60  	}	
    1.61  }
     2.1 --- a/branchobj.h	Wed Jul 27 18:56:32 2005 +0000
     2.2 +++ b/branchobj.h	Wed Jul 27 18:56:35 2005 +0000
     2.3 @@ -58,6 +58,7 @@
     2.4      virtual void positionBBox();
     2.5      virtual void calcBBoxSize();
     2.6      virtual LinkableMapObj* findMapObj(QPoint,LinkableMapObj*);	// find MapObj 
     2.7 +    virtual int getDefHeadingSize();
     2.8      virtual void setHeading (QString);
     2.9      virtual void setURL (QString);
    2.10      virtual QString getURL ();
     3.1 --- a/linkablemapobj.cpp	Wed Jul 27 18:56:32 2005 +0000
     3.2 +++ b/linkablemapobj.cpp	Wed Jul 27 18:56:35 2005 +0000
     3.3 @@ -1,3 +1,5 @@
     3.4 +#include <math.h>
     3.5 +
     3.6  #include "linkablemapobj.h"
     3.7  #include "branchobj.h"
     3.8  #include "mapeditor.h"
     3.9 @@ -651,7 +653,7 @@
    3.10  	// we want to block expensive repositioning, but just do it once at
    3.11  	// the end, thus check first:
    3.12  
    3.13 -	if (mapEditor->blockReposition()) return;
    3.14 +	if (mapEditor->isRepositionBlocked()) return;
    3.15  	
    3.16  	// Pass on the request to parental objects, if this hasn't been done yet
    3.17  	
     4.1 --- a/mapeditor.cpp	Wed Jul 27 18:56:32 2005 +0000
     4.2 +++ b/mapeditor.cpp	Wed Jul 27 18:56:35 2005 +0000
     4.3 @@ -360,7 +360,8 @@
     4.4  	printFrame=true;
     4.5  	printFooter=true;
     4.6  
     4.7 -	blockreposition=false;
     4.8 +	blockReposition=false;
     4.9 +	blockSaveState=false;
    4.10  	isInteractive=interactive;
    4.11  	if (isInteractive)
    4.12  		// Create temporary files
    4.13 @@ -468,9 +469,9 @@
    4.14  	}
    4.15  }
    4.16  
    4.17 -bool MapEditor::blockReposition()
    4.18 +bool MapEditor::isRepositionBlocked()
    4.19  {
    4.20 -	return blockreposition;
    4.21 +	return blockReposition;
    4.22  }
    4.23  
    4.24  void MapEditor::makeTmpDirs()
    4.25 @@ -564,7 +565,7 @@
    4.26  	s+=settings.getXMLData (destPath);
    4.27  
    4.28  	// Save selection
    4.29 -	if (selection && !saveSelection) 
    4.30 +	if (selection && !saveSelection ) 
    4.31  		s+=valueElement("select",selection->getSelectString());
    4.32  
    4.33  	decIndent();
    4.34 @@ -577,29 +578,38 @@
    4.35  
    4.36  void MapEditor::saveState()
    4.37  {
    4.38 -	saveState (CompleteMap,NULL,"");
    4.39 +	saveState (CompleteMap,NULL,"","");
    4.40  }
    4.41  
    4.42  void MapEditor::saveState(LinkableMapObj *undoSel)
    4.43  {
    4.44 -	saveState (PartOfMap,undoSel,"");
    4.45 +	saveState (PartOfMap,undoSel,"","");
    4.46  }
    4.47  
    4.48 -void MapEditor::saveState(const QString & c)
    4.49 +void MapEditor::saveState(const QString & uc, const QString &rc)
    4.50  {
    4.51  	LinkableMapObj *undoSel;
    4.52  	if (selection)
    4.53  		undoSel=selection;
    4.54  	else
    4.55  		undoSel=NULL;
    4.56 -	saveState (UndoCommand,undoSel,c);
    4.57 +	saveState (UndoCommand,undoSel,uc,rc);
    4.58  }
    4.59  
    4.60 -void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom)
    4.61 +void MapEditor::saveState(const SaveMode &savemode, LinkableMapObj *undoSel, const QString &undoCom, const QString &redoCom)
    4.62  {
    4.63 +	if (blockSaveState) return;
    4.64 +
    4.65  	setChanged();
    4.66  
    4.67 -	// Save what is selected now
    4.68 +	// Save current selection 
    4.69 +	redoCommand=redoCom;
    4.70 +	if (selection)
    4.71 +		redoSelection=selection->getSelectString();
    4.72 +	else	
    4.73 +		redoSelection="";
    4.74 +
    4.75 +	// Save the object, which should be undone
    4.76  	if (undoSel)
    4.77  		undoSelection=undoSel->getSelectString();
    4.78  	else
    4.79 @@ -619,10 +629,15 @@
    4.80  	{
    4.81  		undoCommand="undoMap ()";
    4.82  		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),NULL);
    4.83 +		undoSelection="";
    4.84  	}
    4.85  	/* FIXME testing
    4.86  	cout << "ME::saveState()\n";
    4.87  	cout << "  undoCom="<<undoCommand<<endl;
    4.88 +	cout << "  undoSel="<<undoSelection<<endl;
    4.89 +	cout << "  ---------------------------"<<endl;
    4.90 +	cout << "  redoCom="<<redoCommand<<endl;
    4.91 +	cout << "  redoSel="<<redoSelection<<endl<<endl;
    4.92  	*/
    4.93  }
    4.94  
    4.95 @@ -644,8 +659,7 @@
    4.96  		moveBranchDown();
    4.97  	else if (com=="move")
    4.98  	{
    4.99 -		if (api.checkParamCount(2) &&
   4.100 -			selection )
   4.101 +		if (api.checkParamCount(2) && selection )
   4.102  		{	
   4.103  			x=api.parInt (ok,0);
   4.104  			if (ok)
   4.105 @@ -666,10 +680,15 @@
   4.106  				if (dst)
   4.107  				{	
   4.108  					if (typeid(*dst) == typeid(BranchObj) ) 
   4.109 -						((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
   4.110 -					if (typeid(*dst) == typeid(MapCenterObj) ) 
   4.111 +					{
   4.112 +						// Get number in parent
   4.113 +						x=api.parInt (ok,1);
   4.114 +						if (ok)
   4.115 +							((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),x);
   4.116 +					} else if (typeid(*dst) == typeid(MapCenterObj) ) 
   4.117  					{
   4.118  						((BranchObj*)(selection))->moveBranchTo ((BranchObj*)(dst),-1);
   4.119 +						// Get coordinates of mainbranch
   4.120  						x=api.parInt (ok,2);
   4.121  						if (ok)
   4.122  						{
   4.123 @@ -690,8 +709,10 @@
   4.124  	}	
   4.125  	// Internal commands, used for undo etc.	
   4.126  	else if (com==QString("undoMap"))
   4.127 -		undoXML("");
   4.128 -	else if (com==QString("undoPart"))
   4.129 +	{
   4.130 +		if (api.checkParamCount(0))
   4.131 +			undoXML("");
   4.132 +	} else if (com==QString("undoPart"))
   4.133  	{
   4.134  		if (api.checkParamCount(1))
   4.135  		{
   4.136 @@ -862,7 +883,7 @@
   4.137  		returnCode=1;	
   4.138  	} else
   4.139  	{
   4.140 -		blockreposition=true;
   4.141 +		blockReposition=true;
   4.142  		QXmlInputSource source( file);
   4.143  		QXmlSimpleReader reader;
   4.144  		reader.setContentHandler( &handler );
   4.145 @@ -871,7 +892,7 @@
   4.146  		handler.setTmpDir (filePath.left(filePath.findRev("/",-1)));	// needed to load files with rel. path
   4.147  		handler.setLoadMode (lmode);
   4.148  		bool ok = reader.parse( source );
   4.149 -		blockreposition=false;
   4.150 +		blockReposition=false;
   4.151  		file.close();
   4.152  		if ( ok ) 
   4.153  		{
   4.154 @@ -1308,6 +1329,8 @@
   4.155  	actionEditUndo->setEnabled (false);
   4.156  	mapChanged=false;
   4.157  
   4.158 +	if (!redoSelection.isEmpty())
   4.159 +		select (redoSelection);
   4.160  }
   4.161  
   4.162  void MapEditor::undoXML(const QString &undoSel)
   4.163 @@ -1327,6 +1350,7 @@
   4.164  		handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
   4.165  		if (undoSel.isEmpty())
   4.166  		{
   4.167 +			unselect();
   4.168  			mapCenter->clear();
   4.169  			handler.setLoadMode (NewMap);
   4.170  		} else	
   4.171 @@ -1334,9 +1358,11 @@
   4.172  			select (undoSel);
   4.173  			handler.setLoadMode (ImportReplace);
   4.174  		}	
   4.175 -		blockreposition=true;
   4.176 +		blockReposition=true;
   4.177 +		blockSaveState=true;
   4.178  		bool ok = reader.parse( source );
   4.179 -		blockreposition=false;
   4.180 +		blockReposition=false;
   4.181 +		blockSaveState=false;
   4.182  		if (! ok ) 
   4.183  		{	
   4.184  			// This should never ever happen
   4.185 @@ -1450,12 +1476,12 @@
   4.186  	BranchObj* par;
   4.187  	if (typeid(*selection) == typeid(BranchObj)  ) 
   4.188  	{
   4.189 -		saveState("moveBranchDown ()");
   4.190  		bo=(BranchObj*)(selection);
   4.191  		par=(BranchObj*)(bo->getParObj());
   4.192  		selection->unselect();
   4.193  		selection=par->moveBranchUp (bo);
   4.194  		selection->select();
   4.195 +		saveState("moveBranchDown ()",bo->getSelectString());
   4.196  		mapCenter->reposition();
   4.197  		ensureSelectionVisible();
   4.198  	}
   4.199 @@ -1470,12 +1496,12 @@
   4.200  	BranchObj* par;
   4.201  	if (typeid(*selection) == typeid(BranchObj)  ) 
   4.202  	{
   4.203 -		saveState("moveBranchUp ()");
   4.204  		bo=(BranchObj*)(selection);
   4.205  		par=(BranchObj*)(bo->getParObj());
   4.206  		selection->unselect(); 
   4.207  		selection=par->moveBranchDown(bo);
   4.208  		selection->select();
   4.209 +		saveState("moveBranchUp ()",bo->getSelectString());
   4.210  		mapCenter->reposition();
   4.211  		ensureSelectionVisible();
   4.212  	}	
   4.213 @@ -1490,10 +1516,10 @@
   4.214  		 (typeid(*selection) == typeid(BranchObj) || 
   4.215  		  typeid(*selection) == typeid(MapCenterObj) ) ) 
   4.216  	{
   4.217 -		saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")");
   4.218 +		editingBO=(BranchObj*)(selection);
   4.219 +		saveState("setHeading (\""+((BranchObj*)(selection))->getHeading()+"\")",editingBO->getSelectString() );
   4.220  
   4.221  		ensureSelectionVisible();
   4.222 -		editingBO=(BranchObj*)(selection);
   4.223  		QPoint p = worldMatrix().map(QPoint (editingBO->x(),editingBO->y()));
   4.224  		lineedit->setGeometry(p.x()-contentsX(),p.y()-contentsY(),200,25);
   4.225  		QString s=editingBO->getHeading();
   4.226 @@ -1644,7 +1670,14 @@
   4.227  
   4.228  	if (selection  && typeid(*selection) ==typeid(BranchObj) ) 
   4.229  	{
   4.230 -		saveState(selection->getParObj());
   4.231 +		if (selection->getDepth()>1)
   4.232 +			// Normal branch, save parent with childs
   4.233 +			saveState(selection->getParObj());
   4.234 +		else
   4.235 +			// Mainbranch, save whole map
   4.236 +			// FIXME Better would be to insert mainbranch again at pos
   4.237 +			// But undoCommand is missing right now
   4.238 +			saveState();
   4.239  		BranchObj* bo=dynamic_cast <BranchObj*> (selection);
   4.240  		BranchObj* par=(BranchObj*)(bo->getParObj());
   4.241  		bo->unselect();
   4.242 @@ -1690,8 +1723,8 @@
   4.243  		adjustCanvasSize();
   4.244  		ensureSelectionVisible();
   4.245  		return true;
   4.246 -	} else
   4.247 -		return false;
   4.248 +	} 
   4.249 +	return false;
   4.250  }
   4.251  
   4.252  void MapEditor::unselect()
   4.253 @@ -2353,10 +2386,13 @@
   4.254  {
   4.255  	if (selection && (typeid(*selection) == typeid(BranchObj) ))
   4.256  	{		
   4.257 -		saveState(selection->getParObj());
   4.258 -		QString sel=selection->getSelectString();
   4.259  		BranchObj* bo=(BranchObj*)(selection);
   4.260  		BranchObj* par=(BranchObj*)(bo->getParObj());
   4.261 +		if (bo->getDepth()==1)
   4.262 +			saveState();
   4.263 +		else	
   4.264 +			saveState(selection->getParObj());	// FIXME undoCommand
   4.265 +		QString sel=selection->getSelectString();
   4.266  		unselect();
   4.267  		par->removeBranchHere(bo);
   4.268  		mapCenter->reposition();
   4.269 @@ -2412,9 +2448,9 @@
   4.270  	// Finally show dialog
   4.271  	if (dia.exec() == QDialog::Accepted)
   4.272  	{
   4.273 +		saveState();	//FIXME undoCommand
   4.274  		mapCenter->setAuthor (dia.getAuthor() );
   4.275  		mapCenter->setComment (dia.getComment() );
   4.276 -		saveState();	//FIXME undoCommand
   4.277  	}
   4.278  }
   4.279  
   4.280 @@ -2567,7 +2603,7 @@
   4.281  {
   4.282  	linkstyle=ls;
   4.283  
   4.284 -	saveState();
   4.285 +	saveState();	// FIXME undoCommand
   4.286  	BranchObj *bo;
   4.287  	bo=mapCenter->first();
   4.288  	bo=bo->next();
   4.289 @@ -3151,8 +3187,8 @@
   4.290  
   4.291  		if (typeid(*selection) == typeid(FloatImageObj))
   4.292  		{
   4.293 -			saveState("move "+qpointToString(movingObj_orgPos));
   4.294  			FloatObj *fo=(FloatObj*)(selection);
   4.295 +			saveState("move "+qpointToString(movingObj_orgPos),fo->getSelectString() );
   4.296  			if (fo->getLinkStyle()==StyleUndef) 
   4.297  			{
   4.298  				fo->setLinkStyle(fo->getDefLinkStyle());
   4.299 @@ -3203,7 +3239,7 @@
   4.300  				if (lmosel->getDepth()==1)
   4.301  				{
   4.302  					// depth==1, mainbranch
   4.303 -					saveState("move "+qpointToString(movingObj_orgPos));
   4.304 +					saveState("move "+qpointToString(movingObj_orgPos), lmosel->getSelectString() );
   4.305  					lmosel->move(p.x() -movingObj_start.x(), p.y()-movingObj_start.y() );		
   4.306  				} else
   4.307  				{
   4.308 @@ -3348,30 +3384,31 @@
   4.309  			if (dst ) 
   4.310  			{
   4.311  				BranchObj* bs=((BranchObj*)(selection));
   4.312 -				saveState ("linkBranchToPos (\""+ 
   4.313 +				QString undoCom="linkBranchToPos (\""+ 
   4.314  					(bs->getParObj())->getSelectString()+
   4.315  					"\","+
   4.316  					QString("%1").arg(bs->getNum())+
   4.317  					","+
   4.318  					QString ("%1,%2").arg(movingObj_orgPos.x()).arg(movingObj_orgPos.y())+
   4.319 -					")");
   4.320 +					")";
   4.321  				// TODO we also could check, if dest and src are on same branch,
   4.322  				// then it would be sufficient to saveState of this branch
   4.323  
   4.324  				// Modifiers allow to insert above/below dst
   4.325  				if (e->state() & QMouseEvent::ShiftButton)
   4.326  				{
   4.327 -					bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum());
   4.328 +					bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum());
   4.329  				} else 
   4.330  				if (e->state() & QMouseEvent::ControlButton)
   4.331  				{
   4.332 -					bs->moveBranchTo ( (BranchObj*)(dst), ((BranchObj*)(dst))->getNum()+1);
   4.333 +					bs->moveBranchTo ( (BranchObj*)(dst->getParObj()), ((BranchObj*)(dst))->getNum()+1);
   4.334  				} else	
   4.335  				{
   4.336  					bs->moveBranchTo ((BranchObj*)(dst),-1);
   4.337  					if (dst->getDepth()==0) 
   4.338  						bs->move (savePos);
   4.339  				} 
   4.340 +				saveState (undoCom,bs->getSelectString() );
   4.341  			}	
   4.342  			// Draw the original link, before selection was moved around
   4.343  			mapCenter->reposition();
     5.1 --- a/mapeditor.h	Wed Jul 27 18:56:32 2005 +0000
     5.2 +++ b/mapeditor.h	Wed Jul 27 18:56:35 2005 +0000
     5.3 @@ -26,7 +26,7 @@
     5.4      MapCenterObj* getMapCenter();
     5.5  	QCanvas* getCanvas();
     5.6  	void adjustCanvasSize();// adjust canvas size to map and scrollview
     5.7 -	bool blockReposition(); // block while load or undo
     5.8 +	bool isRepositionBlocked(); // block while load or undo
     5.9  	
    5.10  private:
    5.11  	void makeTmpDirs();		// create temporary directories
    5.12 @@ -36,8 +36,8 @@
    5.13      QString saveToDir(const QString&,const QString &,bool, const QPoint &,LinkableMapObj*);
    5.14      void saveState();		// save actual state to backup
    5.15      void saveState(LinkableMapObj *);
    5.16 -    void saveState(const QString &);
    5.17 -    void saveState(const SaveMode&, LinkableMapObj *, const QString &);
    5.18 +    void saveState(const QString &, const QString &);
    5.19 +    void saveState(const SaveMode&, LinkableMapObj *, const QString &, const QString &);
    5.20      void parseAtom(const QString &);	
    5.21  
    5.22      void addFloatImage(const QPixmap &img);
    5.23 @@ -190,6 +190,7 @@
    5.24      LinkableMapObj* selection;		// select a LinkableMapObj
    5.25      LinkableMapObj* selectionLast;	// last selection 
    5.26  	QString undoSelection;			// selection for undo
    5.27 +	QString redoSelection;			// selection for redo
    5.28      MapObj* movingObj;				// moving a MapObj
    5.29  	MapObj* linkingObj_src;			// part of a link
    5.30      QPoint movingObj_orgPos;		// org. pos of mouse before move
    5.31 @@ -204,6 +205,7 @@
    5.32  	bool mapUnsaved;				// Flag if map should be saved
    5.33      QString backupXML;				// backup (XML) for undo
    5.34  	QString undoCommand;			// FIXME testing
    5.35 +	QString redoCommand;			// FIXME testing
    5.36  									// if != NULL
    5.37  
    5.38  	bool printFrame;			// Print frame around map
    5.39 @@ -219,7 +221,8 @@
    5.40  
    5.41  	bool isInteractive;			// non interactive don't need tmpdirs
    5.42  	QString bakMapDir;			// tmp directory with data for undo
    5.43 -	bool blockreposition;		// block while load or undo
    5.44 +	bool blockReposition;		// block while load or undo
    5.45 +	bool blockSaveState;		// block while load or undo
    5.46  
    5.47  	BranchObj* itFind;			// next object in find process
    5.48  	bool EOFind;				// true, if search failed
     6.1 --- a/misc.cpp	Wed Jul 27 18:56:32 2005 +0000
     6.2 +++ b/misc.cpp	Wed Jul 27 18:56:35 2005 +0000
     6.3 @@ -1,3 +1,5 @@
     6.4 +#include <math.h>
     6.5 +
     6.6  #include <qregexp.h>
     6.7  #include <qpoint.h>
     6.8  
     7.1 --- a/tex/vym.changelog	Wed Jul 27 18:56:32 2005 +0000
     7.2 +++ b/tex/vym.changelog	Wed Jul 27 18:56:35 2005 +0000
     7.3 @@ -1,3 +1,8 @@
     7.4 +-------------------------------------------------------------------
     7.5 +Mi Jul 27 17:27:14 CEST 2005
     7.6 +
     7.7 +- Bugfix: if selection changed before undo, undo worked on wrong branch
     7.8 +
     7.9  -------------------------------------------------------------------
    7.10  Mon Jul 25 22:22:21 CEST 2005
    7.11  
     8.1 --- a/version.h	Wed Jul 27 18:56:32 2005 +0000
     8.2 +++ b/version.h	Wed Jul 27 18:56:35 2005 +0000
     8.3 @@ -1,7 +1,7 @@
     8.4  #ifndef VERSION_H 
     8.5  #define VERSION_H
     8.6  
     8.7 -#define __VYM_VERSION__ "1.7.1"
     8.8 -#define __BUILD_DATE__ "July 25, 2005"
     8.9 +#define __VYM_VERSION__ "1.7.2"
    8.10 +#define __BUILD_DATE__ "July 27, 2005"
    8.11  
    8.12  #endif