Commit f2d2ea9f authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

geometry: Add feature to delete multiple line.

Showing with 26 additions and 14 deletions
+26 -14
...@@ -93,7 +93,7 @@ class GeometryWindow(QMainWindow, WindowToolKit): ...@@ -93,7 +93,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.ui.btn_move_down.clicked.connect(self.move_row_down) self.ui.btn_move_down.clicked.connect(self.move_row_down)
self.ui.btn_end_editing.clicked.connect(self.handleSave) self.ui.btn_end_editing.clicked.connect(self.handleSave)
self.ui.btn_add.clicked.connect(self.insert_row) 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.btn_edit.clicked.connect(self.edit_profile)
self.ui.verticalSlider.valueChanged.connect(self.changed_slider_value) self.ui.verticalSlider.valueChanged.connect(self.changed_slider_value)
...@@ -374,13 +374,17 @@ class GeometryWindow(QMainWindow, WindowToolKit): ...@@ -374,13 +374,17 @@ class GeometryWindow(QMainWindow, WindowToolKit):
row = self.index_selected_row() row = self.index_selected_row()
self._tablemodel.insert_row(row + 1) self._tablemodel.insert_row(row + 1)
def delete_row(self): def delete_rows(self):
rows = list(set( rows = sorted(
[index.row() for index in self.tableView.selectedIndexes()] list(
)) set(
[index.row() for index in self.tableView.selectedIndexes()]
)
)
)
if len(rows) > 0: if len(rows) > 0:
self._tablemodel.remove_row(rows[0]) self._tablemodel.remove_rows(rows)
self.update_plot_xy() self.update_plot_xy()
self.select_current_profile() self.select_current_profile()
......
...@@ -47,18 +47,26 @@ class AddCommand(QUndoCommand): ...@@ -47,18 +47,26 @@ class AddCommand(QUndoCommand):
self._reach.insert(self._index) self._reach.insert(self._index)
class DelCommand(QUndoCommand): class DelCommand(QUndoCommand):
def __init__(self, reach, index): def __init__(self, reach, rows):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._reach = reach self._reach = reach
self._index = index self._rows = rows
self._profile = self._reach.profile(index)
self._profile = []
for row in rows:
self._profile.append(self._reach.profile(row))
self._profile.reverse()
def undo(self): 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): def redo(self):
self._reach.delete(self._index) row = self._rows[0]
for _ in self._rows:
self._reach.delete(row)
class SortCommand(QUndoCommand): class SortCommand(QUndoCommand):
def __init__(self, reach, _reverse): def __init__(self, reach, _reverse):
......
...@@ -152,12 +152,12 @@ class PandasModelEditable(QAbstractTableModel): ...@@ -152,12 +152,12 @@ class PandasModelEditable(QAbstractTableModel):
self.endInsertRows() self.endInsertRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def remove_row(self, row, parent=QModelIndex()): def remove_rows(self, rows, parent=QModelIndex()):
self.beginRemoveRows(parent, row, row - 1) self.beginRemoveRows(parent, rows[0], rows[-1])
self._undo_stack.push( self._undo_stack.push(
DelCommand( DelCommand(
self._reach, row self._reach, rows
) )
) )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment