vymmodel.cpp
changeset 848 e265f07f2173
parent 847 43268373032d
     1.1 --- a/vymmodel.cpp	Wed Jun 09 13:14:08 2010 +0000
     1.2 +++ b/vymmodel.cpp	Mon Jun 14 13:59:17 2010 +0000
     1.3 @@ -85,20 +85,14 @@
     1.4  	// Also no scene yet (should not be needed anyway)  FIXME-3 VM
     1.5  	mapScene=NULL;
     1.6  
     1.7 -	// History 
     1.8 +	// States and IDs
     1.9  	idLast++;
    1.10  	mapID=idLast;
    1.11      mapChanged=false;
    1.12  	mapDefault=true;
    1.13  	mapUnsaved=false;
    1.14  
    1.15 -	curStep=0;
    1.16 -	redosAvail=0;
    1.17 -	undosAvail=0;
    1.18 -
    1.19 - 	stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
    1.20 -	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
    1.21 -	mainWindow->updateHistory (undoSet);
    1.22 +	resetHistory();
    1.23  
    1.24  	// Create tmp dirs
    1.25  	makeTmpDirectories();
    1.26 @@ -516,6 +510,8 @@
    1.27  
    1.28  				// Reset timestamp to check for later updates of file
    1.29  				fileChangedTime=QFileInfo (destPath).lastModified();
    1.30 +
    1.31 +				resetHistory();
    1.32  			}
    1.33  
    1.34  	
    1.35 @@ -1062,7 +1058,7 @@
    1.36  		return false;
    1.37  }
    1.38  
    1.39 -void VymModel::undo()	//FIXME-1 segfault when trying to undo in a brandnew map
    1.40 +void VymModel::undo()	
    1.41  {
    1.42  	// Can we undo at all?
    1.43  	if (undosAvail<1) return;
    1.44 @@ -1180,6 +1176,17 @@
    1.45  	return (tmpMapDir+"/"+histName);
    1.46  }
    1.47  
    1.48 +void VymModel::resetHistory()
    1.49 +{
    1.50 +	curStep=0;
    1.51 +	redosAvail=0;
    1.52 +	undosAvail=0;
    1.53 +
    1.54 + 	stepsTotal=settings.readNumEntry("/history/stepsTotal",100);
    1.55 +	undoSet.setEntry ("/history/stepsTotal",QString::number(stepsTotal));
    1.56 +	mainWindow->updateHistory (undoSet);
    1.57 +}
    1.58 +
    1.59  void VymModel::saveState(const SaveMode &savemode, const QString &undoSelection, const QString &undoCom, const QString &redoSelection, const QString &redoCom, const QString &comment, TreeItem *saveSel)
    1.60  {
    1.61  	sendData(redoCom);	//FIXME-3 testing
    1.62 @@ -1732,9 +1739,9 @@
    1.63  			QString ("setURL (\"%1\")").arg(url),
    1.64  			QString ("set URL of %1 to %2").arg(getObjectName(selti)).arg(url)
    1.65  		);
    1.66 +		emitDataHasChanged (selti);
    1.67  		reposition();
    1.68 -		emitDataHasChanged (selti);
    1.69 -		emitShowSelection();
    1.70 +		emitSelectionChanged();
    1.71  	}
    1.72  }	
    1.73  
    1.74 @@ -2274,12 +2281,12 @@
    1.75  	return NULL;
    1.76  }
    1.77  
    1.78 -BranchItem* VymModel::addMapCenter ()
    1.79 +BranchItem* VymModel::addMapCenter (bool saveStateFlag)
    1.80  {
    1.81  	BranchItem *bi=addMapCenter (contextPos);
    1.82  	updateActions();
    1.83  	emitShowSelection();
    1.84 -	saveState (
    1.85 +	if (saveStateFlag) saveState (
    1.86  		bi,
    1.87  		"delete()",
    1.88  		NULL,
    1.89 @@ -3279,9 +3286,8 @@
    1.90  		} else
    1.91  			parser.setError (Aborted,"Wrong number of parameters");
    1.92  	/////////////////////////////////////////////////////////////////////
    1.93 -	} else if (com==QString("addXLink"))  //FIXME-2 not ported yet to Link
    1.94 -	{
    1.95 -	/*
    1.96 +	} else if (com==QString("addXLink")) 
    1.97 +	{
    1.98  		if (parser.parCount()>1)
    1.99  		{
   1.100  			s=parser.parString (ok,0);	// begin
   1.101 @@ -3292,13 +3298,11 @@
   1.102  			{
   1.103  				if (begin->isBranchLikeType() && end->isBranchLikeType())
   1.104  				{
   1.105 -					XLinkItem *xl=createXLink (begin,true);
   1.106 -					if (xl)
   1.107 -					{
   1.108 -						xl->setEnd (end);
   1.109 -						xl->activate();
   1.110 -					} else
   1.111 -						parser.setError (Aborted,"Failed to create xLink");
   1.112 +					Link *li=new Link (this);
   1.113 +					li->setBeginBranch ( (BranchItem*)begin );
   1.114 +					li->setEndBranch ( (BranchItem*)end);
   1.115 +
   1.116 +					createLink (li,true);	// create MO by default
   1.117  				}
   1.118  				else
   1.119  					parser.setError (Aborted,"begin or end of xLink are not branch or mapcenter");
   1.120 @@ -3307,7 +3311,6 @@
   1.121  				parser.setError (Aborted,"Couldn't select begin or end of xLink");
   1.122  		} else
   1.123  			parser.setError (Aborted,"Need at least 2 parameters for begin and end");
   1.124 -	*/		
   1.125  	/////////////////////////////////////////////////////////////////////
   1.126  	} else if (com=="clearFlags")	
   1.127  	{
   1.128 @@ -3319,7 +3322,11 @@
   1.129  			parser.setError (Aborted,"Type of selection is not a branch");
   1.130  		} else if (parser.checkParCount(0))
   1.131  		{
   1.132 -			selbi->deactivateAllStandardFlags();	//FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
   1.133 +			selbi->deactivateAllStandardFlags();
   1.134 +			reposition();
   1.135 +			emitDataHasChanged(selbi);
   1.136 +			emitSelectionChanged();
   1.137 +			setChanged();
   1.138  		}
   1.139  	/////////////////////////////////////////////////////////////////////
   1.140  	} else if (com=="colorBranch")
   1.141 @@ -5156,6 +5163,21 @@
   1.142  	return false;
   1.143  }
   1.144  
   1.145 +bool VymModel::selectLastImage()	
   1.146 +{
   1.147 +	TreeItem *ti=getSelectedBranch();
   1.148 +	if (ti)
   1.149 +	{
   1.150 +		TreeItem *par=ti->parent();
   1.151 +		if (par) 
   1.152 +		{
   1.153 +			TreeItem *ti2=par->getLastImage();
   1.154 +			if (ti2) return select(ti2);
   1.155 +		}
   1.156 +	}		
   1.157 +	return false;
   1.158 +}
   1.159 +
   1.160  bool VymModel::selectParent()
   1.161  {
   1.162  	TreeItem *ti=getSelectedItem();