ProjectExplorer: Add a RunConfigurationFactory::canHandle(Target *)

All RunConfiguration factories had some kind of canHandle(Target *)
implementation. Centralize this notion.

Change-Id: Ie24a355e857bddfd76b866859b8c7a42ffc83840
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
hjk
2017-11-17 08:24:47 +01:00
parent 93bb5081ed
commit d1c9b33eb7
24 changed files with 63 additions and 138 deletions

View File

@@ -39,14 +39,6 @@ using namespace ProjectExplorer;
namespace BareMetal {
namespace Internal {
static bool canHandle(const Target *target)
{
if (!target->project()->supportsKit(target->kit()))
return false;
const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
return deviceType == BareMetal::Constants::BareMetalOsType;
}
// BareMetalRunConfigurationFactory
BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory(QObject *parent) :
@@ -54,6 +46,7 @@ BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory(QObject *pare
{
setObjectName("BareMetalRunConfigurationFactory");
registerRunConfiguration<BareMetalRunConfiguration>();
setSupportedTargetDeviceTypes({BareMetal::Constants::BareMetalOsType});
}
bool BareMetalRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
@@ -104,6 +97,7 @@ BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory(Q
{
setObjectName("BareMetalCustomRunConfigurationFactory");
registerRunConfiguration<BareMetalCustomRunConfiguration>();
setSupportedTargetDeviceTypes({BareMetal::Constants::BareMetalOsType});
}
bool BareMetalCustomRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const

View File

@@ -222,6 +222,7 @@ CMakeRunConfigurationFactory::CMakeRunConfigurationFactory(QObject *parent) :
{
setObjectName("CMakeRunConfigurationFactory");
registerRunConfiguration<CMakeRunConfiguration>();
setSupportedProjectType<CMakeProject>();
}
// used to show the list of possible additons to a project, returns a list of ids
@@ -243,13 +244,6 @@ QString CMakeRunConfigurationFactory::displayNameForId(Core::Id id) const
return buildTargetFromId(id);
}
bool CMakeRunConfigurationFactory::canHandle(Target *parent) const
{
if (!parent->project()->supportsKit(parent->kit()))
return false;
return qobject_cast<CMakeProject *>(parent->project());
}
bool CMakeRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
{
if (!canHandle(parent))

View File

@@ -94,9 +94,6 @@ public:
static Core::Id idFromBuildTarget(const QString &target);
static QString buildTargetFromId(Core::Id id);
private:
bool canHandle(ProjectExplorer::Target *parent) const;
};
} // namespace Internal

View File

@@ -29,11 +29,6 @@
#include "iosrunconfiguration.h"
#include "iosmanager.h"
#include <debugger/analyzer/analyzermanager.h>
#include <debugger/debuggerconstants.h>
#include <projectexplorer/customexecutablerunconfiguration.h>
#include <projectexplorer/kitinformation.h>
#include <projectexplorer/project.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectexplorer.h>
@@ -42,7 +37,6 @@
#include <qmakeprojectmanager/qmakenodes.h>
#include <qmakeprojectmanager/qmakeproject.h>
using namespace Debugger;
using namespace ProjectExplorer;
using namespace QmakeProjectManager;
@@ -54,6 +48,7 @@ IosRunConfigurationFactory::IosRunConfigurationFactory(QObject *parent)
{
setObjectName("IosRunConfigurationFactory");
registerRunConfiguration<IosRunConfiguration>();
setSupportedProjectType<QmakeProject>();
}
bool IosRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
@@ -94,9 +89,7 @@ QString IosRunConfigurationFactory::displayNameForId(Core::Id id) const
bool IosRunConfigurationFactory::canHandle(Target *t) const
{
if (!t->project()->supportsKit(t->kit()))
return false;
return IosManager::supportsIos(t);
return IRunConfigurationFactory::canHandle(t) && IosManager::supportsIos(t->kit());
}
QList<RunConfiguration *> IosRunConfigurationFactory::runConfigurationsForNode(Target *t, const Node *n)

View File

@@ -32,8 +32,6 @@
#include <debugger/debuggerrunconfigurationaspect.h>
#include <projectexplorer/target.h>
#include <memory>
using namespace ProjectExplorer;
namespace Nim {
@@ -41,6 +39,7 @@ namespace Nim {
NimRunConfigurationFactory::NimRunConfigurationFactory()
{
registerRunConfiguration<NimRunConfiguration>();
setSupportedProjectType<NimProject>();
}
QList<Core::Id> NimRunConfigurationFactory::availableCreationIds(Target *parent,
@@ -78,12 +77,4 @@ bool NimRunConfigurationFactory::canClone(Target *parent, RunConfiguration *prod
return canHandle(parent);
}
bool NimRunConfigurationFactory::canHandle(Target *parent) const
{
Q_UNUSED(parent);
if (!parent->project()->supportsKit(parent->kit()))
return false;
return qobject_cast<NimProject *>(parent->project());
}
}

View File

@@ -41,9 +41,6 @@ public:
bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const override;
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product) const override;
private:
bool canHandle(ProjectExplorer::Target *parent) const;
};
}

View File

@@ -341,11 +341,6 @@ bool CustomExecutableRunConfigurationFactory::canClone(Target *parent,
return canCreate(parent, source->id());
}
bool CustomExecutableRunConfigurationFactory::canHandle(Target *parent) const
{
return parent->project()->supportsKit(parent->kit());
}
QList<Core::Id> CustomExecutableRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const
{
Q_UNUSED(mode)

View File

@@ -101,9 +101,6 @@ public:
bool canCreate(Target *parent, Core::Id id) const override;
bool canRestore(Target *parent, const QVariantMap &map) const override;
bool canClone(Target *parent, RunConfiguration *product) const override;
private:
bool canHandle(Target *parent) const;
};
} // namespace ProjectExplorer

View File

@@ -34,6 +34,7 @@
#include "kitinformation.h"
#include "runnables.h"
#include "session.h"
#include "kitinformation.h"
#include <extensionsystem/pluginmanager.h>
@@ -449,6 +450,33 @@ IRunConfigurationFactory::IRunConfigurationFactory(QObject *parent) :
{
}
/*!
Specifies a list of device types for which this RunConfigurationFactory
can create RunConfiguration.
Not calling this function or using an empty list means no restriction.
*/
void IRunConfigurationFactory::setSupportedTargetDeviceTypes(const QList<Core::Id> &ids)
{
m_supportedTargetDeviceTypes = ids;
}
bool IRunConfigurationFactory::canHandle(Target *target) const
{
if (m_projectTypeChecker && !m_projectTypeChecker(target->project()))
return false;
if (!target->project()->supportsKit(target->kit()))
return false;
if (!m_supportedTargetDeviceTypes.isEmpty())
if (!m_supportedTargetDeviceTypes.contains(
DeviceTypeKitInformation::deviceTypeId(target->kit())))
return false;
return true;
}
RunConfiguration *IRunConfigurationFactory::create(Target *parent, Core::Id id)
{
if (!canCreate(parent, id))

View File

@@ -288,6 +288,7 @@ public:
virtual QList<Core::Id> availableCreationIds(Target *parent, CreationMode mode = UserCreate) const = 0;
virtual QString displayNameForId(Core::Id id) const = 0;
virtual bool canHandle(Target *target) const;
virtual bool canCreate(Target *parent, Core::Id id) const = 0;
RunConfiguration *create(Target *parent, Core::Id id);
virtual bool canRestore(Target *parent, const QVariantMap &map) const = 0;
@@ -311,8 +312,20 @@ protected:
m_creator = [](Target *t) -> RunConfiguration * { return new RunConfig(t); };
}
using ProjectTypeChecker = std::function<bool(Project *)>;
template <class ProjectType>
void setSupportedProjectType()
{
m_projectTypeChecker = [](Project *p) { return qobject_cast<ProjectType *>(p) != nullptr; };
}
void setSupportedTargetDeviceTypes(const QList<Core::Id> &ids);
private:
RunConfigurationCreator m_creator;
ProjectTypeChecker m_projectTypeChecker;
QList<Core::Id> m_supportedTargetDeviceTypes;
};
class PROJECTEXPLORER_EXPORT RunConfigWidget : public QWidget

View File

@@ -91,6 +91,7 @@ static Core::Id idFromScript(const QString &target)
class PythonProject : public Project
{
Q_OBJECT
public:
explicit PythonProject(const Utils::FileName &filename);
@@ -279,6 +280,7 @@ public:
{
setObjectName("PythonRunConfigurationFactory");
registerRunConfiguration<PythonRunConfiguration>();
setSupportedProjectType<PythonProject>();
}
QList<Core::Id> availableCreationIds(Target *parent, CreationMode mode) const override
@@ -323,9 +325,6 @@ public:
return false;
return source->id().name().startsWith(PythonRunConfigurationPrefix);
}
private:
bool canHandle(Target *parent) const { return dynamic_cast<PythonProject *>(parent->project()); }
};
PythonProject::PythonProject(const FileName &fileName) :

View File

@@ -355,6 +355,8 @@ QbsRunConfigurationFactory::QbsRunConfigurationFactory(QObject *parent) :
{
setObjectName("QbsRunConfigurationFactory");
registerRunConfiguration<QbsRunConfiguration>();
setSupportedProjectType<QbsProject>();
setSupportedTargetDeviceTypes({Constants::DESKTOP_DEVICE_TYPE});
}
bool QbsRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
@@ -413,15 +415,5 @@ QString QbsRunConfigurationFactory::displayNameForId(Core::Id id) const
return productDisplayNameFromId(id);
}
bool QbsRunConfigurationFactory::canHandle(Target *t) const
{
if (!t->project()->supportsKit(t->kit()))
return false;
if (!qobject_cast<QbsProject *>(t->project()))
return false;
Core::Id devType = DeviceTypeKitInformation::deviceTypeId(t->kit());
return devType == Constants::DESKTOP_DEVICE_TYPE;
}
} // namespace Internal
} // namespace QbsProjectManager

View File

@@ -116,9 +116,6 @@ public:
QList<Core::Id> availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const override;
QString displayNameForId(Core::Id id) const override;
private:
bool canHandle(ProjectExplorer::Target *t) const;
};
} // namespace Internal

View File

@@ -50,6 +50,7 @@ QmakeAndroidRunConfigurationFactory::QmakeAndroidRunConfigurationFactory(QObject
: IRunConfigurationFactory(parent)
{
registerRunConfiguration<QmakeAndroidRunConfiguration>();
setSupportedProjectType<QmakeProject>();
}
QString QmakeAndroidRunConfigurationFactory::displayNameForId(Core::Id id) const
@@ -88,9 +89,7 @@ QList<Core::Id> QmakeAndroidRunConfigurationFactory::availableCreationIds(Target
bool QmakeAndroidRunConfigurationFactory::canHandle(Target *t) const
{
return t->project()->supportsKit(t->kit())
&& AndroidManager::supportsAndroid(t)
&& qobject_cast<QmakeProject *>(t->project());
return IRunConfigurationFactory::canHandle(t) && AndroidManager::supportsAndroid(t);
}
#ifdef Q_CC_GCC

View File

@@ -441,6 +441,8 @@ DesktopQmakeRunConfigurationFactory::DesktopQmakeRunConfigurationFactory(QObject
{
setObjectName("DesktopQmakeRunConfigurationFactory");
registerRunConfiguration<DesktopQmakeRunConfiguration>();
setSupportedProjectType<QmakeProject>();
setSupportedTargetDeviceTypes({Constants::DESKTOP_DEVICE_TYPE});
}
bool DesktopQmakeRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const
@@ -477,16 +479,6 @@ QString DesktopQmakeRunConfigurationFactory::displayNameForId(Core::Id id) const
return pathFromId(id).toFileInfo().completeBaseName();
}
bool DesktopQmakeRunConfigurationFactory::canHandle(Target *t) const
{
if (!t->project()->supportsKit(t->kit()))
return false;
if (!qobject_cast<QmakeProject *>(t->project()))
return false;
Core::Id devType = DeviceTypeKitInformation::deviceTypeId(t->kit());
return devType == Constants::DESKTOP_DEVICE_TYPE;
}
QList<RunConfiguration *> DesktopQmakeRunConfigurationFactory::runConfigurationsForNode(Target *t, const Node *n)
{
QList<RunConfiguration *> result;

View File

@@ -149,9 +149,6 @@ public:
QList<ProjectExplorer::RunConfiguration *> runConfigurationsForNode(ProjectExplorer::Target *t,
const ProjectExplorer::Node *n) override;
private:
bool canHandle(ProjectExplorer::Target *t) const override;
};
} // namespace Internal

View File

@@ -40,7 +40,6 @@ class QMAKEPROJECTMANAGER_EXPORT QmakeRunConfigurationFactory : public ProjectEx
public:
explicit QmakeRunConfigurationFactory(QObject *parent = 0);
virtual bool canHandle(ProjectExplorer::Target *t) const = 0;
virtual QList<ProjectExplorer::RunConfiguration *> runConfigurationsForNode(ProjectExplorer::Target *t,
const ProjectExplorer::Node *n) = 0;

View File

@@ -41,6 +41,8 @@ QmlProjectRunConfigurationFactory::QmlProjectRunConfigurationFactory(QObject *pa
{
setObjectName("QmlProjectRunConfigurationFactory");
registerRunConfiguration<QmlProjectRunConfiguration>();
setSupportedProjectType<QmlProject>();
setSupportedTargetDeviceTypes({ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE});
}
QList<Core::Id> QmlProjectRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const
@@ -113,16 +115,6 @@ bool QmlProjectRunConfigurationFactory::canClone(ProjectExplorer::Target *parent
return canCreate(parent, source->id());
}
bool QmlProjectRunConfigurationFactory::canHandle(ProjectExplorer::Target *parent) const
{
if (!parent->project()->supportsKit(parent->kit()))
return false;
if (!qobject_cast<QmlProject *>(parent->project()))
return false;
Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(parent->kit());
return deviceType == ProjectExplorer::Constants::DESKTOP_DEVICE_TYPE;
}
} // namespace Internal
} // namespace QmlProjectManager

View File

@@ -43,9 +43,6 @@ public:
bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const override;
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const override;
private:
bool canHandle(ProjectExplorer::Target *parent) const;
};
} // namespace Internal

View File

@@ -45,6 +45,7 @@ QnxRunConfigurationFactory::QnxRunConfigurationFactory(QObject *parent) :
ProjectExplorer::IRunConfigurationFactory(parent)
{
registerRunConfiguration<QnxRunConfiguration>();
setSupportedTargetDeviceTypes({Constants::QNX_QNX_OS_TYPE});
}
QList<Core::Id> QnxRunConfigurationFactory::availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const
@@ -95,14 +96,5 @@ bool QnxRunConfigurationFactory::canClone(ProjectExplorer::Target *parent, Proje
return canCreate(parent, source->id());
}
bool QnxRunConfigurationFactory::canHandle(ProjectExplorer::Target *t) const
{
Core::Id deviceType = ProjectExplorer::DeviceTypeKitInformation::deviceTypeId(t->kit());
if (deviceType != QnxDeviceFactory::deviceType())
return false;
return true;
}
} // namespace Internal
} // namespace Qnx

View File

@@ -44,9 +44,6 @@ public:
bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const override;
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) const override;
private:
bool canHandle(ProjectExplorer::Target *t) const;
};
} // namespace Internal

View File

@@ -50,14 +50,6 @@ static QString stringFromId(Core::Id id)
return QString::fromUtf8(idStr.mid(int(strlen(RemoteLinuxRunConfiguration::IdPrefix))));
}
static bool canHandle(const Target *target)
{
if (!target->project()->supportsKit(target->kit()))
return false;
const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit());
return deviceType == RemoteLinux::Constants::GenericLinuxOsType;
}
// RemoteLinuxRunConfigurationFactory
RemoteLinuxRunConfigurationFactory::RemoteLinuxRunConfigurationFactory(QObject *parent)
@@ -65,6 +57,7 @@ RemoteLinuxRunConfigurationFactory::RemoteLinuxRunConfigurationFactory(QObject *
{
setObjectName("RemoteLinuxRunConfigurationFactory");
registerRunConfiguration<RemoteLinuxRunConfiguration>();
setSupportedTargetDeviceTypes({RemoteLinux::Constants::GenericLinuxOsType});
}
bool RemoteLinuxRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const

View File

@@ -41,21 +41,13 @@ using QmakeProjectManager::QmakeProFile;
namespace WinRt {
namespace Internal {
static bool isKitCompatible(Kit *kit)
{
IDevice::ConstPtr device = DeviceKitInformation::device(kit);
if (!device)
return false;
if (device->type() == Constants::WINRT_DEVICE_TYPE_LOCAL
|| device->type() == Constants::WINRT_DEVICE_TYPE_PHONE
|| device->type() == Constants::WINRT_DEVICE_TYPE_EMULATOR)
return true;
return false;
}
WinRtRunConfigurationFactory::WinRtRunConfigurationFactory()
{
registerRunConfiguration<WinRtRunConfiguration>();
setSupportedProjectType<QmakeProject>();
setSupportedTargetDeviceTypes({Constants::WINRT_DEVICE_TYPE_LOCAL,
Constants::WINRT_DEVICE_TYPE_PHONE,
Constants::WINRT_DEVICE_TYPE_EMULATOR});
}
QList<Core::Id> WinRtRunConfigurationFactory::availableCreationIds(Target *parent,
@@ -95,14 +87,5 @@ bool WinRtRunConfigurationFactory::canClone(Target *parent, RunConfiguration *pr
return false;
}
bool WinRtRunConfigurationFactory::canHandle(Target *parent) const
{
if (!isKitCompatible(parent->kit()))
return false;
if (!qobject_cast<QmakeProject *>(parent->project()))
return false;
return true;
}
} // namespace Internal
} // namespace WinRt

View File

@@ -43,9 +43,6 @@ public:
bool canCreate(ProjectExplorer::Target *parent, Core::Id id) const override;
bool canRestore(ProjectExplorer::Target *parent, const QVariantMap &map) const override;
bool canClone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *product) const override;
private:
bool canHandle(ProjectExplorer::Target *parent) const;
};
} // namespace Internal