Changeset fd1ae6d1 in sasview for src/sas


Ignore:
Timestamp:
May 18, 2017 9:05:27 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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:
6964d44
Parents:
6066a3f
Message:

Fixes for structure factor chooser + minor refactoring in the FittingWidget?

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
3 edited

Legend:

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

    rdc5ef15 rfd1ae6d1  
    132132    model.setHeaderData(2, QtCore.Qt.Horizontal, QtCore.QVariant("Min")) 
    133133    model.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Max")) 
    134     model.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("[Units]")) 
     134    model.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Units")) 
    135135 
    136136def addErrorHeadersToModel(model): 
     
    143143    model.setHeaderData(3, QtCore.Qt.Horizontal, QtCore.QVariant("Min")) 
    144144    model.setHeaderData(4, QtCore.Qt.Horizontal, QtCore.QVariant("Max")) 
    145     model.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("[Units]")) 
     145    model.setHeaderData(5, QtCore.Qt.Horizontal, QtCore.QVariant("Units")) 
    146146 
    147147def addPolyHeadersToModel(model): 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r6066a3f rfd1ae6d1  
    395395        self.has_error_column = False 
    396396 
     397        self.respondToModelStructure(model=model, structure_factor=None) 
     398 
     399    def onSelectStructureFactor(self): 
     400        """ 
     401        Select Structure Factor from list 
     402        """ 
     403        model = str(self.cbModel.currentText()) 
     404        category = str(self.cbCategory.currentText()) 
     405        structure = str(self.cbStructureFactor.currentText()) 
     406        if category == CATEGORY_STRUCTURE: 
     407            model = None 
     408        self.respondToModelStructure(model=model, structure_factor=structure) 
     409 
     410    def respondToModelStructure(self, model=None, structure_factor=None): 
    397411        # Set enablement on calculate/plot 
    398412        self.cmdPlot.setEnabled(True) 
    399413 
    400         # SasModel -> QModel 
    401         self.SASModelToQModel(model) 
     414        # kernel parameters -> model_model 
     415        self.SASModelToQModel(model, structure_factor) 
    402416 
    403417        if self.data_is_loaded: 
     
    409423            self.createDefaultDataset() 
    410424 
    411         # Update state stack 
    412         self.updateUndo() 
    413  
    414     def onSelectStructureFactor(self): 
    415         """ 
    416         Select Structure Factor from list 
    417         """ 
    418         model = str(self.cbModel.currentText()) 
    419         category = str(self.cbCategory.currentText()) 
    420         structure = str(self.cbStructureFactor.currentText()) 
    421         if category == CATEGORY_STRUCTURE: 
    422             model = None 
    423         self.SASModelToQModel(model, structure_factor=structure) 
    424425        # Update state stack 
    425426        self.updateUndo() 
     
    836837        Setting model parameters into table based on selected category 
    837838        """ 
    838         # TODO - modify for structure factor-only choice 
    839  
    840839        # Crete/overwrite model items 
    841840        self._model_model.clear() 
    842841 
     842        # First, add parameters from the main model 
     843        if model_name is not None: 
     844            self.fromModelToQModel(model_name) 
     845 
     846        # Then, add structure factor derived parameters 
     847        if structure_factor is not None and structure_factor != "None": 
     848            if model_name is None: 
     849                # Instantiate the current sasmodel for SF-only models 
     850                self.kernel_module = self.models[structure_factor]() 
     851            self.fromStructureFactorToQModel(structure_factor) 
     852        else: 
     853            # Allow the SF combobox visibility for the given sasmodel 
     854            self.enableStructureFactorControl(structure_factor) 
     855 
     856        # Then, add multishells 
     857        if model_name is not None: 
     858            # Multishell models need additional treatment 
     859            self.addExtraShells() 
     860 
     861        # Add polydispersity to the model 
     862        self.setPolyModel() 
     863        # Add magnetic parameters to the model 
     864        self.setMagneticModel() 
     865 
     866        # Adjust the table cells width 
     867        self.lstParams.resizeColumnToContents(0) 
     868        self.lstParams.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding) 
     869 
     870        # Now we claim the model has been loaded 
     871        self.model_is_loaded = True 
     872 
     873        # (Re)-create headers 
     874        FittingUtilities.addHeadersToModel(self._model_model) 
     875 
     876        # Update Q Ranges 
     877        self.updateQRange() 
     878 
     879    def fromModelToQModel(self, model_name): 
     880        """ 
     881        Setting model parameters into QStandardItemModel based on selected _model_ 
     882        """ 
    843883        kernel_module = generate.load_kernel_module(model_name) 
    844884        self.model_parameters = modelinfo.make_parameter_table(getattr(kernel_module, 'parameters', [])) 
     
    858898        self._last_model_row = self._model_model.rowCount() 
    859899 
    860         FittingUtilities.addHeadersToModel(self._model_model) 
    861  
    862         # Add structure factor 
    863         if structure_factor is not None and structure_factor != "None": 
    864             structure_module = generate.load_kernel_module(structure_factor) 
    865             structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
    866             new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 
    867             for row in new_rows: 
    868                 self._model_model.appendRow(row) 
    869             # Update the counter used for multishell display 
    870             self._last_model_row = self._model_model.rowCount() 
    871         else: 
    872             self.addStructureFactor() 
    873  
    874         # Multishell models need additional treatment 
    875         self.addExtraShells() 
    876  
    877         # Add polydispersity to the model 
    878         self.setPolyModel() 
    879         # Add magnetic parameters to the model 
    880         self.setMagneticModel() 
    881  
    882         # Adjust the table cells width 
    883         self.lstParams.resizeColumnToContents(0) 
    884         self.lstParams.setSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Expanding) 
    885  
    886         # Now we claim the model has been loaded 
    887         self.model_is_loaded = True 
    888  
    889         # Update Q Ranges 
    890         self.updateQRange() 
     900    def fromStructureFactorToQModel(self, structure_factor): 
     901        """ 
     902        Setting model parameters into QStandardItemModel based on selected _structure factor_ 
     903        """ 
     904        structure_module = generate.load_kernel_module(structure_factor) 
     905        structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
     906 
     907        new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 
     908        for row in new_rows: 
     909            self._model_model.appendRow(row) 
     910        # Update the counter used for multishell display 
     911        self._last_model_row = self._model_model.rowCount() 
    891912 
    892913    def updateParamsFromModel(self, item): 
     
    11591180        FittingUtilities.addHeadersToModel(self._magnet_model) 
    11601181 
    1161     def addStructureFactor(self): 
     1182    def enableStructureFactorControl(self, structure_factor): 
    11621183        """ 
    11631184        Add structure factors to the list of parameters 
    11641185        """ 
    1165         if self.kernel_module.is_form_factor: 
     1186        if self.kernel_module.is_form_factor or structure_factor == 'None': 
    11661187            self.enableStructureCombo() 
    11671188        else: 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    rdc5ef15 rfd1ae6d1  
    219219        self.assertEqual(self.widget.cbStructureFactor.currentText(), STRUCTURE_DEFAULT) 
    220220 
    221  
    222         # TODO once functionality fixed 
    223         ## Switch category to structure factor 
    224         #structure_index=self.widget.cbCategory.findText(CATEGORY_STRUCTURE) 
    225         #self.widget.cbCategory.setCurrentIndex(structure_index) 
    226         ## Choose the last factor 
    227         #last_index = self.widget.cbStructureFactor.count() 
    228         #self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 
     221        # Switch category to structure factor 
     222        structure_index=self.widget.cbCategory.findText(CATEGORY_STRUCTURE) 
     223        self.widget.cbCategory.setCurrentIndex(structure_index) 
     224        # Observe the correct enablement 
     225        self.assertTrue(self.widget.cbStructureFactor.isEnabled()) 
     226        self.assertFalse(self.widget.cbModel.isEnabled()) 
     227        self.assertEqual(self.widget._model_model.rowCount(), 0) 
     228 
     229        # Choose the last factor 
     230        last_index = self.widget.cbStructureFactor.count() 
     231        self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 
     232        # Do we have all the rows? 
     233        self.assertEqual(self.widget._model_model.rowCount(), 4) 
     234 
     235        # Are the command buttons properly enabled? 
     236        self.assertTrue(self.widget.cmdPlot.isEnabled()) 
     237        self.assertFalse(self.widget.cmdFit.isEnabled()) 
    229238 
    230239    def testReadCategoryInfo(self): 
Note: See TracChangeset for help on using the changeset viewer.