diff --git a/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py b/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py index 6f5bb5703c9f2e0f12509979d87e119202d74b18..0088fe8be66c0a61f9c182a5bdad83153d3684ba 100644 --- a/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py +++ b/src/Model/LateralContributionsAdisTS/LateralContributionAdisTS.py @@ -127,15 +127,11 @@ class LateralContributionAdisTS(SQLSubModel): execute(f"DELETE FROM lateral_contribution_adists WHERE id = {self.id}") execute(f"DELETE FROM lateral_contribution_data_adists WHERE lc = {self.id}") - node = -1 - if self._node is not None: - node = self._node - sql = ( "INSERT INTO " + "lateral_contribution_adists(id, pollutant, edge, begin_kp, end_kp) " + "VALUES (" + - f"{self.id}, {self._pollutant}, " + + f"{self.id}, {self._pollutant}, {self.edge}, " + f"{self._begin_kp}, {self._end_kp}" + ")" ) diff --git a/src/View/LateralContributionsAdisTS/Table.py b/src/View/LateralContributionsAdisTS/Table.py index 5b7fbd31c44c0afad4787c6def5dd6cf5006777c..3375cf5f2398b9983a6626cffccec817d23d074a 100644 --- a/src/View/LateralContributionsAdisTS/Table.py +++ b/src/View/LateralContributionsAdisTS/Table.py @@ -35,10 +35,9 @@ from PyQt5.QtWidgets import ( ) from View.LateralContributionsAdisTS.UndoCommand import ( - SetNameCommand, SetEdgeCommand, SetTypeCommand, + SetEdgeCommand, SetBeginCommand, SetEndCommand, - AddCommand, DelCommand, SortCommand, - MoveCommand, PasteCommand, DuplicateCommand, + AddCommand, DelCommand, ) from View.Tools.PamhyrTable import PamhyrTableModel @@ -156,19 +155,19 @@ class TableModel(PamhyrTableModel): if self._headers[column] == "edge": self._undo.push( SetEdgeCommand( - self._lst, self._tab, row, self._data.edge(value) + self._lcs_list, self._lst, row, self._data.edge(value).id ) ) elif self._headers[column] == "begin_kp": self._undo.push( SetBeginCommand( - self._lst, self._tab, row, value + self._lcs_list, self._lst, row, value ) ) elif self._headers[column] == "end_kp": self._undo.push( SetEndCommand( - self._lst, self._tab, row, value + self._lcs_list, self._lst, row, value ) ) except Exception as e: @@ -195,55 +194,13 @@ class TableModel(PamhyrTableModel): self._undo.push( DelCommand( - self._lst, self._tab, rows + self._lst, rows ) ) self.endRemoveRows() self.layoutChanged.emit() - def sort(self, _reverse, parent=QModelIndex()): - self.layoutAboutToBeChanged.emit() - self._undo.push( - SortCommand( - self._lst, self._tab, False - ) - ) - - self.layoutAboutToBeChanged.emit() - self.layoutChanged.emit() - def move_up(self, row, parent=QModelIndex()): - if row <= 0: - return - - target = row + 2 - - self.beginMoveRows(parent, row - 1, row - 1, parent, target) - - self._undo_stack.push( - MoveCommand( - self._lst, self._tab, "up", row - ) - ) - self.endMoveRows() - self.layoutChanged.emit() - - def move_down(self, index, parent=QModelIndex()): - if row > len(self._lst): - return - - target = row - - self.beginMoveRows(parent, row + 1, row + 1, parent, target) - - self._undo_stack.push( - MoveCommand( - self._lst, self._tab, "down", row - ) - ) - - self.endMoveRows() - self.layoutChanged.emit() diff --git a/src/View/LateralContributionsAdisTS/UndoCommand.py b/src/View/LateralContributionsAdisTS/UndoCommand.py index 707d61a1af041c56e1777ee508184b0f34d4981e..3b4340efc364b74a4db03fe5218177203cd1b1a8 100644 --- a/src/View/LateralContributionsAdisTS/UndoCommand.py +++ b/src/View/LateralContributionsAdisTS/UndoCommand.py @@ -28,93 +28,55 @@ from Model.LateralContributionsAdisTS.LateralContributionsAdisTSList import ( LateralContributionsAdisTSList ) - -class SetNameCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._index = index - self._old = self._lcs.get(self._tab, self._index).name - self._new = str(new_value) - - def undo(self): - self._lcs.get(self._tab, self._index).name = self._old - - def redo(self): - self._lcs.get(self._tab, self._index).name = self._new - - class SetBeginCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): + def __init__(self, lcs, lcs_lst, index, new_value): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).begin_kp + self._old = self._lcs_lst[self._index].begin_kp self._new = float(new_value) def undo(self): - self._lcs.get(self._tab, self._index).begin_kp = float(self._old) + self._lcs_lst[self._index].begin_kp = float(self._old) def redo(self): - self._lcs.get(self._tab, self._index).begin_kp = float(self._new) + self._lcs_lst[self._index].begin_kp = float(self._new) class SetEndCommand(QUndoCommand): - def __init__(self, lcs, tab, index, new_value): + def __init__(self, lcs, lcs_lst, index, new_value): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).end_kp + self._old = self._lcs_lst[self._index].end_kp self._new = float(new_value) def undo(self): - self._lcs.get(self._tab, self._index).end_kp = float(self._old) + self._lcs_lst[self._index].end_kp = float(self._old) def redo(self): - self._lcs.get(self._tab, self._index).end_kp = float(self._new) + self._lcs_lst[self._index].end_kp = float(self._new) class SetEdgeCommand(QUndoCommand): - def __init__(self, lcs, tab, index, edge): + def __init__(self, lcs, lcs_lst, index, edge): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab + self._lcs_lst = lcs_lst self._index = index - self._old = self._lcs.get(self._tab, self._index).edge + self._old = self._lcs_lst[self._index].edge self._new = edge def undo(self): - self._lcs.get(self._tab, self._index).edge = self._old + self._lcs_lst[self._index].edge = self._old def redo(self): - self._lcs.get(self._tab, self._index).edge = self._new - - -class SetTypeCommand(QUndoCommand): - def __init__(self, lcs, tab, index, _type): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._index = index - self._type = _type - self._old = self._lcs.get(self._tab, self._index) - self._new = self._lcs.get(self._tab, self._index)\ - .convert(self._type) - - def undo(self): - self._lcs.set(self._tab, self._index, self._old) - - def redo(self): - self._lcs.set(self._tab, self._index, self._new) - + self._lcs_lst[self._index].edge = self._new class AddCommand(QUndoCommand): def __init__(self, pollutant, lcs, lcs_lst, index): @@ -137,113 +99,22 @@ class AddCommand(QUndoCommand): class DelCommand(QUndoCommand): - def __init__(self, lcs, tab, rows): + def __init__(self, lcs, rows): QUndoCommand.__init__(self) self._lcs = lcs - self._tab = tab self._rows = rows self._bc = [] for row in rows: - self._bc.append((row, self._lcs.get(self._tab, row))) + self._bc.append((row, self._lcs[row])) self._bc.sort() def undo(self): for row, el in self._bc: - self._lcs.insert(self._tab, row, el) - - def redo(self): - self._lcs.delete_i(self._tab, self._rows) - - -class SortCommand(QUndoCommand): - def __init__(self, lcs, tab, _reverse): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._reverse = _reverse - - self._old = self._lcs.get_tab(self._tab) - self._indexes = None - - def undo(self): - ll = self._lcs.get_tab(self._tab) - self._lcs.sort( - self._tab, - key=lambda x: self._indexes[ll.index(x)] - ) - - def redo(self): - self._lcs.sort( - self._tab, - reverse=self._reverse, - key=lambda x: x.name - ) - if self._indexes is None: - self._indexes = list( - map( - lambda p: self._old.index(p), - self._lcs.get_tab(self._tab) - ) - ) - self._old = None - - -class MoveCommand(QUndoCommand): - def __init__(self, lcs, tab, up, i): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._up = up == "up" - self._i = i - - def undo(self): - if self._up: - self._lcs.move_up(self._tab, self._i) - else: - self._lcs.move_down(self._tab, self._i) + self._lcs.insert(row, el) def redo(self): - if self._up: - self._lcs.move_up(self._tab, self._i) - else: - self._lcs.move_down(self._tab, self._i) - - -class PasteCommand(QUndoCommand): - def __init__(self, lcs, tab, row, bc): - QUndoCommand.__init__(self) + for row in self._rows: + del self._lcs[row] - self._lcs = lcs - self._tab = tab - self._row = row - self._bc = deepcopy(bc) - self._bc.reverse() - - def undo(self): - self._lcs.delete(self._tab, self._bc) - - def redo(self): - for bc in self._bc: - self._lcs.insert(self._tab, self._row, bc) - - -class DuplicateCommand(QUndoCommand): - def __init__(self, lcs, tab, rows, bc): - QUndoCommand.__init__(self) - - self._lcs = lcs - self._tab = tab - self._rows = rows - self._bc = deepcopy(bc) - self._bc.reverse() - - def undo(self): - self._lcs.delete(self._tab, self._bc) - - def redo(self): - for bc in self._lcs: - self._lcs.insert(self._tab, self._rows[0], bc) diff --git a/src/View/LateralContributionsAdisTS/Window.py b/src/View/LateralContributionsAdisTS/Window.py index 69c3e0caba21754ad0420b8ced500fbaac2c26e1..3f6a9988b559a12e84826681ee87ff980137a26e 100644 --- a/src/View/LateralContributionsAdisTS/Window.py +++ b/src/View/LateralContributionsAdisTS/Window.py @@ -39,12 +39,6 @@ from PyQt5.QtWidgets import ( QComboBox, QVBoxLayout, QHeaderView, QTabWidget, ) -from View.LateralContributionsAdisTS.UndoCommand import ( - SetNameCommand, SetEdgeCommand, SetTypeCommand, - AddCommand, DelCommand, SortCommand, - MoveCommand, PasteCommand, DuplicateCommand, -) - from View.LateralContributionsAdisTS.Table import ( TableModel, ComboBoxDelegate ) @@ -179,16 +173,18 @@ class LateralContributionAdisTSWindow(PamhyrWindow): tab = "liquid" if len(rows) > 0: - edge = self._study.river\ + edge_id = self._study.river\ .lateral_contributions_adists.lst[rows[0]]\ .edge - if edge: + + if edge_id: + edge = next(filter(lambda e: e.id == edge_id, self._study.river.edges())) data = edge.reach - lc = self._lcs.get(tab, rows[0]) + lc = self._lcs.lst[rows[0]] highlight = (lc.begin_kp, lc.end_kp) - for delegate in self._delegate_kp: - delegate.data = edge + for delegate in self._delegate_kp: + delegate.data = edge self.plot = PlotXY( canvas=self.canvas, diff --git a/tests_cases/Enlargement/Enlargement.pamhyr b/tests_cases/Enlargement/Enlargement.pamhyr index 98658da7f9e9fecc5edd2bd0b851a201b9e5f636..6dc4a66a947b1dc12e17f996a08f4142ebdcc3bc 100644 Binary files a/tests_cases/Enlargement/Enlargement.pamhyr and b/tests_cases/Enlargement/Enlargement.pamhyr differ