@@ -227,52 +227,32 @@ traverseGraphAndPopulateGraphicsObjects()
227227{
228228 auto allNodeIds = _graphModel.allNodeIds ();
229229
230- std::vector<ConnectionId> connectionsToCreate;
231-
232- while (!allNodeIds.empty ())
230+ // First create all the nodes.
231+ for (NodeId const nodeId : allNodeIds)
233232 {
234- std::queue<NodeId> fifo;
235-
236- auto firstId = *allNodeIds.begin ();
237- allNodeIds.erase (firstId);
233+ _nodeGraphicsObjects[nodeId] =
234+ std::make_unique<NodeGraphicsObject>(*this , nodeId);
235+ }
238236
239- fifo.push (firstId);
237+ // Then for each node check output connections and insert them.
238+ for (NodeId const nodeId : allNodeIds)
239+ {
240+ unsigned int nOutPorts =
241+ _graphModel.nodeData <PortCount>(nodeId, NodeRole::OutPortCount);
240242
241- while (!fifo. empty () )
243+ for (PortIndex index = 0 ; index < nOutPorts; ++index )
242244 {
243- auto nodeId = fifo.front ();
244- fifo.pop ();
245+ auto const & outConnectionIds =
246+ _graphModel.connections (nodeId,
247+ PortType::Out,
248+ index);
245249
246- _nodeGraphicsObjects[nodeId] =
247- std::make_unique<NodeGraphicsObject>(*this , nodeId);
248-
249- unsigned int nOutPorts =
250- _graphModel.nodeData (nodeId, NodeRole::OutPortCount).toUInt ();
251-
252- for (PortIndex index = 0 ; index < nOutPorts; ++index)
250+ for (auto cid : outConnectionIds)
253251 {
254- auto const & conns =
255- _graphModel.connections (nodeId,
256- PortType::Out,
257- index);
258-
259- for (auto cn : conns)
260- {
261- fifo.push (cn.inNodeId );
262-
263- allNodeIds.erase (cn.inNodeId );
264-
265- connectionsToCreate.push_back (cn);
266- }
252+ _connectionGraphicsObjects[cid] =
253+ std::make_unique<ConnectionGraphicsObject>(*this , cid);
267254 }
268- } // while
269- }
270-
271- for (auto const & connectionId : connectionsToCreate)
272- {
273- _connectionGraphicsObjects[connectionId] =
274- std::make_unique<ConnectionGraphicsObject>(*this ,
275- connectionId);
255+ }
276256 }
277257}
278258
0 commit comments