forked from qt-creator/qt-creator
ProjectExplorer: Introduce a SimpleRunWorkerFactory template
... and use in as replacement for RunConfiguration::addRunWorkerFactory. It is still convenient to have a simple way to set up run worker factories for the typical "just run for this configuration" case, but it's even better if it follows the nowadays predominant pattern of keeping factories in the plugin's pimpl. Also, it turned out there were two copies of QmlProjectRunconfigurationFactory code, one is enough. Change-Id: I0b28c4ea18d0f52165a49f6133dc8687a3b9c7cf Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -85,10 +85,6 @@ public:
|
||||
registerRunConfiguration<Android::AndroidRunConfiguration>
|
||||
("Qt4ProjectManager.AndroidRunConfiguration:");
|
||||
addSupportedTargetDeviceType(Android::Constants::ANDROID_DEVICE_TYPE);
|
||||
addRunWorkerFactory<AndroidRunSupport>(NORMAL_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidDebugSupport>(DEBUG_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidQmlToolingSupport>(QML_PROFILER_RUN_MODE);
|
||||
addRunWorkerFactory<AndroidQmlToolingSupport>(QML_PREVIEW_RUN_MODE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -135,6 +131,13 @@ public:
|
||||
AndroidPackageInstallationFactory packackeInstallationFactory;
|
||||
AndroidManifestEditorFactory manifestEditorFactory;
|
||||
AndroidRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<AndroidRunConfiguration, AndroidRunSupport> runWorkerFactory;
|
||||
SimpleRunWorkerFactory<AndroidRunConfiguration, AndroidDebugSupport>
|
||||
debugWorkerFactory{DEBUG_RUN_MODE};
|
||||
SimpleRunWorkerFactory<AndroidRunConfiguration, AndroidQmlToolingSupport>
|
||||
profilerWorkerFactory{QML_PROFILER_RUN_MODE};
|
||||
SimpleRunWorkerFactory<AndroidRunConfiguration, AndroidQmlToolingSupport>
|
||||
qmlPreviewWorkerFactory{QML_PREVIEW_RUN_MODE};
|
||||
AndroidBuildApkStepFactory buildApkStepFactory;
|
||||
AndroidGdbServerKitAspect gdbServerKitAspect;
|
||||
};
|
||||
|
@@ -43,9 +43,12 @@
|
||||
#include <coreplugin/actionmanager/actionmanager.h>
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/kitmanager.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
|
||||
#include <utils/parameteraction.h>
|
||||
@@ -67,6 +70,7 @@ public:
|
||||
CMakeManager manager;
|
||||
CMakeBuildStepFactory buildStepFactory;
|
||||
CMakeRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<CMakeRunConfiguration> runWorkerFactory;
|
||||
CMakeBuildConfigurationFactory buildConfigFactory;
|
||||
CMakeEditorFactory editorFactor;
|
||||
CMakeLocatorFilter locatorFiler;
|
||||
|
@@ -93,8 +93,6 @@ CMakeRunConfigurationFactory::CMakeRunConfigurationFactory()
|
||||
registerRunConfiguration<CMakeRunConfiguration>("CMakeProjectManager.CMakeRunConfiguration.");
|
||||
addSupportedProjectType(CMakeProjectManager::Constants::CMAKEPROJECT_ID);
|
||||
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
|
||||
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // Internal
|
||||
|
@@ -43,6 +43,7 @@
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/toolchainmanager.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
#include <texteditor/snippets/snippetprovider.h>
|
||||
|
||||
using namespace Utils;
|
||||
@@ -66,6 +67,7 @@ public:
|
||||
NimEditorFactory editorFactory;
|
||||
NimBuildConfigurationFactory buildConfigFactory;
|
||||
NimRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<NimRunConfiguration> runWorkerFactory;
|
||||
NimCompilerBuildStepFactory buildStepFactory;
|
||||
NimCompilerCleanStepFactory cleanStepFactory;
|
||||
NimCodeStyleSettingsPage codeStyleSettingsPage;
|
||||
|
@@ -100,7 +100,6 @@ NimRunConfigurationFactory::NimRunConfigurationFactory() : FixedRunConfiguration
|
||||
{
|
||||
registerRunConfiguration<NimRunConfiguration>("Nim.NimRunConfiguration");
|
||||
addSupportedProjectType(Constants::C_NIMPROJECT_ID);
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // Nim
|
||||
|
@@ -284,8 +284,6 @@ CustomExecutableRunConfigurationFactory::CustomExecutableRunConfigurationFactory
|
||||
FixedRunConfigurationFactory(CustomExecutableRunConfiguration::tr("Custom Executable"))
|
||||
{
|
||||
registerRunConfiguration<CustomExecutableRunConfiguration>(CUSTOM_EXECUTABLE_ID);
|
||||
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -544,6 +544,7 @@ public:
|
||||
CurrentProjectFind m_curretProjectFind;
|
||||
|
||||
CustomExecutableRunConfigurationFactory m_customExecutableRunConfigFactory;
|
||||
SimpleRunWorkerFactory<CustomExecutableRunConfiguration> m_customExecutableRunWorkerFactory;
|
||||
|
||||
ProjectFileWizardExtension m_projectFileWizardExtension;
|
||||
|
||||
|
@@ -427,8 +427,6 @@ RunConfigurationFactory::RunConfigurationFactory()
|
||||
RunConfigurationFactory::~RunConfigurationFactory()
|
||||
{
|
||||
g_runConfigurationFactories.removeOne(this);
|
||||
qDeleteAll(m_ownedRunWorkerFactories);
|
||||
m_ownedRunWorkerFactories.clear();
|
||||
}
|
||||
|
||||
QString RunConfigurationFactory::decoratedTargetName(const QString &targetName, Target *target)
|
||||
@@ -497,15 +495,7 @@ void RunConfigurationFactory::setDecorateDisplayNames(bool on)
|
||||
m_decorateDisplayNames = on;
|
||||
}
|
||||
|
||||
RunWorkerFactory *RunConfigurationFactory::addRunWorkerFactoryHelper
|
||||
(Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator)
|
||||
{
|
||||
auto factory = new RunWorkerFactory;
|
||||
factory->addConstraint(m_ownTypeChecker);
|
||||
factory->addSupportedRunMode(runMode);
|
||||
factory->setProducer(creator);
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
void RunConfigurationFactory::addSupportedProjectType(Core::Id id)
|
||||
{
|
||||
|
@@ -251,25 +251,13 @@ protected:
|
||||
return new RunConfig(t, runConfigBaseId);
|
||||
};
|
||||
m_runConfigBaseId = runConfigBaseId;
|
||||
m_ownTypeChecker = [](RunConfiguration *runConfig) {
|
||||
return qobject_cast<RunConfig *>(runConfig) != nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
void addSupportedProjectType(Core::Id id);
|
||||
void addSupportedTargetDeviceType(Core::Id id);
|
||||
void setDecorateDisplayNames(bool on);
|
||||
|
||||
template<class Worker>
|
||||
RunWorkerFactory *addRunWorkerFactory(Core::Id runMode)
|
||||
{
|
||||
return addRunWorkerFactoryHelper(runMode, [](RunControl *rc) { return new Worker(rc); });
|
||||
}
|
||||
|
||||
private:
|
||||
RunWorkerFactory *addRunWorkerFactoryHelper
|
||||
(Core::Id runMode, const std::function<RunWorker *(RunControl *)> &creator);
|
||||
|
||||
bool canHandle(Target *target) const;
|
||||
|
||||
friend class RunConfigurationCreationInfo;
|
||||
@@ -278,8 +266,6 @@ private:
|
||||
QList<Core::Id> m_supportedProjectTypes;
|
||||
QList<Core::Id> m_supportedTargetDeviceTypes;
|
||||
bool m_decorateDisplayNames = false;
|
||||
QList<RunWorkerFactory *> m_ownedRunWorkerFactories;
|
||||
std::function<bool(RunConfiguration *)> m_ownTypeChecker;
|
||||
};
|
||||
|
||||
class PROJECTEXPLORER_EXPORT FixedRunConfigurationFactory : public RunConfigurationFactory
|
||||
|
@@ -327,4 +327,20 @@ private:
|
||||
bool m_useTerminal = false;
|
||||
};
|
||||
|
||||
template <class RunConfig, class RunWorker = SimpleTargetRunner>
|
||||
class SimpleRunWorkerFactory : public RunWorkerFactory
|
||||
{
|
||||
public:
|
||||
SimpleRunWorkerFactory(Core::Id runMode = ProjectExplorer::Constants::NORMAL_RUN_MODE)
|
||||
{
|
||||
addSupportedRunMode(runMode);
|
||||
addConstraint([](RunConfiguration *runConfig) {
|
||||
return qobject_cast<RunConfig *>(runConfig) != nullptr;
|
||||
});
|
||||
setProducer([](RunControl *runControl) {
|
||||
return new RunWorker(runControl);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ProjectExplorer
|
||||
|
@@ -312,7 +312,6 @@ public:
|
||||
{
|
||||
registerRunConfiguration<PythonRunConfiguration>("PythonEditor.RunConfiguration.");
|
||||
addSupportedProjectType(PythonProjectId);
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -723,6 +722,7 @@ class PythonEditorPluginPrivate
|
||||
public:
|
||||
PythonEditorFactory editorFactory;
|
||||
PythonRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<PythonRunConfiguration> runWorkerFactory;
|
||||
};
|
||||
|
||||
PythonEditorPlugin::~PythonEditorPlugin()
|
||||
|
@@ -54,6 +54,7 @@
|
||||
#include <projectexplorer/projectexplorerconstants.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
@@ -91,6 +92,7 @@ public:
|
||||
QbsCleanStepFactory cleanStepFactory;
|
||||
QbsInstallStepFactory installStepFactory;
|
||||
QbsRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<QbsRunConfiguration> runWorkerFactory;
|
||||
QbsProfilesSettingsPage profilesSetttingsPage;
|
||||
QbsKitAspect qbsKitAspect;
|
||||
};
|
||||
|
@@ -169,8 +169,6 @@ QbsRunConfigurationFactory::QbsRunConfigurationFactory()
|
||||
registerRunConfiguration<QbsRunConfiguration>("Qbs.RunConfiguration:");
|
||||
addSupportedProjectType(Constants::PROJECT_ID);
|
||||
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
|
||||
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -147,8 +147,6 @@ DesktopQmakeRunConfigurationFactory::DesktopQmakeRunConfigurationFactory()
|
||||
registerRunConfiguration<DesktopQmakeRunConfiguration>("Qt4ProjectManager.Qt4RunConfiguration:");
|
||||
addSupportedProjectType(QmakeProjectManager::Constants::QMAKEPROJECT_ID);
|
||||
addSupportedTargetDeviceType(ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE);
|
||||
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -55,6 +55,7 @@
|
||||
#include <projectexplorer/buildmanager.h>
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <projectexplorer/target.h>
|
||||
|
||||
@@ -100,6 +101,8 @@ public:
|
||||
|
||||
QmakeBuildConfigurationFactory buildConfigFactory;
|
||||
DesktopQmakeRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<DesktopQmakeRunConfiguration, SimpleTargetRunner>
|
||||
runWorkerFactory;
|
||||
|
||||
ProFileEditorFactory profileEditorFactory;
|
||||
|
||||
|
@@ -25,12 +25,13 @@
|
||||
|
||||
#include "qmlprojectplugin.h"
|
||||
#include "qmlproject.h"
|
||||
#include "qmlprojectrunconfigurationfactory.h"
|
||||
#include "qmlprojectrunconfiguration.h"
|
||||
|
||||
#include <coreplugin/fileiconprovider.h>
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <projectexplorer/projectmanager.h>
|
||||
#include <projectexplorer/runcontrol.h>
|
||||
|
||||
#include <qmljstools/qmljstoolsconstants.h>
|
||||
|
||||
@@ -39,16 +40,24 @@ using namespace ProjectExplorer;
|
||||
namespace QmlProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class QmlProjectPluginPrivate
|
||||
{
|
||||
public:
|
||||
QmlProjectRunConfigurationFactory runConfigFactory;
|
||||
SimpleRunWorkerFactory<QmlProjectRunConfiguration, SimpleTargetRunner>
|
||||
runWorkerFactory{ProjectExplorer::Constants::NORMAL_RUN_MODE};
|
||||
};
|
||||
|
||||
QmlProjectPlugin::~QmlProjectPlugin()
|
||||
{
|
||||
delete m_rcFactory;
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
|
||||
{
|
||||
Q_UNUSED(errorMessage)
|
||||
|
||||
m_rcFactory = new QmlProjectRunConfigurationFactory;
|
||||
d = new QmlProjectPluginPrivate;
|
||||
|
||||
ProjectManager::registerProjectType<QmlProject>(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
|
||||
Core::FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png", "qmlproject");
|
||||
|
@@ -43,7 +43,7 @@ private:
|
||||
bool initialize(const QStringList &arguments, QString *errorString) final;
|
||||
void extensionsInitialized() final {}
|
||||
|
||||
class QmlProjectRunConfigurationFactory *m_rcFactory = nullptr;
|
||||
class QmlProjectPluginPrivate *d = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -459,8 +459,6 @@ QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory()
|
||||
registerRunConfiguration<QmlProjectRunConfiguration>
|
||||
("QmlProjectManager.QmlRunConfiguration.QmlScene");
|
||||
addSupportedProjectType(QmlProjectManager::Constants::QML_PROJECT_ID);
|
||||
|
||||
addRunWorkerFactory<SimpleTargetRunner>(ProjectExplorer::Constants::NORMAL_RUN_MODE);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -1,43 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** 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 "qmlprojectrunconfigurationfactory.h"
|
||||
#include "qmlprojectmanagerconstants.h"
|
||||
#include "qmlproject.h"
|
||||
#include "qmlprojectrunconfiguration.h"
|
||||
|
||||
namespace QmlProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory() :
|
||||
ProjectExplorer::FixedRunConfigurationFactory(QmlProjectRunConfiguration::tr("QML Scene"), false)
|
||||
{
|
||||
registerRunConfiguration<QmlProjectRunConfiguration>(Constants::QML_SCENE_RC_ID);
|
||||
addSupportedProjectType(QmlProjectManager::Constants::QML_PROJECT_ID);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProjectManager
|
||||
|
@@ -1,40 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** 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 <projectexplorer/runconfiguration.h>
|
||||
|
||||
namespace QmlProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
class QmlProjectRunConfigurationFactory : public ProjectExplorer::FixedRunConfigurationFactory
|
||||
{
|
||||
public:
|
||||
QmlProjectRunConfigurationFactory();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace QmlProjectManager
|
Reference in New Issue
Block a user