AutoTest: Make delegate independent from sub-classes...

...of TestTreeItem.

Change-Id: Ieacaeff64dced5e2a4dd3bd3a853cfb1081f5146
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
Christian Stenger
2016-04-29 11:15:14 +02:00
parent f429b95b0e
commit 70394b29af
3 changed files with 8 additions and 8 deletions

View File

@@ -88,6 +88,8 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
return false; return false;
case TypeRole: case TypeRole:
return m_type; return m_type;
case EnabledRole:
return true;
} }
return QVariant(); return QVariant();
} }
@@ -869,8 +871,7 @@ QVariant GoogleTestTreeItem::data(int column, int role) const
if (type() == TestTreeItem::Root) if (type() == TestTreeItem::Root)
break; break;
const QString &displayName = (m_state & GoogleTestTreeItem::Disabled) const QString &displayName = (m_state & Disabled) ? name().mid(9) : name();
? name().mid(9) : name();
return QVariant(displayName + nameSuffix()); return QVariant(displayName + nameSuffix());
} }
case Qt::CheckStateRole: case Qt::CheckStateRole:
@@ -883,8 +884,8 @@ QVariant GoogleTestTreeItem::data(int column, int role) const
} }
case ItalicRole: case ItalicRole:
return false; return false;
case StateRole: case EnabledRole:
return (int)m_state; return !(m_state & Disabled);
default: default:
break; break;
} }

View File

@@ -36,7 +36,7 @@ namespace {
LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back
ItalicRole, // used only inside the delegate ItalicRole, // used only inside the delegate
TypeRole, TypeRole,
StateRole EnabledRole
}; };
} }

View File

@@ -25,7 +25,6 @@
#include "testtreeitem.h" #include "testtreeitem.h"
#include "testtreeitemdelegate.h" #include "testtreeitemdelegate.h"
#include "testtreemodel.h"
#include <QPainter> #include <QPainter>
@@ -70,8 +69,8 @@ void TestTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
} }
} }
// paint disabled googletests in gray // paint disabled items in gray
if (index.data(StateRole).toInt() & GoogleTestTreeItem::Disabled) if (!index.data(EnabledRole).toBool())
opt.palette.setColor(QPalette::Text, QColor(0xa0, 0xa0, 0xa0)); opt.palette.setColor(QPalette::Text, QColor(0xa0, 0xa0, 0xa0));
QStyledItemDelegate::paint(painter, opt, index); QStyledItemDelegate::paint(painter, opt, index);