stab window DIF AdisTS (undo / redo / add / delete / save / load), all should work correctly

This commit is contained in:
Dylan Jeannin committed 2026-05-11 12:52:33 +02:00
1 parent 7565d8ee95
commit faff877c80
5 files changed
+65 -30

No files matched your search

+23 -4
View File
@@ -118,9 +118,16 @@ class DIFTableModel(PamhyrTableModel):
super(DIFTableModel, 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 = self._data._data
self._lst = list(
filter(
lambda dif: dif._deleted is False,
self._data._data
)
)
def rowCount(self, parent):
return len(self._lst)
@@ -183,7 +190,10 @@ class DIFTableModel(PamhyrTableModel):
if self._headers[column] != "reach":
self._undo.push(
SetCommandSpec(
self._lst, row, self._headers[column], value
self._lst,
row,
self._headers[column],
value
)
)
elif self._headers[column] == "reach":
@@ -211,25 +221,34 @@ class DIFTableModel(PamhyrTableModel):
)
)
self._setup_lst()
self.endInsertRows()
self.layoutChanged.emit()
def delete(self, rows, parent=QModelIndex()):
self.beginRemoveRows(parent, rows[0], rows[-1])
data_rows = {
id(dif): i for i, dif in enumerate(self._data._data)
}
self._undo.push(
DelCommand(
self._data, self._lst, rows
self._data,
self._data._data,
[data_rows[id(self._lst[row])] for row in rows
if 0 <= row < len(self._lst)]
)
)
self._setup_lst()
self.endRemoveRows()
self.layoutChanged.emit()
def undo(self):
self._undo.undo()
self._setup_lst()
self.layoutChanged.emit()
def redo(self):
self._undo.redo()
self._setup_lst()
self.layoutChanged.emit()
+5 -6
View File
@@ -136,11 +136,11 @@ class SetCommandSpec(QUndoCommand):
class AddCommand(QUndoCommand):
def __init__(self, data, ics_spec, index):
def __init__(self, data, dif_spec, index):
QUndoCommand.__init__(self)
self._data = data
self._ics_spec = ics_spec
self._dif_spec = dif_spec
self._index = index
self._new = None
@@ -155,17 +155,16 @@ class AddCommand(QUndoCommand):
class DelCommand(QUndoCommand):
def __init__(self, data, ics_spec, rows):
def __init__(self, data, dif_spec, rows):
QUndoCommand.__init__(self)
self._data = data
self._ics_spec = ics_spec
self._dif_spec = dif_spec
self._rows = rows
# self._data = data
self._ic = []
for row in rows:
self._ic.append((row, self._ics_spec[row]))
self._ic.append((row, self._dif_spec[row]))
self._ic.sort()
def undo(self):
+18 -2
View File
@@ -51,6 +51,8 @@ from View.DIFAdisTS.Table import (
DIFTableModel, ComboBoxDelegate,
)
from View.DIFAdisTS.UndoCommand import SetCommand
from View.DIFAdisTS.translate import DIFAdisTSTranslate
from Solver.Mage import Mage8
@@ -272,11 +274,25 @@ class DIFAdisTSWindow(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):