mirror of https://gitlab.com/pamhyr/pamhyr2
Split reach : disabled endpoint and struture-linked profiles in reach split selector, instead of deleting them from the list
parent
d97620ad56
commit
a0d8b9ea43
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in New Issue