Skip to content

Commit

Permalink
ListViewFilter: Fix selection
Browse files Browse the repository at this point in the history
  • Loading branch information
VesnaT committed Jun 7, 2024
1 parent 326bed1 commit 450c621
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion orangewidget/utils/listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
QItemSelection,
QSize,
QItemSelectionModel,
Signal,
)

from orangewidget.utils.itemmodels import signal_blocking
Expand All @@ -20,6 +21,7 @@ class ListViewFilter(QListView):
"""
A QListView with implicit and transparent row filtering.
"""
sigSelectionChanged = Signal(object)

def __init__(
self,
Expand All @@ -46,16 +48,22 @@ def __init__(
self.set_source_model(model)
self.selectionModel().selectionChanged.connect(self.__on_sel_changed)

@property
def selection(self) -> QItemSelection:
return self.__selection

def __on_sel_changed(
self,
selected: QItemSelection,
deselected: QItemSelection
):
selected = self.model().mapSelectionToSource(selected)
deselected = self.model().mapSelectionToSource(deselected)
if self.selectionMode() == QListView.SelectionMode.SingleSelection:
self.__selection.clear()
self.__selection.merge(selected, QItemSelectionModel.Select)
self.__selection.merge(deselected, QItemSelectionModel.Deselect)
self.__select()
self.sigSelectionChanged.emit(self.__selection)

def __on_text_edited(self, string: str):
with signal_blocking(self.selectionModel()):
Expand Down

0 comments on commit 450c621

Please sign in to comment.