From 6a4afc7d5f8bb90582fa0e6e68c97448ded29b79 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Thu, 18 Dec 2014 15:02:07 +0100 Subject: rename TestTreeViewWidget to TestNavigationWidget also move it to an extra file Change-Id: Ia76c9b3be4c11207a564e7cc7fcb2eae730ae505 Reviewed-by: Christian Stenger --- plugins/autotest/autotest.pro | 6 +- plugins/autotest/autotestplugin.cpp | 3 +- plugins/autotest/testnavigationwidget.cpp | 230 ++++++++++++++++++++++++++++++ plugins/autotest/testnavigationwidget.h | 91 ++++++++++++ plugins/autotest/testtreeview.cpp | 187 ------------------------ plugins/autotest/testtreeview.h | 58 -------- 6 files changed, 327 insertions(+), 248 deletions(-) create mode 100644 plugins/autotest/testnavigationwidget.cpp create mode 100644 plugins/autotest/testnavigationwidget.h diff --git a/plugins/autotest/autotest.pro b/plugins/autotest/autotest.pro index 507d930300..0366ffae46 100644 --- a/plugins/autotest/autotest.pro +++ b/plugins/autotest/autotest.pro @@ -24,7 +24,8 @@ SOURCES += \ testresultdelegate.cpp \ testtreeitemdelegate.cpp \ testsettings.cpp \ - testsettingspage.cpp + testsettingspage.cpp \ + testnavigationwidget.cpp HEADERS += \ testtreeview.h \ @@ -44,7 +45,8 @@ HEADERS += \ testresultdelegate.h \ testtreeitemdelegate.h \ testsettings.h \ - testsettingspage.h + testsettingspage.h \ + testnavigationwidget.h RESOURCES += \ autotest.qrc diff --git a/plugins/autotest/autotestplugin.cpp b/plugins/autotest/autotestplugin.cpp index 2f99db04ae..2abcebbb80 100644 --- a/plugins/autotest/autotestplugin.cpp +++ b/plugins/autotest/autotestplugin.cpp @@ -24,6 +24,7 @@ #include "testtreeview.h" #include "testtreemodel.h" #include "testresultspane.h" +#include "testnavigationwidget.h" #include #include @@ -105,7 +106,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri TestSettingsPage *settingsPage = new TestSettingsPage(m_settings); addAutoReleasedObject(settingsPage); - addAutoReleasedObject(new TestViewFactory); + addAutoReleasedObject(new TestNavigationWidgetFactory); addAutoReleasedObject(TestResultsPane::instance()); return true; diff --git a/plugins/autotest/testnavigationwidget.cpp b/plugins/autotest/testnavigationwidget.cpp new file mode 100644 index 0000000000..0f1fca7a41 --- /dev/null +++ b/plugins/autotest/testnavigationwidget.cpp @@ -0,0 +1,230 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#include "testnavigationwidget.h" +#include "testtreemodel.h" +#include "testtreeview.h" +#include "testtreeitemdelegate.h" +#include "testcodeparser.h" +#include "testrunner.h" +#include "autotestconstants.h" +#include "testtreeitem.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +namespace Autotest { +namespace Internal { + +TestNavigationWidget::TestNavigationWidget(QWidget *parent) : + QWidget(parent) +{ + setWindowTitle(tr("Tests")); + m_model = TestTreeModel::instance(); + m_sortFilterModel = new TestTreeSortFilterModel(m_model, m_model); + m_sortFilterModel->setDynamicSortFilter(true); + m_view = new TestTreeView(this); + m_view->setModel(m_sortFilterModel); + m_view->setSortingEnabled(true); + m_view->setItemDelegate(new TestTreeItemDelegate(this)); + + QVBoxLayout *layout = new QVBoxLayout; + layout->setMargin(0); + layout->setSpacing(0); + layout->addWidget(Core::ItemViewFind::createSearchableWrapper(m_view)); + setLayout(layout); + + TestCodeParser *parser = m_model->parser(); + ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance(); + connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged, + parser, &TestCodeParser::emitUpdateTestTree); + + CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); + connect(cppMM, &CppTools::CppModelManager::documentUpdated, + parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection); + connect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles, + parser, &TestCodeParser::removeFiles, Qt::QueuedConnection); + + QmlJS::ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance(); + connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated, + parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection); + connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles, + parser, &TestCodeParser::removeFiles, Qt::QueuedConnection); + + connect(m_view, &TestTreeView::activated, this, &TestNavigationWidget::onItemActivated); +} + +void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event) +{ + const bool enabled = !TestRunner::instance()->isTestRunning(); + const bool hasTests = m_model->hasTests(); + QMenu menu; + QAction *runAll = new QAction(tr("Run All Tests"), &menu); + QAction *runSelected = new QAction(tr("Run Selected Tests"), &menu); + QAction *selectAll = new QAction(tr("Select All"), &menu); + QAction *deselectAll = new QAction(tr("Deselect All"), &menu); + // TODO remove? + QAction *rescan = new QAction(tr("Rescan"), &menu); + + connect(runAll, &QAction::triggered, this, &TestNavigationWidget::onRunAllTriggered); + connect(runSelected, &QAction::triggered, this, &TestNavigationWidget::onRunSelectedTriggered); + connect(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll); + connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll); + connect(rescan, &QAction::triggered, TestTreeModel::instance()->parser(), + &TestCodeParser::updateTestTree); + + runAll->setEnabled(enabled && hasTests); + runSelected->setEnabled(enabled && hasTests); + selectAll->setEnabled(enabled && hasTests); + deselectAll->setEnabled(enabled && hasTests); + rescan->setEnabled(enabled); + + menu.addAction(runAll); + menu.addAction(runSelected); + menu.addSeparator(); + menu.addAction(selectAll); + menu.addAction(deselectAll); + menu.addSeparator(); + menu.addAction(rescan); + + menu.exec(mapToGlobal(event->pos())); +} + +QList TestNavigationWidget::createToolButtons() +{ + QList list; + + m_filterButton = new QToolButton(m_view); + m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER))); + m_filterButton->setToolTip(tr("Filter Test Tree")); + m_filterButton->setProperty("noArrow", true); + m_filterButton->setAutoRaise(true); + m_filterButton->setPopupMode(QToolButton::InstantPopup); + m_filterMenu = new QMenu(m_filterButton); + initializeFilterMenu(); + connect(m_filterMenu, &QMenu::triggered, this, &TestNavigationWidget::onFilterMenuTriggered); + m_filterButton->setMenu(m_filterMenu); + + m_sortAlphabetically = true; + m_sort = new QToolButton(this); + m_sort->setIcon((QIcon(QLatin1String(":/images/leafsort.png")))); + m_sort->setToolTip(tr("Sort Naturally")); + + QToolButton *expand = new QToolButton(this); + expand->setIcon(QIcon(QLatin1String(":/images/expand.png"))); + expand->setToolTip(tr("Expand All")); + + QToolButton *collapse = new QToolButton(this); + collapse->setIcon(QIcon(QLatin1String(":/images/collapse.png"))); + collapse->setToolTip(tr("Collapse All")); + + connect(expand, &QToolButton::clicked, m_view, &TestTreeView::expandAll); + connect(collapse, &QToolButton::clicked, m_view, &TestTreeView::collapseAll); + connect(m_sort, &QToolButton::clicked, this, &TestNavigationWidget::onSortClicked); + + list << m_filterButton << m_sort << expand << collapse; + return list; +} + +void TestNavigationWidget::onItemActivated(const QModelIndex &index) +{ + const TextEditor::TextEditorWidget::Link link + = index.data(LinkRole).value(); + if (link.hasValidTarget()) { + Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine, + link.targetColumn); + } +} + +void TestNavigationWidget::onRunAllTriggered() +{ + TestRunner *runner = TestRunner::instance(); + runner->setSelectedTests(m_model->getAllTestCases()); + runner->runTests(); +} + +void TestNavigationWidget::onRunSelectedTriggered() +{ + TestRunner *runner = TestRunner::instance(); + runner->setSelectedTests(m_model->getSelectedTests()); + runner->runTests(); +} + +void TestNavigationWidget::onSortClicked() +{ + if (m_sortAlphabetically) { + m_sort->setIcon((QIcon(QLatin1String(":/images/sort.png")))); + m_sort->setToolTip(tr("Sort Alphabetically")); + m_sortFilterModel->setSortMode(TestTreeSortFilterModel::Naturally); + } else { + m_sort->setIcon((QIcon(QLatin1String(":/images/leafsort.png")))); + m_sort->setToolTip(tr("Sort Naturally")); + m_sortFilterModel->setSortMode(TestTreeSortFilterModel::Alphabetically); + } + m_sortAlphabetically = !m_sortAlphabetically; +} + +void TestNavigationWidget::onFilterMenuTriggered(QAction *action) +{ + m_sortFilterModel->toggleFilter( + TestTreeSortFilterModel::toFilterMode(action->data().value())); +} + +void TestNavigationWidget::initializeFilterMenu() +{ + QAction *action = new QAction(m_filterMenu); + action->setText(tr("Show init and cleanup functions")); + action->setCheckable(true); + action->setChecked(false); + action->setData(TestTreeSortFilterModel::ShowInitAndCleanup); + m_filterMenu->addAction(action); + action = new QAction(m_filterMenu); + action->setText(tr("Show data functions")); + action->setCheckable(true); + action->setChecked(false); + action->setData(TestTreeSortFilterModel::ShowTestData); + m_filterMenu->addAction(action); +} + +TestNavigationWidgetFactory::TestNavigationWidgetFactory() +{ + setDisplayName(tr("Tests")); + setId(Autotest::Constants::AUTOTEST_ID); + setPriority(666); +} + +Core::NavigationView TestNavigationWidgetFactory::createWidget() +{ + TestNavigationWidget *treeViewWidget = new TestNavigationWidget; + Core::NavigationView view; + view.widget = treeViewWidget; + view.dockToolBarWidgets = treeViewWidget->createToolButtons(); + return view; +} + +} // namespace Internal +} // namespace Autotest diff --git a/plugins/autotest/testnavigationwidget.h b/plugins/autotest/testnavigationwidget.h new file mode 100644 index 0000000000..2700cf2c12 --- /dev/null +++ b/plugins/autotest/testnavigationwidget.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc +** All rights reserved. +** For any questions to Digia, please use contact form at http://qt.digia.com +** +** This file is part of the Qt Creator Enterprise Auto Test Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. +** +** If you have questions regarding the use of this file, please use +** contact form at http://qt.digia.com +** +****************************************************************************/ + +#ifndef TESTNAVIGATIONWIDGETTREEVIEW_H +#define TESTNAVIGATIONWIDGETTREEVIEW_H + +#include + +#include + +QT_BEGIN_NAMESPACE +class QAction; +class QMenu; +class QToolButton; +QT_END_NAMESPACE + +namespace Core { +class IContext; +} + +namespace Autotest { +namespace Internal { + +class TestTreeModel; +class TestTreeSortFilterModel; +class TestTreeView; + +class TestNavigationWidget : public QWidget +{ + Q_OBJECT + +public: + explicit TestNavigationWidget(QWidget *parent = 0); + void contextMenuEvent(QContextMenuEvent *event); + QList createToolButtons(); + +signals: + +public slots: + +private slots: + void onItemActivated(const QModelIndex &index); + void onRunAllTriggered(); + void onRunSelectedTriggered(); + void onSortClicked(); + void onFilterMenuTriggered(QAction *action); + +private: + void initializeFilterMenu(); + + TestTreeModel *m_model; + TestTreeSortFilterModel *m_sortFilterModel; + TestTreeView *m_view; + QToolButton *m_sort; + QToolButton *m_filterButton; + QMenu *m_filterMenu; + bool m_sortAlphabetically; + +}; + +class TestNavigationWidgetFactory : public Core::INavigationWidgetFactory +{ + Q_OBJECT + +public: + TestNavigationWidgetFactory(); + +private: + Core::NavigationView createWidget(); + +}; + +} // namespace Internal +} // namespace Autotest + +#endif // TESTNAVIGATIONWIDGETTREEVIEW_H diff --git a/plugins/autotest/testtreeview.cpp b/plugins/autotest/testtreeview.cpp index 9aa7422a94..704067a637 100644 --- a/plugins/autotest/testtreeview.cpp +++ b/plugins/autotest/testtreeview.cpp @@ -44,193 +44,6 @@ namespace Autotest { namespace Internal { -TestTreeViewWidget::TestTreeViewWidget(QWidget *parent) : - QWidget(parent) -{ - setWindowTitle(tr("Tests")); - m_model = TestTreeModel::instance(); - m_sortFilterModel = new TestTreeSortFilterModel(m_model, m_model); - m_sortFilterModel->setDynamicSortFilter(true); - m_view = new TestTreeView(this); - m_view->setModel(m_sortFilterModel); - m_view->setSortingEnabled(true); - m_view->setItemDelegate(new TestTreeItemDelegate(this)); - - QVBoxLayout *layout = new QVBoxLayout; - layout->setMargin(0); - layout->setSpacing(0); - layout->addWidget(Core::ItemViewFind::createSearchableWrapper(m_view)); - setLayout(layout); - - TestCodeParser *parser = m_model->parser(); - ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance(); - connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged, - parser, &TestCodeParser::emitUpdateTestTree); - - CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance(); - connect(cppMM, &CppTools::CppModelManager::documentUpdated, - parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection); - connect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles, - parser, &TestCodeParser::removeFiles, Qt::QueuedConnection); - - QmlJS::ModelManagerInterface *qmlJsMM = QmlJSTools::Internal::ModelManager::instance(); - connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated, - parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection); - connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles, - parser, &TestCodeParser::removeFiles, Qt::QueuedConnection); - - connect(m_view, &TestTreeView::activated, this, &TestTreeViewWidget::onItemActivated); -} - -void TestTreeViewWidget::contextMenuEvent(QContextMenuEvent *event) -{ - const bool enabled = !TestRunner::instance()->isTestRunning(); - const bool hasTests = m_model->hasTests(); - QMenu menu; - QAction *runAll = new QAction(tr("Run All Tests"), &menu); - QAction *runSelected = new QAction(tr("Run Selected Tests"), &menu); - QAction *selectAll = new QAction(tr("Select All"), &menu); - QAction *deselectAll = new QAction(tr("Deselect All"), &menu); - // TODO remove? - QAction *rescan = new QAction(tr("Rescan"), &menu); - - connect(runAll, &QAction::triggered, this, &TestTreeViewWidget::onRunAllTriggered); - connect(runSelected, &QAction::triggered, this, &TestTreeViewWidget::onRunSelectedTriggered); - connect(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll); - connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll); - connect(rescan, &QAction::triggered, - TestTreeModel::instance()->parser(), &TestCodeParser::updateTestTree); - - runAll->setEnabled(enabled && hasTests); - runSelected->setEnabled(enabled && hasTests); - selectAll->setEnabled(enabled && hasTests); - deselectAll->setEnabled(enabled && hasTests); - rescan->setEnabled(enabled); - - menu.addAction(runAll); - menu.addAction(runSelected); - menu.addSeparator(); - menu.addAction(selectAll); - menu.addAction(deselectAll); - menu.addSeparator(); - menu.addAction(rescan); - - menu.exec(mapToGlobal(event->pos())); -} - -QList TestTreeViewWidget::createToolButtons() -{ - QList list; - - m_filterButton = new QToolButton(m_view); - m_filterButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_FILTER))); - m_filterButton->setToolTip(tr("Filter Test Tree")); - m_filterButton->setProperty("noArrow", true); - m_filterButton->setAutoRaise(true); - m_filterButton->setPopupMode(QToolButton::InstantPopup); - m_filterMenu = new QMenu(m_filterButton); - initializeFilterMenu(); - connect(m_filterMenu, &QMenu::triggered, this, &TestTreeViewWidget::onFilterMenuTriggered); - m_filterButton->setMenu(m_filterMenu); - - m_sortAlphabetically = true; - m_sort = new QToolButton(this); - m_sort->setIcon((QIcon(QLatin1String(":/images/leafsort.png")))); - m_sort->setToolTip(tr("Sort Naturally")); - - QToolButton *expand = new QToolButton(this); - expand->setIcon(QIcon(QLatin1String(":/images/expand.png"))); - expand->setToolTip(tr("Expand All")); - - QToolButton *collapse = new QToolButton(this); - collapse->setIcon(QIcon(QLatin1String(":/images/collapse.png"))); - collapse->setToolTip(tr("Collapse All")); - - connect(expand, &QToolButton::clicked, m_view, &TestTreeView::expandAll); - connect(collapse, &QToolButton::clicked, m_view, &TestTreeView::collapseAll); - connect(m_sort, &QToolButton::clicked, this, &TestTreeViewWidget::onSortClicked); - - list << m_filterButton << m_sort << expand << collapse; - return list; -} - -void TestTreeViewWidget::onItemActivated(const QModelIndex &index) -{ - const TextEditor::TextEditorWidget::Link link - = index.data(LinkRole).value(); - if (link.hasValidTarget()) { - Core::EditorManager::openEditorAt(link.targetFileName, - link.targetLine, - link.targetColumn); - } -} - -void TestTreeViewWidget::onRunAllTriggered() -{ - TestRunner *runner = TestRunner::instance(); - runner->setSelectedTests(m_model->getAllTestCases()); - runner->runTests(); -} - -void TestTreeViewWidget::onRunSelectedTriggered() -{ - TestRunner *runner = TestRunner::instance(); - runner->setSelectedTests(m_model->getSelectedTests()); - runner->runTests(); -} - -void TestTreeViewWidget::onSortClicked() -{ - if (m_sortAlphabetically) { - m_sort->setIcon((QIcon(QLatin1String(":/images/sort.png")))); - m_sort->setToolTip(tr("Sort Alphabetically")); - m_sortFilterModel->setSortMode(TestTreeSortFilterModel::Naturally); - } else { - m_sort->setIcon((QIcon(QLatin1String(":/images/leafsort.png")))); - m_sort->setToolTip(tr("Sort Naturally")); - m_sortFilterModel->setSortMode(TestTreeSortFilterModel::Alphabetically); - } - m_sortAlphabetically = !m_sortAlphabetically; -} - -void TestTreeViewWidget::onFilterMenuTriggered(QAction *action) -{ - m_sortFilterModel->toggleFilter( - TestTreeSortFilterModel::toFilterMode(action->data().value())); -} - -void TestTreeViewWidget::initializeFilterMenu() -{ - QAction *action = new QAction(m_filterMenu); - action->setText(tr("Show init and cleanup functions")); - action->setCheckable(true); - action->setChecked(false); - action->setData(TestTreeSortFilterModel::ShowInitAndCleanup); - m_filterMenu->addAction(action); - action = new QAction(m_filterMenu); - action->setText(tr("Show data functions")); - action->setCheckable(true); - action->setChecked(false); - action->setData(TestTreeSortFilterModel::ShowTestData); - m_filterMenu->addAction(action); -} - -TestViewFactory::TestViewFactory() -{ - setDisplayName(tr("Tests")); - setId(Autotest::Constants::AUTOTEST_ID); - setPriority(666); -} - -Core::NavigationView TestViewFactory::createWidget() -{ - TestTreeViewWidget *treeViewWidget = new TestTreeViewWidget; - Core::NavigationView view; - view.widget = treeViewWidget; - view.dockToolBarWidgets = treeViewWidget->createToolButtons(); - return view; -} - TestTreeView::TestTreeView(QWidget *parent) : NavigationTreeView(parent), m_context(new Core::IContext(this)) diff --git a/plugins/autotest/testtreeview.h b/plugins/autotest/testtreeview.h index e9252ab136..9865e69df2 100644 --- a/plugins/autotest/testtreeview.h +++ b/plugins/autotest/testtreeview.h @@ -19,17 +19,8 @@ #ifndef TESTTREEVIEW_H #define TESTTREEVIEW_H -#include - #include -QT_BEGIN_NAMESPACE -class QAction; -class QMenu; -class QModelIndex; -class QToolButton; -QT_END_NAMESPACE - namespace Core { class IContext; } @@ -37,9 +28,6 @@ class IContext; namespace Autotest { namespace Internal { -class TestTreeModel; -class TestTreeSortFilterModel; - class TestTreeView : public Utils::NavigationTreeView { Q_OBJECT @@ -55,52 +43,6 @@ private: Core::IContext *m_context; }; - -class TestTreeViewWidget : public QWidget -{ - Q_OBJECT - -public: - explicit TestTreeViewWidget(QWidget *parent = 0); - void contextMenuEvent(QContextMenuEvent *event); - QList createToolButtons(); - -signals: - -public slots: - -private slots: - void onItemActivated(const QModelIndex &index); - void onRunAllTriggered(); - void onRunSelectedTriggered(); - void onSortClicked(); - void onFilterMenuTriggered(QAction *action); - -private: - void initializeFilterMenu(); - - TestTreeModel *m_model; - TestTreeSortFilterModel *m_sortFilterModel; - TestTreeView *m_view; - QToolButton *m_sort; - QToolButton *m_filterButton; - QMenu *m_filterMenu; - bool m_sortAlphabetically; - -}; - -class TestViewFactory : public Core::INavigationWidgetFactory -{ - Q_OBJECT - -public: - TestViewFactory(); - -private: - Core::NavigationView createWidget(); - -}; - } // namespace Internal } // namespace Autotest -- cgit v1.2.1