| 248 | |
| 249 | |
| 250 | void |
| 251 | FlowView:: |
| 252 | deleteSelectedNodes() |
| 253 | { |
| 254 | // Delete the selected connections first, ensuring that they won't be |
| 255 | // automatically deleted when selected nodes are deleted (deleting a node |
| 256 | // deletes some connections as well) |
| 257 | startNodeDelete(); |
| 258 | |
| 259 | for (QGraphicsItem * item : _scene->selectedItems()) |
| 260 | { |
| 261 | if (auto c = qgraphicsitem_cast<ConnectionGraphicsObject*>(item)) |
| 262 | _scene->deleteConnection(c->connection()); |
| 263 | } |
| 264 | |
| 265 | // Delete the nodes; this will delete many of the connections. |
| 266 | // Selected connections were already deleted prior to this loop, otherwise |
| 267 | // qgraphicsitem_cast<NodeGraphicsObject*>(item) could be a use-after-free |
| 268 | // when a selected connection is deleted by deleting the node. |
| 269 | for (QGraphicsItem * item : _scene->selectedItems()) |
| 270 | { |
| 271 | if (auto n = qgraphicsitem_cast<NodeGraphicsObject*>(item)) |
| 272 | _scene->removeNode(n->node()); |
| 273 | } |
| 274 | |
| 275 | finishNodeDelete(); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | void |