AutoTest: Pimpl plugin

Change-Id: I36c1ec242e29b9d06c1c2304960b445833fb9ebb
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2019-08-19 09:33:14 +02:00
parent d12f90047a
commit df93c6c5a7
2 changed files with 87 additions and 65 deletions

View File

@@ -67,6 +67,7 @@
#include <QAction> #include <QAction>
#include <QList> #include <QList>
#include <QMap>
#include <QMessageBox> #include <QMessageBox>
#include <QMainWindow> #include <QMainWindow>
#include <QMenu> #include <QMenu>
@@ -77,9 +78,32 @@
#include "autotestunittests.h" #include "autotestunittests.h"
#endif #endif
using namespace Autotest::Internal;
using namespace Core; using namespace Core;
namespace Autotest {
namespace Internal {
class AutotestPluginPrivate : public QObject
{
Q_OBJECT
public:
explicit AutotestPluginPrivate(AutotestPlugin *parent);
~AutotestPluginPrivate() override;
AutotestPlugin *q = nullptr;
TestFrameworkManager *m_frameworkManager = nullptr;
TestSettingsPage *m_testSettingPage = nullptr;
TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr;
TestResultsPane *m_resultsPane = nullptr;
QMap<QString, ChoicePair> m_runconfigCache;
void initializeMenuEntries();
void onRunAllTriggered();
void onRunSelectedTriggered();
void onRunFileTriggered();
void onRunUnderCursorTriggered(TestRunMode mode);
};
static AutotestPlugin *s_instance = nullptr; static AutotestPlugin *s_instance = nullptr;
static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings; static QHash<ProjectExplorer::Project *, TestProjectSettings *> s_projectSettings;
@@ -95,6 +119,45 @@ AutotestPlugin::AutotestPlugin()
} }
AutotestPlugin::~AutotestPlugin() AutotestPlugin::~AutotestPlugin()
{
delete d;
}
AutotestPluginPrivate::AutotestPluginPrivate(AutotestPlugin *parent)
: q(parent)
{
m_frameworkManager = TestFrameworkManager::instance();
initializeMenuEntries();
m_frameworkManager->registerTestFramework(new QtTestFramework);
m_frameworkManager->registerTestFramework(new QuickTestFramework);
m_frameworkManager->registerTestFramework(new GTestFramework);
m_frameworkManager->registerTestFramework(new BoostTestFramework);
m_frameworkManager->synchronizeSettings(ICore::settings());
m_testSettingPage = new TestSettingsPage(q->settings());
m_navigationWidgetFactory = new TestNavigationWidgetFactory;
m_resultsPane = TestResultsPane::instance();
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
panelFactory->setPriority(666);
// panelFactory->setIcon(); // TODO ?
panelFactory->setDisplayName(tr("Testing"));
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
return new ProjectTestSettingsWidget(project);
});
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
m_frameworkManager->activateFrameworksFromSettings(q->settings());
TestTreeModel::instance()->scheduleTestFrameworksSync(true);
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged, this, [this] {
m_runconfigCache.clear();
});
}
AutotestPluginPrivate::~AutotestPluginPrivate()
{ {
delete m_navigationWidgetFactory; delete m_navigationWidgetFactory;
delete m_resultsPane; delete m_resultsPane;
@@ -116,7 +179,7 @@ TestProjectSettings *AutotestPlugin::projectSettings(ProjectExplorer::Project *p
return settings; return settings;
} }
void AutotestPlugin::initializeMenuEntries() void AutotestPluginPrivate::initializeMenuEntries()
{ {
ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID); ActionContainer *menu = ActionManager::createMenu(Constants::MENU_ID);
menu->menu()->setTitle(tr("&Tests")); menu->menu()->setTitle(tr("&Tests"));
@@ -128,7 +191,7 @@ void AutotestPlugin::initializeMenuEntries()
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_ID); Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_ALL_ID);
command->setDefaultKeySequence( command->setDefaultKeySequence(
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+A") : tr("Alt+Shift+T,Alt+A"))); QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+A") : tr("Alt+Shift+T,Alt+A")));
connect(action, &QAction::triggered, this, &AutotestPlugin::onRunAllTriggered); connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunAllTriggered);
action->setEnabled(false); action->setEnabled(false);
menu->addAction(command); menu->addAction(command);
@@ -141,7 +204,7 @@ void AutotestPlugin::initializeMenuEntries()
command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_ID); command = ActionManager::registerAction(action, Constants::ACTION_RUN_SELECTED_ID);
command->setDefaultKeySequence( command->setDefaultKeySequence(
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+R") : tr("Alt+Shift+T,Alt+R"))); QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+R") : tr("Alt+Shift+T,Alt+R")));
connect(action, &QAction::triggered, this, &AutotestPlugin::onRunSelectedTriggered); connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunSelectedTriggered);
action->setEnabled(false); action->setEnabled(false);
menu->addAction(command); menu->addAction(command);
@@ -154,7 +217,7 @@ void AutotestPlugin::initializeMenuEntries()
command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID); command = ActionManager::registerAction(action, Constants::ACTION_RUN_FILE_ID);
command->setDefaultKeySequence( command->setDefaultKeySequence(
QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+F") : tr("Alt+Shift+T,Alt+F"))); QKeySequence(useMacShortcuts ? tr("Ctrl+Meta+T, Ctrl+Meta+F") : tr("Alt+Shift+T,Alt+F")));
connect(action, &QAction::triggered, this, &AutotestPlugin::onRunFileTriggered); connect(action, &QAction::triggered, this, &AutotestPluginPrivate::onRunFileTriggered);
action->setEnabled(false); action->setEnabled(false);
menu->addAction(command); menu->addAction(command);
@@ -185,39 +248,7 @@ bool AutotestPlugin::initialize(const QStringList &arguments, QString *errorStri
Q_UNUSED(arguments) Q_UNUSED(arguments)
Q_UNUSED(errorString) Q_UNUSED(errorString)
m_frameworkManager = TestFrameworkManager::instance(); d = new AutotestPluginPrivate(this);
initializeMenuEntries();
m_frameworkManager->registerTestFramework(new QtTestFramework);
m_frameworkManager->registerTestFramework(new QuickTestFramework);
m_frameworkManager->registerTestFramework(new GTestFramework);
m_frameworkManager->registerTestFramework(new BoostTestFramework);
m_frameworkManager->synchronizeSettings(ICore::settings());
m_testSettingPage = new TestSettingsPage(m_settings);
m_navigationWidgetFactory = new TestNavigationWidgetFactory;
m_resultsPane = TestResultsPane::instance();
auto panelFactory = new ProjectExplorer::ProjectPanelFactory();
panelFactory->setPriority(666);
// panelFactory->setIcon(); // TODO ?
panelFactory->setDisplayName(tr("Testing"));
panelFactory->setCreateWidgetFunction([](ProjectExplorer::Project *project) {
return new ProjectTestSettingsWidget(project);
});
ProjectExplorer::ProjectPanelFactory::registerFactory(panelFactory);
m_frameworkManager->activateFrameworksFromSettings(m_settings);
TestTreeModel::instance()->scheduleTestFrameworksSync(true);
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::startupProjectChanged, this, [this] {
m_runconfigCache.clear();
});
connect(ProjectExplorer::SessionManager::instance(),
&ProjectExplorer::SessionManager::aboutToRemoveProject,
this, [] (ProjectExplorer::Project *project) {
delete s_projectSettings.take(project);
});
return true; return true;
} }
@@ -232,8 +263,8 @@ void AutotestPlugin::extensionsInitialized()
action->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR.icon()); action->setIcon(Utils::Icons::RUN_SMALL_TOOLBAR.icon());
Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR); Command *command = ActionManager::registerAction(action, Constants::ACTION_RUN_UCURSOR);
connect(action, &QAction::triggered, std::bind(&AutotestPlugin::onRunUnderCursorTriggered, this, connect(action, &QAction::triggered,
TestRunMode::Run)); std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, d, TestRunMode::Run));
contextMenu->addSeparator(); contextMenu->addSeparator();
contextMenu->addAction(command); contextMenu->addAction(command);
@@ -242,8 +273,8 @@ void AutotestPlugin::extensionsInitialized()
action->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon()); action->setIcon(ProjectExplorer::Icons::DEBUG_START_SMALL.icon());
command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR); command = ActionManager::registerAction(action, Constants::ACTION_RUN_DBG_UCURSOR);
connect(action, &QAction::triggered, std::bind(&AutotestPlugin::onRunUnderCursorTriggered, this, connect(action, &QAction::triggered,
TestRunMode::Debug)); std::bind(&AutotestPluginPrivate::onRunUnderCursorTriggered, d, TestRunMode::Debug));
contextMenu->addAction(command); contextMenu->addAction(command);
contextMenu->addSeparator(); contextMenu->addSeparator();
} }
@@ -254,7 +285,7 @@ ExtensionSystem::IPlugin::ShutdownFlag AutotestPlugin::aboutToShutdown()
return SynchronousShutdown; return SynchronousShutdown;
} }
void AutotestPlugin::onRunAllTriggered() void AutotestPluginPrivate::onRunAllTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance(); TestTreeModel *model = TestTreeModel::instance();
@@ -262,7 +293,7 @@ void AutotestPlugin::onRunAllTriggered()
runner->prepareToRunTests(TestRunMode::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void AutotestPlugin::onRunSelectedTriggered() void AutotestPluginPrivate::onRunSelectedTriggered()
{ {
TestRunner *runner = TestRunner::instance(); TestRunner *runner = TestRunner::instance();
TestTreeModel *model = TestTreeModel::instance(); TestTreeModel *model = TestTreeModel::instance();
@@ -270,7 +301,7 @@ void AutotestPlugin::onRunSelectedTriggered()
runner->prepareToRunTests(TestRunMode::Run); runner->prepareToRunTests(TestRunMode::Run);
} }
void AutotestPlugin::onRunFileTriggered() void AutotestPluginPrivate::onRunFileTriggered()
{ {
const IDocument *document = EditorManager::currentDocument(); const IDocument *document = EditorManager::currentDocument();
if (!document) if (!document)
@@ -301,7 +332,7 @@ static QList<TestConfiguration *> testItemsToTestConfigurations(const QList<Test
return configs; return configs;
} }
void AutotestPlugin::onRunUnderCursorTriggered(TestRunMode mode) void AutotestPluginPrivate::onRunUnderCursorTriggered(TestRunMode mode)
{ {
TextEditor::BaseTextEditor *currentEditor = TextEditor::BaseTextEditor::currentTextEditor(); TextEditor::BaseTextEditor *currentEditor = TextEditor::BaseTextEditor::currentTextEditor();
QTextCursor cursor = currentEditor->editorWidget()->textCursor(); QTextCursor cursor = currentEditor->editorWidget()->textCursor();
@@ -363,24 +394,24 @@ void AutotestPlugin::updateMenuItemsEnabledState()
void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice) void AutotestPlugin::cacheRunConfigChoice(const QString &buildTargetKey, const ChoicePair &choice)
{ {
if (s_instance) if (s_instance)
s_instance->m_runconfigCache.insert(buildTargetKey, choice); s_instance->d->m_runconfigCache.insert(buildTargetKey, choice);
} }
ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey) ChoicePair AutotestPlugin::cachedChoiceFor(const QString &buildTargetKey)
{ {
return s_instance ? s_instance->m_runconfigCache.value(buildTargetKey) : ChoicePair(); return s_instance ? s_instance->d->m_runconfigCache.value(buildTargetKey) : ChoicePair();
} }
void AutotestPlugin::clearChoiceCache() void AutotestPlugin::clearChoiceCache()
{ {
if (s_instance) if (s_instance)
s_instance->m_runconfigCache.clear(); s_instance->d->m_runconfigCache.clear();
} }
void AutotestPlugin::popupResultsPane() void AutotestPlugin::popupResultsPane()
{ {
if (s_instance) if (s_instance)
s_instance->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch); s_instance->d->m_resultsPane->popup(Core::IOutputPane::NoModeSwitch);
} }
QVector<QObject *> AutotestPlugin::createTestObjects() const QVector<QObject *> AutotestPlugin::createTestObjects() const
@@ -396,3 +427,8 @@ bool ChoicePair::matches(const ProjectExplorer::RunConfiguration *rc) const
{ {
return rc && rc->displayName() == displayName && rc->runnable().executable.toString() == executable; return rc && rc->displayName() == displayName && rc->runnable().executable.toString() == executable;
} }
} // Internal
} // Autotest
#include "autotestplugin.moc"

View File

@@ -39,13 +39,8 @@ class RunConfiguration;
namespace Autotest { namespace Autotest {
namespace Internal { namespace Internal {
class TestFrameworkManager;
class TestNavigationWidgetFactory;
class TestProjectSettings; class TestProjectSettings;
class TestResultsPane;
struct TestSettings; struct TestSettings;
class TestSettingsPage;
enum class TestRunMode;
struct ChoicePair struct ChoicePair
{ {
@@ -79,18 +74,9 @@ public:
static void popupResultsPane(); static void popupResultsPane();
private: private:
void initializeMenuEntries();
void onRunAllTriggered();
void onRunSelectedTriggered();
void onRunFileTriggered();
void onRunUnderCursorTriggered(TestRunMode mode);
QVector<QObject *> createTestObjects() const override; QVector<QObject *> createTestObjects() const override;
class AutotestPluginPrivate *d = nullptr;
const QSharedPointer<TestSettings> m_settings; const QSharedPointer<TestSettings> m_settings;
TestFrameworkManager *m_frameworkManager = nullptr;
TestSettingsPage *m_testSettingPage = nullptr;
TestNavigationWidgetFactory *m_navigationWidgetFactory = nullptr;
TestResultsPane *m_resultsPane = nullptr;
QMap<QString, ChoicePair> m_runconfigCache;
}; };
} // namespace Internal } // namespace Internal