forked from qt-creator/qt-creator
Core: Make Id and Feature more separate
Remove Id from the public interfaces of Feature and FeatureSet and disallow implicit conversions from Id to Feature. Change-Id: I33ba692ce82552f0c2b867c6c57b9c8547264243 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -55,32 +55,30 @@ public:
|
|||||||
class CORE_EXPORT Feature : public Id
|
class CORE_EXPORT Feature : public Id
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Feature(Id id) : Id(id) {}
|
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)); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
explicit Feature(const Id id) : Id(id) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class CORE_EXPORT FeatureSet : private QSet<Feature>
|
class CORE_EXPORT FeatureSet : private QSet<Feature>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FeatureSet() {}
|
explicit FeatureSet(Feature id)
|
||||||
|
|
||||||
FeatureSet(Id id)
|
|
||||||
{
|
{
|
||||||
if (id.isValid())
|
if (id.isValid())
|
||||||
insert(id);
|
insert(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
FeatureSet(const FeatureSet &other) : QSet<Feature>(other) {}
|
FeatureSet() = default;
|
||||||
|
FeatureSet(const FeatureSet &other) = default;
|
||||||
|
FeatureSet &operator=(const FeatureSet &other) = default;
|
||||||
|
|
||||||
FeatureSet &operator=(const FeatureSet &other)
|
using QSet<Feature>::isEmpty;
|
||||||
{
|
|
||||||
QSet<Feature>::operator=(other);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isEmpty() const
|
|
||||||
{
|
|
||||||
return QSet<Feature>::isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool contains(const Feature &feature) const
|
bool contains(const Feature &feature) const
|
||||||
{
|
{
|
||||||
@@ -144,7 +142,7 @@ public:
|
|||||||
{
|
{
|
||||||
FeatureSet features;
|
FeatureSet features;
|
||||||
foreach (const QString &i, list)
|
foreach (const QString &i, list)
|
||||||
features |= Feature(Id::fromString(i));
|
features |= Feature::fromString(i);
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Internal {
|
|||||||
|
|
||||||
FormClassWizard::FormClassWizard()
|
FormClassWizard::FormClassWizard()
|
||||||
{
|
{
|
||||||
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QWIDGETS));
|
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QWIDGETS));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString FormClassWizard::headerSuffix() const
|
QString FormClassWizard::headerSuffix() const
|
||||||
|
|||||||
@@ -461,10 +461,8 @@ static inline FeatureSet 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;
|
FeatureSet features;
|
||||||
foreach (const QString &string, stringList) {
|
foreach (const QString &string, stringList)
|
||||||
Feature feature(Id::fromString(string));
|
features |= Feature::fromString(string);
|
||||||
features |= feature;
|
|
||||||
}
|
|
||||||
return features;
|
return features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ QVector<JsonKitsPage::ConditionalFeature> JsonKitsPage::parseFeatures(const QVar
|
|||||||
|
|
||||||
foreach (const QVariant &element, data.toList()) {
|
foreach (const QVariant &element, data.toList()) {
|
||||||
if (element.type() == QVariant::String) {
|
if (element.type() == QVariant::String) {
|
||||||
result.append({ Id::fromString(element.toString()), QVariant(true) });
|
result.append({ Feature::fromString(element.toString()), QVariant(true) });
|
||||||
} else if (element.type() == QVariant::Map) {
|
} else if (element.type() == QVariant::Map) {
|
||||||
const QVariantMap obj = element.toMap();
|
const QVariantMap obj = element.toMap();
|
||||||
const QString feature = obj.value(QLatin1String(KEY_FEATURE)).toString();
|
const QString feature = obj.value(QLatin1String(KEY_FEATURE)).toString();
|
||||||
@@ -177,7 +177,7 @@ QVector<JsonKitsPage::ConditionalFeature> JsonKitsPage::parseFeatures(const QVar
|
|||||||
return QVector<ConditionalFeature>();
|
return QVector<ConditionalFeature>();
|
||||||
}
|
}
|
||||||
|
|
||||||
result.append({ Id::fromString(feature), obj.value(QLatin1String(KEY_CONDITION), true) });
|
result.append({ Feature::fromString(feature), obj.value(QLatin1String(KEY_CONDITION), true) });
|
||||||
} else {
|
} else {
|
||||||
if (errorMessage)
|
if (errorMessage)
|
||||||
*errorMessage = tr("Feature list element is not a string or object.");
|
*errorMessage = tr("Feature list element is not a string or object.");
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public:
|
|||||||
|
|
||||||
class ConditionalFeature {
|
class ConditionalFeature {
|
||||||
public:
|
public:
|
||||||
ConditionalFeature() : feature(Core::Id()) { }
|
ConditionalFeature() = default;
|
||||||
ConditionalFeature(const Core::Feature &f, const QVariant &c) : feature(f), condition(c)
|
ConditionalFeature(const Core::Feature &f, const QVariant &c) : feature(f), condition(c)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ Core::FeatureSet DeviceTypeKitInformation::availableFeatures(const Kit *k) const
|
|||||||
Core::Id id = DeviceTypeKitInformation::deviceTypeId(k);
|
Core::Id id = DeviceTypeKitInformation::deviceTypeId(k);
|
||||||
Core::FeatureSet result;
|
Core::FeatureSet result;
|
||||||
if (id.isValid())
|
if (id.isValid())
|
||||||
result |= Core::Feature(Core::Id::fromString(QString::fromLatin1("DeviceType.") + id.toString()));
|
result |= Core::Feature::fromString(QString::fromLatin1("DeviceType.") + id.toString());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ CustomWidgetWizard::CustomWidgetWizard()
|
|||||||
setDisplayName(tr("Qt Custom Designer Widget"));
|
setDisplayName(tr("Qt Custom Designer Widget"));
|
||||||
setDescription(tr("Creates a Qt Custom Designer Widget or a Custom Widget Collection."));
|
setDescription(tr("Creates a Qt Custom Designer Widget or a Custom Widget Collection."));
|
||||||
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
||||||
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QWIDGETS));
|
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QWIDGETS));
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::BaseFileWizard *CustomWidgetWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
Core::BaseFileWizard *CustomWidgetWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ GuiAppWizard::GuiAppWizard()
|
|||||||
"Includes a Qt Designer-based main window.\n\n"
|
"Includes a Qt Designer-based main window.\n\n"
|
||||||
"Preselects a desktop Qt for building the application if available."));
|
"Preselects a desktop Qt for building the application if available."));
|
||||||
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
||||||
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QWIDGETS));
|
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QWIDGETS));
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::BaseFileWizard *GuiAppWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
Core::BaseFileWizard *GuiAppWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ LibraryWizard::LibraryWizard()
|
|||||||
"<li>a shared C++ library for use with <tt>QPluginLoader</tt> and runtime (Plugins)</li>"
|
"<li>a shared C++ library for use with <tt>QPluginLoader</tt> and runtime (Plugins)</li>"
|
||||||
"<li>a shared or static C++ library for use with another project at linktime</li></ul>"));
|
"<li>a shared or static C++ library for use with another project at linktime</li></ul>"));
|
||||||
setIcon(QIcon(QLatin1String(":/wizards/images/lib.png")));
|
setIcon(QIcon(QLatin1String(":/wizards/images/lib.png")));
|
||||||
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT));
|
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QT));
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::BaseFileWizard *LibraryWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
Core::BaseFileWizard *LibraryWizard::create(QWidget *parent, const Core::WizardDialogParameters ¶meters) const
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ SubdirsProjectWizard::SubdirsProjectWizard()
|
|||||||
setDescription(tr("Creates a qmake-based subdirs project. This allows you to group "
|
setDescription(tr("Creates a qmake-based subdirs project. This allows you to group "
|
||||||
"your projects in a tree structure."));
|
"your projects in a tree structure."));
|
||||||
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
setIcon(QIcon(QLatin1String(":/wizards/images/gui.png")));
|
||||||
setRequiredFeatures(Core::Feature(QtSupport::Constants::FEATURE_QT));
|
setRequiredFeatures(Core::FeatureSet(QtSupport::Constants::FEATURE_QT));
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::BaseFileWizard *SubdirsProjectWizard::create(QWidget *parent,
|
Core::BaseFileWizard *SubdirsProjectWizard::create(QWidget *parent,
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ FeatureSet QtVersionNumber::features() const
|
|||||||
result |= Feature(Constants::FEATURE_QT);
|
result |= Feature(Constants::FEATURE_QT);
|
||||||
if (majorVersion >= 0) {
|
if (majorVersion >= 0) {
|
||||||
QString featureMajor = QString::fromLatin1(Constants::FEATURE_QT) + QString::number(majorVersion);
|
QString featureMajor = QString::fromLatin1(Constants::FEATURE_QT) + QString::number(majorVersion);
|
||||||
result |= Feature(Id::fromString(featureMajor));
|
result |= Feature::fromString(featureMajor);
|
||||||
for (int i = 0; i <= minorVersion; ++i)
|
for (int i = 0; i <= minorVersion; ++i)
|
||||||
result |= Feature(Id::fromString(featureMajor + QLatin1Char('.') + QString::number(i)));
|
result |= Feature::fromString(featureMajor + QLatin1Char('.') + QString::number(i));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user