Commit eebe44d3 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Wizards: Turn "platform" into an Id



It used to be a string constant.

Change-Id: Ibea34dc52e97a483989e6d628b908231f4e2dc54
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 4b0a8648
...@@ -80,7 +80,7 @@ static int indexOfFile(const GeneratedFiles &f, const QString &path) ...@@ -80,7 +80,7 @@ static int indexOfFile(const GeneratedFiles &f, const QString &path)
*/ */
Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QString &platform, Id platform,
const QVariantMap &extraValues) const QVariantMap &extraValues)
{ {
QTC_ASSERT(!path.isEmpty(), return 0); QTC_ASSERT(!path.isEmpty(), return 0);
......
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
}; };
Q_DECLARE_FLAGS(DialogParameterFlags, DialogParameterEnum) Q_DECLARE_FLAGS(DialogParameterFlags, DialogParameterEnum)
explicit WizardDialogParameters(const QString &defaultPath, const QString &platform, explicit WizardDialogParameters(const QString &defaultPath, Id platform,
const QSet<Id> &requiredFeatures, DialogParameterFlags flags, const QSet<Id> &requiredFeatures, DialogParameterFlags flags,
QVariantMap extraValues) QVariantMap extraValues)
: m_defaultPath(defaultPath), : m_defaultPath(defaultPath),
...@@ -75,7 +75,7 @@ public: ...@@ -75,7 +75,7 @@ public:
QString defaultPath() const QString defaultPath() const
{ return m_defaultPath; } { return m_defaultPath; }
QString selectedPlatform() const Id selectedPlatform() const
{ return m_selectedPlatform; } { return m_selectedPlatform; }
QSet<Id> requiredFeatures() const QSet<Id> requiredFeatures() const
...@@ -89,7 +89,7 @@ public: ...@@ -89,7 +89,7 @@ public:
private: private:
QString m_defaultPath; QString m_defaultPath;
QString m_selectedPlatform; Id m_selectedPlatform;
QSet<Id> m_requiredFeatures; QSet<Id> m_requiredFeatures;
DialogParameterFlags m_parameterFlags; DialogParameterFlags m_parameterFlags;
QVariantMap m_extraValues; QVariantMap m_extraValues;
...@@ -123,7 +123,7 @@ protected: ...@@ -123,7 +123,7 @@ protected:
private: private:
// IWizard // IWizard
Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform, Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Id platform,
const QVariantMap &extraValues) override; const QVariantMap &extraValues) override;
}; };
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <coreplugin/coreicons.h> #include <coreplugin/coreicons.h>
#include <coreplugin/icontext.h> #include <coreplugin/icontext.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <QAbstractProxyModel> #include <QAbstractProxyModel>
...@@ -76,7 +77,7 @@ class PlatformFilterProxyModel : public QSortFilterProxyModel ...@@ -76,7 +77,7 @@ class PlatformFilterProxyModel : public QSortFilterProxyModel
public: public:
PlatformFilterProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent) {} PlatformFilterProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent) {}
void setPlatform(const QString& platform) void setPlatform(Core::Id platform)
{ {
m_platform = platform; m_platform = platform;
invalidateFilter(); invalidateFilter();
...@@ -95,7 +96,7 @@ public: ...@@ -95,7 +96,7 @@ public:
return true; return true;
} }
private: private:
QString m_platform; Core::Id m_platform;
}; };
class TwoLevelProxyModel : public QAbstractProxyModel class TwoLevelProxyModel : public QAbstractProxyModel
...@@ -270,12 +271,12 @@ void NewDialog::setWizardFactories(QList<IWizardFactory *> factories, ...@@ -270,12 +271,12 @@ void NewDialog::setWizardFactories(QList<IWizardFactory *> factories,
if (m_dummyIcon.isNull()) if (m_dummyIcon.isNull())
m_dummyIcon = Core::Icons::NEWFILE.icon(); m_dummyIcon = Core::Icons::NEWFILE.icon();
QStringList availablePlatforms = IWizardFactory::allAvailablePlatforms(); QSet<Id> availablePlatforms = IWizardFactory::allAvailablePlatforms();
m_ui->comboBox->addItem(tr("All Templates"), QString()); m_ui->comboBox->addItem(tr("All Templates"), Id().toSetting());
foreach (const QString &platform, availablePlatforms) { foreach (Id platform, availablePlatforms) {
const QString displayNameForPlatform = IWizardFactory::displayNameForPlatform(platform); const QString displayNameForPlatform = IWizardFactory::displayNameForPlatform(platform);
m_ui->comboBox->addItem(tr("%1 Templates").arg(displayNameForPlatform), platform); m_ui->comboBox->addItem(tr("%1 Templates").arg(displayNameForPlatform), platform.toSetting());
} }
m_ui->comboBox->setCurrentIndex(0); // "All templates" m_ui->comboBox->setCurrentIndex(0); // "All templates"
...@@ -334,11 +335,10 @@ void NewDialog::showDialog() ...@@ -334,11 +335,10 @@ void NewDialog::showDialog()
show(); show();
} }
QString NewDialog::selectedPlatform() const Id NewDialog::selectedPlatform() const
{ {
int index = m_ui->comboBox->currentIndex(); const int index = m_ui->comboBox->currentIndex();
return Id::fromSetting(m_ui->comboBox->itemData(index));
return m_ui->comboBox->itemData(index).toString();
} }
bool NewDialog::isRunning() bool NewDialog::isRunning()
...@@ -422,8 +422,9 @@ void NewDialog::currentItemChanged(const QModelIndex &index) ...@@ -422,8 +422,9 @@ void NewDialog::currentItemChanged(const QModelIndex &index)
if (const IWizardFactory *wizard = factoryOfItem(cat)) { if (const IWizardFactory *wizard = factoryOfItem(cat)) {
QString desciption = wizard->description(); QString desciption = wizard->description();
QStringList displayNamesForSupportedPlatforms; QStringList displayNamesForSupportedPlatforms;
foreach (const QString &platform, wizard->supportedPlatforms()) foreach (Id platform, wizard->supportedPlatforms())
displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform); displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform);
Utils::sort(displayNamesForSupportedPlatforms);
if (!Qt::mightBeRichText(desciption)) if (!Qt::mightBeRichText(desciption))
desciption.replace(QLatin1Char('\n'), QLatin1String("<br>")); desciption.replace(QLatin1Char('\n'), QLatin1String("<br>"));
desciption += QLatin1String("<br><br><b>"); desciption += QLatin1String("<br><br><b>");
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
void setWizardFactories(QList<IWizardFactory*> factories, const QString &defaultLocation, const QVariantMap &extraVariables); void setWizardFactories(QList<IWizardFactory*> factories, const QString &defaultLocation, const QVariantMap &extraVariables);
void showDialog(); void showDialog();
QString selectedPlatform() const; Id selectedPlatform() const;
static bool isRunning(); static bool isRunning();
......
...@@ -47,9 +47,9 @@ class CORE_EXPORT IFeatureProvider ...@@ -47,9 +47,9 @@ class CORE_EXPORT IFeatureProvider
public: public:
virtual ~IFeatureProvider() = default; virtual ~IFeatureProvider() = default;
virtual QSet<Id> availableFeatures(const QString &platform) const = 0; virtual QSet<Id> availableFeatures(Id id) const = 0;
virtual QStringList availablePlatforms() const = 0; virtual QSet<Id> availablePlatforms() const = 0;
virtual QString displayNameForPlatform(const QString &string) const = 0; virtual QString displayNameForPlatform(Id id) const = 0;
}; };
} // namespace Core } // namespace Core
......
...@@ -250,7 +250,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories() ...@@ -250,7 +250,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() { connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() {
if (!ICore::isNewItemDialogRunning()) { if (!ICore::isNewItemDialogRunning()) {
QString path = newFactory->runPath(QString()); QString path = newFactory->runPath(QString());
newFactory->runWizard(path, ICore::dialogParent(), QString(), QVariantMap()); newFactory->runWizard(path, ICore::dialogParent(), Id(), QVariantMap());
} }
}); });
...@@ -290,7 +290,7 @@ QString IWizardFactory::runPath(const QString &defaultPath) ...@@ -290,7 +290,7 @@ QString IWizardFactory::runPath(const QString &defaultPath)
return path; return path;
} }
Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, const QString &platform, const QVariantMap &variables) Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, Id platform, const QVariantMap &variables)
{ {
QTC_ASSERT(!s_isWizardRunning, return 0); QTC_ASSERT(!s_isWizardRunning, return 0);
...@@ -326,24 +326,24 @@ Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, c ...@@ -326,24 +326,24 @@ Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, c
return wizard; return wizard;
} }
bool IWizardFactory::isAvailable(const QString &platformName) const bool IWizardFactory::isAvailable(Id platformId) const
{ {
if (platformName.isEmpty()) if (!platformId.isValid())
return true; return true;
return availableFeatures(platformName).contains(requiredFeatures()); return availableFeatures(platformId).contains(requiredFeatures());
} }
QStringList IWizardFactory::supportedPlatforms() const QSet<Id> IWizardFactory::supportedPlatforms() const
{ {
QStringList stringList; QSet<Id> platformIds;
foreach (const QString &platform, allAvailablePlatforms()) { foreach (Id platform, allAvailablePlatforms()) {
if (isAvailable(platform)) if (isAvailable(platform))
stringList.append(platform); platformIds.insert(platform);
} }
return stringList; return platformIds;
} }
void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator &creator) void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator &creator)
...@@ -351,20 +351,20 @@ void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator ...@@ -351,20 +351,20 @@ void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator
s_factoryCreators << creator; s_factoryCreators << creator;
} }
QStringList IWizardFactory::allAvailablePlatforms() QSet<Id> IWizardFactory::allAvailablePlatforms()
{ {
QStringList platforms; QSet<Id> platforms;
foreach (const IFeatureProvider *featureManager, s_providerList) foreach (const IFeatureProvider *featureManager, s_providerList)
platforms.append(featureManager->availablePlatforms()); platforms.unite(featureManager->availablePlatforms());
return platforms; return platforms;
} }
QString IWizardFactory::displayNameForPlatform(const QString &string) QString IWizardFactory::displayNameForPlatform(Id i)
{ {
foreach (const IFeatureProvider *featureManager, s_providerList) { foreach (const IFeatureProvider *featureManager, s_providerList) {
QString displayName = featureManager->displayNameForPlatform(string); const QString displayName = featureManager->displayNameForPlatform(i);
if (!displayName.isEmpty()) if (!displayName.isEmpty())
return displayName; return displayName;
} }
...@@ -420,12 +420,12 @@ QSet<Id> IWizardFactory::pluginFeatures() const ...@@ -420,12 +420,12 @@ QSet<Id> IWizardFactory::pluginFeatures() const
return plugins; return plugins;
} }
QSet<Id> IWizardFactory::availableFeatures(const QString &platformName) const QSet<Id> IWizardFactory::availableFeatures(Id platformId) const
{ {
QSet<Id> availableFeatures; QSet<Id> availableFeatures;
foreach (const IFeatureProvider *featureManager, s_providerList) foreach (const IFeatureProvider *featureManager, s_providerList)
availableFeatures.unite(featureManager->availableFeatures(platformName)); availableFeatures.unite(featureManager->availableFeatures(platformId));
return availableFeatures; return availableFeatures;
} }
......
...@@ -89,11 +89,11 @@ public: ...@@ -89,11 +89,11 @@ public:
QString runPath(const QString &defaultPath); QString runPath(const QString &defaultPath);
// Does bookkeeping and the calls runWizardImpl. Please implement that. // Does bookkeeping and the calls runWizardImpl. Please implement that.
virtual Utils::Wizard *runWizard(const QString &path, QWidget *parent, const QString &platform, virtual Utils::Wizard *runWizard(const QString &path, QWidget *parent, Id platform,
const QVariantMap &variables); const QVariantMap &variables);
virtual bool isAvailable(const QString &platformName) const; virtual bool isAvailable(Id platformId) const;
QStringList supportedPlatforms() const; QSet<Id> supportedPlatforms() const;
typedef std::function<QList<IWizardFactory *>()> FactoryCreator; typedef std::function<QList<IWizardFactory *>()> FactoryCreator;
static void registerFactoryCreator(const FactoryCreator &creator); static void registerFactoryCreator(const FactoryCreator &creator);
...@@ -102,8 +102,8 @@ public: ...@@ -102,8 +102,8 @@ public:
static QList<IWizardFactory*> allWizardFactories(); static QList<IWizardFactory*> allWizardFactories();
// Utility to find all registered wizards of a certain kind // Utility to find all registered wizards of a certain kind
static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind); static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind);
static QStringList allAvailablePlatforms(); static QSet<Id> allAvailablePlatforms();
static QString displayNameForPlatform(const QString &string); static QString displayNameForPlatform(Id i);
static void registerFeatureProvider(IFeatureProvider *provider); static void registerFeatureProvider(IFeatureProvider *provider);
...@@ -116,9 +116,9 @@ public: ...@@ -116,9 +116,9 @@ public:
protected: protected:
QSet<Id> pluginFeatures() const; QSet<Id> pluginFeatures() const;
QSet<Id> availableFeatures(const QString &platformName) const; QSet<Id> availableFeatures(Id platformId) const;
virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform, virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Id platform,
const QVariantMap &variables) = 0; const QVariantMap &variables) = 0;
private: private:
......
...@@ -53,7 +53,7 @@ struct BaseProjectWizardDialogPrivate { ...@@ -53,7 +53,7 @@ struct BaseProjectWizardDialogPrivate {
const int desiredIntroPageId; const int desiredIntroPageId;
Utils::ProjectIntroPage *introPage; Utils::ProjectIntroPage *introPage;
int introPageId; int introPageId;
QString selectedPlatform; Core::Id selectedPlatform;
QSet<Core::Id> requiredFeatureSet; QSet<Core::Id> requiredFeatureSet;
}; };
...@@ -189,12 +189,12 @@ void BaseProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wiza ...@@ -189,12 +189,12 @@ void BaseProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wiza
addPage(p); addPage(p);
} }
QString BaseProjectWizardDialog::selectedPlatform() const Core::Id BaseProjectWizardDialog::selectedPlatform() const
{ {
return d->selectedPlatform; return d->selectedPlatform;
} }
void BaseProjectWizardDialog::setSelectedPlatform(const QString &platform) void BaseProjectWizardDialog::setSelectedPlatform(Core::Id platform)
{ {
d->selectedPlatform = platform; d->selectedPlatform = platform;
} }
......
...@@ -77,8 +77,8 @@ signals: ...@@ -77,8 +77,8 @@ signals:
protected: protected:
Utils::ProjectIntroPage *introPage() const; Utils::ProjectIntroPage *introPage() const;
QString selectedPlatform() const; Core::Id selectedPlatform() const;
void setSelectedPlatform(const QString &platform); void setSelectedPlatform(Core::Id platform);
QSet<Core::Id> requiredFeatures() const; QSet<Core::Id> requiredFeatures() const;
void setRequiredFeatures(const QSet<Core::Id> &featureSet); void setRequiredFeatures(const QSet<Core::Id> &featureSet);
......
...@@ -62,7 +62,7 @@ void JsonKitsPage::initializePage() ...@@ -62,7 +62,7 @@ void JsonKitsPage::initializePage()
connect(wiz, &JsonWizard::filesPolished, this, &JsonKitsPage::setupProjectFiles); connect(wiz, &JsonWizard::filesPolished, this, &JsonKitsPage::setupProjectFiles);
const QString platform = wiz->stringValue(QLatin1String("Platform")); const Id platform = Id::fromString(wiz->stringValue(QLatin1String("Platform")));
const QSet<Id> preferred const QSet<Id> preferred
= evaluate(m_preferredFeatures, wiz->value(QLatin1String("PreferredFeatures")), wiz); = evaluate(m_preferredFeatures, wiz->value(QLatin1String("PreferredFeatures")), wiz);
const QSet<Id> required const QSet<Id> required
......
...@@ -357,7 +357,7 @@ JsonWizardFactory::~JsonWizardFactory() ...@@ -357,7 +357,7 @@ JsonWizardFactory::~JsonWizardFactory()
{ } { }
Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QString &platform, Core::Id platform,
const QVariantMap &variables) const QVariantMap &variables)
{ {
auto wizard = new JsonWizard(parent); auto wizard = new JsonWizard(parent);
...@@ -380,7 +380,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa ...@@ -380,7 +380,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
wizard->setValue(i.key(), i.value()); wizard->setValue(i.key(), i.value());
wizard->setValue(QStringLiteral("InitialPath"), path); wizard->setValue(QStringLiteral("InitialPath"), path);
wizard->setValue(QStringLiteral("Platform"), platform); wizard->setValue(QStringLiteral("Platform"), platform.toString());
QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN); QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN);
if (kind() == IWizardFactory::FileWizard) if (kind() == IWizardFactory::FileWizard)
...@@ -483,17 +483,17 @@ QString JsonWizardFactory::localizedString(const QVariant &value) ...@@ -483,17 +483,17 @@ QString JsonWizardFactory::localizedString(const QVariant &value)
return QCoreApplication::translate("ProjectExplorer::JsonWizardFactory", value.toByteArray()); return QCoreApplication::translate("ProjectExplorer::JsonWizardFactory", value.toByteArray());
} }
bool JsonWizardFactory::isAvailable(const QString &platformName) const bool JsonWizardFactory::isAvailable(Core::Id platformId) const
{ {
if (!IWizardFactory::isAvailable(platformName)) // check for required features if (!IWizardFactory::isAvailable(platformId)) // check for required features
return false; return false;
Utils::MacroExpander expander; Utils::MacroExpander expander;
Utils::MacroExpander *e = &expander; Utils::MacroExpander *e = &expander;
expander.registerVariable("Platform", tr("The platform selected for the wizard."), expander.registerVariable("Platform", tr("The platform selected for the wizard."),
[platformName]() { return platformName; }); [platformId]() { return platformId.toString(); });
expander.registerVariable("Features", tr("The features available to this wizard."), expander.registerVariable("Features", tr("The features available to this wizard."),
[this, e, platformName]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(availableFeatures(platformName)), e); }); [this, e, platformId]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(availableFeatures(platformId)), e); });
expander.registerVariable("Plugins", tr("The plugins loaded."), expander.registerVariable("Plugins", tr("The plugins loaded."),
[this, e]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e); }); [this, e]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e); });
......
...@@ -91,10 +91,10 @@ public: ...@@ -91,10 +91,10 @@ public:
static QString localizedString(const QVariant &value); static QString localizedString(const QVariant &value);
bool isAvailable(const QString &platformName) const override; bool isAvailable(Core::Id platformId) const override;
private: private:
Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform, Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Core::Id platform,
const QVariantMap &variables) override; const QVariantMap &variables) override;
// Create all wizards. As other plugins might register factories for derived // Create all wizards. As other plugins might register factories for derived
......
...@@ -312,7 +312,7 @@ FileGeneratorFactory::FileGeneratorFactory() ...@@ -312,7 +312,7 @@ FileGeneratorFactory::FileGeneratorFactory()
} }
JsonWizardGenerator *FileGeneratorFactory::create(Id typeId, const QVariant &data, JsonWizardGenerator *FileGeneratorFactory::create(Id typeId, const QVariant &data,
const QString &path, const QString &platform, const QString &path, Id platform,
const QVariantMap &variables) const QVariantMap &variables)
{ {
Q_UNUSED(path); Q_UNUSED(path);
...@@ -352,7 +352,7 @@ ScannerGeneratorFactory::ScannerGeneratorFactory() ...@@ -352,7 +352,7 @@ ScannerGeneratorFactory::ScannerGeneratorFactory()
} }
JsonWizardGenerator *ScannerGeneratorFactory::create(Id typeId, const QVariant &data, JsonWizardGenerator *ScannerGeneratorFactory::create(Id typeId, const QVariant &data,
const QString &path, const QString &platform, const QString &path, Id platform,
const QVariantMap &variables) const QVariantMap &variables)
{ {
Q_UNUSED(path); Q_UNUSED(path);
......
...@@ -79,7 +79,7 @@ public: ...@@ -79,7 +79,7 @@ public:
QList<Core::Id> supportedIds() const { return m_typeIds; } QList<Core::Id> supportedIds() const { return m_typeIds; }
virtual JsonWizardGenerator *create(Core::Id typeId, const QVariant &data, virtual JsonWizardGenerator *create(Core::Id typeId, const QVariant &data,
const QString &path, const QString &platform, const QString &path, Core::Id platform,
const QVariantMap &variables) = 0; const QVariantMap &variables) = 0;
// Basic syntax check for the data taken from the wizard.json file: // Basic syntax check for the data taken from the wizard.json file:
...@@ -104,7 +104,7 @@ public: ...@@ -104,7 +104,7 @@ public:
FileGeneratorFactory(); FileGeneratorFactory();