mapeditor.cpp
changeset 625 22955004d512
parent 616 16d63fc9ae42
child 628 d7d0708b1c60
     1.1 --- a/mapeditor.cpp	Fri Nov 09 12:07:21 2007 +0000
     1.2 +++ b/mapeditor.cpp	Fri Nov 09 12:07:22 2007 +0000
     1.3 @@ -159,6 +159,10 @@
     1.4  {
     1.5  	//cout <<"Destructor MapEditor\n";
     1.6  	autosaveTimer->stop();
     1.7 +
     1.8 +	// tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes
     1.9 +	
    1.10 +	//removeDir(QDir(tmpMapDir));
    1.11  }
    1.12  
    1.13  MapCenterObj* MapEditor::getMapCenter()
    1.14 @@ -227,8 +231,8 @@
    1.15  void MapEditor::makeTmpDirs()
    1.16  {
    1.17  	// Create unique temporary directories
    1.18 -	tmpMapDir=QDir::convertSeparators (tmpVymDir+QString("/mapeditor-%1").arg(mapNum));
    1.19 -	histPath=QDir::convertSeparators (tmpMapDir+"/history");
    1.20 +	tmpMapDir = tmpVymDir+QString("/mapeditor-%1").arg(mapNum);
    1.21 +	histPath = tmpMapDir+"/history";
    1.22  	QDir d;
    1.23  	d.mkdir (tmpMapDir);
    1.24  }
    1.25 @@ -317,8 +321,8 @@
    1.26  
    1.27  QString MapEditor::getHistoryDir()
    1.28  {
    1.29 -	QString histName=QDir::convertSeparators (QString("history-%1").arg(curStep));
    1.30 -	return QDir::convertSeparators (tmpMapDir +"/"+histName);
    1.31 +	QString histName(QString("history-%1").arg(curStep));
    1.32 +	return (tmpMapDir+"/"+histName);
    1.33  }
    1.34  
    1.35  void MapEditor::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, LinkableMapObj *saveSel)
    1.36 @@ -339,7 +343,7 @@
    1.37  	
    1.38  	QString backupXML="";
    1.39  	QString histDir=getHistoryDir();
    1.40 -	QString bakMapPath=QDir::convertSeparators(histDir+"/map.xml");
    1.41 +	QString bakMapPath=histDir+"/map.xml";
    1.42  
    1.43  	// Create histDir if not available
    1.44  	QDir d(histDir);
    1.45 @@ -363,7 +367,7 @@
    1.46  
    1.47  	if (!backupXML.isEmpty())
    1.48  		// Write XML Data to disk
    1.49 -		saveStringToDisk (QString(bakMapPath),backupXML);
    1.50 +		saveStringToDisk (bakMapPath,backupXML);
    1.51  
    1.52  	// We would have to save all actions in a tree, to keep track of 
    1.53  	// possible redos after a action. Possible, but we are too lazy: forget about redos.
    1.54 @@ -545,7 +549,7 @@
    1.55  		{
    1.56  			//s=parser.parString (ok,0);	// selection
    1.57  			t=parser.parString (ok,0);	// path to map
    1.58 -			if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
    1.59 +			if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
    1.60  			addMapReplaceInt(selb->getSelectString(),t);	
    1.61  		}
    1.62  	/////////////////////////////////////////////////////////////////////
    1.63 @@ -563,7 +567,7 @@
    1.64  			{
    1.65  				t=parser.parString (ok,0);	// path to map
    1.66  				n=parser.parInt(ok,1);		// position
    1.67 -				if (QDir::isRelativePath(t)) t=QDir::convertSeparators (tmpMapDir + "/"+t);
    1.68 +				if (QDir::isRelativePath(t)) t=(tmpMapDir + "/"+t);
    1.69  				addMapInsertInt(t,n);	
    1.70  			}
    1.71  		}
    1.72 @@ -1952,8 +1956,8 @@
    1.73  		}
    1.74  
    1.75  		// Copy also to global clipboard, because we are at last step in history
    1.76 -		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
    1.77 -		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
    1.78 +		QString bakMapName(QString("history-%1").arg(curStep));
    1.79 +		QString bakMapDir(tmpMapDir +"/"+bakMapName);
    1.80  		copyDir (bakMapDir,clipboardDir );
    1.81  
    1.82  		clipboardEmpty=false;
    1.83 @@ -1987,7 +1991,7 @@
    1.84  
    1.85  
    1.86  	// Find out current undo directory
    1.87 -	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
    1.88 +	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
    1.89  
    1.90  	if (debug)
    1.91  	{
    1.92 @@ -2063,7 +2067,7 @@
    1.93  			tr("Version %1 of saved undo/redo data\ndoes not match current vym version %2.").arg(version).arg(vymVersion));
    1.94  
    1.95  	// Find out current undo directory
    1.96 -	QString bakMapDir=QDir::convertSeparators (QString(tmpMapDir+"/undo-%1").arg(curStep));
    1.97 +	QString bakMapDir(QString(tmpMapDir+"/undo-%1").arg(curStep));
    1.98  
    1.99  	// select  object before undo
   1.100  	if (!undoSelection.isEmpty())
   1.101 @@ -2227,8 +2231,8 @@
   1.102  	if (redosAvail > 0 || n!=0)
   1.103  	{
   1.104  		// Use the "historical" buffer
   1.105 -		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
   1.106 -		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
   1.107 +		QString bakMapName(QString("history-%1").arg(n));
   1.108 +		QString bakMapDir(tmpMapDir +"/"+bakMapName);
   1.109  		load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap);
   1.110  	} else
   1.111  		// Use the global buffer
   1.112 @@ -2278,17 +2282,21 @@
   1.113  	LinkableMapObj *sel=xelection.single();
   1.114  	if (sel)
   1.115  	{
   1.116 -		QString ps=qpointfToString (sel->getAbsPos());
   1.117 -		QString s=xelection.single()->getSelectString();
   1.118 -		saveState(
   1.119 -			s, "move "+ps, 
   1.120 -			s, "move "+qpointfToString (QPointF (x,y)), 
   1.121 -			QString("Move %1 to  %2").arg(getName(sel)).arg(ps));
   1.122 -		sel->move(x,y);
   1.123 -		mapCenter->reposition();
   1.124 -		xelection.update();
   1.125 +        QPointF ap(sel->getAbsPos());
   1.126 +        QPointF to(x, y);
   1.127 +        if (ap != to)
   1.128 +        {
   1.129 +            QString ps=qpointfToString(ap);
   1.130 +            QString s=xelection.single()->getSelectString();
   1.131 +            saveState(
   1.132 +                s, "move "+ps, 
   1.133 +                s, "move "+qpointfToString(to), 
   1.134 +                QString("Move %1 to %2").arg(getName(sel)).arg(ps));
   1.135 +            sel->move(x,y);
   1.136 +            mapCenter->reposition();
   1.137 +            xelection.update();
   1.138 +        }
   1.139  	}
   1.140 -
   1.141  }
   1.142  
   1.143  void MapEditor::moveRel (const double &x, const double &y)
   1.144 @@ -2296,16 +2304,21 @@
   1.145  	LinkableMapObj *sel=xelection.single();
   1.146  	if (sel)
   1.147  	{
   1.148 -		QString ps=qpointfToString (sel->getRelPos());
   1.149 -		QString s=sel->getSelectString();
   1.150 -		saveState(
   1.151 -			s, "moveRel "+ps, 
   1.152 -			s, "moveRel "+qpointfToString (QPointF (x,y)), 
   1.153 -			QString("Move %1 to relativ position %2").arg(getName(sel)).arg(ps));
   1.154 -		((OrnamentedObj*)sel)->move2RelPos (x,y);
   1.155 -		mapCenter->reposition();
   1.156 -		sel->updateLink();
   1.157 -		xelection.update();
   1.158 +        QPointF rp(sel->getRelPos());
   1.159 +        QPointF to(x, y);
   1.160 +        if (rp != to)
   1.161 +        {
   1.162 +            QString ps=qpointfToString (sel->getRelPos());
   1.163 +            QString s=sel->getSelectString();
   1.164 +            saveState(
   1.165 +                s, "moveRel "+ps, 
   1.166 +                s, "moveRel "+qpointfToString(to), 
   1.167 +                QString("Move %1 to relative position %2").arg(getName(sel)).arg(ps));
   1.168 +            ((OrnamentedObj*)sel)->move2RelPos (x,y);
   1.169 +            mapCenter->reposition();
   1.170 +            sel->updateLink();
   1.171 +            xelection.update();
   1.172 +        }
   1.173  	}
   1.174  }
   1.175  
   1.176 @@ -4452,7 +4465,7 @@
   1.177  						"moveRel "+pold,
   1.178  						fio,
   1.179  						"moveRel "+pnow,
   1.180 -						QString("Move %1 to relativ position %2").arg(getName(fio)).arg(pnow));
   1.181 +						QString("Move %1 to relative position %2").arg(getName(fio)).arg(pnow));
   1.182  					fio->getParObj()->requestReposition();
   1.183  					mapCenter->reposition();
   1.184  
   1.185 @@ -4596,7 +4609,7 @@
   1.186  				"moveRel "+pold,
   1.187  				fo,
   1.188  				"moveRel "+pnow,
   1.189 -				QString("Move %1 to relativ position %2").arg(getName(fo)).arg(pnow));
   1.190 +				QString("Move %1 to relative position %2").arg(getName(fo)).arg(pnow));
   1.191  
   1.192  			fo->getParObj()->requestReposition();
   1.193  			mapCenter->reposition();
   1.194 @@ -4613,16 +4626,19 @@
   1.195  		{	
   1.196  			// TODO: Check for problems if graphicsview is resized for 
   1.197  			// undo/redo...
   1.198 -		    QString pold=qpointfToString(movingObj_orgPos);
   1.199 -		    QString pnow=qpointfToString(mapCenter->getAbsPos());
   1.200 -			saveState(
   1.201 -				fo,
   1.202 -				"move "+pold,
   1.203 -				fo,
   1.204 -				"move "+pnow,
   1.205 -				QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
   1.206 +            if (movingObj_orgPos != mapCenter->getAbsPos())
   1.207 +            {
   1.208 +                QString pold=qpointfToString(movingObj_orgPos);
   1.209 +                QString pnow=qpointfToString(mapCenter->getAbsPos());
   1.210 +                saveState(
   1.211 +                    fo,
   1.212 +                    "move "+pold,
   1.213 +                    fo,
   1.214 +                    "move "+pnow,
   1.215 +                    QString("Move mapcenter %1 to position %2").arg(getName(mapCenter)).arg(pnow));
   1.216 +            }
   1.217  		}
   1.218 -		
   1.219 +
   1.220  		if (xelection.type() == Selection::Branch )
   1.221  		{	// A branch was moved
   1.222  			
   1.223 @@ -4683,12 +4699,15 @@
   1.224  					// Therefor reposition and then use string of old selection, too
   1.225  					mapCenter->reposition();
   1.226  
   1.227 -					QString ps=qpointfToString ( lmosel->getRelPos() );
   1.228 -					saveState(
   1.229 -						lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
   1.230 -						preSelStr, "moveRel "+ps, 
   1.231 -						QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
   1.232 -			
   1.233 +                    QPointF rp(lmosel->getRelPos());
   1.234 +                    if (rp != movingObj_orgRelPos)
   1.235 +                    {
   1.236 +                        QString ps=qpointfToString(rp);
   1.237 +                        saveState(
   1.238 +                            lmosel->getSelectString(), "moveRel "+qpointfToString(movingObj_orgRelPos), 
   1.239 +                            preSelStr, "moveRel "+ps, 
   1.240 +                            QString("Move %1 to relative position %2").arg(getName(lmosel)).arg(ps));
   1.241 +                    }
   1.242  				}
   1.243  			// Draw the original link, before selection was moved around
   1.244  			mapCenter->reposition();
   1.245 @@ -4788,7 +4807,7 @@
   1.246  						s=uris.at(i).toLocalFile();
   1.247  						if (!s.isEmpty()) 
   1.248  						{
   1.249 -						   QString file = QDir::convertSeparators(s);
   1.250 +						   QString file = QDir::fromNativeSeparators(s);
   1.251  						   heading = QFileInfo(file).baseName();
   1.252  						   files.append(file);
   1.253  						   if (file.endsWith(".vym", false))