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
+2 -10
View File
@@ -104,20 +104,12 @@ void NodeView::DeleteSelected()
void NodeView::SelectAll()
{
QList<QGraphicsItem *> all_items = this->items();
foreach (QGraphicsItem* i, all_items) {
i->setSelected(true);
}
scene_.SelectAll();
}
void NodeView::DeselectAll()
{
QList<QGraphicsItem *> selected_items = scene_.selectedItems();
foreach (QGraphicsItem* i, selected_items) {
i->setSelected(false);
}
scene_.DeselectAll();
}
void NodeView::Select(const QList<Node *> &nodes)
+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);
+3
View File
@@ -16,6 +16,9 @@ public:
void clear();
void SelectAll();
void DeselectAll();
/**
* @brief Retrieve the graphical widget corresponding to a specific Node
*