xml-vym.cpp
changeset 647 bef71af3f6ab
parent 611 a1ae877b438d
child 652 700553af9ca5
     1.1 --- a/xml-vym.cpp	Mon Jan 14 16:26:59 2008 +0000
     1.2 +++ b/xml-vym.cpp	Mon Jan 14 16:27:00 2008 +0000
     1.3 @@ -68,6 +68,8 @@
     1.4      if ( state == StateInit && (eName == "vymmap")  ) 
     1.5  	{
     1.6          state = StateMap;
     1.7 +
     1.8 +		// Check version
     1.9  		if (!atts.value( "version").isEmpty() ) 
    1.10  		{
    1.11  			if (!checkVersion(atts.value("version")))
    1.12 @@ -79,55 +81,51 @@
    1.13  				   ". If you run into problems after pressing "
    1.14  				   "the ok-button below, updating vym should help.");
    1.15  			else	   
    1.16 -				mc->setVersion(atts.value( "version" ));
    1.17 +				model->setVersion(atts.value( "version" ));
    1.18  
    1.19  		}
    1.20 -		if (loadMode==NewMap || 
    1.21 -			(loadMode==ImportReplace && me->getSelection()==mc))
    1.22 +
    1.23 +		if (loadMode==NewMap )
    1.24  		{
    1.25 +			// Create mapCenter
    1.26 +			model->clear();
    1.27 +			lastBranch=model->first();	// avoid empty pointer
    1.28 +
    1.29  			if (!atts.value( "author").isEmpty() )
    1.30 -			{
    1.31 -				mc->setAuthor(atts.value( "author" ) );
    1.32 -			}
    1.33 +				model->setAuthor(atts.value( "author" ) );
    1.34  			if (!atts.value( "comment").isEmpty() )
    1.35 -			{
    1.36 -				mc->setComment (atts.value( "comment" ) );
    1.37 -			}
    1.38 +				model->setComment (atts.value( "comment" ) );
    1.39  			if (!atts.value( "backgroundColor").isEmpty() )
    1.40  			{
    1.41  				col.setNamedColor(atts.value("backgroundColor"));
    1.42 -				mc->getScene()->setBackgroundBrush(col);
    1.43 +				model->getScene()->setBackgroundBrush(col);
    1.44  			}	    
    1.45  			if (!atts.value( "selectionColor").isEmpty() )
    1.46  			{
    1.47  				col.setNamedColor(atts.value("selectionColor"));
    1.48 -				me->setSelectionColor(col);
    1.49 +				model->getMapEditor()->setSelectionColor(col);
    1.50  			}	    
    1.51  			if (!atts.value( "linkColorHint").isEmpty() ) 
    1.52  			{
    1.53  				if (atts.value("linkColorHint")=="HeadingColor")
    1.54 -					me->setMapLinkColorHint(LinkableMapObj::HeadingColor);
    1.55 +					model->getMapEditor()->setMapLinkColorHint(LinkableMapObj::HeadingColor);
    1.56  				else
    1.57 -					me->setMapLinkColorHint(LinkableMapObj::DefaultColor);
    1.58 +					model->getMapEditor()->setMapLinkColorHint(LinkableMapObj::DefaultColor);
    1.59  			}
    1.60  			if (!atts.value( "linkStyle").isEmpty() ) 
    1.61 -			{
    1.62 -				me->setMapLinkStyle(atts.value("linkStyle"));
    1.63 -			}	
    1.64 +				model->getMapEditor()->setMapLinkStyle(atts.value("linkStyle"));
    1.65  			if (!atts.value( "linkColor").isEmpty() ) 
    1.66  			{
    1.67  				col.setNamedColor(atts.value("linkColor"));
    1.68 -				me->setMapDefLinkColor(col);
    1.69 +				model->getMapEditor()->setMapDefLinkColor(col);
    1.70  			}	
    1.71  			if (!atts.value( "defXLinkColor").isEmpty() ) 
    1.72  			{
    1.73  				col.setNamedColor(atts.value("defXLinkColor"));
    1.74 -				me->setMapDefXLinkColor(col);
    1.75 +				model->getMapEditor()->setMapDefXLinkColor(col);
    1.76  			}	
    1.77  			if (!atts.value( "defXLinkWidth").isEmpty() ) 
    1.78 -			{
    1.79 -				me->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
    1.80 -			}	
    1.81 +				model->getMapEditor()->setMapDefXLinkWidth(atts.value("defXLinkWidth").toInt ());
    1.82  		}	
    1.83  	} else if ( eName == "select" && state == StateMap ) 
    1.84  	{
    1.85 @@ -143,12 +141,15 @@
    1.86  		if (loadMode==NewMap)
    1.87  		{	
    1.88  			// Really use the found mapcenter as MCO in a new map
    1.89 -			lastBranch=mc;	// avoid empty pointer
    1.90 +
    1.91 +			// FIXME not working for multiple mapCenters yet:
    1.92 +			lastBranch=model->addMapCenter();
    1.93 +			//lastBranch=model->first();	// avoid empty pointer
    1.94  		} else
    1.95  		{
    1.96  			// Treat the found mapcenter as a branch 
    1.97  			// in an existing map
    1.98 -			LinkableMapObj* lmo=me->getSelection();
    1.99 +			LinkableMapObj* lmo=model->getSelection();
   1.100  			if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
   1.101  			        || (typeid(*lmo) == typeid(MapCenterObj) ) )
   1.102  			{
   1.103 @@ -197,14 +198,14 @@
   1.104  	{
   1.105  		// This is used in vymparts, which have no mapcenter!
   1.106  		isVymPart=true;
   1.107 -		LinkableMapObj* lmo=me->getSelection();
   1.108 +		LinkableMapObj* lmo=model->getSelection();
   1.109  		if (!lmo)
   1.110  		{
   1.111  			// If a vym part is _loaded_ (not imported), 
   1.112  			// selection==lmo==NULL
   1.113  			// Treat it like ImportAdd then...
   1.114  			loadMode=ImportAdd;
   1.115 -			lmo=mc;
   1.116 +			lmo=model->first();		// FIXME this used to be lmo=mc before
   1.117  		}	
   1.118  		if (lmo && (typeid(*lmo) == typeid(BranchObj) ) 
   1.119  				|| (typeid(*lmo) == typeid(MapCenterObj) ) )
   1.120 @@ -320,7 +321,7 @@
   1.121          case StateInit: break;
   1.122          case StateMap: break; 
   1.123  		case StateMapSelect:
   1.124 -			me->select(ch_simplified);
   1.125 +			model->select(ch_simplified);
   1.126  			break;
   1.127  		case StateMapSetting:break;
   1.128          case StateMapCenter: break;
   1.129 @@ -539,7 +540,7 @@
   1.130  				{
   1.131  					lastFloat->setRelPos (QPointF (x,y) );
   1.132  					// make sure floats in mapcenter are repositioned to relative pos
   1.133 -					if (mc==lastBranch) mc->positionContents();
   1.134 +					if (lastBranch->getDepth()==0) lastBranch->positionContents();
   1.135  				}
   1.136  			else
   1.137  				// Couldn't read relPos
   1.138 @@ -561,7 +562,7 @@
   1.139  	QColor col;
   1.140  	bool okx;
   1.141  	bool success=false;
   1.142 -	XLinkObj *xlo=new XLinkObj (mc->getScene());
   1.143 +	XLinkObj *xlo=new XLinkObj (model->getScene());
   1.144  	if (!a.value( "color").isEmpty() ) 
   1.145  	{
   1.146  		col.setNamedColor(a.value("color"));
   1.147 @@ -578,11 +579,11 @@
   1.148  	{ 
   1.149  		if (!a.value( "endBranch").isEmpty() ) 
   1.150  		{
   1.151 -			LinkableMapObj *lmo=mc->findObjBySelect (a.value( "beginBranch"));
   1.152 +			LinkableMapObj *lmo=model->findObjBySelect (a.value( "beginBranch"));
   1.153  			if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.154  			{
   1.155  				xlo->setBegin ((BranchObj*)lmo);
   1.156 -				lmo=mc->findObjBySelect (a.value( "endBranch"));
   1.157 +				lmo=model->findObjBySelect (a.value( "endBranch"));
   1.158  				if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.159  				{
   1.160  					xlo->setEnd ((BranchObj*)(lmo));
   1.161 @@ -598,11 +599,11 @@
   1.162  	{ 
   1.163  		if (!a.value( "endID").isEmpty() ) 
   1.164  		{
   1.165 -			LinkableMapObj *lmo=mc->findID (a.value( "beginID"));
   1.166 +			LinkableMapObj *lmo=model->findID (a.value( "beginID"));
   1.167  			if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.168  			{
   1.169  				xlo->setBegin ((BranchObj*)lmo);
   1.170 -				lmo=mc->findID (a.value( "endID"));
   1.171 +				lmo=model->findID (a.value( "endID"));
   1.172  				if (lmo && typeid (*lmo)==typeid (BranchObj))
   1.173  				{
   1.174  					xlo->setEnd ((BranchObj*)(lmo));
   1.175 @@ -628,7 +629,7 @@
   1.176  	if (!a.value( "key").isEmpty() ) 
   1.177  	{
   1.178  		if (!a.value( "value").isEmpty() ) 
   1.179 -			settings.setLocalEntry (me->getDestPath(), a.value ("key"), a.value ("value"));
   1.180 +			settings.setLocalEntry (model->getMapEditor()->getDestPath(), a.value ("key"), a.value ("value"));
   1.181  		else
   1.182  			return false;
   1.183