mapeditor.cpp
changeset 570 ab83f030285e
parent 537 16d3598f611f
child 571 bc9083a4a7fb
     1.1 --- a/mapeditor.cpp	Wed Jul 04 11:05:15 2007 +0000
     1.2 +++ b/mapeditor.cpp	Mon Jul 30 09:47:08 2007 +0000
     1.3 @@ -20,6 +20,7 @@
     1.4  #include "texteditor.h"
     1.5  #include "warningdialog.h"
     1.6  #include "xml.h"
     1.7 +#include "xml-fm.h"
     1.8  
     1.9  
    1.10  extern TextEditor *textEditor;
    1.11 @@ -1514,7 +1515,7 @@
    1.12  	}	
    1.13  	
    1.14      
    1.15 -    mapBuilderHandler handler;
    1.16 +    parseVYMHandler handler;
    1.17  	QFile file( fname );
    1.18  
    1.19  	// I am paranoid: file should exist anyway
    1.20 @@ -1721,7 +1722,7 @@
    1.21  QPixmap MapEditor::getPixmap()
    1.22  {
    1.23  	QRectF mapRect=mapCenter->getTotalBBox();
    1.24 -	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+2);
    1.25 +	QPixmap pix((int)mapRect.width()+2,(int)mapRect.height()+1);
    1.26  	QPainter pp (&pix);
    1.27  	
    1.28  	pp.setRenderHints(renderHints());
    1.29 @@ -2132,7 +2133,7 @@
    1.30  	if (d.exists() )
    1.31  	{
    1.32  		// We need to parse saved XML data
    1.33 -		mapBuilderHandler handler;
    1.34 +		parseVYMHandler handler;
    1.35  		QXmlInputSource source( file);
    1.36  		QXmlSimpleReader reader;
    1.37  		reader.setContentHandler( &handler );
    1.38 @@ -2174,7 +2175,7 @@
    1.39  		if (d.exists() )
    1.40  		{
    1.41  			// We need to parse saved XML data
    1.42 -			mapBuilderHandler handler;
    1.43 +			parseVYMHandler handler;
    1.44  			QXmlInputSource source( file);
    1.45  			QXmlSimpleReader reader;
    1.46  			reader.setContentHandler( &handler );
    1.47 @@ -4110,7 +4111,64 @@
    1.48  
    1.49  void MapEditor::testFunction1()
    1.50  {
    1.51 -
    1.52 +	ErrorCode err=success;
    1.53 +	LoadMode lmode=NewMap;
    1.54 +
    1.55 +	//QString fname="test/freemind/doc/freemind.xml";
    1.56 +	QString fname="test/freemind/doc/icons.mm";
    1.57 +    parseFMHandler handler;
    1.58 +	QFile file( fname );
    1.59 +
    1.60 +	// I am paranoid: file should exist anyway
    1.61 +	// according to check in mainwindow.
    1.62 +	if (!file.exists() )
    1.63 +	{
    1.64 +		QMessageBox::critical( 0, tr( "Critical Parse Error" ),
    1.65 +				   tr("Couldn't open map " +fname)+".");
    1.66 +		err=aborted;	
    1.67 +	} else
    1.68 +	{
    1.69 +		bool blockSaveStateOrg=blockSaveState;
    1.70 +		blockReposition=true;
    1.71 +		blockSaveState=true;
    1.72 +		QXmlInputSource source( file);
    1.73 +		QXmlSimpleReader reader;
    1.74 +		reader.setContentHandler( &handler );
    1.75 +		reader.setErrorHandler( &handler );
    1.76 +		handler.setMapEditor( this );
    1.77 +
    1.78 +
    1.79 +		// We need to set the tmpDir in order  to load files with rel. path
    1.80 +		QString tmpdir= fname.left(fname.findRev("/",-1));	
    1.81 +		handler.setTmpDir (tmpdir);
    1.82 +		handler.setInputFile (file.name());
    1.83 +		//handler.setLoadMode (lmode);
    1.84 +		bool ok = reader.parse( source );
    1.85 +		blockReposition=false;
    1.86 +		blockSaveState=blockSaveStateOrg;
    1.87 +		file.close();
    1.88 +		if ( ok ) 
    1.89 +		{
    1.90 +			mapCenter->reposition();
    1.91 +			xelection.update();
    1.92 +			if (lmode==NewMap)
    1.93 +			{
    1.94 +				mapDefault=false;
    1.95 +				mapChanged=false;
    1.96 +				mapUnsaved=false;
    1.97 +				autosaveTimer->stop();
    1.98 +			}
    1.99 +		} else 
   1.100 +		{
   1.101 +			QMessageBox::critical( 0, tr( "Critical Parse Error" ),
   1.102 +					   tr( handler.errorProtocol() ) );
   1.103 +			// returnCode=1;	
   1.104 +			// Still return "success": the map maybe at least
   1.105 +			// partially read by the parser
   1.106 +		}	
   1.107 +	}	
   1.108 +	updateActions();
   1.109 +	//return err;
   1.110  /*
   1.111  	BranchObj *bo=xelection.getBranch();
   1.112  	if (bo) animObjList.append( bo );