194-fitrange #219

Merged
dominik merged 7 commits from 194-fitrange into master 2024-01-18 18:25:07 +00:00
Showing only changes of commit c508965a28 - Show all commits

View File

@ -62,7 +62,7 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit):
self.glob_values = [1] * len(func.params) self.glob_values = [1] * len(func.params)
for k, v in enumerate(func.params): for k, v in enumerate(func.params):
widgt = ParameterGlobalWidget(label=v, parent=self.scrollwidget) widgt = ParameterGlobalWidget(name=v, parent=self.scrollwidget)
widgt.parameter_pos = k widgt.parameter_pos = k
widgt.func_idx = idx widgt.func_idx = idx
try: try:
@ -290,36 +290,57 @@ class QFitParameterWidget(QtWidgets.QWidget, Ui_FormFit):
return param_len return param_len
class ParameterSingleWidget(QtWidgets.QWidget, Ui_FitParameter): class ParameterSingleWidget(QtWidgets.QWidget):
valueChanged = QtCore.pyqtSignal(object) valueChanged = QtCore.pyqtSignal(object)
removeSingleValue = QtCore.pyqtSignal() removeSingleValue = QtCore.pyqtSignal()
def __init__(self, name: str, parent=None): def __init__(self, name: str, parent=None):
super().__init__(parent=parent) super().__init__(parent=parent)
self.setupUi(self)
self._init_ui()
self.name = name self.name = name
self.parametername.setText(convert(name)) self.parametername.setText(convert(name))
self.parametername.setToolTip('If this is bold then this parameter is only for this data. ' self.parametername.setToolTip('If this is bold then this parameter is only for this data. '
'Otherwise, the general parameter is used and displayed') 'Otherwise, the general parameter is used and displayed')
self.parameter_line.textChanged.connect(lambda: self.valueChanged.emit(self.value) if self.value is not None else 0) # self.value_line.setValidator(QtGui.QDoubleValidator())
self.value_line.textChanged.connect(lambda: self.valueChanged.emit(self.value) if self.value is not None else 0)
self.reset_button.clicked.connect(lambda x: self.removeSingleValue.emit()) self.reset_button.clicked.connect(lambda x: self.removeSingleValue.emit())
self.global_checkbox.setVisible(False) def _init_ui(self):
layout = QtWidgets.QHBoxLayout(self)
layout.setContentsMargins(2, 2, 2, 2)
layout.setSpacing(2)
self.parametername = QtWidgets.QLabel(self)
layout.addWidget(self.parametername)
layout.addSpacerItem(QtWidgets.QSpacerItem(0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum))
self.value_line = QtWidgets.QLineEdit(self)
self.value_line.textEdited.connect(lambda x: self.show_as_local_parameter(True))
layout.addWidget(self.value_line)
self.reset_button = QtWidgets.QToolButton(self)
self.reset_button.setText('Use global')
self.reset_button.clicked.connect(lambda: self.show_as_local_parameter(False))
layout.addWidget(self.reset_button)
self.setLayout(layout)
@property @property
def value(self) -> float: def value(self) -> float:
try: try:
return float(self.parameter_line.text().replace(',', '.')) return float(self.value_line.text().replace(',', '.'))
except ValueError: except ValueError:
return 0.0 return 0.0
@value.setter @value.setter
def value(self, val): def value(self, val):
# self.value_line.setText(f'{float(val):.5g}') # self.value_line.setText(f'{float(val):.5g}')
self.parameter_line.setText(f'{val}') self.value_line.setText(f'{val}')
self.parameter_line.setCursorPosition(0) self.value_line.setCursorPosition(0)
def show_as_local_parameter(self, is_local: bool): def show_as_local_parameter(self, is_local: bool):
if is_local: if is_local:
@ -338,21 +359,21 @@ class ParameterGlobalWidget(QtWidgets.QWidget, Ui_FitParameter):
state_changed = QtCore.pyqtSignal() state_changed = QtCore.pyqtSignal()
replace_single_value = QtCore.pyqtSignal(object) replace_single_value = QtCore.pyqtSignal(object)
def __init__(self, label: str = 'Fitparameter', parent=None, fixed: bool = False): def __init__(self, name: str = 'Fitparameter', parent=None, fixed: bool = False):
super().__init__(parent) super().__init__(parent)
self.setupUi(self) self.setupUi(self)
self.name = label self.name = name
self.reset_button.setVisible(False) self.reset_button.setVisible(False)
self.parametername.setText(convert(label) + ' ') self.parametername.setText(convert(name) + ' ')
self.parameter_line.setText('1') self.parameter_line.setText('1')
self.parameter_line.setMaximumWidth(160) self.parameter_line.setMaximumWidth(160)
self.lineEdit.setMaximumWidth(100) self.lineEdit.setMaximumWidth(100)
self.lineEdit_2.setMaximumWidth(100) self.lineEdit_2.setMaximumWidth(100)
self.label_3.setText(f'< {convert(label)} <') self.label_3.setText(f'< {convert(name)} <')
self.checkBox.stateChanged.connect(self.enableBounds) self.checkBox.stateChanged.connect(self.enableBounds)
self.global_checkbox.stateChanged.connect(lambda: self.state_changed.emit()) self.global_checkbox.stateChanged.connect(lambda: self.state_changed.emit())