From eca35ce8684b833ae8d878fdb21faf7fd4cea1bb Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 15 Jan 2016 07:21:38 +0100 Subject: [PATCH] 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: Niels Weber --- plugins/autotest/testcodeparser.cpp | 5 ++++- plugins/autotest/testtreeitem.cpp | 18 +++++++++++------- plugins/autotest/testtreeitem.h | 22 ++++++++++++++++++---- plugins/autotest/testtreeitemdelegate.cpp | 2 +- plugins/autotest/testtreemodel.cpp | 2 -- plugins/autotest/testvisitor.cpp | 7 +++++-- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/plugins/autotest/testcodeparser.cpp b/plugins/autotest/testcodeparser.cpp index 0b73568443f..9270a6d4548 100644 --- a/plugins/autotest/testcodeparser.cpp +++ b/plugins/autotest/testcodeparser.cpp @@ -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); } diff --git a/plugins/autotest/testtreeitem.cpp b/plugins/autotest/testtreeitem.cpp index e514e9cd704..e6ea3a89131 100644 --- a/plugins/autotest/testtreeitem.cpp +++ b/plugins/autotest/testtreeitem.cpp @@ -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: diff --git a/plugins/autotest/testtreeitem.h b/plugins/autotest/testtreeitem.h index ac4134ee36a..bc6038809c8 100644 --- a/plugins/autotest/testtreeitem.h +++ b/plugins/autotest/testtreeitem.h @@ -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 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 TestCodeLocationList; diff --git a/plugins/autotest/testtreeitemdelegate.cpp b/plugins/autotest/testtreeitemdelegate.cpp index 17475e2326a..e17e6029c97 100644 --- a/plugins/autotest/testtreeitemdelegate.cpp +++ b/plugins/autotest/testtreeitemdelegate.cpp @@ -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); diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index d6e4d1d724d..19f47e40006 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -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; diff --git a/plugins/autotest/testvisitor.cpp b/plugins/autotest/testvisitor.cpp index 9c4d4d272d8..256e679d2fc 100644 --- a/plugins/autotest/testvisitor.cpp +++ b/plugins/autotest/testvisitor.cpp @@ -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);