From e0d32a80363759837cc13eb24365f3cd07174da7 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 30 Apr 2015 13:24:47 +0200 Subject: Enhance test tree to be able to support Squish tests Change-Id: I93fec9ee1a413fe02fb19475a44644578b842c88 Reviewed-by: Robert Loehning Reviewed-by: Christian Stenger --- plugins/autotest/testnavigationwidget.cpp | 71 +++++++++++++++++++++++++++++++ plugins/autotest/testnavigationwidget.h | 1 + plugins/autotest/testtreeitem.cpp | 33 +++++++++++++- plugins/autotest/testtreeitem.h | 6 ++- plugins/autotest/testtreemodel.cpp | 33 ++++++++++++-- plugins/autotest/testtreemodel.h | 7 ++- 6 files changed, 142 insertions(+), 9 deletions(-) diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp index f9847a5782..68565c0b3c 100644 --- a/plugins/autotest/testnavigationwidget.cpp +++ b/plugins/autotest/testnavigationwidget.cpp @@ -84,11 +84,82 @@ TestNavigationWidget::~TestNavigationWidget() m_model->disableParsing(); } +bool TestNavigationWidget::handleSquishContextMenuEvent(QContextMenuEvent *event, bool enabled) +{ + bool isSquishMenu = false; + QMenu menu; + + // item specific menu entries + const QModelIndexList list = m_view->selectionModel()->selectedIndexes(); + if (list.size() == 1) { + QRect rect(m_view->visualRect(list.first())); + if (rect.contains(event->pos())) { + TestTreeItem::Type type = TestTreeItem::toTestType(list.first().data(TypeRole).toInt()); + + if (type == TestTreeItem::SQUISH_TESTCASE) { + isSquishMenu = true; + QAction *runThisTestCase = new QAction(tr("Run This Test Case"), &menu); + menu.addAction(runThisTestCase); + runThisTestCase->setEnabled(enabled); + QAction *deleteTestCase = new QAction(tr("Delete Test Case"), &menu); + menu.addAction(deleteTestCase); + deleteTestCase->setEnabled(enabled); + menu.addSeparator(); + } else if (type == TestTreeItem::SQUISH_SUITE) { + isSquishMenu = true; + QAction *runThisTestSuite = new QAction(tr("Run This Test Suite"), &menu); + menu.addAction(runThisTestSuite); + runThisTestSuite->setEnabled(enabled); + menu.addSeparator(); + QAction *addNewTestCase = new QAction(tr("Add New Test Case..."), &menu); + menu.addAction(addNewTestCase); + addNewTestCase->setEnabled(enabled); + QAction *closeTestSuite = new QAction(tr("Close Test Suite"), &menu); + menu.addAction(closeTestSuite); + closeTestSuite->setEnabled(enabled); + QAction *deleteTestSuite = new QAction(tr("Delete Test Suite"), &menu); + menu.addAction(deleteTestSuite); + deleteTestSuite->setEnabled(enabled); + menu.addSeparator(); + } + } + } + // ROOT items aren't selectable - so, check for them different way + QModelIndex squishIndex = m_view->model()->index(2, 0); + QRect squishRootRect(m_view->visualRect(squishIndex)); + if (squishRootRect.contains(event->pos())) + isSquishMenu = true; + + if (isSquishMenu) { + // general squish related menu entries + QAction *openSquishSuites = new QAction(tr("Open Squish Suites..."), &menu); + menu.addAction(openSquishSuites); + openSquishSuites->setEnabled(enabled); + QAction *createNewTestSuite = new QAction(tr("Create New Test Suite..."), &menu); + menu.addAction(createNewTestSuite); + createNewTestSuite->setEnabled(enabled); + + if (m_view->model()->rowCount(squishIndex) > 0) { + menu.addSeparator(); + QAction *closeAllSuites = new QAction(tr("Close All Test Suites"), &menu); + menu.addAction(closeAllSuites); + closeAllSuites->setEnabled(enabled); + } + + menu.exec(mapToGlobal(event->pos())); + } + return isSquishMenu; +} + void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) { const bool enabled = !TestRunner::instance()->isTestRunning() && m_model->parser()->state() == TestCodeParser::Idle; const bool hasTests = m_model->hasTests(); + + if (handleSquishContextMenuEvent(event, enabled)) + return; + QMenu menu; QAction *runAll = Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action(); QAction *runSelected = Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action(); diff --git a/plugins/autotest/testnavigationwidget.h b/plugins/autotest/testnavigationwidget.h index a4b4c6f061..a2a7d2fae7 100644 --- a/plugins/autotest/testnavigationwidget.h +++ b/plugins/autotest/testnavigationwidget.h @@ -68,6 +68,7 @@ private slots: void onParsingFinished(); private: + bool handleSquishContextMenuEvent(QContextMenuEvent *event, bool enabled); void initializeFilterMenu(); TestTreeModel *m_model; diff --git a/plugins/autotest/testtreeitem.cpp b/plugins/autotest/testtreeitem.cpp index 721c605473..4c430db177 100644 --- a/plugins/autotest/testtreeitem.cpp +++ b/plugins/autotest/testtreeitem.cpp @@ -35,6 +35,8 @@ TestTreeItem::TestTreeItem(const QString &name, const QString &filePath, Type ty break; case TEST_CLASS: case TEST_FUNCTION: + case SQUISH_SUITE: + case SQUISH_TESTCASE: m_checked = Qt::Checked; break; case TEST_DATAFUNCTION: @@ -144,12 +146,14 @@ bool TestTreeItem::modifyContent(const TestTreeItem *modified) void TestTreeItem::setChecked(const Qt::CheckState checkState) { switch (m_type) { - case TEST_FUNCTION: { + case TEST_FUNCTION: + case SQUISH_TESTCASE: { m_checked = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked); m_parent->revalidateCheckState(); break; } - case TEST_CLASS: { + case TEST_CLASS: + case SQUISH_SUITE: { Qt::CheckState usedState = (checkState == Qt::Unchecked ? Qt::Unchecked : Qt::Checked); foreach (TestTreeItem *child, m_children) { child->setChecked(usedState); @@ -166,6 +170,8 @@ Qt::CheckState TestTreeItem::checked() const switch (m_type) { case TEST_CLASS: case TEST_FUNCTION: + case SQUISH_SUITE: + case SQUISH_TESTCASE: return m_checked; case TEST_DATAFUNCTION: case TEST_SPECIALFUNCTION: @@ -185,6 +191,29 @@ QList TestTreeItem::getChildNames() const return names; } +TestTreeItem::Type TestTreeItem::toTestType(int testType) +{ + switch (testType) { + case ROOT: + return ROOT; + case TEST_CLASS: + return TEST_CLASS; + case TEST_FUNCTION: + return TEST_FUNCTION; + case TEST_DATAFUNCTION: + return TEST_DATAFUNCTION; + case TEST_SPECIALFUNCTION: + return TEST_SPECIALFUNCTION; + case SQUISH_SUITE: + return SQUISH_SUITE; + case SQUISH_TESTCASE: + return SQUISH_TESTCASE; + default: + qWarning("This should not happen: Unknown test type %d", testType); + return ROOT; // should cause the least trouble + } +} + void TestTreeItem::revalidateCheckState() { if (m_children.size() == 0) diff --git a/plugins/autotest/testtreeitem.h b/plugins/autotest/testtreeitem.h index 0cfa1aead1..825e53f0ca 100644 --- a/plugins/autotest/testtreeitem.h +++ b/plugins/autotest/testtreeitem.h @@ -36,7 +36,9 @@ public: TEST_CLASS, TEST_FUNCTION, TEST_DATAFUNCTION, - TEST_SPECIALFUNCTION + TEST_SPECIALFUNCTION, + SQUISH_SUITE, + SQUISH_TESTCASE }; TestTreeItem(const QString &name = QString(), const QString &filePath = QString(), @@ -69,6 +71,8 @@ public: void setParent(TestTreeItem *parent) { m_parent = parent; } QList getChildNames() const; + static Type toTestType(int testType); + private: void revalidateCheckState(); diff --git a/plugins/autotest/testtreemodel.cpp b/plugins/autotest/testtreemodel.cpp index 2ee021ad06..b4d0b582b6 100644 --- a/plugins/autotest/testtreemodel.cpp +++ b/plugins/autotest/testtreemodel.cpp @@ -22,6 +22,8 @@ #include "testtreeitem.h" #include "testtreemodel.h" +#include // remove if placeholder icon is removed as well + #include #include @@ -50,11 +52,13 @@ TestTreeModel::TestTreeModel(QObject *parent) : m_rootItem(new TestTreeItem(QString(), QString(), TestTreeItem::ROOT)), m_autoTestRootItem(new TestTreeItem(tr("Auto Tests"), QString(), TestTreeItem::ROOT, m_rootItem)), m_quickTestRootItem(new TestTreeItem(tr("Qt Quick Tests"), QString(), TestTreeItem::ROOT, m_rootItem)), + m_squishTestRootItem(new TestTreeItem(tr("Squish Tests"), QString(), TestTreeItem::ROOT, m_rootItem)), m_parser(new TestCodeParser(this)), m_connectionsInitialized(false) { m_rootItem->appendChild(m_autoTestRootItem); m_rootItem->appendChild(m_quickTestRootItem); + m_rootItem->appendChild(m_squishTestRootItem); connect(m_parser, &TestCodeParser::cacheCleared, this, &TestTreeModel::removeAllTestItems, Qt::QueuedConnection); @@ -183,13 +187,21 @@ int TestTreeModel::columnCount(const QModelIndex &) const static QIcon testTreeIcon(TestTreeItem::Type type) { - static QIcon icons[3] = { + static QIcon icons[5] = { QIcon(), QIcon(QLatin1String(":/images/class.png")), - QIcon(QLatin1String(":/images/func.png")) + QIcon(QLatin1String(":/images/func.png")), + // TODO these icons are actually only placeholder + QIcon(QLatin1String(Core::Constants::ICON_DIR)), + QIcon(QLatin1String(":/fancyactionbar/images/mode_Edit.png")) }; - if (type >= 3) + if (type >= 3) { + if (type == TestTreeItem::SQUISH_SUITE) + return icons[3]; + if (type == TestTreeItem::SQUISH_TESTCASE) + return icons[4]; return icons[2]; + } return icons[type]; } @@ -204,7 +216,8 @@ QVariant TestTreeModel::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { if ((item == m_autoTestRootItem && m_autoTestRootItem->childCount() == 0) - || (item == m_quickTestRootItem && m_quickTestRootItem->childCount() == 0)) { + || (item == m_quickTestRootItem && m_quickTestRootItem->childCount() == 0) + || (item == m_squishTestRootItem && m_squishTestRootItem->childCount() == 0)) { return QString(item->name() + tr(" (none)")); } else { if (item->name().isEmpty()) @@ -238,6 +251,8 @@ QVariant TestTreeModel::data(const QModelIndex &index, int role) const return parent->name().isEmpty() ? QVariant() : item->checked(); else return item->checked(); + case TestTreeItem::SQUISH_SUITE: + case TestTreeItem::SQUISH_TESTCASE: default: return item->checked(); } @@ -262,6 +277,8 @@ QVariant TestTreeModel::data(const QModelIndex &index, int role) const default: return false; } + case TypeRole: + return item->type(); } // TODO ? @@ -280,12 +297,14 @@ bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int if (item->checked() != old) { switch(item->type()) { case TestTreeItem::TEST_CLASS: + case TestTreeItem::SQUISH_SUITE: emit dataChanged(index, index); if (item->childCount() > 0) { emit dataChanged(index.child(0, 0), index.child(item->childCount() - 1, 0)); } break; case TestTreeItem::TEST_FUNCTION: + case TestTreeItem::SQUISH_TESTCASE: emit dataChanged(index, index); emit dataChanged(index.parent(), index.parent()); break; @@ -306,10 +325,12 @@ Qt::ItemFlags TestTreeModel::flags(const QModelIndex &index) const TestTreeItem *item = static_cast(index.internalPointer()); switch(item->type()) { case TestTreeItem::TEST_CLASS: + case TestTreeItem::SQUISH_SUITE: if (item->name().isEmpty()) return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsTristate | Qt::ItemIsUserCheckable; case TestTreeItem::TEST_FUNCTION: + case TestTreeItem::SQUISH_TESTCASE: if (item->parent()->name().isEmpty()) return Qt::ItemIsEnabled | Qt::ItemIsSelectable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; @@ -780,6 +801,8 @@ TestTreeItem *TestTreeModel::rootItemForType(TestTreeModel::Type type) return m_autoTestRootItem; case QuickTest: return m_quickTestRootItem; + case SquishTest: + return m_squishTestRootItem; } QTC_ASSERT(false, return 0); } @@ -791,6 +814,8 @@ QModelIndex TestTreeModel::rootIndexForType(TestTreeModel::Type type) return index(0, 0); case QuickTest: return index(1, 0); + case SquishTest: + return index(2, 0); } QTC_ASSERT(false, return QModelIndex()); } diff --git a/plugins/autotest/testtreemodel.h b/plugins/autotest/testtreemodel.h index 15a00ecb38..9aad3fc529 100644 --- a/plugins/autotest/testtreemodel.h +++ b/plugins/autotest/testtreemodel.h @@ -31,7 +31,8 @@ namespace { enum ItemRole { // AnnotationRole = Qt::UserRole + 1, LinkRole = Qt::UserRole + 2, // can be removed if AnnotationRole comes back - ItalicRole // used only inside the delegate + ItalicRole, // used only inside the delegate + TypeRole }; } @@ -49,7 +50,8 @@ class TestTreeModel : public QAbstractItemModel public: enum Type { AutoTest, - QuickTest + QuickTest, + SquishTest }; static TestTreeModel* instance(); @@ -110,6 +112,7 @@ private: TestTreeItem *m_rootItem; TestTreeItem *m_autoTestRootItem; TestTreeItem *m_quickTestRootItem; + TestTreeItem *m_squishTestRootItem; TestCodeParser *m_parser; bool m_connectionsInitialized; QAtomicInt m_refCounter; -- cgit v1.2.1