Page MenuHomePhabricator

Initial auto-selection does not work in QmitkSingleNodeSelectionWidget
Open, NormalPublic

Description

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?

Event Timeline

kislinsk triaged this task as High priority.
kislinsk created this task.
kislinsk moved this task from Backlog to Cycle on the MITK (v2023.04) board.

It is indeed two conflicting mechanisms.

Your proposed fix would break another behavior. It would not possible to have the widget optional and autoselecting at the same time.

One real fix that I see would be

  • to introduce a state (e.g. m_UnrevisedDataStorageReset) in QmitkSingleNodeSelectionWidget.
  • default is False.
  • QmitkSingleNodeSelectionWidget:::OnDataStorageChanged sets it to true.
  • QmitkSingleNodeSelectionWidget::ReviseSelectionChanged checks the state and if true calls DetermineAutoSelectNode with no argument. If false it is called like it is currently.
  • At the end RevisedSelectionChanged sets m_UnrevisedDataStorageReset to false again.

But I would not say that this issue is release relevant as we have an easy mitigation strategy at hand. Move the widget->->SetAutoSelectNewNodes(true) to the end of your CreateQtPartControl (when everything else for the widget is configred and connected) (see SegmentationView for example).
Then it works already like expected.

Because we have more pressing issues (and my solution might miss something), I would propose to

  1. use the workarround for now
  2. move that issue out of the cycle and lower priority
  3. document that problem in the SingelNodeSelection class including the work arround and the reference to the open issue.
kislinsk lowered the priority of this task from High to Normal.Apr 13 2023, 9:36 AM
kislinsk moved this task from Cycle to Backlog on the MITK (v2023.04) board.