diff --git a/src/Model/Geometry/Reach.py b/src/Model/Geometry/Reach.py index 04272f23a3c3773449378325be3e90b7c988d76c..2e3a6b8098730e948b2eb8c306429d5a0f950084 100644 --- a/src/Model/Geometry/Reach.py +++ b/src/Model/Geometry/Reach.py @@ -99,30 +99,18 @@ class Reach: self._update_profile_numbers() - def delete(self, list_index: list): + def delete(self, index: int): """Delete some elements in profile list Args: - list_index: The list of element index + index: The index to delete Returns: Nothing. """ - try: - if list_index: - indices = sorted(list(set(list_index)), reverse=True) - for idx in indices: - try: - self._profiles.pop(idx) - self._update_profile_numbers() - except IndexError: - print(f"Invalid profile index: {idx}") - except TypeError: - if isinstance(list_index, int): - self._profiles.pop(list_index) - self._update_profile_numbers() - else: - raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'") + self._profiles.pop(index) + self._update_profile_numbers() + def get_x(self): return [profile.x() for profile in self.profiles] diff --git a/src/View/Geometry/GeometryWindow.py b/src/View/Geometry/GeometryWindow.py index 7948e380bdb80e1f01dd434cccdae8ae4c94e1bb..9a339bdfeb4fce48fd91a2d6696b0f75572ee481 100644 --- a/src/View/Geometry/GeometryWindow.py +++ b/src/View/Geometry/GeometryWindow.py @@ -377,7 +377,7 @@ class GeometryWindow(QMainWindow, WindowToolKit): )) if len(rows) > 0: - self._tablemodel.remove_rows(rows) + self._tablemodel.remove_row(rows[0]) self.update_plot_xy() self.select_current_profile() @@ -385,7 +385,6 @@ class GeometryWindow(QMainWindow, WindowToolKit): self.plot_kpc() self.changed_slider_value() - def index_selected_row(self): return self.tableView\ .selectionModel()\ diff --git a/src/View/Geometry/PlotXY.py b/src/View/Geometry/PlotXY.py index 7e182447b4752c98abd73bc0ba6dab765aaddf80..fdb5fcc112807ecd7ef88d0143d5a675d2a6a05b 100644 --- a/src/View/Geometry/PlotXY.py +++ b/src/View/Geometry/PlotXY.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from tools import timer +from tools import timer, trace from View.Plot.APlot import APlot from PyQt5.QtCore import ( @@ -115,7 +115,6 @@ class PlotXY(APlot): self.after_plot_selected.set_data(self.data.profile(after).x(), self.data.profile(after).y()) self.after_plot_selected.set_visible(True) - else: for ind in range(self.data.number_profiles): self.line_xy[ind][0].set_data( @@ -123,13 +122,14 @@ class PlotXY(APlot): self.data.profile(ind).y() ) + self.data.compute_guidelines() x_complete = self.data.get_guidelines_x() y_complete = self.data.get_guidelines_y() - for i in range(len(self.line_gl)): - self.line_gl[i].set_data( - [x[i] for x in x_complete], - [y[i] for y in y_complete] + for ind in range(len(self.line_gl)): + self.line_gl[ind][0].set_data( + x_complete[ind], + y_complete[ind] ) self.canvas.figure.tight_layout() diff --git a/src/View/Geometry/ReachUndoCommand.py b/src/View/Geometry/ReachUndoCommand.py index a96b71eb54fcebb8a566e0ddbdd2b57bc9661e9c..92764f67a6f2864dc21fdb85179737f9d5b5967e 100644 --- a/src/View/Geometry/ReachUndoCommand.py +++ b/src/View/Geometry/ReachUndoCommand.py @@ -47,18 +47,18 @@ class AddCommand(QUndoCommand): self._reach.insert(self._index) class DelCommand(QUndoCommand): - def __init__(self, reach, index, profile): + def __init__(self, reach, index): QUndoCommand.__init__(self) self._reach = reach self._index = index - self._profile = profile + self._profile = self._reach.profile(index) def undo(self): self._reach.insert_profile(self._index, self._profile) def redo(self): - self._reach.delete([self._index]) + self._reach.delete(self._index) 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 6ad89bbfa08c000c71ffdfccd3a16ab705401a47..210e336b012cce16afd647d0c49e063d8d1830a4 100644 --- a/src/View/Geometry/qtableview_reach.py +++ b/src/View/Geometry/qtableview_reach.py @@ -150,14 +150,14 @@ class PandasModelEditable(QAbstractTableModel): self.endInsertRows() self.layoutChanged.emit() - def remove_rows(self, list_row_selected, parent=QModelIndex()): - self.beginRemoveRows(parent, list_row_selected[0], list_row_selected[-1]) - - if len(list_row_selected) >= 1: - if len(list_row_selected) == 1: - self._reach.delete_profile(list_row_selected[0]) - elif len(list_row_selected) > 1: - self._reach.delete_profile_rows(list_row_selected) + def remove_row(self, row, parent=QModelIndex()): + self.beginRemoveRows(parent, row, row - 1) + + self._undo_stack.push( + DelCommand( + self._reach, row + ) + ) self.endRemoveRows() self.layoutChanged.emit()