diff --git a/src/plugins/baremetal/baremetalplugin.cpp b/src/plugins/baremetal/baremetalplugin.cpp index 77687499c90..0bee8a70e9e 100644 --- a/src/plugins/baremetal/baremetalplugin.cpp +++ b/src/plugins/baremetal/baremetalplugin.cpp @@ -68,6 +68,7 @@ bool BareMetalPlugin::initialize(const QStringList &arguments, QString *errorStr addAutoReleasedObject(new BareMetalDeviceConfigurationFactory); addAutoReleasedObject(new BareMetalRunConfigurationFactory); + addAutoReleasedObject(new BareMetalCustomRunConfigurationFactory); addAutoReleasedObject(new GdbServerProvidersSettingsPage); addAutoReleasedObject(new GdbServerProviderManager); diff --git a/src/plugins/baremetal/baremetalrunconfigurationfactory.cpp b/src/plugins/baremetal/baremetalrunconfigurationfactory.cpp index 4c0c34596ac..8ab6a720150 100644 --- a/src/plugins/baremetal/baremetalrunconfigurationfactory.cpp +++ b/src/plugins/baremetal/baremetalrunconfigurationfactory.cpp @@ -50,6 +50,16 @@ static QString pathFromId(Core::Id id) return QString::fromUtf8(idStr.mid(int(strlen(BareMetalRunConfiguration::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 == BareMetal::Constants::BareMetalOsType; +} + +// BareMetalRunConfigurationFactory + BareMetalRunConfigurationFactory::BareMetalRunConfigurationFactory(QObject *parent) : IRunConfigurationFactory(parent) { @@ -61,23 +71,19 @@ bool BareMetalRunConfigurationFactory::canCreate(Target *parent, Core::Id id) co if (!canHandle(parent)) return false; const QString targetName = QFileInfo(pathFromId(id)).fileName(); - return id == BareMetalCustomRunConfiguration::runConfigId() - || !parent->applicationTargets().targetFilePath(targetName).isEmpty(); + return !parent->applicationTargets().targetFilePath(targetName).isEmpty(); } bool BareMetalRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const { if (!canHandle(parent)) return false; - const Core::Id id = idFromMap(map); - return id == BareMetalCustomRunConfiguration::runConfigId() - || idFromMap(map).name().startsWith(BareMetalRunConfiguration::IdPrefix); + return idFromMap(map).name().startsWith(BareMetalRunConfiguration::IdPrefix); } bool BareMetalRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const { - const BareMetalRunConfiguration * const bmrc - = qobject_cast(source); + auto bmrc = qobject_cast(source); return bmrc && canCreate(parent, source->id()); } @@ -91,46 +97,91 @@ QList BareMetalRunConfigurationFactory::availableCreationIds(Target *p const Core::Id base = Core::Id(BareMetalRunConfiguration::IdPrefix); foreach (const BuildTargetInfo &bti, parent->applicationTargets().list) result << base.withSuffix(bti.projectFilePath.toString() + QLatin1Char('/') + bti.targetName); - result << BareMetalCustomRunConfiguration::runConfigId(); return result; } QString BareMetalRunConfigurationFactory::displayNameForId(Core::Id id) const { - if (id == BareMetalCustomRunConfiguration::runConfigId()) - return BareMetalCustomRunConfiguration::runConfigDefaultDisplayName(); return tr("%1 (on GDB server or hardware debugger)") .arg(QFileInfo(pathFromId(id)).fileName()); } RunConfiguration *BareMetalRunConfigurationFactory::doCreate(Target *parent, Core::Id id) { - if (id == BareMetalCustomRunConfiguration::runConfigId()) - return new BareMetalCustomRunConfiguration(parent); return createHelper(parent, id, pathFromId(id)); } -RunConfiguration *BareMetalRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &map) +RunConfiguration *BareMetalRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &) { - if (idFromMap(map) == BareMetalCustomRunConfiguration::runConfigId()) - return new BareMetalCustomRunConfiguration(parent); return doCreate(parent,Core::Id(BareMetalRunConfiguration::IdPrefix)); } RunConfiguration *BareMetalRunConfigurationFactory::clone(Target *parent, RunConfiguration *source) { QTC_ASSERT(canClone(parent, source), return 0); - if (qobject_cast(source)) - return cloneHelper(parent, source); return cloneHelper(parent, source); } -bool BareMetalRunConfigurationFactory::canHandle(const Target *target) const + +// BareMetalCustomRunConfigurationFactory + +BareMetalCustomRunConfigurationFactory::BareMetalCustomRunConfigurationFactory(QObject *parent) : + IRunConfigurationFactory(parent) { - if (!target->project()->supportsKit(target->kit())) + setObjectName("BareMetalCustomRunConfigurationFactory"); +} + +bool BareMetalCustomRunConfigurationFactory::canCreate(Target *parent, Core::Id id) const +{ + if (!canHandle(parent)) return false; - const Core::Id deviceType = DeviceTypeKitInformation::deviceTypeId(target->kit()); - return deviceType == BareMetal::Constants::BareMetalOsType; + return id == BareMetalCustomRunConfiguration::runConfigId(); +} + +bool BareMetalCustomRunConfigurationFactory::canRestore(Target *parent, const QVariantMap &map) const +{ + if (!canHandle(parent)) + return false; + const Core::Id id = idFromMap(map); + return id == BareMetalCustomRunConfiguration::runConfigId(); +} + +bool BareMetalCustomRunConfigurationFactory::canClone(Target *parent, RunConfiguration *source) const +{ + auto bmrc = qobject_cast(source); + return bmrc && canCreate(parent, source->id()); +} + +QList BareMetalCustomRunConfigurationFactory::availableCreationIds(Target *parent, CreationMode mode) const +{ + Q_UNUSED(mode) + QList result; + if (!canHandle(parent)) + return result; + + result << BareMetalCustomRunConfiguration::runConfigId(); + return result; +} + +QString BareMetalCustomRunConfigurationFactory::displayNameForId(Core::Id) const +{ + return BareMetalCustomRunConfiguration::runConfigDefaultDisplayName(); +} + +RunConfiguration *BareMetalCustomRunConfigurationFactory::doCreate(Target *parent, Core::Id) +{ + return new BareMetalCustomRunConfiguration(parent); +} + +RunConfiguration *BareMetalCustomRunConfigurationFactory::doRestore(Target *parent, const QVariantMap &) +{ + return new BareMetalCustomRunConfiguration(parent); +} + +RunConfiguration *BareMetalCustomRunConfigurationFactory::clone(Target *parent, RunConfiguration *source) +{ + QTC_ASSERT(canClone(parent, source), return 0); + return cloneHelper(parent, source); } } // namespace Internal diff --git a/src/plugins/baremetal/baremetalrunconfigurationfactory.h b/src/plugins/baremetal/baremetalrunconfigurationfactory.h index eff00764e5d..cb57ae23a1d 100644 --- a/src/plugins/baremetal/baremetalrunconfigurationfactory.h +++ b/src/plugins/baremetal/baremetalrunconfigurationfactory.h @@ -48,12 +48,32 @@ public: ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, ProjectExplorer::RunConfiguration *source) override; private: - bool canHandle(const ProjectExplorer::Target *target) const; - ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id) override; ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent, const QVariantMap &map) override; }; +class BareMetalCustomRunConfigurationFactory : public ProjectExplorer::IRunConfigurationFactory +{ + Q_OBJECT + +public: + explicit BareMetalCustomRunConfigurationFactory(QObject *parent = 0); + + QString displayNameForId(Core::Id id) const override; + QList availableCreationIds(ProjectExplorer::Target *parent, CreationMode mode) const override; + + 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; + ProjectExplorer::RunConfiguration *clone(ProjectExplorer::Target *parent, + ProjectExplorer::RunConfiguration *source) override; +private: + ProjectExplorer::RunConfiguration *doCreate(ProjectExplorer::Target *parent, Core::Id id) override; + ProjectExplorer::RunConfiguration *doRestore(ProjectExplorer::Target *parent, + const QVariantMap &map) override; +}; } // namespace Internal } // namespace RemoteLinux