nodeview: worked around qt issue where the selection signal would still be sent after an item was deleted

This commit is contained in:
itsmattkc
2020-03-17 00:34:32 +11:00
parent 1c192100c2
commit 72eb3a5d82
3 changed files with 32 additions and 10 deletions
+27
View File
@@ -10,6 +10,15 @@ NodeViewScene::NodeViewScene(QObject *parent) :
void NodeViewScene::clear()
{
// Deselect everything (prevents signals that a selection has changed after deleting an object)
DeselectAll();
// HACK: QGraphicsScene contains some sort of internal hashing of the selected items which doesn't update unless
// we call a function like this. That means even though we deselect all items above, QGraphicsScene will
// continue to incorrectly signal selectionChanged() when items that were selected (but are now not) get
// deleted. Calling this function appears to update the internal cache and prevent this.
selectedItems();
{
QHash<Node*, NodeViewItem*>::const_iterator i;
for (i=item_map_.begin();i!=item_map_.end();i++) {
@@ -27,6 +36,24 @@ void NodeViewScene::clear()
}
}
void NodeViewScene::SelectAll()
{
QList<QGraphicsItem *> all_items = this->items();
foreach (QGraphicsItem* i, all_items) {
i->setSelected(true);
}
}
void NodeViewScene::DeselectAll()
{
QList<QGraphicsItem *> selected_items = this->selectedItems();
foreach (QGraphicsItem* i, selected_items) {
i->setSelected(false);
}
}
NodeViewItem *NodeViewScene::NodeToUIObject(Node *n)
{
return item_map_.value(n);