From 82f8cb70e63934bbeebf1fb7ead8c7018e4ad0c8 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 7 Jul 2017 17:47:06 +0200 Subject: [PATCH] WinRT: Dissolve RunControlFactory Less code, and it's what most other targets do nowadays. Change-Id: I2cf55d1a32ad10427ce2508536d03bca8921b451 Reviewed-by: David Schulz --- src/plugins/winrt/winrtplugin.cpp | 36 +++++++++++++++-- src/plugins/winrt/winrtrunfactories.cpp | 51 ------------------------- src/plugins/winrt/winrtrunfactories.h | 12 ------ 3 files changed, 33 insertions(+), 66 deletions(-) diff --git a/src/plugins/winrt/winrtplugin.cpp b/src/plugins/winrt/winrtplugin.cpp index 70f7efaae79..dd55b0c3e68 100644 --- a/src/plugins/winrt/winrtplugin.cpp +++ b/src/plugins/winrt/winrtplugin.cpp @@ -24,21 +24,28 @@ ****************************************************************************/ #include "winrtplugin.h" +#include "winrtconstants.h" #include "winrtrunfactories.h" #include "winrtdevice.h" #include "winrtdevicefactory.h" #include "winrtdeployconfiguration.h" #include "winrtqtversionfactory.h" +#include "winrtrunconfiguration.h" +#include "winrtruncontrol.h" +#include "winrtdebugsupport.h" #include #include + #include +#include +#include +#include #include #include -using ExtensionSystem::PluginManager; -using ProjectExplorer::DeviceManager; +using namespace ProjectExplorer; namespace WinRt { namespace Internal { @@ -54,10 +61,33 @@ bool WinRtPlugin::initialize(const QStringList &arguments, QString *errorMessage Q_UNUSED(errorMessage) addAutoReleasedObject(new Internal::WinRtRunConfigurationFactory); - addAutoReleasedObject(new Internal::WinRtRunControlFactory); addAutoReleasedObject(new Internal::WinRtQtVersionFactory); addAutoReleasedObject(new Internal::WinRtDeployConfigurationFactory); addAutoReleasedObject(new Internal::WinRtDeployStepFactory); + + auto runConstraint = [](RunConfiguration *runConfig) { + IDevice::ConstPtr device = DeviceKitInformation::device(runConfig->target()->kit()); + if (!device) + return false; + return qobject_cast(runConfig) != nullptr; + }; + + auto debugConstraint = [](RunConfiguration *runConfig) { + IDevice::ConstPtr device = DeviceKitInformation::device(runConfig->target()->kit()); + if (!device) + return false; + if (device->type() != Internal::Constants::WINRT_DEVICE_TYPE_LOCAL) + return false; + return qobject_cast(runConfig) != nullptr; + }; + + RunControl::registerWorker + (ProjectExplorer::Constants::NORMAL_RUN_MODE, runConstraint); + RunControl::registerWorker + (ProjectExplorer::Constants::DEBUG_RUN_MODE, debugConstraint); + RunControl::registerWorker + (ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN, debugConstraint); + return true; } diff --git a/src/plugins/winrt/winrtrunfactories.cpp b/src/plugins/winrt/winrtrunfactories.cpp index 3269b32d641..4adde539749 100644 --- a/src/plugins/winrt/winrtrunfactories.cpp +++ b/src/plugins/winrt/winrtrunfactories.cpp @@ -27,14 +27,12 @@ #include "winrtrunconfiguration.h" #include "winrtruncontrol.h" #include "winrtconstants.h" -#include "winrtdebugsupport.h" #include #include #include #include #include -#include using namespace ProjectExplorer; using QmakeProjectManager::QmakeProject; @@ -124,54 +122,5 @@ bool WinRtRunConfigurationFactory::canHandle(Target *parent) const return true; } -WinRtRunControlFactory::WinRtRunControlFactory() -{ -} - -bool WinRtRunControlFactory::canRun(RunConfiguration *runConfiguration, - Core::Id mode) const -{ - if (!runConfiguration) - return false; - IDevice::ConstPtr device = DeviceKitInformation::device(runConfiguration->target()->kit()); - if (!device) - return false; - - if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE - || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) { - if (device->type() != Constants::WINRT_DEVICE_TYPE_LOCAL) - return false; - return qobject_cast(runConfiguration); - } - - if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) - return qobject_cast(runConfiguration); - - return false; -} - -RunControl *WinRtRunControlFactory::create( - RunConfiguration *runConfiguration, Core::Id mode, QString *) -{ - RunControl *runControl = nullptr; - if (mode == ProjectExplorer::Constants::NORMAL_RUN_MODE) { - runControl = new RunControl(runConfiguration, mode); - (void) new WinRtRunner(runControl); - return runControl; - } else if (mode == ProjectExplorer::Constants::DEBUG_RUN_MODE - || mode == ProjectExplorer::Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN) { - runControl = new RunControl(runConfiguration, mode); - (void) new WinRtDebugSupport(runControl); - return runControl; - } - - return nullptr; -} - -QString WinRtRunControlFactory::displayName() const -{ - return tr("WinRT Run Control Factory"); -} - } // namespace Internal } // namespace WinRt diff --git a/src/plugins/winrt/winrtrunfactories.h b/src/plugins/winrt/winrtrunfactories.h index 59a35ff3a63..9ff24b72072 100644 --- a/src/plugins/winrt/winrtrunfactories.h +++ b/src/plugins/winrt/winrtrunfactories.h @@ -52,17 +52,5 @@ private: virtual ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent, const QVariantMap &map) override; }; -class WinRtRunControlFactory : public ProjectExplorer::IRunControlFactory -{ - Q_OBJECT -public: - WinRtRunControlFactory(); - bool canRun(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id mode) const override; - ProjectExplorer::RunControl *create(ProjectExplorer::RunConfiguration *runConfiguration, - Core::Id mode, QString *errorMessage) override; - QString displayName() const; -}; - } // namespace Internal } // namespace WinRt