2014-10-07 12:30:54 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-07 12:30:54 +02:00
|
|
|
**
|
2016-01-22 10:37:55 +01:00
|
|
|
** This file is part of Qt Creator.
|
2014-10-07 12:30:54 +02: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-10-07 12:30:54 +02: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-10-07 12:30:54 +02: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-10-07 12:30:54 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2014-11-11 17:30:34 +01:00
|
|
|
#include "autotestconstants.h"
|
2016-02-01 15:12:10 +01:00
|
|
|
#include "autotestplugin.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testcodeparser.h"
|
2016-06-01 16:22:50 +02:00
|
|
|
#include "testframeworkmanager.h"
|
2016-02-01 15:12:10 +01:00
|
|
|
#include "testsettings.h"
|
2014-10-07 12:30:54 +02:00
|
|
|
#include "testtreeitem.h"
|
|
|
|
|
#include "testtreemodel.h"
|
|
|
|
|
|
2014-10-21 13:10:37 +02:00
|
|
|
#include <cpptools/cppmodelmanager.h>
|
2014-10-07 15:51:02 +02:00
|
|
|
#include <projectexplorer/project.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
2015-02-12 15:48:24 +01:00
|
|
|
#include <qmljs/qmljsmodelmanagerinterface.h>
|
2014-10-21 13:10:37 +02:00
|
|
|
#include <texteditor/texteditor.h>
|
2015-04-27 16:11:28 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2014-10-21 13:10:37 +02:00
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
namespace Autotest {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
TestTreeModel::TestTreeModel(QObject *parent) :
|
2016-06-24 09:36:42 +02:00
|
|
|
TreeModel<>(parent),
|
2016-09-29 12:15:43 +02:00
|
|
|
m_parser(new TestCodeParser(this))
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2016-01-25 13:05:12 +01:00
|
|
|
connect(m_parser, &TestCodeParser::aboutToPerformFullParse, this,
|
2015-02-13 15:44:18 +01:00
|
|
|
&TestTreeModel::removeAllTestItems, Qt::QueuedConnection);
|
2016-02-03 15:59:59 +01:00
|
|
|
connect(m_parser, &TestCodeParser::testParseResultReady,
|
|
|
|
|
this, &TestTreeModel::onParseResultReady, Qt::QueuedConnection);
|
2016-01-25 13:05:12 +01:00
|
|
|
connect(m_parser, &TestCodeParser::parsingFinished,
|
|
|
|
|
this, &TestTreeModel::sweep, Qt::QueuedConnection);
|
|
|
|
|
connect(m_parser, &TestCodeParser::parsingFailed,
|
|
|
|
|
this, &TestTreeModel::sweep, Qt::QueuedConnection);
|
2016-12-12 09:35:49 +01:00
|
|
|
setupParsingConnections();
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static TestTreeModel *m_instance = 0;
|
|
|
|
|
|
|
|
|
|
TestTreeModel *TestTreeModel::instance()
|
|
|
|
|
{
|
|
|
|
|
if (!m_instance)
|
|
|
|
|
m_instance = new TestTreeModel;
|
|
|
|
|
return m_instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeModel::~TestTreeModel()
|
|
|
|
|
{
|
2016-06-06 15:35:00 +02:00
|
|
|
foreach (Utils::TreeItem *item, rootItem()->children()) {
|
|
|
|
|
item->removeChildren();
|
|
|
|
|
takeItem(item); // do NOT delete the item as it's still a ptr hold by TestFrameworkManager
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
m_instance = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 15:12:10 +01:00
|
|
|
void TestTreeModel::setupParsingConnections()
|
|
|
|
|
{
|
2015-07-27 13:54:27 +02:00
|
|
|
if (!m_connectionsInitialized)
|
|
|
|
|
m_parser->setDirty();
|
|
|
|
|
|
2015-02-19 11:19:59 +01:00
|
|
|
m_parser->setState(TestCodeParser::Idle);
|
2015-02-12 15:48:24 +01:00
|
|
|
if (m_connectionsInitialized)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ProjectExplorer::SessionManager *sm = ProjectExplorer::SessionManager::instance();
|
|
|
|
|
connect(sm, &ProjectExplorer::SessionManager::startupProjectChanged,
|
2015-07-27 10:44:14 +02:00
|
|
|
m_parser, &TestCodeParser::onStartupProjectChanged);
|
2015-02-12 15:48:24 +01:00
|
|
|
|
|
|
|
|
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
|
|
|
|
|
connect(cppMM, &CppTools::CppModelManager::documentUpdated,
|
|
|
|
|
m_parser, &TestCodeParser::onCppDocumentUpdated, Qt::QueuedConnection);
|
|
|
|
|
connect(cppMM, &CppTools::CppModelManager::aboutToRemoveFiles,
|
2016-01-25 13:05:12 +01:00
|
|
|
this, &TestTreeModel::removeFiles, Qt::QueuedConnection);
|
2015-04-02 12:16:55 +02:00
|
|
|
connect(cppMM, &CppTools::CppModelManager::projectPartsUpdated,
|
|
|
|
|
m_parser, &TestCodeParser::onProjectPartsUpdated);
|
2015-02-12 15:48:24 +01:00
|
|
|
|
|
|
|
|
QmlJS::ModelManagerInterface *qmlJsMM = QmlJS::ModelManagerInterface::instance();
|
|
|
|
|
connect(qmlJsMM, &QmlJS::ModelManagerInterface::documentUpdated,
|
|
|
|
|
m_parser, &TestCodeParser::onQmlDocumentUpdated, Qt::QueuedConnection);
|
|
|
|
|
connect(qmlJsMM, &QmlJS::ModelManagerInterface::aboutToRemoveFiles,
|
2016-01-25 13:05:12 +01:00
|
|
|
this, &TestTreeModel::removeFiles, Qt::QueuedConnection);
|
2015-02-12 15:48:24 +01:00
|
|
|
m_connectionsInitialized = true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
bool TestTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2015-09-10 10:57:15 +02:00
|
|
|
TestTreeItem *item = static_cast<TestTreeItem *>(index.internalPointer());
|
|
|
|
|
if (item && item->setData(index.column(), value, role)) {
|
|
|
|
|
emit dataChanged(index, index);
|
|
|
|
|
if (role == Qt::CheckStateRole) {
|
|
|
|
|
switch (item->type()) {
|
2016-02-23 15:56:52 +01:00
|
|
|
case TestTreeItem::TestCase:
|
2015-09-10 10:57:15 +02:00
|
|
|
if (item->childCount() > 0)
|
2014-10-07 12:30:54 +02:00
|
|
|
emit dataChanged(index.child(0, 0), index.child(item->childCount() - 1, 0));
|
|
|
|
|
break;
|
2016-02-23 15:56:52 +01:00
|
|
|
case TestTreeItem::TestFunctionOrSet:
|
2014-10-07 12:30:54 +02:00
|
|
|
emit dataChanged(index.parent(), index.parent());
|
|
|
|
|
break;
|
|
|
|
|
default: // avoid warning regarding unhandled enum member
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-09-10 10:57:15 +02:00
|
|
|
return true;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags TestTreeModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
|
|
|
|
|
2015-09-10 15:32:12 +02:00
|
|
|
TestTreeItem *item = static_cast<TestTreeItem *>(itemForIndex(index));
|
2016-04-28 16:42:14 +02:00
|
|
|
return item->flags(index.column());
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeModel::hasTests() const
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (Utils::TreeItem *frameworkRoot, rootItem()->children()) {
|
|
|
|
|
if (frameworkRoot->hasChildren())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2014-10-07 12:30:54 +02:00
|
|
|
}
|
|
|
|
|
|
2014-10-07 15:51:02 +02:00
|
|
|
QList<TestConfiguration *> TestTreeModel::getAllTestCases() const
|
|
|
|
|
{
|
|
|
|
|
QList<TestConfiguration *> result;
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (Utils::TreeItem *frameworkRoot, rootItem()->children())
|
|
|
|
|
result.append(static_cast<TestTreeItem *>(frameworkRoot)->getAllTestConfigurations());
|
2014-10-07 15:51:02 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
|
|
|
|
|
{
|
|
|
|
|
QList<TestConfiguration *> result;
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (Utils::TreeItem *frameworkRoot, rootItem()->children())
|
|
|
|
|
result.append(static_cast<TestTreeItem *>(frameworkRoot)->getSelectedTestConfigurations());
|
2014-10-07 15:51:02 +02:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
void TestTreeModel::syncTestFrameworks()
|
2015-02-05 16:07:45 +01:00
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
// remove all currently registered
|
2016-06-06 15:35:00 +02:00
|
|
|
foreach (Utils::TreeItem *item, rootItem()->children()) {
|
|
|
|
|
item->removeChildren();
|
|
|
|
|
takeItem(item); // do NOT delete the item as it's still a ptr hold by TestFrameworkManager
|
|
|
|
|
}
|
2015-02-05 16:07:45 +01:00
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
TestFrameworkManager *frameworkManager = TestFrameworkManager::instance();
|
2016-06-06 15:35:00 +02:00
|
|
|
QVector<Core::Id> sortedIds = frameworkManager->sortedActiveFrameworkIds();
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (const Core::Id &id, sortedIds)
|
|
|
|
|
rootItem()->appendChild(frameworkManager->rootNodeForTestFramework(id));
|
|
|
|
|
|
|
|
|
|
m_parser->syncTestFrameworks(sortedIds);
|
2016-06-08 12:56:25 +02:00
|
|
|
emit updatedActiveFrameworks(sortedIds.size());
|
2014-11-06 16:01:06 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-25 13:05:12 +01:00
|
|
|
void TestTreeModel::removeFiles(const QStringList &files)
|
2014-10-07 12:30:54 +02:00
|
|
|
{
|
2016-01-25 13:05:12 +01:00
|
|
|
foreach (const QString &file, files)
|
|
|
|
|
markForRemoval(file);
|
|
|
|
|
sweep();
|
2015-12-07 15:18:25 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-26 13:52:45 +01:00
|
|
|
void TestTreeModel::markAllForRemoval()
|
|
|
|
|
{
|
2016-06-06 14:18:38 +02:00
|
|
|
foreach (Utils::TreeItem *frameworkRoot, rootItem()->children()) {
|
|
|
|
|
foreach (Utils::TreeItem *item, frameworkRoot->children())
|
|
|
|
|
static_cast<TestTreeItem *>(item)->markForRemovalRecursively(true);
|
|
|
|
|
}
|
2016-01-26 13:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeModel::markForRemoval(const QString &filePath)
|
|
|
|
|
{
|
|
|
|
|
if (filePath.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
2016-06-06 14:18:38 +02:00
|
|
|
for (Utils::TreeItem *frameworkRoot : rootItem()->children()) {
|
|
|
|
|
TestTreeItem *root = static_cast<TestTreeItem *>(frameworkRoot);
|
2016-01-26 13:52:45 +01:00
|
|
|
for (int childRow = root->childCount() - 1; childRow >= 0; --childRow) {
|
|
|
|
|
TestTreeItem *child = root->childItem(childRow);
|
2016-04-28 16:42:14 +02:00
|
|
|
child->markForRemovalRecursively(filePath);
|
2016-01-26 13:52:45 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeModel::sweep()
|
|
|
|
|
{
|
2016-06-06 14:18:38 +02:00
|
|
|
for (Utils::TreeItem *frameworkRoot : rootItem()->children()) {
|
|
|
|
|
TestTreeItem *root = static_cast<TestTreeItem *>(frameworkRoot);
|
2016-02-29 11:14:40 +01:00
|
|
|
sweepChildren(root);
|
2016-01-26 13:52:45 +01:00
|
|
|
}
|
2016-02-29 11:14:40 +01:00
|
|
|
// even if nothing has changed by the sweeping we might had parse which added or modified items
|
|
|
|
|
emit testTreeModelChanged();
|
2016-02-10 10:43:31 +01:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
if (m_parser->state() == TestCodeParser::Idle && !m_parser->furtherParsingExpected())
|
|
|
|
|
emit sweepingDone();
|
|
|
|
|
#endif
|
2016-01-26 13:52:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @note after calling this function emit testTreeModelChanged() if it returns true
|
|
|
|
|
*/
|
|
|
|
|
bool TestTreeModel::sweepChildren(TestTreeItem *item)
|
|
|
|
|
{
|
|
|
|
|
bool hasChanged = false;
|
|
|
|
|
for (int row = item->childCount() - 1; row >= 0; --row) {
|
|
|
|
|
TestTreeItem *child = item->childItem(row);
|
|
|
|
|
|
|
|
|
|
if (child->parentItem()->type() != TestTreeItem::Root && child->markedForRemoval()) {
|
2016-07-04 15:53:53 +02:00
|
|
|
destroyItem(child);
|
2016-01-26 13:52:45 +01:00
|
|
|
hasChanged = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (bool noEndNode = child->hasChildren()) {
|
|
|
|
|
hasChanged |= sweepChildren(child);
|
|
|
|
|
if (noEndNode && child->childCount() == 0) {
|
2016-07-04 15:53:53 +02:00
|
|
|
destroyItem(child);
|
2016-01-26 13:52:45 +01:00
|
|
|
hasChanged = true;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-04 11:56:56 +01:00
|
|
|
hasChanged |= child->newlyAdded();
|
2016-01-26 13:52:45 +01:00
|
|
|
child->markForRemoval(false);
|
|
|
|
|
}
|
|
|
|
|
return hasChanged;
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 12:44:56 +02:00
|
|
|
void TestTreeModel::onParseResultReady(const TestParseResultPtr result)
|
2016-02-03 15:59:59 +01:00
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
TestTreeItem *rootNode
|
|
|
|
|
= TestFrameworkManager::instance()->rootNodeForTestFramework(result->frameworkId);
|
2016-05-09 10:27:47 +02:00
|
|
|
QTC_ASSERT(rootNode, return);
|
|
|
|
|
handleParseResult(result.data(), rootNode);
|
2016-02-03 15:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
2016-05-09 10:27:47 +02:00
|
|
|
void TestTreeModel::handleParseResult(const TestParseResult *result, TestTreeItem *parentNode)
|
2016-02-08 15:56:07 +01:00
|
|
|
{
|
2016-05-09 10:27:47 +02:00
|
|
|
// lookup existing items
|
|
|
|
|
if (TestTreeItem *toBeModified = parentNode->find(result)) {
|
|
|
|
|
// found existing item... Do not remove
|
|
|
|
|
toBeModified->markForRemoval(false);
|
|
|
|
|
// modify and when content has changed inform ui
|
|
|
|
|
if (toBeModified->modify(result)) {
|
|
|
|
|
const QModelIndex &idx = indexForItem(toBeModified);
|
|
|
|
|
emit dataChanged(idx, idx);
|
2016-02-08 15:56:07 +01:00
|
|
|
}
|
2016-05-09 10:27:47 +02:00
|
|
|
// recursively handle children of this item
|
|
|
|
|
foreach (const TestParseResult *child, result->children)
|
|
|
|
|
handleParseResult(child, toBeModified);
|
2016-04-11 14:50:04 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// if there's no matching item, add the new one
|
2016-05-09 10:27:47 +02:00
|
|
|
TestTreeItem *newItem = result->createTestTreeItem();
|
|
|
|
|
QTC_ASSERT(newItem, return);
|
|
|
|
|
parentNode->appendChild(newItem);
|
2016-02-08 15:56:07 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-05 16:07:45 +01:00
|
|
|
void TestTreeModel::removeAllTestItems()
|
2014-11-06 16:01:06 +01:00
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (Utils::TreeItem *item, rootItem()->children())
|
|
|
|
|
item->removeChildren();
|
2014-11-06 16:01:06 +01:00
|
|
|
emit testTreeModelChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
// we're inside tests - so use some internal knowledge to make testing easier
|
|
|
|
|
TestTreeItem *qtRootNode()
|
2015-02-05 16:07:45 +01:00
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
return TestFrameworkManager::instance()->rootNodeForTestFramework(
|
|
|
|
|
Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtTest"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *quickRootNode()
|
|
|
|
|
{
|
|
|
|
|
return TestFrameworkManager::instance()->rootNodeForTestFramework(
|
|
|
|
|
Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("QtQuickTest"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *gtestRootNode()
|
|
|
|
|
{
|
|
|
|
|
return TestFrameworkManager::instance()->rootNodeForTestFramework(
|
|
|
|
|
Core::Id(Constants::FRAMEWORK_PREFIX).withSuffix("GTest"));
|
2015-02-05 16:07:45 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-10 14:20:43 +01:00
|
|
|
int TestTreeModel::autoTestsCount() const
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
TestTreeItem *rootNode = qtRootNode();
|
|
|
|
|
return rootNode ? rootNode->childCount() : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeModel::hasUnnamedQuickTests(const TestTreeItem *rootNode) const
|
|
|
|
|
{
|
|
|
|
|
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
|
|
|
|
|
if (rootNode->childItem(row)->name().isEmpty())
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeItem *TestTreeModel::unnamedQuickTests() const
|
|
|
|
|
{
|
|
|
|
|
TestTreeItem *rootNode = quickRootNode();
|
|
|
|
|
if (!rootNode)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
|
|
|
|
|
TestTreeItem *child = rootNode->childItem(row);
|
|
|
|
|
if (child->name().isEmpty())
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2015-02-10 14:20:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TestTreeModel::namedQuickTestsCount() const
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
TestTreeItem *rootNode = quickRootNode();
|
|
|
|
|
return rootNode
|
|
|
|
|
? rootNode->childCount() - (hasUnnamedQuickTests(rootNode) ? 1 : 0)
|
2015-02-10 14:20:43 +01:00
|
|
|
: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TestTreeModel::unnamedQuickTestsCount() const
|
|
|
|
|
{
|
|
|
|
|
if (TestTreeItem *unnamed = unnamedQuickTests())
|
|
|
|
|
return unnamed->childCount();
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-11-02 11:06:19 +01:00
|
|
|
|
|
|
|
|
int TestTreeModel::dataTagsCount() const
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
TestTreeItem *rootNode = qtRootNode();
|
|
|
|
|
if (!rootNode)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2015-11-02 11:06:19 +01:00
|
|
|
int dataTagCount = 0;
|
2016-06-01 16:22:50 +02:00
|
|
|
foreach (Utils::TreeItem *item, rootNode->children()) {
|
2015-11-02 11:06:19 +01:00
|
|
|
TestTreeItem *classItem = static_cast<TestTreeItem *>(item);
|
|
|
|
|
foreach (Utils::TreeItem *functionItem, classItem->children())
|
|
|
|
|
dataTagCount += functionItem->childCount();
|
|
|
|
|
}
|
|
|
|
|
return dataTagCount;
|
|
|
|
|
}
|
2015-12-10 13:46:04 +01:00
|
|
|
|
|
|
|
|
int TestTreeModel::gtestNamesCount() const
|
|
|
|
|
{
|
2016-06-01 16:22:50 +02:00
|
|
|
TestTreeItem *rootNode = gtestRootNode();
|
|
|
|
|
return rootNode ? rootNode->childCount() : 0;
|
2015-12-10 13:46:04 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-13 09:10:11 +01:00
|
|
|
QMultiMap<QString, int> TestTreeModel::gtestNamesAndSets() const
|
2015-12-10 13:46:04 +01:00
|
|
|
{
|
2016-01-13 09:10:11 +01:00
|
|
|
QMultiMap<QString, int> result;
|
2015-12-10 13:46:04 +01:00
|
|
|
|
2016-06-01 16:22:50 +02:00
|
|
|
if (TestTreeItem *rootNode = gtestRootNode()) {
|
|
|
|
|
for (int row = 0, count = rootNode->childCount(); row < count; ++row) {
|
|
|
|
|
const TestTreeItem *current = rootNode->childItem(row);
|
2015-12-10 13:46:04 +01:00
|
|
|
result.insert(current->name(), current->childCount());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2015-02-10 14:20:43 +01:00
|
|
|
#endif
|
|
|
|
|
|
2014-11-11 17:30:34 +01:00
|
|
|
/***************************** Sort/Filter Model **********************************/
|
|
|
|
|
|
|
|
|
|
TestTreeSortFilterModel::TestTreeSortFilterModel(TestTreeModel *sourceModel, QObject *parent)
|
|
|
|
|
: QSortFilterProxyModel(parent),
|
2016-09-29 12:15:43 +02:00
|
|
|
m_sourceModel(sourceModel)
|
2014-11-11 17:30:34 +01:00
|
|
|
{
|
|
|
|
|
setSourceModel(sourceModel);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
void TestTreeSortFilterModel::setSortMode(TestTreeItem::SortMode sortMode)
|
2014-11-11 17:30:34 +01:00
|
|
|
{
|
|
|
|
|
m_sortMode = sortMode;
|
|
|
|
|
invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeSortFilterModel::setFilterMode(FilterMode filterMode)
|
|
|
|
|
{
|
|
|
|
|
m_filterMode = filterMode;
|
|
|
|
|
invalidateFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestTreeSortFilterModel::toggleFilter(FilterMode filterMode)
|
|
|
|
|
{
|
|
|
|
|
m_filterMode = toFilterMode(m_filterMode ^ filterMode);
|
|
|
|
|
invalidateFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TestTreeSortFilterModel::FilterMode TestTreeSortFilterModel::toFilterMode(int f)
|
|
|
|
|
{
|
|
|
|
|
switch (f) {
|
|
|
|
|
case TestTreeSortFilterModel::ShowInitAndCleanup:
|
|
|
|
|
return TestTreeSortFilterModel::ShowInitAndCleanup;
|
|
|
|
|
case TestTreeSortFilterModel::ShowTestData:
|
|
|
|
|
return TestTreeSortFilterModel::ShowTestData;
|
|
|
|
|
case TestTreeSortFilterModel::ShowAll:
|
|
|
|
|
return TestTreeSortFilterModel::ShowAll;
|
|
|
|
|
default:
|
|
|
|
|
return TestTreeSortFilterModel::Basic;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeSortFilterModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
|
|
|
|
|
{
|
2016-04-28 16:42:14 +02:00
|
|
|
// root items keep the intended order
|
2014-11-11 17:30:34 +01:00
|
|
|
const TestTreeItem *leftItem = static_cast<TestTreeItem *>(left.internalPointer());
|
2015-12-07 08:26:54 +01:00
|
|
|
if (leftItem->type() == TestTreeItem::Root)
|
2014-11-11 17:30:34 +01:00
|
|
|
return left.row() > right.row();
|
|
|
|
|
|
2016-04-28 16:42:14 +02:00
|
|
|
const TestTreeItem *rightItem = static_cast<TestTreeItem *>(right.internalPointer());
|
|
|
|
|
return leftItem->lessThan(rightItem, m_sortMode);
|
2014-11-11 17:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TestTreeSortFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
|
|
|
|
|
{
|
|
|
|
|
QModelIndex index = m_sourceModel->index(sourceRow, 0,sourceParent);
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return false;
|
|
|
|
|
|
2014-11-13 12:31:58 +01:00
|
|
|
const TestTreeItem *item = static_cast<TestTreeItem *>(index.internalPointer());
|
2014-11-11 17:30:34 +01:00
|
|
|
|
2014-11-13 12:31:58 +01:00
|
|
|
switch (item->type()) {
|
2015-12-07 08:26:54 +01:00
|
|
|
case TestTreeItem::TestDataFunction:
|
2014-11-13 12:31:58 +01:00
|
|
|
return m_filterMode & ShowTestData;
|
2015-12-07 08:26:54 +01:00
|
|
|
case TestTreeItem::TestSpecialFunction:
|
2014-11-13 12:31:58 +01:00
|
|
|
return m_filterMode & ShowInitAndCleanup;
|
|
|
|
|
default:
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-11 17:30:34 +01:00
|
|
|
}
|
|
|
|
|
|
2014-10-07 12:30:54 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Autotest
|