diff --git a/src/View/Geometry/GeometryWindow.py b/src/View/Geometry/GeometryWindow.py index 4fbd5e1e4f7e16e654a8cacce84c58c8304e49a2..2817dfeece0f347a65e1ebe41cbcf0a0bf95115a 100644 --- a/src/View/Geometry/GeometryWindow.py +++ b/src/View/Geometry/GeometryWindow.py @@ -93,7 +93,7 @@ class GeometryWindow(QMainWindow, WindowToolKit): self.ui.btn_move_down.clicked.connect(self.move_row_down) self.ui.btn_end_editing.clicked.connect(self.handleSave) self.ui.btn_add.clicked.connect(self.insert_row) - self.ui.btn_delete.clicked.connect(self.delete_row) + self.ui.btn_delete.clicked.connect(self.delete_rows) self.ui.btn_edit.clicked.connect(self.edit_profile) self.ui.verticalSlider.valueChanged.connect(self.changed_slider_value) @@ -374,13 +374,17 @@ class GeometryWindow(QMainWindow, WindowToolKit): row = self.index_selected_row() self._tablemodel.insert_row(row + 1) - def delete_row(self): - rows = list(set( - [index.row() for index in self.tableView.selectedIndexes()] - )) + def delete_rows(self): + rows = sorted( + list( + set( + [index.row() for index in self.tableView.selectedIndexes()] + ) + ) + ) if len(rows) > 0: - self._tablemodel.remove_row(rows[0]) + self._tablemodel.remove_rows(rows) self.update_plot_xy() self.select_current_profile() diff --git a/src/View/Geometry/ReachUndoCommand.py b/src/View/Geometry/ReachUndoCommand.py index e3e2191f43efca019df0c55b33dcdaa5e879fcd2..c783587bd0b68a6322db7bafc0946008ce55aa07 100644 --- a/src/View/Geometry/ReachUndoCommand.py +++ b/src/View/Geometry/ReachUndoCommand.py @@ -47,18 +47,26 @@ class AddCommand(QUndoCommand): self._reach.insert(self._index) class DelCommand(QUndoCommand): - def __init__(self, reach, index): + def __init__(self, reach, rows): QUndoCommand.__init__(self) self._reach = reach - self._index = index - self._profile = self._reach.profile(index) + self._rows = rows + + self._profile = [] + for row in rows: + self._profile.append(self._reach.profile(row)) + self._profile.reverse() def undo(self): - self._reach.insert_profile(self._index, self._profile) + row = self._rows[0] + for pro in self._profile: + self._reach.insert_profile(row, pro) def redo(self): - self._reach.delete(self._index) + row = self._rows[0] + for _ in self._rows: + self._reach.delete(row) class SortCommand(QUndoCommand): def __init__(self, reach, _reverse): diff --git a/src/View/Geometry/qtableview_reach.py b/src/View/Geometry/qtableview_reach.py index 07f4c0fdc269bb545ebc2d3461792cf192e97352..bb984e83f685f99fbb2731b7011fd8d23fbe1d8c 100644 --- a/src/View/Geometry/qtableview_reach.py +++ b/src/View/Geometry/qtableview_reach.py @@ -152,12 +152,12 @@ class PandasModelEditable(QAbstractTableModel): self.endInsertRows() self.layoutChanged.emit() - def remove_row(self, row, parent=QModelIndex()): - self.beginRemoveRows(parent, row, row - 1) + def remove_rows(self, rows, parent=QModelIndex()): + self.beginRemoveRows(parent, rows[0], rows[-1]) self._undo_stack.push( DelCommand( - self._reach, row + self._reach, rows ) )