Ignore:
File:
1 edited

Legend:

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

    r70f4458 rbc7371fd  
    88from sas.qtgui.Plotting.PlotterData import Data1D 
    99from sas.qtgui.Plotting.PlotterData import Data2D 
     10 
     11from sas.qtgui.Perspectives.Fitting.AssociatedComboBox import AssociatedComboBox 
    1012 
    1113model_header_captions = ['Parameter', 'Value', 'Min', 'Max', 'Units'] 
     
    6163    return (param_name, param_length) 
    6264 
    63 def addParametersToModel(parameters, kernel_module, is2D): 
    64     """ 
    65     Update local ModelModel with sasmodel parameters 
     65def 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 
     93def 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. 
    6698    """ 
    6799    multishell_parameters = getIterParams(parameters) 
     
    72104    else: 
    73105        params = parameters.iq_parameters 
    74     item = [] 
     106 
     107    rows = [] 
    75108    for param in params: 
    76109        # don't include shell parameters 
    77110        if param.name == multishell_param_name: 
    78111            continue 
     112 
    79113        # Modify parameter name from <param>[n] to <param>1 
    80114        item_name = param.name 
    81115        if param in multishell_parameters: 
    82116            continue 
    83         #    item_name = replaceShellName(param.name, 1) 
    84117 
    85118        item1 = QtGui.QStandardItem(item_name) 
    86119        item1.setCheckable(True) 
    87120        item1.setEditable(False) 
    88         # item_err = QtGui.QStandardItem() 
     121 
    89122        # check for polydisp params 
    90123        if param.polydisperse: 
     
    93126            item1_1 = QtGui.QStandardItem("Distribution") 
    94127            item1_1.setEditable(False) 
     128 
    95129            # Find param in volume_params 
    96130            for p in parameters.form_volume_parameters: 
     
    99133                width = kernel_module.getParam(p.name+'.width') 
    100134                ptype = kernel_module.getParam(p.name+'.type') 
    101  
    102135                item1_2 = QtGui.QStandardItem(str(width)) 
    103136                item1_2.setEditable(False) 
     
    110143                poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    111144                break 
     145 
    112146            # Add the polydisp item as a child 
    113147            item1.appendRow([poly_item]) 
     148 
    114149        # Param values 
    115150        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() 
    119151        item3 = QtGui.QStandardItem(str(param.limits[0])) 
    120152        item4 = QtGui.QStandardItem(str(param.limits[1])) 
    121         item5 = QtGui.QStandardItem(param.units) 
     153        item5 = QtGui.QStandardItem(str(param.units)) 
    122154        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 
     169def 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. 
    131174    """ 
    132175    if is2D: 
     
    135178        params = parameters.iq_parameters 
    136179 
    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: 
    151182        # Create the top level, checkable item 
    152         item_name = param_orig.name 
     183        item_name = param.name 
    153184        item1 = QtGui.QStandardItem(item_name) 
    154         item1.setData(param.name, QtCore.Qt.UserRole) 
    155185        item1.setCheckable(True) 
    156186        item1.setEditable(False) 
     187 
    157188        # Param values 
    158189        # TODO: add delegate for validation of cells 
    159190        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 
    166208 
    167209def markParameterDisabled(model, row): 
     
    198240    model.appendRow(item_list) 
    199241 
    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  
    216242def addHeadersToModel(model): 
    217243    """ 
     
    259285    model.header_tooltips = copy.copy(poly_header_error_tooltips) 
    260286 
    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. 
     287def 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. 
    266292    """ 
    267293    multishell_parameters = getIterParams(parameters) 
     
    285311                    item1_3 = QtGui.QStandardItem(str(p.limits[0])) 
    286312                    item1_4 = QtGui.QStandardItem(str(p.limits[1])) 
    287                     item1_5 = QtGui.QStandardItem(p.units) 
     313                    item1_5 = QtGui.QStandardItem(str(p.units)) 
    288314                    poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    289315                    break 
     
    293319            item3 = QtGui.QStandardItem(str(par.limits[0])) 
    294320            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) 
    296325            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 
    297335            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 
    304336 
    305337    return rows 
     
    474506 
    475507    theory_name = str(current_data.name.split()[0]) 
    476     residuals.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 + "]" 
    478510    residuals.title = residuals.name 
    479511    residuals.ytransform = 'y' 
     
    501533    """ 
    502534    weight = None 
     535    if data is None: 
     536        return [] 
    503537    if is2d: 
     538        if not hasattr(data, 'err_data'): 
     539            return [] 
    504540        dy_data = data.err_data 
    505541        data = data.data 
    506542    else: 
     543        if not hasattr(data, 'dy'): 
     544            return [] 
    507545        dy_data = data.dy 
    508546        data = data.y 
Note: See TracChangeset for help on using the changeset viewer.