Skip to content

Commit f9c38d3

Browse files
committed
fixed copying or plotting multiple rows in the editor when they were selected via drag and drop on headers (closes #59)
1 parent 45cfa28 commit f9c38d3

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

larray_editor/arraywidget.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@
7474
from itertools import chain
7575

7676
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
7878
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,
8080
QMessageBox, QMenu, QLabel, QSpinBox, QWidget, QToolTip, QShortcut, QScrollBar,
8181
QHBoxLayout, QVBoxLayout, QGridLayout, QSizePolicy, QFrame)
8282

@@ -333,13 +333,19 @@ def updateSectionWidth(self, logicalIndex, oldSize, newSize):
333333
def selectNewRow(self, row_index):
334334
# if not MultiSelection mode activated, selectRow will unselect previously
335335
# 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
336339
self.setSelectionMode(QTableView.MultiSelection)
337340
self.selectRow(row_index)
338341
self.setSelectionMode(QTableView.ContiguousSelection)
339342

340343
def selectNewColumn(self, column_index):
341344
# if not MultiSelection mode activated, selectColumn will unselect previously
342345
# 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
343349
self.setSelectionMode(QTableView.MultiSelection)
344350
self.selectColumn(column_index)
345351
self.setSelectionMode(QTableView.ContiguousSelection)
@@ -427,13 +433,12 @@ def _selection_bounds(self, none_selects_all=True):
427433
return 0, model.total_rows, 0, model.total_cols
428434
else:
429435
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+
437442
# if not all rows/columns have been loaded
438443
if row_min == 0 and row_max == self.model().rows_loaded - 1:
439444
row_max = self.model().total_rows - 1

0 commit comments

Comments
 (0)