From e615a6b9d45aef7bc43e2169f6848410d3b0033a Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Mon, 4 May 2026 13:03:18 +0200 Subject: [PATCH] debug index matching in delete function for LCAdisTS --- src/View/LateralContributionsAdisTS/Table.py | 18 +++++++++++++----- .../LateralContributionsAdisTS/UndoCommand.py | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/View/LateralContributionsAdisTS/Table.py b/src/View/LateralContributionsAdisTS/Table.py index 1bd0b2b0..04c1e933 100644 --- a/src/View/LateralContributionsAdisTS/Table.py +++ b/src/View/LateralContributionsAdisTS/Table.py @@ -121,7 +121,7 @@ class TableModel(PamhyrTableModel): def _setup_lst(self): if self._lcs_list is not None: self._lcs_pol_list = [ - lcs for lcs in self._lcs_list.lst + lcs for lcs in self._lcs_list._lst if lcs.pollutant == self._pollutant ] @@ -209,9 +209,14 @@ class TableModel(PamhyrTableModel): def delete(self, rows, parent=QModelIndex()): self.beginRemoveRows(parent, rows[0], rows[-1]) - global_rows = list( - map(self._global_row, rows) - ) + row_by_lc = { + id(lc): row for row, lc in enumerate(self._lcs_list._lst) + } + global_rows = [ + row_by_lc[id(self._lst[row])] + for row in rows + if 0 <= row < len(self._lst) + ] self._undo.push( DelCommand( self._lcs_list, global_rows @@ -241,4 +246,7 @@ class TableModel(PamhyrTableModel): bc = self.get(row) if bc is None: return None - return self._lcs_list.index(bc) + return next( + index for index, lcs in enumerate(self._lcs_list._lst) + if lcs is bc + ) diff --git a/src/View/LateralContributionsAdisTS/UndoCommand.py b/src/View/LateralContributionsAdisTS/UndoCommand.py index 371d7408..08cf408a 100644 --- a/src/View/LateralContributionsAdisTS/UndoCommand.py +++ b/src/View/LateralContributionsAdisTS/UndoCommand.py @@ -109,7 +109,7 @@ class DelCommand(QUndoCommand): self._lc = [] for row in rows: - self._lc.append((row, self._lcs.get(row))) + self._lc.append((row, self._lcs._lst[row])) self._lc.sort() def undo(self):