mirror of https://gitlab.com/pamhyr/pamhyr2
Friction: application's strickler now appears in combobox to pick a strickler, and create a copy of it in the study
parent
b468a1eb70
commit
db62af6f71
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Reference in New Issue