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)
*/
Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QString &platform,
Id platform,
const QVariantMap &extraValues)
{
QTC_ASSERT(!path.isEmpty(), return 0);
......
......@@ -62,7 +62,7 @@ public:
};
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,
QVariantMap extraValues)
: m_defaultPath(defaultPath),
......@@ -75,7 +75,7 @@ public:
QString defaultPath() const
{ return m_defaultPath; }
QString selectedPlatform() const
Id selectedPlatform() const
{ return m_selectedPlatform; }
QSet<Id> requiredFeatures() const
......@@ -89,7 +89,7 @@ public:
private:
QString m_defaultPath;
QString m_selectedPlatform;
Id m_selectedPlatform;
QSet<Id> m_requiredFeatures;
DialogParameterFlags m_parameterFlags;
QVariantMap m_extraValues;
......@@ -123,7 +123,7 @@ protected:
private:
// 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;
};
......
......@@ -34,6 +34,7 @@
#include <coreplugin/coreicons.h>
#include <coreplugin/icontext.h>
#include <coreplugin/icore.h>
#include <utils/algorithm.h>
#include <utils/qtcassert.h>
#include <QAbstractProxyModel>
......@@ -76,7 +77,7 @@ class PlatformFilterProxyModel : public QSortFilterProxyModel
public:
PlatformFilterProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent) {}
void setPlatform(const QString& platform)
void setPlatform(Core::Id platform)
{
m_platform = platform;
invalidateFilter();
......@@ -95,7 +96,7 @@ public:
return true;
}
private:
QString m_platform;
Core::Id m_platform;
};
class TwoLevelProxyModel : public QAbstractProxyModel
......@@ -270,12 +271,12 @@ void NewDialog::setWizardFactories(QList<IWizardFactory *> factories,
if (m_dummyIcon.isNull())
m_dummyIcon = Core::Icons::NEWFILE.icon();
QStringList availablePlatforms = IWizardFactory::allAvailablePlatforms();
m_ui->comboBox->addItem(tr("All Templates"), QString());
QSet<Id> availablePlatforms = IWizardFactory::allAvailablePlatforms();
m_ui->comboBox->addItem(tr("All Templates"), Id().toSetting());
foreach (const QString &platform, availablePlatforms) {
foreach (Id platform, availablePlatforms) {
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"
......@@ -334,11 +335,10 @@ void NewDialog::showDialog()
show();
}
QString NewDialog::selectedPlatform() const
Id NewDialog::selectedPlatform() const
{
int index = m_ui->comboBox->currentIndex();
return m_ui->comboBox->itemData(index).toString();
const int index = m_ui->comboBox->currentIndex();
return Id::fromSetting(m_ui->comboBox->itemData(index));
}
bool NewDialog::isRunning()
......@@ -422,8 +422,9 @@ void NewDialog::currentItemChanged(const QModelIndex &index)
if (const IWizardFactory *wizard = factoryOfItem(cat)) {
QString desciption = wizard->description();
QStringList displayNamesForSupportedPlatforms;
foreach (const QString &platform, wizard->supportedPlatforms())
foreach (Id platform, wizard->supportedPlatforms())
displayNamesForSupportedPlatforms << IWizardFactory::displayNameForPlatform(platform);
Utils::sort(displayNamesForSupportedPlatforms);
if (!Qt::mightBeRichText(desciption))
desciption.replace(QLatin1Char('\n'), QLatin1String("<br>"));
desciption += QLatin1String("<br><br><b>");
......
......@@ -65,7 +65,7 @@ public:
void setWizardFactories(QList<IWizardFactory*> factories, const QString &defaultLocation, const QVariantMap &extraVariables);
void showDialog();
QString selectedPlatform() const;
Id selectedPlatform() const;
static bool isRunning();
......
......@@ -47,9 +47,9 @@ class CORE_EXPORT IFeatureProvider
public:
virtual ~IFeatureProvider() = default;
virtual QSet<Id> availableFeatures(const QString &platform) const = 0;
virtual QStringList availablePlatforms() const = 0;
virtual QString displayNameForPlatform(const QString &string) const = 0;
virtual QSet<Id> availableFeatures(Id id) const = 0;
virtual QSet<Id> availablePlatforms() const = 0;
virtual QString displayNameForPlatform(Id id) const = 0;
};
} // namespace Core
......
......@@ -250,7 +250,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() {
if (!ICore::isNewItemDialogRunning()) {
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)
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);
......@@ -326,24 +326,24 @@ Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, c
return wizard;
}
bool IWizardFactory::isAvailable(const QString &platformName) const
bool IWizardFactory::isAvailable(Id platformId) const
{
if (platformName.isEmpty())
if (!platformId.isValid())
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))
stringList.append(platform);
platformIds.insert(platform);
}
return stringList;
return platformIds;
}
void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator &creator)
......@@ -351,20 +351,20 @@ void IWizardFactory::registerFactoryCreator(const IWizardFactory::FactoryCreator
s_factoryCreators << creator;
}
QStringList IWizardFactory::allAvailablePlatforms()
QSet<Id> IWizardFactory::allAvailablePlatforms()
{
QStringList platforms;
QSet<Id> platforms;
foreach (const IFeatureProvider *featureManager, s_providerList)
platforms.append(featureManager->availablePlatforms());
platforms.unite(featureManager->availablePlatforms());
return platforms;
}
QString IWizardFactory::displayNameForPlatform(const QString &string)
QString IWizardFactory::displayNameForPlatform(Id i)
{
foreach (const IFeatureProvider *featureManager, s_providerList) {
QString displayName = featureManager->displayNameForPlatform(string);
const QString displayName = featureManager->displayNameForPlatform(i);
if (!displayName.isEmpty())
return displayName;
}
......@@ -420,12 +420,12 @@ QSet<Id> IWizardFactory::pluginFeatures() const
return plugins;
}
QSet<Id> IWizardFactory::availableFeatures(const QString &platformName) const
QSet<Id> IWizardFactory::availableFeatures(Id platformId) const
{
QSet<Id> availableFeatures;
foreach (const IFeatureProvider *featureManager, s_providerList)
availableFeatures.unite(featureManager->availableFeatures(platformName));
availableFeatures.unite(featureManager->availableFeatures(platformId));
return availableFeatures;
}
......
......@@ -89,11 +89,11 @@ public:
QString runPath(const QString &defaultPath);
// 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);
virtual bool isAvailable(const QString &platformName) const;
QStringList supportedPlatforms() const;
virtual bool isAvailable(Id platformId) const;
QSet<Id> supportedPlatforms() const;
typedef std::function<QList<IWizardFactory *>()> FactoryCreator;
static void registerFactoryCreator(const FactoryCreator &creator);
......@@ -102,8 +102,8 @@ public:
static QList<IWizardFactory*> allWizardFactories();
// Utility to find all registered wizards of a certain kind
static QList<IWizardFactory*> wizardFactoriesOfKind(WizardKind kind);
static QStringList allAvailablePlatforms();
static QString displayNameForPlatform(const QString &string);
static QSet<Id> allAvailablePlatforms();
static QString displayNameForPlatform(Id i);
static void registerFeatureProvider(IFeatureProvider *provider);
......@@ -116,9 +116,9 @@ public:
protected:
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;
private:
......
......@@ -53,7 +53,7 @@ struct BaseProjectWizardDialogPrivate {
const int desiredIntroPageId;
Utils::ProjectIntroPage *introPage;
int introPageId;
QString selectedPlatform;
Core::Id selectedPlatform;
QSet<Core::Id> requiredFeatureSet;
};
......@@ -189,12 +189,12 @@ void BaseProjectWizardDialog::addExtensionPages(const QList<QWizardPage *> &wiza
addPage(p);
}
QString BaseProjectWizardDialog::selectedPlatform() const
Core::Id BaseProjectWizardDialog::selectedPlatform() const
{
return d->selectedPlatform;
}
void BaseProjectWizardDialog::setSelectedPlatform(const QString &platform)
void BaseProjectWizardDialog::setSelectedPlatform(Core::Id platform)
{
d->selectedPlatform = platform;
}
......
......@@ -77,8 +77,8 @@ signals:
protected:
Utils::ProjectIntroPage *introPage() const;
QString selectedPlatform() const;
void setSelectedPlatform(const QString &platform);
Core::Id selectedPlatform() const;
void setSelectedPlatform(Core::Id platform);
QSet<Core::Id> requiredFeatures() const;
void setRequiredFeatures(const QSet<Core::Id> &featureSet);
......
......@@ -62,7 +62,7 @@ void JsonKitsPage::initializePage()
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
= evaluate(m_preferredFeatures, wiz->value(QLatin1String("PreferredFeatures")), wiz);
const QSet<Id> required
......
......@@ -357,7 +357,7 @@ JsonWizardFactory::~JsonWizardFactory()
{ }
Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent,
const QString &platform,
Core::Id platform,
const QVariantMap &variables)
{
auto wizard = new JsonWizard(parent);
......@@ -380,7 +380,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
wizard->setValue(i.key(), i.value());
wizard->setValue(QStringLiteral("InitialPath"), path);
wizard->setValue(QStringLiteral("Platform"), platform);
wizard->setValue(QStringLiteral("Platform"), platform.toString());
QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN);
if (kind() == IWizardFactory::FileWizard)
......@@ -483,17 +483,17 @@ QString JsonWizardFactory::localizedString(const QVariant &value)
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;
Utils::MacroExpander expander;
Utils::MacroExpander *e = &expander;
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."),
[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."),
[this, e]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e); });
......
......@@ -91,10 +91,10 @@ public:
static QString localizedString(const QVariant &value);
bool isAvailable(const QString &platformName) const override;
bool isAvailable(Core::Id platformId) const override;
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;
// Create all wizards. As other plugins might register factories for derived
......
......@@ -312,7 +312,7 @@ FileGeneratorFactory::FileGeneratorFactory()
}
JsonWizardGenerator *FileGeneratorFactory::create(Id typeId, const QVariant &data,
const QString &path, const QString &platform,
const QString &path, Id platform,
const QVariantMap &variables)
{
Q_UNUSED(path);
......@@ -352,7 +352,7 @@ ScannerGeneratorFactory::ScannerGeneratorFactory()
}
JsonWizardGenerator *ScannerGeneratorFactory::create(Id typeId, const QVariant &data,
const QString &path, const QString &platform,
const QString &path, Id platform,
const QVariantMap &variables)
{
Q_UNUSED(path);
......
......@@ -79,7 +79,7 @@ public:
QList<Core::Id> supportedIds() const { return m_typeIds; }
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;
// Basic syntax check for the data taken from the wizard.json file:
......@@ -104,7 +104,7 @@ public:
FileGeneratorFactory();
JsonWizardGenerator *create(Core::Id typeId, const QVariant &data,
const QString &path, const QString &platform,
const QString &path, Core::Id platform,
const QVariantMap &variables);
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
};
......@@ -117,7 +117,7 @@ public:
ScannerGeneratorFactory();
JsonWizardGenerator *create(Core::Id typeId, const QVariant &data,
const QString &path, const QString &platform,
const QString &path, Core::Id platform,
const QVariantMap &variables);
bool validateData(Core::Id typeId, const QVariant &data, QString *errorMessage);
};
......
......@@ -613,22 +613,22 @@ bool Kit::isMutable(Id id) const
return d->m_mutable.contains(id);
}
QSet<QString> Kit::availablePlatforms() const
QSet<Id> Kit::availablePlatforms() const
{
QSet<QString> platforms;
QSet<Id> platforms;
foreach (const KitInformation *ki, KitManager::kitInformation())
platforms.unite(ki->availablePlatforms(this));
return platforms;
}
bool Kit::hasPlatform(const QString &platform) const
bool Kit::hasPlatform(Id platform) const
{
if (platform.isEmpty())
if (!platform.isValid())
return true;
return availablePlatforms().contains(platform);
}
QString Kit::displayNameForPlatform(const QString &platform) const
QString Kit::displayNameForPlatform(Id platform) const
{
foreach (const KitInformation *ki, KitManager::kitInformation()) {
const QString displayName = ki->displayNameForPlatform(this, platform);
......
......@@ -121,9 +121,9 @@ public:
void setMutable(Core::Id id, bool b);
bool isMutable(Core::Id id) const;
QSet<QString> availablePlatforms() const;
bool hasPlatform(const QString &platform) const;
QString displayNameForPlatform(const QString &platform) const;
QSet<Core::Id> availablePlatforms() const;
bool hasPlatform(Core::Id platform) const;
QString displayNameForPlatform(Core::Id platform) const;
QSet<Core::Id> availableFeatures() const;
bool hasFeatures(const QSet<Core::Id> &features) const;
Utils::MacroExpander *macroExpander() const;
......
......@@ -40,9 +40,9 @@ namespace Internal {
class KitFeatureProvider : public Core::IFeatureProvider
{
public:
QSet<Core::Id> availableFeatures(const QString &platform) const;
QStringList availablePlatforms() const;
QString displayNameForPlatform(const QString &string) const;
QSet<Core::Id> availableFeatures(Core::Id id) const;
QSet<Core::Id> availablePlatforms() const;
QString displayNameForPlatform(Core::Id id) const;
};
} // namespace Internal
......
......@@ -302,15 +302,15 @@ void KitManager::deregisterKitInformation(KitInformation *ki)
delete ki;
}
QSet<QString> KitManager::availablePlatforms()
QSet<Id> KitManager::availablePlatforms()
{
QSet<QString> platforms;
QSet<Id> platforms;
foreach (const Kit *k, kits())
platforms.unite(k->availablePlatforms());
return platforms;
}
QString KitManager::displayNameForPlatform(const QString &platform)
QString KitManager::displayNameForPlatform(Id platform)
{
foreach (const Kit *k, kits()) {
const QString displayName = k->displayNameForPlatform(platform);
......@@ -320,13 +320,13 @@ QString KitManager::displayNameForPlatform(const QString &platform)
return QString();
}
QSet<Id> KitManager::availableFeatures(const QString &platform)
QSet<Id> KitManager::availableFeatures(Id platform)
{
QSet<Id> features;
foreach (const Kit *k, kits()) {
QSet<QString> kitPlatforms = k->availablePlatforms();
if (kitPlatforms.isEmpty() || kitPlatforms.contains(platform) || platform.isEmpty())
features |= k->availableFeatures();
QSet<Id> kitPlatforms = k->availablePlatforms();
if (kitPlatforms.isEmpty() || kitPlatforms.contains(platform) || !platform.isValid())
features.unite(k->availableFeatures());
}
return features;
}
......@@ -553,13 +553,13 @@ QString KitInformation::displayNamePostfix(const Kit *k) const
return QString();
}
QSet<QString> KitInformation::availablePlatforms(const Kit *k) const
QSet<Id> KitInformation::availablePlatforms(const Kit *k) const
{
Q_UNUSED(k);
return QSet<QString>();
return QSet<Id>();
}
QString KitInformation::displayNameForPlatform(const Kit *k, const QString &platform) const
QString KitInformation::displayNameForPlatform(const Kit *k, Id platform) const
{
Q_UNUSED(k);
Q_UNUSED(platform);
......@@ -588,19 +588,19 @@ void KitInformation::notifyAboutUpdate(Kit *k)
// KitFeatureProvider:
// --------------------------------------------------------------------
QSet<Id> KitFeatureProvider::availableFeatures(const QString &platform) const
QSet<Id> KitFeatureProvider::availableFeatures(Id id) const
{
return KitManager::availableFeatures(platform);
return KitManager::availableFeatures(id);
}
QStringList KitFeatureProvider::availablePlatforms() const
QSet<Id> KitFeatureProvider::availablePlatforms() const
{
return KitManager::availablePlatforms().toList();
return KitManager::availablePlatforms();
}
QString KitFeatureProvider::displayNameForPlatform(const QString &string) const
QString KitFeatureProvider::displayNameForPlatform(Id id) const
{
return KitManager::displayNameForPlatform(string);
return KitManager::displayNameForPlatform(id);
}
} // namespace ProjectExplorer
......@@ -95,8 +95,8 @@ public:
virtual QString displayNamePostfix(const Kit *k) const;
virtual QSet<QString> availablePlatforms(const Kit *k) const;
virtual QString displayNameForPlatform(const Kit *k, const QString &platform) const;
virtual QSet<Core::Id> availablePlatforms(const Kit *k) const;
virtual QString displayNameForPlatform(const Kit *k, Core::Id platform) const;
virtual QSet<Core::Id> availableFeatures(const Kit *k) const;
virtual void addToMacroExpander(ProjectExplorer::Kit *kit, Utils::MacroExpander *expander) const;
......@@ -152,9 +152,9 @@ public:
static void registerKitInformation(KitInformation *ki);
static void deregisterKitInformation(KitInformation *ki);
static QSet<QString> availablePlatforms();
static QString displayNameForPlatform(const QString &platform);
static QSet<Core::Id> availableFeatures(const QString &platform);
static QSet<Core::Id> availablePlatforms();
static QString displayNameForPlatform(Core::Id platform);
static QSet<Core::Id> availableFeatures(Core::Id platform);
static QList<Kit *> sortKits(const QList<Kit *> kits); // Avoid sorting whenever possible!
......
......@@ -110,7 +110,7 @@ GuiAppParameters GuiAppWizardDialog::parameters() const
rc.formFileName = m_filesPage->formFileName();
rc.designerForm = m_filesPage->formInputChecked();