2014-12-18 15:02:07 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
2014-12-18 15:02:07 +01:00
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-22 10:37:55 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-12-18 15:02:07 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "testnavigationwidget.h"
|
2016-06-08 12:56:25 +02:00
|
|
|
#include "testframeworkmanager.h"
|
2014-12-18 15:02:07 +01:00
|
|
|
#include "testtreemodel.h"
|
|
|
|
|
#include "testtreeview.h"
|
|
|
|
|
#include "testtreeitemdelegate.h"
|
|
|
|
|
#include "testcodeparser.h"
|
|
|
|
|
#include "testrunner.h"
|
|
|
|
|
#include "autotestconstants.h"
|
2015-11-24 15:46:51 +01:00
|
|
|
#include "autotesticons.h"
|
2014-12-18 15:02:07 +01:00
|
|
|
#include "testtreeitem.h"
|
|
|
|
|
|
2015-02-26 16:50:39 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2014-12-18 15:02:07 +01:00
|
|
|
#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>
|
2016-08-03 17:55:54 +02:00
|
|
|
#include <utils/utilsicons.h>
|
2015-03-30 07:47:07 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2017-06-15 10:43:44 +02:00
|
|
|
#include <projectexplorer/buildmanager.h>
|
2014-12-18 15:02:07 +01:00
|
|
|
|
2015-02-26 16:50:39 +01:00
|
|
|
#include <QAction>
|
|
|
|
|
#include <QMenu>
|
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));
|
|
|
|
|
|
2016-06-08 12:56:25 +02:00
|
|
|
QPalette pal;
|
|
|
|
|
pal.setColor(QPalette::Window,
|
|
|
|
|
Utils::creatorTheme()->color(Utils::Theme::InfoBarBackground));
|
|
|
|
|
pal.setColor(QPalette::WindowText,
|
|
|
|
|
Utils::creatorTheme()->color(Utils::Theme::InfoBarText));
|
|
|
|
|
m_missingFrameworksWidget = new QFrame;
|
|
|
|
|
m_missingFrameworksWidget->setPalette(pal);
|
|
|
|
|
m_missingFrameworksWidget->setAutoFillBackground(true);
|
|
|
|
|
QHBoxLayout *hLayout = new QHBoxLayout;
|
|
|
|
|
m_missingFrameworksWidget->setLayout(hLayout);
|
|
|
|
|
hLayout->addWidget(new QLabel(tr("No active test frameworks.")));
|
|
|
|
|
m_missingFrameworksWidget->setVisible(!TestFrameworkManager::instance()->hasActiveFrameworks());
|
2014-12-18 15:02:07 +01:00
|
|
|
QVBoxLayout *layout = new QVBoxLayout;
|
|
|
|
|
layout->setMargin(0);
|
|
|
|
|
layout->setSpacing(0);
|
2016-06-08 12:56:25 +02:00
|
|
|
layout->addWidget(m_missingFrameworksWidget);
|
2014-12-18 15:02:07 +01:00
|
|
|
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
|
|
|
|
2017-07-25 13:51:36 +02:00
|
|
|
m_progressIndicator = new Utils::ProgressIndicator(Utils::ProgressIndicatorSize::Medium, this);
|
2015-02-17 14:45:26 +01:00
|
|
|
m_progressIndicator->attachToWidget(m_view);
|
|
|
|
|
m_progressIndicator->hide();
|
|
|
|
|
|
|
|
|
|
m_progressTimer = new QTimer(this);
|
|
|
|
|
m_progressTimer->setSingleShot(true);
|
2016-04-01 10:20:58 +02:00
|
|
|
m_progressTimer->setInterval(1000); // don't display indicator if progress takes less than 1s
|
2015-02-17 14:45:26 +01:00
|
|
|
|
|
|
|
|
connect(m_model->parser(), &TestCodeParser::parsingStarted,
|
|
|
|
|
this, &TestNavigationWidget::onParsingStarted);
|
|
|
|
|
connect(m_model->parser(), &TestCodeParser::parsingFinished,
|
|
|
|
|
this, &TestNavigationWidget::onParsingFinished);
|
2015-07-27 13:54:27 +02:00
|
|
|
connect(m_model->parser(), &TestCodeParser::parsingFailed,
|
|
|
|
|
this, &TestNavigationWidget::onParsingFinished);
|
2016-06-08 12:56:25 +02:00
|
|
|
connect(m_model, &TestTreeModel::updatedActiveFrameworks,
|
2017-11-20 07:12:16 +01:00
|
|
|
this, [this] (int numberOfActive) {
|
2016-06-08 12:56:25 +02:00
|
|
|
m_missingFrameworksWidget->setVisible(numberOfActive == 0);
|
|
|
|
|
});
|
2015-02-17 14:45:26 +01:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestNavigationWidget::contextMenuEvent(QContextMenuEvent *event)
|
|
|
|
|
{
|
2017-06-15 10:43:44 +02:00
|
|
|
const bool enabled = !ProjectExplorer::BuildManager::isBuilding()
|
|
|
|
|
&& !TestRunner::instance()->isTestRunning()
|
2016-12-12 09:35:49 +01:00
|
|
|
&& m_model->parser()->state() == TestCodeParser::Idle;
|
2015-04-16 14:04:36 +02:00
|
|
|
|
2014-12-18 15:02:07 +01:00
|
|
|
QMenu menu;
|
2017-02-13 10:05:06 +01:00
|
|
|
QAction *runThisTest = nullptr;
|
|
|
|
|
QAction *runWithoutDeploy = nullptr;
|
|
|
|
|
QAction *debugThisTest = nullptr;
|
|
|
|
|
QAction *debugWithoutDeploy = nullptr;
|
2015-04-16 14:04:36 +02:00
|
|
|
const QModelIndexList list = m_view->selectionModel()->selectedIndexes();
|
|
|
|
|
if (list.size() == 1) {
|
|
|
|
|
const QModelIndex index = list.first();
|
|
|
|
|
QRect rect(m_view->visualRect(index));
|
|
|
|
|
if (rect.contains(event->pos())) {
|
2016-04-08 14:58:23 +02:00
|
|
|
TestTreeItem *item = static_cast<TestTreeItem *>(
|
|
|
|
|
m_model->itemForIndex(m_sortFilterModel->mapToSource(index)));
|
|
|
|
|
if (item->canProvideTestConfiguration()) {
|
2015-04-16 14:04:36 +02:00
|
|
|
runThisTest = new QAction(tr("Run This Test"), &menu);
|
|
|
|
|
runThisTest->setEnabled(enabled);
|
|
|
|
|
connect(runThisTest, &QAction::triggered,
|
2016-06-15 12:29:24 +02:00
|
|
|
this, [this] () {
|
2017-09-05 13:57:22 +02:00
|
|
|
onRunThisTestTriggered(TestRunMode::Run);
|
2016-06-15 12:29:24 +02:00
|
|
|
});
|
2016-06-27 11:07:16 +02:00
|
|
|
runWithoutDeploy = new QAction(tr("Run Without Deployment"), &menu);
|
|
|
|
|
runWithoutDeploy->setEnabled(enabled);
|
|
|
|
|
connect(runWithoutDeploy, &QAction::triggered,
|
|
|
|
|
this, [this] () {
|
2017-09-05 13:57:22 +02:00
|
|
|
onRunThisTestTriggered(TestRunMode::RunWithoutDeploy);
|
2016-06-27 11:07:16 +02:00
|
|
|
});
|
2016-06-15 12:29:24 +02:00
|
|
|
}
|
|
|
|
|
if (item->canProvideDebugConfiguration()) {
|
|
|
|
|
debugThisTest = new QAction(tr("Debug This Test"), &menu);
|
|
|
|
|
debugThisTest->setEnabled(enabled);
|
|
|
|
|
connect(debugThisTest, &QAction::triggered,
|
|
|
|
|
this, [this] () {
|
2017-09-05 13:57:22 +02:00
|
|
|
onRunThisTestTriggered(TestRunMode::Debug);
|
2016-06-15 12:29:24 +02:00
|
|
|
});
|
2016-06-27 11:07:16 +02:00
|
|
|
debugWithoutDeploy = new QAction(tr("Debug Without Deployment"), &menu);
|
|
|
|
|
debugWithoutDeploy->setEnabled(enabled);
|
|
|
|
|
connect(debugWithoutDeploy, &QAction::triggered,
|
|
|
|
|
this, [this] () {
|
2017-09-05 13:57:22 +02:00
|
|
|
onRunThisTestTriggered(TestRunMode::DebugWithoutDeploy);
|
2016-06-27 11:07:16 +02:00
|
|
|
});
|
2015-04-16 14:04:36 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-30 07:47:07 +02:00
|
|
|
QAction *runAll = Core::ActionManager::command(Constants::ACTION_RUN_ALL_ID)->action();
|
|
|
|
|
QAction *runSelected = Core::ActionManager::command(Constants::ACTION_RUN_SELECTED_ID)->action();
|
2014-12-18 15:02:07 +01:00
|
|
|
QAction *selectAll = new QAction(tr("Select All"), &menu);
|
|
|
|
|
QAction *deselectAll = new QAction(tr("Deselect All"), &menu);
|
|
|
|
|
// TODO remove?
|
2015-03-30 07:47:07 +02:00
|
|
|
QAction *rescan = Core::ActionManager::command(Constants::ACTION_SCAN_ID)->action();
|
2014-12-18 15:02:07 +01:00
|
|
|
|
|
|
|
|
connect(selectAll, &QAction::triggered, m_view, &TestTreeView::selectAll);
|
|
|
|
|
connect(deselectAll, &QAction::triggered, m_view, &TestTreeView::deselectAll);
|
|
|
|
|
|
2016-06-27 11:07:16 +02:00
|
|
|
if (runThisTest) {
|
2015-04-16 14:04:36 +02:00
|
|
|
menu.addAction(runThisTest);
|
2016-06-27 11:07:16 +02:00
|
|
|
menu.addAction(runWithoutDeploy);
|
|
|
|
|
}
|
|
|
|
|
if (debugThisTest) {
|
2016-06-15 12:29:24 +02:00
|
|
|
menu.addAction(debugThisTest);
|
2016-06-27 11:07:16 +02:00
|
|
|
menu.addAction(debugWithoutDeploy);
|
|
|
|
|
}
|
2016-06-15 12:29:24 +02:00
|
|
|
if (runThisTest || debugThisTest)
|
2015-04-16 14:04:36 +02:00
|
|
|
menu.addSeparator();
|
2016-06-15 12:29:24 +02:00
|
|
|
|
2014-12-18 15:02:07 +01:00
|
|
|
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);
|
2016-08-03 17:55:54 +02:00
|
|
|
m_filterButton->setIcon(Utils::Icons::FILTER.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
m_filterButton->setToolTip(tr("Filter Test Tree"));
|
|
|
|
|
m_filterButton->setProperty("noArrow", 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);
|
2015-11-24 15:46:51 +01:00
|
|
|
m_sort->setIcon(Icons::SORT_NATURALLY.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
m_sort->setToolTip(tr("Sort Naturally"));
|
|
|
|
|
|
|
|
|
|
QToolButton *expand = new QToolButton(this);
|
2016-08-03 17:55:54 +02:00
|
|
|
expand->setIcon(Utils::Icons::EXPAND_TOOLBAR.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
expand->setToolTip(tr("Expand All"));
|
|
|
|
|
|
|
|
|
|
QToolButton *collapse = new QToolButton(this);
|
2016-08-03 17:55:54 +02:00
|
|
|
collapse->setIcon(Utils::Icons::COLLAPSE_TOOLBAR.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
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)
|
|
|
|
|
{
|
2017-10-05 09:45:33 +02:00
|
|
|
const Utils::Link link = index.data(LinkRole).value<Utils::Link>();
|
2014-12-18 15:02:07 +01:00
|
|
|
if (link.hasValidTarget()) {
|
|
|
|
|
Core::EditorManager::openEditorAt(link.targetFileName, link.targetLine,
|
|
|
|
|
link.targetColumn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestNavigationWidget::onSortClicked()
|
|
|
|
|
{
|
|
|
|
|
if (m_sortAlphabetically) {
|
2019-04-04 14:33:08 +02:00
|
|
|
m_sort->setIcon(Utils::Icons::SORT_ALPHABETICALLY_TOOLBAR.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
m_sort->setToolTip(tr("Sort Alphabetically"));
|
2016-04-28 16:42:14 +02:00
|
|
|
m_sortFilterModel->setSortMode(TestTreeItem::Naturally);
|
2014-12-18 15:02:07 +01:00
|
|
|
} else {
|
2015-11-24 15:46:51 +01:00
|
|
|
m_sort->setIcon(Icons::SORT_NATURALLY.icon());
|
2014-12-18 15:02:07 +01:00
|
|
|
m_sort->setToolTip(tr("Sort Naturally"));
|
2016-04-28 16:42:14 +02:00
|
|
|
m_sortFilterModel->setSortMode(TestTreeItem::Alphabetically);
|
2014-12-18 15:02:07 +01:00
|
|
|
}
|
|
|
|
|
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);
|
2015-03-30 13:56:50 +02:00
|
|
|
action->setText(tr("Show Init and Cleanup Functions"));
|
2014-12-18 15:02:07 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
|
action->setChecked(false);
|
|
|
|
|
action->setData(TestTreeSortFilterModel::ShowInitAndCleanup);
|
|
|
|
|
m_filterMenu->addAction(action);
|
|
|
|
|
action = new QAction(m_filterMenu);
|
2015-03-30 13:56:50 +02:00
|
|
|
action->setText(tr("Show Data Functions"));
|
2014-12-18 15:02:07 +01:00
|
|
|
action->setCheckable(true);
|
|
|
|
|
action->setChecked(false);
|
|
|
|
|
action->setData(TestTreeSortFilterModel::ShowTestData);
|
|
|
|
|
m_filterMenu->addAction(action);
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-05 13:57:22 +02:00
|
|
|
void TestNavigationWidget::onRunThisTestTriggered(TestRunMode runMode)
|
2015-04-16 14:04:36 +02:00
|
|
|
{
|
|
|
|
|
const QModelIndexList selected = m_view->selectionModel()->selectedIndexes();
|
|
|
|
|
if (selected.isEmpty())
|
|
|
|
|
return;
|
2016-06-15 12:29:24 +02:00
|
|
|
const QModelIndex &sourceIndex = m_sortFilterModel->mapToSource(selected.first());
|
2015-04-16 14:04:36 +02:00
|
|
|
if (!sourceIndex.isValid())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TestTreeItem *item = static_cast<TestTreeItem *>(sourceIndex.internalPointer());
|
2017-09-09 16:46:43 +02:00
|
|
|
TestRunner::instance()->runTest(runMode, item);
|
2015-04-16 14:04:36 +02:00
|
|
|
}
|
|
|
|
|
|
2014-12-18 15:02:07 +01:00
|
|
|
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
|