Dear Slicer developers,
I would like to get some feedback on a potential fix in qMRMLSubjectHierarchyTreeView: ENH: qMRMLSubjectHierarchyTreeView: call setCurrentIndex rather than … · Slicer/Slicer@1fdee41 · GitHub
In my custom 3d slicer app I load a case which:
- contains only 2 volumes in the data tree
- sets the current item of a qMRMLSubjectHierarchyCombobox to the last volume (this combobox is used in my custom module)
Scenario 1:
- Load the case.
- Remove the last volume from the data tree.
- Result: the combobox displays None.
Scenario 2:
- Load the case.
- Click on the combobox and click on the last volume (which is already selected)
- Remove the last volume from the data tree.
- Result: the combobox displays the first volume.
Analysis
When the last volume is removed from the data tree, this method is called:
QAbstractItemView::rowsAboutToBeRemoved
This method checks the current index:
if the current index is valid then the next index is selected (previous volume => scenario 2)
if the current index is NOT valid then no index is selected (None => scenario 1)
In scenario 1 there is no current index because qMRMLSubjectHierarchyCombobox simply calls qMRMLSubjectHierarchyTreeView which calls only selectionModel()->select which does not set the current index.
As you can see in this commit , this->selectionModel()->setCurrentIndex selects the item AND set the current index.
Do you see any case where an item must be selected without being the current index ?
Do you see any other issue ?
Best regards