mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
Merge branch 'dev_dylan' into scenarios
This commit is contained in:
commit
e940dead70
20 files changed
+230
-93
No files matched your search
@@ -50,6 +50,22 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def get_true_data_row(self, row):
|
||||
if len(self._data.data) > 0:
|
||||
bc = self._data.data[row]
|
||||
else:
|
||||
return 0
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == bc,
|
||||
enumerate(self._data._data)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
@@ -63,6 +79,7 @@ class TableModel(PamhyrTableModel):
|
||||
value = QVariant()
|
||||
|
||||
if 0 <= column < 2:
|
||||
row = self.get_true_data_row(row)
|
||||
v = self._data._data[row][column]
|
||||
if self._data._types[column] == float:
|
||||
value = f"{v:.4f}"
|
||||
@@ -84,6 +101,8 @@ class TableModel(PamhyrTableModel):
|
||||
column = index.column()
|
||||
|
||||
try:
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
SetDataCommand(
|
||||
self._data, row, column, value
|
||||
@@ -110,14 +129,20 @@ class TableModel(PamhyrTableModel):
|
||||
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
_rows = list(
|
||||
map(
|
||||
lambda r: self.get_true_data_row(r),
|
||||
rows
|
||||
)
|
||||
)
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, rows
|
||||
self._data, _rows
|
||||
)
|
||||
)
|
||||
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
|
||||
def sort(self, _reverse, parent=QModelIndex()):
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
@@ -80,10 +80,11 @@ class DelCommand(QUndoCommand):
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._bc:
|
||||
self._data.insert(row, el)
|
||||
el.set_as_not_deleted()
|
||||
|
||||
def redo(self):
|
||||
self._data.delete_i(self._rows)
|
||||
for row, el in self._bc:
|
||||
el.set_as_deleted()
|
||||
|
||||
|
||||
class PasteCommand(QUndoCommand):
|
||||
|
||||
@@ -43,7 +43,7 @@ from View.Tools.PamhyrTable import PamhyrTableModel
|
||||
|
||||
from View.BoundaryConditionsAdisTS.UndoCommand import (
|
||||
SetNodeCommand, SetTypeCommand,
|
||||
AddCommand, DelCommand, SetPolCommand
|
||||
AddCommand, DelCommand
|
||||
)
|
||||
from View.BoundaryCondition.translate import BC_types
|
||||
|
||||
|
||||
@@ -62,22 +62,6 @@ class SetTypeCommand(QUndoCommand):
|
||||
self._bcs.get(self._index).type = self._new
|
||||
|
||||
|
||||
class SetPolCommand(QUndoCommand):
|
||||
def __init__(self, bcs, index, pollutant):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._bcs = bcs
|
||||
self._index = index
|
||||
self._old = self._bcs.get(self._index).pollutant
|
||||
self._new = pollutant
|
||||
|
||||
def undo(self):
|
||||
self._bcs.get(self._index).pollutant = self._old
|
||||
|
||||
def redo(self):
|
||||
self._bcs.get(self._index).pollutant = self._new
|
||||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, pollutant, bcs, index):
|
||||
QUndoCommand.__init__(self)
|
||||
@@ -106,7 +90,7 @@ class DelCommand(QUndoCommand):
|
||||
|
||||
self._bc = []
|
||||
for row in rows:
|
||||
self._bc.append((row, self._bcs.get(row)))
|
||||
self._bc.append((row, self._bcs._lst[row]))
|
||||
self._bc.sort()
|
||||
|
||||
def undo(self):
|
||||
|
||||
@@ -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()
|
||||
@@ -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):
|
||||
|
||||
+32
-10
@@ -46,25 +46,28 @@ _translate = QCoreApplication.translate
|
||||
|
||||
|
||||
class ComboBoxDelegate(QItemDelegate):
|
||||
def __init__(self, data=None, ic_spec_lst=None,
|
||||
def __init__(self, data=None, dif_spec_lst=None,
|
||||
trad=None, parent=None, mode="reaches"):
|
||||
super(ComboBoxDelegate, self).__init__(parent)
|
||||
|
||||
self._data = data
|
||||
self._mode = mode
|
||||
self._trad = trad
|
||||
self._ic_spec_lst = ic_spec_lst
|
||||
self._dif_spec_lst = dif_spec_lst
|
||||
|
||||
def createEditor(self, parent, option, index):
|
||||
self.editor = QComboBox(parent)
|
||||
|
||||
val = []
|
||||
if self._mode == "rk":
|
||||
reach_id = self._ic_spec_lst[index.row()].reach
|
||||
reach_id = self._dif_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(
|
||||
@@ -118,9 +121,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 +193,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 +224,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()
|
||||
@@ -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,21 +155,20 @@ 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 = []
|
||||
self._dif = []
|
||||
for row in rows:
|
||||
self._ic.append((row, self._ics_spec[row]))
|
||||
self._ic.sort()
|
||||
self._dif.append((row, self._dif_spec[row]))
|
||||
self._dif.sort()
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._ic:
|
||||
for row, el in self._dif:
|
||||
self._data.insert(row, el)
|
||||
|
||||
def redo(self):
|
||||
|
||||
@@ -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
|
||||
@@ -100,7 +102,7 @@ class DIFAdisTSWindow(PamhyrWindow):
|
||||
self._delegate_method = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
dif_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="method"
|
||||
)
|
||||
@@ -144,14 +146,14 @@ class DIFAdisTSWindow(PamhyrWindow):
|
||||
self._delegate_reach = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
dif_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="reaches"
|
||||
)
|
||||
self._delegate_rk = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
ic_spec_lst=self._data[0]._data,
|
||||
dif_spec_lst=self._data[0]._data,
|
||||
parent=self,
|
||||
mode="rk"
|
||||
)
|
||||
@@ -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):
|
||||
|
||||
@@ -245,8 +245,10 @@ class InitialConditionTableModel(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()
|
||||
@@ -273,11 +273,27 @@ class InitialConditionsAdisTSWindow(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):
|
||||
|
||||
@@ -52,6 +52,23 @@ logger = logging.getLogger()
|
||||
|
||||
|
||||
class TableModel(PamhyrTableModel):
|
||||
def get_true_data_row(self, row):
|
||||
|
||||
if len(self._data.data) > 0:
|
||||
lc = self._data.data[row]
|
||||
else:
|
||||
return 0
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == lc,
|
||||
enumerate(self._data._data)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
if role == Qt.TextAlignmentRole:
|
||||
return Qt.AlignHCenter | Qt.AlignVCenter
|
||||
@@ -65,6 +82,7 @@ class TableModel(PamhyrTableModel):
|
||||
value = QVariant()
|
||||
|
||||
if 0 <= column < 2:
|
||||
row = self.get_true_data_row(row)
|
||||
v = self._data._data[row][column]
|
||||
if self._data._types[column] == float:
|
||||
value = f"{v:.4f}"
|
||||
@@ -86,6 +104,8 @@ class TableModel(PamhyrTableModel):
|
||||
column = index.column()
|
||||
|
||||
try:
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
SetDataCommand(
|
||||
self._data, row, column, value
|
||||
@@ -113,10 +133,18 @@ class TableModel(PamhyrTableModel):
|
||||
def delete(self, rows, parent=QModelIndex()):
|
||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||
|
||||
_rows = list(
|
||||
map(
|
||||
lambda r: self.get_true_data_row(r),
|
||||
rows
|
||||
)
|
||||
)
|
||||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._data, rows
|
||||
self._data, _rows
|
||||
)
|
||||
)
|
||||
|
||||
self.endRemoveRows()
|
||||
self.layoutChanged.emit()
|
||||
@@ -76,8 +76,8 @@ class DelCommand(QUndoCommand):
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._lc:
|
||||
self._data._data.insert(row, el)
|
||||
el.set_as_not_deleted()
|
||||
|
||||
def redo(self):
|
||||
for row in self._rows:
|
||||
del self._data._data[row]
|
||||
for row, el in self._lc:
|
||||
el.set_as_deleted()
|
||||
@@ -91,7 +91,7 @@ class AddCommand(QUndoCommand):
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
self._lcs.delete_i(self._index)
|
||||
self._lcs.delete_i([self._index])
|
||||
|
||||
def redo(self):
|
||||
if self._new is None:
|
||||
|
||||
Reference in new issue
Block a user