Changeset 6011788 in sasview


Ignore:
Timestamp:
May 15, 2017 3:21:45 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:
2241130
Parents:
ad6b4e2
Message:

Towards the FitPage? stack.
Improvements to view delegates.

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

Legend:

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

    rad6b4e2 r6011788  
    3434from sas.qtgui.Perspectives.Fitting.FitPage import FitPage 
    3535from sas.qtgui.Perspectives.Fitting.ViewDelegate import ModelViewDelegate 
     36from sas.qtgui.Perspectives.Fitting.ViewDelegate import PolyViewDelegate 
    3637 
    3738TAB_MAGNETISM = 4 
     
    7778        self.chi2 = None 
    7879 
     80        # Does the control support UNDO/REDO 
     81        # temporarily off 
     82        self.support_undo = False 
     83 
    7984        # Data for chosen model 
    8085        self.model_data = None 
     
    146151        self.setPolyModel() 
    147152        self.setTableProperties(self.lstPoly) 
     153        # Delegates for custom editing and display 
     154        self.lstPoly.setItemDelegate(PolyViewDelegate(self)) 
    148155 
    149156        # Magnetism model displayed in magnetism list 
     
    361368            self.createDefaultDataset() 
    362369 
    363         # TODO: update state stack 
    364         #state = self.currentState() 
     370        # Update state stack 
     371        if self.support_undo: 
     372            state = self.currentState() 
     373            self.pushFitPage(state) 
    365374 
    366375    def onSelectStructureFactor(self): 
     
    850859 
    851860        # Extract changed value. Assumes proper validation by QValidator/Delegate 
    852         # TODO: disable model update for uneditable cells/columns 
    853861        try: 
    854862            value = float(item.text()) 
     
    10681076            checked_list = ["Distribution of "+param.name, str(param.default), 
    10691077                            str(param.limits[0]), str(param.limits[1]), 
    1070                             "35", "3", ""] 
     1078                            "35", "3", "gaussian"] 
    10711079            FittingUtilities.addCheckedListToModel(self._poly_model, checked_list) 
    10721080 
    10731081            #TODO: Need to find cleaner way to input functions 
    1074             func = QtGui.QComboBox() 
    1075             func.addItems(['rectangle', 'array', 'lognormal', 'gaussian', 'schulz',]) 
    1076             func_index = self.lstPoly.model().index(row, 6) 
    1077             self.lstPoly.setIndexWidget(func_index, func) 
     1082            #func = QtGui.QComboBox() 
     1083            #func.addItems(['rectangle', 'array', 'lognormal', 'gaussian', 'schulz',]) 
     1084            #func_index = self.lstPoly.model().index(row, 6) 
     1085            #self.lstPoly.setIndexWidget(func_index, func) 
    10781086 
    10791087        FittingUtilities.addPolyHeadersToModel(self._poly_model) 
     
    11791187        self.q_range_max = fp.fit_options[fp.MAX_RANGE] 
    11801188        self.npts = fp.fit_options[fp.NPTS] 
    1181         #fp.fit_options[fp.NPTS_FIT] = self.npts_fit 
    11821189        self.log_points = fp.fit_options[fp.LOG_POINTS] 
    11831190        self.weighting = fp.fit_options[fp.WEIGHTING] 
     
    12581265        Add a new fit page object with current state 
    12591266        """ 
    1260         #page_stack.append(new_page) 
     1267        self.page_stack.append(new_page) 
    12611268        pass 
    12621269 
     
    12651272        Remove top fit page from stack 
    12661273        """ 
    1267         #if page_stack: 
    1268         #    page_stack.pop() 
     1274        if self.page_stack: 
     1275            self.page_stack.pop() 
    12691276        pass 
    12701277 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r1bc27f1 r6011788  
    329329        for row in xrange(self.widget._poly_model.rowCount()): 
    330330            func_index = self.widget._poly_model.index(row, 6) 
    331             self.assertTrue(isinstance(self.widget.lstPoly.indexWidget(func_index), QtGui.QComboBox)) 
     331            #self.assertTrue(isinstance(self.widget.lstPoly.indexWidget(func_index), QtGui.QComboBox)) 
    332332            self.assertIn('Distribution of', self.widget._poly_model.item(row, 0).text()) 
    333333 
  • src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py

    rad6b4e2 r6011788  
    44import sas.qtgui.Utilities.GuiUtils as GuiUtils 
    55 
    6 # Table view columns 
    7 PROPERTY=0 
    8 VALUE=1 
    9 MIN=2 
    10 MAX=3 
    11 UNIT=4 
     6# Main parameter table view columns 
     7PARAM_PROPERTY=0 
     8PARAM_VALUE=1 
     9PARAM_MIN=2 
     10PARAM_MAX=3 
     11PARAM_UNIT=4 
     12 
     13# polydispersity functions 
     14POLYDISPERSE_FUNCTIONS=['rectangle', 'array', 'lognormal', 'gaussian', 'schulz'] 
     15# polydispersity columns 
     16POLY_PARAMETER=0 
     17POLY_PD=1 
     18POLY_MIN=2 
     19POLY_MAX=3 
     20POLY_NPTS=4 
     21POLY_NSIGS=5 
     22POLY_FUNCTION=6 
     23 
     24class CustomLineEdit(QtGui.QLineEdit): 
     25    editingFinished = QtCore.pyqtSignal() 
     26    def __init__(self, parent=None, old_value=None): 
     27        super(CustomLineEdit, self).__init__(parent) 
     28        self.setAutoFillBackground(True) 
     29        self.old_value = old_value 
     30    def focusOutEvent(self, event): 
     31        self.editingFinished.emit() 
    1232 
    1333class ModelViewDelegate(QtGui.QStyledItemDelegate): 
     
    1939        Overwrite generic painter for certain columns 
    2040        """ 
    21         if index.column() == UNIT or index.column() == MIN or index.column() == MAX: 
     41        if index.column() in (PARAM_UNIT, PARAM_MIN, PARAM_MAX): 
    2242            # Units - present in nice HTML 
    2343            options = QtGui.QStyleOptionViewItemV4(option) 
     
    5070            QtGui.QStyledItemDelegate.paint(self, painter, option, index) 
    5171 
    52     #def sizeHint(self, option, index): 
    53     #    options = QtGui.QStyleOptionViewItemV4(option) 
    54     #    self.initStyleOption(options,index) 
     72    def createEditor(self, widget, option, index): 
     73        """ 
     74        Overwrite generic editor for certain columns 
     75        """ 
     76        if not index.isValid(): 
     77            return 0 
     78        if index.column() == PARAM_VALUE: #only in the value column 
     79            editor = QtGui.QLineEdit(widget) 
     80            validator = QtGui.QDoubleValidator() 
     81            editor.setValidator(validator) 
     82            return editor 
     83        elif index.column() in (PARAM_MIN, PARAM_MAX): 
     84            # Save current value in case we need to revert 
     85            #self._old_value = index.data().toFloat()[0] 
     86            self._old_value = index.data().toString() 
     87            editor = CustomLineEdit(widget, old_value=self._old_value) 
     88            editor.editingFinished.connect(self.commitAndCloseEditor) 
     89            return editor 
    5590 
    56     #    doc = QtGui.QTextDocument() 
    57     #    doc.setHtml(options.text) 
    58     #    doc.setTextWidth(options.rect.width()) 
    59     #    return QtCore.QSize(doc.idealWidth(), doc.size().height()) 
     91        return super(ModelViewDelegate, self).createEditor(widget, option, index) 
     92 
     93    #def setEditorData(self, editor, index): 
     94    #    if index.column() == MIN: 
     95    #        #value = index.data().toString()[0] 
     96    #        value = index.model().data(index, QtCore.Qt.DisplayRole).toString() 
     97    #        print "VALUE = ", value 
     98    #        editor.setText('['+value+']') 
     99    #        return editor 
     100 
     101    #    return super(ModelViewDelegate, self).setEditorData(editor, index) 
     102 
     103    def commitAndCloseEditor(self): 
     104            editor = self.sender() 
     105            content = editor.text() 
     106            try: 
     107                value_float = float(content) 
     108            except ValueError: 
     109                # TODO: Notify the user 
     110                # <scary popup> 
     111                # Do nothing 
     112                return 
     113            self.commitData.emit(editor) 
     114            self.closeEditor.emit(editor, QtGui.QAbstractItemDelegate.NoHint) 
     115 
     116 
     117class PolyViewDelegate(QtGui.QStyledItemDelegate): 
     118    """ 
     119    Custom delegate for appearance and behavior control of the polydisperisty view 
     120    """ 
     121    def createEditor(self, parent, option, index): 
     122        # TODO: set it to correct index on creation 
     123        if index.column() == POLY_FUNCTION: 
     124            editor = QtGui.QComboBox(parent) 
     125            for function in POLYDISPERSE_FUNCTIONS: 
     126                editor.addItem(function) 
     127            return editor 
     128        else: 
     129            QtGui.QStyledItemDelegate.createEditor(self, parent, option, index) 
Note: See TracChangeset for help on using the changeset viewer.