Changeset cd31251 in sasview for src/sas/qtgui/Perspectives/Fitting
- Timestamp:
- Mar 15, 2017 8:14:00 AM (8 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 811bec1
- Parents:
- cbcdd2c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rcbcdd2c rcd31251 1 1 import sys 2 2 import json 3 import 3 import os 4 4 import numpy 5 5 from collections import defaultdict … … 82 82 83 83 # Set the main models 84 # We can't use a single model here, due to restrictions on flattening 85 # the model tree with subclassed QAbstractProxyModel... 84 86 self._model_model = QtGui.QStandardItemModel() 85 87 self._poly_model = QtGui.QStandardItemModel() 86 88 self._magnet_model = QtGui.QStandardItemModel() 87 89 90 # Set the proxy models for display 91 # Main display 92 self._model_proxy = QtGui.QSortFilterProxyModel() 93 self._model_proxy.setSourceModel(self._model_model) 94 #self._model_proxy.setFilterRegExp(r"[^()]") 95 96 # Proxy display 97 self._poly_proxy = QtGui.QSortFilterProxyModel() 98 self._poly_proxy.setSourceModel(self._poly_model) 99 self._poly_proxy.setFilterRegExp(r"[^()]") 100 101 # Magnetism display 102 self._magnet_proxy = QtGui.QSortFilterProxyModel() 103 self._magnet_proxy.setSourceModel(self._magnet_model) 104 #self._magnet_proxy.setFilterRegExp(r"[^()]") 105 88 106 # Param model displayed in param list 89 107 self.lstParams.setModel(self._model_model) 108 #self.lstParams.setModel(self._model_proxy) 90 109 self.readCategoryInfo() 91 110 self.model_parameters = None … … 93 112 94 113 # Poly model displayed in poly list 95 self.lstPoly.setModel(self._poly_ model)114 self.lstPoly.setModel(self._poly_proxy) 96 115 self.setPolyModel() 97 116 self.setTableProperties(self.lstPoly) … … 204 223 """ 205 224 # Comboboxes 206 self.cbStructureFactor.currentIndexChanged.connect(self. selectStructureFactor)207 self.cbCategory.currentIndexChanged.connect(self. selectCategory)208 self.cbModel.currentIndexChanged.connect(self. selectModel)225 self.cbStructureFactor.currentIndexChanged.connect(self.onSelectStructureFactor) 226 self.cbCategory.currentIndexChanged.connect(self.onSelectCategory) 227 self.cbModel.currentIndexChanged.connect(self.onSelectModel) 209 228 # Checkboxes 210 229 self.chk2DView.toggled.connect(self.toggle2D) … … 221 240 # Respond to change in parameters from the UI 222 241 self._model_model.itemChanged.connect(self.updateParamsFromModel) 242 self._poly_model.itemChanged.connect(self.onPolyModelChange) 243 # TODO after the poly_model prototype accepted 244 #self._magnet_model.itemChanged.connect(self.onMagneticModelChange) 223 245 224 246 def setDefaultStructureCombo(self): … … 227 249 """ 228 250 structure_factor_list = self.master_category_dict.pop('Structure Factor') 229 structure_factors = [ ]251 structure_factors = ["None"] 230 252 self.cbStructureFactor.clear() 231 253 for (structure_factor, _) in structure_factor_list: … … 233 255 self.cbStructureFactor.addItems(sorted(structure_factors)) 234 256 235 def selectCategory(self):257 def onSelectCategory(self): 236 258 """ 237 259 Select Category from list … … 267 289 self.cbModel.addItems(sorted(models)) 268 290 269 def selectModel(self):291 def onSelectModel(self): 270 292 """ 271 293 Respond to select Model from list event … … 292 314 # TODO: attach the chart to index 293 315 294 def selectStructureFactor(self):316 def onSelectStructureFactor(self): 295 317 """ 296 318 Select Structure Factor from list 297 319 """ 298 model = str(self.cbStructureFactor.currentText()) 299 self.setModelModel(model) 320 model = str(self.cbModel.currentText()) 321 structure = str(self.cbStructureFactor.currentText()) 322 self.setModelModel(model, structure_factor=structure) 300 323 301 324 def readCategoryInfo(self): … … 396 419 model.setHeaderData(6, QtCore.Qt.Horizontal, QtCore.QVariant("Function")) 397 420 398 def setModelModel(self, model_name ):421 def setModelModel(self, model_name, structure_factor=None): 399 422 """ 400 423 Setting model parameters into table based on selected category 401 424 """ 402 assert isinstance(model_name, str)403 404 425 # Crete/overwrite model items 405 426 self._model_model.clear() … … 418 439 self.addParametersToModel(self.model_parameters, self._model_model) 419 440 self.addHeadersToModel(self._model_model) 441 442 # Add structure factor 443 if structure_factor is not None and structure_factor != "None": 444 structure_module = generate.load_kernel_module(structure_factor) 445 structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 446 self.addSimpleParametersToModel(structure_parameters, self._model_model) 447 else: 448 self.addStructureFactor() 449 420 450 # Multishell models need additional treatment 421 451 self.addExtraShells() … … 432 462 self.updateQRange() 433 463 434 def updateParamsFromModel(self, item): 435 """ 436 Callback method for updating the sasmodel parameters with the GUI values 437 """ 464 def onPolyModelChange(self, item): 465 """ 466 Callback method for updating the main model and sasmodel 467 parameters with the GUI values in the polydispersity view 468 """ 469 model_column = item.column() 470 model_row = item.row() 471 name_index = self._poly_model.index(model_row, 0) 438 472 # Extract changed value. Assumes proper validation by QValidator/Delegate 439 473 value = float(item.text()) 474 parameter_name = str(self._poly_model.data(name_index).toPyObject()) # "distribution of sld" etc. 475 if "Distribution of" in parameter_name: 476 parameter_name = parameter_name[16:] 477 property_name = str(self._poly_model.headerData(model_column, 1).toPyObject()) # Value, min, max, etc. 478 print "%s(%s) => %d" % (parameter_name, property_name, value) 479 480 # Update the sasmodel 481 #self.kernel_module.params[parameter_name] = value 482 483 # Reload the main model - may not be required if no variable is shown in main view 484 #model = str(self.cbModel.currentText()) 485 #self.setModelModel(model) 486 487 pass # debug anchor 488 489 def updateParamsFromModel(self, item): 490 """ 491 Callback method for updating the sasmodel parameters with the GUI values 492 """ 440 493 model_column = item.column() 441 494 model_row = item.row() 442 495 name_index = self._model_model.index(model_row, 0) 496 497 if model_column == 0: 498 # Assure we're dealing with checkboxes 499 if not item.isCheckable(): 500 return 501 status = item.checkState() 502 # If multiple rows selected - toggle all of them 503 rows = [s.row() for s in self.lstParams.selectionModel().selectedRows()] 504 505 # Switch off signaling from the model to avoid multiple calls 506 self._model_model.blockSignals(True) 507 # Convert to proper indices and set requested enablement 508 items = [self._model_model.item(row, 0).setCheckState(status) for row in rows] 509 self._model_model.blockSignals(False) 510 return 511 512 # Extract changed value. Assumes proper validation by QValidator/Delegate 513 value = float(item.text()) 443 514 parameter_name = str(self._model_model.data(name_index).toPyObject()) # sld, background etc. 444 515 property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc. … … 490 561 multishell_param_name, _ = self.getMultiplicity(parameters) 491 562 492 #TODO: iq_parameters are used here. If orientation paramateres or magnetic are needed493 # kernel_paramters should be used instead494 563 for param in parameters.iq_parameters: 495 564 # don't include shell parameters … … 532 601 self._last_model_row = self._model_model.rowCount() 533 602 603 def addSimpleParametersToModel(self, parameters, model): 604 """ 605 Update local ModelModel with sasmodel parameters 606 """ 607 for param in parameters.iq_parameters: 608 # Modify parameter name from <param>[n] to <param>1 609 item_name = param.name 610 item1 = QtGui.QStandardItem(item_name) 611 item1.setCheckable(True) 612 # Param values 613 item2 = QtGui.QStandardItem(str(param.default)) 614 # TODO: the error column. 615 # Either add a proxy model or a custom view delegate 616 #item_err = QtGui.QStandardItem() 617 item3 = QtGui.QStandardItem(str(param.limits[0])) 618 item4 = QtGui.QStandardItem(str(param.limits[1])) 619 item5 = QtGui.QStandardItem(param.units) 620 model.appendRow([item1, item2, item3, item4, item5]) 621 622 # Update the counter used for multishell display 623 self._last_model_row = self._model_model.rowCount() 624 534 625 def createDefault1dData(self): 535 626 """ … … 656 747 try: 657 748 self.q_range_min = float(text) 658 # set Q range labels on the main tab659 self.lblMinRangeDef.setText(str(self.q_range_min))660 749 except: 661 750 pass 751 # set Q range labels on the main tab 752 self.lblMinRangeDef.setText(str(self.q_range_min)) 662 753 663 754 def onMaxRange(self, text): … … 668 759 try: 669 760 self.q_range_max = float(text) 670 # set Q range labels on the main tab671 self.lblMaxRangeDef.setText(str(self.q_range_max))672 761 except: 673 762 pass 763 # set Q range labels on the main tab 764 self.lblMaxRangeDef.setText(str(self.q_range_max)) 674 765 675 766 def calculate1DForModel(self): … … 848 939 Set polydispersity values 849 940 """ 850 ### TODO: apply proper proxy model filtering from the main _model_model851 852 941 if not self.model_parameters: 853 942 return … … 890 979 891 980 self.addHeadersToModel(self._magnet_model) 981 982 def addStructureFactor(self): 983 """ 984 Add structure factors to the list of parameters 985 """ 986 if self.kernel_module.is_form_factor: 987 self.enableStructureCombo() 988 else: 989 self.disableStructureCombo() 892 990 893 991 def addExtraShells(self):
Note: See TracChangeset
for help on using the changeset viewer.