mirror of https://gitlab.com/pamhyr/pamhyr2
IC: Fix modification method and display.
parent
22aeda105e
commit
1b70e22a58
|
|
@ -375,7 +375,7 @@ class InitialConditions(SQLSubModel):
|
|||
return ok
|
||||
|
||||
def __len__(self):
|
||||
return len(self._data)
|
||||
return len(self.data)
|
||||
|
||||
def lst(self):
|
||||
return self._data
|
||||
|
|
@ -403,7 +403,7 @@ class InitialConditions(SQLSubModel):
|
|||
self._data = data
|
||||
|
||||
def get(self, index):
|
||||
return self._data[index]
|
||||
return self.data[index]
|
||||
|
||||
def set(self, index, data):
|
||||
self._data.insert(index, data)
|
||||
|
|
@ -441,9 +441,12 @@ class InitialConditions(SQLSubModel):
|
|||
|
||||
def delete(self, data):
|
||||
list(
|
||||
filter(
|
||||
map(
|
||||
lambda x: x.set_as_deleted(),
|
||||
self._data
|
||||
filter(
|
||||
lambda x: x in data,
|
||||
self._data
|
||||
)
|
||||
)
|
||||
)
|
||||
self.modified()
|
||||
|
|
@ -468,7 +471,7 @@ class InitialConditions(SQLSubModel):
|
|||
return list(
|
||||
map(
|
||||
lambda d: d[key],
|
||||
self._data
|
||||
self.data
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -476,7 +479,7 @@ class InitialConditions(SQLSubModel):
|
|||
return list(
|
||||
map(
|
||||
lambda d: d["rk"].rk,
|
||||
self._data
|
||||
self.data
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -486,6 +489,10 @@ class InitialConditions(SQLSubModel):
|
|||
def get_discharge(self):
|
||||
return self._data_get("discharge")
|
||||
|
||||
def clear_data(self):
|
||||
for data in self._data:
|
||||
data.set_as_deleted()
|
||||
|
||||
def generate_growing_constant_depth(self, height: float,
|
||||
compute_discharge: bool):
|
||||
profiles = self._reach.reach.profiles.copy()
|
||||
|
|
@ -502,7 +509,9 @@ class InitialConditions(SQLSubModel):
|
|||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
self._data = []
|
||||
|
||||
self.clear_data()
|
||||
|
||||
for profile in reversed(profiles):
|
||||
width = profile.wet_width(profile.z_min() + height)
|
||||
area = profile.wet_area(profile.z_min() + height)
|
||||
|
|
@ -568,7 +577,9 @@ class InitialConditions(SQLSubModel):
|
|||
|
||||
incline = self._reach.reach.get_incline_median_mean()
|
||||
logger.debug(f"incline = {incline}")
|
||||
self._data = []
|
||||
|
||||
self.clear_data()
|
||||
|
||||
for profile in reversed(profiles):
|
||||
width = profile.width_approximation()
|
||||
frictions = self._reach.frictions.frictions
|
||||
|
|
@ -631,7 +642,7 @@ class InitialConditions(SQLSubModel):
|
|||
for data in self._data:
|
||||
data_discharge[data["rk"].rk] = data["discharge"]
|
||||
|
||||
self._data = []
|
||||
self.clear_data()
|
||||
for profile in profiles:
|
||||
|
||||
if not compute_discharge:
|
||||
|
|
|
|||
|
|
@ -104,6 +104,19 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
def _setup_lst(self):
|
||||
self._lst = self._data.river.initial_conditions.get(self._reach)
|
||||
|
||||
def get_true_data_row(self, row):
|
||||
data = self._lst.get(row)
|
||||
|
||||
return next(
|
||||
map(
|
||||
lambda e: e[0],
|
||||
filter(
|
||||
lambda e: e[1] == data,
|
||||
enumerate(self._lst._data)
|
||||
)
|
||||
), 0
|
||||
)
|
||||
|
||||
def data(self, index, role):
|
||||
if role != Qt.ItemDataRole.DisplayRole:
|
||||
return QVariant()
|
||||
|
|
@ -122,8 +135,11 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
return f"{velocity:.4f}"
|
||||
|
||||
return ""
|
||||
|
||||
if self._headers[column] == "rk":
|
||||
p = self._lst.get(row)[self._headers[column]]
|
||||
if p is None:
|
||||
return ""
|
||||
return f"{p.rk:.4f}"
|
||||
elif self._headers[column] not in ["name", "comment"]:
|
||||
v = self._lst.get(row)[self._headers[column]]
|
||||
|
|
@ -157,6 +173,8 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
def add(self, row, parent=QModelIndex()):
|
||||
self.beginInsertRows(parent, row, row - 1)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
AddCommand(
|
||||
self._lst, row
|
||||
|
|
@ -171,7 +189,12 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
|
||||
self._undo.push(
|
||||
DelCommand(
|
||||
self._lst, rows
|
||||
self._lst, list(
|
||||
map(
|
||||
lambda row: self._lst.get(row),
|
||||
rows
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
@ -194,10 +217,11 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
if row <= 0:
|
||||
return
|
||||
|
||||
target = row + 2
|
||||
|
||||
target = row + 1
|
||||
self.beginMoveRows(parent, row - 1, row - 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
MoveCommand(
|
||||
self._lst, "up", row
|
||||
|
|
@ -215,6 +239,8 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
|
||||
self.beginMoveRows(parent, row + 1, row + 1, parent, target)
|
||||
|
||||
row = self.get_true_data_row(row)
|
||||
|
||||
self._undo.push(
|
||||
MoveCommand(
|
||||
self._lst, "down", row
|
||||
|
|
@ -239,6 +265,8 @@ class InitialConditionTableModel(PamhyrTableModel):
|
|||
|
||||
self.layoutAboutToBeChanged.emit()
|
||||
|
||||
index = self.get_true_data_row(index)
|
||||
|
||||
self._undo.push(
|
||||
InsertCommand(
|
||||
self._lst, index,
|
||||
|
|
|
|||
|
|
@ -75,23 +75,18 @@ class AddCommand(QUndoCommand):
|
|||
|
||||
|
||||
class DelCommand(QUndoCommand):
|
||||
def __init__(self, ics, rows):
|
||||
def __init__(self, ics, data):
|
||||
QUndoCommand.__init__(self)
|
||||
|
||||
self._ics = ics
|
||||
self._rows = rows
|
||||
|
||||
self._ic = []
|
||||
for row in rows:
|
||||
self._ic.append((row, self._ics.get(row)))
|
||||
self._ic.sort()
|
||||
self._data = data
|
||||
|
||||
def undo(self):
|
||||
for row, el in self._ic:
|
||||
self._ics.insert(row, el)
|
||||
for ic in self._data:
|
||||
ic.set_as_not_deleted()
|
||||
|
||||
def redo(self):
|
||||
self._ics.delete_i(self._rows)
|
||||
self._ics.delete(self._data)
|
||||
|
||||
|
||||
class SortCommand(QUndoCommand):
|
||||
|
|
|
|||
Loading…
Reference in New Issue