From db62af6f718c8169d5b899b8f1ce95b0411a02f2 Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Mon, 27 Jul 2026 16:28:14 +0200 Subject: [PATCH] Friction: application's strickler now appears in combobox to pick a strickler, and create a copy of it in the study --- src/View/Frictions/Table.py | 56 ++++++++++++++++++++++++++++++++++-- src/View/Frictions/Window.py | 4 +++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/View/Frictions/Table.py b/src/View/Frictions/Table.py index 6d2081d8..48f5ca63 100644 --- a/src/View/Frictions/Table.py +++ b/src/View/Frictions/Table.py @@ -52,27 +52,58 @@ _translate = QCoreApplication.translate class ComboBoxDelegate(QItemDelegate): - def __init__(self, data=None, study=None, + def __init__(self, data=None, study=None, application_stricklers=None, mode="stricklers", trad=None, display_manning=True, parent=None): super(ComboBoxDelegate, self).__init__(parent) self._data = data self._study = study + self._application_stricklers = application_stricklers or [] self._trad = trad self._mode = mode self._display_manning = display_manning + @staticmethod + def same_strickler(first, second): + return ( + first.name == second.name + and first.comment == second.comment + and first.minor == second.minor + and first.medium == second.medium + ) + def createEditor(self, parent, option, index): self.editor = QComboBox(parent) if self._mode == "stricklers": self.editor.addItem(self._trad["not_defined"], None) - for strickler in self._study.river.stricklers.stricklers: + study_stricklers = self._study.river.stricklers.stricklers + for strickler in study_stricklers: self.editor.addItem( display_strickler(strickler, self._display_manning), strickler ) + + application_stricklers = [ + application_strickler + for application_strickler in self._application_stricklers + if not any( + self.same_strickler( + application_strickler, study_strickler + ) + for study_strickler in study_stricklers + ) + ] + if application_stricklers: + self.editor.insertSeparator(self.editor.count()) + for strickler in application_stricklers: + self.editor.addItem( + display_strickler( + strickler, self._display_manning + ), + strickler + ) elif self._mode == "rk": self.editor.addItems( list(map(str, self._data.reach.get_rk())) @@ -113,6 +144,25 @@ class FrictionTableModel(PamhyrTableModel): self._lst = self._data.frictions self._study = self._opt_data + def study_strickler(self, strickler): + if strickler is None: + return None + + study_stricklers = self._study.river.stricklers + if any(s is strickler for s in study_stricklers.stricklers): + return strickler + + for current in study_stricklers.stricklers: + if ComboBoxDelegate.same_strickler(current, strickler): + return current + + copied = study_stricklers.new(len(study_stricklers)) + copied.name = strickler.name + copied.comment = strickler.comment + copied.minor = strickler.minor + copied.medium = strickler.medium + return copied + def data(self, index, role): if role != Qt.ItemDataRole.DisplayRole: return QVariant() @@ -171,6 +221,7 @@ class FrictionTableModel(PamhyrTableModel): elif self._headers[column] == "begin_strickler": strickler = value if hasattr(value, "minor") else \ self._study.river.strickler(value) + strickler = self.study_strickler(strickler) self._undo.push( SetBeginStricklerCommand( self._lst, row, strickler @@ -179,6 +230,7 @@ class FrictionTableModel(PamhyrTableModel): elif self._headers[column] == "end_strickler": strickler = value if hasattr(value, "minor") else \ self._study.river.strickler(value) + strickler = self.study_strickler(strickler) self._undo.push( SetEndStricklerCommand( self._lst, row, strickler diff --git a/src/View/Frictions/Window.py b/src/View/Frictions/Window.py index 4d6c2528..9ecfe98c 100644 --- a/src/View/Frictions/Window.py +++ b/src/View/Frictions/Window.py @@ -104,6 +104,10 @@ class FrictionsWindow(PamhyrWindow): self._delegate_stricklers = ComboBoxDelegate( data=self._reach, study=self._study, + application_stricklers=( + self._config.stricklers.stricklers + if self._config is not None else [] + ), mode="stricklers", trad=self._trad, display_manning=getattr(self._config, "display_manning", False),