Changeset 00b3b40 in sasview for src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py
- Timestamp:
- May 15, 2017 8:57:34 AM (7 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:
- 2a432e7
- Parents:
- 2241130
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py
r6011788 r00b3b40 22 22 POLY_FUNCTION=6 23 23 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_value30 def focusOutEvent(self, event):31 self.editingFinished.emit()32 24 33 25 class ModelViewDelegate(QtGui.QStyledItemDelegate): … … 81 73 editor.setValidator(validator) 82 74 return editor 83 elif index.column() in (PARAM_MIN, PARAM_MAX):84 # Save current value in case we need to revert85 #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 editor90 75 91 76 return super(ModelViewDelegate, self).createEditor(widget, option, index) 92 77 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): 106 83 try: 107 value_float = float( content)84 value_float = float(editor.text()) 108 85 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? 112 88 return 113 self.commitData.emit(editor) 114 self.closeEditor.emit(editor, QtGui.QAbstractItemDelegate.NoHint) 89 QtGui.QStyledItemDelegate.setModelData(self, editor, model, index) 115 90 116 91 117 92 class PolyViewDelegate(QtGui.QStyledItemDelegate): 118 93 """ 119 Custom delegate for appearance and behavior control of the polydisper isty view94 Custom delegate for appearance and behavior control of the polydispersity view 120 95 """ 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() 123 99 if index.column() == POLY_FUNCTION: 124 editor = QtGui.QComboBox( parent)100 editor = QtGui.QComboBox(widget) 125 101 for function in POLYDISPERSE_FUNCTIONS: 126 102 editor.addItem(function) 103 current_index = editor.findText(current_text) 104 editor.setCurrentIndex(current_index if current_index>-1 else 0) 127 105 return editor 128 106 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.