mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
IC: Fix modification method and display.
This commit is contained in:
1 parent
22aeda105e
commit
1b70e22a58
3 files changed
+56
-22
No files matched your search
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user