xlinkobj.cpp
changeset 790 133e2ed6b9c5
parent 685 d788ebd97c45
child 847 43268373032d
     1.1 --- a/xlinkobj.cpp	Mon Aug 24 14:39:07 2009 +0000
     1.2 +++ b/xlinkobj.cpp	Thu Sep 03 08:52:00 2009 +0000
     1.3 @@ -1,31 +1,28 @@
     1.4  #include "xlinkobj.h"
     1.5 +
     1.6  #include "branchobj.h"
     1.7 +#include "branchitem.h"
     1.8 +#include "xlinkitem.h"
     1.9  
    1.10 +#include <iostream>
    1.11 +using namespace std;
    1.12  
    1.13  /////////////////////////////////////////////////////////////////
    1.14  // XLinkObj
    1.15  /////////////////////////////////////////////////////////////////
    1.16  
    1.17 -int XLinkObj::arrowSize=10;						// make instances 
    1.18 +int XLinkObj::arrowSize=10;					// make instances
    1.19  
    1.20 -XLinkObj::XLinkObj ():MapObj() 
    1.21 +XLinkObj::XLinkObj (QGraphicsScene* scene, TreeItem* ti):MapObj(scene,ti)
    1.22  {
    1.23 -	//	cout << "Const XLinkObj ()\n";
    1.24 +	//cout << "Const XLinkObj (s)\n";
    1.25  	init();
    1.26  }
    1.27  
    1.28 -XLinkObj::XLinkObj (QGraphicsScene* s):MapObj(s)
    1.29 -{
    1.30 -	//	cout << "Const XLinkObj (s)  called from MapCenterObj (s)\n";
    1.31 -	init();
    1.32 -}
    1.33 -
    1.34  
    1.35  XLinkObj::~XLinkObj ()
    1.36  {
    1.37 -//	cout << "Destr XLinkObj\n";
    1.38 -	if (xLinkState!=undefinedXLink)
    1.39 -		deactivate();
    1.40 +	//cout << "Destr XLinkObj\n";
    1.41  	delete (line);
    1.42  	delete (poly);
    1.43  }
    1.44 @@ -33,87 +30,17 @@
    1.45  
    1.46  void XLinkObj::init () 
    1.47  {
    1.48 -	beginBranch=NULL;
    1.49 -	endBranch=NULL;
    1.50 +	XLinkItem *xli=(XLinkItem*)treeItem;
    1.51  	visBranch=NULL;
    1.52 -	xLinkState=undefinedXLink;
    1.53  
    1.54 -	color=QColor (180,180,180);
    1.55 -	width=1;
    1.56 -	pen.setColor (color);
    1.57 -	pen.setWidth (width);
    1.58 +	pen.setColor ( xli->getColor() );
    1.59 +	pen.setWidth ( xli->getWidth() );
    1.60  	pen.setCapStyle (  Qt::RoundCap );
    1.61  	line=scene->addLine(QLineF(1,1,1,1),pen);
    1.62      line->setZValue (Z_XLINK);
    1.63 -	poly=scene->addPolygon(QPolygonF(),pen,color);
    1.64 +	poly=scene->addPolygon(QPolygonF(),pen, xli->getColor());
    1.65      poly->setZValue (Z_XLINK);
    1.66 -	setVisibility (false);
    1.67 -}
    1.68 -
    1.69 -void XLinkObj::copy (XLinkObj* other)
    1.70 -{
    1.71 -	// TODO copy not used yet
    1.72 -	MapObj::copy (other);
    1.73 -	setVisibility (other->visible);
    1.74 -	beginBranch=other->beginBranch;
    1.75 -	endBranch=other->endBranch;
    1.76 -	width=other->width;
    1.77 -
    1.78 -}
    1.79 -
    1.80 -void XLinkObj::setBegin (BranchObj *bo)
    1.81 -{
    1.82 -	if (bo) 
    1.83 -	{
    1.84 -		xLinkState=initXLink;
    1.85 -		beginBranch=bo;
    1.86 -		beginPos=beginBranch->getChildPos();
    1.87 -	}	
    1.88 -}
    1.89 -
    1.90 -BranchObj* XLinkObj::getBegin ()
    1.91 -{
    1.92 -	return beginBranch;
    1.93 -}
    1.94 -
    1.95 -void XLinkObj::setEnd (BranchObj *bo)
    1.96 -{
    1.97 -	if (bo) 
    1.98 -	{
    1.99 -		xLinkState=initXLink;
   1.100 -		endBranch=bo;
   1.101 -		endPos=endBranch->getChildPos();
   1.102 -	}		
   1.103 -}
   1.104 -
   1.105 -BranchObj* XLinkObj::getEnd()
   1.106 -{
   1.107 -	return endBranch;
   1.108 -}
   1.109 -
   1.110 -void XLinkObj::setWidth (int w)
   1.111 -{
   1.112 -	width=w;
   1.113 -	pen.setWidth (w);
   1.114 -	setColor (color);
   1.115 -}
   1.116 -
   1.117 -int XLinkObj::getWidth()
   1.118 -{
   1.119 -	return pen.width();
   1.120 -}
   1.121 -
   1.122 -void XLinkObj::setColor(QColor c)
   1.123 -{
   1.124 -	color=c;
   1.125 -	pen.setColor (c);
   1.126 -	line->setPen (pen);
   1.127 -	poly->setBrush( color );
   1.128 -}
   1.129 -
   1.130 -QColor XLinkObj::getColor()
   1.131 -{
   1.132 -	return pen.color();
   1.133 +	setVisibility (true);
   1.134  }
   1.135  
   1.136  void XLinkObj::setEnd (QPointF p)
   1.137 @@ -121,41 +48,6 @@
   1.138  	endPos=p;
   1.139  }
   1.140  
   1.141 -bool XLinkObj::activate ()
   1.142 -{
   1.143 -	if (beginBranch && endBranch)
   1.144 -	{
   1.145 -		if (beginBranch==endBranch) return false;
   1.146 -		xLinkState=activeXLink;
   1.147 -		beginBranch->addXLink (this);
   1.148 -		endBranch->addXLink (this);
   1.149 -		setVisibility ();
   1.150 -		return true;
   1.151 -	} else
   1.152 -		return false;
   1.153 -}
   1.154 -
   1.155 -void XLinkObj::deactivate ()
   1.156 -{
   1.157 -	if (beginBranch)
   1.158 -		beginBranch->removeXLinkRef (this);
   1.159 -	beginBranch=NULL;	
   1.160 -	if (endBranch)
   1.161 -		endBranch->removeXLinkRef (this);
   1.162 -	endBranch=NULL;	
   1.163 -	visBranch=NULL;
   1.164 -	xLinkState=undefinedXLink;
   1.165 -
   1.166 -	line->hide();
   1.167 -}
   1.168 -
   1.169 -bool XLinkObj::isUsed()
   1.170 -{
   1.171 -	if (beginBranch || endBranch || xLinkState!=undefinedXLink)
   1.172 -		return true;
   1.173 -	else
   1.174 -		return false;
   1.175 -}
   1.176  
   1.177  void XLinkObj::updateXLink()
   1.178  {
   1.179 @@ -164,8 +56,11 @@
   1.180  	if (visBranch)
   1.181  	{
   1.182  		// Only one of the linked branches is visible
   1.183 -		a=b=visBranch->getChildPos();
   1.184 -		if (visBranch->getOrientation()==LinkableMapObj::RightOfCenter)
   1.185 +		BranchObj *bo=(BranchObj*)(visBranch->getLMO());
   1.186 +		if (!bo) return;
   1.187 +
   1.188 +		a=b=bo->getChildPos();
   1.189 +		if (bo->getOrientation()==LinkableMapObj::RightOfCenter)
   1.190  		{
   1.191  			b.setX (b.x()+25);
   1.192  			
   1.193 @@ -186,43 +81,43 @@
   1.194  	} else
   1.195  	{
   1.196  		// Both linked branches are visible
   1.197 -		if (beginBranch)
   1.198 +		BranchItem *bi=((XLinkItem*)treeItem)->getBegin();
   1.199 +		if ( bi)
   1.200 +		{
   1.201  			// If a link is just drawn in the editor,
   1.202  			// we have already a beginBranch
   1.203 -			a=beginBranch->getChildPos();
   1.204 +			BranchObj *bo=(BranchObj*)(bi->getLMO());
   1.205 +			if (bo)	
   1.206 +				a=bo->getChildPos();
   1.207 +			else 
   1.208 +				return;	
   1.209 +		}	
   1.210  		else
   1.211  			// This shouldn't be reached normally...
   1.212  			a=beginPos;
   1.213 -		if (xLinkState==activeXLink && endBranch)
   1.214 -			b=endBranch->getChildPos();
   1.215 +
   1.216 +		// FIXME-3 try to get rid of xLinkstate if (xLinkState==activeXLink && endBranch)
   1.217 +		bi=((XLinkItem*)treeItem)->getEnd();
   1.218 +		if (bi)
   1.219 +		{
   1.220 +			BranchObj *bo=(BranchObj*)(bi->getLMO());
   1.221 +			if (bo)	
   1.222 +				b=bo->getChildPos();
   1.223 +			else 
   1.224 +				return;	
   1.225 +		}
   1.226  		else
   1.227  			b=endPos;
   1.228  	}
   1.229  
   1.230 -
   1.231 -	if (line->line().p1()==a && line->line().p2()==b && !visBranch)
   1.232 -	{
   1.233 -		// update is called from both branches, so only
   1.234 -		// update if something has changed
   1.235 -		return;
   1.236 -	}	
   1.237 -	else
   1.238 -	{
   1.239 -		beginPos=a;
   1.240 -		endPos=b;
   1.241 -		line->setPen (pen);
   1.242 -		line->setLine(a.x(), a.y(), b.x(), b.y());
   1.243 -	}
   1.244 -}
   1.245 -
   1.246 -BranchObj* XLinkObj::otherBranch(BranchObj* thisBranch)
   1.247 -{
   1.248 -	if (!beginBranch && !endBranch)
   1.249 -		return NULL;
   1.250 -	if (thisBranch==beginBranch)
   1.251 -		return endBranch;
   1.252 -	else	
   1.253 -		return beginBranch;
   1.254 +	beginPos=a;
   1.255 +	endPos=b;
   1.256 +	XLinkItem *xli=(XLinkItem*)treeItem;
   1.257 +	pen.setColor ( xli->getColor() );
   1.258 +	pen.setWidth ( xli->getWidth() );
   1.259 +	poly->setBrush (xli->getColor() );
   1.260 +	line->setPen (pen);
   1.261 +	line->setLine(a.x(), a.y(), b.x(), b.y());
   1.262  }
   1.263  
   1.264  void XLinkObj::positionBBox()
   1.265 @@ -253,49 +148,36 @@
   1.266  
   1.267  void XLinkObj::setVisibility ()
   1.268  {
   1.269 -	if (beginBranch && endBranch)
   1.270 +	BranchItem* beginBI=((XLinkItem*)treeItem)->getBegin();
   1.271 +	BranchObj* beginBO=NULL;
   1.272 +	if (beginBI) beginBO=(BranchObj*)(beginBI->getLMO());
   1.273 +
   1.274 +	BranchObj* endBO=NULL;
   1.275 +	BranchItem* endBI=((XLinkItem*)treeItem)->getEnd();
   1.276 +	if (endBI) endBO=(BranchObj*)(endBI->getLMO());
   1.277 +	if (beginBO && endBO)
   1.278  	{
   1.279 -		if(beginBranch->isVisibleObj() && endBranch->isVisibleObj())
   1.280 +		if(beginBO->isVisibleObj() && endBO->isVisibleObj())
   1.281  		{	// Both ends are visible
   1.282  			visBranch=NULL;
   1.283  			setVisibility (true);
   1.284  		} else
   1.285  		{
   1.286 -			if(!beginBranch->isVisibleObj() && !endBranch->isVisibleObj())
   1.287 +			if(!beginBO->isVisibleObj() && !endBO->isVisibleObj())
   1.288  			{	//None of the ends is visible
   1.289  				visBranch=NULL;
   1.290  				setVisibility (false);
   1.291  			} else
   1.292  			{	// Just one end is visible, draw a symbol that shows
   1.293  				// that there is a link to a scrolled branch
   1.294 -				if (beginBranch->isVisibleObj())
   1.295 -					visBranch=beginBranch;
   1.296 +				if (beginBO->isVisibleObj())
   1.297 +					visBranch=beginBI;
   1.298  				else
   1.299 -					visBranch=endBranch;
   1.300 +					visBranch=endBI;
   1.301  				setVisibility (true);
   1.302  			}
   1.303  		}
   1.304  	}
   1.305  }
   1.306  
   1.307 -QString XLinkObj::saveToDir ()
   1.308 -{
   1.309 -	QString s="";
   1.310 -	if (beginBranch && endBranch &&xLinkState==activeXLink)
   1.311 -	{
   1.312 -		if (beginBranch==endBranch && xLinkState)
   1.313 -			s="";
   1.314 -		else
   1.315 -		{
   1.316 -			QString colAttr=attribut ("color",color.name());
   1.317 -			QString widAttr=attribut ("width",QString().setNum(width,10));
   1.318 -			QString begSelAttr=attribut ("beginID",beginBranch->getSelectString());
   1.319 -			QString endSelAttr=attribut ("endID",  endBranch->getSelectString());
   1.320 -			s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
   1.321  
   1.322 -			s+=endElement ("xlink");
   1.323 -		}
   1.324 -	}
   1.325 -	return s;
   1.326 -}
   1.327 -