forked from paceholder/nodeeditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlowSceneModel.cpp
More file actions
63 lines (51 loc) · 1.34 KB
/
FlowSceneModel.cpp
File metadata and controls
63 lines (51 loc) · 1.34 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
#include "FlowSceneModel.hpp"
#include "NodeIndex.hpp"
namespace QtNodes
{
bool
FlowSceneModel::
removeNodeWithConnections(NodeIndex const& index)
{
// delete the conenctions that node has first
auto deleteConnections =
[&](PortType ty) -> bool
{
for (PortIndex portID = 0; (size_t)portID < nodePortCount(index, ty); ++portID)
{
auto inputConnections = nodePortConnections(index, portID, ty);
for (const auto& conn : inputConnections)
{
// try to remove it
bool success;
if (ty == PortType::In)
{
success = removeConnection(conn.first, conn.second, index, portID);
}
else {
success = removeConnection(index, portID, conn.first, conn.second);
}
// failed, abort the node deletion
if (!success)
{
return false;
}
}
}
return true;
};
bool success = deleteConnections(PortType::In);
if (!success)
return false;
success = deleteConnections(PortType::Out);
if (!success)
return false;
// if we get here, then try to remove the node itsself
return removeNode(index);
}
NodeIndex
FlowSceneModel::
createIndex(const QUuid& id, void* internalPointer) const
{
return NodeIndex(id, internalPointer, this);
}
} // namespace QtNodes