nodeview: ensure nodes are disconnected when clearing

This commit is contained in:
itsmattkc
2021-07-16 21:32:34 -07:00
parent e5340dab81
commit 84e639606f
2 changed files with 22 additions and 5 deletions
+18 -5
View File
@@ -65,7 +65,10 @@ void NodeViewScene::clear()
// deleted. Calling this function appears to update the internal cache and prevent this.
selectedItems();
qDeleteAll(item_map_);
for (auto it=item_map_.cbegin(); it!=item_map_.cend(); it++) {
DisconnectNode(it.key());
delete it.value();
}
item_map_.clear();
qDeleteAll(edges_);
@@ -157,16 +160,14 @@ NodeViewItem* NodeViewScene::AddNode(Node* node)
addItem(item);
item_map_.insert(node, item);
connect(node, &Node::LabelChanged, this, &NodeViewScene::NodeAppearanceChanged);
connect(node, &Node::ColorChanged, this, &NodeViewScene::NodeAppearanceChanged);
ConnectNode(node);
return item;
}
void NodeViewScene::RemoveNode(Node *node)
{
disconnect(node, &Node::ColorChanged, this, &NodeViewScene::NodeAppearanceChanged);
disconnect(node, &Node::LabelChanged, this, &NodeViewScene::NodeAppearanceChanged);
DisconnectNode(node);
delete item_map_.take(node);
}
@@ -224,6 +225,18 @@ NodeViewEdge* NodeViewScene::AddEdgeInternal(const NodeOutput& output, const Nod
return edge_ui;
}
void NodeViewScene::ConnectNode(Node *n)
{
connect(n, &Node::LabelChanged, this, &NodeViewScene::NodeAppearanceChanged);
connect(n, &Node::ColorChanged, this, &NodeViewScene::NodeAppearanceChanged);
}
void NodeViewScene::DisconnectNode(Node *n)
{
disconnect(n, &Node::ColorChanged, this, &NodeViewScene::NodeAppearanceChanged);
disconnect(n, &Node::LabelChanged, this, &NodeViewScene::NodeAppearanceChanged);
}
Qt::Orientation NodeViewScene::GetFlowOrientation() const
{
return NodeViewCommon::GetFlowOrientation(direction_);