Skip to content

Commit

Permalink
Simplify some of the logic for handling multiplicity models
Browse files Browse the repository at this point in the history
  • Loading branch information
krzywon committed Sep 21, 2023
1 parent 22fe701 commit b3a21cc
Showing 1 changed file with 7 additions and 38 deletions.
45 changes: 7 additions & 38 deletions src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2161,8 +2161,6 @@ def updateModelFromList(self, param_dict):
Update the model with new parameters, create the errors column
"""
assert isinstance(param_dict, dict)
if not dict:
return

def updateFittedValues(row):
# Utility function for main model update
Expand Down Expand Up @@ -4288,40 +4286,26 @@ def gatherParams(row):
Create list of main parameters based on _model_model
"""
param_name = str(self._model_model.item(row, 0).text())
current_list = self.tabToList[self.tabFitting.currentIndex()]
model = self._model_model
if model.item(row, 0) is None:
return
# Assure this is a parameter - must contain a checkbox
if not model.item(row, 0).isCheckable():
# maybe it is a combobox item (multiplicity)
try:
index = model.index(row, 1)
widget = current_list.indexWidget(index)
if widget is None:
return
if isinstance(widget, QtWidgets.QComboBox):
# find the index of the combobox
current_index = widget.currentIndex()
param_list.append([param_name, 'None', str(current_index)])
except Exception as ex:
pass
return

param_checked = str(model.item(row, 0).checkState() == QtCore.Qt.Checked)
param_checked = None
else:
param_checked = str(model.item(row, 0).checkState() == QtCore.Qt.Checked)
# Value of the parameter. In some cases this is the text of the combobox choice.
param_value = str(model.item(row, 1).text())
param_error = None
param_min = None
param_max = None
_, param_min, param_max = self.kernel_module.details.get(param_name, ('', None, None))
column_offset = 0
if self.has_error_column:
column_offset = 1
param_error = str(model.item(row, 1+column_offset).text())
try:
param_min = str(model.item(row, 2+column_offset).text())
param_max = str(model.item(row, 3+column_offset).text())
except:
except Exception:
pass
# Do we have any constraints on this parameter?
constraint = self.getConstraintForRow(row, model_key="standard")
Expand Down Expand Up @@ -4434,10 +4418,9 @@ def updatePageWithParameters(self, line_dict, warn_user=True):
self.chk2DView.setChecked(line_dict['2D_params'][0]=='True')

# Create the context dictionary for parameters
# Exclude multiplicity and number of shells params from context
context = {k: v for (k, v) in line_dict.items() if len(v) > 3 and k != model}
context['model_name'] = model
for key, value in line_dict.items():
if len(value) > 2:
context[key] = value

if warn_user and str(self.cbModel.currentText()) != str(context['model_name']):
msg = QtWidgets.QMessageBox()
Expand Down Expand Up @@ -4513,20 +4496,6 @@ def updateFittedValues(row):
param_name = str(self._model_model.item(row, 0).text())
if param_name not in list(param_dict.keys()):
return
# Special case of combo box in the cell (multiplicity)
param_line = param_dict[param_name]
if len(param_line) == 1:
# modify the shells value
try:
combo_index = int(param_line[0])
except ValueError:
# quietly pass
return
index = self._model_model.index(row, 1)
widget = self.lstParams.indexWidget(index)
if widget is not None and isinstance(widget, QtWidgets.QComboBox):
#widget.setCurrentIndex(combo_index)
return
# checkbox state
param_checked = QtCore.Qt.Checked if param_dict[param_name][0] == "True" else QtCore.Qt.Unchecked
self._model_model.item(row, 0).setCheckState(param_checked)
Expand Down

0 comments on commit b3a21cc

Please # to comment.