Commit 72d46620 authored by Daniel Teske's avatar Daniel Teske

ITargetFactory: Make supportedTargetIds() and canCreate() orthogonal

ITargetFactory::supportedTargetIds should return all targets that this
factory can support, regardless of e.g. installed qt versions.

Whereas canCreate() should check the availability of e.g. a qt version.
This makes supportedTargetIds() have the same meaning as
ITargetFactory::supportsTargetId().

Change-Id: I744abb89e441026d6f3f8de21944d780e9b9fa32
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent 6572cfa5
......@@ -118,10 +118,8 @@ bool AutotoolsTargetFactory::supportsTargetId(const QString &id) const
return id == QLatin1String(Constants::DEFAULT_AUTOTOOLS_TARGET_ID);
}
QStringList AutotoolsTargetFactory::supportedTargetIds(Project *parent) const
QStringList AutotoolsTargetFactory::supportedTargetIds() const
{
if (!qobject_cast<AutotoolsProject *>(parent))
return QStringList();
return QStringList() << QLatin1String(Constants::DEFAULT_AUTOTOOLS_TARGET_ID);
}
......
......@@ -84,7 +84,7 @@ public:
bool supportsTargetId(const QString &id) const;
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
......
......@@ -179,10 +179,8 @@ CMakeTargetFactory::~CMakeTargetFactory()
{
}
QStringList CMakeTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList CMakeTargetFactory::supportedTargetIds() const
{
if (!qobject_cast<CMakeProject *>(parent))
return QStringList();
return QStringList() << QLatin1String(DEFAULT_CMAKE_TARGET_ID);
}
QString CMakeTargetFactory::displayNameForId(const QString &id) const
......
......@@ -85,7 +85,7 @@ public:
bool supportsTargetId(const QString &id) const;
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
......
......@@ -101,10 +101,8 @@ bool GenericTargetFactory::supportsTargetId(const QString &id) const
return id == QLatin1String(GENERIC_DESKTOP_TARGET_ID);
}
QStringList GenericTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList GenericTargetFactory::supportedTargetIds() const
{
if (!qobject_cast<GenericProject *>(parent))
return QStringList();
return QStringList() << QLatin1String(GENERIC_DESKTOP_TARGET_ID);
}
......
......@@ -85,7 +85,7 @@ public:
bool supportsTargetId(const QString &id) const;
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
......
......@@ -71,17 +71,12 @@ bool Qt4MaemoTargetFactory::supportsTargetId(const QString &id) const
return MaemoGlobal::isMaemoTargetId(id);
}
QStringList Qt4MaemoTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList Qt4MaemoTargetFactory::supportedTargetIds() const
{
QStringList targetIds;
if (parent && !qobject_cast<Qt4Project *>(parent))
return targetIds;
if (!QtSupport::QtVersionManager::instance()->versionsForTargetId(QLatin1String(MAEMO5_DEVICE_TARGET_ID)).isEmpty())
targetIds << QLatin1String(MAEMO5_DEVICE_TARGET_ID);
if (!QtSupport::QtVersionManager::instance()->versionsForTargetId(QLatin1String(HARMATTAN_DEVICE_TARGET_ID)).isEmpty())
targetIds << QLatin1String(HARMATTAN_DEVICE_TARGET_ID);
if (!QtSupport::QtVersionManager::instance()->versionsForTargetId(QLatin1String(MEEGO_DEVICE_TARGET_ID)).isEmpty())
targetIds << QLatin1String(MEEGO_DEVICE_TARGET_ID);
targetIds << QLatin1String(MAEMO5_DEVICE_TARGET_ID)
<< QLatin1String(HARMATTAN_DEVICE_TARGET_ID)
<< QLatin1String(MEEGO_DEVICE_TARGET_ID);
return targetIds;
}
......@@ -106,12 +101,15 @@ bool Qt4MaemoTargetFactory::canCreate(ProjectExplorer::Project *parent, const QS
{
if (!qobject_cast<Qt4Project *>(parent))
return false;
return supportsTargetId(id);
if (!supportsTargetId(id))
return false;
return !QtSupport::QtVersionManager::instance()->versionsForTargetId(id).isEmpty();
}
bool Qt4MaemoTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
return qobject_cast<Qt4Project *>(parent) && supportsTargetId(idFromMap(map));
}
ProjectExplorer::Target *Qt4MaemoTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
......
......@@ -45,7 +45,7 @@ public:
Qt4MaemoTargetFactory(QObject *parent = 0);
~Qt4MaemoTargetFactory();
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
QIcon iconForId(const QString &id) const;
......
......@@ -312,11 +312,14 @@ bool ProjectWindow::useTargetPage(ProjectExplorer::Project *project)
return false;
if (project->targets().size() > 1)
return true;
QStringList tmp;
int count = 0;
foreach (ITargetFactory *fac, ExtensionSystem::PluginManager::instance()->getObjects<ITargetFactory>()) {
tmp.append(fac->supportedTargetIds(project));
if (tmp.size() > 1)
return true;
foreach (const QString &targetId, fac->supportedTargetIds()) {
if (fac->canCreate(project, targetId))
++count;
if (count > 1)
return true;
}
}
return false;
}
......
......@@ -168,7 +168,7 @@ class PROJECTEXPLORER_EXPORT ITargetFactory :
public:
explicit ITargetFactory(QObject *parent = 0);
virtual QStringList supportedTargetIds(ProjectExplorer::Project *project) const = 0;
virtual QStringList supportedTargetIds() const = 0;
virtual bool supportsTargetId(const QString &id) const = 0;
// used to translate the types to names to display to the user
......
......@@ -316,9 +316,11 @@ void TargetSettingsPanelWidget::updateTargetAddAndRemoveButtons()
ExtensionSystem::PluginManager::instance()->getObjects<ITargetFactory>();
foreach (ITargetFactory *fac, factories) {
foreach (const QString &id, fac->supportedTargetIds(m_project)) {
foreach (const QString &id, fac->supportedTargetIds()) {
if (m_project->target(id))
continue;
if (!fac->canCreate(m_project, id))
continue;
QString displayName = fac->displayNameForId(id);
QAction *action = new QAction(displayName, m_addMenu);
action->setData(QVariant(id));
......
......@@ -102,10 +102,8 @@ bool QmlProjectTargetFactory::supportsTargetId(const QString &id) const
return id == QLatin1String(Constants::QML_VIEWER_TARGET_ID);
}
QStringList QmlProjectTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList QmlProjectTargetFactory::supportedTargetIds() const
{
if (!qobject_cast<QmlProject *>(parent))
return QStringList();
return QStringList() << QLatin1String(Constants::QML_VIEWER_TARGET_ID);
}
......
......@@ -74,7 +74,7 @@ public:
~QmlProjectTargetFactory();
bool supportsTargetId(const QString &id) const;
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
bool canCreate(ProjectExplorer::Project *parent, const QString &id) const;
......
......@@ -69,13 +69,9 @@ bool Qt4DesktopTargetFactory::supportsTargetId(const QString &id) const
return id == QLatin1String(Constants::DESKTOP_TARGET_ID);
}
QStringList Qt4DesktopTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList Qt4DesktopTargetFactory::supportedTargetIds() const
{
if (parent && !qobject_cast<Qt4Project *>(parent))
return QStringList();
const QString desktopId = QLatin1String(Constants::DESKTOP_TARGET_ID);
return QtSupport::QtVersionManager::instance()->supportsTargetId(desktopId) ?
QStringList(desktopId) : QStringList();
return QStringList(QLatin1String(Constants::DESKTOP_TARGET_ID));
}
QString Qt4DesktopTargetFactory::displayNameForId(const QString &id) const
......@@ -103,12 +99,14 @@ bool Qt4DesktopTargetFactory::canCreate(ProjectExplorer::Project *parent, const
{
if (!qobject_cast<Qt4Project *>(parent))
return false;
return supportsTargetId(id);
if (!supportsTargetId(id))
return false;
return QtSupport::QtVersionManager::instance()->supportsTargetId(id);
}
bool Qt4DesktopTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
return qobject_cast<Qt4Project *>(parent) && supportsTargetId(idFromMap(map));
}
ProjectExplorer::Target *Qt4DesktopTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
......
......@@ -44,7 +44,7 @@ public:
Qt4DesktopTargetFactory(QObject *parent = 0);
~Qt4DesktopTargetFactory();
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
QIcon iconForId(const QString &id) const;
......
......@@ -69,13 +69,9 @@ bool Qt4SimulatorTargetFactory::supportsTargetId(const QString &id) const
return id == QLatin1String(Constants::QT_SIMULATOR_TARGET_ID);
}
QStringList Qt4SimulatorTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList Qt4SimulatorTargetFactory::supportedTargetIds() const
{
if (parent && !qobject_cast<Qt4Project *>(parent))
return QStringList();
const QString simulatorId = QLatin1String(Constants::QT_SIMULATOR_TARGET_ID);
return QtSupport::QtVersionManager::instance()->supportsTargetId(simulatorId) ?
QStringList(simulatorId) : QStringList();
return QStringList() << QLatin1String(Constants::QT_SIMULATOR_TARGET_ID);
}
QString Qt4SimulatorTargetFactory::displayNameForId(const QString &id) const
......@@ -103,12 +99,14 @@ bool Qt4SimulatorTargetFactory::canCreate(ProjectExplorer::Project *parent, cons
{
if (!qobject_cast<Qt4Project *>(parent))
return false;
return supportsTargetId(id);
if (!supportsTargetId(id))
return false;
return QtSupport::QtVersionManager::instance()->supportsTargetId(id);
}
bool Qt4SimulatorTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
return qobject_cast<Qt4Project *>(parent) && supportsTargetId(idFromMap(map));
}
ProjectExplorer::Target *Qt4SimulatorTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
......
......@@ -47,7 +47,7 @@ public:
bool supportsTargetId(const QString &id);
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
QString displayNameForId(const QString &id) const;
QIcon iconForId(const QString &id) const;
......
......@@ -74,20 +74,11 @@ bool Qt4SymbianTargetFactory::supportsTargetId(const QString &id) const
|| id == QLatin1String(Constants::S60_EMULATOR_TARGET_ID);
}
QStringList Qt4SymbianTargetFactory::supportedTargetIds(ProjectExplorer::Project *parent) const
QStringList Qt4SymbianTargetFactory::supportedTargetIds() const
{
if (parent && !qobject_cast<Qt4Project *>(parent))
return QStringList();
QStringList ids;
// The QtVersionManager will just check whether theres
const QString deviceId = QLatin1String(Constants::S60_DEVICE_TARGET_ID);
if (QtSupport::QtVersionManager::instance()->supportsTargetId(deviceId))
ids << deviceId;
const QString emulatorId = QLatin1String(Constants::S60_EMULATOR_TARGET_ID);
if (QtSupport::QtVersionManager::instance()->supportsTargetId(emulatorId))
ids << emulatorId;
ids << QLatin1String(Constants::S60_DEVICE_TARGET_ID)
<< QLatin1String(Constants::S60_EMULATOR_TARGET_ID);
return ids;
}
......@@ -109,12 +100,14 @@ bool Qt4SymbianTargetFactory::canCreate(ProjectExplorer::Project *parent, const
{
if (!qobject_cast<Qt4Project *>(parent))
return false;
return supportsTargetId(id);
if (!supportsTargetId(id))
return false;
return QtSupport::QtVersionManager::instance()->supportsTargetId(id);
}
bool Qt4SymbianTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
return canCreate(parent, idFromMap(map));
return qobject_cast<Qt4Project *>(parent) && supportsTargetId(idFromMap(map));
}
ProjectExplorer::Target *Qt4SymbianTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
......
......@@ -44,7 +44,7 @@ public:
Qt4SymbianTargetFactory(QObject *parent = 0);
~Qt4SymbianTargetFactory();
QStringList supportedTargetIds(ProjectExplorer::Project *parent) const;
QStringList supportedTargetIds() const;
bool supportsTargetId(const QString &id) const;
QString displayNameForId(const QString &id) const;
QIcon iconForId(const QString &id) const;
......
......@@ -1251,7 +1251,7 @@ QList<BuildConfigurationInfo> BuildConfigurationInfo::importBuildConfigurations(
QList<Qt4BaseTargetFactory *> factories =
ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
foreach (Qt4BaseTargetFactory *factory, factories) {
foreach (const QString &id, factory->supportedTargetIds(0)) {
foreach (const QString &id, factory->supportedTargetIds()) {
QString expectedBuildprefix = factory->shadowBuildDirectory(proFilePath, id, QString());
QString baseDir = QFileInfo(expectedBuildprefix).absolutePath();
foreach (const QString &dir, QDir(baseDir).entryList()) {
......
......@@ -152,7 +152,7 @@ void TargetSetupPage::setupWidgets()
QList<Qt4BaseTargetFactory *> factories = ExtensionSystem::PluginManager::instance()->getObjects<Qt4BaseTargetFactory>();
bool atLeastOneTargetSelected = false;
foreach (Qt4BaseTargetFactory *factory, factories) {
QStringList ids = factory->supportedTargetIds(0);
QStringList ids = factory->supportedTargetIds();
foreach (const QString &id, ids) {
if (!factory->targetFeatures(id).contains(m_requiredTargetFeatures))
continue;
......@@ -167,7 +167,6 @@ void TargetSetupPage::setupWidgets()
m_selectedPlatform);
Qt4TargetSetupWidget *widget =
factory->createTargetSetupWidget(id, m_proFilePath,
m_minimumQtVersionNumber,
......
......@@ -80,12 +80,9 @@ QSet<QString> EmbeddedLinuxTargetFactory::targetFeatures(const QString & /*id*/)
return features;
}
QStringList EmbeddedLinuxTargetFactory::supportedTargetIds(ProjectExplorer::Project *project) const
QStringList EmbeddedLinuxTargetFactory::supportedTargetIds() const
{
Q_UNUSED(project);
if (QtSupport::QtVersionManager::instance()->supportsTargetId(RemoteLinux::Constants::EMBEDDED_LINUX_TARGET_ID))
return QStringList() << QLatin1String(RemoteLinux::Constants::EMBEDDED_LINUX_TARGET_ID);
return QStringList();
return QStringList() << QLatin1String(RemoteLinux::Constants::EMBEDDED_LINUX_TARGET_ID);
}
bool EmbeddedLinuxTargetFactory::supportsTargetId(const QString &id) const
......@@ -102,7 +99,7 @@ QString EmbeddedLinuxTargetFactory::displayNameForId(const QString &id) const
bool EmbeddedLinuxTargetFactory::canRestore(ProjectExplorer::Project *parent, const QVariantMap &map) const
{
return canCreate(parent, ProjectExplorer::idFromMap(map));
return qobject_cast<Qt4ProjectManager::Qt4Project *>(parent) && supportsTargetId(ProjectExplorer::idFromMap(map));
}
ProjectExplorer::Target *EmbeddedLinuxTargetFactory::restore(ProjectExplorer::Project *parent, const QVariantMap &map)
......@@ -124,7 +121,10 @@ bool EmbeddedLinuxTargetFactory::canCreate(ProjectExplorer::Project *parent, con
if (!project)
return false;
return supportsTargetId(id);
if (!supportsTargetId(id))
return false;
return QtSupport::QtVersionManager::instance()->supportsTargetId(id);
}
ProjectExplorer::Target *EmbeddedLinuxTargetFactory::create(ProjectExplorer::Project *parent,
......
......@@ -51,7 +51,7 @@ public:
QSet<QString> targetFeatures(const QString &id) const;
QStringList supportedTargetIds(ProjectExplorer::Project *project) const;
QStringList supportedTargetIds() const;
bool supportsTargetId(const QString &id) const;
QString displayNameForId(const QString &id) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment