diff options
author | Christian Stenger <christian.stenger@qt.io> | 2023-12-05 14:12:06 +0100 |
---|---|---|
committer | Christian Stenger <christian.stenger@qt.io> | 2023-12-05 14:45:00 +0000 |
commit | bc64be06d77b66cb4afd6b842bd16812925682bd (patch) | |
tree | 2ed55702ed39002edf8dc2db5712e6b567a28219 /src/plugins/autotest | |
parent | 938a230dd0f8c13ae0577b3d4359d01d873c1124 (diff) |
AutoTest: Provide locator for finding data tags
Makes it possible to jump to Qt Test data tags using the locator.
Change-Id: I9b4590b0520a59675cd05055ee07918aa0dcf08d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/autotest/autotestplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/autotest/qtest/datataglocatorfilter.cpp | 87 | ||||
-rw-r--r-- | src/plugins/autotest/qtest/datataglocatorfilter.h | 18 |
4 files changed, 108 insertions, 0 deletions
diff --git a/src/plugins/autotest/CMakeLists.txt b/src/plugins/autotest/CMakeLists.txt index fd5e51ca004..01d6c39fa4c 100644 --- a/src/plugins/autotest/CMakeLists.txt +++ b/src/plugins/autotest/CMakeLists.txt @@ -42,6 +42,7 @@ add_qtc_plugin(AutoTest itestframework.cpp itestframework.h itestparser.cpp itestparser.h projectsettingswidget.cpp projectsettingswidget.h + qtest/datataglocatorfilter.cpp qtest/datataglocatorfilter.h qtest/qttest_utils.cpp qtest/qttest_utils.h qtest/qttestconfiguration.cpp qtest/qttestconfiguration.h qtest/qttestconstants.h diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index c9b2372b0d4..ce507311696 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -21,6 +21,7 @@ #include "catch/catchtestframework.h" #include "ctest/ctesttool.h" #include "gtest/gtestframework.h" +#include "qtest/datataglocatorfilter.h" #include "qtest/qttestframework.h" #include "quick/quicktestframework.h" @@ -99,6 +100,7 @@ public: TestCodeParser m_testCodeParser; TestTreeModel m_testTreeModel{&m_testCodeParser}; TestRunner m_testRunner; + DataTagLocatorFilter m_dataTagLocatorFilter; #ifdef WITH_TESTS LoadProjectScenario m_loadProjectScenario{&m_testTreeModel}; #endif diff --git a/src/plugins/autotest/qtest/datataglocatorfilter.cpp b/src/plugins/autotest/qtest/datataglocatorfilter.cpp new file mode 100644 index 00000000000..bb0745d189e --- /dev/null +++ b/src/plugins/autotest/qtest/datataglocatorfilter.cpp @@ -0,0 +1,87 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "datataglocatorfilter.h" + +#include "qttestframework.h" + +#include "../autotesttr.h" +#include "../testtreeitem.h" + +#include <coreplugin/editormanager/editormanager.h> + +#include <projectexplorer/project.h> +#include <projectexplorer/projectmanager.h> + +#include <solutions/tasking/tasktree.h> + +namespace Autotest::Internal { + +static void linkAcceptor(const Utils::Link &link) +{ + if (link.hasValidTarget()) + Core::EditorManager::openEditorAt(link); +} + +using LinkAcceptor = std::function<void(const Utils::Link &)>; + +static Core::LocatorMatcherTasks dataTagMatchers(const LinkAcceptor &acceptor) +{ + using namespace Tasking; + + Storage<Core::LocatorStorage> storage; + + const auto onSetup = [storage, acceptor] { + const QString input = storage->input(); + const TestTreeItem *qtTestRoot = theQtTestFramework().rootNode(); + if (!qtTestRoot) + return; + + Core::LocatorFilterEntries entries; + qtTestRoot->forAllChildItems([&entries, &input, acceptor = acceptor](TestTreeItem *it) { + if (it->type() != TestTreeItem::TestDataTag) + return; + if (it->name().contains(input)) { + Core::LocatorFilterEntry entry; + entry.displayName = it->data(0, Qt::DisplayRole).toString(); + { + const TestTreeItem *parent = it->parentItem(); + if (QTC_GUARD(parent)) { + const TestTreeItem *grandParent = parent->parentItem(); + if (QTC_GUARD(grandParent)) + entry.displayExtra = grandParent->name() + "::" + parent->name(); + } + } + entry.linkForEditor = std::make_optional(it->data(0, LinkRole).value<Utils::Link>()); + entry.acceptor = [link = entry.linkForEditor, acceptor = acceptor] { + if (link) + acceptor(*link); + return Core::AcceptResult(); + }; + entries.append(entry); + } + }); + storage->reportOutput(entries); + }; + return {{Sync(onSetup), storage}}; +} + +DataTagLocatorFilter::DataTagLocatorFilter() +{ + setId("Locate Qt Test data tags"); + setDisplayName(Tr::tr("Locate Qt Test data tags")); + setDescription(Tr::tr("Locates a Qt Test data tag found inside the active project.")); + setDefaultShortcutString("qdt"); + setPriority(Medium); + using namespace ProjectExplorer; + QObject::connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, + this, [this] { setEnabled(ProjectManager::startupProject()); }); + setEnabled(ProjectManager::startupProject()); +} + +Core::LocatorMatcherTasks DataTagLocatorFilter::matchers() +{ + return dataTagMatchers(&linkAcceptor); +} + +} // namespace Autotest::Internal diff --git a/src/plugins/autotest/qtest/datataglocatorfilter.h b/src/plugins/autotest/qtest/datataglocatorfilter.h new file mode 100644 index 00000000000..2900efe432e --- /dev/null +++ b/src/plugins/autotest/qtest/datataglocatorfilter.h @@ -0,0 +1,18 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#pragma once + +#include <coreplugin/locator/ilocatorfilter.h> + +namespace Autotest::Internal { + +class DataTagLocatorFilter final : public Core::ILocatorFilter +{ +public: + DataTagLocatorFilter(); + + Core::LocatorMatcherTasks matchers() final; +}; + +} // namespace Autotest::Internal |