1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
class RepositoryTableDelegate(QtGui.QItemDelegate):
'''
Class that defines and implement the visual customization of the table
view to show check boxes and progress bars.
@ingroup DM
'''
def __init__(self, owner):
'''
Class constructor
@param[in] owner The owner of this widget.
'''
QtGui.QItemDelegate.__init__(self, owner)
def paint(self, painter, option, index):
'''
Method to draw the model.
@param[in] painter The painter to use to draw.
@param[in] option The QStyleOptionViewItem defining the needed object option.
@param[in] index The
'''
column = index.column()
if column == 0:
# Get item data
value = index.data(QtCore.Qt.DisplayRole).toBool()
# fill style options with item data
style = QtGui.QApplication.style()
opt = QtGui.QStyleOptionButton()
opt.state |= QtGui.QStyle.State_On if value else QtGui.QStyle.State_Off
opt.state |= QtGui.QStyle.State_Enabled
opt.text = ""
opt.rect = option.rect
# draw item data as CheckBox
style.drawControl(QtGui.QStyle.CE_CheckBox, opt, painter)
return
elif column == 2:
# Get the % number of loaded revisions.
value = index.data(QtCore.Qt.DisplayRole)
value,_ = value.toInt()
# fill style options with item data
style = QtGui.QApplication.style()
opt = QtGui.QStyleOptionProgressBarV2()
opt.maximum = 100
opt.progress = value
opt.rect = option.rect
opt.textVisible = False
opt.text = str(value)
# draw item data as CheckBox
style.drawControl(QtGui.QStyle.CE_ProgressBar, opt, painter)
return
QtGui.QItemDelegate.paint(self, painter, option, index)
def createEditor(self, parent, option, index):
column = index.column()
if column == 0:
# create check box as our editor.
editor = QtGui.QCheckBox(parent)
return editor
elif column == 2:
# create the ProgressBar as our editor.
editor = QtGui.QProgressBar(parent)
return editor
return QtGui.QAbstractItemDelegate.createEditor(self, parent, option, index)
def setEditorData(self, editor, index):
column = index.column()
if column == 0:
# set editor data
value = index.data(QtCore.Qt.DisplayRole).toBool()
editor.setChecked(value)
return
elif column == 2:
value,_ = index.data(QtCore.Qt.DisplayRole).toInt()
editor.setValue(value)
return
QtGui.QAbstractItemDelegate.setEditorData(self, editor, index)
def updateEditorGeometry(self, editor, option, index):
editor.setGeometry(option.rect) |
Partager