Changeset 04f775d in sasview for src/sas/qtgui
- Timestamp:
- Sep 6, 2018 9:34:38 AM (6 years ago)
- 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
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
rb764ae5 r04f775d 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): 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 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 93 def addParametersToModel(model, view, parameters, kernel_module, is2D): 64 94 """ 65 95 Update local ModelModel with sasmodel parameters … … 72 102 else: 73 103 params = parameters.iq_parameters 74 item = [] 104 75 105 for param in params: 76 106 # don't include shell parameters 77 107 if param.name == multishell_param_name: 78 108 continue 109 79 110 # Modify parameter name from <param>[n] to <param>1 80 111 item_name = param.name 81 112 if param in multishell_parameters: 82 113 continue 83 # item_name = replaceShellName(param.name, 1)84 114 85 115 item1 = QtGui.QStandardItem(item_name) 86 116 item1.setCheckable(True) 87 117 item1.setEditable(False) 88 # item_err = QtGui.QStandardItem() 118 89 119 # check for polydisp params 90 120 if param.polydisperse: … … 93 123 item1_1 = QtGui.QStandardItem("Distribution") 94 124 item1_1.setEditable(False) 125 95 126 # Find param in volume_params 96 127 for p in parameters.form_volume_parameters: … … 99 130 width = kernel_module.getParam(p.name+'.width') 100 131 ptype = kernel_module.getParam(p.name+'.type') 101 102 132 item1_2 = QtGui.QStandardItem(str(width)) 103 133 item1_2.setEditable(False) … … 110 140 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 111 141 break 142 112 143 # Add the polydisp item as a child 113 144 item1.appendRow([poly_item]) 145 114 146 # Param values 115 147 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 148 item3 = QtGui.QStandardItem(str(param.limits[0])) 120 149 item4 = QtGui.QStandardItem(str(param.limits[1])) 121 item5 = QtGui.QStandardItem( param.units)150 item5 = QtGui.QStandardItem(str(param.units)) 122 151 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 162 def addSimpleParametersToModel(model, view, parameters, is2D): 163 """ 164 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 129 165 """ 130 166 if is2D: … … 132 168 else: 133 169 params = parameters.iq_parameters 134 item = [] 170 135 171 for param in params: 136 172 # Create the top level, checkable item … … 139 175 item1.setCheckable(True) 140 176 item1.setEditable(False) 177 141 178 # Param values 142 179 # TODO: add delegate for validation of cells 143 180 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) 150 194 151 195 def markParameterDisabled(model, row): -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rf84d793 r04f775d 2050 2050 2051 2051 # Update the QModel 2052 new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 2053 2054 for row in new_rows: 2055 self._model_model.appendRow(row) 2052 FittingUtilities.addParametersToModel( 2053 self._model_model, 2054 self.lstParams, 2055 self.model_parameters, 2056 self.kernel_module, 2057 self.is2D) 2058 2056 2059 # Update the counter used for multishell display 2057 2060 self._last_model_row = self._model_model.rowCount() … … 2071 2074 self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 2072 2075 2073 new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 2074 for row in new_rows: 2075 self._model_model.appendRow(row) 2076 # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 2077 if row[0].text() not in self.kernel_module.params.keys(): 2078 row_num = self._model_model.rowCount() - 1 2079 FittingUtilities.markParameterDisabled(self._model_model, row_num) 2076 # Update the QModel 2077 FittingUtilities.addSimpleParametersToModel( 2078 self._model_model, 2079 self.lstParams, 2080 structure_parameters, 2081 self.is2D) 2082 2083 # Any parameters removed from the structure factor when producing the product model, e.g. radius_effective, must 2084 # be disabled (greyed out, etc.) 2085 for r in range(self._last_model_row, self._model_model.rowCount()): 2086 param_name = self._model_model.item(r, 0).text() 2087 if param_name not in self.kernel_module.params.keys(): 2088 FittingUtilities.markParameterDisabled(self._model_model, r) 2080 2089 2081 2090 # Update the counter used for multishell display
Note: See TracChangeset
for help on using the changeset viewer.