From dee1271fe188b0e44abe83bc95b9732610b3d1cc Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Fri, 8 Sep 2023 18:59:14 +0200 Subject: [PATCH] add action to context menu to replace single set fit parameter with general fit parameter --- src/gui_qt/fit/fit_forms.py | 2 ++ src/gui_qt/fit/fit_parameter.py | 8 ++++++++ src/gui_qt/lib/forms.py | 7 ++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gui_qt/fit/fit_forms.py b/src/gui_qt/fit/fit_forms.py index ed215cf..db7561d 100644 --- a/src/gui_qt/fit/fit_forms.py +++ b/src/gui_qt/fit/fit_forms.py @@ -13,6 +13,7 @@ class FitModelWidget(QtWidgets.QWidget, Ui_FitParameter): value_requested = QtCore.pyqtSignal(object) value_changed = QtCore.pyqtSignal(str) state_changed = QtCore.pyqtSignal() + replace_single_value = QtCore.pyqtSignal(object) def __init__(self, label: str = 'Fitparameter', parent=None, fixed: bool = False): super().__init__(parent) @@ -32,6 +33,7 @@ class FitModelWidget(QtWidgets.QWidget, Ui_FitParameter): self.checkBox.stateChanged.connect(self.enableBounds) self.global_checkbox.stateChanged.connect(lambda: self.state_changed.emit()) self.parameter_line.values_requested.connect(lambda: self.value_requested.emit(self)) + self.parameter_line.replace_single_values.connect(lambda: self.replace_single_value.emit(None)) self.parameter_line.editingFinished.connect(lambda: self.value_changed.emit(self.parameter_line.text())) self.fixed_check.toggled.connect(self.set_fixed) diff --git a/src/gui_qt/fit/fit_parameter.py b/src/gui_qt/fit/fit_parameter.py index 3229f10..6c3ec60 100644 --- a/src/gui_qt/fit/fit_parameter.py +++ b/src/gui_qt/fit/fit_parameter.py @@ -78,6 +78,7 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit): widgt.state_changed.connect(self.make_global) widgt.value_requested.connect(self.look_for_value) widgt.value_changed.connect(self.change_global_parameter) + widgt.replace_single_value.connect(self.delete_single_parameter) self.global_parameter.append(widgt) self.scrollwidget.layout().addWidget(widgt) @@ -148,6 +149,13 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit): if value is None: self.change_data(self.comboBox.currentIndex()) + def delete_single_parameter(self): + idx = self.global_parameter.index(self.sender()) + for i in range(self.comboBox.count()): + set_id = self.comboBox.itemData(i) + self.data_values[set_id][idx] = None + self.change_data(self.comboBox.currentIndex()) + def change_single_choice(self, _, value, sender=None): if sender is None: sender = self.sender() diff --git a/src/gui_qt/lib/forms.py b/src/gui_qt/lib/forms.py index c0b73aa..ab20ce3 100644 --- a/src/gui_qt/lib/forms.py +++ b/src/gui_qt/lib/forms.py @@ -52,19 +52,24 @@ class QDelayWidget(QtWidgets.QWidget): class LineEdit(QtWidgets.QLineEdit): values_requested = QtCore.pyqtSignal() + replace_single_values = QtCore.pyqtSignal() def __init__(self, parent=None): super().__init__(parent=parent) def contextMenuEvent(self, evt): menu = self.createStandardContextMenu() - request_action = menu.addAction('Use value of sets') + request_action = menu.addAction('Use numeric value of sets') + set_value_action = menu.addAction('Replace single set values') action = menu.exec(evt.globalPos()) if action == request_action: self.values_requested.emit() + elif action == set_value_action: + self.replace_single_values.emit() + class LineEditPost(QtWidgets.QLineEdit): values_requested = QtCore.pyqtSignal()