1.6.8 started API to speedup undos
authorinsilmaril
Mon, 06 Jun 2005 20:27:42 +0000
changeset 10567a91e28b30f
parent 104 270593ab83b2
child 106 4083860dd82e
1.6.8 started API to speedup undos
api.cpp
api.h
demos/todo.vym
mainwindow.cpp
mapeditor.cpp
mapeditor.h
tex/vym.tex
version.h
vym.pro
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/api.cpp	Mon Jun 06 20:27:42 2005 +0000
     1.3 @@ -0,0 +1,38 @@
     1.4 +#include "api.h"
     1.5 +
     1.6 +#include <qregexp.h>
     1.7 +
     1.8 +void API::parseCommand (const QString &s,QString &command,QString
     1.9 +&param)
    1.10 +{
    1.11 +	param="";
    1.12 +	command="";
    1.13 +	QRegExp re;
    1.14 +	int pos;
    1.15 +
    1.16 +	// Get command
    1.17 +	re.setPattern ("(.*)\\s");
    1.18 +	re.setMinimal (false);
    1.19 +	pos=re.search (s);
    1.20 +	if (pos>=0)
    1.21 +		command=re.cap(1);
    1.22 +
    1.23 +	// Get parameters
    1.24 +	re.setPattern ("\\((.*)\\)");
    1.25 +	pos=re.search (s);
    1.26 +	if (pos>=0)
    1.27 +		param=re.cap (1);
    1.28 +}
    1.29 +
    1.30 +void API::getString (const QString &s, QString &rs)
    1.31 +{
    1.32 +	// return the string in s, this could be also stored in
    1.33 +	// a variable later
    1.34 +	QRegExp re("\"(.*)\"");
    1.35 +	int pos=re.search (s);
    1.36 +	if (pos>=0)
    1.37 +		rs=re.cap (1);
    1.38 +	else	
    1.39 +		rs="";
    1.40 +
    1.41 +}
    1.42 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/api.h	Mon Jun 06 20:27:42 2005 +0000
     2.3 @@ -0,0 +1,13 @@
     2.4 +#ifndef API_H
     2.5 +#define API_H
     2.6 +
     2.7 +#include <qstring.h>
     2.8 +
     2.9 +class API
    2.10 +{
    2.11 +public:
    2.12 +	void parseCommand (const QString&, QString &, QString &);
    2.13 +	void getString (const QString&, QString &);
    2.14 +};
    2.15 +
    2.16 +#endif
     3.1 Binary file demos/todo.vym has changed
     4.1 --- a/mainwindow.cpp	Mon May 30 05:39:10 2005 +0000
     4.2 +++ b/mainwindow.cpp	Mon Jun 06 20:27:42 2005 +0000
     4.3 @@ -927,13 +927,13 @@
     4.4  	// This will be populated "on demand" in MapEditor::updateActions
     4.5  	branchContextMenu->insertSeparator();	
     4.6  	branchLinksContextMenu =new QPopupMenu (this);
     4.7 -	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
     4.8 -	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
     4.9 -	
    4.10  	branchLinksContextMenuDup =new QPopupMenu (this);
    4.11  	branchContextMenu->insertItem (tr("Edit XLink"),branchLinksContextMenuDup);
    4.12  	connect( branchLinksContextMenuDup, SIGNAL( activated(int) ), this, SLOT( editEditXLink(int ) ) );
    4.13  
    4.14 +	branchContextMenu->insertItem (tr("Goto XLink"),branchLinksContextMenu);
    4.15 +	connect( branchLinksContextMenu, SIGNAL( activated(int) ), this, SLOT( editFollowXLink(int ) ) );
    4.16 +	
    4.17  	// Context menu for floatimage
    4.18  	floatimageContextMenu =new QPopupMenu (this);
    4.19  	saveImageFormatMenu=new QPopupMenu (this);
     5.1 --- a/mapeditor.cpp	Mon May 30 05:39:10 2005 +0000
     5.2 +++ b/mapeditor.cpp	Mon Jun 06 20:27:42 2005 +0000
     5.3 @@ -22,6 +22,7 @@
     5.4  
     5.5  #include "version.h"
     5.6  
     5.7 +#include "api.h"
     5.8  #include "xml.h"
     5.9  #include "texteditor.h"
    5.10  #include "linkablemapobj.h"
    5.11 @@ -571,6 +572,11 @@
    5.12  
    5.13  void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part)
    5.14  {
    5.15 +	saveState (mode,part,"");
    5.16 +}
    5.17 +
    5.18 +void MapEditor::saveState(const SaveMode &mode, LinkableMapObj *part, const QString &undoCom)
    5.19 +{
    5.20  	// all binary data is saved in bakMapDir (created in Constructor)
    5.21  	// the xml data itself is kept in memory in backupXML
    5.22  	// 
    5.23 @@ -580,11 +586,20 @@
    5.24  
    5.25  	if (mode==PartOfMap && part && (typeid(*part) == typeid (BranchObj) ) ) 
    5.26  	{
    5.27 -		// Writing a vympart only is useful for BranchObj
    5.28 -		undoSelection=part;
    5.29 -		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
    5.30 +		// So far we only test undoCommands for BranchObjs
    5.31 +		undoCommand=undoCom;
    5.32 +		if (undoCommand!="")
    5.33 +		{
    5.34 +			undoSelection=part;
    5.35 +		} else
    5.36 +		{
    5.37 +			// Writing a vympart only is useful for BranchObj
    5.38 +			undoSelection=part;
    5.39 +			backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),PartOfMap);
    5.40 +		}
    5.41  	} else	
    5.42  	{
    5.43 +		undoCommand="";
    5.44  		undoSelection=NULL;
    5.45  		backupXML=saveToDir (bakMapDir,mapName+"-",false, QPoint (),CompleteMap);
    5.46  	}	
    5.47 @@ -1105,37 +1120,50 @@
    5.48  			selection=NULL;
    5.49  		}	
    5.50  		
    5.51 -		mapBuilderHandler handler;
    5.52 -		QXmlInputSource source;
    5.53 -		source.setData(backupXML);
    5.54 -		QXmlSimpleReader reader;
    5.55 -		reader.setContentHandler( &handler );
    5.56 -		reader.setErrorHandler( &handler );
    5.57 -		handler.setMapEditor( this );
    5.58 -		handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
    5.59 -		if (undoSelection)
    5.60 +		if (undoCommand!="" && undoSelection)
    5.61  		{
    5.62 +			// We don't need to parse XML backup, but
    5.63 +			// do the undoCommand
    5.64  			selection=undoSelection;
    5.65  			selection->select();
    5.66 -			handler.setLoadMode (ImportReplace);
    5.67 -
    5.68 -		} else	
    5.69 +			parseTest (undoCommand);
    5.70 +
    5.71 +		} else
    5.72  		{
    5.73 -			mapCenter->clear();
    5.74 -			handler.setLoadMode (NewMap);
    5.75 -		}	
    5.76 -		blockreposition=true;
    5.77 -		bool ok = reader.parse( source );
    5.78 -		blockreposition=false;
    5.79 -		if ( ok ) 
    5.80 -			mapCenter->reposition();
    5.81 -			
    5.82 -		else 
    5.83 -		{	
    5.84 -			// This should never ever happen
    5.85 -			QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
    5.86 -								   tr( handler.errorProtocol() )+" in "+backupXML );
    5.87 -		}
    5.88 +			// We need to parse saved XML data
    5.89 +			mapBuilderHandler handler;
    5.90 +			QXmlInputSource source;
    5.91 +			source.setData(backupXML);
    5.92 +			QXmlSimpleReader reader;
    5.93 +			reader.setContentHandler( &handler );
    5.94 +			reader.setErrorHandler( &handler );
    5.95 +			handler.setMapEditor( this );
    5.96 +			handler.setTmpDir ( bakMapDir );	// needed to load files with rel. path
    5.97 +			if (undoSelection)
    5.98 +			{
    5.99 +				selection=undoSelection;
   5.100 +				selection->select();
   5.101 +				handler.setLoadMode (ImportReplace);
   5.102 +
   5.103 +			} else	
   5.104 +			{
   5.105 +				mapCenter->clear();
   5.106 +				handler.setLoadMode (NewMap);
   5.107 +			}	
   5.108 +			blockreposition=true;
   5.109 +			bool ok = reader.parse( source );
   5.110 +			blockreposition=false;
   5.111 +			if ( ok ) 
   5.112 +				mapCenter->reposition();
   5.113 +				
   5.114 +			else 
   5.115 +			{	
   5.116 +				// This should never ever happen
   5.117 +				QMessageBox::critical( 0, tr( "Critical Parse Error by reading backupFile" ),
   5.118 +									   tr( handler.errorProtocol() )+" in "+backupXML );
   5.119 +			}
   5.120 +		} // restoring saved version	
   5.121 +
   5.122  		// Undo not longer available now
   5.123  		actionEditUndo->setEnabled (false);
   5.124  		undoSelection=false;
   5.125 @@ -1307,7 +1335,7 @@
   5.126  	if (typeid(*selection) == typeid(BranchObj)  ) 
   5.127  	{
   5.128  		setChanged();
   5.129 -		saveState(PartOfMap,selection->getParObj());
   5.130 +		saveState(PartOfMap,selection,"moveBranchDown ()");
   5.131  		bo=(BranchObj*)(selection);
   5.132  		par=(BranchObj*)(bo->getParObj());
   5.133  		selection->unselect();
   5.134 @@ -1328,7 +1356,7 @@
   5.135  	if (typeid(*selection) == typeid(BranchObj)  ) 
   5.136  	{
   5.137  		setChanged();
   5.138 -		saveState(PartOfMap,selection->getParObj());
   5.139 +		saveState(PartOfMap,selection,"moveBranchUp ()");
   5.140  		bo=(BranchObj*)(selection);
   5.141  		par=(BranchObj*)(bo->getParObj());
   5.142  		selection->unselect(); 
   5.143 @@ -2779,9 +2807,32 @@
   5.144  	}
   5.145  }
   5.146  
   5.147 +#include "api.h"
   5.148 +
   5.149  void MapEditor::testFunction()
   5.150  {
   5.151  	cout << "MapEditor::testFunction() called\n";
   5.152 +	if (selection && 
   5.153 +		(typeid(*selection) == typeid(BranchObj)) )
   5.154 +	{
   5.155 +		QString s=((BranchObj*)(selection))->getHeading();
   5.156 +		parseTest (s);
   5.157 +	}
   5.158 +}
   5.159 +
   5.160 +void MapEditor::parseTest(const QString &s)
   5.161 +{
   5.162 +	API api;
   5.163 +	QString c,p,p0;
   5.164 +	api.parseCommand (s,c,p);
   5.165 +	if (c==QString("moveBranchUp"))
   5.166 +		moveBranchUp();
   5.167 +	else if (c=="moveBranchDown")
   5.168 +		moveBranchDown();
   5.169 +	else if (c=="select")
   5.170 +		select (p);
   5.171 +	else
   5.172 +		cout << "Don't know about command \""<<s<<"\".\n";
   5.173  }
   5.174  
   5.175  void MapEditor::ensureSelectionVisible()
     6.1 --- a/mapeditor.h	Mon May 30 05:39:10 2005 +0000
     6.2 +++ b/mapeditor.h	Mon Jun 06 20:27:42 2005 +0000
     6.3 @@ -33,6 +33,7 @@
     6.4  	&,SaveMode);
     6.5      void saveState();		// save actual state to backup
     6.6      void saveState(const SaveMode&, LinkableMapObj *);
     6.7 +    void saveState(const SaveMode&, LinkableMapObj *, const QString &);
     6.8  
     6.9  private slots:
    6.10      void finishedLineEditNoSave();
    6.11 @@ -137,6 +138,7 @@
    6.12  	void followXLink (int);
    6.13  	void editXLink (int);
    6.14      void testFunction();				// FIXME just testing
    6.15 +    void parseTest(const QString &);	// FIXME just testing
    6.16  
    6.17  protected:
    6.18  	void ensureSelectionVisible();		
    6.19 @@ -184,6 +186,7 @@
    6.20  	bool mapUnsaved;				// Flag if map should be saved
    6.21      QString backupXML;				// backup (XML) for undo
    6.22  	LinkableMapObj* undoSelection;	// replace this LMO with vympart from backup
    6.23 +	QString undoCommand;			// FIXME testing
    6.24  									// if != NULL
    6.25  
    6.26  	bool printFrame;			// Print frame around map
     7.1 --- a/tex/vym.tex	Mon May 30 05:39:10 2005 +0000
     7.2 +++ b/tex/vym.tex	Mon Jun 06 20:27:42 2005 +0000
     7.3 @@ -33,7 +33,6 @@
     7.4  \begin{document}
     7.5  \title{VYM \\ -- \\View Your Mind}
     7.6  \author{\textcopyright Uwe Drechsel  }
     7.7 -%\date{September 26, 2002}
     7.8  
     7.9  \maketitle
    7.10  
    7.11 @@ -582,6 +581,7 @@
    7.12  \section{Hello world}
    7.13  \vym can export its maps in various formats and can import data from
    7.14  outside (though import is still limited at the moment).
    7.15 +Also parts of a map can be exported.
    7.16  
    7.17  \subsection{Export}
    7.18  The format in which the map will be exported can be chosen with
    7.19 @@ -671,6 +671,12 @@
    7.20  on. This is useful if e.g. for a website several combined maps have to
    7.21  be stored in the same directory.
    7.22  
    7.23 +\subsubsection*{Export a part of a map}
    7.24 +Select a branch you want to export together with its childs, than open
    7.25 +the context menu and choose {\em Save Selection}. This will create a
    7.26 +file with the postfix {\tt .vyp}, which is an abbreviation for \lq vym
    7.27 +part\rq.
    7.28 +
    7.29  \subsection{Import} 
    7.30  At the moment \vym can read a directory structure. This is mainly for
    7.31  testing \vym e.g. to easily create huge maps used for benchmarks (yes,
    7.32 @@ -679,6 +685,8 @@
    7.33  Many other applications meanwhile can export their data using XML, so
    7.34  volunteers to write import filters are welcome.
    7.35  
    7.36 +Also parts of a vym map ({\tt .vyp}) can be imported.
    7.37 +
    7.38  \subsection{File format}
    7.39  \vym maps usually have the postfix "{\tt .vym}" and represent a
    7.40  compressed archive of data. If you want to have a
    7.41 @@ -698,12 +706,34 @@
    7.42  	zip -r vymfile.vym .
    7.43  \end{verbatim}
    7.44  
    7.45 +\subsubsection*{Importa part of a map}
    7.46 +Select a branch where you want to add a previously save part of a map
    7.47 +({\tt .vyp}), then open
    7.48 +the context menu and choose {\em Add \ra Import}. For the import you can
    7.49 +choose between {\em Import Add} and {\em Import Replace}: The imported
    7.50 +data will be added after the selection resp. replace the selection.
    7.51  
    7.52  %TODO
    7.53  %\subsubsection{Menus}
    7.54  %\subsubsection{Keyboard shortcuts}
    7.55  %Where does vym save its settings? -> ~/.qt/vymrc
    7.56  
    7.57 +
    7.58 +\section{\vym on Mac OS X}
    7.59 +\subsection{Overview}
    7.60 +Basically there are two ways to run \vym on Macs:
    7.61 +\subsubsection{QT Mac Edition:}
    7.62 +	\vym here provides the well known Mac look and feel.  \vym is
    7.63 +	available as zipped Mac OS X application. It has been compiled and
    7.64 +	tested in Mac~OS~10.3, but should also work on Tiger. It is using
    7.65 +	the Mac version of Trolltechs QT library.  
    7.66 +\subsubsection{X11}
    7.67 +	\vym can also be run using the Linux version, but then menus and
    7.68 +	handling will also be those of the Linux version e.g. The menu bar
    7.69 +	will look different. 
    7.70 +
    7.71 +%TODO  Concept on Mac   context menu, shortcuts...
    7.72 +
    7.73  \section{History of \vym}
    7.74  \subsection{Future}
    7.75  There are lots of features which might find their way into \vym.
    7.76 @@ -729,7 +759,7 @@
    7.77  1.6.5	& -	&	removing a branch and keeping its childs	& 2005-05-19 \\
    7.78          & -	&	removing childs of a branch			& \\
    7.79          & -	&	insert branch and make selection its child& \\
    7.80 -        & -	&	restructured branch context menu	& \\
    7.81 +        & -	&	restructured branch context menu	
    7.82  				in a basic version (straight line)	& 2005-04-15\\
    7.83          & -	&	New shortcuts  for use on Mac OS X	& \\
    7.84          & -	&	Importing directories generates vymlinks now & \\
     8.1 --- a/version.h	Mon May 30 05:39:10 2005 +0000
     8.2 +++ b/version.h	Mon Jun 06 20:27:42 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.6.7"
     8.8 -#define __BUILD_DATE__ "May 27, 2005"
     8.9 +#define __VYM_VERSION__ "1.6.8"
    8.10 +#define __BUILD_DATE__ "June 06, 2005"
    8.11  
    8.12  #endif
     9.1 --- a/vym.pro	Mon May 30 05:39:10 2005 +0000
     9.2 +++ b/vym.pro	Mon Jun 06 20:27:42 2005 +0000
     9.3 @@ -3,7 +3,8 @@
     9.4  
     9.5  CONFIG	+= qt warn_on release
     9.6  
     9.7 -HEADERS	+= branchobj.h \
     9.8 +HEADERS	+= api.h \
     9.9 +	branchobj.h \
    9.10  	exports.h \
    9.11  	findwindow.h \
    9.12  	flagobj.h \
    9.13 @@ -30,7 +31,8 @@
    9.14  	settings.h \
    9.15  	options.h
    9.16  
    9.17 -SOURCES	+= branchobj.cpp \
    9.18 +SOURCES	+= api.cpp \
    9.19 +	branchobj.cpp \
    9.20  	exports.cpp \
    9.21  	findwindow.cpp \
    9.22  	flagobj.cpp \