Scenario
- Data storage contains an auto-selectable node but a view with a QmitkSingleNodeSelectionWidget with auto-select mode is not yet open
- Open a view with a QmitkSingleNodeSelectionWidget with auto-select mode
Expected behavior
- The auto-selectable node is selected
Actual behavior
- Nothing is selected, the invalid selection error text is shown
Reason
- A view typically calls QmitkAbstractNodeSelectionWidget::SetDataStorage() on its initialization
- This method calls OnDataStorageChanged() which is correctly delegated to the QmitkSingleNodeSelectionWidget subclass and the node actually is selected for now
- However, also HandleChangeOfInternalSelection({}) is called:
- The method correctly notices that the current selection is different as the new selection is empty
- It calls ReviseSelectionChanged() with both the old and new selection so the QmitkSingleNodeSelectionWidget can decide to intervene which it should and actually does in this scenario
- Here's the catch:
QmitkSingleNodeSelectionWidget::ReviseSelectionChanged(const NodeList& oldInternalSelection, NodeList& newInternalSelection)
if (newInternalSelection.empty()) { if (m_AutoSelectNodes) { auto autoSelectedNode = this->DetermineAutoSelectNode(oldInternalSelection); if (autoSelectedNode.IsNotNull()) { newInternalSelection.append(autoSelectedNode); } } }
NOTE: The oldInternalSelection passed to DetermineAutoSelectNode() tells the method to ignore it in any checks so it cannot be determined to be selected anymore even so it definitely should.
Question
Is it an easy fix or is there a good reason to ignore the selection in that case for other scenarios?