Ignore:
Timestamp:
Sep 6, 2018 9:34:38 AM (6 years ago)
Author:
Torin Cooper-Bennun <torin.cooper-bennun@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
04ce9ac
Parents:
dda8f16
Message:

cherry-pick fixed-choice param support, made more generic and cleaner

File:
1 edited

Legend:

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

    rb764ae5 r04f775d  
    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): 
     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 type(param.choices) is list and len(param.choices) > 0: 
     78        # The choices property is concrete in sasmodels, probably will use this 
     79        choices = param.choices 
     80    elif type(param.units) is list: 
     81        choices = 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(model, view, parameters, kernel_module, is2D): 
    6494    """ 
    6595    Update local ModelModel with sasmodel parameters 
     
    72102    else: 
    73103        params = parameters.iq_parameters 
    74     item = [] 
     104 
    75105    for param in params: 
    76106        # don't include shell parameters 
    77107        if param.name == multishell_param_name: 
    78108            continue 
     109 
    79110        # Modify parameter name from <param>[n] to <param>1 
    80111        item_name = param.name 
    81112        if param in multishell_parameters: 
    82113            continue 
    83         #    item_name = replaceShellName(param.name, 1) 
    84114 
    85115        item1 = QtGui.QStandardItem(item_name) 
    86116        item1.setCheckable(True) 
    87117        item1.setEditable(False) 
    88         # item_err = QtGui.QStandardItem() 
     118 
    89119        # check for polydisp params 
    90120        if param.polydisperse: 
     
    93123            item1_1 = QtGui.QStandardItem("Distribution") 
    94124            item1_1.setEditable(False) 
     125 
    95126            # Find param in volume_params 
    96127            for p in parameters.form_volume_parameters: 
     
    99130                width = kernel_module.getParam(p.name+'.width') 
    100131                ptype = kernel_module.getParam(p.name+'.type') 
    101  
    102132                item1_2 = QtGui.QStandardItem(str(width)) 
    103133                item1_2.setEditable(False) 
     
    110140                poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    111141                break 
     142 
    112143            # Add the polydisp item as a child 
    113144            item1.appendRow([poly_item]) 
     145 
    114146        # Param values 
    115147        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() 
    119148        item3 = QtGui.QStandardItem(str(param.limits[0])) 
    120149        item4 = QtGui.QStandardItem(str(param.limits[1])) 
    121         item5 = QtGui.QStandardItem(param.units) 
     150        item5 = QtGui.QStandardItem(str(param.units)) 
    122151        item5.setEditable(False) 
    123         item.append([item1, item2, item3, item4, item5]) 
    124     return item 
    125  
    126 def addSimpleParametersToModel(parameters, is2D): 
    127     """ 
    128     Update local ModelModel with sasmodel parameters 
     152 
     153        # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 
     154        row = [item1, item2, item3, item4, item5] 
     155        cbox = createFixedChoiceComboBox(param, row) 
     156 
     157        # Append to the model and use the combobox, if required 
     158        model.appendRow(row) 
     159        if cbox is not None: 
     160            view.setIndexWidget(item2.index(), cbox) 
     161 
     162def addSimpleParametersToModel(model, view, parameters, is2D): 
     163    """ 
     164    Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 
    129165    """ 
    130166    if is2D: 
     
    132168    else: 
    133169        params = parameters.iq_parameters 
    134     item = [] 
     170 
    135171    for param in params: 
    136172        # Create the top level, checkable item 
     
    139175        item1.setCheckable(True) 
    140176        item1.setEditable(False) 
     177 
    141178        # Param values 
    142179        # TODO: add delegate for validation of cells 
    143180        item2 = QtGui.QStandardItem(str(param.default)) 
    144         item4 = QtGui.QStandardItem(str(param.limits[0])) 
    145         item5 = QtGui.QStandardItem(str(param.limits[1])) 
    146         item6 = QtGui.QStandardItem(param.units) 
    147         item6.setEditable(False) 
    148         item.append([item1, item2, item4, item5, item6]) 
    149     return item 
     181        item3 = QtGui.QStandardItem(str(param.limits[0])) 
     182        item4 = QtGui.QStandardItem(str(param.limits[1])) 
     183        item5 = QtGui.QStandardItem(str(param.units)) 
     184        item5.setEditable(False) 
     185 
     186        # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 
     187        row = [item1, item2, item3, item4, item5] 
     188        cbox = createFixedChoiceComboBox(param, row) 
     189 
     190        # Append to the model and use the combobox, if required 
     191        model.appendRow(row) 
     192        if cbox is not None: 
     193            view.setIndexWidget(item2.index(), cbox) 
    150194 
    151195def markParameterDisabled(model, row): 
Note: See TracChangeset for help on using the changeset viewer.