Commit 4b0a8648 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

FeatureProvider: Remove Feature and FeatureSet



Use Core::Id for Feature and QSet<Core::Id> for FeatureSet.

Change-Id: I12341036bd9eaa82589d92bd3f7d21f2e6b737bd
Reviewed-by: default avatarNiels Weber <niels.weber@theqtcompany.com>
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 19ee4144
...@@ -134,12 +134,12 @@ void AndroidQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const ...@@ -134,12 +134,12 @@ void AndroidQtVersion::parseMkSpec(ProFileEvaluator *evaluator) const
BaseQtVersion::parseMkSpec(evaluator); BaseQtVersion::parseMkSpec(evaluator);
} }
Core::FeatureSet AndroidQtVersion::availableFeatures() const QSet<Core::Id> AndroidQtVersion::availableFeatures() const
{ {
Core::FeatureSet features = QtSupport::BaseQtVersion::availableFeatures(); QSet<Core::Id> features = QtSupport::BaseQtVersion::availableFeatures();
features |= Core::FeatureSet(QtSupport::Constants::FEATURE_MOBILE); features.insert(QtSupport::Constants::FEATURE_MOBILE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_CONSOLE)); features.remove(QtSupport::Constants::FEATURE_QT_CONSOLE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_WEBKIT)); features.remove(QtSupport::Constants::FEATURE_QT_WEBKIT);
return features; return features;
} }
......
...@@ -56,7 +56,7 @@ public: ...@@ -56,7 +56,7 @@ public:
void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const; void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const;
Utils::Environment qmakeRunEnvironment() const; Utils::Environment qmakeRunEnvironment() const;
Core::FeatureSet availableFeatures() const; QSet<Core::Id> availableFeatures() const;
QString platformName() const; QString platformName() const;
QString platformDisplayName() const; QString platformDisplayName() const;
......
...@@ -63,7 +63,7 @@ public: ...@@ -63,7 +63,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, const QString &platform,
const FeatureSet &requiredFeatures, DialogParameterFlags flags, const QSet<Id> &requiredFeatures, DialogParameterFlags flags,
QVariantMap extraValues) QVariantMap extraValues)
: m_defaultPath(defaultPath), : m_defaultPath(defaultPath),
m_selectedPlatform(platform), m_selectedPlatform(platform),
...@@ -78,7 +78,7 @@ public: ...@@ -78,7 +78,7 @@ public:
QString selectedPlatform() const QString selectedPlatform() const
{ return m_selectedPlatform; } { return m_selectedPlatform; }
FeatureSet requiredFeatures() const QSet<Id> requiredFeatures() const
{ return m_requiredFeatures; } { return m_requiredFeatures; }
DialogParameterFlags flags() const DialogParameterFlags flags() const
...@@ -90,7 +90,7 @@ public: ...@@ -90,7 +90,7 @@ public:
private: private:
QString m_defaultPath; QString m_defaultPath;
QString m_selectedPlatform; QString m_selectedPlatform;
FeatureSet m_requiredFeatures; QSet<Id> m_requiredFeatures;
DialogParameterFlags m_parameterFlags; DialogParameterFlags m_parameterFlags;
QVariantMap m_extraValues; QVariantMap m_extraValues;
}; };
......
...@@ -52,92 +52,7 @@ ...@@ -52,92 +52,7 @@
\sa QtSupport::QtVersionManager \sa QtSupport::QtVersionManager
*/ */
/*!
\fn IFeatureProvider::IFeatureProvider()
\internal
*/
/*! /*!
\fn IFeatureProvider::~IFeatureProvider() \fn IFeatureProvider::~IFeatureProvider()
\internal \internal
*/ */
/*!
\fn FetureSet IFeatureProvider::availableFeatures(const QString &platform) const
Returns available features provided by this manager.
\sa FeatureProvider::Features
*/
/*!
\class Core::Feature
\brief The Feature class describes a single feature to be used in
Core::FeatureProvider::Features.
\sa Core::FeaturesSet
\sa Core::IWizard
\sa QtSupport::QtVersionManager
*/
/*!
\class Core::FeatureSet
\brief The FeatureSet class is a set of available or required feature sets.
This class behaves similarly to QFlags. However, instead of enums, Features
relies on string ids and is therefore extendable.
\sa Core::Feature
\sa Core::IWizard
\sa QtSupport::QtVersionManager
*/
/*!
\fn bool FeatureSet::contains(const Feature &feature) const
Returns true if \a feature is available.
*/
/*!
\fn bool FeatureSet::contains(const FeatureSet &features) const
Returns true if all \a features are available.
*/
Core::Feature Core::Feature::versionedFeature(const QByteArray &prefix, int major, int minor)
{
if (major < 0)
return Feature::fromName(prefix);
QByteArray result = prefix + '.';
result += QString::number(major).toLatin1();
if (minor < 0)
return Feature::fromName(result);
return Feature::fromName(result + '.' + QString::number(minor).toLatin1());
}
Core::FeatureSet Core::FeatureSet::versionedFeatures(const QByteArray &prefix, int major, int minor)
{
FeatureSet result;
result |= Feature::fromName(prefix);
if (major < 0)
return result;
const QByteArray majorStr = QString::number(major).toLatin1();
const QByteArray featureMajor = prefix + majorStr;
const QByteArray featureDotMajor = prefix + '.' + majorStr;
result |= Feature::fromName(featureMajor) | Feature::fromName(featureDotMajor);
for (int i = 0; i <= minor; ++i) {
const QByteArray minorStr = QString::number(i).toLatin1();
result |= Feature::fromName(featureMajor + '.' + minorStr)
| Feature::fromName(featureDotMajor + '.' + minorStr);
}
return result;
}
...@@ -45,125 +45,13 @@ class CORE_EXPORT FeatureSet; ...@@ -45,125 +45,13 @@ class CORE_EXPORT FeatureSet;
class CORE_EXPORT IFeatureProvider class CORE_EXPORT IFeatureProvider
{ {
public: public:
IFeatureProvider() {} virtual ~IFeatureProvider() = default;
virtual ~IFeatureProvider() {}
virtual FeatureSet availableFeatures(const QString &platform) const = 0; virtual QSet<Id> availableFeatures(const QString &platform) const = 0;
virtual QStringList availablePlatforms() const = 0; virtual QStringList availablePlatforms() const = 0;
virtual QString displayNameForPlatform(const QString &string) const = 0; virtual QString displayNameForPlatform(const QString &string) const = 0;
}; };
class CORE_EXPORT Feature : public Id
{
public:
Feature() = default;
template <int N> Feature(const char(&ch)[N]) : Id(ch) { }
static Feature fromString(const QString &str) { return Feature(Id::fromString(str)); }
static Feature fromName(const QByteArray &ba) { return Feature(Id::fromName(ba)); }
static Feature versionedFeature(const QByteArray &prefix, int major = -1, int minor = -1);
private:
explicit Feature(const Id id) : Id(id) { }
};
class CORE_EXPORT FeatureSet : private QSet<Feature>
{
public:
explicit FeatureSet(Feature id)
{
if (id.isValid())
insert(id);
}
FeatureSet() = default;
FeatureSet(const FeatureSet &other) = default;
FeatureSet &operator=(const FeatureSet &other) = default;
static FeatureSet versionedFeatures(const QByteArray &prefix, int major, int minor = -1);
using QSet<Feature>::isEmpty;
bool contains(const Feature &feature) const
{
return QSet<Feature>::contains(feature);
}
bool contains(const FeatureSet &features) const
{
return QSet<Feature>::contains(features);
}
void remove(const Feature &feature)
{
QSet<Feature>::remove(feature);
}
void remove(const FeatureSet &features)
{
QSet<Feature>::subtract(features);
}
FeatureSet operator|(const Feature &feature) const
{
FeatureSet copy = *this;
if (feature.isValid())
copy.insert(feature);
return copy;
}
FeatureSet operator|(const FeatureSet &features) const
{
FeatureSet copy = *this;
if (!features.isEmpty())
copy.unite(features);
return copy;
}
FeatureSet &operator|=(const Feature &feature)
{
if (feature.isValid())
insert(feature);
return *this;
}
FeatureSet &operator|=(const FeatureSet &features)
{
if (!features.isEmpty())
unite(features);
return *this;
}
QStringList toStringList() const
{
QStringList stringList;
foreach (const Feature &feature, QSet<Feature>(*this))
stringList.append(feature.toString());
return stringList;
}
static FeatureSet fromStringList(const QStringList &list)
{
FeatureSet features;
foreach (const QString &i, list)
features |= Feature::fromString(i);
return features;
}
};
} // namespace Core } // namespace Core
/*
The following operators have to be defined in the global namespace!
Otherwise "using namespace Core" would hide other | operators
defined in the global namespace (e. g. QFlags).
*/
inline Core::FeatureSet operator |(Core::Feature feature1, Core::Feature feature2)
{ return Core::FeatureSet(feature1) | feature2; }
inline Core::FeatureSet operator|(Core::Feature feature1, Core::FeatureSet feature2)
{ return feature2 | feature1; }
#endif // FEATUREPROVIDER_H #endif // FEATUREPROVIDER_H
...@@ -266,7 +266,9 @@ QSet<Id> Id::fromStringList(const QStringList &list) ...@@ -266,7 +266,9 @@ QSet<Id> Id::fromStringList(const QStringList &list)
QStringList Id::toStringList(const QSet<Id> &ids) QStringList Id::toStringList(const QSet<Id> &ids)
{ {
return Utils::transform(ids.toList(), [](Id i) { return i.toString(); }); QList<Id> idList = ids.toList();
Utils::sort(idList);
return Utils::transform(idList, [](Id i) { return i.toString(); });
} }
/*! /*!
......
...@@ -74,8 +74,7 @@ public: ...@@ -74,8 +74,7 @@ public:
static Id fromName(const QByteArray &ba); // FIXME: avoid. static Id fromName(const QByteArray &ba); // FIXME: avoid.
static Id fromSetting(const QVariant &variant); // Good to use. static Id fromSetting(const QVariant &variant); // Good to use.
static Id versionedId(const QByteArray &prefix, int major, int minor); static Id versionedId(const QByteArray &prefix, int major = -1, int minor = -1);
static QSet<Id> versionedIds(const QByteArray &prefix, int major, int minor);
static QSet<Id> fromStringList(const QStringList &list); static QSet<Id> fromStringList(const QStringList &list);
static QStringList toStringList(const QSet<Id> &ids); static QStringList toStringList(const QSet<Id> &ids);
......
...@@ -407,27 +407,25 @@ void IWizardFactory::clearWizardFactories() ...@@ -407,27 +407,25 @@ void IWizardFactory::clearWizardFactories()
s_areFactoriesLoaded = false; s_areFactoriesLoaded = false;
} }
FeatureSet IWizardFactory::pluginFeatures() const QSet<Id> IWizardFactory::pluginFeatures() const
{ {
static FeatureSet plugins; static QSet<Id> plugins;
if (plugins.isEmpty()) { if (plugins.isEmpty()) {
QStringList list;
// Implicitly create a feature for each plugin loaded: // Implicitly create a feature for each plugin loaded:
foreach (ExtensionSystem::PluginSpec *s, ExtensionSystem::PluginManager::plugins()) { foreach (ExtensionSystem::PluginSpec *s, ExtensionSystem::PluginManager::plugins()) {
if (s->state() == ExtensionSystem::PluginSpec::Running) if (s->state() == ExtensionSystem::PluginSpec::Running)
list.append(s->name()); plugins.insert(Id::fromString(s->name()));
} }
plugins = FeatureSet::fromStringList(list);
} }
return plugins; return plugins;
} }
FeatureSet IWizardFactory::availableFeatures(const QString &platformName) const QSet<Id> IWizardFactory::availableFeatures(const QString &platformName) const
{ {
FeatureSet availableFeatures; QSet<Id> availableFeatures;
foreach (const IFeatureProvider *featureManager, s_providerList) foreach (const IFeatureProvider *featureManager, s_providerList)
availableFeatures |= featureManager->availableFeatures(platformName); availableFeatures.unite(featureManager->availableFeatures(platformName));
return availableFeatures; return availableFeatures;
} }
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
QString category() const { return m_category; } QString category() const { return m_category; }
QString displayCategory() const { return m_displayCategory; } QString displayCategory() const { return m_displayCategory; }
QString descriptionImage() const { return m_descriptionImage; } QString descriptionImage() const { return m_descriptionImage; }
FeatureSet requiredFeatures() const { return m_requiredFeatures; } QSet<Id> requiredFeatures() const { return m_requiredFeatures; }
WizardFlags flags() const { return m_flags; } WizardFlags flags() const { return m_flags; }
void setId(const Id id) { m_id = id; } void setId(const Id id) { m_id = id; }
...@@ -82,8 +82,8 @@ public: ...@@ -82,8 +82,8 @@ public:
void setCategory(const QString &category) { m_category = category; } void setCategory(const QString &category) { m_category = category; }
void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; } void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
void setDescriptionImage(const QString &descriptionImage) { m_descriptionImage = descriptionImage; } void setDescriptionImage(const QString &descriptionImage) { m_descriptionImage = descriptionImage; }
void setRequiredFeatures(const FeatureSet &featureSet) { m_requiredFeatures = featureSet; } void setRequiredFeatures(const QSet<Id> &featureSet) { m_requiredFeatures = featureSet; }
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; } void addRequiredFeature(const Id &feature) { m_requiredFeatures |= feature; }
void setFlags(WizardFlags flags) { m_flags = flags; } void setFlags(WizardFlags flags) { m_flags = flags; }
QString runPath(const QString &defaultPath); QString runPath(const QString &defaultPath);
...@@ -115,8 +115,8 @@ public: ...@@ -115,8 +115,8 @@ public:
const QVariantMap &extraVariables); const QVariantMap &extraVariables);
protected: protected:
FeatureSet pluginFeatures() const; QSet<Id> pluginFeatures() const;
FeatureSet availableFeatures(const QString &platformName) const; QSet<Id> availableFeatures(const QString &platformName) const;
virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform, virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &variables) = 0; const QVariantMap &variables) = 0;
...@@ -135,7 +135,7 @@ private: ...@@ -135,7 +135,7 @@ private:
QString m_displayCategory; QString m_displayCategory;
QString m_descriptionImage; QString m_descriptionImage;
Id m_id; Id m_id;
FeatureSet m_requiredFeatures; QSet<Id> m_requiredFeatures;
WizardKind m_kind = FileWizard; WizardKind m_kind = FileWizard;
WizardFlags m_flags = 0; WizardFlags m_flags = 0;
......
...@@ -43,7 +43,7 @@ namespace Internal { ...@@ -43,7 +43,7 @@ namespace Internal {
FormClassWizard::FormClassWizard() FormClassWizard::FormClassWizard()
{ {
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QWIDGETS)); setRequiredFeatures({ QtSupport::Constants::FEATURE_QWIDGETS });
} }
QString FormClassWizard::headerSuffix() const QString FormClassWizard::headerSuffix() const
......
...@@ -110,12 +110,12 @@ QString IosQtVersion::description() const ...@@ -110,12 +110,12 @@ QString IosQtVersion::description() const
return tr("iOS"); return tr("iOS");
} }
Core::FeatureSet IosQtVersion::availableFeatures() const QSet<Core::Id> IosQtVersion::availableFeatures() const
{ {
Core::FeatureSet features = QtSupport::BaseQtVersion::availableFeatures(); QSet<Core::Id> features = QtSupport::BaseQtVersion::availableFeatures();
features |= Core::FeatureSet(QtSupport::Constants::FEATURE_MOBILE); features.insert(QtSupport::Constants::FEATURE_MOBILE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_CONSOLE)); features.remove(QtSupport::Constants::FEATURE_QT_CONSOLE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_WEBKIT)); features.remove(QtSupport::Constants::FEATURE_QT_WEBKIT);
return features; return features;
} }
......
...@@ -55,7 +55,7 @@ public: ...@@ -55,7 +55,7 @@ public:
void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const override; void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const override;
Core::FeatureSet availableFeatures() const override; QSet<Core::Id> availableFeatures() const override;
QString platformName() const override; QString platformName() const override;
QString platformDisplayName() const override; QString platformDisplayName() const override;
......
...@@ -54,7 +54,7 @@ struct BaseProjectWizardDialogPrivate { ...@@ -54,7 +54,7 @@ struct BaseProjectWizardDialogPrivate {
Utils::ProjectIntroPage *introPage; Utils::ProjectIntroPage *introPage;
int introPageId; int introPageId;
QString selectedPlatform; QString selectedPlatform;
Core::FeatureSet requiredFeatureSet; QSet<Core::Id> requiredFeatureSet;
}; };
BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) : BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) :
...@@ -199,12 +199,12 @@ void BaseProjectWizardDialog::setSelectedPlatform(const QString &platform) ...@@ -199,12 +199,12 @@ void BaseProjectWizardDialog::setSelectedPlatform(const QString &platform)
d->selectedPlatform = platform; d->selectedPlatform = platform;
} }
Core::FeatureSet BaseProjectWizardDialog::requiredFeatures() const QSet<Core::Id> BaseProjectWizardDialog::requiredFeatures() const
{ {
return d->requiredFeatureSet; return d->requiredFeatureSet;
} }
void BaseProjectWizardDialog::setRequiredFeatures(const Core::FeatureSet &featureSet) void BaseProjectWizardDialog::setRequiredFeatures(const QSet<Core::Id> &featureSet)
{ {
d->requiredFeatureSet = featureSet; d->requiredFeatureSet = featureSet;
} }
......
...@@ -80,8 +80,8 @@ protected: ...@@ -80,8 +80,8 @@ protected:
QString selectedPlatform() const; QString selectedPlatform() const;
void setSelectedPlatform(const QString &platform); void setSelectedPlatform(const QString &platform);
Core::FeatureSet requiredFeatures() const; QSet<Core::Id> requiredFeatures() const;
void setRequiredFeatures(const Core::FeatureSet &featureSet); void setRequiredFeatures(const QSet<Core::Id> &featureSet);
private: private:
void init(); void init();
......
...@@ -457,13 +457,13 @@ static inline IWizardFactory::WizardKind kindAttribute(const QXmlStreamReader &r ...@@ -457,13 +457,13 @@ static inline IWizardFactory::WizardKind kindAttribute(const QXmlStreamReader &r
return IWizardFactory::ProjectWizard; return IWizardFactory::ProjectWizard;
} }
static inline FeatureSet readRequiredFeatures(const QXmlStreamReader &reader) static inline QSet<Id> readRequiredFeatures(const QXmlStreamReader &reader)
{ {
QString value = reader.attributes().value(QLatin1String(featuresRequiredC)).toString(); QString value = reader.attributes().value(QLatin1String(featuresRequiredC)).toString();
QStringList stringList = value.split(QLatin1Char(','), QString::SkipEmptyParts); QStringList stringList = value.split(QLatin1Char(','), QString::SkipEmptyParts);
FeatureSet features; QSet<Id> features;
foreach (const QString &string, stringList) foreach (const QString &string, stringList)
features |= Feature::fromString(string); features |= Id::fromString(string);
return features; return features;
} }
......