xlink.cpp
changeset 847 43268373032d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xlink.cpp	Wed Jun 09 13:14:08 2010 +0000
     1.3 @@ -0,0 +1,192 @@
     1.4 +#include <QDebug>
     1.5 +
     1.6 +#include "xlink.h"
     1.7 +
     1.8 +#include "vymmodel.h"
     1.9 +#include "xlinkitem.h"
    1.10 +#include "xlinkobj.h"
    1.11 +
    1.12 +/////////////////////////////////////////////////////////////////
    1.13 +// Link
    1.14 +/////////////////////////////////////////////////////////////////
    1.15 +
    1.16 +Link::Link (VymModel *m)
    1.17 +{
    1.18 +	//qDebug() << "Const Link () this="<<this;
    1.19 +	init();
    1.20 +	model=m;
    1.21 +}
    1.22 +
    1.23 +Link::~Link ()
    1.24 +{
    1.25 +	//qDebug()<<"* Destr Link begin this="<<this<<"  bLI="<<beginLinkItem<<"  eLI="<<endLinkItem;
    1.26 +	//deactivate();
    1.27 +	//qDebug()<<"* Destr Link end   this="<<this;
    1.28 +}
    1.29 +
    1.30 +void Link::init () 
    1.31 +{
    1.32 +	xlo=NULL;
    1.33 +	beginBranch=NULL;
    1.34 +	endBranch=NULL;
    1.35 +	xLinkState=Link::undefinedXLink;
    1.36 +
    1.37 +	color=QColor (180,180,180);
    1.38 +	width=1;
    1.39 +}
    1.40 +
    1.41 +void Link::setBeginBranch (BranchItem *bi)
    1.42 +{
    1.43 +	if (bi) 
    1.44 +	{
    1.45 +		xLinkState=initXLink;
    1.46 +		beginBranch=bi;
    1.47 +	}	
    1.48 +}
    1.49 +
    1.50 +BranchItem* Link::getBeginBranch ()
    1.51 +{
    1.52 +	return beginBranch;
    1.53 +}
    1.54 +
    1.55 +void Link::setEndBranch (BranchItem *bi)
    1.56 +{
    1.57 +	if (bi) 
    1.58 +	{
    1.59 +		xLinkState=initXLink;
    1.60 +		endBranch=bi;
    1.61 +	}		
    1.62 +}
    1.63 +
    1.64 +BranchItem* Link::getEndBranch()
    1.65 +{
    1.66 +	return endBranch;
    1.67 +}
    1.68 +
    1.69 +void Link::setEndPoint (QPointF p)
    1.70 +{
    1.71 +	if (xlo) xlo->setEnd (p);
    1.72 +}
    1.73 +
    1.74 +void Link::setBeginLinkItem (XLinkItem *li)
    1.75 +{
    1.76 +	if (li) 
    1.77 +	{
    1.78 +		xLinkState=initXLink;
    1.79 +		beginLinkItem=li;
    1.80 +	}	
    1.81 +}
    1.82 +
    1.83 +XLinkItem* Link::getBeginLinkItem ()
    1.84 +{
    1.85 +	return beginLinkItem;
    1.86 +}
    1.87 +
    1.88 +void Link::setEndLinkItem (XLinkItem *li)
    1.89 +{
    1.90 +	if (li) 
    1.91 +	{
    1.92 +		xLinkState=initXLink;
    1.93 +		endLinkItem=li;
    1.94 +	}		
    1.95 +}
    1.96 +
    1.97 +XLinkItem* Link::getEndLinkItem()
    1.98 +{
    1.99 +	return endLinkItem;
   1.100 +}
   1.101 +
   1.102 +void Link::setWidth (int w)
   1.103 +{
   1.104 +	width=w;
   1.105 +	if (xlo) xlo->updateXLink();
   1.106 +}
   1.107 +
   1.108 +int Link::getWidth()
   1.109 +{
   1.110 +	return width;
   1.111 +}
   1.112 +
   1.113 +void Link::setColor(QColor c)
   1.114 +{
   1.115 +	color=c;
   1.116 +	if (xlo) xlo->updateXLink();
   1.117 +}
   1.118 +
   1.119 +QColor Link::getColor()
   1.120 +{
   1.121 +	return color;
   1.122 +}
   1.123 +
   1.124 +bool Link::activate ()	
   1.125 +{
   1.126 +	if (beginBranch && endBranch)
   1.127 +	{
   1.128 +		
   1.129 +		if (beginBranch==endBranch) return false;
   1.130 +		xLinkState=activeXLink;
   1.131 +
   1.132 +		model->updateActions();
   1.133 +		return true;
   1.134 +	} else
   1.135 +		return false;
   1.136 +}
   1.137 +
   1.138 +void Link::deactivate ()	
   1.139 +{
   1.140 +	// Remove pointers from XLinkItem to Link and
   1.141 +	// delete XLinkObj
   1.142 +
   1.143 +	xLinkState=deleteXLink;
   1.144 +	if (beginLinkItem) beginLinkItem->setLink (NULL);
   1.145 +	if (endLinkItem) endLinkItem->setLink (NULL);
   1.146 +	if (xlo)
   1.147 +	{
   1.148 +		delete (xlo);  
   1.149 +		xlo=NULL;
   1.150 +	}
   1.151 +}
   1.152 +
   1.153 +void Link::removeXLinkItem (XLinkItem *xli)
   1.154 +{
   1.155 +	if (xli==beginLinkItem) beginLinkItem=NULL;
   1.156 +	if (xli==endLinkItem) endLinkItem=NULL;
   1.157 +}
   1.158 +
   1.159 +void Link::updateLink()
   1.160 +{
   1.161 +	if(xlo ) xlo->updateXLink();
   1.162 +}
   1.163 +
   1.164 +QString Link::saveToDir ()
   1.165 +{
   1.166 +	QString s="";
   1.167 +	if (beginBranch && endBranch && xLinkState==activeXLink)
   1.168 +	{
   1.169 +		if (beginBranch==endBranch )
   1.170 +			qWarning ("Link::saveToDir  beginBranch==endBranch");
   1.171 +		else
   1.172 +		{
   1.173 +			QString colAttr=attribut ("color",color.name());
   1.174 +			QString widAttr=attribut ("width",QString().setNum(width,10));
   1.175 +			QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
   1.176 +			QString endSelAttr=attribut ("endID",  model->getSelectString(endBranch));
   1.177 +			s=singleElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
   1.178 +
   1.179 +		}
   1.180 +	}
   1.181 +	return s;
   1.182 +}
   1.183 +
   1.184 +XLinkObj* Link::getXLinkObj()
   1.185 +{
   1.186 +	return xlo;
   1.187 +}
   1.188 +
   1.189 +XLinkObj* Link::createMapObj(QGraphicsScene *scene)  
   1.190 +{
   1.191 +	if (!xlo) xlo=new XLinkObj (scene,this);  
   1.192 +	return xlo;
   1.193 +}
   1.194 +
   1.195 +