Changes in src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py [70f4458:bc7371fd] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
r70f4458 rbc7371fd 8 8 from sas.qtgui.Plotting.PlotterData import Data1D 9 9 from sas.qtgui.Plotting.PlotterData import Data2D 10 11 from sas.qtgui.Perspectives.Fitting.AssociatedComboBox import AssociatedComboBox 10 12 11 13 model_header_captions = ['Parameter', 'Value', 'Min', 'Max', 'Units'] … … 61 63 return (param_name, param_length) 62 64 63 def addParametersToModel(parameters, kernel_module, is2D): 64 """ 65 Update local ModelModel with sasmodel parameters 65 def createFixedChoiceComboBox(param, item_row): 66 """ 67 Determines whether param is a fixed-choice parameter, modifies items in item_row appropriately and returns a combo 68 box containing the fixed choices. Returns None if param is not fixed-choice. 69 70 item_row is a list of QStandardItem objects for insertion into the parameter table. 71 """ 72 73 # Determine whether this is a fixed-choice parameter. There are lots of conditionals, simply because the 74 # implementation is not yet concrete; there are several possible indicators that the parameter is fixed-choice. 75 # TODO: (when the sasmodels implementation is concrete, clean this up) 76 choices = None 77 if isinstance(param.choices, (list, tuple)) and len(param.choices) > 0: 78 # The choices property is concrete in sasmodels, probably will use this 79 choices = param.choices 80 elif isinstance(param.units, (list, tuple)): 81 choices = [str(x) for x in param.units] 82 83 cbox = None 84 if choices is not None: 85 # Use combo box for input, if it is fixed-choice 86 cbox = AssociatedComboBox(item_row[1], idx_as_value=True) 87 cbox.addItems(choices) 88 item_row[2].setEditable(False) 89 item_row[3].setEditable(False) 90 91 return cbox 92 93 def addParametersToModel(parameters, kernel_module, is2D, model=None, view=None): 94 """ 95 Update local ModelModel with sasmodel parameters. 96 Actually appends to model, if model and view params are not None. 97 Always returns list of lists of QStandardItems. 66 98 """ 67 99 multishell_parameters = getIterParams(parameters) … … 72 104 else: 73 105 params = parameters.iq_parameters 74 item = [] 106 107 rows = [] 75 108 for param in params: 76 109 # don't include shell parameters 77 110 if param.name == multishell_param_name: 78 111 continue 112 79 113 # Modify parameter name from <param>[n] to <param>1 80 114 item_name = param.name 81 115 if param in multishell_parameters: 82 116 continue 83 # item_name = replaceShellName(param.name, 1)84 117 85 118 item1 = QtGui.QStandardItem(item_name) 86 119 item1.setCheckable(True) 87 120 item1.setEditable(False) 88 # item_err = QtGui.QStandardItem() 121 89 122 # check for polydisp params 90 123 if param.polydisperse: … … 93 126 item1_1 = QtGui.QStandardItem("Distribution") 94 127 item1_1.setEditable(False) 128 95 129 # Find param in volume_params 96 130 for p in parameters.form_volume_parameters: … … 99 133 width = kernel_module.getParam(p.name+'.width') 100 134 ptype = kernel_module.getParam(p.name+'.type') 101 102 135 item1_2 = QtGui.QStandardItem(str(width)) 103 136 item1_2.setEditable(False) … … 110 143 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 111 144 break 145 112 146 # Add the polydisp item as a child 113 147 item1.appendRow([poly_item]) 148 114 149 # Param values 115 150 item2 = QtGui.QStandardItem(str(param.default)) 116 # TODO: the error column.117 # Either add a proxy model or a custom view delegate118 #item_err = QtGui.QStandardItem()119 151 item3 = QtGui.QStandardItem(str(param.limits[0])) 120 152 item4 = QtGui.QStandardItem(str(param.limits[1])) 121 item5 = QtGui.QStandardItem( param.units)153 item5 = QtGui.QStandardItem(str(param.units)) 122 154 item5.setEditable(False) 123 item.append([item1, item2, item3, item4, item5]) 124 return item 125 126 def addSimpleParametersToModel(parameters, is2D, parameters_original=None): 127 """ 128 Update local ModelModel with sasmodel parameters 129 parameters_original: list of parameters before any tagging on their IDs, e.g. for product model 130 (so that those are the display names; see below) 155 156 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 157 row = [item1, item2, item3, item4, item5] 158 cbox = createFixedChoiceComboBox(param, row) 159 160 # Append to the model and use the combobox, if required 161 if None not in (model, view): 162 model.appendRow(row) 163 if cbox: 164 view.setIndexWidget(item2.index(), cbox) 165 rows.append(row) 166 167 return rows 168 169 def addSimpleParametersToModel(parameters, is2D, model=None, view=None): 170 """ 171 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 172 Actually appends to model, if model and view params are not None. 173 Always returns list of lists of QStandardItems. 131 174 """ 132 175 if is2D: … … 135 178 params = parameters.iq_parameters 136 179 137 if parameters_original: 138 # 'parameters_original' contains the parameters as they are to be DISPLAYED, while 'parameters' 139 # contains the parameters as they were renamed; this is for handling name collisions in product model. 140 # The 'real name' of the parameter will be stored in the item's user data. 141 if is2D: 142 params_orig = [p for p in parameters_original.kernel_parameters if p.type != 'magnetic'] 143 else: 144 params_orig = parameters_original.iq_parameters 145 else: 146 # no difference in names anyway 147 params_orig = params 148 149 item = [] 150 for param, param_orig in zip(params, params_orig): 180 rows = [] 181 for param in params: 151 182 # Create the top level, checkable item 152 item_name = param _orig.name183 item_name = param.name 153 184 item1 = QtGui.QStandardItem(item_name) 154 item1.setData(param.name, QtCore.Qt.UserRole)155 185 item1.setCheckable(True) 156 186 item1.setEditable(False) 187 157 188 # Param values 158 189 # TODO: add delegate for validation of cells 159 190 item2 = QtGui.QStandardItem(str(param.default)) 160 item4 = QtGui.QStandardItem(str(param.limits[0])) 161 item5 = QtGui.QStandardItem(str(param.limits[1])) 162 item6 = QtGui.QStandardItem(str(param.units)) 163 item6.setEditable(False) 164 item.append([item1, item2, item4, item5, item6]) 165 return item 191 item3 = QtGui.QStandardItem(str(param.limits[0])) 192 item4 = QtGui.QStandardItem(str(param.limits[1])) 193 item5 = QtGui.QStandardItem(str(param.units)) 194 item5.setEditable(False) 195 196 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 197 row = [item1, item2, item3, item4, item5] 198 cbox = createFixedChoiceComboBox(param, row) 199 200 # Append to the model and use the combobox, if required 201 if None not in (model, view): 202 model.appendRow(row) 203 if cbox: 204 view.setIndexWidget(item2.index(), cbox) 205 rows.append(row) 206 207 return rows 166 208 167 209 def markParameterDisabled(model, row): … … 198 240 model.appendRow(item_list) 199 241 200 def addHeadingRowToModel(model, name):201 """adds a non-interactive top-level row to the model"""202 header_row = [QtGui.QStandardItem() for i in range(5)]203 header_row[0].setText(name)204 205 font = header_row[0].font()206 font.setBold(True)207 header_row[0].setFont(font)208 209 for item in header_row:210 item.setEditable(False)211 item.setCheckable(False)212 item.setSelectable(False)213 214 model.appendRow(header_row)215 216 242 def addHeadersToModel(model): 217 243 """ … … 259 285 model.header_tooltips = copy.copy(poly_header_error_tooltips) 260 286 261 def addShellsToModel(parameters, model, index, row_num=None):262 """ 263 Find out multishell parameters and update the model with the requested number of them .264 Inserts them after the row at row_num, if not None; otherwise, appends to end.265 Returns a list of lists of QStandardItem objects.287 def addShellsToModel(parameters, model, index, view=None): 288 """ 289 Find out multishell parameters and update the model with the requested number of them 290 Always appends to model. If view param is not None, supports fixed-choice params. 291 Returns list of lists of QStandardItems. 266 292 """ 267 293 multishell_parameters = getIterParams(parameters) … … 285 311 item1_3 = QtGui.QStandardItem(str(p.limits[0])) 286 312 item1_4 = QtGui.QStandardItem(str(p.limits[1])) 287 item1_5 = QtGui.QStandardItem( p.units)313 item1_5 = QtGui.QStandardItem(str(p.units)) 288 314 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 289 315 break … … 293 319 item3 = QtGui.QStandardItem(str(par.limits[0])) 294 320 item4 = QtGui.QStandardItem(str(par.limits[1])) 295 item5 = QtGui.QStandardItem(par.units) 321 item5 = QtGui.QStandardItem(str(par.units)) 322 item5.setEditable(False) 323 324 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 296 325 row = [item1, item2, item3, item4, item5] 326 cbox = createFixedChoiceComboBox(par, row) 327 328 # Always append to the model 329 model.appendRow(row) 330 331 # Apply combobox if required 332 if None not in (view, cbox): 333 view.setIndexWidget(item2.index(), cbox) 334 297 335 rows.append(row) 298 299 if row_num is None:300 model.appendRow(row)301 else:302 model.insertRow(row_num, row)303 row_num += 1304 336 305 337 return rows … … 474 506 475 507 theory_name = str(current_data.name.split()[0]) 476 res iduals.name = "Residuals for " + str(theory_name) + "[" + \477 str(reference_data.filename)+ "]"508 res_name = reference_data.filename if reference_data.filename else reference_data.name 509 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]" 478 510 residuals.title = residuals.name 479 511 residuals.ytransform = 'y' … … 501 533 """ 502 534 weight = None 535 if data is None: 536 return [] 503 537 if is2d: 538 if not hasattr(data, 'err_data'): 539 return [] 504 540 dy_data = data.err_data 505 541 data = data.data 506 542 else: 543 if not hasattr(data, 'dy'): 544 return [] 507 545 dy_data = data.dy 508 546 data = data.y
Note: See TracChangeset
for help on using the changeset viewer.