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