Commit 705ac153 authored by Tobias Hunger's avatar Tobias Hunger

Move some code from QtVersionNumber to FeatureSet

Change-Id: I35f187606c3922809673d44ea2e1f15e91a9e62b
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
parent 4de821a8
......@@ -86,8 +86,7 @@
\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.
relies on string ids and is therefore extendable.
\sa Core::Feature
\sa Core::IWizard
......@@ -106,3 +105,39 @@
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;
}
......@@ -61,6 +61,8 @@ public:
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) { }
};
......@@ -78,6 +80,8 @@ public:
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
......
......@@ -98,15 +98,7 @@ QtVersionNumber::QtVersionNumber()
FeatureSet QtVersionNumber::features() const
{
FeatureSet result;
result |= Feature(Constants::FEATURE_QT);
if (majorVersion >= 0) {
QString featureMajor = QString::fromLatin1(Constants::FEATURE_QT) + QString::number(majorVersion);
result |= Feature::fromString(featureMajor);
for (int i = 0; i <= minorVersion; ++i)
result |= Feature::fromString(featureMajor + QLatin1Char('.') + QString::number(i));
}
return result;
return FeatureSet::versionedFeatures(Constants::FEATURE_QT, majorVersion, minorVersion);
}
bool QtVersionNumber::operator <(const QtVersionNumber &b) 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