diff --git a/src/plugins/projectexplorer/runconfiguration.cpp b/src/plugins/projectexplorer/runconfiguration.cpp index 79f7067104c..af7121ef246 100644 --- a/src/plugins/projectexplorer/runconfiguration.cpp +++ b/src/plugins/projectexplorer/runconfiguration.cpp @@ -488,10 +488,19 @@ static WorkerFactories &theWorkerFactories() return factories; } +bool RunControl::WorkerFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const +{ + if (runMode != runMode) + return false; + if (!constraint) + return true; + return constraint(runConfiguration); +} + bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id runMode) const { for (const RunControl::WorkerFactory &factory : theWorkerFactories()) { - if (factory.runMode == runMode && factory.constraint(runConfiguration)) + if (factory.canRun(runConfiguration, runMode)) return true; }; return false; @@ -500,7 +509,7 @@ bool IRunControlFactory::canRun(RunConfiguration *runConfiguration, Core::Id run RunControl *IRunControlFactory::create(RunConfiguration *runConfiguration, Core::Id runMode, QString *) { for (const RunControl::WorkerFactory &factory : theWorkerFactories()) { - if (factory.runMode == runMode && factory.constraint(runConfiguration)) { + if (factory.canRun(runConfiguration, runMode)) { auto runControl = new RunControl(runConfiguration, runMode); factory.producer(runControl); return runControl; @@ -758,7 +767,7 @@ RunWorker *RunControl::createWorker(Core::Id id) { auto keys = theWorkerCreators().keys(); Q_UNUSED(keys); - Producer creator = theWorkerCreators().value(id); + WorkerCreator creator = theWorkerCreators().value(id); if (creator) return creator(this); creator = device()->workerCreator(id); @@ -767,10 +776,11 @@ RunWorker *RunControl::createWorker(Core::Id id) return nullptr; } -RunControl::Producer RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode) +RunControl::WorkerCreator RunControl::producer(RunConfiguration *runConfiguration, Core::Id runMode) { for (const auto &factory : theWorkerFactories()) { - if (factory.runMode == runMode && factory.constraint(runConfiguration)) + if (factory.runMode == runMode + && (!factory.constraint || factory.constraint(runConfiguration))) return factory.producer; } return {}; diff --git a/src/plugins/projectexplorer/runconfiguration.h b/src/plugins/projectexplorer/runconfiguration.h index cf1d5c7a9ad..ab3ce3b58a0 100644 --- a/src/plugins/projectexplorer/runconfiguration.h +++ b/src/plugins/projectexplorer/runconfiguration.h @@ -478,9 +478,6 @@ public: const QString &cancelButtonText = QString(), bool *prompt = nullptr); - using WorkerCreator = std::function; - static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator); - RunWorker *workerById(Core::Id id) const; QList> workers() const; template T *worker() const { @@ -495,9 +492,16 @@ public: RunWorker *createWorker(Core::Id id); - using Producer = std::function; + using WorkerCreator = std::function; using Constraint = std::function; + static void registerWorkerCreator(Core::Id id, const WorkerCreator &workerCreator); + + static void registerWorker(Core::Id runMode, const WorkerCreator &producer, + const Constraint &constraint = {}) + { + addWorkerFactory({runMode, constraint, producer}); + } template static void registerWorker(Core::Id runMode, const Constraint &constraint) { @@ -515,10 +519,12 @@ public: struct WorkerFactory { Core::Id runMode; Constraint constraint; - Producer producer; + WorkerCreator producer; + + bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const; }; - static Producer producer(RunConfiguration *runConfiguration, Core::Id runMode); + static WorkerCreator producer(RunConfiguration *runConfiguration, Core::Id runMode); signals: void appendMessageRequested(ProjectExplorer::RunControl *runControl, @@ -533,7 +539,6 @@ private: friend class Internal::RunWorkerPrivate; static void addWorkerFactory(const WorkerFactory &workerFactory); - void bringApplicationToForegroundInternal(); Internal::RunControlPrivate *d; }; diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index 1564fcb78d0..689a986d8c8 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -41,7 +41,6 @@ #include #include #include -#include #include #include @@ -99,6 +98,7 @@ using namespace Valgrind::Callgrind; using namespace TextEditor; using namespace ProjectExplorer; using namespace Utils; +using namespace std::placeholders; namespace Valgrind { namespace Internal { @@ -118,7 +118,7 @@ class CallgrindTool : public QObject Q_OBJECT public: - CallgrindTool(QObject *parent); + CallgrindTool(); ~CallgrindTool(); ValgrindToolRunner *createRunTool(RunControl *runControl); @@ -222,8 +222,7 @@ public: bool m_toolBusy = false; }; -CallgrindTool::CallgrindTool(QObject *parent) - : QObject(parent) +CallgrindTool::CallgrindTool() { setObjectName(QLatin1String("CallgrindTool")); @@ -251,10 +250,6 @@ CallgrindTool::CallgrindTool(QObject *parent) QString toolTip = tr("Valgrind Function Profiler uses the " "Callgrind tool to record function calls when a program runs."); - RunControl::registerWorkerCreator(CALLGRIND_RUN_MODE, [this](RunControl *runControl) { - return createRunTool(runControl); - }); - if (!Utils::HostOsInfo::isWindowsHost()) { auto action = new QAction(tr("Valgrind Function Profiler"), this); action->setToolTip(toolTip); @@ -966,48 +961,20 @@ void CallgrindTool::createTextMarks() } -class CallgrindRunControlFactory : public IRunControlFactory -{ -public: - CallgrindRunControlFactory() : m_tool(new CallgrindTool(this)) {} - - bool canRun(RunConfiguration *runConfiguration, Core::Id runMode) const override - { - Q_UNUSED(runConfiguration); - return runMode == CALLGRIND_RUN_MODE; - } - - RunControl *create(RunConfiguration *runConfiguration, Core::Id runMode, QString *errorMessage) override - { - Q_UNUSED(errorMessage); - auto runControl = new RunControl(runConfiguration, runMode); - m_tool->createRunTool(runControl); - return runControl; - } - - IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override - { - return createValgrindRunConfigurationAspect(rc); - } - -public: - CallgrindTool *m_tool; -}; - - -static CallgrindRunControlFactory *theCallgrindRunControlFactory; +static CallgrindTool *theCallgrindTool; void initCallgrindTool() { - theCallgrindRunControlFactory = new CallgrindRunControlFactory; - ExtensionSystem::PluginManager::addObject(theCallgrindRunControlFactory); + theCallgrindTool = new CallgrindTool; + + auto producer = std::bind(&CallgrindTool::createRunTool, theCallgrindTool, _1); + RunControl::registerWorker(CALLGRIND_RUN_MODE, producer); } void destroyCallgrindTool() { - ExtensionSystem::PluginManager::removeObject(theCallgrindRunControlFactory); - delete theCallgrindRunControlFactory; - theCallgrindRunControlFactory = 0; + delete theCallgrindTool; + theCallgrindTool = nullptr; } } // namespace Internal diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 5ae5bf3f152..9b5223c895e 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -36,7 +36,6 @@ #include #include -#include #include #include #include @@ -241,7 +240,7 @@ class MemcheckTool : public QObject Q_DECLARE_TR_FUNCTIONS(Valgrind::Internal::MemcheckTool) public: - MemcheckTool(QObject *parent); + MemcheckTool(); RunWorker *createRunWorker(RunControl *runControl); @@ -286,8 +285,7 @@ private: bool m_toolBusy = false; }; -MemcheckTool::MemcheckTool(QObject *parent) - : QObject(parent) +MemcheckTool::MemcheckTool() { m_settings = ValgrindPlugin::globalSettings(); @@ -393,9 +391,6 @@ MemcheckTool::MemcheckTool(QObject *parent) ActionContainer *menu = ActionManager::actionContainer(Debugger::Constants::M_DEBUG_ANALYZER); QString toolTip = tr("Valgrind Analyze Memory uses the Memcheck tool to find memory leaks."); - RunControl::registerWorkerCreator(MEMCHECK_RUN_MODE, std::bind(&MemcheckTool::createRunWorker, this, _1)); - RunControl::registerWorkerCreator(MEMCHECK_WITH_GDB_RUN_MODE, std::bind(&MemcheckTool::createRunWorker, this, _1)); - if (!Utils::HostOsInfo::isWindowsHost()) { action = new QAction(this); action->setText(tr("Valgrind Memory Analyzer")); @@ -711,49 +706,21 @@ void MemcheckTool::setBusyCursor(bool busy) } -class MemcheckRunControlFactory : public IRunControlFactory -{ -public: - MemcheckRunControlFactory() : m_tool(new MemcheckTool(this)) {} - - bool canRun(RunConfiguration *runConfiguration, Core::Id mode) const override - { - Q_UNUSED(runConfiguration); - return mode == MEMCHECK_RUN_MODE || mode == MEMCHECK_WITH_GDB_RUN_MODE; - } - - RunControl *create(RunConfiguration *runConfiguration, Core::Id mode, QString *errorMessage) override - { - Q_UNUSED(errorMessage); - auto runControl = new RunControl(runConfiguration, mode); - runControl->createWorker(mode); - return runControl; - } - - // Do not create an aspect, let the Callgrind tool create one and use that, too. -// IRunConfigurationAspect *createRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc) override -// { -// return createValgrindRunConfigurationAspect(rc); -// } - -public: - MemcheckTool *m_tool; -}; - - -static MemcheckRunControlFactory *theMemcheckRunControlFactory; +static MemcheckTool *theMemcheckTool; void initMemcheckTool() { - theMemcheckRunControlFactory = new MemcheckRunControlFactory; - ExtensionSystem::PluginManager::addObject(theMemcheckRunControlFactory); + theMemcheckTool = new MemcheckTool; + + auto producer = std::bind(&MemcheckTool::createRunWorker, theMemcheckTool, _1); + RunControl::registerWorker(MEMCHECK_RUN_MODE, producer); + RunControl::registerWorker(MEMCHECK_WITH_GDB_RUN_MODE, producer); } void destroyMemcheckTool() { - ExtensionSystem::PluginManager::removeObject(theMemcheckRunControlFactory); - delete theMemcheckRunControlFactory; - theMemcheckRunControlFactory = 0; + delete theMemcheckTool; + theMemcheckTool = nullptr; } } // namespace Internal diff --git a/src/plugins/valgrind/valgrind.pro b/src/plugins/valgrind/valgrind.pro index 592fe8338b4..4bbd41fc5c7 100644 --- a/src/plugins/valgrind/valgrind.pro +++ b/src/plugins/valgrind/valgrind.pro @@ -23,8 +23,7 @@ HEADERS += \ memchecktool.h \ memcheckengine.h \ memcheckerrorview.h \ - suppressiondialog.h \ - valgrindruncontrolfactory.h + suppressiondialog.h SOURCES += \ valgrindplugin.cpp \ @@ -44,8 +43,7 @@ SOURCES += \ memchecktool.cpp \ memcheckengine.cpp \ memcheckerrorview.cpp \ - suppressiondialog.cpp \ - valgrindruncontrolfactory.cpp + suppressiondialog.cpp FORMS += \ valgrindconfigwidget.ui diff --git a/src/plugins/valgrind/valgrind.qbs b/src/plugins/valgrind/valgrind.qbs index 963fa2265db..c7e992921ec 100644 --- a/src/plugins/valgrind/valgrind.qbs +++ b/src/plugins/valgrind/valgrind.qbs @@ -34,7 +34,6 @@ QtcPlugin { "valgrindconfigwidget.cpp", "valgrindconfigwidget.h", "valgrindconfigwidget.ui", "valgrindengine.cpp", "valgrindengine.h", "valgrindplugin.cpp", "valgrindplugin.h", - "valgrindruncontrolfactory.cpp", "valgrindruncontrolfactory.h", "valgrindrunner.cpp", "valgrindrunner.h", "valgrindsettings.cpp", "valgrindsettings.h", "workarounds.cpp", "workarounds.h", diff --git a/src/plugins/valgrind/valgrindplugin.cpp b/src/plugins/valgrind/valgrindplugin.cpp index ce58373512a..4cb71eab681 100644 --- a/src/plugins/valgrind/valgrindplugin.cpp +++ b/src/plugins/valgrind/valgrindplugin.cpp @@ -28,7 +28,6 @@ #include "callgrindtool.h" #include "memchecktool.h" -#include "valgrindruncontrolfactory.h" #include "valgrindsettings.h" #include "valgrindconfigwidget.h" @@ -40,6 +39,7 @@ #include #include #include +#include #include @@ -88,6 +88,37 @@ private: QPointer m_widget; }; +class ValgrindRunConfigurationAspect : public IRunConfigurationAspect +{ +public: + ValgrindRunConfigurationAspect(RunConfiguration *parent) + : IRunConfigurationAspect(parent) + { + setProjectSettings(new ValgrindProjectSettings()); + setGlobalSettings(ValgrindPlugin::globalSettings()); + setId(ANALYZER_VALGRIND_SETTINGS); + setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect", + "Valgrind Settings")); + setUsingGlobalSettings(true); + resetProjectToGlobalSettings(); + setRunConfigWidgetCreator([this] { return new Debugger::AnalyzerRunConfigWidget(this); }); + } + + ValgrindRunConfigurationAspect *create(RunConfiguration *parent) const override + { + return new ValgrindRunConfigurationAspect(parent); + } +}; + +class ValgrindRunControlFactory : public IRunControlFactory +{ +public: + IRunConfigurationAspect *createRunConfigurationAspect(RunConfiguration *rc) override + { + return new ValgrindRunConfigurationAspect(rc); + } +}; + ValgrindPlugin::~ValgrindPlugin() { delete theGlobalSettings; @@ -100,6 +131,7 @@ bool ValgrindPlugin::initialize(const QStringList &, QString *) theGlobalSettings->readSettings(); addAutoReleasedObject(new ValgrindOptionsPage); + addAutoReleasedObject(new ValgrindRunControlFactory); return true; } diff --git a/src/plugins/valgrind/valgrindruncontrolfactory.cpp b/src/plugins/valgrind/valgrindruncontrolfactory.cpp deleted file mode 100644 index 4acd1da1d98..00000000000 --- a/src/plugins/valgrind/valgrindruncontrolfactory.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Kläralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** 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. -** -** 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. -** -****************************************************************************/ - -#include "valgrindruncontrolfactory.h" - -#include "valgrindengine.h" -#include "valgrindsettings.h" -#include "valgrindplugin.h" -#include "callgrindtool.h" -#include "memchecktool.h" - -#include -#include - -#include - -using namespace Debugger; -using namespace ProjectExplorer; - -namespace Valgrind { -namespace Internal { - -class ValgrindRunConfigurationAspect : public IRunConfigurationAspect -{ -public: - ValgrindRunConfigurationAspect(RunConfiguration *parent) - : IRunConfigurationAspect(parent) - { - setProjectSettings(new ValgrindProjectSettings()); - setGlobalSettings(ValgrindPlugin::globalSettings()); - setId(ANALYZER_VALGRIND_SETTINGS); - setDisplayName(QCoreApplication::translate("Valgrind::Internal::ValgrindRunConfigurationAspect", "Valgrind Settings")); - setUsingGlobalSettings(true); - resetProjectToGlobalSettings(); - setRunConfigWidgetCreator([this] { return new AnalyzerRunConfigWidget(this); }); - } - - ValgrindRunConfigurationAspect *create(RunConfiguration *parent) const override - { - return new ValgrindRunConfigurationAspect(parent); - } -}; - -IRunConfigurationAspect *createValgrindRunConfigurationAspect(RunConfiguration *rc) -{ - return new ValgrindRunConfigurationAspect(rc); -} - -} // namespace Internal -} // namespace Valgrind diff --git a/src/plugins/valgrind/valgrindruncontrolfactory.h b/src/plugins/valgrind/valgrindruncontrolfactory.h deleted file mode 100644 index 01099043b3e..00000000000 --- a/src/plugins/valgrind/valgrindruncontrolfactory.h +++ /dev/null @@ -1,36 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Kläralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of Qt Creator. -** -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** 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. -** -** 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. -** -****************************************************************************/ - -#pragma once - -#include - -namespace Valgrind { -namespace Internal { - -ProjectExplorer::IRunConfigurationAspect *createValgrindRunConfigurationAspect(ProjectExplorer::RunConfiguration *rc); - -} // namespace Internal -} // namespace Valgrind