mirror of https://gitlab.com/pamhyr/pamhyr2
Compare commits
No commits in common. "b450796df592334e9db4ba3743ea1b2feb64f3b2" and "7565d8ee956102d60e1875194a6359341b11487b" have entirely different histories.
b450796df5
...
7565d8ee95
|
|
@ -142,24 +142,24 @@ class DIFAdisTS(SQLSubModel):
|
||||||
enabled = (next(it) == 1)
|
enabled = (next(it) == 1)
|
||||||
owner_scenario = next(it)
|
owner_scenario = next(it)
|
||||||
|
|
||||||
DIF = cls(
|
dif = cls(
|
||||||
id=pid,
|
id=pid,
|
||||||
name=name,
|
name=name,
|
||||||
status=status,
|
status=status,
|
||||||
owner_scenario=owner_scenario,
|
owner_scenario=owner_scenario,
|
||||||
)
|
)
|
||||||
|
|
||||||
DIF.method = method
|
dif.method = method
|
||||||
DIF.dif = dif
|
dif.dif = dif
|
||||||
DIF.b = b
|
dif.b = b
|
||||||
DIF.c = c
|
dif.c = c
|
||||||
DIF.enabled = enabled
|
dif.enabled = enabled
|
||||||
|
|
||||||
data['dif_default_id'] = pid
|
data['dif_default_id'] = pid
|
||||||
DIF._data = DIFAdisTSSpec._db_load(execute, data)
|
dif._data = DIFAdisTSSpec._db_load(execute, data)
|
||||||
|
|
||||||
loaded.add(pid)
|
loaded.add(pid)
|
||||||
new.append(DIF)
|
new.append(dif)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
new += cls._db_load(execute, data)
|
new += cls._db_load(execute, data)
|
||||||
|
|
@ -190,7 +190,7 @@ class DIFAdisTS(SQLSubModel):
|
||||||
b = self.b
|
b = self.b
|
||||||
|
|
||||||
c = -1.
|
c = -1.
|
||||||
if self.c is not None:
|
if self.dif is not None:
|
||||||
c = self.c
|
c = self.c
|
||||||
|
|
||||||
sql = (
|
sql = (
|
||||||
|
|
@ -201,7 +201,7 @@ class DIFAdisTS(SQLSubModel):
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, '{self._db_format(self._name)}', " +
|
f"{self.id}, '{self._db_format(self._name)}', " +
|
||||||
f"'{self._db_format(self._method)}', " +
|
f"'{self._db_format(self._method)}', " +
|
||||||
f"{dif}, {b}, {c}, {self._enabled}, " +
|
f"{dif.id}, {b}, {c}, {self._enabled}, " +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -33,15 +33,15 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||||
_id_cnt = 0
|
_id_cnt = 0
|
||||||
|
|
||||||
def __init__(self, id: int = -1, method: str = "",
|
def __init__(self, id: int = -1, method: str = "",
|
||||||
status=None, owner_scenario=-1):
|
status=None):
|
||||||
super(DIFAdisTSSpec, self).__init__()
|
super(DIFAdisTSSpec, self).__init__()
|
||||||
|
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
if id == -1:
|
if id == -1:
|
||||||
self._id = DIFAdisTSSpec._id_cnt
|
self.id = DIFAdisTSSpec._id_cnt
|
||||||
else:
|
else:
|
||||||
self._id = id
|
self.id = id
|
||||||
|
|
||||||
self._method = method
|
self._method = method
|
||||||
self._reach = None
|
self._reach = None
|
||||||
|
|
@ -52,7 +52,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||||
self._c = None
|
self._c = None
|
||||||
self._enabled = True
|
self._enabled = True
|
||||||
|
|
||||||
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self._id)
|
DIFAdisTSSpec._id_cnt = max(DIFAdisTSSpec._id_cnt + 1, self.id)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _db_create(cls, execute, ext=""):
|
def _db_create(cls, execute, ext=""):
|
||||||
|
|
@ -195,7 +195,7 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||||
new_spec.c = c
|
new_spec.c = c
|
||||||
new_spec.enabled = enabled
|
new_spec.enabled = enabled
|
||||||
|
|
||||||
loaded.add(id)
|
loaded.add(pid)
|
||||||
new.append(new_spec)
|
new.append(new_spec)
|
||||||
|
|
||||||
data["scenario"] = scenario.parent
|
data["scenario"] = scenario.parent
|
||||||
|
|
@ -210,23 +210,22 @@ class DIFAdisTSSpec(SQLSubModel):
|
||||||
|
|
||||||
dif_default = data['dif_default_id']
|
dif_default = data['dif_default_id']
|
||||||
|
|
||||||
sql = (
|
execute(
|
||||||
"INSERT INTO " +
|
"INSERT INTO " +
|
||||||
"dif_adists_spec(pamhyr_id, deleted, " +
|
"dif_adists_spec(pamhyr_id, deleted, " +
|
||||||
"dif_default, method, reach, " +
|
"dif_default, method, reach, " +
|
||||||
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
"start_rk, end_rk, dif, b, c, enabled, scenario) " +
|
||||||
"VALUES (" +
|
"VALUES (" +
|
||||||
f"{self.id}, {self._db_format(self.is_deleted())}, " +
|
f"{self.id}, {self._db_format(self.is_deleted())}" +
|
||||||
f"{dif_default}, " +
|
f"{dif_default}, " +
|
||||||
f"'{self._db_format(self._method)}', " +
|
f"'{self._db_format(self._method)}', " +
|
||||||
f"{self._reach}, " +
|
f"{self._reach}, " +
|
||||||
f"{self._start_rk}, {self._end_rk}, " +
|
f"{self._start_rk}, {self._end_rk}, " +
|
||||||
f"{self._dif}, {self._b}, {self._c}, " +
|
f"{self._dif}, {self._b}, {self._c}, " +
|
||||||
f"{self._enabled}, " +
|
f"{self._enabled}" +
|
||||||
f"{self._status.scenario_id}" +
|
f"{self._status.scenario_id}" +
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
execute(sql)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,12 +62,9 @@ class ComboBoxDelegate(QItemDelegate):
|
||||||
if self._mode == "rk":
|
if self._mode == "rk":
|
||||||
reach_id = self._d90_spec_lst[index.row()].reach
|
reach_id = self._d90_spec_lst[index.row()].reach
|
||||||
|
|
||||||
reach = next(
|
reach = next(filter(
|
||||||
filter(
|
lambda edge: edge.id == reach_id, self._data.edges()
|
||||||
lambda edge: edge.id == reach_id, self._data.edges()
|
))
|
||||||
),
|
|
||||||
None
|
|
||||||
)
|
|
||||||
|
|
||||||
if reach_id is not None:
|
if reach_id is not None:
|
||||||
val = list(
|
val = list(
|
||||||
|
|
@ -119,8 +116,6 @@ class D90TableModel(PamhyrTableModel):
|
||||||
super(D90TableModel, self).__init__(data=data, **kwargs)
|
super(D90TableModel, self).__init__(data=data, **kwargs)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
if self._undo is not None:
|
|
||||||
self._undo.indexChanged.connect(lambda _: self.update())
|
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = list(
|
self._lst = list(
|
||||||
|
|
@ -221,8 +216,7 @@ class D90TableModel(PamhyrTableModel):
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data,
|
self._data,
|
||||||
self._data._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)]
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -232,10 +226,8 @@ class D90TableModel(PamhyrTableModel):
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._undo.redo()
|
self._undo.redo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ from PyQt5.QtWidgets import (
|
||||||
|
|
||||||
from Modules import Modules
|
from Modules import Modules
|
||||||
|
|
||||||
from View.D90AdisTS.UndoCommand import (
|
from View.InitialConditionsAdisTS.UndoCommand import (
|
||||||
SetCommand,
|
SetCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -264,27 +264,11 @@ class D90AdisTSWindow(PamhyrWindow):
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
def _undo(self):
|
def _undo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.undo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def _redo(self):
|
def _redo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.redo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
|
|
|
||||||
|
|
@ -46,28 +46,25 @@ _translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
class ComboBoxDelegate(QItemDelegate):
|
class ComboBoxDelegate(QItemDelegate):
|
||||||
def __init__(self, data=None, dif_spec_lst=None,
|
def __init__(self, data=None, ic_spec_lst=None,
|
||||||
trad=None, parent=None, mode="reaches"):
|
trad=None, parent=None, mode="reaches"):
|
||||||
super(ComboBoxDelegate, self).__init__(parent)
|
super(ComboBoxDelegate, self).__init__(parent)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._mode = mode
|
self._mode = mode
|
||||||
self._trad = trad
|
self._trad = trad
|
||||||
self._dif_spec_lst = dif_spec_lst
|
self._ic_spec_lst = ic_spec_lst
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
self.editor = QComboBox(parent)
|
self.editor = QComboBox(parent)
|
||||||
|
|
||||||
val = []
|
val = []
|
||||||
if self._mode == "rk":
|
if self._mode == "rk":
|
||||||
reach_id = self._dif_spec_lst[index.row()].reach
|
reach_id = self._ic_spec_lst[index.row()].reach
|
||||||
|
|
||||||
reach = next(
|
reach = next(filter(
|
||||||
filter(
|
lambda edge: edge.id == reach_id, self._data.edges()
|
||||||
lambda edge: edge.id == reach_id, self._data.edges()
|
))
|
||||||
),
|
|
||||||
None
|
|
||||||
)
|
|
||||||
|
|
||||||
if reach_id is not None:
|
if reach_id is not None:
|
||||||
val = list(
|
val = list(
|
||||||
|
|
@ -121,16 +118,9 @@ class DIFTableModel(PamhyrTableModel):
|
||||||
super(DIFTableModel, self).__init__(data=data, **kwargs)
|
super(DIFTableModel, self).__init__(data=data, **kwargs)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
if self._undo is not None:
|
|
||||||
self._undo.indexChanged.connect(lambda _: self.update())
|
|
||||||
|
|
||||||
def _setup_lst(self):
|
def _setup_lst(self):
|
||||||
self._lst = list(
|
self._lst = self._data._data
|
||||||
filter(
|
|
||||||
lambda dif: dif._deleted is False,
|
|
||||||
self._data._data
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
def rowCount(self, parent):
|
def rowCount(self, parent):
|
||||||
return len(self._lst)
|
return len(self._lst)
|
||||||
|
|
@ -193,10 +183,7 @@ class DIFTableModel(PamhyrTableModel):
|
||||||
if self._headers[column] != "reach":
|
if self._headers[column] != "reach":
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
SetCommandSpec(
|
SetCommandSpec(
|
||||||
self._lst,
|
self._lst, row, self._headers[column], value
|
||||||
row,
|
|
||||||
self._headers[column],
|
|
||||||
value
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif self._headers[column] == "reach":
|
elif self._headers[column] == "reach":
|
||||||
|
|
@ -224,34 +211,25 @@ class DIFTableModel(PamhyrTableModel):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
self._setup_lst()
|
|
||||||
self.endInsertRows()
|
self.endInsertRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def delete(self, rows, parent=QModelIndex()):
|
def delete(self, rows, parent=QModelIndex()):
|
||||||
self.beginRemoveRows(parent, rows[0], rows[-1])
|
self.beginRemoveRows(parent, rows[0], rows[-1])
|
||||||
|
|
||||||
data_rows = {
|
|
||||||
id(dif): i for i, dif in enumerate(self._data._data)
|
|
||||||
}
|
|
||||||
self._undo.push(
|
self._undo.push(
|
||||||
DelCommand(
|
DelCommand(
|
||||||
self._data,
|
self._data, self._lst, rows
|
||||||
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.endRemoveRows()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._undo.redo()
|
self._undo.redo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -136,11 +136,11 @@ class SetCommandSpec(QUndoCommand):
|
||||||
|
|
||||||
|
|
||||||
class AddCommand(QUndoCommand):
|
class AddCommand(QUndoCommand):
|
||||||
def __init__(self, data, dif_spec, index):
|
def __init__(self, data, ics_spec, index):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._dif_spec = dif_spec
|
self._ics_spec = ics_spec
|
||||||
self._index = index
|
self._index = index
|
||||||
self._new = None
|
self._new = None
|
||||||
|
|
||||||
|
|
@ -155,20 +155,21 @@ class AddCommand(QUndoCommand):
|
||||||
|
|
||||||
|
|
||||||
class DelCommand(QUndoCommand):
|
class DelCommand(QUndoCommand):
|
||||||
def __init__(self, data, dif_spec, rows):
|
def __init__(self, data, ics_spec, rows):
|
||||||
QUndoCommand.__init__(self)
|
QUndoCommand.__init__(self)
|
||||||
|
|
||||||
self._data = data
|
self._data = data
|
||||||
self._dif_spec = dif_spec
|
self._ics_spec = ics_spec
|
||||||
self._rows = rows
|
self._rows = rows
|
||||||
|
# self._data = data
|
||||||
|
|
||||||
self._dif = []
|
self._ic = []
|
||||||
for row in rows:
|
for row in rows:
|
||||||
self._dif.append((row, self._dif_spec[row]))
|
self._ic.append((row, self._ics_spec[row]))
|
||||||
self._dif.sort()
|
self._ic.sort()
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
for row, el in self._dif:
|
for row, el in self._ic:
|
||||||
self._data.insert(row, el)
|
self._data.insert(row, el)
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,6 @@ from View.DIFAdisTS.Table import (
|
||||||
DIFTableModel, ComboBoxDelegate,
|
DIFTableModel, ComboBoxDelegate,
|
||||||
)
|
)
|
||||||
|
|
||||||
from View.DIFAdisTS.UndoCommand import SetCommand
|
|
||||||
|
|
||||||
from View.DIFAdisTS.translate import DIFAdisTSTranslate
|
from View.DIFAdisTS.translate import DIFAdisTSTranslate
|
||||||
|
|
||||||
from Solver.Mage import Mage8
|
from Solver.Mage import Mage8
|
||||||
|
|
@ -102,7 +100,7 @@ class DIFAdisTSWindow(PamhyrWindow):
|
||||||
self._delegate_method = ComboBoxDelegate(
|
self._delegate_method = ComboBoxDelegate(
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
dif_spec_lst=self._data[0]._data,
|
ic_spec_lst=self._data[0]._data,
|
||||||
parent=self,
|
parent=self,
|
||||||
mode="method"
|
mode="method"
|
||||||
)
|
)
|
||||||
|
|
@ -146,14 +144,14 @@ class DIFAdisTSWindow(PamhyrWindow):
|
||||||
self._delegate_reach = ComboBoxDelegate(
|
self._delegate_reach = ComboBoxDelegate(
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
dif_spec_lst=self._data[0]._data,
|
ic_spec_lst=self._data[0]._data,
|
||||||
parent=self,
|
parent=self,
|
||||||
mode="reaches"
|
mode="reaches"
|
||||||
)
|
)
|
||||||
self._delegate_rk = ComboBoxDelegate(
|
self._delegate_rk = ComboBoxDelegate(
|
||||||
trad=self._trad,
|
trad=self._trad,
|
||||||
data=self._study.river,
|
data=self._study.river,
|
||||||
dif_spec_lst=self._data[0]._data,
|
ic_spec_lst=self._data[0]._data,
|
||||||
parent=self,
|
parent=self,
|
||||||
mode="rk"
|
mode="rk"
|
||||||
)
|
)
|
||||||
|
|
@ -274,25 +272,11 @@ class DIFAdisTSWindow(PamhyrWindow):
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
def _undo(self):
|
def _undo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.undo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def _redo(self):
|
def _redo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.redo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
|
|
|
||||||
|
|
@ -245,10 +245,8 @@ class InitialConditionTableModel(PamhyrTableModel):
|
||||||
|
|
||||||
def undo(self):
|
def undo(self):
|
||||||
self._undo.undo()
|
self._undo.undo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
def redo(self):
|
def redo(self):
|
||||||
self._undo.redo()
|
self._undo.redo()
|
||||||
self._setup_lst()
|
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
|
||||||
|
|
@ -273,27 +273,11 @@ class InitialConditionsAdisTSWindow(PamhyrWindow):
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
def _undo(self):
|
def _undo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.undo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def _redo(self):
|
def _redo(self):
|
||||||
undo_stack = self._undo_stack
|
self._table.redo()
|
||||||
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()
|
self._update()
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue