1 #include <QGraphicsScene>
4 #include "branchitem.h"
5 #include "linkablemapobj.h"
12 /////////////////////////////////////////////////////////////////
14 /////////////////////////////////////////////////////////////////
16 XLinkItem::XLinkItem (const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
19 //cout << "Const XLinkItem () "<<this<<endl;
23 XLinkItem::~XLinkItem ()
25 cout << "Destr XLinkItem "<<this<<" lmo="<<lmo<<endl;
26 if (lmo){cout <<" calling delete\n"; delete (lmo);}
29 // Also delete partner
30 cout << " deleting partner="<<partnerXLink<<endl;
31 partnerXLink->partnerXLink=NULL; // avoid endless recusion
32 model->deleteItem (partnerXLink);
37 void XLinkItem::init ()
44 xLinkState=XLinkItem::undefinedXLink;
46 color=QColor (180,180,180);
50 void XLinkItem::setBegin (BranchItem *bi)
59 BranchItem* XLinkItem::getBegin ()
64 void XLinkItem::setEnd (BranchItem *bi)
73 BranchItem* XLinkItem::getEnd()
78 void XLinkItem::setWidth (int w)
83 if (lmo) ((XLinkObj*)lmo)->updateXLink();
87 partnerXLink->setWidth (w);
90 int XLinkItem::getWidth()
92 if (isBeginXLink) return width;
94 return partnerXLink->getWidth();
99 void XLinkItem::setColor(QColor c)
104 if (lmo) ((XLinkObj*)lmo)->updateXLink();
108 partnerXLink->setColor (c);
111 QColor XLinkItem::getColor()
113 if (isBeginXLink) return color;
115 return partnerXLink->getColor();
120 void XLinkItem::setEnd (QPointF p)
122 if (lmo) ((XLinkObj*)lmo)->setEnd (p);
125 bool XLinkItem::activate ()
127 if (beginBranch && endBranch)
129 if (beginBranch==endBranch) return false;
131 partnerXLink=model->createXLink (endBranch);
132 partnerXLink->setBegin (beginBranch);
133 partnerXLink->setEnd (endBranch);
134 partnerXLink->partnerXLink=this;
135 partnerXLink->isBeginXLink=false;
137 xLinkState=activeXLink;
138 partnerXLink->xLinkState=activeXLink;
139 partnerXLink->setHeading ("xLink to: "+beginBranch->getHeading());
140 setHeading ("xLink to: "+endBranch->getHeading());
142 model->updateActions();
148 bool XLinkItem::isBegin()
153 void XLinkItem::updateXLink()
155 if(lmo && isBeginXLink)
156 ((XLinkObj*)lmo)->updateXLink();
158 if (partnerXLink) partnerXLink->updateXLink();
161 void XLinkItem::updateVisibility()
163 if (lmo) lmo->updateVisibility();
166 BranchItem* XLinkItem::getPartnerBranch()
168 if (!beginBranch && !endBranch)
177 XLinkItem* XLinkItem::getPartnerXLink()
183 QString XLinkItem::saveToDir ()
186 if (beginBranch && endBranch && xLinkState==activeXLink)
188 if (beginBranch==endBranch )
189 qWarning ("XLI::saveToDir beginBranch==endBranch"); //FIXME-3 s=""
192 QString colAttr=attribut ("color",color.name());
193 QString widAttr=attribut ("width",QString().setNum(width,10));
194 QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
195 QString endSelAttr=attribut ("endID", model->getSelectString(endBranch));
196 s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
198 s+=endElement ("xlink");
204 XLinkObj* XLinkItem::createMapObj(QGraphicsScene *scene)
206 XLinkObj* xlo=new XLinkObj (scene,this);
207 lmo=(LinkableMapObj*)xlo;