2014-12-18 15:02:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2015-02-19 08:09:02 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd
|
2014-12-18 15:02:07 +01:00
|
|
|
** All rights reserved.
|
2015-02-19 08:09:02 +01:00
|
|
|
** For any questions to The Qt Company, please use contact form at
|
|
|
|
|
** http://www.qt.io/contact-us
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
|
|
|
|
** 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
|
2015-02-19 08:09:02 +01:00
|
|
|
** a written agreement between you and The Qt Company.
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
|
|
|
|
** If you have questions regarding the use of this file, please use
|
2015-02-19 08:09:02 +01:00
|
|
|
** contact form at http://www.qt.io/contact-us
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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 <coreplugin/find/itemviewfind.h>
|
|
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
2015-02-17 14:45:26 +01:00
|
|
|
#include <utils/progressindicator.h>
|
2014-12-18 15:02:07 +01:00
|
|
|
|
2015-02-17 14:45:26 +01:00
|
|
|
#include <QTimer>
|
2014-12-18 15:02:07 +01:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
connect(m_view, &TestTreeView::activated, this, &TestNavigationWidget::onItemActivated);
|
2015-02-17 14:45:26 +01:00
|
|
|
|
|
|
|
|
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicator::Medium, this);
|
|
|
|
|
m_progressIndicator->attachToWidget(m_view);
|
|
|
|
|
m_progressIndicator->hide();
|
|
|
|
|
|
|
|
|
|
m_progressTimer = new QTimer(this);
|
|
|
|
|
m_progressTimer->setSingleShot(true);
|
|
|
|
|
m_progressTimer->setInterval(100); // don't display indicator if progress takes less than 100ms
|
|
|
|
|
|
|
|
|
|
connect(m_model->parser(), &TestCodeParser::parsingStarted,
|
|
|
|
|
this, &TestNavigationWidget::onParsingStarted);
|
|
|
|
|
connect(m_model->parser(), &TestCodeParser::parsingFinished,
|
|
|
|
|
this, &TestNavigationWidget::onParsingFinished);
|
|
|
|
|
connect(m_progressTimer, &QTimer::timeout,
|
2015-02-18 08:31:18 +01:00
|
|
|
m_progressIndicator, &Utils::ProgressIndicator::show);
|
2014-12-18 15:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-12 15:48:24 +01:00
|
|
|
TestNavigationWidget::~TestNavigationWidget()
|
|
|
|
|
{
|
|
|
|
|
m_model->disableParsing();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:07 +01:00
|
|
|
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<QToolButton *> TestNavigationWidget::createToolButtons()
|
|
|
|
|
{
|
|
|
|
|
QList<QToolButton *> 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<TextEditor::TextEditorWidget::Link>();
|
|
|
|
|
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<int>()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-17 14:45:26 +01:00
|
|
|
void TestNavigationWidget::onParsingStarted()
|
|
|
|
|
{
|
|
|
|
|
m_progressTimer->start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestNavigationWidget::onParsingFinished()
|
|
|
|
|
{
|
|
|
|
|
m_progressTimer->stop();
|
|
|
|
|
m_progressIndicator->hide();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:07 +01:00
|
|
|
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();
|
2015-02-12 15:48:24 +01:00
|
|
|
TestTreeModel::instance()->enableParsing();
|
2014-12-18 15:02:07 +01:00
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|