mapeditor.cpp
branchrelease-1-12-maintained
changeset 75 dbb2a175f7b5
parent 70 e3a85616dbc5
child 76 a36a289372a6
     1.1 --- a/mapeditor.cpp	Wed Jul 22 11:47:03 2009 +0000
     1.2 +++ b/mapeditor.cpp	Thu Jul 30 12:55:17 2009 +0000
     1.3 @@ -249,7 +249,9 @@
     1.4  		
     1.5  		s=(((BranchObj*)lmo)->getHeading());
     1.6  		if (s=="") s="unnamed";
     1.7 -		return QString("branch (%1)").arg(s);
     1.8 +		if ((typeid(*lmo) == typeid(BranchObj) ) )
     1.9 +			return QString("branch (%1)").arg(s);
    1.10 +		return QString("mapcenter (%1)").arg(s);
    1.11  	}	
    1.12  	if ((typeid(*lmo) == typeid(FloatImageObj) ))
    1.13  		return QString ("floatimage [%1]").arg(((FloatImageObj*)lmo)->getOriginalFilename());
    1.14 @@ -321,12 +323,15 @@
    1.15  	FloatImageObj (mapScene).resetSaveCounter();
    1.16  
    1.17  	// Build xml recursivly
    1.18 -	if (!saveSel || typeid (*saveSel) == typeid (MapCenterObj))
    1.19 +	if (!saveSel )
    1.20  		// Save complete map, if saveSel not set
    1.21  		s+=model->saveToDir(tmpdir,prefix,writeflags,offset);
    1.22  	else
    1.23  	{
    1.24 -		if ( typeid(*saveSel) == typeid(BranchObj) )
    1.25 +		if ( typeid (*saveSel) == typeid (MapCenterObj))
    1.26 +			// Save Subtree
    1.27 +			s+=((MapCenterObj*)saveSel)->saveToDir(tmpdir,prefix,0,offset);
    1.28 +		else if ( typeid(*saveSel) == typeid(BranchObj) )
    1.29  			// Save Subtree
    1.30  			s+=((BranchObj*)saveSel)->saveToDir(tmpdir,prefix,offset);
    1.31  		else 
    1.32 @@ -471,10 +476,12 @@
    1.33  		qWarning ("MapEditor::saveStateRemovingPart  no redoSel given!");
    1.34  		return;
    1.35  	}
    1.36 -	QString undoSelection=model->getSelectString (redoSel->getParObj());
    1.37 +	
    1.38 +	QString undoSelection;
    1.39  	QString redoSelection=model->getSelectString(redoSel);
    1.40  	if (typeid(*redoSel) == typeid(BranchObj)  ) 
    1.41  	{
    1.42 +		undoSelection=model->getSelectString (redoSel->getParObj());
    1.43  		// save the selected branch of the map, Undo will insert part of map 
    1.44  		saveState (PartOfMap,
    1.45  			undoSelection, QString("addMapInsert (\"PATH\",%1)").arg(((BranchObj*)redoSel)->getNum()),
    1.46 @@ -482,6 +489,16 @@
    1.47  			comment, 
    1.48  			redoSel);
    1.49  	}
    1.50 +	if (typeid(*redoSel) == typeid(MapCenterObj)  ) 
    1.51 +	{
    1.52 +		undoSelection.clear();
    1.53 +		// save the selected branch of the map, Undo will insert part of map 
    1.54 +		saveState (PartOfMap,
    1.55 +			undoSelection, QString("addMapInsert (\"PATH\")"),
    1.56 +			redoSelection, "delete ()", 
    1.57 +			comment, 
    1.58 +			redoSel);
    1.59 +	}
    1.60  }
    1.61  
    1.62  
    1.63 @@ -611,21 +628,26 @@
    1.64  	/////////////////////////////////////////////////////////////////////
    1.65  	} else if (com==QString("addMapInsert"))
    1.66  	{
    1.67 -		if (xelection.isEmpty())
    1.68 +		if (parser.parCount()==2)
    1.69  		{
    1.70 -			parser.setError (Aborted,"Nothing selected");
    1.71 -		} else if (! selb )
    1.72 -		{				  
    1.73 -			parser.setError (Aborted,"Type of selection is not a branch");
    1.74 -		} else 
    1.75 -		{	
    1.76 -			if (parser.checkParCount(2))
    1.77 +			if (xelection.isEmpty())
    1.78 +			{
    1.79 +				parser.setError (Aborted,"Nothing selected");
    1.80 +			} else if (! selb )
    1.81 +			{				  
    1.82 +				parser.setError (Aborted,"Type of selection is not a branch");
    1.83 +			} else
    1.84  			{
    1.85  				t=parser.parString (ok,0);	// path to map
    1.86  				n=parser.parInt(ok,1);		// position
    1.87  				if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
    1.88 -				addMapInsertInt(t,n);	
    1.89 +				addMapInsertInt(t,n);
    1.90  			}
    1.91 +		} else if (parser.parCount ()==1)
    1.92 +		{
    1.93 +			t=parser.parString (ok,0);	// path to map
    1.94 +			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
    1.95 +			addMapInsertInt(t);	
    1.96  		}
    1.97  	/////////////////////////////////////////////////////////////////////
    1.98  	} else if (com=="clearFlags")
    1.99 @@ -2312,8 +2334,7 @@
   1.100  	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
   1.101  
   1.102  	// select  object before undo
   1.103 -	if (!undoSelection.isEmpty())
   1.104 -		select (undoSelection);
   1.105 +	select (undoSelection);
   1.106  
   1.107  	if (debug)
   1.108  	{
   1.109 @@ -2430,40 +2451,56 @@
   1.110  		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   1.111  }
   1.112  
   1.113 -void MapEditor::addMapInsertInt (const QString &path, int pos)
   1.114 +bool MapEditor::addMapInsertInt (const QString &path)
   1.115 +{
   1.116 +	QString pathDir=path.left(path.findRev("/"));
   1.117 +	QDir d(pathDir);
   1.118 +	QFile file (path);
   1.119 +
   1.120 +	if (d.exists() )
   1.121 +	{
   1.122 +		// We need to parse saved XML data
   1.123 +		parseVYMHandler handler;
   1.124 +		QXmlInputSource source( file);
   1.125 +		QXmlSimpleReader reader;
   1.126 +		reader.setContentHandler( &handler );
   1.127 +		reader.setErrorHandler( &handler );
   1.128 +		handler.setModel (model);
   1.129 +		handler.setTmpDir ( pathDir );	// needed to load files with rel. path
   1.130 +		handler.setLoadMode (ImportAdd);
   1.131 +		blockReposition=true;
   1.132 +		bool ok = reader.parse( source );
   1.133 +		blockReposition=false;
   1.134 +		if ( ok ) return true;	
   1.135 +
   1.136 +		// This should never ever happen
   1.137 +		QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
   1.138 +								handler.errorProtocol());
   1.139 +	} else	
   1.140 +		QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   1.141 +	return false;	
   1.142 +}
   1.143 +
   1.144 +bool MapEditor::addMapInsertInt (const QString &path, int pos)
   1.145  {
   1.146  	BranchObj *sel=xelection.getBranch();
   1.147  	if (sel)
   1.148  	{
   1.149 -		QString pathDir=path.left(path.findRev("/"));
   1.150 -		QDir d(pathDir);
   1.151 -		QFile file (path);
   1.152 -
   1.153 -		if (d.exists() )
   1.154 +		if (addMapInsertInt (path))
   1.155  		{
   1.156 -			// We need to parse saved XML data
   1.157 -			parseVYMHandler handler;
   1.158 -			QXmlInputSource source( file);
   1.159 -			QXmlSimpleReader reader;
   1.160 -			reader.setContentHandler( &handler );
   1.161 -			reader.setErrorHandler( &handler );
   1.162 -			handler.setModel (model);
   1.163 -			handler.setTmpDir ( pathDir );	// needed to load files with rel. path
   1.164 -			handler.setLoadMode (ImportAdd);
   1.165 -			blockReposition=true;
   1.166 -			bool ok = reader.parse( source );
   1.167 -			blockReposition=false;
   1.168 -			if (! ok ) 
   1.169 -			{	
   1.170 -				// This should never ever happen
   1.171 -				QMessageBox::critical( 0, tr( "Critical Parse Error while reading %1").arg(path),
   1.172 -										handler.errorProtocol());
   1.173 +			{
   1.174 +				if (sel->getDepth()>0)
   1.175 +					sel->getLastBranch()->linkTo (sel,pos);
   1.176  			}
   1.177 -			if (sel->getDepth()>0)
   1.178 -				sel->getLastBranch()->linkTo (sel,pos);
   1.179 +			return true;
   1.180  		} else	
   1.181 +		{
   1.182  			QMessageBox::critical( 0, tr( "Critical Error" ), tr("Could not read %1").arg(path));
   1.183 +			return false;
   1.184 +		}	
   1.185  	}		
   1.186 +	qWarning ("ME::addMapInsertInt nothing selected");
   1.187 +	return false;
   1.188  }
   1.189  
   1.190  void MapEditor::pasteNoSave(const int &n)
   1.191 @@ -2828,11 +2865,8 @@
   1.192  	BranchObj *bo = xelection.getBranch();
   1.193  	if (bo && xelection.type()==Selection::MapCenter)
   1.194  	{
   1.195 -	//	BranchObj* par=(BranchObj*)(bo->getParObj());
   1.196  		xelection.unselect();
   1.197 -	/* FIXME Note:  does saveStateRemovingPart work for MCO? (No parent!)
   1.198  		saveStateRemovingPart (bo, QString ("Delete %1").arg(getName(bo)));
   1.199 -		*/
   1.200  		bo=model->removeMapCenter ((MapCenterObj*)bo);
   1.201  		if (bo) 
   1.202  		{
   1.203 @@ -2852,7 +2886,6 @@
   1.204  		xelection.select (par);
   1.205  		ensureSelectionVisible();
   1.206  		model->reposition();
   1.207 -//		xelection.update();
   1.208  		xelection.update();
   1.209  		return;
   1.210  	}