diff options
author | hjk <hjk@qt.io> | 2024-01-12 08:51:08 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2024-01-12 08:41:43 +0000 |
commit | 3e3cf3f8a4e42302dd4f1c34140e0d70410a5f70 (patch) | |
tree | 1401e8ad168e81a6bb92abd720b0d1b4791d1d3b /src/plugins/autotest | |
parent | bffd9a39b5541b85d05870a929a0d9d85fc36955 (diff) |
AutoTest: Hide plugin class definition in the .cpp
It's not meant to be accessed from the outside.
Change-Id: I0652ec8309e678a9b28e05acab6d0f77a0b13639
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Diffstat (limited to 'src/plugins/autotest')
-rw-r--r-- | src/plugins/autotest/autotestplugin.cpp | 198 | ||||
-rw-r--r-- | src/plugins/autotest/autotestplugin.h | 37 | ||||
-rw-r--r-- | src/plugins/autotest/projectsettingswidget.cpp | 2 | ||||
-rw-r--r-- | src/plugins/autotest/testresultspane.cpp | 4 | ||||
-rw-r--r-- | src/plugins/autotest/testrunner.cpp | 10 | ||||
-rw-r--r-- | src/plugins/autotest/testsettingspage.cpp | 2 | ||||
-rw-r--r-- | src/plugins/autotest/testtreemodel.cpp | 11 |
7 files changed, 127 insertions, 137 deletions
diff --git a/src/plugins/autotest/autotestplugin.cpp b/src/plugins/autotest/autotestplugin.cpp index c577ab08398..0b870f0bc0d 100644 --- a/src/plugins/autotest/autotestplugin.cpp +++ b/src/plugins/autotest/autotestplugin.cpp @@ -39,6 +39,7 @@ #include <cppeditor/cppeditorconstants.h> #include <cppeditor/cppmodelmanager.h> +#include <extensionsystem/iplugin.h> #include <extensionsystem/pluginmanager.h> #include <projectexplorer/buildmanager.h> @@ -73,8 +74,7 @@ using namespace Core; using namespace Utils; -namespace Autotest { -namespace Internal { +namespace Autotest::Internal { class AutotestPluginPrivate final : public QObject { @@ -108,24 +108,6 @@ public: static AutotestPluginPrivate *dd = nullptr; static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings; -AutotestPlugin::AutotestPlugin() -{ - // needed to be used in QueuedConnection connects - qRegisterMetaType<TestResult>(); - qRegisterMetaType<TestTreeItem *>(); - qRegisterMetaType<TestCodeLocationAndType>(); - // warm up meta type system to be able to read Qt::CheckState with persistent settings - qRegisterMetaType<Qt::CheckState>(); - - setupTestNavigationWidgetFactory(); -} - -AutotestPlugin::~AutotestPlugin() -{ - delete dd; - dd = nullptr; -} - AutotestPluginPrivate::AutotestPluginPrivate() { dd = this; // Needed as the code below access it via the static plugin interface @@ -170,7 +152,7 @@ AutotestPluginPrivate::~AutotestPluginPrivate() delete m_resultsPane; } -TestProjectSettings *AutotestPlugin::projectSettings(ProjectExplorer::Project *project) +TestProjectSettings *projectSettings(ProjectExplorer::Project *project) { auto &settings = s_projectSettings[project]; if (!settings) @@ -262,73 +244,13 @@ void AutotestPluginPrivate::initializeMenuEntries() toolsMenu->addMenu(menu); using namespace ProjectExplorer; connect(BuildManager::instance(), &BuildManager::buildStateChanged, - this, &AutotestPlugin::updateMenuItemsEnabledState); + this, &updateMenuItemsEnabledState); connect(BuildManager::instance(), &BuildManager::buildQueueFinished, - this, &AutotestPlugin::updateMenuItemsEnabledState); + this, &updateMenuItemsEnabledState); connect(ProjectExplorerPlugin::instance(), &ProjectExplorerPlugin::runActionsUpdated, - this, &AutotestPlugin::updateMenuItemsEnabledState); + this, &updateMenuItemsEnabledState); connect(&dd->m_testTreeModel, &TestTreeModel::testTreeModelChanged, - this, &AutotestPlugin::updateMenuItemsEnabledState); -} - -void AutotestPlugin::initialize() -{ - dd = new AutotestPluginPrivate; -#ifdef WITH_TESTS - ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface", - [] { return dd->m_loadProjectScenario(); }); - - addTest<AutoTestUnitTests>(&dd->m_testTreeModel); -#endif -} - -void AutotestPlugin::extensionsInitialized() -{ - ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); - if (!contextMenu) // if QC is started without CppEditor plugin - return; - - const Id menuId = "Autotest.TestUnderCursor"; - ActionContainer * const runTestMenu = ActionManager::createMenu(menuId); - runTestMenu->menu()->setTitle(Tr::tr("Run Test Under Cursor")); - contextMenu->addSeparator(); - contextMenu->addMenu(runTestMenu); - contextMenu->addSeparator(); - - ActionBuilder(this, Constants::ACTION_RUN_UCURSOR) - .setText(Tr::tr("&Run Test")) - .setEnabled(false) - .setIcon(Utils::Icons::RUN_SMALL.icon()) - .addToContainer(menuId) - .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Run); }); - - ActionBuilder(this, Constants::ACTION_RUN_UCURSOR_NODEPLOY) - .setText(Tr::tr("Run Test Without Deployment")) - .setIcon(Utils::Icons::RUN_SMALL.icon()) - .setEnabled(false) - .addToContainer(menuId) - .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::RunWithoutDeploy); }); - - ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR) - .setText(Tr::tr("&Debug Test")) - .setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon()) - .setEnabled(false) - .addToContainer(menuId) - .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Debug); }); - - ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY) - .setText(Tr::tr("Debug Test Without Deployment")) - .setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon()) - .setEnabled(false) - .addToContainer(menuId) - .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::DebugWithoutDeploy); }); -} - -ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown() -{ - dd->m_testCodeParser.aboutToShutdown(true); - dd->m_testTreeModel.disconnect(); - return SynchronousShutdown; + this, &updateMenuItemsEnabledState); } void AutotestPluginPrivate::onRunAllTriggered(TestRunMode mode) @@ -400,7 +322,7 @@ void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode) const QList<const CPlusPlus::Name *> fullName = CPlusPlus::LookupContext::fullyQualifiedName(scope); const QString funcName = CPlusPlus::Overview().prettyName(fullName); - const TestFrameworks active = AutotestPlugin::activeTestFrameworks(); + const TestFrameworks active = activeTestFrameworks(); for (auto framework : active) { const QStringList testName = framework->testNameForSymbolName(funcName); if (!testName.size()) @@ -468,7 +390,7 @@ void AutotestPluginPrivate::onDisableTemporarily(bool disable) // clear model m_testTreeModel.removeAllTestItems(); m_testTreeModel.removeAllTestToolItems(); - AutotestPlugin::updateMenuItemsEnabledState(); + updateMenuItemsEnabledState(); } else { // re-enable m_testCodeParser.setState(TestCodeParser::Idle); @@ -477,7 +399,7 @@ void AutotestPluginPrivate::onDisableTemporarily(bool disable) } } -TestFrameworks AutotestPlugin::activeTestFrameworks() +TestFrameworks activeTestFrameworks() { ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); TestFrameworks sorted; @@ -495,7 +417,7 @@ TestFrameworks AutotestPlugin::activeTestFrameworks() return sorted; } -void AutotestPlugin::updateMenuItemsEnabledState() +void updateMenuItemsEnabledState() { const ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); const ProjectExplorer::Target *target = project ? project->activeTarget() : nullptr; @@ -528,24 +450,24 @@ void AutotestPlugin::updateMenuItemsEnabledState() ActionManager::command(Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY)->action()->setEnabled(canRun); } -void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice) +void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice) { if (dd) dd->m_runconfigCache.insert(buildTargetKey, choice); } -ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey) +ChoicePair cachedChoiceFor(const QString &buildTargetKey) { return dd ? dd->m_runconfigCache.value(buildTargetKey) : ChoicePair(); } -void AutotestPlugin::clearChoiceCache() +void clearChoiceCache() { if (dd) dd->m_runconfigCache.clear(); } -void AutotestPlugin::popupResultsPane() +void popupResultsPane() { if (dd) dd->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch); @@ -556,7 +478,93 @@ bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const return rc && rc->displayName() == displayName && rc->runnable().command.executable() == executable; } -} // Internal -} // Autotest +// AutotestPlugin + +class AutotestPlugin final : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "AutoTest.json") + +public: + AutotestPlugin() + { + // needed to be used in QueuedConnection connects + qRegisterMetaType<TestResult>(); + qRegisterMetaType<TestTreeItem *>(); + qRegisterMetaType<TestCodeLocationAndType>(); + // warm up meta type system to be able to read Qt::CheckState with persistent settings + qRegisterMetaType<Qt::CheckState>(); + + setupTestNavigationWidgetFactory(); + } + + ~AutotestPlugin() final + { + delete dd; + dd = nullptr; + } + + void initialize() final + { + dd = new AutotestPluginPrivate; + #ifdef WITH_TESTS + ExtensionSystem::PluginManager::registerScenario("TestModelManagerInterface", + [] { return dd->m_loadProjectScenario(); }); + + addTest<AutoTestUnitTests>(&dd->m_testTreeModel); + #endif + } + + void extensionsInitialized() + { + ActionContainer *contextMenu = ActionManager::actionContainer(CppEditor::Constants::M_CONTEXT); + if (!contextMenu) // if QC is started without CppEditor plugin + return; + + const Id menuId = "Autotest.TestUnderCursor"; + ActionContainer * const runTestMenu = ActionManager::createMenu(menuId); + runTestMenu->menu()->setTitle(Tr::tr("Run Test Under Cursor")); + contextMenu->addSeparator(); + contextMenu->addMenu(runTestMenu); + contextMenu->addSeparator(); + + ActionBuilder(this, Constants::ACTION_RUN_UCURSOR) + .setText(Tr::tr("&Run Test")) + .setEnabled(false) + .setIcon(Utils::Icons::RUN_SMALL.icon()) + .addToContainer(menuId) + .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Run); }); + + ActionBuilder(this, Constants::ACTION_RUN_UCURSOR_NODEPLOY) + .setText(Tr::tr("Run Test Without Deployment")) + .setIcon(Utils::Icons::RUN_SMALL.icon()) + .setEnabled(false) + .addToContainer(menuId) + .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::RunWithoutDeploy); }); + + ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR) + .setText(Tr::tr("&Debug Test")) + .setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon()) + .setEnabled(false) + .addToContainer(menuId) + .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::Debug); }); + + ActionBuilder(this, Constants::ACTION_RUN_DBG_UCURSOR_NODEPLOY) + .setText(Tr::tr("Debug Test Without Deployment")) + .setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon()) + .setEnabled(false) + .addToContainer(menuId) + .addOnTriggered([] { dd->onRunUnderCursorTriggered(TestRunMode::DebugWithoutDeploy); }); + } + + ShutdownFlag aboutToShutdown() final + { + dd->m_testCodeParser.aboutToShutdown(true); + dd->m_testTreeModel.disconnect(); + return SynchronousShutdown; + } +}; + +} // Autotest::Internal #include "autotestplugin.moc" diff --git a/src/plugins/autotest/autotestplugin.h b/src/plugins/autotest/autotestplugin.h index e6daa0c7390..a70066813d9 100644 --- a/src/plugins/autotest/autotestplugin.h +++ b/src/plugins/autotest/autotestplugin.h @@ -5,8 +5,6 @@ #include "itestframework.h" -#include <extensionsystem/iplugin.h> - #include <utils/filepath.h> namespace ProjectExplorer { @@ -14,8 +12,7 @@ class Project; class RunConfiguration; } -namespace Autotest { -namespace Internal { +namespace Autotest::Internal { class TestProjectSettings; @@ -29,27 +26,13 @@ struct ChoicePair Utils::FilePath executable; }; -class AutotestPlugin : public ExtensionSystem::IPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "AutoTest.json") - -public: - AutotestPlugin(); - ~AutotestPlugin() override; - - void initialize() override; - void extensionsInitialized() override; - ShutdownFlag aboutToShutdown() override; - - static TestProjectSettings *projectSettings(ProjectExplorer::Project *project); - static TestFrameworks activeTestFrameworks(); - static void updateMenuItemsEnabledState(); - static void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice); - static ChoicePair cachedChoiceFor(const QString &buildTargetKey); - static void clearChoiceCache(); - static void popupResultsPane(); -}; +TestProjectSettings *projectSettings(ProjectExplorer::Project *project); +TestFrameworks activeTestFrameworks(); +void updateMenuItemsEnabledState(); +void cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice); +ChoicePair cachedChoiceFor(const QString &buildTargetKey); +void clearChoiceCache(); +void popupResultsPane(); + -} // namespace Internal -} // namespace Autotest +} // Autotest::Internal diff --git a/src/plugins/autotest/projectsettingswidget.cpp b/src/plugins/autotest/projectsettingswidget.cpp index 48151dea290..c5a8b410596 100644 --- a/src/plugins/autotest/projectsettingswidget.cpp +++ b/src/plugins/autotest/projectsettingswidget.cpp @@ -46,7 +46,7 @@ private: }; ProjectTestSettingsWidget::ProjectTestSettingsWidget(Project *project) - : m_projectSettings(AutotestPlugin::projectSettings(project)) + : m_projectSettings(projectSettings(project)) { setGlobalSettingsId(Constants::AUTOTEST_SETTINGS_ID); diff --git a/src/plugins/autotest/testresultspane.cpp b/src/plugins/autotest/testresultspane.cpp index 6d9eea70991..aacc1808bfe 100644 --- a/src/plugins/autotest/testresultspane.cpp +++ b/src/plugins/autotest/testresultspane.cpp @@ -513,7 +513,7 @@ void TestResultsPane::onTestRunStarted() { m_testRunning = true; m_stopTestRun->setEnabled(true); - AutotestPlugin::updateMenuItemsEnabledState(); + updateMenuItemsEnabledState(); m_summaryWidget->setVisible(false); } @@ -529,7 +529,7 @@ void TestResultsPane::onTestRunFinished() m_testRunning = false; m_stopTestRun->setEnabled(false); - AutotestPlugin::updateMenuItemsEnabledState(); + updateMenuItemsEnabledState(); updateSummaryLabel(); m_summaryWidget->setVisible(true); m_model->removeCurrentTestMessage(); diff --git a/src/plugins/autotest/testrunner.cpp b/src/plugins/autotest/testrunner.cpp index 2c49614acce..c437510bec7 100644 --- a/src/plugins/autotest/testrunner.cpp +++ b/src/plugins/autotest/testrunner.cpp @@ -225,7 +225,7 @@ static RunConfiguration *getRunConfiguration(const QString &buildTargetKey) return !rc->runnable().command.isEmpty(); }); - const ChoicePair oldChoice = AutotestPlugin::cachedChoiceFor(buildTargetKey); + const ChoicePair oldChoice = cachedChoiceFor(buildTargetKey); if (!oldChoice.executable.isEmpty()) { runConfig = Utils::findOrDefault(runConfigurations, [&oldChoice](const RunConfiguration *rc) { @@ -251,7 +251,7 @@ static RunConfiguration *getRunConfiguration(const QString &buildTargetKey) return rc->runnable().command.executable() == exe; }); if (runConfig && dialog.rememberChoice()) - AutotestPlugin::cacheRunConfigChoice(buildTargetKey, ChoicePair(dName, exe)); + cacheRunConfigChoice(buildTargetKey, ChoicePair(dName, exe)); } return runConfig; } @@ -468,7 +468,7 @@ void TestRunner::runTestsHelper() }); if (testSettings().popupOnStart()) - AutotestPlugin::popupResultsPane(); + popupResultsPane(); m_taskTree->start(); } @@ -590,7 +590,7 @@ void TestRunner::debugTests() connect(runControl, &RunControl::stopped, this, &TestRunner::onFinished); ProjectExplorerPlugin::startRunControl(runControl); if (useOutputProcessor && testSettings().popupOnStart()) - AutotestPlugin::popupResultsPane(); + popupResultsPane(); } static bool executablesEmpty() @@ -672,7 +672,7 @@ static RunAfterBuildMode runAfterBuild() if (!project->namedSettings(Constants::SK_USE_GLOBAL).isValid()) return testSettings().runAfterBuildMode(); - TestProjectSettings *projectSettings = AutotestPlugin::projectSettings(project); + TestProjectSettings *projectSettings = Internal::projectSettings(project); return projectSettings->useGlobalSettings() ? testSettings().runAfterBuildMode() : projectSettings->runAfterBuild(); } diff --git a/src/plugins/autotest/testsettingspage.cpp b/src/plugins/autotest/testsettingspage.cpp index 985206238fd..f168af2f1e4 100644 --- a/src/plugins/autotest/testsettingspage.cpp +++ b/src/plugins/autotest/testsettingspage.cpp @@ -77,7 +77,7 @@ TestSettingsWidget::TestSettingsWidget() text(Tr::tr("Reset Cached Choices")), tooltip(Tr::tr("Clear all cached choices of run configurations for " "tests where the executable could not be deduced.")), - onClicked([] { AutotestPlugin::clearChoiceCache(); }, this) + onClicked(&clearChoiceCache, this) }; TestSettings &s = Internal::testSettings(); diff --git a/src/plugins/autotest/testtreemodel.cpp b/src/plugins/autotest/testtreemodel.cpp index 85e98b7c218..073ab32213f 100644 --- a/src/plugins/autotest/testtreemodel.cpp +++ b/src/plugins/autotest/testtreemodel.cpp @@ -80,8 +80,7 @@ void TestTreeModel::setupParsingConnections() m_parser->onStartupProjectChanged(project); removeAllTestToolItems(); synchronizeTestTools(); - m_checkStateCache = project ? AutotestPlugin::projectSettings(project)->checkStateCache() - : nullptr; + m_checkStateCache = project ? projectSettings(project)->checkStateCache() : nullptr; onBuildSystemTestsUpdated(); // we may have old results if project was open before switching m_failedStateCache.clear(); if (project) { @@ -251,7 +250,7 @@ void TestTreeModel::onBuildSystemTestsUpdated() if (!testTool) return; // FIXME - const TestProjectSettings *projectSettings = AutotestPlugin::projectSettings(bs->project()); + const TestProjectSettings *projectSettings = Internal::projectSettings(bs->project()); if ((projectSettings->useGlobalSettings() && !testTool->active()) || !projectSettings->activeTestTools().contains(testTool)) { return; @@ -303,7 +302,7 @@ QList<ITestTreeItem *> TestTreeModel::testItemsByName(const QString &testName) void TestTreeModel::synchronizeTestFrameworks() { - const TestFrameworks sorted = AutotestPlugin::activeTestFrameworks(); + const TestFrameworks sorted = activeTestFrameworks(); qCDebug(LOG) << "Active frameworks sorted by priority" << sorted; const auto sortedParsers = Utils::transform(sorted, &ITestFramework::testParser); // pre-check to avoid further processing when frameworks are unchanged @@ -339,12 +338,12 @@ void TestTreeModel::synchronizeTestTools() { ProjectExplorer::Project *project = ProjectExplorer::ProjectManager::startupProject(); TestTools tools; - if (!project || AutotestPlugin::projectSettings(project)->useGlobalSettings()) { + if (!project || Internal::projectSettings(project)->useGlobalSettings()) { tools = Utils::filtered(TestFrameworkManager::registeredTestTools(), &ITestFramework::active); qCDebug(LOG) << "Active test tools" << tools; // FIXME tools aren't sorted } else { // we've got custom project settings - const TestProjectSettings *settings = AutotestPlugin::projectSettings(project); + const TestProjectSettings *settings = Internal::projectSettings(project); const QHash<ITestTool *, bool> active = settings->activeTestTools(); tools = Utils::filtered(TestFrameworkManager::registeredTestTools(), [active](ITestTool *testTool) { |