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

geometry: Fix delete reach row.

Showing with 23 additions and 36 deletions
+23 -36
......@@ -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]
......
......@@ -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()\
......
# -*- 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()
......
......@@ -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):
......
......@@ -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()
......
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