forked from qt-creator/qt-creator
Move some code from QtVersionNumber to FeatureSet
Change-Id: I35f187606c3922809673d44ea2e1f15e91a9e62b Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -86,8 +86,7 @@
|
|||||||
\brief The FeatureSet class is a set of available or required feature sets.
|
\brief The FeatureSet class is a set of available or required feature sets.
|
||||||
|
|
||||||
This class behaves similarly to QFlags. However, instead of enums, Features
|
This class behaves similarly to QFlags. However, instead of enums, Features
|
||||||
relies on string ids
|
relies on string ids and is therefore extendable.
|
||||||
and is therefore extendable.
|
|
||||||
|
|
||||||
\sa Core::Feature
|
\sa Core::Feature
|
||||||
\sa Core::IWizard
|
\sa Core::IWizard
|
||||||
@@ -106,3 +105,39 @@
|
|||||||
|
|
||||||
Returns true if all \a features are available.
|
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 fromString(const QString &str) { return Feature(Id::fromString(str)); }
|
||||||
static Feature fromName(const QByteArray &ba) { return Feature(Id::fromName(ba)); }
|
static Feature fromName(const QByteArray &ba) { return Feature(Id::fromName(ba)); }
|
||||||
|
|
||||||
|
static Feature versionedFeature(const QByteArray &prefix, int major = -1, int minor = -1);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Feature(const Id id) : Id(id) { }
|
explicit Feature(const Id id) : Id(id) { }
|
||||||
};
|
};
|
||||||
@@ -78,6 +80,8 @@ public:
|
|||||||
FeatureSet(const FeatureSet &other) = default;
|
FeatureSet(const FeatureSet &other) = default;
|
||||||
FeatureSet &operator=(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;
|
using QSet<Feature>::isEmpty;
|
||||||
|
|
||||||
bool contains(const Feature &feature) const
|
bool contains(const Feature &feature) const
|
||||||
|
@@ -98,15 +98,7 @@ QtVersionNumber::QtVersionNumber()
|
|||||||
|
|
||||||
FeatureSet QtVersionNumber::features() const
|
FeatureSet QtVersionNumber::features() const
|
||||||
{
|
{
|
||||||
FeatureSet result;
|
return FeatureSet::versionedFeatures(Constants::FEATURE_QT, majorVersion, minorVersion);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QtVersionNumber::operator <(const QtVersionNumber &b) const
|
bool QtVersionNumber::operator <(const QtVersionNumber &b) const
|
||||||
|
Reference in New Issue
Block a user