From d9aea9eb3c1c568eaa23e22f218a46c3eed3f162 Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Tue, 16 Sep 2025 17:40:02 +0200 Subject: [PATCH 1/4] REPLines: Fix undo commands. --- src/Model/Tools/PamhyrListExt.py | 9 ++++++--- src/View/REPLines/List.py | 18 +++++++++++++++++- src/View/REPLines/UndoCommand.py | 13 ++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Model/Tools/PamhyrListExt.py b/src/Model/Tools/PamhyrListExt.py index 18796590..c45f0942 100644 --- a/src/Model/Tools/PamhyrListExt.py +++ b/src/Model/Tools/PamhyrListExt.py @@ -83,7 +83,7 @@ class PamhyrModelList(SQLSubModel): return self.lst.index(el) def get(self, index): - if len(self._lst) == 0: + if len(self.lst) <= index : return None return self.lst[index] @@ -122,7 +122,10 @@ class PamhyrModelList(SQLSubModel): raise NotImplementedMethodeError(self, self.new) def insert(self, index, new): - self._lst.insert(index, new) + if new in self._lst: + new.set_as_not_deleted() + else: + self._lst.insert(index, new) if self._status is not None: self._status.modified() @@ -165,7 +168,7 @@ class PamhyrModelList(SQLSubModel): lambda x: x[1], filter( lambda x: x[0] in indexes, - enumerate(self.lst) + enumerate(self._lst) ) ) ) diff --git a/src/View/REPLines/List.py b/src/View/REPLines/List.py index 1c6cb119..31ea8b91 100644 --- a/src/View/REPLines/List.py +++ b/src/View/REPLines/List.py @@ -38,6 +38,19 @@ logger = logging.getLogger() class ListModel(PamhyrListModel): + def get_true_data_row(self, row): + el = self._data.get(row) + + return next( + map( + lambda e: e[0], + filter( + lambda e: e[1] == el, + enumerate(self._data._lst) + ) + ), 0 + ) + def data(self, index, role): row = index.row() column = index.column() @@ -65,17 +78,20 @@ class ListModel(PamhyrListModel): return QVariant() def add(self, row): + row = self.get_true_data_row(row) + self._undo.push( AddCommand( self._data, row ) ) + self.update() def delete(self, row): self._undo.push( DelCommand( - self._data, row + self._data, self._data.lines[row] ) ) self.update() diff --git a/src/View/REPLines/UndoCommand.py b/src/View/REPLines/UndoCommand.py index 13b672db..cb783bf6 100644 --- a/src/View/REPLines/UndoCommand.py +++ b/src/View/REPLines/UndoCommand.py @@ -58,25 +58,24 @@ class AddCommand(QUndoCommand): self._new = None def undo(self): - self._lines.delete([self._new]) + self._new.set_as_deleted() def redo(self): if self._new is None: self._new = self._lines.new(self._row) else: - self._lines.insert(self._row, self._new) + self._new.set_as_not_deleted() class DelCommand(QUndoCommand): - def __init__(self, lines, row): + def __init__(self, lines, data): QUndoCommand.__init__(self) self._lines = lines - self._row = row - self._old = self._lines.get(row) + self._data = data def undo(self): - self._lines.insert(self._row, self._old) + self._data.set_as_not_deleted() def redo(self): - self._lines.delete_i([self._row]) + self._data.set_as_deleted() From e2e8c5ec9e6ba6d422b8a671b8b71ba79bb1a86b Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 18 Sep 2025 10:45:31 +0200 Subject: [PATCH 2/4] AddFile: Fix undo commands. --- src/View/AdditionalFiles/List.py | 18 +++++++++++++++++- src/View/AdditionalFiles/UndoCommand.py | 16 ++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/View/AdditionalFiles/List.py b/src/View/AdditionalFiles/List.py index a2579aba..53875f20 100644 --- a/src/View/AdditionalFiles/List.py +++ b/src/View/AdditionalFiles/List.py @@ -38,6 +38,20 @@ logger = logging.getLogger() class ListModel(PamhyrListModel): + def get_true_data_row(self, row): + el = self._data.get(row) + + return next( + map( + lambda e: e[0], + filter( + lambda e: e[1] == el, + enumerate(self._data._lst) + ) + ), 0 + ) + + def data(self, index, role): row = index.row() column = index.column() @@ -65,6 +79,8 @@ class ListModel(PamhyrListModel): return QVariant() def add(self, row): + row = self.get_true_data_row(row) + self._undo.push( AddCommand( self._data, row @@ -75,7 +91,7 @@ class ListModel(PamhyrListModel): def delete(self, row): self._undo.push( DelCommand( - self._data, row + self._data, self._data.files[row] ) ) self.update() diff --git a/src/View/AdditionalFiles/UndoCommand.py b/src/View/AdditionalFiles/UndoCommand.py index 43f7554f..1e597b84 100644 --- a/src/View/AdditionalFiles/UndoCommand.py +++ b/src/View/AdditionalFiles/UndoCommand.py @@ -58,27 +58,23 @@ class AddCommand(QUndoCommand): self._new = None def undo(self): - self._files.delete([self._new]) + self._new.set_as_deleted() def redo(self): if self._new is None: self._new = self._files.new(self._row) else: - self._files.undelete([self._new]) - # self._files.insert(self._row, self._new) - + self._new.set_as_not_deleted() class DelCommand(QUndoCommand): - def __init__(self, files, row): + def __init__(self, files, line): QUndoCommand.__init__(self) self._files = files - self._row = row - self._old = self._files.get(row) + self._line = line def undo(self): - self._files.undelete([self._old]) - # self._files.insert(self._row, self._old) + self._line.set_as_not_deleted() def redo(self): - self._files.delete_i([self._row]) + self._line.set_as_deleted() From 589e591d3bbf163004a67a21edbbee58ddeaa6af Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 18 Sep 2025 11:19:30 +0200 Subject: [PATCH 3/4] Strickler: Fix undo command. --- src/View/Stricklers/Table.py | 23 ++++++++++++++++++++++- src/View/Stricklers/UndoCommand.py | 20 ++++++++------------ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/View/Stricklers/Table.py b/src/View/Stricklers/Table.py index 067b95e0..3d80cdad 100644 --- a/src/View/Stricklers/Table.py +++ b/src/View/Stricklers/Table.py @@ -48,6 +48,20 @@ _translate = QCoreApplication.translate class TableModel(PamhyrTableModel): + def get_true_data_row(self, row): + el = self._data.get(row) + + return next( + map( + lambda e: e[0], + filter( + lambda e: e[1] == el, + enumerate(self._data._lst) + ) + ), 0 + ) + + def data(self, index, role): if role != Qt.ItemDataRole.DisplayRole: return QVariant() @@ -109,6 +123,8 @@ class TableModel(PamhyrTableModel): def add(self, row, parent=QModelIndex()): self.beginInsertRows(parent, row, row - 1) + row = self.get_true_data_row(row) + self._undo.push( AddCommand( self._data, row @@ -123,7 +139,12 @@ class TableModel(PamhyrTableModel): self._undo.push( DelCommand( - self._data, rows + self._data, list( + map( + lambda r: self._data.get(r), + rows + ) + ) ) ) diff --git a/src/View/Stricklers/UndoCommand.py b/src/View/Stricklers/UndoCommand.py index eff13736..97737917 100644 --- a/src/View/Stricklers/UndoCommand.py +++ b/src/View/Stricklers/UndoCommand.py @@ -102,33 +102,29 @@ class AddCommand(QUndoCommand): self._new = None def undo(self): - self._data.delete_i([self._index]) + self._new.set_as_deleted() def redo(self): if self._new is None: self._new = self._data.new(self._index) else: - self._data.undelete([self._new]) - # self._data.insert(self._index, self._new) + self._new.set_as_not_deleted() class DelCommand(QUndoCommand): - def __init__(self, data, rows): + def __init__(self, data, lines): QUndoCommand.__init__(self) self._data = data - self._rows = rows - - self._el = [] - for row in rows: - self._el.append(self._data.get(row)) - self._el.sort() + self._lines = lines def undo(self): - self._data.undelete(self._el) + for line in self._lines: + line.set_as_not_deleted() def redo(self): - self._data.delete(self._el) + for line in self._lines: + line.set_as_deleted() class SortCommand(QUndoCommand): From 8bcf776813f62d4c6212ddc7145845bee2d8610f Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 18 Sep 2025 11:26:20 +0200 Subject: [PATCH 4/4] Pamhyr: Fix PEP8. --- src/Model/SedimentLayer/SedimentLayer.py | 1 + src/Model/Tools/PamhyrDB.py | 1 - src/Model/Tools/PamhyrListExt.py | 2 +- src/View/AdditionalFiles/List.py | 1 - src/View/AdditionalFiles/UndoCommand.py | 1 + src/View/LateralContribution/UndoCommand.py | 1 + src/View/Scenarios/ContextMenu.py | 2 +- src/View/Stricklers/Table.py | 1 - 8 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/SedimentLayer/SedimentLayer.py b/src/Model/SedimentLayer/SedimentLayer.py index f20e99fa..4ec52541 100644 --- a/src/Model/SedimentLayer/SedimentLayer.py +++ b/src/Model/SedimentLayer/SedimentLayer.py @@ -275,6 +275,7 @@ class Layer(SQLSubModel): self._sl.modified() + class SedimentLayer(SQLSubModel): _sub_classes = [Layer] diff --git a/src/Model/Tools/PamhyrDB.py b/src/Model/Tools/PamhyrDB.py index edb47dfa..9bba82ce 100644 --- a/src/Model/Tools/PamhyrDB.py +++ b/src/Model/Tools/PamhyrDB.py @@ -414,7 +414,6 @@ class SQLSubModel(PamhyrID): """ raise NotImplementedMethodeError(self, self._db_save) - def _data_traversal(self, predicate=lambda obj, data: True, modifier=lambda obj, data: None, diff --git a/src/Model/Tools/PamhyrListExt.py b/src/Model/Tools/PamhyrListExt.py index c45f0942..07d0ed58 100644 --- a/src/Model/Tools/PamhyrListExt.py +++ b/src/Model/Tools/PamhyrListExt.py @@ -83,7 +83,7 @@ class PamhyrModelList(SQLSubModel): return self.lst.index(el) def get(self, index): - if len(self.lst) <= index : + if len(self.lst) <= index: return None return self.lst[index] diff --git a/src/View/AdditionalFiles/List.py b/src/View/AdditionalFiles/List.py index 53875f20..98d09e2c 100644 --- a/src/View/AdditionalFiles/List.py +++ b/src/View/AdditionalFiles/List.py @@ -51,7 +51,6 @@ class ListModel(PamhyrListModel): ), 0 ) - def data(self, index, role): row = index.row() column = index.column() diff --git a/src/View/AdditionalFiles/UndoCommand.py b/src/View/AdditionalFiles/UndoCommand.py index 1e597b84..bcc75f49 100644 --- a/src/View/AdditionalFiles/UndoCommand.py +++ b/src/View/AdditionalFiles/UndoCommand.py @@ -66,6 +66,7 @@ class AddCommand(QUndoCommand): else: self._new.set_as_not_deleted() + class DelCommand(QUndoCommand): def __init__(self, files, line): QUndoCommand.__init__(self) diff --git a/src/View/LateralContribution/UndoCommand.py b/src/View/LateralContribution/UndoCommand.py index 61113525..f7be897c 100644 --- a/src/View/LateralContribution/UndoCommand.py +++ b/src/View/LateralContribution/UndoCommand.py @@ -134,6 +134,7 @@ class AddCommand(QUndoCommand): else: self._new.set_as_not_deleted() + class DelCommand(QUndoCommand): def __init__(self, lcs, tab, rows): QUndoCommand.__init__(self) diff --git a/src/View/Scenarios/ContextMenu.py b/src/View/Scenarios/ContextMenu.py index 5d55a960..319c0d92 100644 --- a/src/View/Scenarios/ContextMenu.py +++ b/src/View/Scenarios/ContextMenu.py @@ -71,7 +71,7 @@ class ScenarioMenu(AbstractMenu): ) action = self._exec() - if action == None: + if action is None: return elif action == select: self._parent.select_scenario(item) diff --git a/src/View/Stricklers/Table.py b/src/View/Stricklers/Table.py index 3d80cdad..2f97e684 100644 --- a/src/View/Stricklers/Table.py +++ b/src/View/Stricklers/Table.py @@ -61,7 +61,6 @@ class TableModel(PamhyrTableModel): ), 0 ) - def data(self, index, role): if role != Qt.ItemDataRole.DisplayRole: return QVariant()