Menu

[c54480]: / xlink.cpp  Maximize  Restore  History

Download this file

287 lines (249 with data), 5.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include <QDebug>
#include "xlink.h"
#include "branchitem.h"
#include "misc.h"
#include "vymmodel.h"
#include "xlinkitem.h"
#include "xlinkobj.h"
class VymModel;
/////////////////////////////////////////////////////////////////
// Link
/////////////////////////////////////////////////////////////////
Link::Link (VymModel *m)
{
//qDebug() << "Const Link () this="<<this;
model=m;
init();
}
Link::~Link ()
{
// qDebug()<<"* Destr Link begin this="<<this<<" bLI="<<beginLinkItem<<" eLI="<<endLinkItem;
deactivate();
// qDebug()<<"* Destr Link end this="<<this;
}
void Link::init ()
{
xlo=NULL;
beginBranch=NULL;
endBranch=NULL;
beginLinkItem=NULL;
endLinkItem=NULL;
xLinkState=Link::undefinedXLink;
type=Bezier;
pen=model->getMapDefXLinkPen();
}
VymModel* Link::getModel()
{
return model;
}
void Link::setBeginBranch (BranchItem *bi)
{
if (bi)
{
xLinkState=initXLink;
beginBranch=bi;
}
}
BranchItem* Link::getBeginBranch ()
{
return beginBranch;
}
void Link::setEndBranch (BranchItem *bi)
{
if (bi)
{
endBranch=bi;
if (xlo) xlo->initC1();
}
}
BranchItem* Link::getEndBranch()
{
return endBranch;
}
void Link::setEndPoint (QPointF p)
{
// Used only while creating the link, without endBranch
if (xlo) xlo->setEnd (p);
}
void Link::setBeginLinkItem (XLinkItem *li)
{
if (li)
{
xLinkState=initXLink;
beginLinkItem=li;
}
}
XLinkItem* Link::getBeginLinkItem ()
{
return beginLinkItem;
}
void Link::setEndLinkItem (XLinkItem *li)
{
if (li)
{
xLinkState=initXLink;
endLinkItem=li;
}
}
XLinkItem* Link::getEndLinkItem()
{
return endLinkItem;
}
XLinkItem* Link::getOtherEnd (XLinkItem *xli)
{
if (xli==beginLinkItem) return endLinkItem;
if (xli==endLinkItem) return beginLinkItem;
return NULL;
}
void Link::setPen (const QPen &p)
{
pen = p;
if (xlo) xlo->updateXLink();
}
QPen Link::getPen ()
{
return pen;
}
void Link::setLinkType (const QString &s)
{
if (s=="Linear")
type=Linear;
else if (s=="Bezier")
type=Bezier;
else
qWarning()<<"Link::setLinkType Unknown type: "<<s;
}
void Link::setStyleBegin (const QString &s)
{
if (xlo)
{
xlo->setStyleBegin( s );
xlo->updateXLink();
}
}
QString Link::getStyleBeginString()
{
if (xlo)
return ArrowObj::styleToString( xlo->getStyleBegin() );
else
return QString();
}
void Link::setStyleEnd (const QString &s)
{
if (xlo)
{
xlo->setStyleEnd( s );
xlo->updateXLink();
}
}
QString Link::getStyleEndString()
{
if (xlo)
return ArrowObj::styleToString( xlo->getStyleEnd() );
else
return QString();
}
bool Link::activate ()
{
if (beginBranch && endBranch)
{
if ( beginBranch == endBranch) return false;
xLinkState = activeXLink;
model->updateActions();
return true;
} else
return false;
}
void Link::deactivate ()
{
// Remove pointers from XLinkItem to Link and
// delete XLinkObj
// qDebug()<<"Link::deactivate ******************************";
xLinkState=deleteXLink;
if (beginLinkItem) beginLinkItem->setLink (NULL);
if (endLinkItem) endLinkItem->setLink (NULL);
if (xlo)
{
delete (xlo);
xlo=NULL;
}
}
Link::XLinkState Link::getState()
{
return xLinkState;
}
void Link::removeXLinkItem (XLinkItem *xli)
{
// Only mark _one_ end for removal here!
if (xli==beginLinkItem) beginLinkItem=NULL;
if (xli==endLinkItem) endLinkItem=NULL;
xLinkState=deleteXLink;
}
void Link::updateLink()
{
if(xlo ) xlo->updateXLink();
}
QString Link::saveToDir ()
{
// qDebug()<<"Link::saveToDir this="<<this<<" beginBranch="<<beginBranch<<" endBranch="<<endBranch<<" state="<<xLinkState;
QString s="";
if (beginBranch && endBranch && xLinkState==activeXLink)
{
if (beginBranch==endBranch )
qWarning ("Link::saveToDir ignored, because beginBranch==endBranch, ");
else
{
QString colAttr=attribut ("color",pen.color().name());
QString widAttr=attribut ("width",QString().setNum(pen.width(),10));
QString styAttr=attribut ("penstyle",penStyleToString (pen.style()));
QString ctrlAttr;
QString typeAttr;
switch (type)
{
case Linear:
typeAttr=attribut("type","Linear");
break;
case Bezier:
typeAttr=attribut("type","Bezier");
if (xlo)
{
ctrlAttr +=attribut ("c0",pointToString (xlo->getC0() ) );
ctrlAttr +=attribut ("c1",pointToString (xlo->getC1() ) );
}
break;
}
QString begSelAttr=attribut ("beginID",model->getSelectString(beginBranch));
QString endSelAttr=attribut ("endID", model->getSelectString(endBranch));
QString styleAttr;
if (xlo)
{
styleAttr = QString(" styleBegin=\"%1\"").arg( ArrowObj::styleToString( xlo->getStyleBegin() ));
styleAttr+= QString(" styleEnd=\"%1\"" ).arg( ArrowObj::styleToString( xlo->getStyleEnd() ));
}
s=singleElement ("xlink",
colAttr
+widAttr
+styAttr
+typeAttr
+ctrlAttr
+begSelAttr
+endSelAttr
+styleAttr);
}
}
return s;
}
XLinkObj* Link::getXLinkObj()
{
return xlo;
}
XLinkObj* Link::createMapObj()
{
if (!xlo) xlo=new XLinkObj (beginBranch->getLMO(),this);
xlo->setVisibility();
return xlo;
}
MapObj* Link::getMO()
{
return xlo;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.