Friction: application's strickler now appears in combobox to pick a strickler, and create a copy of it in the study

manning
Dylan Jeannin 2026-07-27 16:28:14 +02:00
parent b468a1eb70
commit db62af6f71
2 changed files with 58 additions and 2 deletions

View File

@ -52,27 +52,58 @@ _translate = QCoreApplication.translate
class ComboBoxDelegate(QItemDelegate): 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, mode="stricklers", trad=None, display_manning=True,
parent=None): parent=None):
super(ComboBoxDelegate, self).__init__(parent) super(ComboBoxDelegate, self).__init__(parent)
self._data = data self._data = data
self._study = study self._study = study
self._application_stricklers = application_stricklers or []
self._trad = trad self._trad = trad
self._mode = mode self._mode = mode
self._display_manning = display_manning 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): def createEditor(self, parent, option, index):
self.editor = QComboBox(parent) self.editor = QComboBox(parent)
if self._mode == "stricklers": if self._mode == "stricklers":
self.editor.addItem(self._trad["not_defined"], None) 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( self.editor.addItem(
display_strickler(strickler, self._display_manning), display_strickler(strickler, self._display_manning),
strickler 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": elif self._mode == "rk":
self.editor.addItems( self.editor.addItems(
list(map(str, self._data.reach.get_rk())) list(map(str, self._data.reach.get_rk()))
@ -113,6 +144,25 @@ class FrictionTableModel(PamhyrTableModel):
self._lst = self._data.frictions self._lst = self._data.frictions
self._study = self._opt_data 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): def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole: if role != Qt.ItemDataRole.DisplayRole:
return QVariant() return QVariant()
@ -171,6 +221,7 @@ class FrictionTableModel(PamhyrTableModel):
elif self._headers[column] == "begin_strickler": elif self._headers[column] == "begin_strickler":
strickler = value if hasattr(value, "minor") else \ strickler = value if hasattr(value, "minor") else \
self._study.river.strickler(value) self._study.river.strickler(value)
strickler = self.study_strickler(strickler)
self._undo.push( self._undo.push(
SetBeginStricklerCommand( SetBeginStricklerCommand(
self._lst, row, strickler self._lst, row, strickler
@ -179,6 +230,7 @@ class FrictionTableModel(PamhyrTableModel):
elif self._headers[column] == "end_strickler": elif self._headers[column] == "end_strickler":
strickler = value if hasattr(value, "minor") else \ strickler = value if hasattr(value, "minor") else \
self._study.river.strickler(value) self._study.river.strickler(value)
strickler = self.study_strickler(strickler)
self._undo.push( self._undo.push(
SetEndStricklerCommand( SetEndStricklerCommand(
self._lst, row, strickler self._lst, row, strickler

View File

@ -104,6 +104,10 @@ class FrictionsWindow(PamhyrWindow):
self._delegate_stricklers = ComboBoxDelegate( self._delegate_stricklers = ComboBoxDelegate(
data=self._reach, data=self._reach,
study=self._study, study=self._study,
application_stricklers=(
self._config.stricklers.stricklers
if self._config is not None else []
),
mode="stricklers", mode="stricklers",
trad=self._trad, trad=self._trad,
display_manning=getattr(self._config, "display_manning", False), display_manning=getattr(self._config, "display_manning", False),