Changeset b00414d in sasview for src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py
- Timestamp:
- Jul 25, 2017 7:36:45 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:
- 0d13814
- Parents:
- 2a8bd705
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/ViewDelegate.py
r8eaa101 rb00414d 178 178 # Just the default paint 179 179 QtGui.QStyledItemDelegate.paint(self, painter, option, index) 180 181 class MagnetismViewDelegate(QtGui.QStyledItemDelegate): 182 """ 183 Custom delegate for appearance and behavior control of the magnetism view 184 """ 185 def __init__(self, parent=None): 186 """ 187 Overwrite generic constructor to allow for some globals 188 """ 189 super(QtGui.QStyledItemDelegate, self).__init__() 190 191 self.mag_parameter = 0 192 self.mag_value = 1 193 self.mag_min = 2 194 self.mag_max = 3 195 self.mag_unit = 4 196 197 def editableParameters(self): 198 return [self.mag_min, self.mag_max] 199 200 def addErrorColumn(self): 201 """ 202 Modify local column pointers 203 Note: the reverse is never required! 204 """ 205 self.mag_parameter = 0 206 self.mag_value = 1 207 self.mag_min = 3 208 self.mag_max = 4 209 self.mag_unit = 5 210 211 def createEditor(self, widget, option, index): 212 # Remember the current choice 213 current_text = index.data().toString() 214 if not index.isValid(): 215 return 0 216 if index.column() in self.editableParameters(): 217 editor = QtGui.QLineEdit(widget) 218 validator = QtGui.QDoubleValidator() 219 editor.setValidator(validator) 220 return editor 221 else: 222 QtGui.QStyledItemDelegate.createEditor(self, widget, option, index) 223 224 def paint(self, painter, option, index): 225 """ 226 Overwrite generic painter for certain columns 227 """ 228 if index.column() in (self.mag_min, self.mag_max): 229 # Units - present in nice HTML 230 options = QtGui.QStyleOptionViewItemV4(option) 231 self.initStyleOption(options,index) 232 233 style = QtGui.QApplication.style() if options.widget is None else options.widget.style() 234 235 # Prepare document for inserting into cell 236 doc = QtGui.QTextDocument() 237 238 # Convert the unit description into HTML 239 text_html = GuiUtils.convertUnitToHTML(str(options.text)) 240 doc.setHtml(text_html) 241 242 # delete the original content 243 options.text = "" 244 style.drawControl(QtGui.QStyle.CE_ItemViewItem, options, painter, options.widget); 245 246 context = QtGui.QAbstractTextDocumentLayout.PaintContext() 247 textRect = style.subElementRect(QtGui.QStyle.SE_ItemViewItemText, options) 248 249 painter.save() 250 painter.translate(textRect.topLeft()) 251 painter.setClipRect(textRect.translated(-textRect.topLeft())) 252 # Draw the QTextDocument in the cell 253 doc.documentLayout().draw(painter, context) 254 painter.restore() 255 else: 256 # Just the default paint 257 QtGui.QStyledItemDelegate.paint(self, painter, option, index)
Note: See TracChangeset
for help on using the changeset viewer.