Skip to content

Commit

Permalink
itemselectionmodel: Slight cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Jan 12, 2021
1 parent af0ec1a commit 1b95643
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions Orange/widgets/utils/itemselectionmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def select(self, selection: Union[QItemSelection, QModelIndex],

model = self.model()

def to_ranges(spans):
return list(range(*r) for r in spans)

if flags & QItemSelectionModel.Current: # no current selection support
flags &= ~QItemSelectionModel.Current
if flags & QItemSelectionModel.Toggle: # no toggle support either
Expand All @@ -62,9 +59,8 @@ def to_ranges(spans):
selection = QItemSelection()
for row_range, col_range in \
product(to_ranges(sel_rows), to_ranges(sel_cols)):
selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
qitemselection_select_range(
selection, model, row_range, col_range
)
elif flags & (QItemSelectionModel.Select |
QItemSelectionModel.Deselect):
Expand All @@ -76,15 +72,13 @@ def to_ranges(spans):
ext_selection = QItemSelection()
for row_range, col_range in \
product(to_ranges(rows), to_ranges(sel_cols)):
ext_selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
qitemselection_select_range(
ext_selection, model, row_range, col_range
)
for row_range, col_range in \
product(to_ranges(sel_rows), to_ranges(cols)):
ext_selection.select(
model.index(row_range.start, col_range.start),
model.index(row_range.stop - 1, col_range.stop - 1)
qitemselection_select_range(
ext_selection, model, row_range, col_range
)
selection.merge(ext_selection, QItemSelectionModel.Select)
super().select(selection, flags)
Expand Down Expand Up @@ -209,15 +203,17 @@ def qitemselection_select_range(
)


def to_ranges(spans: Iterable[Tuple[int, int]]) -> Sequence[range]:
return list(starmap(range, spans))


class SymmetricSelectionModel(QItemSelectionModel):
"""
Item selection model ensuring the selection is symmetric
"""
def select(self, selection: Union[QItemSelection, QModelIndex],
flags: QItemSelectionModel.SelectionFlags) -> None:
def to_ranges(rngs: Iterable[Tuple[int, int]]) -> Sequence[range]:
return list(starmap(range, rngs))
if isinstance(selection, QModelIndex):
selection = QItemSelection(selection, selection)

Expand Down

0 comments on commit 1b95643

Please sign in to comment.