@@ -46,9 +46,6 @@ def select(self, selection: Union[QItemSelection, QModelIndex],
4646
4747 model = self .model ()
4848
49- def to_ranges (spans ):
50- return list (range (* r ) for r in spans )
51-
5249 if flags & QItemSelectionModel .Current : # no current selection support
5350 flags &= ~ QItemSelectionModel .Current
5451 if flags & QItemSelectionModel .Toggle : # no toggle support either
@@ -62,9 +59,8 @@ def to_ranges(spans):
6259 selection = QItemSelection ()
6360 for row_range , col_range in \
6461 product (to_ranges (sel_rows ), to_ranges (sel_cols )):
65- selection .select (
66- model .index (row_range .start , col_range .start ),
67- model .index (row_range .stop - 1 , col_range .stop - 1 )
62+ qitemselection_select_range (
63+ selection , model , row_range , col_range
6864 )
6965 elif flags & (QItemSelectionModel .Select |
7066 QItemSelectionModel .Deselect ):
@@ -76,15 +72,13 @@ def to_ranges(spans):
7672 ext_selection = QItemSelection ()
7773 for row_range , col_range in \
7874 product (to_ranges (rows ), to_ranges (sel_cols )):
79- ext_selection .select (
80- model .index (row_range .start , col_range .start ),
81- model .index (row_range .stop - 1 , col_range .stop - 1 )
75+ qitemselection_select_range (
76+ ext_selection , model , row_range , col_range
8277 )
8378 for row_range , col_range in \
8479 product (to_ranges (sel_rows ), to_ranges (cols )):
85- ext_selection .select (
86- model .index (row_range .start , col_range .start ),
87- model .index (row_range .stop - 1 , col_range .stop - 1 )
80+ qitemselection_select_range (
81+ ext_selection , model , row_range , col_range
8882 )
8983 selection .merge (ext_selection , QItemSelectionModel .Select )
9084 super ().select (selection , flags )
@@ -209,15 +203,17 @@ def qitemselection_select_range(
209203 )
210204
211205
206+ def to_ranges (spans : Iterable [Tuple [int , int ]]) -> Sequence [range ]:
207+ return list (starmap (range , spans ))
208+
209+
212210class SymmetricSelectionModel (QItemSelectionModel ):
213211 """
214212 Item selection model ensuring the selection is symmetric
215213
216214 """
217215 def select (self , selection : Union [QItemSelection , QModelIndex ],
218216 flags : QItemSelectionModel .SelectionFlags ) -> None :
219- def to_ranges (rngs : Iterable [Tuple [int , int ]]) -> Sequence [range ]:
220- return list (starmap (range , rngs ))
221217 if isinstance (selection , QModelIndex ):
222218 selection = QItemSelection (selection , selection )
223219
0 commit comments