xml-vym.cpp
changeset 847 43268373032d
parent 841 46553c106c52
     1.1 --- a/xml-vym.cpp	Fri Apr 09 14:24:04 2010 +0000
     1.2 +++ b/xml-vym.cpp	Wed Jun 09 13:14:08 2010 +0000
     1.3 @@ -146,9 +146,15 @@
     1.4  				lastBranch=bi;
     1.5  				if (loadMode==ImportAdd)
     1.6  				{
     1.7 +					// Import Add
     1.8  					lastBranch=model->createBranch(lastBranch);
     1.9 -				} //else
    1.10 -					model->clearItem(lastBranch); 
    1.11 +				} else  
    1.12 +				{
    1.13 +					// Import Replace 
    1.14 +					// Parser should not be called with ImportReplace any longer,
    1.15 +					// that's done in VymModel now.
    1.16 +					qDebug()<<"xml-vym:  ImportReplace  ?!"; 
    1.17 +				}
    1.18  			} else
    1.19  				// add mapCenter without parent
    1.20  				lastBranch=model->createMapCenter(); 
    1.21 @@ -208,6 +214,8 @@
    1.22  				if (loadMode==ImportAdd)
    1.23  				{
    1.24  					lastBranch=model->createBranch(lastBranch);
    1.25 +					if (insertPos>=0)
    1.26 +						model->relinkBranch (lastBranch,(BranchItem*)ti,insertPos);
    1.27  				} else
    1.28  					model->clearItem (lastBranch);
    1.29  				readBranchAttr (atts);
    1.30 @@ -239,6 +247,10 @@
    1.31  	{
    1.32  		state=StateBranchXLink;
    1.33  		if (!readXLinkAttr (atts)) return false;
    1.34 +    } else if ( eName == "xlink" && state == StateMap) 
    1.35 +	{
    1.36 +		state=StateLink;
    1.37 +		if (!readLinkNewAttr (atts)) return false;
    1.38      } else if ( eName == "branch" && state == StateBranch ) 
    1.39  	{
    1.40  		lastBranch=model->createBranch(lastBranch);
    1.41 @@ -545,10 +557,17 @@
    1.42  	return true;
    1.43  }
    1.44  
    1.45 -bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a)	
    1.46 +bool parseVYMHandler::readXLinkAttr (const QXmlAttributes& a) 
    1.47  {
    1.48 +	// Format of links was changed several times:
    1.49 +	//
    1.50  	// object ID is used starting in version 1.8.76
    1.51  	// (before there was beginBranch and endBranch)
    1.52 +	//
    1.53 +	// Starting in 1.13.2 xlinks are no longer subitems of branches,
    1.54 +	// but listed at the end of the data in a map. This make handling 
    1.55 +	// of links much safer and easier
    1.56 +
    1.57  	if (!a.value( "beginID").isEmpty() ) 
    1.58  	{ 
    1.59  		if (!a.value( "endID").isEmpty() ) 
    1.60 @@ -557,28 +576,66 @@
    1.61  			TreeItem   *endBI=model->findBySelectString (a.value( "endID"));
    1.62  			if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() )
    1.63  			{
    1.64 -				XLinkItem *xli=model->createXLink (lastBranch,true);
    1.65 -				xli->setBegin ( (BranchItem*)beginBI );
    1.66 -				xli->setEnd ( (BranchItem*)endBI);
    1.67 -				xli->activate();
    1.68 +				Link *li=new Link (model);
    1.69 +				li->setBeginBranch ( (BranchItem*)beginBI );
    1.70 +				li->setEndBranch ( (BranchItem*)endBI);
    1.71  
    1.72  				if (!a.value( "color").isEmpty() ) 
    1.73  				{
    1.74  					QColor col;
    1.75  					col.setNamedColor(a.value("color"));
    1.76 -					xli->setColor (col);
    1.77 +					li->setColor (col);
    1.78  				}
    1.79  
    1.80  				if (!a.value( "width").isEmpty() ) 
    1.81  				{
    1.82  					bool okx;
    1.83 -					xli->setWidth(a.value ("width").toInt (&okx, 10));
    1.84 +					li->setWidth(a.value ("width").toInt (&okx, 10));
    1.85  				}
    1.86 -				xli->updateXLink();
    1.87 +				model->createLink (li,true);	// create MO by default
    1.88  			}
    1.89  		}           
    1.90  	}	
    1.91 -	return true;	// xLinks can only be established at the "end branch", return true
    1.92 +	return true;	
    1.93 +}
    1.94 +
    1.95 +bool parseVYMHandler::readLinkNewAttr (const QXmlAttributes& a)	
    1.96 +{
    1.97 +	// object ID is used starting in version 1.8.76
    1.98 +	// (before there was beginBranch and endBranch)
    1.99 +
   1.100 +	// Beginning in 1.13.2 xLinks are no longer parts of branches, but
   1.101 +	// a separate list after all the mapCenters within <vymmap> ... </vymmap>
   1.102 +
   1.103 +	if (!a.value( "beginID").isEmpty() ) 
   1.104 +	{ 
   1.105 +		if (!a.value( "endID").isEmpty() ) 
   1.106 +		{
   1.107 +			TreeItem *beginBI=model->findBySelectString (a.value( "beginID"));
   1.108 +			TreeItem   *endBI=model->findBySelectString (a.value( "endID"));
   1.109 +			if (beginBI && endBI && beginBI->isBranchLikeType() && endBI->isBranchLikeType() )
   1.110 +			{
   1.111 +				Link *li=new Link (model);
   1.112 +				li->setBeginBranch ( (BranchItem*)beginBI );
   1.113 +				li->setEndBranch ( (BranchItem*)endBI);
   1.114 +
   1.115 +				if (!a.value( "color").isEmpty() ) 
   1.116 +				{
   1.117 +					QColor col;
   1.118 +					col.setNamedColor(a.value("color"));
   1.119 +					li->setColor (col);
   1.120 +				}
   1.121 +
   1.122 +				if (!a.value( "width").isEmpty() ) 
   1.123 +				{
   1.124 +					bool okx;
   1.125 +					li->setWidth(a.value ("width").toInt (&okx, 10));
   1.126 +				}
   1.127 +				model->createLink (li,true);	// create MO by default
   1.128 +			}
   1.129 +		}           
   1.130 +	}	
   1.131 +	return true;	
   1.132  }
   1.133  
   1.134  bool parseVYMHandler::readHtmlAttr (const QXmlAttributes& a)