From 606b9919e377d21330100c0b7d9b6f584ddf6939 Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Mon, 11 May 2026 14:58:42 +0200 Subject: [PATCH] stab window D90 AdisTS (undo / redo / add / delete / save / load), all should work correctly --- src/View/D90AdisTS/Table.py | 16 ++++++++++++---- src/View/D90AdisTS/Window.py | 22 +++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/View/D90AdisTS/Table.py b/src/View/D90AdisTS/Table.py index 090a5a8b..f926bf41 100644 --- a/src/View/D90AdisTS/Table.py +++ b/src/View/D90AdisTS/Table.py @@ -62,9 +62,12 @@ class ComboBoxDelegate(QItemDelegate): if self._mode == "rk": reach_id = self._d90_spec_lst[index.row()].reach - reach = next(filter( - lambda edge: edge.id == reach_id, self._data.edges() - )) + reach = next( + filter( + lambda edge: edge.id == reach_id, self._data.edges() + ), + None + ) if reach_id is not None: val = list( @@ -116,6 +119,8 @@ class D90TableModel(PamhyrTableModel): super(D90TableModel, self).__init__(data=data, **kwargs) self._data = data + if self._undo is not None: + self._undo.indexChanged.connect(lambda _: self.update()) def _setup_lst(self): self._lst = list( @@ -216,7 +221,8 @@ class D90TableModel(PamhyrTableModel): DelCommand( self._data, self._data._data, - [data_rows[id(self._lst[row])] for row in rows] + [data_rows[id(self._lst[row])] for row in rows + if 0 <= row < len(self._lst)] ) ) @@ -226,8 +232,10 @@ class D90TableModel(PamhyrTableModel): def undo(self): self._undo.undo() + self._setup_lst() self.layoutChanged.emit() def redo(self): self._undo.redo() + self._setup_lst() self.layoutChanged.emit() diff --git a/src/View/D90AdisTS/Window.py b/src/View/D90AdisTS/Window.py index cb36d690..0af4f4b6 100644 --- a/src/View/D90AdisTS/Window.py +++ b/src/View/D90AdisTS/Window.py @@ -43,7 +43,7 @@ from PyQt5.QtWidgets import ( from Modules import Modules -from View.InitialConditionsAdisTS.UndoCommand import ( +from View.D90AdisTS.UndoCommand import ( SetCommand, ) @@ -264,11 +264,27 @@ class D90AdisTSWindow(PamhyrWindow): self._update() def _undo(self): - self._table.undo() + undo_stack = self._undo_stack + if undo_stack is None or not undo_stack.canUndo(): + return + + if isinstance(undo_stack.command(undo_stack.index() - 1), SetCommand): + self._table.undo() + else: + self._table_spec.undo() + self._update() def _redo(self): - self._table.redo() + undo_stack = self._undo_stack + if undo_stack is None or not undo_stack.canRedo(): + return + + if isinstance(undo_stack.command(undo_stack.index()), SetCommand): + self._table.redo() + else: + self._table_spec.redo() + self._update() def add(self):