Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,11 @@ def headerData(self, section, orientation, role):
else:
return super().headerData(section, orientation, role)

def removeRows(self, row, count, parent=QModelIndex()):
self._l.debug(f"Deleting rows from '{row}' to '{row + count - 1}'.")
self.beginRemoveRows(parent, row, row + count - 1)
for _ in range(count):
self._data.drop(self._data.index[row], inplace=True)
def removeRows(self, rows, count, parent=QModelIndex()):

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not the nicest thing to do maybe, as it differs from the behaviour of QAbstractTableModel

self._l.debug(f"Deleting rows {rows}.")
self.beginRemoveRows(parent, rows[0], rows[-1])
indices = [self._data.index[r] for r in rows]
self._data.drop(indices, inplace=True)
self.endRemoveRows()
self.layoutChanged.emit()
self._l.debug(f"Dataframe length after deleting: {self._data.shape[0]}")
Expand Down Expand Up @@ -642,9 +642,7 @@ def _init_ui(self) -> None:
self.setSizeAdjustPolicy(QHeaderView.AdjustToContents)
self.setSizePolicy(SIZE_MIN_EXPANDING, SIZE_MIN_EXPANDING)
self.setSelectionBehavior(QAbstractItemView.SelectRows)
# NOTE: ContiguousSelection is needed as PandasModel.removeRows() does
# not support arbitrary row selection
self.setSelectionMode(QAbstractItemView.ContiguousSelection)
self.setSelectionMode(QAbstractItemView.ExtendedSelection)
self.setEditTriggers(QAbstractItemView.NoEditTriggers)
self.setSortingEnabled(True)

Expand Down Expand Up @@ -692,7 +690,7 @@ def keyPressEvent(self, e: Optional[QKeyEvent]) -> None:
rows = self.selectionModel().selectedRows()
if len(rows) == 0:
return
self.model().removeRows(rows[0].row(), len(rows), rows[0])
self.model().removeRows([r.row() for r in rows], len(rows), rows[0])
self.selectionModel().clearSelection()
super().keyPressEvent(e)

Expand Down