Skip to content

Commit 87f0d38

Browse files
facontidavidepaceholder
authored andcommitted
Prefer for loop over lambda (paceholder#181)
1 parent b3a3e98 commit 87f0d38

File tree

5 files changed

+170
-211
lines changed

5 files changed

+170
-211
lines changed

src/ConnectionGraphicsObject.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,7 @@ void
100100
ConnectionGraphicsObject::
101101
move()
102102
{
103-
104-
auto moveEndPoint =
105-
[this] (PortType portType)
103+
for(PortType portType: { PortType::In, PortType::Out } )
106104
{
107105
if (auto node = _connection.getNode(portType))
108106
{
@@ -115,22 +113,18 @@ move()
115113
portType,
116114
nodeGraphics.sceneTransform());
117115

118-
{
119-
QTransform sceneTransform = this->sceneTransform();
116+
QTransform sceneTransform = this->sceneTransform();
120117

121-
QPointF connectionPos = sceneTransform.inverted().map(scenePos);
118+
QPointF connectionPos = sceneTransform.inverted().map(scenePos);
122119

123-
_connection.connectionGeometry().setEndPoint(portType,
124-
connectionPos);
120+
_connection.connectionGeometry().setEndPoint(portType,
121+
connectionPos);
125122

126-
_connection.getConnectionGraphicsObject().setGeometryChanged();
127-
_connection.getConnectionGraphicsObject().update();
128-
}
123+
_connection.getConnectionGraphicsObject().setGeometryChanged();
124+
_connection.getConnectionGraphicsObject().update();
129125
}
130-
};
126+
}
131127

132-
moveEndPoint(PortType::In);
133-
moveEndPoint(PortType::Out);
134128
}
135129

136130
void ConnectionGraphicsObject::lock(bool locked)
@@ -221,7 +215,6 @@ mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
221215
}
222216
else if (_connection.connectionState().requiresPort())
223217
{
224-
225218
_scene.deleteConnection(_connection);
226219
}
227220
}

src/FlowScene.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,21 +223,17 @@ removeNode(Node& node)
223223
// call signal
224224
nodeDeleted(node);
225225

226-
auto deleteConnections =
227-
[&node, this] (PortType portType)
228-
{
229-
auto nodeState = node.nodeState();
230-
auto const & nodeEntries = nodeState.getEntries(portType);
231-
232-
for (auto &connections : nodeEntries)
233-
{
234-
for (auto const &pair : connections)
235-
deleteConnection(*pair.second);
236-
}
237-
};
226+
for(auto portType: {PortType::In,PortType::Out})
227+
{
228+
auto nodeState = node.nodeState();
229+
auto const & nodeEntries = nodeState.getEntries(portType);
238230

239-
deleteConnections(PortType::In);
240-
deleteConnections(PortType::Out);
231+
for (auto &connections : nodeEntries)
232+
{
233+
for (auto const &pair : connections)
234+
deleteConnection(*pair.second);
235+
}
236+
}
241237

242238
_nodes.erase(node.id());
243239
}

src/FlowView.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,8 @@ contextMenuEvent(QContextMenuEvent *event)
189189
{
190190
auto child = topLvlItem->child(i);
191191
auto modelName = child->data(0, Qt::UserRole).toString();
192-
if (modelName.contains(text, Qt::CaseInsensitive))
193-
{
194-
child->setHidden(false);
195-
}
196-
else
197-
{
198-
child->setHidden(true);
199-
}
192+
const bool match = (modelName.contains(text, Qt::CaseInsensitive));
193+
child->setHidden(!match);
200194
}
201195
}
202196
});

src/NodeGraphicsObject.cpp

Lines changed: 47 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -137,25 +137,19 @@ void
137137
NodeGraphicsObject::
138138
moveConnections() 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

161155
void 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

Comments
 (0)