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 + +#include +#include + +#include + +namespace Autotest::Internal { + +static void linkAcceptor(const Utils::Link &link) +{ + if (link.hasValidTarget()) + Core::EditorManager::openEditorAt(link); +} + +using LinkAcceptor = std::function; + +static Core::LocatorMatcherTasks dataTagMatchers(const LinkAcceptor &acceptor) +{ + using namespace Tasking; + + Storage 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()); + 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 + +namespace Autotest::Internal { + +class DataTagLocatorFilter final : public Core::ILocatorFilter +{ +public: + DataTagLocatorFilter(); + + Core::LocatorMatcherTasks matchers() final; +}; + +} // namespace Autotest::Internal