-
Notifications
You must be signed in to change notification settings - Fork 0
/
Socket.cpp
85 lines (68 loc) · 1.72 KB
/
Socket.cpp
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
#include "Socket.h"
#include "Node.h"
#include "Edge.h"
#include "NodeScene.h"
#include <QDebug>
#include <QJsonObject>
Socket::Socket(Node *p) : parent(p)
{
// edges.reserve(8);
id = QUuid::createUuid().toString(QUuid::WithoutBraces);
}
Socket::~Socket()
{
edges.clear();
}
void Socket::setLocation(Location l)
{
location = l;
}
QJsonObject Socket::serialize()
{
QVariantMap map;
map.insert("id", id);
map.insert("index", index);
map.insert("location", QVariant::fromValue((int)location).toJsonValue());
map.insert("type", QVariant::fromValue((int)type).toJsonValue());
return QJsonObject::fromVariantMap(map);
}
Socket* Socket::deserialize(QJsonObject object, NodeScene *nodeScene)
{
// QString startingSocketId = object.value("start").toString();
// QString endingSocketId = object.value("end").toString();
// A = nodeScene->sockets.take(startingSocketId);
// parent = nodeScene->nodes.last();
// qDebug() << nodeScene;
edges.reserve(8);
id = object.value("id").toString();
index = object.value("index").toInt();
type = static_cast<Type>(object.value("type").toInt());
location = static_cast<Location>(object.value("location").toInt());
return this;
}
void Socket::setLocalSocketPosition(QPoint pos)
{
socketPosition = pos;
}
bool Socket::hasEdge() {
return !edges.isEmpty();
}
bool Socket::hasInputEdge()
{
return edges.first();
}
QPoint Socket::getSocketLocalPosition()
{
return socketPosition;
}
Node *Socket::getImmediateParent()
{
if (hasEdge()) {
return getEdges().first()->getOutputSocket()->getParent();
}
return nullptr;
}
QPoint Socket::getSocketGlobalPosition()
{
return socketPosition + parent->getPosition();
}