ProjectExplorer: Allow specifying deploy config widgets in the factory

Keep the generality of creating any widget, but also add a convenience
function handling the single special case that was ever used.

Change-Id: Iab4cbe62de04b9fcc6cb0bb305eaf9a48649d991
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2019-01-18 14:51:05 +01:00
parent d89ad246be
commit a8d2546dad
6 changed files with 31 additions and 36 deletions

View File

@@ -27,6 +27,7 @@
#include "buildsteplist.h"
#include "buildconfiguration.h"
#include "deploymentdataview.h"
#include "kitinformation.h"
#include "project.h"
#include "projectexplorer.h"
@@ -67,6 +68,13 @@ const BuildStepList *DeployConfiguration::stepList() const
return &m_stepList;
}
NamedWidget *DeployConfiguration::createConfigWidget() const
{
if (!m_configWidgetCreator)
return nullptr;
return m_configWidgetCreator(target());
}
QVariantMap DeployConfiguration::toMap() const
{
QVariantMap map(ProjectConfiguration::toMap());
@@ -75,11 +83,6 @@ QVariantMap DeployConfiguration::toMap() const
return map;
}
NamedWidget *DeployConfiguration::createConfigWidget()
{
return nullptr;
}
bool DeployConfiguration::isEnabled() const
{
return false;
@@ -176,6 +179,16 @@ bool DeployConfigurationFactory::canHandle(Target *target) const
return true;
}
void DeployConfigurationFactory::setConfigWidgetCreator(const std::function<NamedWidget *(Target *)> &configWidgetCreator)
{
m_configWidgetCreator = configWidgetCreator;
}
void DeployConfigurationFactory::setUseDeploymentDataView()
{
m_configWidgetCreator = [](Target *target) { return new DeploymentDataView(target); };
}
bool DeployConfigurationFactory::canCreate(Target *parent, Core::Id id) const
{
if (!canHandle(parent))
@@ -197,6 +210,7 @@ DeployConfiguration *DeployConfigurationFactory::create(Target *parent, Core::Id
if (!info.condition || info.condition(parent))
dc->stepList()->appendStep(info.deployStepId);
}
dc->m_configWidgetCreator = m_configWidgetCreator;
return dc;
}

View File

@@ -51,11 +51,11 @@ public:
BuildStepList *stepList();
const BuildStepList *stepList() const;
NamedWidget *createConfigWidget() const;
bool fromMap(const QVariantMap &map) override;
QVariantMap toMap() const override;
virtual NamedWidget *createConfigWidget();
virtual bool isEnabled() const;
virtual QString disabledReason() const;
@@ -69,6 +69,7 @@ signals:
private:
BuildStepList m_stepList;
std::function<NamedWidget *(Target *)> m_configWidgetCreator;
};
class PROJECTEXPLORER_EXPORT DeployConfigurationFactory
@@ -100,6 +101,9 @@ public:
virtual bool canHandle(ProjectExplorer::Target *target) const;
void setConfigWidgetCreator(const std::function<NamedWidget *(Target *)> &configWidgetCreator);
void setUseDeploymentDataView();
protected:
using DeployConfigurationCreator = std::function<DeployConfiguration *(Target *)>;
@@ -109,6 +113,7 @@ protected:
m_creator = [this, deployConfigBaseId](Target *t) {
auto dc = new DeployConfig(t, deployConfigBaseId);
dc->setDefaultDisplayName(m_defaultDisplayName);
dc->m_configWidgetCreator = m_configWidgetCreator;
return dc;
};
m_deployConfigBaseId = deployConfigBaseId;
@@ -125,6 +130,7 @@ private:
QList<Core::Id> m_supportedTargetDeviceTypes;
QList<DeployStepCreationInfo> m_initialSteps;
QString m_defaultDisplayName;
std::function<NamedWidget *(Target *)> m_configWidgetCreator;
};
class DefaultDeployConfigurationFactory : public DeployConfigurationFactory

View File

@@ -29,7 +29,6 @@
#include "qnxdevicefactory.h"
#include <projectexplorer/devicesupport/devicecheckbuildstep.h>
#include <projectexplorer/deploymentdataview.h>
#include <remotelinux/genericdirectuploadstep.h>
#include <remotelinux/remotelinuxcheckforfreediskspacestep.h>
@@ -40,22 +39,14 @@ using namespace RemoteLinux;
namespace Qnx {
namespace Internal {
QnxDeployConfiguration::QnxDeployConfiguration(Target *target, Core::Id id)
: DeployConfiguration(target, id)
{
}
NamedWidget *QnxDeployConfiguration::createConfigWidget()
{
return new DeploymentDataView(target());
}
QnxDeployConfigurationFactory::QnxDeployConfigurationFactory()
{
registerDeployConfiguration<DeployConfiguration>
(Constants::QNX_QNX_DEPLOYCONFIGURATION_ID);
setDefaultDisplayName(QnxDeployConfiguration::tr("Deploy to QNX Device"));
setDefaultDisplayName(QCoreApplication::translate("Qnx::Internal::QnxDeployConfiguration",
"Deploy to QNX Device"));
addSupportedTargetDeviceType(QnxDeviceFactory::deviceType());
setUseDeploymentDataView();
addInitialStep(DeviceCheckBuildStep::stepId());
addInitialStep(RemoteLinuxCheckForFreeDiskSpaceStep::stepId());

View File

@@ -30,15 +30,6 @@
namespace Qnx {
namespace Internal {
class QnxDeployConfiguration : public ProjectExplorer::DeployConfiguration
{
Q_OBJECT
public:
QnxDeployConfiguration(ProjectExplorer::Target *target, Core::Id id);
ProjectExplorer::NamedWidget *createConfigWidget() override;
};
class QnxDeployConfigurationFactory : public ProjectExplorer::DeployConfigurationFactory
{
public:

View File

@@ -33,7 +33,6 @@
#include "rsyncdeploystep.h"
#include <projectexplorer/abi.h>
#include <projectexplorer/deploymentdataview.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/target.h>
@@ -50,11 +49,6 @@ RemoteLinuxDeployConfiguration::RemoteLinuxDeployConfiguration(Target *target, C
: DeployConfiguration(target, id)
{}
NamedWidget *RemoteLinuxDeployConfiguration::createConfigWidget()
{
return new DeploymentDataView(target());
}
Core::Id RemoteLinuxDeployConfiguration::genericDeployConfigurationId()
{
return "DeployToGenericLinux";
@@ -69,6 +63,7 @@ RemoteLinuxDeployConfigurationFactory::RemoteLinuxDeployConfigurationFactory()
addSupportedTargetDeviceType(RemoteLinux::Constants::GenericLinuxOsType);
setDefaultDisplayName(QCoreApplication::translate("RemoteLinux",
"Deploy to Remote Linux Host"));
setUseDeploymentDataView();
addInitialStep(RemoteLinuxCheckForFreeDiskSpaceStep::stepId());
addInitialStep(RemoteLinuxKillAppStep::stepId());

View File

@@ -42,8 +42,6 @@ public:
static Core::Id genericDeployConfigurationId();
ProjectExplorer::NamedWidget *createConfigWidget() override;
template<class T> T *earlierBuildStep(const ProjectExplorer::BuildStep *laterBuildStep) const
{
const QList<ProjectExplorer::BuildStep *> &buildSteps = stepList()->steps();