Menu

[efa3d9]: / src / xlink.cpp  Maximize  Restore  History

Download this file

248 lines (206 with data), 5.7 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
#include <QDebug>
#include "xlink.h"
#include "branchitem.h"
#include "misc.h"
#include "scripting-xlink-wrapper.h"
#include "vymmodel.h"
#include "xlinkitem.h"
#include "xlinkobj.h"
class VymModel;
/////////////////////////////////////////////////////////////////
// Link
/////////////////////////////////////////////////////////////////
XLink::XLink(VymModel *m)
{
// qDebug() << "Const Link () this="<<this;
model = m;
init();
}
XLink::~XLink()
{
//std::cout << "Destr XLink" << this << std::endl << std::flush;
delete (xlo);
if (xlinkWrapperInt) {
delete xlinkWrapperInt;
xlinkWrapperInt = nullptr;
}
// XLinkItems are deleted in VymModel::deleteXLinkInt()
}
void XLink::init()
{
uuid = QUuid::createUuid();
xlo = nullptr;
beginBranch = nullptr;
endBranch = nullptr;
beginXLinkItemInt = nullptr;
endXLinkItemInt = nullptr;
stateInt = XLink::undefinedXLink;
type = Bezier;
pen = model->mapDesign()->defXLinkPen();
xlinkWrapperInt = nullptr;
}
void XLink::setUuid(const QString &id) { uuid = QUuid(id); }
QUuid XLink::getUuid() { return uuid; }
VymModel* XLink::getModel() { return model; }
XLinkWrapper* XLink::xlinkWrapper()
{
if (!xlinkWrapperInt)
xlinkWrapperInt = new XLinkWrapper(this);
return xlinkWrapperInt;
}
void XLink::setBeginBranch(BranchItem *bi)
{
if (bi) {
stateInt = initXLink;
beginBranch = bi;
}
}
BranchItem *XLink::getBeginBranch() { return beginBranch; }
void XLink::setEndBranch(BranchItem *bi)
{
if (bi)
endBranch = bi;
}
BranchItem *XLink::getEndBranch() { return endBranch; }
void XLink::setEndPoint(QPointF p)
{
// Used only while creating the link, without endBranch
if (xlo)
xlo->setEnd(p);
}
void XLink::setBeginXLinkItem(XLinkItem *li)
{
if (li) {
stateInt = initXLink;
beginXLinkItemInt = li;
}
}
XLinkItem *XLink::beginXLinkItem() { return beginXLinkItemInt;}
void XLink::setEndXLinkItem(XLinkItem *li)
{
if (li) {
stateInt = initXLink;
endXLinkItemInt = li;
}
}
XLinkItem *XLink::endXLinkItem() { return endXLinkItemInt; }
void XLink::setPen(const QPen &p)
{
pen = p;
if (xlo)
xlo->updateGeometry();
}
void XLink::unsetXLinkItem(XLinkItem *xli)
{
// If deleting XLink is triggered from destructor of XLinkItem,
// VymModel will not try to delete XLinkItem a second time
if (xli == beginXLinkItemInt) {
beginXLinkItemInt = nullptr;
} else if (xli == endXLinkItemInt) {
endXLinkItemInt = nullptr;
}
stateInt = deleteXLink;
}
QPen XLink::getPen() { return pen; }
void XLink::setLinkType(const QString &s)
{
if (s == "Linear")
type = Linear;
else if (s == "Bezier")
type = Bezier;
else
qWarning() << "XLink::setLinkType Unknown type: " << s;
}
void XLink::setStyleBegin(const QString &s)
{
if (xlo) {
xlo->setStyleBegin(s);
xlo->updateGeometry();
}
}
QString XLink::getStyleBeginString()
{
if (xlo)
return ArrowObj::styleToString(xlo->getStyleBegin());
else
return QString();
}
void XLink::setStyleEnd(const QString &s)
{
if (xlo) {
xlo->setStyleEnd(s);
xlo->updateGeometry();
}
}
QString XLink::getStyleEndString()
{
if (xlo)
return ArrowObj::styleToString(xlo->getStyleEnd());
else
return QString();
}
bool XLink::activate()
{
if (beginBranch && endBranch) {
if (beginBranch == endBranch)
return false;
stateInt = activeXLink;
if (xlo) xlo->initC1();
model->updateActions();
return true;
}
else
return false;
}
XLink::XLinkState XLink::state() { return stateInt; }
void XLink::updateXLink()
{
if (xlo)
xlo->updateGeometry();
}
QString XLink::saveToDir()
{
// qDebug()<<"XLink::saveToDir this="<<this<<"
// beginBranch="<<beginBranch<<" endBranch="<<endBranch<<"
// state="<<stateInt;
QString s = "";
if (beginBranch && endBranch && stateInt == activeXLink) {
if (beginBranch == endBranch)
qWarning(
"XLink::saveToDir ignored, because beginBranch==endBranch, ");
else {
QStringList attrs;
attrs << attribute("color", pen.color().name());
attrs << attribute("width", QString().setNum(pen.width(), 10));
attrs << attribute("penstyle", penStyleToString(pen.style()));
switch (type) {
case Linear:
attrs << attribute("type", "Linear");
break;
case Bezier:
attrs << attribute("type", "Bezier");
if (xlo) {
attrs << attribute("c0", pointToString(xlo->getC0()));
attrs << attribute("c1", pointToString(xlo->getC1()));
}
break;
}
attrs << attribute("beginID", beginBranch->getUuid().toString());
attrs << attribute("endID", endBranch->getUuid().toString());
if (xlo) {
attrs << attribute("styleBegin", ArrowObj::styleToString(xlo->getStyleBegin()));
attrs << attribute("styleEnd", ArrowObj::styleToString(xlo->getStyleEnd()));
}
attrs << attribute("uuid", uuid.toString());
s = singleElement("xlink", attrs.join(""));
}
}
return s;
}
XLinkObj *XLink::getXLinkObj() { return xlo; }
XLinkObj *XLink::createXLinkObj()
{
if (!xlo)
xlo = new XLinkObj(this);
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.