]> git.sven.stormbind.net Git - sven/vym.git/blob - xlinkitem.cpp
1836342ff207ba2e0cfe6142613384e39339dbc7
[sven/vym.git] / xlinkitem.cpp
1 #include <QGraphicsScene>
2 #include "xlinkitem.h"
3
4 #include "branchitem.h"
5 #include "linkablemapobj.h"
6 #include "vymmodel.h"
7 #include "xlinkobj.h"
8
9 /////////////////////////////////////////////////////////////////
10 // XLinkItem
11 /////////////////////////////////////////////////////////////////
12
13 XLinkItem::XLinkItem (const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
14
15 {
16     //qDebug() << "Const XLinkItem () "<<this;
17     init();
18 }
19
20 XLinkItem::~XLinkItem ()
21 {
22  //   qDebug() << "Destr XLinkItem begin "<<this<<"  pI="<<parentItem<<"  link="<<link;
23     if (link)
24     {
25         XLinkItem *xli=link->getOtherEnd (this);
26         if (xli) model->deleteLater (xli->getID());
27         model->deleteLink (link);
28     }   
29 //    qDebug() << "Destr XLinkItem end";
30 }
31
32
33 void XLinkItem::init () 
34 {
35     setType (XLink);
36     link=NULL;
37 }
38
39 void XLinkItem::clear() 
40 {
41 }
42
43 void XLinkItem::setLink (Link *l)
44 {
45     link=l;
46 }
47
48 Link* XLinkItem::getLink ()
49 {
50     return link;
51 }
52
53 void XLinkItem::updateXLink()
54 {
55     if (link)
56         link->updateLink();
57 }
58
59 MapObj* XLinkItem::getMO()
60 {
61     if (link)
62         return link->getMO();
63     return NULL;        
64 }
65
66 void XLinkItem::setSelection()
67 {
68     if (link)
69     {
70         XLinkObj* xlo=(XLinkObj*)getMO();
71         if (xlo) 
72         {
73             if (parentItem==link->getBeginBranch() )
74                 xlo->setSelection(XLinkObj::C0);
75             else if (parentItem==link->getEndBranch() )
76                 xlo->setSelection(XLinkObj::C1);
77         }
78     }
79 }
80
81 BranchItem* XLinkItem::getPartnerBranch()
82 {
83     if (link && link->getBeginBranch() && link->getEndBranch())
84     {
85         if (parentItem==link->getBeginBranch())
86             return link->getEndBranch();
87         else    
88             return link->getBeginBranch();
89     }
90     return NULL;
91 }
92