More robust coloring code in the CC Enum Delegate

This commit is contained in:
Charles Haley 2011-05-21 19:40:27 +01:00
parent 45fcacf2ec
commit 6eec4fa410

View File

@ -289,11 +289,14 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{
elif option.state & QStyle.State_Selected: elif option.state & QStyle.State_Selected:
painter.fillRect(option.rect, option.palette.highlight()) painter.fillRect(option.rect, option.palette.highlight())
m = index.model() m = index.model()
col = m.column_map[index.column()] cc = m.custom_columns[m.column_map[index.column()]]['display']
colors = m.custom_columns[col]['display'].get('enum_colors', []) colors = cc.get('enum_colors', [])
values = m.custom_columns[col]['display']['enum_values'] values = cc.get('enum_values', [])
if len(colors) > 0 and txt in values: if len(colors) > 0 and txt in values:
painter.fillRect(option.rect, QColor(colors[values.index(txt)])) try:
painter.fillRect(option.rect, QColor(colors[values.index(txt)]))
except:
pass
painter.setClipRect(option.rect) painter.setClipRect(option.rect)
painter.translate(option.rect.topLeft()) painter.translate(option.rect.topLeft())
self.document.drawContents(painter) self.document.drawContents(painter)