xlink.cpp
author convert-repo
Fri, 23 Jul 2010 16:43:49 +0000
changeset 849 988f1908a7c4
parent 847 43268373032d
permissions -rw-r--r--
update tags
     1 #include <QDebug>
     2 
     3 #include "xlink.h"
     4 
     5 #include "vymmodel.h"
     6 #include "xlinkitem.h"
     7 #include "xlinkobj.h"
     8 
     9 /////////////////////////////////////////////////////////////////
    10 // Link
    11 /////////////////////////////////////////////////////////////////
    12 
    13 Link::Link (VymModel *m)
    14 {
    15 	//qDebug() << "Const Link () this="<<this;
    16 	init();
    17 	model=m;
    18 }
    19 
    20 Link::~Link ()
    21 {
    22 	//qDebug()<<"* Destr Link begin this="<<this<<"  bLI="<<beginLinkItem<<"  eLI="<<endLinkItem;
    23 	//deactivate();
    24 	//qDebug()<<"* Destr Link end   this="<<this;
    25 }
    26 
    27 void Link::init () 
    28 {
    29 	xlo=NULL;
    30 	beginBranch=NULL;
    31 	endBranch=NULL;
    32 	xLinkState=Link::undefinedXLink;
    33 
    34 	color=QColor (180,180,180);
    35 	width=1;
    36 }
    37 
    38 void Link::setBeginBranch (BranchItem *bi)
    39 {
    40 	if (bi) 
    41 	{
    42 		xLinkState=initXLink;
    43 		beginBranch=bi;
    44 	}	
    45 }
    46 
    47 BranchItem* Link::getBeginBranch ()
    48 {
    49 	return beginBranch;
    50 }
    51 
    52 void Link::setEndBranch (BranchItem *bi)
    53 {
    54 	if (bi) 
    55 	{
    56 		xLinkState=initXLink;
    57 		endBranch=bi;
    58 	}		
    59 }
    60 
    61 BranchItem* Link::getEndBranch()
    62 {
    63 	return endBranch;
    64 }
    65 
    66 void Link::setEndPoint (QPointF p)
    67 {
    68 	if (xlo) xlo->setEnd (p);
    69 }
    70 
    71 void Link::setBeginLinkItem (XLinkItem *li)
    72 {
    73 	if (li) 
    74 	{
    75 		xLinkState=initXLink;
    76 		beginLinkItem=li;
    77 	}	
    78 }
    79 
    80 XLinkItem* Link::getBeginLinkItem ()
    81 {
    82 	return beginLinkItem;
    83 }
    84 
    85 void Link::setEndLinkItem (XLinkItem *li)
    86 {
    87 	if (li) 
    88 	{
    89 		xLinkState=initXLink;
    90 		endLinkItem=li;
    91 	}		
    92 }
    93 
    94 XLinkItem* Link::getEndLinkItem()
    95 {
    96 	return endLinkItem;
    97 }
    98 
    99 void Link::setWidth (int w)
   100 {
   101 	width=w;
   102 	if (xlo) xlo->updateXLink();
   103 }
   104 
   105 int Link::getWidth()
   106 {
   107 	return width;
   108 }
   109 
   110 void Link::setColor(QColor c)
   111 {
   112 	color=c;
   113 	if (xlo) xlo->updateXLink();
   114 }
   115 
   116 QColor Link::getColor()
   117 {
   118 	return color;
   119 }
   120 
   121 bool Link::activate ()	
   122 {
   123 	if (beginBranch && endBranch)
   124 	{
   125 		
   126 		if (beginBranch==endBranch) return false;
   127 		xLinkState=activeXLink;
   128 
   129 		model->updateActions();
   130 		return true;
   131 	} else
   132 		return false;
   133 }
   134 
   135 void Link::deactivate ()	
   136 {
   137 	// Remove pointers from XLinkItem to Link and
   138 	// delete XLinkObj
   139 
   140 	xLinkState=deleteXLink;
   141 	if (beginLinkItem) beginLinkItem->setLink (NULL);
   142 	if (endLinkItem) endLinkItem->setLink (NULL);
   143 	if (xlo)
   144 	{
   145 		delete (xlo);  
   146 		xlo=NULL;
   147 	}
   148 }
   149 
   150 void Link::removeXLinkItem (XLinkItem *xli)
   151 {
   152 	if (xli==beginLinkItem) beginLinkItem=NULL;
   153 	if (xli==endLinkItem) endLinkItem=NULL;
   154 }
   155 
   156 void Link::updateLink()
   157 {
   158 	if(xlo ) xlo->updateXLink();
   159 }
   160 
   161 QString Link::saveToDir ()
   162 {
   163 	QString s="";
   164 	if (beginBranch && endBranch && xLinkState==activeXLink)
   165 	{
   166 		if (beginBranch==endBranch )
   167 			qWarning ("Link::saveToDir  beginBranch==endBranch");
   168 		else
   169 		{
   170 			QString colAttr=attribut ("color",color.name());
   171 			QString widAttr=attribut ("width",QString().setNum(width,10));
   172 			QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
   173 			QString endSelAttr=attribut ("endID",  model->getSelectString(endBranch));
   174 			s=singleElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
   175 
   176 		}
   177 	}
   178 	return s;
   179 }
   180 
   181 XLinkObj* Link::getXLinkObj()
   182 {
   183 	return xlo;
   184 }
   185 
   186 XLinkObj* Link::createMapObj(QGraphicsScene *scene)  
   187 {
   188 	if (!xlo) xlo=new XLinkObj (scene,this);  
   189 	return xlo;
   190 }
   191 
   192