Commit eca35ce8 authored by Christian Stenger's avatar Christian Stenger Committed by Niels Weber
Browse files

Make disabled a state instead of separate type



State will be enhanced later on to provide better support for gtest.

Change-Id: I3f3f6b986d6a25ebd36fe44330c792608844b35c
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
parent 00f93b95
......@@ -434,6 +434,7 @@ static TestTreeItem *constructTestTreeItem(const QString &fileName,
locationAndType.m_type);
treeItemChild->setLine(locationAndType.m_line);
treeItemChild->setColumn(locationAndType.m_column);
treeItemChild->setState(locationAndType.m_state);
// check for data tags and if there are any for this function add them
const QString qualifiedFunctionName = testCaseName + QLatin1String("::") + functionName;
......@@ -445,6 +446,7 @@ static TestTreeItem *constructTestTreeItem(const QString &fileName,
tagLocation.m_type);
tagTreeItem->setLine(tagLocation.m_line);
tagTreeItem->setColumn(tagLocation.m_column);
tagTreeItem->setState(tagLocation.m_state);
treeItemChild->appendChild(tagTreeItem);
}
}
......@@ -464,6 +466,7 @@ static TestTreeItem *constructGTestTreeItem(const QString &filePath, const GTest
foreach (const TestCodeLocationAndType &locationAndType, testSets) {
TestTreeItem *treeItemChild = new TestTreeItem(locationAndType.m_name, filePath,
locationAndType.m_type);
treeItemChild->setState(locationAndType.m_state);
treeItemChild->setLine(locationAndType.m_line);
treeItemChild->setColumn(locationAndType.m_column);
treeItemChild->setMainFile(proFile);
......@@ -1032,7 +1035,7 @@ void TestCodeParser::updateGTests(const CPlusPlus::Document::Ptr &doc,
info.setProFile(proFile);
foreach (const TestCodeLocationAndType &testSet, tests.value(testSpec)) {
GTestInfo gtestInfo(testSpec.testCaseName, testSet.m_name, fileName);
if (testSet.m_type == TestTreeItem::GTestNameDisabled)
if (testSet.m_state & TestTreeItem::Disabled)
gtestInfo.setEnabled(false);
m_gtestDocList.append(gtestInfo);
}
......
......@@ -34,7 +34,8 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty
m_name(name),
m_filePath(filePath),
m_type(type),
m_line(0)
m_line(0),
m_state(Enabled)
{
switch (m_type) {
case TestClass:
......@@ -42,7 +43,6 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty
case GTestCase:
case GTestCaseParameterized:
case GTestName:
case GTestNameDisabled:
m_checked = Qt::Checked;
break;
default:
......@@ -63,7 +63,8 @@ TestTreeItem::TestTreeItem(const TestTreeItem &other)
m_type(other.m_type),
m_line(other.m_line),
m_column(other.m_column),
m_mainFile(other.m_mainFile)
m_mainFile(other.m_mainFile),
m_state(other.m_state)
{
for (int row = 0, count = other.childCount(); row < count; ++row)
appendChild(new TestTreeItem(*childItem(row)));
......@@ -118,7 +119,6 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
return m_name.isEmpty() ? QVariant() : checked();
case TestFunction:
case GTestName:
case GTestNameDisabled:
if (parentItem() && parentItem()->name().isEmpty())
return QVariant();
return checked();
......@@ -144,6 +144,8 @@ QVariant TestTreeItem::data(int /*column*/, int role) const
}
case TypeRole:
return m_type;
case StateRole:
return (int)m_state;
}
return QVariant();
}
......@@ -181,6 +183,10 @@ bool TestTreeItem::modifyContent(const TestTreeItem *modified)
m_type = modified->m_type;
hasBeenModified = true;
}
if (m_state != modified->m_state) {
m_state = modified->m_state;
hasBeenModified = true;
}
return hasBeenModified;
}
......@@ -188,8 +194,7 @@ void TestTreeItem::setChecked(const Qt::CheckState checkState)
{
switch (m_type) {
case TestFunction:
case GTestName:
case GTestNameDisabled: {
case GTestName: {
m_checked = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked);
parentItem()->revalidateCheckState();
break;
......@@ -215,7 +220,6 @@ Qt::CheckState TestTreeItem::checked() const
case GTestCase:
case GTestCaseParameterized:
case GTestName:
case GTestNameDisabled:
return m_checked;
case TestDataFunction:
case TestSpecialFunction:
......
......@@ -30,7 +30,8 @@ namespace {
enum ItemRole {
LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back
ItalicRole, // used only inside the delegate
TypeRole
TypeRole,
StateRole
};
}
......@@ -41,7 +42,8 @@ class TestTreeItem : public Utils::TreeItem
{
public:
enum Type {
enum Type
{
Root,
TestClass,
TestFunction,
......@@ -50,10 +52,18 @@ public:
TestSpecialFunction,
GTestCase,
GTestCaseParameterized,
GTestName,
GTestNameDisabled
GTestName
};
enum TestState
{
Enabled = 0x00,
Disabled = 0x01,
};
Q_FLAGS(TestState)
Q_DECLARE_FLAGS(TestStates, TestState)
TestTreeItem(const QString &name = QString(), const QString &filePath = QString(),
Type type = Root);
virtual ~TestTreeItem();
......@@ -74,6 +84,8 @@ public:
void setChecked(const Qt::CheckState checked);
Qt::CheckState checked() const;
Type type() const { return m_type; }
void setState(TestStates states) { m_state = states; }
TestStates state() const { return m_state; }
QList<QString> getChildNames() const;
TestTreeItem *parentItem() const;
TestTreeItem *childItem(int row) const;
......@@ -88,6 +100,7 @@ private:
unsigned m_line;
unsigned m_column;
QString m_mainFile; // main for Quick tests, project file for gtest
TestStates m_state;
};
struct TestCodeLocationAndType {
......@@ -95,6 +108,7 @@ struct TestCodeLocationAndType {
unsigned m_line;
unsigned m_column;
TestTreeItem::Type m_type;
TestTreeItem::TestStates m_state;
};
typedef QVector<TestCodeLocationAndType> TestCodeLocationList;
......
......@@ -65,7 +65,7 @@ void TestTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
}
// paint disabled googletests in gray
if (index.data(TypeRole).toInt() == TestTreeItem::GTestNameDisabled)
if (index.data(StateRole).toInt() & TestTreeItem::Disabled)
opt.palette.setColor(QPalette::Text, QColor(0xa0, 0xa0, 0xa0));
QStyledItemDelegate::paint(painter, opt, index);
......
......@@ -146,7 +146,6 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int
break;
case TestTreeItem::TestFunction:
case TestTreeItem::GTestName:
case TestTreeItem::GTestNameDisabled:
emit dataChanged(index.parent(), index.parent());
break;
default: // avoid warning regarding unhandled enum member
......@@ -173,7 +172,6 @@ Qt::ItemFlags TestTreeModel::flags(const QModelIndex &index) const
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsTristate | Qt::ItemIsUserCheckable;
case TestTreeItem::TestFunction:
case TestTreeItem::GTestName:
case TestTreeItem::GTestNameDisabled:
if (item->parentItem()->name().isEmpty())
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable;
......
......@@ -89,6 +89,7 @@ bool TestVisitor::visit(CPlusPlus::Class *symbol)
locationAndType.m_type = TestTreeItem::TestDataFunction;
else
locationAndType.m_type = TestTreeItem::TestFunction;
locationAndType.m_state = TestTreeItem::Enabled;
m_privSlots.insert(name, locationAndType);
}
}
......@@ -218,6 +219,7 @@ bool TestDataFunctionVisitor::visit(CPlusPlus::CallAST *ast)
locationAndType.m_column = column - 1;
locationAndType.m_line = line;
locationAndType.m_type = TestTreeItem::TestDataTag;
locationAndType.m_state = TestTreeItem::Enabled;
m_currentTags.append(locationAndType);
}
}
......@@ -329,6 +331,7 @@ bool TestQmlVisitor::visit(QmlJS::AST::FunctionDeclaration *ast)
else
locationAndType.m_type = TestTreeItem::TestFunction;
locationAndType.m_state = TestTreeItem::Enabled;
m_testFunctions.insert(name.toString(), locationAndType);
}
return false;
......@@ -378,8 +381,8 @@ bool GTestVisitor::visit(CPlusPlus::FunctionDefinitionAST *ast)
locationAndType.m_name = disabled ? testName.mid(9) : testName;
locationAndType.m_line = line;
locationAndType.m_column = column - 1;
locationAndType.m_type = disabled ? TestTreeItem::GTestNameDisabled
: TestTreeItem::GTestName;
locationAndType.m_type = TestTreeItem::GTestName;
locationAndType.m_state = disabled ? TestTreeItem::Disabled : TestTreeItem::Enabled;
GTestCaseSpec spec;
spec.testCaseName = testCaseName;
spec.parameterized = TestUtils::isGTestParameterized(prettyName);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment