insilmaril@795
|
1 |
#include <QGraphicsScene>
|
insilmaril@795
|
2 |
#include "xlinkitem.h"
|
insilmaril@795
|
3 |
|
insilmaril@795
|
4 |
#include "branchitem.h"
|
insilmaril@795
|
5 |
#include "linkablemapobj.h"
|
insilmaril@795
|
6 |
#include "vymmodel.h"
|
insilmaril@795
|
7 |
#include "xlinkobj.h"
|
insilmaril@795
|
8 |
|
insilmaril@795
|
9 |
#include <iostream>
|
insilmaril@795
|
10 |
using namespace std;
|
insilmaril@795
|
11 |
|
insilmaril@795
|
12 |
/////////////////////////////////////////////////////////////////
|
insilmaril@795
|
13 |
// XLinkItem
|
insilmaril@795
|
14 |
/////////////////////////////////////////////////////////////////
|
insilmaril@795
|
15 |
|
insilmaril@795
|
16 |
XLinkItem::XLinkItem (const QList<QVariant> &data, TreeItem *parent):MapItem (data,parent)
|
insilmaril@795
|
17 |
|
insilmaril@795
|
18 |
{
|
insilmaril@795
|
19 |
//cout << "Const XLinkItem () "<<this<<endl;
|
insilmaril@795
|
20 |
init();
|
insilmaril@795
|
21 |
}
|
insilmaril@795
|
22 |
|
insilmaril@795
|
23 |
XLinkItem::~XLinkItem ()
|
insilmaril@795
|
24 |
{
|
insilmaril@795
|
25 |
cout << "Destr XLinkItem "<<this<<" lmo="<<lmo<<endl;
|
insilmaril@795
|
26 |
if (lmo){cout <<" calling delete\n"; delete (lmo);}
|
insilmaril@795
|
27 |
if (partnerXLink)
|
insilmaril@795
|
28 |
{
|
insilmaril@795
|
29 |
// Also delete partner
|
insilmaril@795
|
30 |
cout << " deleting partner="<<partnerXLink<<endl;
|
insilmaril@795
|
31 |
partnerXLink->partnerXLink=NULL; // avoid endless recusion
|
insilmaril@795
|
32 |
model->deleteItem (partnerXLink);
|
insilmaril@795
|
33 |
}
|
insilmaril@795
|
34 |
}
|
insilmaril@795
|
35 |
|
insilmaril@795
|
36 |
|
insilmaril@795
|
37 |
void XLinkItem::init ()
|
insilmaril@795
|
38 |
{
|
insilmaril@795
|
39 |
setType (XLink);
|
insilmaril@795
|
40 |
beginBranch=NULL;
|
insilmaril@795
|
41 |
endBranch=NULL;
|
insilmaril@795
|
42 |
partnerXLink=NULL;
|
insilmaril@795
|
43 |
isBeginXLink=true;
|
insilmaril@795
|
44 |
xLinkState=XLinkItem::undefinedXLink;
|
insilmaril@795
|
45 |
|
insilmaril@795
|
46 |
color=QColor (180,180,180);
|
insilmaril@795
|
47 |
width=1;
|
insilmaril@795
|
48 |
}
|
insilmaril@795
|
49 |
|
insilmaril@795
|
50 |
void XLinkItem::setBegin (BranchItem *bi)
|
insilmaril@795
|
51 |
{
|
insilmaril@795
|
52 |
if (bi)
|
insilmaril@795
|
53 |
{
|
insilmaril@795
|
54 |
xLinkState=initXLink;
|
insilmaril@795
|
55 |
beginBranch=bi;
|
insilmaril@795
|
56 |
}
|
insilmaril@795
|
57 |
}
|
insilmaril@795
|
58 |
|
insilmaril@795
|
59 |
BranchItem* XLinkItem::getBegin ()
|
insilmaril@795
|
60 |
{
|
insilmaril@795
|
61 |
return beginBranch;
|
insilmaril@795
|
62 |
}
|
insilmaril@795
|
63 |
|
insilmaril@795
|
64 |
void XLinkItem::setEnd (BranchItem *bi)
|
insilmaril@795
|
65 |
{
|
insilmaril@795
|
66 |
if (bi)
|
insilmaril@795
|
67 |
{
|
insilmaril@795
|
68 |
xLinkState=initXLink;
|
insilmaril@795
|
69 |
endBranch=bi;
|
insilmaril@795
|
70 |
}
|
insilmaril@795
|
71 |
}
|
insilmaril@795
|
72 |
|
insilmaril@795
|
73 |
BranchItem* XLinkItem::getEnd()
|
insilmaril@795
|
74 |
{
|
insilmaril@795
|
75 |
return endBranch;
|
insilmaril@795
|
76 |
}
|
insilmaril@795
|
77 |
|
insilmaril@795
|
78 |
void XLinkItem::setWidth (int w)
|
insilmaril@795
|
79 |
{
|
insilmaril@795
|
80 |
if (isBeginXLink)
|
insilmaril@795
|
81 |
{
|
insilmaril@795
|
82 |
width=w;
|
insilmaril@795
|
83 |
if (lmo) ((XLinkObj*)lmo)->updateXLink();
|
insilmaril@795
|
84 |
return;
|
insilmaril@795
|
85 |
}
|
insilmaril@795
|
86 |
if (partnerXLink)
|
insilmaril@795
|
87 |
partnerXLink->setWidth (w);
|
insilmaril@795
|
88 |
}
|
insilmaril@795
|
89 |
|
insilmaril@795
|
90 |
int XLinkItem::getWidth()
|
insilmaril@795
|
91 |
{
|
insilmaril@795
|
92 |
if (isBeginXLink) return width;
|
insilmaril@795
|
93 |
if (partnerXLink)
|
insilmaril@795
|
94 |
return partnerXLink->getWidth();
|
insilmaril@795
|
95 |
else
|
insilmaril@795
|
96 |
return -1;
|
insilmaril@795
|
97 |
}
|
insilmaril@795
|
98 |
|
insilmaril@795
|
99 |
void XLinkItem::setColor(QColor c)
|
insilmaril@795
|
100 |
{
|
insilmaril@795
|
101 |
if (isBeginXLink)
|
insilmaril@795
|
102 |
{
|
insilmaril@795
|
103 |
color=c;
|
insilmaril@795
|
104 |
if (lmo) ((XLinkObj*)lmo)->updateXLink();
|
insilmaril@795
|
105 |
return;
|
insilmaril@795
|
106 |
}
|
insilmaril@795
|
107 |
if (partnerXLink)
|
insilmaril@795
|
108 |
partnerXLink->setColor (c);
|
insilmaril@795
|
109 |
}
|
insilmaril@795
|
110 |
|
insilmaril@795
|
111 |
QColor XLinkItem::getColor()
|
insilmaril@795
|
112 |
{
|
insilmaril@795
|
113 |
if (isBeginXLink) return color;
|
insilmaril@795
|
114 |
if (partnerXLink)
|
insilmaril@795
|
115 |
return partnerXLink->getColor();
|
insilmaril@795
|
116 |
else
|
insilmaril@795
|
117 |
return QColor();
|
insilmaril@795
|
118 |
}
|
insilmaril@795
|
119 |
|
insilmaril@795
|
120 |
void XLinkItem::setEnd (QPointF p)
|
insilmaril@795
|
121 |
{
|
insilmaril@795
|
122 |
if (lmo) ((XLinkObj*)lmo)->setEnd (p);
|
insilmaril@795
|
123 |
}
|
insilmaril@795
|
124 |
|
insilmaril@795
|
125 |
bool XLinkItem::activate ()
|
insilmaril@795
|
126 |
{
|
insilmaril@795
|
127 |
if (beginBranch && endBranch)
|
insilmaril@795
|
128 |
{
|
insilmaril@795
|
129 |
if (beginBranch==endBranch) return false;
|
insilmaril@795
|
130 |
|
insilmaril@795
|
131 |
partnerXLink=model->createXLink (endBranch);
|
insilmaril@795
|
132 |
partnerXLink->setBegin (beginBranch);
|
insilmaril@795
|
133 |
partnerXLink->setEnd (endBranch);
|
insilmaril@795
|
134 |
partnerXLink->partnerXLink=this;
|
insilmaril@795
|
135 |
partnerXLink->isBeginXLink=false;
|
insilmaril@795
|
136 |
|
insilmaril@795
|
137 |
xLinkState=activeXLink;
|
insilmaril@795
|
138 |
partnerXLink->xLinkState=activeXLink;
|
insilmaril@795
|
139 |
partnerXLink->setHeading ("xLink to: "+beginBranch->getHeading());
|
insilmaril@795
|
140 |
setHeading ("xLink to: "+endBranch->getHeading());
|
insilmaril@795
|
141 |
|
insilmaril@795
|
142 |
model->updateActions();
|
insilmaril@795
|
143 |
return true;
|
insilmaril@795
|
144 |
} else
|
insilmaril@795
|
145 |
return false;
|
insilmaril@795
|
146 |
}
|
insilmaril@795
|
147 |
|
insilmaril@795
|
148 |
bool XLinkItem::isBegin()
|
insilmaril@795
|
149 |
{
|
insilmaril@795
|
150 |
return isBeginXLink;
|
insilmaril@795
|
151 |
}
|
insilmaril@795
|
152 |
|
insilmaril@795
|
153 |
void XLinkItem::updateXLink()
|
insilmaril@795
|
154 |
{
|
insilmaril@795
|
155 |
if(lmo && isBeginXLink)
|
insilmaril@795
|
156 |
((XLinkObj*)lmo)->updateXLink();
|
insilmaril@795
|
157 |
else
|
insilmaril@795
|
158 |
if (partnerXLink) partnerXLink->updateXLink();
|
insilmaril@795
|
159 |
}
|
insilmaril@795
|
160 |
|
insilmaril@795
|
161 |
void XLinkItem::updateVisibility()
|
insilmaril@795
|
162 |
{
|
insilmaril@795
|
163 |
if (lmo) lmo->updateVisibility();
|
insilmaril@795
|
164 |
}
|
insilmaril@795
|
165 |
|
insilmaril@795
|
166 |
BranchItem* XLinkItem::getPartnerBranch()
|
insilmaril@795
|
167 |
{
|
insilmaril@795
|
168 |
if (!beginBranch && !endBranch)
|
insilmaril@795
|
169 |
return NULL;
|
insilmaril@795
|
170 |
if (isBeginXLink)
|
insilmaril@795
|
171 |
return endBranch;
|
insilmaril@795
|
172 |
else
|
insilmaril@795
|
173 |
return beginBranch;
|
insilmaril@795
|
174 |
}
|
insilmaril@795
|
175 |
|
insilmaril@795
|
176 |
|
insilmaril@795
|
177 |
XLinkItem* XLinkItem::getPartnerXLink()
|
insilmaril@795
|
178 |
{
|
insilmaril@795
|
179 |
return partnerXLink;
|
insilmaril@795
|
180 |
}
|
insilmaril@795
|
181 |
|
insilmaril@795
|
182 |
|
insilmaril@795
|
183 |
QString XLinkItem::saveToDir ()
|
insilmaril@795
|
184 |
{
|
insilmaril@795
|
185 |
QString s="";
|
insilmaril@795
|
186 |
if (beginBranch && endBranch && xLinkState==activeXLink)
|
insilmaril@795
|
187 |
{
|
insilmaril@795
|
188 |
if (beginBranch==endBranch )
|
insilmaril@795
|
189 |
qWarning ("XLI::saveToDir beginBranch==endBranch"); //FIXME-3 s=""
|
insilmaril@795
|
190 |
else
|
insilmaril@795
|
191 |
{
|
insilmaril@795
|
192 |
QString colAttr=attribut ("color",color.name());
|
insilmaril@795
|
193 |
QString widAttr=attribut ("width",QString().setNum(width,10));
|
insilmaril@795
|
194 |
QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
|
insilmaril@795
|
195 |
QString endSelAttr=attribut ("endID", model->getSelectString(endBranch));
|
insilmaril@795
|
196 |
s=beginElement ("xlink", colAttr +widAttr +begSelAttr +endSelAttr);
|
insilmaril@795
|
197 |
|
insilmaril@795
|
198 |
s+=endElement ("xlink");
|
insilmaril@795
|
199 |
}
|
insilmaril@795
|
200 |
}
|
insilmaril@795
|
201 |
return s;
|
insilmaril@795
|
202 |
}
|
insilmaril@795
|
203 |
|
insilmaril@795
|
204 |
XLinkObj* XLinkItem::createMapObj(QGraphicsScene *scene)
|
insilmaril@795
|
205 |
{
|
insilmaril@795
|
206 |
XLinkObj* xlo=new XLinkObj (scene,this);
|
insilmaril@795
|
207 |
lmo=(LinkableMapObj*)xlo;
|
insilmaril@795
|
208 |
return xlo;
|
insilmaril@795
|
209 |
}
|
insilmaril@795
|
210 |
|