From a0d8b9ea43a0f678b6c8e132aed6988186b22fc7 Mon Sep 17 00:00:00 2001 From: Dylan Jeannin Date: Wed, 9 Sep 2026 13:54:01 +0200 Subject: [PATCH] Split reach : disabled endpoint and struture-linked profiles in reach split selector, instead of deleting them from the list --- src/View/Network/ProfileDialog.py | 32 ++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/View/Network/ProfileDialog.py b/src/View/Network/ProfileDialog.py index 8abc415f..f37c6ba8 100644 --- a/src/View/Network/ProfileDialog.py +++ b/src/View/Network/ProfileDialog.py @@ -64,7 +64,17 @@ class SelectProfileDialog(PamhyrDialog): self._reach = reach self._profile = None - self._profiles = self._reach.reach.enabled_profiles + self._profiles = list(self._reach.reach.profiles) + structure_profiles = [ + structure.input_section + for structure in study.river.hydraulic_structures.lst + if structure.input_reach is reach and not structure.is_deleted() + ] + self._selectable_indices = [ + index for index, profile in enumerate(self._profiles) + if 0 < index < len(self._profiles) - 1 + and profile not in structure_profiles + ] self.setup_combobox() @@ -74,19 +84,27 @@ class SelectProfileDialog(PamhyrDialog): list( map( lambda p: p.display_name(), - self._reach.reach.profiles[1:-1] + self._profiles ) ) ) - if len(self._profiles) == 0: - self.find(QDialogButtonBox, "buttonBox")\ - .button(QDialogButtonBox.Ok)\ - .setEnabled(False) + combobox = self.find(QComboBox, "comboBox") + for index in range(len(self._profiles)): + if index not in self._selectable_indices: + item = combobox.model().item(index) + item.setFlags(item.flags() & ~(Qt.ItemIsEnabled | Qt.ItemIsSelectable)) + + combobox.setCurrentIndex( + self._selectable_indices[0] if self._selectable_indices else -1 + ) + self.find(QDialogButtonBox, "buttonBox")\ + .button(QDialogButtonBox.Ok)\ + .setEnabled(bool(self._selectable_indices)) def accept(self): index = self.find(QComboBox, "comboBox").currentIndex() - if not 0 <= index < len(self._profiles): + if index not in self._selectable_indices: return self._profile = self._profiles[index]