nodeview: automatically deselect blocks that have been removed

Fixes segfault attempting to access and select an item that's already been
removed.
This commit is contained in:
itsmattkc
2020-08-05 23:56:42 +10:00
parent d5dce29b22
commit 02c0fb7316
2 changed files with 11 additions and 0 deletions
+9
View File
@@ -74,6 +74,7 @@ void NodeView::SetGraph(NodeGraph *graph)
if (graph_ != nullptr) {
disconnect(graph_, &NodeGraph::NodeAdded, &scene_, &NodeViewScene::AddNode);
disconnect(graph_, &NodeGraph::NodeRemoved, &scene_, &NodeViewScene::RemoveNode);
disconnect(graph_, &NodeGraph::NodeRemoved, this, &NodeView::GraphNodeRemoved);
disconnect(graph_, &NodeGraph::EdgeAdded, this, &NodeView::GraphEdgeAdded);
disconnect(graph_, &NodeGraph::EdgeRemoved, this, &NodeView::GraphEdgeRemoved);
}
@@ -89,6 +90,7 @@ void NodeView::SetGraph(NodeGraph *graph)
if (graph_ != nullptr) {
connect(graph_, &NodeGraph::NodeAdded, &scene_, &NodeViewScene::AddNode);
connect(graph_, &NodeGraph::NodeRemoved, &scene_, &NodeViewScene::RemoveNode);
connect(graph_, &NodeGraph::NodeRemoved, this, &NodeView::GraphNodeRemoved);
connect(graph_, &NodeGraph::EdgeAdded, this, &NodeView::GraphEdgeAdded);
connect(graph_, &NodeGraph::EdgeRemoved, this, &NodeView::GraphEdgeRemoved);
@@ -977,6 +979,13 @@ void NodeView::AssociatedNodeDestroyed()
DisassociateNode(static_cast<Node*>(sender()), true);
}
void NodeView::GraphNodeRemoved(Node *node)
{
if (selected_blocks_.contains(static_cast<Block*>(node))) {
DeselectBlocks({static_cast<Block*>(node)});
}
}
void NodeView::GraphEdgeAdded(NodeEdgePtr edge)
{
Node* input_node = edge->input()->parentNode();