mirror of https://gitlab.com/pamhyr/pamhyr2
Ensemble: Fix some view/model interations.
parent
b203e8e062
commit
8b36905842
|
|
@ -22,6 +22,7 @@ import itertools
|
|||
|
||||
from Model.Tools.PamhyrDB import SQLSubModel
|
||||
from Model.Scenario import Scenario
|
||||
from Model.Ensembles.Function import Uniform
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
|
@ -30,7 +31,8 @@ class Ensemble(SQLSubModel):
|
|||
_sub_classes = []
|
||||
|
||||
def __init__(self, id: int = -1, name: str = "",
|
||||
function=None, range=[], target_data=None,
|
||||
function=None, range=[],
|
||||
data_type=None, target_data=None,
|
||||
status=None, owner_scenario=-1):
|
||||
super(Ensemble, self).__init__(
|
||||
id=id, status=status,
|
||||
|
|
@ -38,7 +40,7 @@ class Ensemble(SQLSubModel):
|
|||
)
|
||||
|
||||
self._name = name
|
||||
self._data_type = "generic"
|
||||
self._data_type = data_type
|
||||
self._function = function
|
||||
self._range = range
|
||||
self._target_data = target_data
|
||||
|
|
@ -132,6 +134,7 @@ class Ensemble(SQLSubModel):
|
|||
id, name=name,
|
||||
function=function,
|
||||
range=rdata,
|
||||
data_type=data_type,
|
||||
target_data=target_data,
|
||||
status=data["status"],
|
||||
owner_scenario=owner_scenario
|
||||
|
|
@ -158,9 +161,12 @@ class Ensemble(SQLSubModel):
|
|||
|
||||
if self._function is None:
|
||||
fid = -1
|
||||
fname = "NULL"
|
||||
else:
|
||||
fid = self._function._pamhyr_id
|
||||
if self._function._data_type == "generic":
|
||||
fname = self._function._name
|
||||
|
||||
if self._function._type == "generic":
|
||||
fid = -1
|
||||
|
||||
data_pid = -1
|
||||
|
|
@ -175,7 +181,7 @@ class Ensemble(SQLSubModel):
|
|||
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
self.pamhyr_id, self.is_deleted(),
|
||||
self._name, self._data_type,
|
||||
fid, self._function._name, brange, length,
|
||||
fid, fname, brange, length,
|
||||
data_pid, self._status.scenario_id
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ class Function(SQLSubModel):
|
|||
self._type = "generic"
|
||||
self._script = script
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@classmethod
|
||||
def _db_create(cls, execute, ext=""):
|
||||
execute(f"""
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
[self._trad["not_defined"]] +
|
||||
list(
|
||||
map(
|
||||
lambda s: str(s),
|
||||
lambda f: f.name,
|
||||
self._study._ens_functions.lst
|
||||
)
|
||||
)
|
||||
|
|
@ -100,7 +100,36 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
|
||||
def setModelData(self, editor, model, index):
|
||||
text = str(editor.currentText())
|
||||
model.setData(index, text)
|
||||
|
||||
if self._mode == "data_type":
|
||||
value = next(
|
||||
filter(
|
||||
lambda x: self._trad[x] == text,
|
||||
["strickler_minor", "strickler_medium"],
|
||||
),
|
||||
""
|
||||
)
|
||||
elif self._mode == "stricklers":
|
||||
value = next(
|
||||
filter(
|
||||
lambda s: str(s) == text,
|
||||
self._study.river.stricklers.stricklers
|
||||
),
|
||||
None
|
||||
)
|
||||
elif self._mode == "function":
|
||||
value = next(
|
||||
filter(
|
||||
lambda f: f.name == text,
|
||||
self._study._ens_functions.lst
|
||||
),
|
||||
None
|
||||
)
|
||||
else:
|
||||
value = text
|
||||
|
||||
model.setData(index, value)
|
||||
|
||||
editor.close()
|
||||
editor.deleteLater()
|
||||
|
||||
|
|
@ -131,7 +160,7 @@ class EnsembleTableModel(PamhyrTableModel):
|
|||
if self._headers[column] == "name":
|
||||
return self._lst.get(row).name
|
||||
elif self._headers[column] == "type":
|
||||
return self._lst.get(row).data_type
|
||||
return self._trad[self._lst.get(row).data_type]
|
||||
elif self._headers[column] == "target_data":
|
||||
value = self._lst.get(row).target_data
|
||||
if value is None:
|
||||
|
|
@ -141,7 +170,7 @@ class EnsembleTableModel(PamhyrTableModel):
|
|||
value = self._lst.get(row).function
|
||||
if value is None:
|
||||
return self._trad["not_defined"]
|
||||
return str(value)
|
||||
return value.name
|
||||
|
||||
return QVariant()
|
||||
|
||||
|
|
@ -192,7 +221,7 @@ class EnsembleTableModel(PamhyrTableModel):
|
|||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._lst, row, self._data
|
||||
self._lst, row,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -61,13 +61,14 @@ class SetTypeCommand(QUndoCommand):
|
|||
|
||||
|
||||
class SetDataCommand(QUndoCommand):
|
||||
def __init__(self, ensembles, index, edge):
|
||||
def __init__(self, ensembles, index, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ensembles = ensembles
|
||||
self._index = index
|
||||
self._old = self._ensembles.get(self._index).edge
|
||||
self._new = edge
|
||||
self._old = self._ensembles.get(self._index)\
|
||||
.target_data
|
||||
self._new = data
|
||||
|
||||
def undo(self):
|
||||
self._ensembles.get(self._index).target_data = self._old
|
||||
|
|
@ -77,13 +78,13 @@ class SetDataCommand(QUndoCommand):
|
|||
|
||||
|
||||
class SetFunctionCommand(QUndoCommand):
|
||||
def __init__(self, ensembles, index, edge):
|
||||
def __init__(self, ensembles, index, function):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ensembles = ensembles
|
||||
self._index = index
|
||||
self._old = self._ensembles.get(self._index).edge
|
||||
self._new = edge
|
||||
self._old = self._ensembles.get(self._index).function
|
||||
self._new = function
|
||||
|
||||
def undo(self):
|
||||
self._ensembles.get(self._index).function = self._old
|
||||
|
|
@ -93,12 +94,11 @@ class SetFunctionCommand(QUndoCommand):
|
|||
|
||||
|
||||
class AddCommand(QUndoCommand):
|
||||
def __init__(self, ensembles, index, reach):
|
||||
def __init__(self, ensembles, index):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ensembles = ensembles
|
||||
self._index = index
|
||||
self._reach = reach
|
||||
self._new = None
|
||||
|
||||
def undo(self):
|
||||
|
|
@ -107,7 +107,6 @@ class AddCommand(QUndoCommand):
|
|||
def redo(self):
|
||||
if self._new is None:
|
||||
self._new = self._ensembles.new(self._index)
|
||||
self._new.edge = self._reach
|
||||
else:
|
||||
self._ensembles.insert(self._index, self._new)
|
||||
|
||||
|
|
|
|||
|
|
@ -96,14 +96,13 @@ class ComboBoxDelegate(QItemDelegate):
|
|||
reach = self._data.hydraulic_structures\
|
||||
.get(index.row())\
|
||||
.input_reach
|
||||
profiles = list(
|
||||
value = next(
|
||||
filter(
|
||||
lambda p: p.display_name() == text,
|
||||
reach.reach.profiles
|
||||
)
|
||||
),
|
||||
None
|
||||
)
|
||||
|
||||
value = profiles[0] if len(profiles) > 0 else None
|
||||
else:
|
||||
value = text
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue