MCPcopy Create free account
hub / github.com/BehaviorTree/Groot / canConnect

Method canConnect

QtNodeEditor/src/NodeConnectionInteraction.cpp:27–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26
27bool
28NodeConnectionInteraction::
29canConnect(PortIndex &portIndex, TypeConverter & converter) const
30{
31 // 1) Connection requires a port
32
33 PortType requiredPort = connectionRequiredPort();
34
35
36 if (requiredPort == PortType::None)
37 {
38 return false;
39 }
40
41 // 1.5) Forbid connecting the node to itself
42 Node* node = _connection->getNode(oppositePort(requiredPort));
43
44 if (node == _node)
45 return false;
46
47 // 2) connection point is on top of the node port
48
49 QPointF connectionPoint = connectionEndScenePosition(requiredPort);
50
51 portIndex = nodePortIndexUnderScenePoint(requiredPort,
52 connectionPoint);
53
54 if (portIndex == INVALID)
55 {
56 return false;
57 }
58
59 // 3) Node port is vacant
60
61 // port should be empty
62 if (!nodePortIsEmpty(requiredPort, portIndex))
63 return false;
64
65 // 4) Connection type equals node port type, or there is a registered type conversion that can translate between the two
66
67 auto connectionDataType =
68 _connection->dataType(oppositePort(requiredPort));
69
70 auto const &modelTarget = _node->nodeDataModel();
71 NodeDataType candidateNodeDataType = modelTarget->dataType(requiredPort, portIndex);
72
73 if (connectionDataType.id != candidateNodeDataType.id)
74 {
75 if (requiredPort == PortType::In)
76 {
77 converter = _scene->registry().getTypeConverter(connectionDataType, candidateNodeDataType);
78 }
79 else if (requiredPort == PortType::Out)
80 {
81 converter = _scene->registry().getTypeConverter(candidateNodeDataType , connectionDataType);
82 }
83
84 return (converter != nullptr);

Callers

nothing calls this directly

Calls 2

oppositePortFunction · 0.85
dataTypeMethod · 0.80

Tested by

no test coverage detected