geometry: Fix delete reach row.

mesh
Pierre-Antoine Rouby 2023-04-20 13:59:26 +02:00
parent b93b6fe62d
commit 59c4463bf7
5 changed files with 22 additions and 35 deletions

View File

@ -99,30 +99,18 @@ class Reach:
self._update_profile_numbers() self._update_profile_numbers()
def delete(self, list_index: list): def delete(self, index: int):
"""Delete some elements in profile list """Delete some elements in profile list
Args: Args:
list_index: The list of element index index: The index to delete
Returns: Returns:
Nothing. Nothing.
""" """
try: self._profiles.pop(index)
if list_index: self._update_profile_numbers()
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)}'")
def get_x(self): def get_x(self):
return [profile.x() for profile in self.profiles] return [profile.x() for profile in self.profiles]

View File

@ -377,7 +377,7 @@ class GeometryWindow(QMainWindow, WindowToolKit):
)) ))
if len(rows) > 0: if len(rows) > 0:
self._tablemodel.remove_rows(rows) self._tablemodel.remove_row(rows[0])
self.update_plot_xy() self.update_plot_xy()
self.select_current_profile() self.select_current_profile()
@ -385,7 +385,6 @@ class GeometryWindow(QMainWindow, WindowToolKit):
self.plot_kpc() self.plot_kpc()
self.changed_slider_value() self.changed_slider_value()
def index_selected_row(self): def index_selected_row(self):
return self.tableView\ return self.tableView\
.selectionModel()\ .selectionModel()\

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from tools import timer from tools import timer, trace
from View.Plot.APlot import APlot from View.Plot.APlot import APlot
from PyQt5.QtCore import ( from PyQt5.QtCore import (
@ -115,7 +115,6 @@ class PlotXY(APlot):
self.after_plot_selected.set_data(self.data.profile(after).x(), self.after_plot_selected.set_data(self.data.profile(after).x(),
self.data.profile(after).y()) self.data.profile(after).y())
self.after_plot_selected.set_visible(True) self.after_plot_selected.set_visible(True)
else: else:
for ind in range(self.data.number_profiles): for ind in range(self.data.number_profiles):
self.line_xy[ind][0].set_data( self.line_xy[ind][0].set_data(
@ -123,13 +122,14 @@ class PlotXY(APlot):
self.data.profile(ind).y() self.data.profile(ind).y()
) )
self.data.compute_guidelines()
x_complete = self.data.get_guidelines_x() x_complete = self.data.get_guidelines_x()
y_complete = self.data.get_guidelines_y() y_complete = self.data.get_guidelines_y()
for i in range(len(self.line_gl)): for ind in range(len(self.line_gl)):
self.line_gl[i].set_data( self.line_gl[ind][0].set_data(
[x[i] for x in x_complete], x_complete[ind],
[y[i] for y in y_complete] y_complete[ind]
) )
self.canvas.figure.tight_layout() self.canvas.figure.tight_layout()

View File

@ -47,18 +47,18 @@ class AddCommand(QUndoCommand):
self._reach.insert(self._index) self._reach.insert(self._index)
class DelCommand(QUndoCommand): class DelCommand(QUndoCommand):
def __init__(self, reach, index, profile): def __init__(self, reach, index):
QUndoCommand.__init__(self) QUndoCommand.__init__(self)
self._reach = reach self._reach = reach
self._index = index self._index = index
self._profile = profile self._profile = self._reach.profile(index)
def undo(self): def undo(self):
self._reach.insert_profile(self._index, self._profile) self._reach.insert_profile(self._index, self._profile)
def redo(self): def redo(self):
self._reach.delete([self._index]) self._reach.delete(self._index)
class SortCommand(QUndoCommand): class SortCommand(QUndoCommand):
def __init__(self, reach, _reverse): def __init__(self, reach, _reverse):

View File

@ -150,14 +150,14 @@ class PandasModelEditable(QAbstractTableModel):
self.endInsertRows() self.endInsertRows()
self.layoutChanged.emit() self.layoutChanged.emit()
def remove_rows(self, list_row_selected, parent=QModelIndex()): def remove_row(self, row, parent=QModelIndex()):
self.beginRemoveRows(parent, list_row_selected[0], list_row_selected[-1]) self.beginRemoveRows(parent, row, row - 1)
if len(list_row_selected) >= 1: self._undo_stack.push(
if len(list_row_selected) == 1: DelCommand(
self._reach.delete_profile(list_row_selected[0]) self._reach, row
elif len(list_row_selected) > 1: )
self._reach.delete_profile_rows(list_row_selected) )
self.endRemoveRows() self.endRemoveRows()
self.layoutChanged.emit() self.layoutChanged.emit()