]> git.sven.stormbind.net Git - sven/vym.git/blob - src/xlinkitem.cpp
Replace Pierre as the maintainer
[sven/vym.git] / src / xlinkitem.cpp
1 #include "xlinkitem.h"
2 #include <QGraphicsScene>
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(TreeItem *parent)
14     : MapItem(parent)
15
16 {
17     // qDebug() << "Const XLinkItem () "<<this;
18     init();
19 }
20
21 XLinkItem::~XLinkItem()
22 {
23     //   qDebug() << "Destr XLinkItem begin "<<this<<"  pI="<<parentItem<<"
24     //   link="<<link;
25     if (link) {
26         XLinkItem *xli = link->getOtherEnd(this);
27         if (xli)
28             model->deleteLater(xli->getID());
29         model->deleteLink(link);
30     }
31     //    qDebug() << "Destr XLinkItem end";
32 }
33
34 void XLinkItem::init()
35 {
36     setType(XLink);
37     link = nullptr;
38 }
39
40 void XLinkItem::clear() {}
41
42 void XLinkItem::setLink(Link *l) { link = l; }
43
44 Link *XLinkItem::getLink() { return link; }
45
46 void XLinkItem::updateXLink()
47 {
48     if (link)
49         link->updateLink();
50 }
51
52 MapObj *XLinkItem::getMO()
53 {
54     if (link)
55         return link->getMO();
56     return nullptr;
57 }
58
59 void XLinkItem::setSelection()
60 {
61     if (link) {
62         XLinkObj *xlo = (XLinkObj *)getMO();
63         if (xlo) {
64             if (parentItem == link->getBeginBranch())
65                 xlo->setSelection(XLinkObj::C0);
66             else if (parentItem == link->getEndBranch())
67                 xlo->setSelection(XLinkObj::C1);
68         }
69     }
70 }
71
72 BranchItem *XLinkItem::getPartnerBranch()
73 {
74     if (link && link->getBeginBranch() && link->getEndBranch()) {
75         if (parentItem == link->getBeginBranch())
76             return link->getEndBranch();
77         else
78             return link->getBeginBranch();
79     }
80     return NULL;
81 }