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
BaseQtVersion::parseMkSpec(evaluator);
}
Core::FeatureSet AndroidQtVersion::availableFeatures() const
QSet<Core::Id> AndroidQtVersion::availableFeatures() const
{
Core::FeatureSet features = QtSupport::BaseQtVersion::availableFeatures();
features |= Core::FeatureSet(QtSupport::Constants::FEATURE_MOBILE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_CONSOLE));
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_WEBKIT));
QSet<Core::Id> features = QtSupport::BaseQtVersion::availableFeatures();
features.insert(QtSupport::Constants::FEATURE_MOBILE);
features.remove(QtSupport::Constants::FEATURE_QT_CONSOLE);
features.remove(QtSupport::Constants::FEATURE_QT_WEBKIT);
return features;
}
......
......@@ -56,7 +56,7 @@ public:
void addToEnvironment(const ProjectExplorer::Kit *k, Utils::Environment &env) const;
Utils::Environment qmakeRunEnvironment() const;
Core::FeatureSet availableFeatures() const;
QSet<Core::Id> availableFeatures() const;
QString platformName() const;
QString platformDisplayName() const;
......
......@@ -63,7 +63,7 @@ public:
Q_DECLARE_FLAGS(DialogParameterFlags, DialogParameterEnum)
explicit WizardDialogParameters(const QString &defaultPath, const QString &platform,
const FeatureSet &requiredFeatures, DialogParameterFlags flags,
const QSet<Id> &requiredFeatures, DialogParameterFlags flags,
QVariantMap extraValues)
: m_defaultPath(defaultPath),
m_selectedPlatform(platform),
......@@ -78,7 +78,7 @@ public:
QString selectedPlatform() const
{ return m_selectedPlatform; }
FeatureSet requiredFeatures() const
QSet<Id> requiredFeatures() const
{ return m_requiredFeatures; }
DialogParameterFlags flags() const
......@@ -90,7 +90,7 @@ public:
private:
QString m_defaultPath;
QString m_selectedPlatform;
FeatureSet m_requiredFeatures;
QSet<Id> m_requiredFeatures;
DialogParameterFlags m_parameterFlags;
QVariantMap m_extraValues;
};
......
......@@ -52,92 +52,7 @@
\sa QtSupport::QtVersionManager
*/
/*!
\fn IFeatureProvider::IFeatureProvider()
\internal
*/
/*!
\fn IFeatureProvider::~IFeatureProvider()
\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;
class CORE_EXPORT IFeatureProvider
{
public:
IFeatureProvider() {}
virtual ~IFeatureProvider() {}
virtual FeatureSet availableFeatures(const QString &platform) const = 0;
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;
};
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
/*
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
......@@ -266,7 +266,9 @@ QSet<Id> Id::fromStringList(const QStringList &list)
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:
static Id fromName(const QByteArray &ba); // FIXME: avoid.
static Id fromSetting(const QVariant &variant); // Good to use.
static Id versionedId(const QByteArray &prefix, int major, int minor);
static QSet<Id> versionedIds(const QByteArray &prefix, int major, int minor);
static Id versionedId(const QByteArray &prefix, int major = -1, int minor = -1);
static QSet<Id> fromStringList(const QStringList &list);
static QStringList toStringList(const QSet<Id> &ids);
......
......@@ -407,27 +407,25 @@ void IWizardFactory::clearWizardFactories()
s_areFactoriesLoaded = false;
}
FeatureSet IWizardFactory::pluginFeatures() const
QSet<Id> IWizardFactory::pluginFeatures() const
{
static FeatureSet plugins;
static QSet<Id> plugins;
if (plugins.isEmpty()) {
QStringList list;
// Implicitly create a feature for each plugin loaded:
foreach (ExtensionSystem::PluginSpec *s, ExtensionSystem::PluginManager::plugins()) {
if (s->state() == ExtensionSystem::PluginSpec::Running)
list.append(s->name());
plugins.insert(Id::fromString(s->name()));
}
plugins = FeatureSet::fromStringList(list);
}
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)
availableFeatures |= featureManager->availableFeatures(platformName);
availableFeatures.unite(featureManager->availableFeatures(platformName));
return availableFeatures;
}
......
......@@ -71,7 +71,7 @@ public:
QString category() const { return m_category; }
QString displayCategory() const { return m_displayCategory; }
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; }
void setId(const Id id) { m_id = id; }
......@@ -82,8 +82,8 @@ public:
void setCategory(const QString &category) { m_category = category; }
void setDisplayCategory(const QString &displayCategory) { m_displayCategory = displayCategory; }
void setDescriptionImage(const QString &descriptionImage) { m_descriptionImage = descriptionImage; }
void setRequiredFeatures(const FeatureSet &featureSet) { m_requiredFeatures = featureSet; }
void addRequiredFeature(const Feature &feature) { m_requiredFeatures |= feature; }
void setRequiredFeatures(const QSet<Id> &featureSet) { m_requiredFeatures = featureSet; }
void addRequiredFeature(const Id &feature) { m_requiredFeatures |= feature; }
void setFlags(WizardFlags flags) { m_flags = flags; }
QString runPath(const QString &defaultPath);
......@@ -115,8 +115,8 @@ public:
const QVariantMap &extraVariables);
protected:
FeatureSet pluginFeatures() const;
FeatureSet availableFeatures(const QString &platformName) const;
QSet<Id> pluginFeatures() const;
QSet<Id> availableFeatures(const QString &platformName) const;
virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, const QString &platform,
const QVariantMap &variables) = 0;
......@@ -135,7 +135,7 @@ private:
QString m_displayCategory;
QString m_descriptionImage;
Id m_id;
FeatureSet m_requiredFeatures;
QSet<Id> m_requiredFeatures;
WizardKind m_kind = FileWizard;
WizardFlags m_flags = 0;
......
......@@ -43,7 +43,7 @@ namespace Internal {
FormClassWizard::FormClassWizard()
{
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QWIDGETS));
setRequiredFeatures({ QtSupport::Constants::FEATURE_QWIDGETS });
}
QString FormClassWizard::headerSuffix() const
......
......@@ -110,12 +110,12 @@ QString IosQtVersion::description() const
return tr("iOS");
}
Core::FeatureSet IosQtVersion::availableFeatures() const
QSet<Core::Id> IosQtVersion::availableFeatures() const
{
Core::FeatureSet features = QtSupport::BaseQtVersion::availableFeatures();
features |= Core::FeatureSet(QtSupport::Constants::FEATURE_MOBILE);
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_CONSOLE));
features.remove(Core::Feature(QtSupport::Constants::FEATURE_QT_WEBKIT));
QSet<Core::Id> features = QtSupport::BaseQtVersion::availableFeatures();
features.insert(QtSupport::Constants::FEATURE_MOBILE);
features.remove(QtSupport::Constants::FEATURE_QT_CONSOLE);
features.remove(QtSupport::Constants::FEATURE_QT_WEBKIT);
return features;
}
......
......@@ -55,7 +55,7 @@ public:
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 platformDisplayName() const override;
......
......@@ -54,7 +54,7 @@ struct BaseProjectWizardDialogPrivate {
Utils::ProjectIntroPage *introPage;
int introPageId;
QString selectedPlatform;
Core::FeatureSet requiredFeatureSet;
QSet<Core::Id> requiredFeatureSet;
};
BaseProjectWizardDialogPrivate::BaseProjectWizardDialogPrivate(Utils::ProjectIntroPage *page, int id) :
......@@ -199,12 +199,12 @@ void BaseProjectWizardDialog::setSelectedPlatform(const QString &platform)
d->selectedPlatform = platform;
}
Core::FeatureSet BaseProjectWizardDialog::requiredFeatures() const
QSet<Core::Id> BaseProjectWizardDialog::requiredFeatures() const
{
return d->requiredFeatureSet;
}
void BaseProjectWizardDialog::setRequiredFeatures(const Core::FeatureSet &featureSet)
void BaseProjectWizardDialog::setRequiredFeatures(const QSet<Core::Id> &featureSet)
{
d->requiredFeatureSet = featureSet;
}
......
......@@ -80,8 +80,8 @@ protected:
QString selectedPlatform() const;
void setSelectedPlatform(const QString &platform);
Core::FeatureSet requiredFeatures() const;
void setRequiredFeatures(const Core::FeatureSet &featureSet);
QSet<Core::Id> requiredFeatures() const;
void setRequiredFeatures(const QSet<Core::Id> &featureSet);
private:
void init();
......
......@@ -457,13 +457,13 @@ static inline IWizardFactory::WizardKind kindAttribute(const QXmlStreamReader &r
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();
QStringList stringList = value.split(QLatin1Char(','), QString::SkipEmptyParts);
FeatureSet features;
QSet<Id> features;
foreach (const QString &string, stringList)
features |= Feature::fromString(string);
features |= Id::fromString(string);
return features;
}
......
......@@ -134,7 +134,7 @@ public:
QString displayName;
QString category;
QString displayCategory;
Core::FeatureSet requiredFeatures;
QSet<Core::Id> requiredFeatures;
Core::IWizardFactory::WizardFlags flags;
};
......
......@@ -63,9 +63,9 @@ void JsonKitsPage::initializePage()
connect(wiz, &JsonWizard::filesPolished, this, &JsonKitsPage::setupProjectFiles);
const QString platform = wiz->stringValue(QLatin1String("Platform"));
const FeatureSet preferred
const QSet<Id> preferred
= evaluate(m_preferredFeatures, wiz->value(QLatin1String("PreferredFeatures")), wiz);
const FeatureSet required
const QSet<Id> required
= evaluate(m_requiredFeatures, wiz->value(QLatin1String("RequiredFeatures")), wiz);
setRequiredKitMatcher(KitMatcher([required](const Kit *k) { return k->hasFeatures(required); }));
......@@ -133,16 +133,16 @@ void JsonKitsPage::setupProjectFiles(const JsonWizard::GeneratorFiles &files)
}
}
FeatureSet JsonKitsPage::evaluate(const QVector<JsonKitsPage::ConditionalFeature> &list,
const QVariant &defaultSet, JsonWizard *wiz)
QSet<Id> JsonKitsPage::evaluate(const QVector<JsonKitsPage::ConditionalFeature> &list,
const QVariant &defaultSet, JsonWizard *wiz)
{
if (list.isEmpty())
return FeatureSet::fromStringList(defaultSet.toStringList());
return Id::fromStringList(defaultSet.toStringList());
FeatureSet features;
QSet<Id> features;
foreach (const ConditionalFeature &f, list) {
if (JsonWizard::boolFromVariant(f.condition, wiz->expander()))
features |= Feature::fromString(wiz->expander()->expand(f.feature));
features.insert(Id::fromString(wiz->expander()->expand(f.feature)));
}
return features;
}
......
......@@ -76,7 +76,7 @@ private:
QVector<ConditionalFeature> m_requiredFeatures;
QVector<ConditionalFeature> m_preferredFeatures;
Core::FeatureSet evaluate(const QVector<ConditionalFeature> &list, const QVariant &defaultSet,
QSet<Core::Id> evaluate(const QVector<ConditionalFeature> &list, const QVariant &defaultSet,
JsonWizard *wiz);
};
......
......@@ -365,15 +365,15 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
wizard->setWindowTitle(displayName());
wizard->setValue(QStringLiteral("WizardDir"), m_wizardDir);
Core::FeatureSet tmp = requiredFeatures();
tmp.remove(pluginFeatures());
wizard->setValue(QStringLiteral("RequiredFeatures"), tmp.toStringList());
QSet<Core::Id> tmp = requiredFeatures();
tmp.subtract(pluginFeatures());
wizard->setValue(QStringLiteral("RequiredFeatures"), Core::Id::toStringList(tmp));
tmp = m_preferredFeatures;
tmp.remove(pluginFeatures());
wizard->setValue(QStringLiteral("PreferredFeatures"), tmp.toStringList());
tmp.subtract(pluginFeatures());
wizard->setValue(QStringLiteral("PreferredFeatures"), Core::Id::toStringList(tmp));
wizard->setValue(QStringLiteral("Features"), availableFeatures(platform).toStringList());
wizard->setValue(QStringLiteral("Plugins"), pluginFeatures().toStringList());
wizard->setValue(QStringLiteral("Features"), Core::Id::toStringList(availableFeatures(platform)));
wizard->setValue(QStringLiteral("Plugins"), Core::Id::toStringList(pluginFeatures()));
// Add data to wizard:
for (auto i = variables.constBegin(); i != variables.constEnd(); ++i)
......@@ -493,9 +493,9 @@ bool JsonWizardFactory::isAvailable(const QString &platformName) const
expander.registerVariable("Platform", tr("The platform selected for the wizard."),
[platformName]() { return platformName; });
expander.registerVariable("Features", tr("The features available to this wizard."),
[this, e, platformName]() { return JsonWizard::stringListToArrayString(availableFeatures(platformName).toStringList(), e); });
[this, e, platformName]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(availableFeatures(platformName)), e); });
expander.registerVariable("Plugins", tr("The plugins loaded."),
[this, e]() { return JsonWizard::stringListToArrayString(pluginFeatures().toStringList(), e); });
[this, e]() { return JsonWizard::stringListToArrayString(Core::Id::toStringList(pluginFeatures()), e); });
return JsonWizard::boolFromVariant(m_enabledExpression, &expander);
}
......@@ -564,9 +564,9 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
setDescriptionImage(strVal);
}
setRequiredFeatures(Core::FeatureSet::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList()));
m_preferredFeatures = Core::FeatureSet::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList());
m_preferredFeatures |= requiredFeatures();
setRequiredFeatures(Core::Id::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList()));
m_preferredFeatures = Core::Id::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList());
m_preferredFeatures.unite(requiredFeatures());