Changes in src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py [70f4458:f3cc979] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
r70f4458 rf3cc979 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 for p in parameters.form_volume_parameters: 130 poly_pars = parameters.form_volume_parameters 131 if is2D: 132 poly_pars += parameters.orientation_parameters 133 for p in poly_pars: 97 134 if p.name != param.name: 98 135 continue 99 136 width = kernel_module.getParam(p.name+'.width') 100 137 ptype = kernel_module.getParam(p.name+'.type') 101 102 138 item1_2 = QtGui.QStandardItem(str(width)) 103 139 item1_2.setEditable(False) … … 110 146 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 111 147 break 148 112 149 # Add the polydisp item as a child 113 150 item1.appendRow([poly_item]) 151 114 152 # Param values 115 153 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 154 item3 = QtGui.QStandardItem(str(param.limits[0])) 120 155 item4 = QtGui.QStandardItem(str(param.limits[1])) 121 item5 = QtGui.QStandardItem( param.units)156 item5 = QtGui.QStandardItem(str(param.units)) 122 157 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) 158 159 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 160 row = [item1, item2, item3, item4, item5] 161 cbox = createFixedChoiceComboBox(param, row) 162 163 # Append to the model and use the combobox, if required 164 if None not in (model, view): 165 model.appendRow(row) 166 if cbox: 167 view.setIndexWidget(item2.index(), cbox) 168 rows.append(row) 169 170 return rows 171 172 def addSimpleParametersToModel(parameters, is2D, parameters_original=None, model=None, view=None, row_num=None): 173 """ 174 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 175 Actually appends to model, if model and view params are not None. 176 Always returns list of lists of QStandardItems. 177 178 parameters_original: list of parameters before any tagging on their IDs, e.g. for product model (so that those are 179 the display names; see below) 131 180 """ 132 181 if is2D: … … 147 196 params_orig = params 148 197 149 item= []198 rows = [] 150 199 for param, param_orig in zip(params, params_orig): 151 200 # Create the top level, checkable item … … 155 204 item1.setCheckable(True) 156 205 item1.setEditable(False) 206 157 207 # Param values 158 208 # TODO: add delegate for validation of cells 159 209 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 210 item3 = QtGui.QStandardItem(str(param.limits[0])) 211 item4 = QtGui.QStandardItem(str(param.limits[1])) 212 item5 = QtGui.QStandardItem(str(param.units)) 213 item5.setEditable(False) 214 215 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 216 row = [item1, item2, item3, item4, item5] 217 cbox = createFixedChoiceComboBox(param, row) 218 219 # Append to the model and use the combobox, if required 220 if None not in (model, view): 221 if row_num is None: 222 model.appendRow(row) 223 else: 224 model.insertRow(row_num, row) 225 row_num += 1 226 227 if cbox: 228 view.setIndexWidget(item2.index(), cbox) 229 230 rows.append(row) 231 232 return rows 166 233 167 234 def markParameterDisabled(model, row): … … 259 326 model.header_tooltips = copy.copy(poly_header_error_tooltips) 260 327 261 def addShellsToModel(parameters, model, index, row_num=None ):328 def addShellsToModel(parameters, model, index, row_num=None, view=None): 262 329 """ 263 330 Find out multishell parameters and update the model with the requested number of them. 264 331 Inserts them after the row at row_num, if not None; otherwise, appends to end. 332 If view param is not None, supports fixed-choice params. 265 333 Returns a list of lists of QStandardItem objects. 266 334 """ … … 285 353 item1_3 = QtGui.QStandardItem(str(p.limits[0])) 286 354 item1_4 = QtGui.QStandardItem(str(p.limits[1])) 287 item1_5 = QtGui.QStandardItem( p.units)355 item1_5 = QtGui.QStandardItem(str(p.units)) 288 356 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 289 357 break … … 293 361 item3 = QtGui.QStandardItem(str(par.limits[0])) 294 362 item4 = QtGui.QStandardItem(str(par.limits[1])) 295 item5 = QtGui.QStandardItem(par.units) 363 item5 = QtGui.QStandardItem(str(par.units)) 364 item5.setEditable(False) 365 366 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 296 367 row = [item1, item2, item3, item4, item5] 297 rows.append(row) 298 368 cbox = createFixedChoiceComboBox(par, row) 369 370 # Always add to the model 299 371 if row_num is None: 300 372 model.appendRow(row) … … 302 374 model.insertRow(row_num, row) 303 375 row_num += 1 376 377 # Apply combobox if required 378 if None not in (view, cbox): 379 view.setIndexWidget(item2.index(), cbox) 380 381 rows.append(row) 304 382 305 383 return rows … … 474 552 475 553 theory_name = str(current_data.name.split()[0]) 476 res iduals.name = "Residuals for " + str(theory_name) + "[" + \477 str(reference_data.filename)+ "]"554 res_name = reference_data.filename if reference_data.filename else reference_data.name 555 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]" 478 556 residuals.title = residuals.name 479 557 residuals.ytransform = 'y' … … 501 579 """ 502 580 weight = None 581 if data is None: 582 return [] 503 583 if is2d: 584 if not hasattr(data, 'err_data'): 585 return [] 504 586 dy_data = data.err_data 505 587 data = data.data 506 588 else: 589 if not hasattr(data, 'dy'): 590 return [] 507 591 dy_data = data.dy 508 592 data = data.y
Note: See TracChangeset
for help on using the changeset viewer.