Page MenuHomePhabricator

QmitkDataStorageComboBox dosn't work in case of data node deletion
Closed, ResolvedPublic

Description

When you delete a data node which is currently selected by a QmitkDataStorageComboBox, its selection changes to another still existing data node. And event is fired when the selection changes. However, the newly selected node, which is given as a parameter of the event, is still the old deleted data node. This bug affects all views using the QmitkDataStorageComboBox and leads to undefined behavior or application crashes.

Event Timeline

https://dl.dropbox.com/u/5822501/test.mitk

Open this file. Look at Boolean Operations View (Segmentation). (A) should be selected. Delete (A). Selection switches to (B) or (C). Press "Union". CRASH

Rough call stack:

QmitkDataManagerView::RemoveSelectedNodes()
StandaloneDataStorage::Remove()
DataStorage::EmitRemoveNodeEvent()
QmitkDataStorageComboBox::RemoveNode(DataNode*)
QmitkDataStorageComboBox::RemoveNode(int)

QmitkDataStorageComboBox maintains an internal list of items besides the model item list of the QComboBox. In RemoveNode(int index), the index is shortly out of sync since the item was already deleted from the model but not from the internal list m_Nodes. During this phase events are emitted (e.g. OnSelectionChanged) that still point to the already deleted data node instead of the newly selected node.

To fix this, I reordered the lines which erase the item/node:

m_Nodes.erase(m_Nodes.begin() + index); Do this first
this->removeItem(index);
An THAN this

[c7c894]: Merge branch 'bug-14919-SelectionChangeOnDataNodeRemoval'

Merged commits:

2013-04-10 15:24:03 Stefan Kislinskiy [6bfc93]
Fixed out-of-sync index (Qt model index vs. m_Nodes index).