Compare commits

...

6 Commits

Author SHA1 Message Date
Dylan Jeannin 377c508038 correction pep8 2026-05-05 10:29:13 +02:00
Dylan Jeannin 30e34b6847 debug add function and save/load in db for edit LCAdisTS window 2026-05-05 10:28:30 +02:00
Dylan Jeannin 102702e1df fix delete function for BCAdisTS 2026-05-04 14:52:31 +02:00
Dylan Jeannin c014f0ef34 erase old and useless methods 2026-05-04 14:51:34 +02:00
Dylan Jeannin e615a6b9d4 debug index matching in delete function for LCAdisTS 2026-05-04 13:03:18 +02:00
Dylan Jeannin f1dca727c6 rename edition BCadisTS and LCadisTS windows 2026-05-04 11:11:23 +02:00
9 changed files with 126 additions and 76 deletions

View File

@ -144,6 +144,7 @@ class Data(SQLSubModel):
"SELECT pamhyr_id, deleted, data0, data1, scenario FROM " + "SELECT pamhyr_id, deleted, data0, data1, scenario FROM " +
"boundary_condition_data_adists " + "boundary_condition_data_adists " +
f"WHERE bca = {bca.id} " + f"WHERE bca = {bca.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
f"AND scenario = {scenario.id}" f"AND scenario = {scenario.id}"
) )

View File

@ -135,7 +135,7 @@ class Data(SQLSubModel):
lca = data["lca"] lca = data["lca"]
table = execute( table = execute(
"SELECT pamhyr_id, deleted, data0, data1 " + "SELECT pamhyr_id, deleted, data0, data1, scenario " +
"FROM lateral_contribution_data_adists " + "FROM lateral_contribution_data_adists " +
f"WHERE scenario = {scenario.id} " + f"WHERE scenario = {scenario.id} " +
f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " + f"AND pamhyr_id NOT IN ({', '.join(map(str, loaded))}) " +
@ -152,16 +152,16 @@ class Data(SQLSubModel):
data1 = next(it) data1 = next(it)
owner_scenario = next(it) owner_scenario = next(it)
data = cls( lc = cls(
data0, data1, data0, data1,
id=pid, status=status, id=pid, status=status,
owner_scenario=owner_scenario owner_scenario=owner_scenario
) )
if deleted: if deleted:
data.set_as_deleted() lc.set_as_deleted()
loaded.add(pid) loaded.add(pid)
new.append(data) new.append(lc)
data["scenario"] = scenario.parent data["scenario"] = scenario.parent
new += cls._db_load(execute, data) new += cls._db_load(execute, data)
@ -177,7 +177,7 @@ class Data(SQLSubModel):
execute( execute(
"INSERT INTO " + "INSERT INTO " +
"lateral_contribution_adists(pamhyr_id, deleted," + "lateral_contribution_data_adists(pamhyr_id, deleted," +
"data0, data1, lca, scenario) " + "data0, data1, lca, scenario) " +
"VALUES (" + "VALUES (" +
f"{self.id}, {self._db_format(self.is_deleted())}, " + f"{self.id}, {self._db_format(self.is_deleted())}, " +
@ -384,6 +384,8 @@ class LateralContributionAdisTS(SQLSubModel):
")" ")"
) )
data["lca"] = self
ind = 0 ind = 0
for d in self._data: for d in self._data:
data["ind"] = ind data["ind"] = ind
@ -473,3 +475,57 @@ class LateralContributionAdisTS(SQLSubModel):
def end_rk(self, end_rk): def end_rk(self, end_rk):
self._end_rk = end_rk self._end_rk = end_rk
self.modified() self.modified()
@property
def _default_0(self):
return self._types[0](0)
@property
def _default_1(self):
return self._types[1](0.0)
def add(self, index: int):
value = Data(self._default_0, self._default_1, status=self._status)
self._data.insert(index, value)
self.modified()
return value
def insert(self, index: int, data: Data):
self._data.insert(index, data)
self.modified()
def delete_i(self, indexes):
self._data = list(
map(
lambda e: e[1],
filter(
lambda e: e[0] not in indexes,
enumerate(self.data)
)
)
)
self.modified()
def index(self, bc):
self._data.index(bc)
def get_i(self, index: int):
return self._data[index]
def get_range(self, _range):
lst = []
for r in _range:
lst.append(r)
return lst
def _set_i_c_v(self, index: int, column: int, value):
v = self._data[index]
v[column] = self._types[column](value)
self._data[index] = v
self.modified()
def set_i_0(self, index: int, value):
self._set_i_c_v(index, 0, value)
def set_i_1(self, index: int, value):
self._set_i_c_v(index, 1, value)

View File

@ -63,6 +63,16 @@ class EditBoundaryConditionWindow(PamhyrWindow):
name = trad[self._pamhyr_name] name = trad[self._pamhyr_name]
if self._data is not None:
n = self._data.node
node_name = next(filter(
lambda x: x.id == n, study.river._nodes
)).name
name += (
f" - {study.name} " +
f"({node_name})"
)
super(EditBoundaryConditionWindow, self).__init__( super(EditBoundaryConditionWindow, self).__init__(
title=name, title=name,
study=study, study=study,
@ -71,16 +81,6 @@ class EditBoundaryConditionWindow(PamhyrWindow):
parent=parent parent=parent
) )
if self._data is not None:
n = self._data.node
node_name = next(filter(
lambda x: x.id == n, self._study.river._nodes
)).name
name += (
f" - {study.name} " +
f"({node_name})"
)
self._hash_data.append(data) self._hash_data.append(data)
self.setup_table() self.setup_table()

View File

@ -215,9 +215,14 @@ class TableModel(PamhyrTableModel):
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])
global_rows = list( row_by_bc = {
map(self._global_row, rows) id(bc): row for row, bc in enumerate(self._bc_list._lst)
) }
global_rows = [
row_by_bc[id(self._lst[row])]
for row in rows
if 0 <= row < len(self._lst)
]
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._bc_list, global_rows self._bc_list, global_rows

View File

@ -34,29 +34,14 @@ class SetDataCommand(QUndoCommand):
self._data = data self._data = data
self._index = index self._index = index
self._column = column self._column = column
self._old = self._data._data[self._index][self._column] self._old = self._data.get_i(self._index)[self._column]
_type = self._data._types[self._column] self._new = new_value
self._new = _type(new_value)
def undo(self): def undo(self):
if self._column == 0: self._data._set_i_c_v(self._index, self._column, self._old)
self._data._data[self._index] = (
self._old, self._data._data[self._index][1]
)
else:
self._data._data[self._index] = (
self._data._data[self._index][0], self._old
)
def redo(self): def redo(self):
if self._column == 0: self._data._set_i_c_v(self._index, self._column, self._new)
self._data._data[self._index] = (
self._new, self._data._data[self._index][1]
)
else:
self._data._data[self._index] = (
self._data._data[self._index][0], self._new
)
class AddCommand(QUndoCommand): class AddCommand(QUndoCommand):
@ -72,11 +57,7 @@ class AddCommand(QUndoCommand):
def redo(self): def redo(self):
if self._new is None: if self._new is None:
self._new = self._data._data.insert( self._new = self._data.add(self._index)
self._index, (
self._data._types[0](0), self._data._types[1](0.0)
)
)
else: else:
self._data._data.insert(self._index, self._new) self._data._data.insert(self._index, self._new)

View File

@ -50,14 +50,38 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
_pamhyr_ui = "EditLateralContributionAdisTS" _pamhyr_ui = "EditLateralContributionAdisTS"
_pamhyr_name = "Edit lateral contribution AdisTS" _pamhyr_name = "Edit lateral contribution AdisTS"
def __init__(self, data=None, def __init__(self, data=None, study=None, config=None, parent=None):
study=None, config=None,
parent=None):
self._data = data self._data = data
trad = LCETranslate() trad = LCETranslate()
name = trad[self._pamhyr_name] name = trad[self._pamhyr_name]
if self._data is not None:
if self._data.reach is not None:
reach_name = next(filter(
lambda reach: reach.id == self._data.reach,
study.river.reachs()
)).name
else:
reach_name = trad['not_associated']
if self._data.begin_rk is not None:
begin_rk = self._data.begin_rk
else:
begin_rk = trad['not_associated']
if self._data.end_rk is not None:
end_rk = self._data.end_rk
else:
end_rk = trad['not_associated']
name += (
f" - {study.name} - " +
f"{reach_name} - " +
f"({begin_rk} - " +
f"{end_rk})"
)
super(EditLateralContributionAdisTSWindow, self).__init__( super(EditLateralContributionAdisTSWindow, self).__init__(
title=name, title=name,
study=study, study=study,
@ -66,20 +90,6 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow):
parent=parent parent=parent
) )
if self._data is not None:
if self._data.edge is not None:
edge_name = next(filter(
lambda edge: edge.id == self._data.edge,
self._study.river.edges()
)).name
else:
edge_name = trad['not_associated']
name += (
f"{study.name} - " +
f"{edge_name})"
)
self._hash_data.append(data) self._hash_data.append(data)
self.setup_table() self.setup_table()

View File

@ -121,7 +121,7 @@ class TableModel(PamhyrTableModel):
def _setup_lst(self): def _setup_lst(self):
if self._lcs_list is not None: if self._lcs_list is not None:
self._lcs_pol_list = [ self._lcs_pol_list = [
lcs for lcs in self._lcs_list.lst lcs for lcs in self._lcs_list._lst
if lcs.pollutant == self._pollutant if lcs.pollutant == self._pollutant
] ]
@ -209,9 +209,14 @@ class TableModel(PamhyrTableModel):
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])
global_rows = list( row_by_lc = {
map(self._global_row, rows) id(lc): row for row, lc in enumerate(self._lcs_list._lst)
) }
global_rows = [
row_by_lc[id(self._lst[row])]
for row in rows
if 0 <= row < len(self._lst)
]
self._undo.push( self._undo.push(
DelCommand( DelCommand(
self._lcs_list, global_rows self._lcs_list, global_rows
@ -231,14 +236,3 @@ class TableModel(PamhyrTableModel):
self._undo.redo() self._undo.redo()
self._setup_lst() self._setup_lst()
self.layoutChanged.emit() self.layoutChanged.emit()
def get(self, row):
if row < 0 or row >= len(self._lst):
return None
return self._lst[row]
def _global_row(self, row):
bc = self.get(row)
if bc is None:
return None
return self._lcs_list.index(bc)

View File

@ -109,7 +109,7 @@ class DelCommand(QUndoCommand):
self._lc = [] self._lc = []
for row in rows: for row in rows:
self._lc.append((row, self._lcs.get(row))) self._lc.append((row, self._lcs._lst[row]))
self._lc.sort() self._lc.sort()
def undo(self): def undo(self):

View File

@ -250,6 +250,9 @@ class LateralContributionAdisTSWindow(PamhyrWindow):
def edit(self): def edit(self):
rows = self.index_selected_rows() rows = self.index_selected_rows()
if not rows:
return
for row in rows: for row in rows:
data = self._lcs.lst[row] data = self._lcs.lst[row]