mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-29 19:10:42 +01:00
Ensemble: Add undo command to ensemble edition.
This commit is contained in:
1 parent
93a4b44143
commit
97867080d9
4 files changed
+46
-7
No files matched your search
@@ -252,3 +252,19 @@ class Ensemble(SQLSubModel):
|
||||
def target_data(self, target_data):
|
||||
self._target_data = target_data
|
||||
self._status.modified()
|
||||
|
||||
def get_data_dict(self):
|
||||
return {
|
||||
"name": self.name,
|
||||
"data_type": self.data_type,
|
||||
"target_data": self.target_data,
|
||||
"distribution": self.distribution,
|
||||
"params": self.params,
|
||||
}
|
||||
|
||||
def set_data_dict(self, data):
|
||||
self.name = data["name"]
|
||||
self.data_type = data["data_type"]
|
||||
self.target_data = data["target_data"]
|
||||
self.distribution = data["distribution"]
|
||||
self.params = data["params"]
|
||||
@@ -201,19 +201,22 @@ class EnsembleEditDialog(PamhyrDialog):
|
||||
return self._values
|
||||
|
||||
def accept(self):
|
||||
self._ensemble.name = self.get_line_edit_text("lineEdit_name")
|
||||
self._ensemble.data_type = self._target_data[0]
|
||||
self._ensemble.target_data = self._target_data[1]
|
||||
|
||||
txt = self.get_combobox_text("comboBox_distribution")
|
||||
self._ensemble.distribution = next(
|
||||
distribution = next(
|
||||
filter(
|
||||
lambda d: d.name == txt,
|
||||
self._study._ens_distributions.lst
|
||||
),
|
||||
None
|
||||
)
|
||||
self._ensemble.params = self._params_widget.values
|
||||
|
||||
self._values = {
|
||||
"name": self.get_line_edit_text("lineEdit_name"),
|
||||
"data_type": self._target_data[0],
|
||||
"target_data": self._target_data[1],
|
||||
"distribution": distribution,
|
||||
"params": self._params_widget.values,
|
||||
}
|
||||
|
||||
super().accept()
|
||||
|
||||
|
||||
@@ -133,3 +133,18 @@ class DelCommand(QUndoCommand):
|
||||
|
||||
def redo(self):
|
||||
self._ensembles.delete_i(self._rows)
|
||||
|
||||
|
||||
class SetAllCommand(QUndoCommand):
|
||||
def __init__(self, ensemble, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ensemble = ensemble
|
||||
self._old = self._ensemble.get_data_dict()
|
||||
self._new = data
|
||||
|
||||
def undo(self):
|
||||
self._ensemble.set_data_dict(self._old)
|
||||
|
||||
def redo(self):
|
||||
self._ensemble.set_data_dict(self._new)
|
||||
@@ -47,6 +47,7 @@ from View.Ensembles.Table import (
|
||||
EnsembleTableModel, ComboBoxDelegate
|
||||
)
|
||||
from View.Ensembles.Translate import EnsemblesTranslate
|
||||
from View.Ensembles.UndoCommand import SetAllCommand
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
@@ -194,7 +195,11 @@ class EnsemblesWindow(PamhyrWindow):
|
||||
)
|
||||
|
||||
if dlg.exec():
|
||||
return
|
||||
self._undo_stack.push(
|
||||
SetAllCommand(
|
||||
ens, dlg.values
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
logger_exception(e)
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user