Ignore:
Timestamp:
Sep 7, 2018 8:53:02 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:
c0de493
Parents:
8136e09 (diff), f0365a2e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'ESS_GUI' into ESS_GUI_iss1034

File:
1 edited

Legend:

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

    rb764ae5 r01b4877  
    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): 
    127     """ 
    128     Update local ModelModel with sasmodel parameters 
     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, parameters_original=None, model=None, view=None, row_num=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. 
     174 
     175    parameters_original: list of parameters before any tagging on their IDs, e.g. for product model (so that those are 
     176    the display names; see below) 
    129177    """ 
    130178    if is2D: 
     
    132180    else: 
    133181        params = parameters.iq_parameters 
    134     item = [] 
    135     for param in params: 
     182 
     183    if parameters_original: 
     184        # 'parameters_original' contains the parameters as they are to be DISPLAYED, while 'parameters' 
     185        # contains the parameters as they were renamed; this is for handling name collisions in product model. 
     186        # The 'real name' of the parameter will be stored in the item's user data. 
     187        if is2D: 
     188            params_orig = [p for p in parameters_original.kernel_parameters if p.type != 'magnetic'] 
     189        else: 
     190            params_orig = parameters_original.iq_parameters 
     191    else: 
     192        # no difference in names anyway 
     193        params_orig = params 
     194 
     195    rows = [] 
     196    for param, param_orig in zip(params, params_orig): 
    136197        # Create the top level, checkable item 
    137         item_name = param.name 
     198        item_name = param_orig.name 
    138199        item1 = QtGui.QStandardItem(item_name) 
     200        item1.setData(param.name, QtCore.Qt.UserRole) 
    139201        item1.setCheckable(True) 
    140202        item1.setEditable(False) 
     203 
    141204        # Param values 
    142205        # TODO: add delegate for validation of cells 
    143206        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 
     207        item3 = QtGui.QStandardItem(str(param.limits[0])) 
     208        item4 = QtGui.QStandardItem(str(param.limits[1])) 
     209        item5 = QtGui.QStandardItem(str(param.units)) 
     210        item5.setEditable(False) 
     211 
     212        # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 
     213        row = [item1, item2, item3, item4, item5] 
     214        cbox = createFixedChoiceComboBox(param, row) 
     215 
     216        # Append to the model and use the combobox, if required 
     217        if None not in (model, view): 
     218            if row_num is None: 
     219                model.appendRow(row) 
     220            else: 
     221                model.insertRow(row_num, row) 
     222                row_num += 1 
     223 
     224            if cbox: 
     225                view.setIndexWidget(item2.index(), cbox) 
     226 
     227        rows.append(row) 
     228 
     229    return rows 
    150230 
    151231def markParameterDisabled(model, row): 
     
    182262    model.appendRow(item_list) 
    183263 
     264def addHeadingRowToModel(model, name): 
     265    """adds a non-interactive top-level row to the model""" 
     266    header_row = [QtGui.QStandardItem() for i in range(5)] 
     267    header_row[0].setText(name) 
     268 
     269    font = header_row[0].font() 
     270    font.setBold(True) 
     271    header_row[0].setFont(font) 
     272 
     273    for item in header_row: 
     274        item.setEditable(False) 
     275        item.setCheckable(False) 
     276        item.setSelectable(False) 
     277 
     278    model.appendRow(header_row) 
     279 
    184280def addHeadersToModel(model): 
    185281    """ 
     
    227323    model.header_tooltips = copy.copy(poly_header_error_tooltips) 
    228324 
    229 def addShellsToModel(parameters, model, index): 
    230     """ 
    231     Find out multishell parameters and update the model with the requested number of them 
     325def addShellsToModel(parameters, model, index, row_num=None, view=None): 
     326    """ 
     327    Find out multishell parameters and update the model with the requested number of them. 
     328    Inserts them after the row at row_num, if not None; otherwise, appends to end. 
     329    If view param is not None, supports fixed-choice params. 
     330    Returns a list of lists of QStandardItem objects. 
    232331    """ 
    233332    multishell_parameters = getIterParams(parameters) 
    234333 
     334    rows = [] 
    235335    for i in range(index): 
    236336        for par in multishell_parameters: 
     
    250350                    item1_3 = QtGui.QStandardItem(str(p.limits[0])) 
    251351                    item1_4 = QtGui.QStandardItem(str(p.limits[1])) 
    252                     item1_5 = QtGui.QStandardItem(p.units) 
     352                    item1_5 = QtGui.QStandardItem(str(p.units)) 
    253353                    poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 
    254354                    break 
     
    258358            item3 = QtGui.QStandardItem(str(par.limits[0])) 
    259359            item4 = QtGui.QStandardItem(str(par.limits[1])) 
    260             item5 = QtGui.QStandardItem(par.units) 
    261             model.appendRow([item1, item2, item3, item4, item5]) 
     360            item5 = QtGui.QStandardItem(str(par.units)) 
     361            item5.setEditable(False) 
     362 
     363            # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 
     364            row = [item1, item2, item3, item4, item5] 
     365            cbox = createFixedChoiceComboBox(par, row) 
     366 
     367            # Always add to the model 
     368            if row_num is None: 
     369                model.appendRow(row) 
     370            else: 
     371                model.insertRow(row_num, row) 
     372                row_num += 1 
     373 
     374            # Apply combobox if required 
     375            if None not in (view, cbox): 
     376                view.setIndexWidget(item2.index(), cbox) 
     377 
     378            rows.append(row) 
     379 
     380    return rows 
    262381 
    263382def calculateChi2(reference_data, current_data): 
Note: See TracChangeset for help on using the changeset viewer.