From 3087023caafdc151aa8f8167c2165bd8d6906c5e Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Thu, 28 May 2026 11:44:03 +0200 Subject: [PATCH] Pollutants: Add translation for type of pol --- src/Model/Pollutants/Pollutants.py | 12 ------------ src/View/Pollutants/Edit/Table.py | 23 ++++++++++++++++------- src/View/Pollutants/Edit/Translate.py | 22 ++++++++++++++++++++++ src/View/Pollutants/Edit/Window.py | 1 + 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/src/Model/Pollutants/Pollutants.py b/src/Model/Pollutants/Pollutants.py index 080a4dfc..982a9325 100644 --- a/src/Model/Pollutants/Pollutants.py +++ b/src/Model/Pollutants/Pollutants.py @@ -34,18 +34,6 @@ from Model.BoundaryConditionsAdisTS.BoundaryConditionAdisTS import ( logger = logging.getLogger() -# Types de polluants: indice -> nom du type -POLLUTANT_TYPES = { - 0: "Soluté", - 1: "Particules sphériques", - 2: "Galets lisses", - 3: "Sable naturel", - 4: "Sable concassé", - 5: "Cylindres longs", - 6: "Limon, particules cohésives", - 7: "Flocs" -} - class PollutantCharacteristics(SQLSubModel): _sub_classes = [] diff --git a/src/View/Pollutants/Edit/Table.py b/src/View/Pollutants/Edit/Table.py index 26b77b61..87c6b808 100644 --- a/src/View/Pollutants/Edit/Table.py +++ b/src/View/Pollutants/Edit/Table.py @@ -40,8 +40,6 @@ from View.Pollutants.Edit.UndoCommand import ( SetDataCommand, PasteCommand, ) -from Model.Pollutants.Pollutants import POLLUTANT_TYPES - _translate = QCoreApplication.translate logger = logging.getLogger() @@ -51,17 +49,20 @@ class ComboBoxDelegate(QItemDelegate): def __init__(self, type_dict=None, trad=None, parent=None): super(ComboBoxDelegate, self).__init__(parent) - self._type_dict = type_dict if type_dict else POLLUTANT_TYPES + # self._type_dict = type_dict if type_dict else POLLUTANT_TYPES self._trad = trad self.editor = None + self._type = {} + if self._trad is not None: + self._type = self._trad.get_dict("type") + def createEditor(self, parent, option, index): self.editor = QComboBox(parent) # Ajouter les items du dictionnaire - for key in sorted(self._type_dict.keys()): - display_text = self._type_dict[key] - self.editor.addItem(display_text, userData=key) + for key, value in self._type.items(): + self.editor.addItem(value, key) self.editor.currentTextChanged.connect(self.currentItemChanged) return self.editor @@ -96,6 +97,14 @@ class ComboBoxDelegate(QItemDelegate): class TableModel(PamhyrTableModel): + def __init__(self, trad=None, **kwargs): + self._trad = trad + self._types = {} + if self._trad is not None: + self._types = self._trad.get_dict("types") + + super(TableModel, self).__init__(trad=trad, **kwargs) + def is_same_data(self, index, value): row = index.row() column = index.column() @@ -122,7 +131,7 @@ class TableModel(PamhyrTableModel): # Si c'est la colonne "type", convertir l'indice en string if self._headers[column] == "type": - return POLLUTANT_TYPES.get(int(value), str(value)) + value = self._trad.get_dict("type").get(value, "") return value diff --git a/src/View/Pollutants/Edit/Translate.py b/src/View/Pollutants/Edit/Translate.py index b11a55fd..acd0877c 100644 --- a/src/View/Pollutants/Edit/Translate.py +++ b/src/View/Pollutants/Edit/Translate.py @@ -24,6 +24,17 @@ from View.Pollutants.Translate import PollutantsTranslate _translate = QCoreApplication.translate +# Types de polluants: indice -> nom du type +POLLUTANT_TYPES = { + 0: "Solutes", + 1: "Spherical particles", + 2: "Smooth pebbles", + 3: "Natural sand", + 4: "Crushed sand", + 5: "Elongated cylinders", + 6: "Silts, cohesive particles", + 7: "Flocs" +} class EditPollutantTranslate(PollutantsTranslate): def __init__(self): @@ -44,3 +55,14 @@ class EditPollutantTranslate(PollutantsTranslate): "ac": self._dict["unit_ac"], "bc": self._dict["unit_bc"], } + + self._sub_dict["type"] = { + 0: _translate("Pollutants", "Solutes"), + 1: _translate("Pollutants", "Spherical particles"), + 2: _translate("Pollutants", "Smooth pebbles"), + 3: _translate("Pollutants", "Natural sand"), + 4: _translate("Pollutants", "Crushed sand"), + 5: _translate("Pollutants", "Elongated cylinders"), + 6: _translate("Pollutants", "Silts, cohesive particles"), + 7: _translate("Pollutants", "Flocs"), + } diff --git a/src/View/Pollutants/Edit/Window.py b/src/View/Pollutants/Edit/Window.py index d0061f80..c07e3c68 100644 --- a/src/View/Pollutants/Edit/Window.py +++ b/src/View/Pollutants/Edit/Window.py @@ -95,6 +95,7 @@ class EditPolluantWindow(PamhyrWindow): editable_headers=editable_headers, delegates={"type": self._delegate_type}, data=self._data, + trad=self._trad, undo=self._undo_stack, opt_data=self._study.time_system )