Changeset 00b3b40 in sasview


Ignore:
Timestamp:
May 15, 2017 8:57:34 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:
2a432e7
Parents:
2241130
Message:

Improvements to view delegates and model updates.

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

Legend:

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

    r2241130 r00b3b40  
    370370 
    371371        # Update state stack 
    372         if self.undo_supported: 
    373             state = self.currentState() 
    374             self.pushFitPage(state) 
     372        self.updateUndo() 
    375373 
    376374    def onSelectStructureFactor(self): 
     
    429427        name_index = self._poly_model.index(model_row, 0) 
    430428        # Extract changed value. Assumes proper validation by QValidator/Delegate 
    431         # Checkbox in column 0 
     429        # TODO: abstract away hardcoded column numbers 
    432430        if model_column == 0: 
     431            # Is the parameter checked for fitting? 
    433432            value = item.checkState() 
     433            # TODO: add the param to self.params_for_fitting 
     434        elif model_column == 6: 
     435            value = item.text() 
     436            # TODO: Modify Npts/Nsigs based on function choice 
    434437        else: 
    435438            try: 
     
    866869            return 
    867870        parameter_name = str(self._model_model.data(name_index).toPyObject()) # sld, background etc. 
    868         property_name = str(self._model_model.headerData(1, model_column).toPyObject()) # Value, min, max, etc. 
    869  
     871        property_index = self._model_model.headerData(1, model_column).toInt()[0]-1 # Value, min, max, etc. 
     872 
     873        # Update the parameter value - note: this supports +/-inf as well 
    870874        self.kernel_module.params[parameter_name] = value 
    871875 
    872         # TODO: update min/max based on property_name 
    873876        # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 
    874         # magnetic params in self.kernel_module.details['M0:parameter_name'] = value 
    875         # multishell params in self.kernel_module.details[??] = value 
     877        self.kernel_module.details[parameter_name][property_index] = value 
     878 
     879        # TODO: magnetic params in self.kernel_module.details['M0:parameter_name'] = value 
     880        # TODO: multishell params in self.kernel_module.details[??] = value 
    876881 
    877882        # Force the chart update when actual parameters changed 
     
    880885 
    881886        # Update state stack 
    882         if self.undo_supported: 
    883             state = self.currentState() 
    884             self.pushFitPage(state) 
     887        self.updateUndo() 
    885888 
    886889    def checkboxSelected(self, item): 
     
    943946        Update a QStandardModelIndex containing model data 
    944947        """ 
    945         if fitted_data.name is None: 
    946             name = self.nameForFittedData(self.logic.data.filename) 
    947             fitted_data.title = name 
    948             fitted_data.name = name 
    949         else: 
    950             name = fitted_data.name 
     948        name = self.nameFromData(fitted_data) 
    951949        # Make this a line if no other defined 
    952950        if hasattr(fitted_data, 'symbol') and fitted_data.symbol is None: 
     
    959957        Create a QStandardModelIndex containing model data 
    960958        """ 
     959        name = self.nameFromData(fitted_data) 
     960        # Notify the GUI manager so it can create the theory model in DataExplorer 
     961        new_item = GuiUtils.createModelItemWithPlot(QtCore.QVariant(fitted_data), name=name) 
     962        self.communicate.updateTheoryFromPerspectiveSignal.emit(new_item) 
     963 
     964    def nameFromData(self, fitted_data): 
     965        """ 
     966        Return name for the dataset. Terribly impure function. 
     967        """ 
    961968        if fitted_data.name is None: 
    962             name = self.nameForFittedData(self.kernel_module.name) 
     969            name = self.nameForFittedData(self.logic.data.filename) 
    963970            fitted_data.title = name 
    964971            fitted_data.name = name 
     
    966973        else: 
    967974            name = fitted_data.name 
    968         # Notify the GUI manager so it can create the theory model in DataExplorer 
    969         new_item = GuiUtils.createModelItemWithPlot(QtCore.QVariant(fitted_data), name=name) 
    970         self.communicate.updateTheoryFromPerspectiveSignal.emit(new_item) 
     975        return name 
    971976 
    972977    def methodCalculateForData(self): 
     
    12581263        # TODO: add polidyspersity and magnetism 
    12591264 
     1265 
     1266    def updateUndo(self): 
     1267        """ 
     1268        Create a new state page and add it to the stack 
     1269        """ 
     1270        if self.undo_supported: 
     1271            self.pushFitPage(self.currentState()) 
     1272 
    12601273    def currentState(self): 
    12611274        """ 
  • src/sas/qtgui/Perspectives/Fitting/UI/FittingWidgetUI.ui

    rf7f5796 r00b3b40  
    394394         <layout class="QGridLayout" name="gridLayout_9"> 
    395395          <item row="0" column="0"> 
    396            <widget class="QTableView" name="lstPoly"/> 
     396           <widget class="QTableView" name="lstPoly"> 
     397            <property name="editTriggers"> 
     398             <set>QAbstractItemView::AllEditTriggers</set> 
     399            </property> 
     400            <property name="alternatingRowColors"> 
     401             <bool>true</bool> 
     402            </property> 
     403            <property name="selectionMode"> 
     404             <enum>QAbstractItemView::MultiSelection</enum> 
     405            </property> 
     406            <property name="selectionBehavior"> 
     407             <enum>QAbstractItemView::SelectRows</enum> 
     408            </property> 
     409           </widget> 
    397410          </item> 
    398411         </layout> 
  • src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py

    r6011788 r00b3b40  
    2222POLY_FUNCTION=6 
    2323 
    24 class 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() 
    3224 
    3325class ModelViewDelegate(QtGui.QStyledItemDelegate): 
     
    8173            editor.setValidator(validator) 
    8274            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 
    9075 
    9176        return super(ModelViewDelegate, self).createEditor(widget, option, index) 
    9277 
    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() 
     78    def setModelData(self, editor, model, index): 
     79        """ 
     80        Overwrite generic model update method for certain columns 
     81        """ 
     82        if index.column() in (PARAM_MIN, PARAM_MAX): 
    10683            try: 
    107                 value_float = float(content) 
     84                value_float = float(editor.text()) 
    10885            except ValueError: 
    109                 # TODO: Notify the user 
    110                 # <scary popup> 
    111                 # Do nothing 
     86                # TODO: present the failure to the user 
     87                # balloon popup? tooltip? cell background colour flash? 
    11288                return 
    113             self.commitData.emit(editor) 
    114             self.closeEditor.emit(editor, QtGui.QAbstractItemDelegate.NoHint) 
     89        QtGui.QStyledItemDelegate.setModelData(self, editor, model, index) 
    11590 
    11691 
    11792class PolyViewDelegate(QtGui.QStyledItemDelegate): 
    11893    """ 
    119     Custom delegate for appearance and behavior control of the polydisperisty view 
     94    Custom delegate for appearance and behavior control of the polydispersity view 
    12095    """ 
    121     def createEditor(self, parent, option, index): 
    122         # TODO: set it to correct index on creation 
     96    def createEditor(self, widget, option, index): 
     97        # Remember the current choice 
     98        current_text = index.data().toString() 
    12399        if index.column() == POLY_FUNCTION: 
    124             editor = QtGui.QComboBox(parent) 
     100            editor = QtGui.QComboBox(widget) 
    125101            for function in POLYDISPERSE_FUNCTIONS: 
    126102                editor.addItem(function) 
     103            current_index = editor.findText(current_text) 
     104            editor.setCurrentIndex(current_index if current_index>-1 else 0) 
    127105            return editor 
    128106        else: 
    129             QtGui.QStyledItemDelegate.createEditor(self, parent, option, index) 
     107            QtGui.QStyledItemDelegate.createEditor(self, widget, option, index) 
Note: See TracChangeset for help on using the changeset viewer.