Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py

    rbc7371fd r70f4458  
    88from sas.qtgui.Plotting.PlotterData import Data1D 
    99from sas.qtgui.Plotting.PlotterData import Data2D 
    10  
    11 from sas.qtgui.Perspectives.Fitting.AssociatedComboBox import AssociatedComboBox 
    1210 
    1311model_header_captions = ['Parameter', 'Value', 'Min', 'Max', 'Units'] 
     
    6361    return (param_name, param_length) 
    6462 
    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. 
     63def addParametersToModel(parameters, kernel_module, is2D): 
     64    """ 
     65    Update local ModelModel with sasmodel parameters 
    9866    """ 
    9967    multishell_parameters = getIterParams(parameters) 
     
    10472    else: 
    10573        params = parameters.iq_parameters 
    106  
    107     rows = [] 
     74    item = [] 
    10875    for param in params: 
    10976        # don't include shell parameters 
    11077        if param.name == multishell_param_name: 
    11178            continue 
    112  
    11379        # Modify parameter name from <param>[n] to <param>1 
    11480        item_name = param.name 
    11581        if param in multishell_parameters: 
    11682            continue 
     83        #    item_name = replaceShellName(param.name, 1) 
    11784 
    11885        item1 = QtGui.QStandardItem(item_name) 
    11986        item1.setCheckable(True) 
    12087        item1.setEditable(False) 
    121  
     88        # item_err = QtGui.QStandardItem() 
    12289        # check for polydisp params 
    12390        if param.polydisperse: 
     
    12693            item1_1 = QtGui.QStandardItem("Distribution") 
    12794            item1_1.setEditable(False) 
    128  
    12995            # Find param in volume_params 
    13096            for p in parameters.form_volume_parameters: 
     
    13399                width = kernel_module.getParam(p.name+'.width') 
    134100                ptype = kernel_module.getParam(p.name+'.type') 
     101 
    135102                item1_2 = QtGui.QStandardItem(str(width)) 
    136103                item1_2.setEditable(False) 
     
    143110                poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    144111                break 
    145  
    146112            # Add the polydisp item as a child 
    147113            item1.appendRow([poly_item]) 
    148  
    149114        # Param values 
    150115        item2 = QtGui.QStandardItem(str(param.default)) 
     116        # TODO: the error column. 
     117        # Either add a proxy model or a custom view delegate 
     118        #item_err = QtGui.QStandardItem() 
    151119        item3 = QtGui.QStandardItem(str(param.limits[0])) 
    152120        item4 = QtGui.QStandardItem(str(param.limits[1])) 
    153         item5 = QtGui.QStandardItem(str(param.units)) 
     121        item5 = QtGui.QStandardItem(param.units) 
    154122        item5.setEditable(False) 
    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. 
     123        item.append([item1, item2, item3, item4, item5]) 
     124    return item 
     125 
     126def 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) 
    174131    """ 
    175132    if is2D: 
     
    178135        params = parameters.iq_parameters 
    179136 
    180     rows = [] 
    181     for param in params: 
     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): 
    182151        # Create the top level, checkable item 
    183         item_name = param.name 
     152        item_name = param_orig.name 
    184153        item1 = QtGui.QStandardItem(item_name) 
     154        item1.setData(param.name, QtCore.Qt.UserRole) 
    185155        item1.setCheckable(True) 
    186156        item1.setEditable(False) 
    187  
    188157        # Param values 
    189158        # TODO: add delegate for validation of cells 
    190159        item2 = QtGui.QStandardItem(str(param.default)) 
    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 
     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 
    208166 
    209167def markParameterDisabled(model, row): 
     
    240198    model.appendRow(item_list) 
    241199 
     200def 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 
    242216def addHeadersToModel(model): 
    243217    """ 
     
    285259    model.header_tooltips = copy.copy(poly_header_error_tooltips) 
    286260 
    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. 
     261def 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. 
    292266    """ 
    293267    multishell_parameters = getIterParams(parameters) 
     
    311285                    item1_3 = QtGui.QStandardItem(str(p.limits[0])) 
    312286                    item1_4 = QtGui.QStandardItem(str(p.limits[1])) 
    313                     item1_5 = QtGui.QStandardItem(str(p.units)) 
     287                    item1_5 = QtGui.QStandardItem(p.units) 
    314288                    poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    315289                    break 
     
    319293            item3 = QtGui.QStandardItem(str(par.limits[0])) 
    320294            item4 = QtGui.QStandardItem(str(par.limits[1])) 
    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) 
     295            item5 = QtGui.QStandardItem(par.units) 
    325296            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  
    335297            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 += 1 
    336304 
    337305    return rows 
     
    506474 
    507475    theory_name = str(current_data.name.split()[0]) 
    508     res_name = reference_data.filename if reference_data.filename else reference_data.name 
    509     residuals.name = "Residuals for " + str(theory_name) + "[" + res_name + "]" 
     476    residuals.name = "Residuals for " + str(theory_name) + "[" + \ 
     477                    str(reference_data.filename) + "]" 
    510478    residuals.title = residuals.name 
    511479    residuals.ytransform = 'y' 
     
    533501    """ 
    534502    weight = None 
    535     if data is None: 
    536         return [] 
    537503    if is2d: 
    538         if not hasattr(data, 'err_data'): 
    539             return [] 
    540504        dy_data = data.err_data 
    541505        data = data.data 
    542506    else: 
    543         if not hasattr(data, 'dy'): 
    544             return [] 
    545507        dy_data = data.dy 
    546508        data = data.y 
Note: See TracChangeset for help on using the changeset viewer.