@@ -137,25 +137,19 @@ void
137137NodeGraphicsObject::
138138moveConnections () const
139139{
140-
141140 NodeState const & nodeState = _node.nodeState ();
142141
143- auto moveConnections =
144- [&](PortType portType)
145- {
146- auto const & connectionEntries =
142+ for (PortType portType: {PortType::In, PortType::Out})
143+ {
144+ auto const & connectionEntries =
147145 nodeState.getEntries (portType);
148146
149- for (auto const & connections : connectionEntries)
150- {
151- for (auto & con : connections)
152- con.second ->getConnectionGraphicsObject ().move ();
153- }
154- };
155-
156- moveConnections (PortType::In);
157-
158- moveConnections (PortType::Out);
147+ for (auto const & connections : connectionEntries)
148+ {
149+ for (auto & con : connections)
150+ con.second ->getConnectionGraphicsObject ().move ();
151+ }
152+ };
159153}
160154
161155void NodeGraphicsObject::lock (bool locked)
@@ -205,60 +199,55 @@ mousePressEvent(QGraphicsSceneMouseEvent * event)
205199 _scene.clearSelection ();
206200 }
207201
208- auto clickPort =
209- [&](PortType portToCheck)
210- {
211- NodeGeometry & nodeGeometry = _node.nodeGeometry ();
212-
213- // TODO do not pass sceneTransform
214- int portIndex = nodeGeometry.checkHitScenePoint (portToCheck,
215- event->scenePos (),
216- sceneTransform ());
202+ for (PortType portToCheck: {PortType::In, PortType::Out})
203+ {
204+ NodeGeometry & nodeGeometry = _node.nodeGeometry ();
217205
218- if (portIndex != INVALID )
219- {
220- NodeState const & nodeState = _node.nodeState ();
206+ // TODO do not pass sceneTransform
207+ int portIndex = nodeGeometry.checkHitScenePoint (portToCheck,
208+ event->scenePos (),
209+ sceneTransform ());
210+ if (portIndex != INVALID )
211+ {
212+ NodeState const & nodeState = _node.nodeState ();
221213
222- std::unordered_map<QUuid, Connection*> connections =
214+ std::unordered_map<QUuid, Connection*> connections =
223215 nodeState.connections (portToCheck, portIndex);
224216
225- // start dragging existing connection
226- if (!connections.empty () && portToCheck == PortType::In)
227- {
228- auto con = connections.begin ()->second ;
217+ // start dragging existing connection
218+ if (!connections.empty () && portToCheck == PortType::In)
219+ {
220+ auto con = connections.begin ()->second ;
229221
230- NodeConnectionInteraction interaction (_node, *con, _scene);
222+ NodeConnectionInteraction interaction (_node, *con, _scene);
231223
232- interaction.disconnect (portToCheck);
233- }
234- else // initialize new Connection
224+ interaction.disconnect (portToCheck);
225+ }
226+ else // initialize new Connection
227+ {
228+ if (portToCheck == PortType::Out)
235229 {
236- if (portToCheck == PortType::Out)
230+ const auto outPolicy = _node.nodeDataModel ()->portOutConnectionPolicy (portIndex);
231+ if (!connections.empty () &&
232+ outPolicy == NodeDataModel::ConnectionPolicy::One)
237233 {
238- const auto outPolicy = _node.nodeDataModel ()->portOutConnectionPolicy (portIndex);
239- if (!connections.empty () &&
240- outPolicy == NodeDataModel::ConnectionPolicy::One)
241- {
242- _scene.deleteConnection ( *connections.begin ()->second );
243- }
244-
245- // todo add to FlowScene
246- auto connection = _scene.createConnection (portToCheck,
247- _node,
248- portIndex);
249-
250- _node.nodeState ().setConnection (portToCheck,
251- portIndex,
252- *connection);
253-
254- connection->getConnectionGraphicsObject ().grabMouse ();
234+ _scene.deleteConnection ( *connections.begin ()->second );
255235 }
236+
237+ // todo add to FlowScene
238+ auto connection = _scene.createConnection (portToCheck,
239+ _node,
240+ portIndex);
241+
242+ _node.nodeState ().setConnection (portToCheck,
243+ portIndex,
244+ *connection);
245+
246+ connection->getConnectionGraphicsObject ().grabMouse ();
256247 }
257248 }
258- };
259-
260- clickPort (PortType::In);
261- clickPort (PortType::Out);
249+ }
250+ }
262251
263252 auto pos = event->pos ();
264253 auto & geom = _node.nodeGeometry ();
0 commit comments