|
74 | 74 | from itertools import chain
|
75 | 75 |
|
76 | 76 | import numpy as np
|
77 |
| -from qtpy.QtCore import Qt, QPoint, QItemSelection, QItemSelectionModel, QItemSelectionRange, Slot, Signal |
| 77 | +from qtpy.QtCore import Qt, QPoint, QItemSelection, QItemSelectionModel, Signal |
78 | 78 | from qtpy.QtGui import QDoubleValidator, QIntValidator, QKeySequence, QFontMetrics, QCursor
|
79 |
| -from qtpy.QtWidgets import (QApplication, QTableView, QHeaderView, QItemDelegate, QLineEdit, QCheckBox, |
| 79 | +from qtpy.QtWidgets import (QApplication, QTableView, QItemDelegate, QLineEdit, QCheckBox, |
80 | 80 | QMessageBox, QMenu, QLabel, QSpinBox, QWidget, QToolTip, QShortcut, QScrollBar,
|
81 | 81 | QHBoxLayout, QVBoxLayout, QGridLayout, QSizePolicy, QFrame)
|
82 | 82 |
|
@@ -333,13 +333,19 @@ def updateSectionWidth(self, logicalIndex, oldSize, newSize):
|
333 | 333 | def selectNewRow(self, row_index):
|
334 | 334 | # if not MultiSelection mode activated, selectRow will unselect previously
|
335 | 335 | # selected rows (unless SHIFT or CTRL key is pressed)
|
| 336 | + |
| 337 | + # this produces a selection with multiple QItemSelectionRange. We could merge them here, but it is |
| 338 | + # easier to handle in _selection_bounds |
336 | 339 | self.setSelectionMode(QTableView.MultiSelection)
|
337 | 340 | self.selectRow(row_index)
|
338 | 341 | self.setSelectionMode(QTableView.ContiguousSelection)
|
339 | 342 |
|
340 | 343 | def selectNewColumn(self, column_index):
|
341 | 344 | # if not MultiSelection mode activated, selectColumn will unselect previously
|
342 | 345 | # selected columns (unless SHIFT or CTRL key is pressed)
|
| 346 | + |
| 347 | + # this produces a selection with multiple QItemSelectionRange. We could merge them here, but it is |
| 348 | + # easier to handle in _selection_bounds |
343 | 349 | self.setSelectionMode(QTableView.MultiSelection)
|
344 | 350 | self.selectColumn(column_index)
|
345 | 351 | self.setSelectionMode(QTableView.ContiguousSelection)
|
@@ -427,13 +433,12 @@ def _selection_bounds(self, none_selects_all=True):
|
427 | 433 | return 0, model.total_rows, 0, model.total_cols
|
428 | 434 | else:
|
429 | 435 | return None
|
430 |
| - assert len(selection) == 1 |
431 |
| - srange = selection[0] |
432 |
| - assert isinstance(srange, QItemSelectionRange) |
433 |
| - row_min = srange.top() |
434 |
| - row_max = srange.bottom() |
435 |
| - col_min = srange.left() |
436 |
| - col_max = srange.right() |
| 436 | + # merge potentially multiple selections into one big rect |
| 437 | + row_min = min(srange.top() for srange in selection) |
| 438 | + row_max = max(srange.bottom() for srange in selection) |
| 439 | + col_min = min(srange.left() for srange in selection) |
| 440 | + col_max = max(srange.right() for srange in selection) |
| 441 | + |
437 | 442 | # if not all rows/columns have been loaded
|
438 | 443 | if row_min == 0 and row_max == self.model().rows_loaded - 1:
|
439 | 444 | row_max = self.model().total_rows - 1
|
|
0 commit comments