]> git.sven.stormbind.net Git - sven/vym.git/blobdiff - src/xlinkitem.cpp
New upstream version 2.9.22
[sven/vym.git] / src / xlinkitem.cpp
diff --git a/src/xlinkitem.cpp b/src/xlinkitem.cpp
new file mode 100644 (file)
index 0000000..e3df3e1
--- /dev/null
@@ -0,0 +1,81 @@
+#include "xlinkitem.h"
+#include <QGraphicsScene>
+
+#include "branchitem.h"
+#include "linkablemapobj.h"
+#include "vymmodel.h"
+#include "xlinkobj.h"
+
+/////////////////////////////////////////////////////////////////
+// XLinkItem
+/////////////////////////////////////////////////////////////////
+
+XLinkItem::XLinkItem(TreeItem *parent)
+    : MapItem(parent)
+
+{
+    // qDebug() << "Const XLinkItem () "<<this;
+    init();
+}
+
+XLinkItem::~XLinkItem()
+{
+    //   qDebug() << "Destr XLinkItem begin "<<this<<"  pI="<<parentItem<<"
+    //   link="<<link;
+    if (link) {
+        XLinkItem *xli = link->getOtherEnd(this);
+        if (xli)
+            model->deleteLater(xli->getID());
+        model->deleteLink(link);
+    }
+    //    qDebug() << "Destr XLinkItem end";
+}
+
+void XLinkItem::init()
+{
+    setType(XLink);
+    link = nullptr;
+}
+
+void XLinkItem::clear() {}
+
+void XLinkItem::setLink(Link *l) { link = l; }
+
+Link *XLinkItem::getLink() { return link; }
+
+void XLinkItem::updateXLink()
+{
+    if (link)
+        link->updateLink();
+}
+
+MapObj *XLinkItem::getMO()
+{
+    if (link)
+        return link->getMO();
+    return nullptr;
+}
+
+void XLinkItem::setSelection()
+{
+    if (link) {
+        XLinkObj *xlo = (XLinkObj *)getMO();
+        if (xlo) {
+            if (parentItem == link->getBeginBranch())
+                xlo->setSelection(XLinkObj::C0);
+            else if (parentItem == link->getEndBranch())
+                xlo->setSelection(XLinkObj::C1);
+        }
+    }
+}
+
+BranchItem *XLinkItem::getPartnerBranch()
+{
+    if (link && link->getBeginBranch() && link->getEndBranch()) {
+        if (parentItem == link->getBeginBranch())
+            return link->getEndBranch();
+        else
+            return link->getBeginBranch();
+    }
+    return NULL;
+}