From a78be47e2b907813608bf34d4bcfabdc225ff1e7 Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Fri, 22 May 2026 16:47:02 +0200 Subject: [PATCH] AdisTS: Fix the possibility to edit AdisTS windows on a parent scenario --- .../BoundaryConditionsAdisTS/Edit/Window.py | 15 ++++++++---- src/View/BoundaryConditionsAdisTS/Window.py | 13 +++++++--- src/View/D90AdisTS/Window.py | 23 ++++++++++++++---- src/View/DIFAdisTS/Window.py | 23 ++++++++++++++---- src/View/InitialConditionsAdisTS/Window.py | 24 ++++++++++++++----- .../LateralContributionsAdisTS/Edit/Window.py | 12 +++++++--- src/View/LateralContributionsAdisTS/Window.py | 14 +++++++---- src/View/Network/GraphWidget.py | 3 ++- src/View/Pollutants/Edit/Window.py | 8 +++++-- src/View/Pollutants/UndoCommand.py | 4 ++-- src/View/Pollutants/Window.py | 13 +++++++--- 11 files changed, 115 insertions(+), 37 deletions(-) diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Window.py b/src/View/BoundaryConditionsAdisTS/Edit/Window.py index 837f9f56..fac2cf4a 100644 --- a/src/View/BoundaryConditionsAdisTS/Edit/Window.py +++ b/src/View/BoundaryConditionsAdisTS/Edit/Window.py @@ -89,6 +89,12 @@ class EditBoundaryConditionWindow(PamhyrWindow): def setup_table(self): table_headers = self._trad.get_dict("table_headers") + + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + if self._data.type == "Concentration": self._data.header = ["time", "concentration"] else: @@ -108,7 +114,7 @@ class EditBoundaryConditionWindow(PamhyrWindow): self._table = TableModel( table_view=table, table_headers=headers, - editable_headers=self._data.header, + editable_headers=editable_headers, delegates={ # "time": self._delegate_time, }, @@ -141,9 +147,10 @@ class EditBoundaryConditionWindow(PamhyrWindow): self.plot.draw() def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_del").triggered.connect(self.delete) - self.find(QAction, "action_sort").triggered.connect(self.sort) + if self._study.is_editable(): + self.find(QAction, "action_add").triggered.connect(self.add) + self.find(QAction, "action_del").triggered.connect(self.delete) + self.find(QAction, "action_sort").triggered.connect(self.sort) self._table.dataChanged.connect(self.update) def update(self): diff --git a/src/View/BoundaryConditionsAdisTS/Window.py b/src/View/BoundaryConditionsAdisTS/Window.py index 439e2acf..b1b4a411 100644 --- a/src/View/BoundaryConditionsAdisTS/Window.py +++ b/src/View/BoundaryConditionsAdisTS/Window.py @@ -106,11 +106,16 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow): parent=self ) + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + table = self.find(QTableView, f"tableView") self._table = TableModel( table_view=table, table_headers=self._trad.get_dict("table_headers"), - editable_headers=["type", "node", "pol"], + editable_headers=editable_headers, delegates={ "type": self._delegate_type, "node": self._delegate_node, @@ -137,8 +142,10 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow): self.graph_layout.addWidget(self.graph_widget) def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_del").triggered.connect(self.delete) + if self._study.is_editable(): + self.find(QAction, "action_add").triggered.connect(self.add) + self.find(QAction, "action_del").triggered.connect(self.delete) + self.find(QAction, "action_edit").triggered.connect(self.edit) def index_selected_row(self): diff --git a/src/View/D90AdisTS/Window.py b/src/View/D90AdisTS/Window.py index 3f76bca3..b24f99b6 100644 --- a/src/View/D90AdisTS/Window.py +++ b/src/View/D90AdisTS/Window.py @@ -99,12 +99,17 @@ class D90AdisTSWindow(PamhyrWindow): path_icons = os.path.join(self._get_ui_directory(), f"ressources") + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + table_default = self.find(QTableView, f"tableView") self._table = D90TableDefaultModel( table_view=table_default, table_headers=self._trad.get_dict("table_headers"), - editable_headers=["name", "d90"], + editable_headers=editable_headers, delegates={}, data=self._data, undo=self._undo_stack, @@ -124,10 +129,15 @@ class D90AdisTSWindow(PamhyrWindow): action_add = QAction(self) action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png"))) - action_add.triggered.connect(self.add) + + if self._study.is_editable(): + action_add.triggered.connect(self.add) + action_delete = QAction(self) action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png"))) - action_delete.triggered.connect(self.delete) + + if self._study.is_editable(): + action_delete.triggered.connect(self.delete) toolBar.addAction(action_add) toolBar.addAction(action_delete) @@ -150,10 +160,15 @@ class D90AdisTSWindow(PamhyrWindow): mode="rk" ) + if self._study.is_editable(): + editable_headers_spec = self._trad.get_dict("table_headers_spec") + else: + editable_headers_spec = [] + self._table_spec = D90TableModel( table_view=self.table_spec, table_headers=self._trad.get_dict("table_headers_spec"), - editable_headers=["name", "reach", "start_rk", "end_rk", "d90"], + editable_headers=editable_headers_spec, delegates={ "reach": self._delegate_reach, "start_rk": self._delegate_rk, diff --git a/src/View/DIFAdisTS/Window.py b/src/View/DIFAdisTS/Window.py index 304cce3b..d2b637e8 100644 --- a/src/View/DIFAdisTS/Window.py +++ b/src/View/DIFAdisTS/Window.py @@ -99,6 +99,11 @@ class DIFAdisTSWindow(PamhyrWindow): table_default = self.find(QTableView, f"tableView") + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + self._delegate_method = ComboBoxDelegate( trad=self._trad, data=self._study.river, @@ -110,7 +115,7 @@ class DIFAdisTSWindow(PamhyrWindow): self._table = DIFTableDefaultModel( table_view=table_default, table_headers=self._trad.get_dict("table_headers"), - editable_headers=["method", "dif", "b", "c"], + editable_headers=editable_headers, delegates={ "method": self._delegate_method }, @@ -132,10 +137,14 @@ class DIFAdisTSWindow(PamhyrWindow): action_add = QAction(self) action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png"))) - action_add.triggered.connect(self.add) + + if self._study.is_editable(): + action_add.triggered.connect(self.add) action_delete = QAction(self) action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png"))) - action_delete.triggered.connect(self.delete) + + if self._study.is_editable(): + action_delete.triggered.connect(self.delete) toolBar.addAction(action_add) toolBar.addAction(action_delete) @@ -158,11 +167,15 @@ class DIFAdisTSWindow(PamhyrWindow): mode="rk" ) + if self._study.is_editable(): + editable_headers_spec = self._trad.get_dict("table_headers_spec") + else: + editable_headers_spec = [] + self._table_spec = DIFTableModel( table_view=self.table_spec, table_headers=self._trad.get_dict("table_headers_spec"), - editable_headers=["method", "reach", "start_rk", - "end_rk", "dif", "b", "c"], + editable_headers=editable_headers_spec, delegates={ "method": self._delegate_method, "reach": self._delegate_reach, diff --git a/src/View/InitialConditionsAdisTS/Window.py b/src/View/InitialConditionsAdisTS/Window.py index a38ad0ff..46b84d55 100644 --- a/src/View/InitialConditionsAdisTS/Window.py +++ b/src/View/InitialConditionsAdisTS/Window.py @@ -108,10 +108,15 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): table_default = self.find(QTableView, f"tableView") + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + self._table = InitialConditionTableDefaultModel( table_view=table_default, table_headers=self._trad.get_dict("table_headers"), - editable_headers=["name", "concentration", "eg", "em", "ed"], + editable_headers=editable_headers, delegates={}, data=self._data, undo=self._undo_stack, @@ -131,10 +136,14 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): action_add = QAction(self) action_add.setIcon(QIcon(os.path.join(path_icons, f"add.png"))) - action_add.triggered.connect(self.add) + + if self._study.is_editable(): + action_add.triggered.connect(self.add) action_delete = QAction(self) action_delete.setIcon(QIcon(os.path.join(path_icons, f"del.png"))) - action_delete.triggered.connect(self.delete) + + if self._study.is_editable(): + action_delete.triggered.connect(self.delete) toolBar.addAction(action_add) toolBar.addAction(action_delete) @@ -157,12 +166,15 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): mode="rk" ) + if self._study.is_editable(): + editable_headers_spec = self._trad.get_dict("table_headers_spec") + else: + editable_headers_spec = [] + self._table_spec = InitialConditionTableModel( table_view=self.table_spec, table_headers=self._trad.get_dict("table_headers_spec"), - editable_headers=["name", "reach", "start_rk", - "end_rk", "concentration", - "eg", "em", "ed", "rate"], + editable_headers=editable_headers_spec, delegates={ "reach": self._delegate_reach, "start_rk": self._delegate_rk, diff --git a/src/View/LateralContributionsAdisTS/Edit/Window.py b/src/View/LateralContributionsAdisTS/Edit/Window.py index 01aa64fb..820b81c6 100644 --- a/src/View/LateralContributionsAdisTS/Edit/Window.py +++ b/src/View/LateralContributionsAdisTS/Edit/Window.py @@ -103,6 +103,11 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow): parent=self ) + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + headers = {} table_headers = self._trad.get_dict("table_headers") for h in self._data.header: @@ -112,7 +117,7 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow): self._table = TableModel( table_view=table, table_headers=headers, - editable_headers=self._data.header, + editable_headers=editable_headers, delegates={ # "time": self._delegate_time, }, @@ -147,8 +152,9 @@ class EditLateralContributionAdisTSWindow(PamhyrWindow): self.plot.draw() def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_del").triggered.connect(self.delete) + if self._study.is_editable(): + self.find(QAction, "action_add").triggered.connect(self.add) + self.find(QAction, "action_del").triggered.connect(self.delete) self._table.dataChanged.connect(self.update) diff --git a/src/View/LateralContributionsAdisTS/Window.py b/src/View/LateralContributionsAdisTS/Window.py index 491c44f4..1103506e 100644 --- a/src/View/LateralContributionsAdisTS/Window.py +++ b/src/View/LateralContributionsAdisTS/Window.py @@ -92,9 +92,13 @@ class LateralContributionAdisTSWindow(PamhyrWindow): def setup_table(self): self._table = {} - self._delegate_rk = [] + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + delegate_rk = ComboBoxDelegate( data=None, mode="rk", @@ -114,7 +118,7 @@ class LateralContributionAdisTSWindow(PamhyrWindow): self._table = TableModel( table_view=table, table_headers=self._trad.get_dict("table_headers"), - editable_headers=self._trad.get_dict("table_headers"), + editable_headers=editable_headers, delegates={ "reach": self._delegate_reach, "begin_rk": delegate_rk, @@ -146,8 +150,10 @@ class LateralContributionAdisTSWindow(PamhyrWindow): ) def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_del").triggered.connect(self.delete) + if self._study.is_editable(): + self.find(QAction, "action_add").triggered.connect(self.add) + self.find(QAction, "action_del").triggered.connect(self.delete) + self.find(QAction, "action_edit").triggered.connect(self.edit) table = self.find(QTableView, f"tableView") diff --git a/src/View/Network/GraphWidget.py b/src/View/Network/GraphWidget.py index 4646a011..5c41ee9d 100644 --- a/src/View/Network/GraphWidget.py +++ b/src/View/Network/GraphWidget.py @@ -965,7 +965,8 @@ class GraphWidget(QGraphicsView): if self.selected_new_edge_src_node() is None: self.set_selected_new_edge_src_node(nodes[0]) else: - self.add_edge(self.selected_new_edge_src_node(), nodes[0]) + self.add_edge(self.selected_new_edge_src_node(), + nodes[0]) # Delete nodes and edges elif self._state == "del": diff --git a/src/View/Pollutants/Edit/Window.py b/src/View/Pollutants/Edit/Window.py index 4135b52d..bade6cae 100644 --- a/src/View/Pollutants/Edit/Window.py +++ b/src/View/Pollutants/Edit/Window.py @@ -76,14 +76,18 @@ class EditPolluantWindow(PamhyrWindow): self.setup_table() def setup_table(self): - headers = {} table_headers = self._trad.get_dict("table_headers") + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + table = self.find(QTableView, "tableView") self._table = TableModel( table_view=table, table_headers=table_headers, - editable_headers=table_headers, + editable_headers=editable_headers, delegates={}, data=self._data, undo=self._undo_stack, diff --git a/src/View/Pollutants/UndoCommand.py b/src/View/Pollutants/UndoCommand.py index f27958c8..2526efb4 100644 --- a/src/View/Pollutants/UndoCommand.py +++ b/src/View/Pollutants/UndoCommand.py @@ -54,10 +54,10 @@ class SetEnabledCommand(QUndoCommand): self._new = enabled def undo(self): - self._pollutants_lst.get(self._index).enabled = self._old + self._pollutants_lst[self._index].enabled = self._old def redo(self): - self._pollutants_lst.get(self._index).enabled = self._new + self._pollutants_lst[self._index].enabled = self._new class AddCommand(QUndoCommand): diff --git a/src/View/Pollutants/Window.py b/src/View/Pollutants/Window.py index 75055462..5419c5ef 100644 --- a/src/View/Pollutants/Window.py +++ b/src/View/Pollutants/Window.py @@ -78,11 +78,16 @@ class PollutantsWindow(PamhyrWindow): def setup_table(self): self._table = None + if self._study.is_editable(): + editable_headers = self._trad.get_dict("table_headers") + else: + editable_headers = [] + table = self.find(QTableView, f"tableView") self._table = TableModel( table_view=table, table_headers=self._trad.get_dict("table_headers"), - editable_headers=["name"], + editable_headers=editable_headers, trad=self._trad, data=self._study.river, undo=self._undo_stack, @@ -104,8 +109,10 @@ class PollutantsWindow(PamhyrWindow): self._set_checkbox_state() def setup_connections(self): - self.find(QAction, "action_add").triggered.connect(self.add) - self.find(QAction, "action_delete").triggered.connect(self.delete) + if self._study.is_editable(): + self.find(QAction, "action_add").triggered.connect(self.add) + self.find(QAction, "action_delete").triggered.connect(self.delete) + self.find(QAction, "action_edit").triggered.connect(self.edit) self.find(QAction, "action_initial_conditions" ).triggered.connect(self.initial_conditions)