Bootstrap: remove QVariant

I added QT_NO_VARIANT to qconfig-bootstrapped.h to be clearer on what
the #ifs are, but there's no testing of that feature outside of
QT_BOOTSTRAPPED.

Change-Id: I01ec3c774d9943adb903fffd17b7e8ac4340fb89
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Thiago Macieira 2024-02-27 19:20:10 -08:00
parent 4be7c046b1
commit cdbc76360a
10 changed files with 59 additions and 17 deletions

View File

@ -92,6 +92,7 @@
#define QT_FEATURE_topleveldomain -1 #define QT_FEATURE_topleveldomain -1
#define QT_NO_TRANSLATION #define QT_NO_TRANSLATION
#define QT_FEATURE_translation -1 #define QT_FEATURE_translation -1
#define QT_NO_VARIANT -1
#define QT_NO_COMPRESS #define QT_NO_COMPRESS

View File

@ -21,7 +21,6 @@
#include "qeasingcurve.h" #include "qeasingcurve.h"
#endif #endif
#include "quuid.h" #include "quuid.h"
#include "qvariant.h"
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
# include "qregularexpression.h" # include "qregularexpression.h"
@ -1273,6 +1272,9 @@ static constexpr struct : QMetaTypeModuleHelper
QMETATYPE_CONVERTER_ASSIGN(QPointF, QPoint); QMETATYPE_CONVERTER_ASSIGN(QPointF, QPoint);
#endif #endif
QMETATYPE_CONVERTER(QStringList, QString, result = QStringList() << source; return true;);
#ifndef QT_NO_VARIANT
QMETATYPE_CONVERTER(QByteArrayList, QVariantList, QMETATYPE_CONVERTER(QByteArrayList, QVariantList,
result.reserve(source.size()); result.reserve(source.size());
for (const auto &v: source) for (const auto &v: source)
@ -1298,7 +1300,6 @@ static constexpr struct : QMetaTypeModuleHelper
result.append(QVariant(v)); result.append(QVariant(v));
return true; return true;
); );
QMETATYPE_CONVERTER(QStringList, QString, result = QStringList() << source; return true;);
QMETATYPE_CONVERTER(QVariantHash, QVariantMap, QMETATYPE_CONVERTER(QVariantHash, QVariantMap,
for (auto it = source.begin(); it != source.end(); ++it) for (auto it = source.begin(); it != source.end(); ++it)
@ -1310,7 +1311,7 @@ static constexpr struct : QMetaTypeModuleHelper
result.insert(it.key(), it.value()); result.insert(it.key(), it.value());
return true; return true;
); );
#endif // !QT_NO_VARIANT
#ifndef QT_BOOTSTRAPPED #ifndef QT_BOOTSTRAPPED
QMETATYPE_CONVERTER_ASSIGN(QCborValue, QString); QMETATYPE_CONVERTER_ASSIGN(QCborValue, QString);
QMETATYPE_CONVERTER(QString, QCborValue, QMETATYPE_CONVERTER(QString, QCborValue,
@ -2092,7 +2093,6 @@ static bool convertIterableToVariantHash(QMetaType fromType, const void *from, v
h.insert(it.key().toString(), it.value()); h.insert(it.key().toString(), it.value());
return true; return true;
} }
#endif
static bool convertIterableToVariantPair(QMetaType fromType, const void *from, void *to) static bool convertIterableToVariantPair(QMetaType fromType, const void *from, void *to)
{ {
@ -2124,7 +2124,6 @@ static bool convertIterableToVariantPair(QMetaType fromType, const void *from, v
return true; return true;
} }
#ifndef QT_BOOTSTRAPPED
static bool convertToSequentialIterable(QMetaType fromType, const void *from, void *to) static bool convertToSequentialIterable(QMetaType fromType, const void *from, void *to)
{ {
using namespace QtMetaTypePrivate; using namespace QtMetaTypePrivate;
@ -2335,7 +2334,7 @@ static bool convertMetaObject(QMetaType fromType, const void *from, QMetaType to
} }
return false; return false;
} }
#endif #endif // !QT_BOOTSTRAPPED
/*! /*!
\fn bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId) \fn bool QMetaType::convert(const void *from, int fromTypeId, void *to, int toTypeId)
@ -2392,10 +2391,11 @@ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType,
} }
} }
#ifndef QT_BOOTSTRAPPED
# ifndef QT_NO_VARIANT
if (toTypeId == QVariantPair && convertIterableToVariantPair(fromType, from, to)) if (toTypeId == QVariantPair && convertIterableToVariantPair(fromType, from, to))
return true; return true;
#ifndef QT_BOOTSTRAPPED
// handle iterables // handle iterables
if (toTypeId == QVariantList && convertIterableToVariantList(fromType, from, to)) if (toTypeId == QVariantList && convertIterableToVariantList(fromType, from, to))
return true; return true;
@ -2405,6 +2405,7 @@ bool QMetaType::convert(QMetaType fromType, const void *from, QMetaType toType,
if (toTypeId == QVariantHash && convertIterableToVariantHash(fromType, from, to)) if (toTypeId == QVariantHash && convertIterableToVariantHash(fromType, from, to))
return true; return true;
# endif
if (toTypeId == qMetaTypeId<QSequentialIterable>()) if (toTypeId == qMetaTypeId<QSequentialIterable>())
return convertToSequentialIterable(fromType, from, to); return convertToSequentialIterable(fromType, from, to);
@ -2588,7 +2589,8 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType)
if (toTypeId == qMetaTypeId<QAssociativeIterable>()) if (toTypeId == qMetaTypeId<QAssociativeIterable>())
return canConvertToAssociativeIterable(fromType); return canConvertToAssociativeIterable(fromType);
#endif
#ifndef QT_NO_VARIANT
if (toTypeId == QVariantList if (toTypeId == QVariantList
&& canConvert(fromType, QMetaType::fromType<QSequentialIterable>())) { && canConvert(fromType, QMetaType::fromType<QSequentialIterable>())) {
return true; return true;
@ -2598,11 +2600,11 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType)
&& canConvert(fromType, QMetaType::fromType<QAssociativeIterable>())) { && canConvert(fromType, QMetaType::fromType<QAssociativeIterable>())) {
return true; return true;
} }
#endif
if (toTypeId == QVariantPair && hasRegisteredConverterFunction( if (toTypeId == QVariantPair && hasRegisteredConverterFunction(
fromType, QMetaType::fromType<QtMetaTypePrivate::QPairVariantInterfaceImpl>())) fromType, QMetaType::fromType<QtMetaTypePrivate::QPairVariantInterfaceImpl>()))
return true; return true;
#endif
if (fromType.flags() & IsEnumeration) { if (fromType.flags() & IsEnumeration) {
if (toTypeId == QString || toTypeId == QByteArray) if (toTypeId == QString || toTypeId == QByteArray)

View File

@ -92,6 +92,12 @@ inline constexpr int qMetaTypeId();
#else #else
# define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) # define QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F)
#endif #endif
#ifndef QT_NO_VARIANT
# define QT_FOR_EACH_STATIC_QVARIANT(F) \
F(QVariant, 41, QVariant)
#else
# define QT_FOR_EACH_STATIC_QVARIANT(F)
#endif
#define QT_FOR_EACH_STATIC_CORE_CLASS(F)\ #define QT_FOR_EACH_STATIC_CORE_CLASS(F)\
F(QChar, 7, QChar) \ F(QChar, 7, QChar) \
@ -113,7 +119,7 @@ inline constexpr int qMetaTypeId();
F(QPointF, 26, QPointF) \ F(QPointF, 26, QPointF) \
QT_FOR_EACH_STATIC_EASINGCURVE(F) \ QT_FOR_EACH_STATIC_EASINGCURVE(F) \
F(QUuid, 30, QUuid) \ F(QUuid, 30, QUuid) \
F(QVariant, 41, QVariant) \ QT_FOR_EACH_STATIC_QVARIANT(F) \
QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) \ QT_FOR_EACH_STATIC_REGULAR_EXPRESSION(F) \
F(QJsonValue, 45, QJsonValue) \ F(QJsonValue, 45, QJsonValue) \
F(QJsonObject, 46, QJsonObject) \ F(QJsonObject, 46, QJsonObject) \
@ -128,6 +134,7 @@ inline constexpr int qMetaTypeId();
#define QT_FOR_EACH_STATIC_CORE_POINTER(F)\ #define QT_FOR_EACH_STATIC_CORE_POINTER(F)\
F(QObjectStar, 39, QObject*) F(QObjectStar, 39, QObject*)
#ifndef QT_NO_VARIANT
# define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\ # define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\
F(QVariantMap, 8, QVariantMap) \ F(QVariantMap, 8, QVariantMap) \
F(QVariantList, 9, QVariantList) \ F(QVariantList, 9, QVariantList) \
@ -135,6 +142,12 @@ inline constexpr int qMetaTypeId();
F(QVariantPair, 58, QVariantPair) \ F(QVariantPair, 58, QVariantPair) \
F(QByteArrayList, 49, QByteArrayList) \ F(QByteArrayList, 49, QByteArrayList) \
F(QStringList, 11, QStringList) \ F(QStringList, 11, QStringList) \
/**/
#else
# define QT_FOR_EACH_STATIC_CORE_TEMPLATE(F)\
F(QByteArrayList, 49, QByteArrayList) \
F(QStringList, 11, QStringList)
#endif
#if QT_CONFIG(shortcut) #if QT_CONFIG(shortcut)
#define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)\ #define QT_FOR_EACH_STATIC_KEYSEQUENCE_CLASS(F)\
@ -188,12 +201,20 @@ inline constexpr int qMetaTypeId();
F(UInt, -1, uint, "quint32") \ F(UInt, -1, uint, "quint32") \
F(LongLong, -1, qlonglong, "qint64") \ F(LongLong, -1, qlonglong, "qint64") \
F(ULongLong, -1, qulonglong, "quint64") \ F(ULongLong, -1, qulonglong, "quint64") \
F(QByteArrayList, -1, QByteArrayList, "QList<QByteArray>") \
F(QStringList, -1, QStringList, "QList<QString>") \
QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F)
#ifndef QT_NO_VARIANT
#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F) \
F(QVariantList, -1, QVariantList, "QList<QVariant>") \ F(QVariantList, -1, QVariantList, "QList<QVariant>") \
F(QVariantMap, -1, QVariantMap, "QMap<QString,QVariant>") \ F(QVariantMap, -1, QVariantMap, "QMap<QString,QVariant>") \
F(QVariantHash, -1, QVariantHash, "QHash<QString,QVariant>") \ F(QVariantHash, -1, QVariantHash, "QHash<QString,QVariant>") \
F(QVariantPair, -1, QVariantPair, "QPair<QVariant,QVariant>") \ F(QVariantPair, -1, QVariantPair, "QPair<QVariant,QVariant>") \
F(QByteArrayList, -1, QByteArrayList, "QList<QByteArray>") \ /**/
F(QStringList, -1, QStringList, "QList<QString>") \ #else
#define QT_FOR_EACH_STATIC_VARIANT_ALIAS_TYPE(F)
#endif
#define QT_FOR_EACH_STATIC_TYPE(F)\ #define QT_FOR_EACH_STATIC_TYPE(F)\
QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\ QT_FOR_EACH_STATIC_PRIMITIVE_TYPE(F)\

View File

@ -796,15 +796,17 @@ template<typename T> inline T qvariant_cast(QVariant &&v)
return t; return t;
} }
# ifndef QT_NO_VARIANT
template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v) template<> inline QVariant qvariant_cast<QVariant>(const QVariant &v)
{ {
if (v.metaType().id() == QMetaType::QVariant) if (v.metaType().id() == QMetaType::QVariant)
return *reinterpret_cast<const QVariant *>(v.constData()); return *reinterpret_cast<const QVariant *>(v.constData());
return v; return v;
} }
# endif # endif
#endif // QT_MOC
#ifndef QT_NO_DEBUG_STREAM #ifndef QT_NO_DEBUG_STREAM
#if QT_DEPRECATED_SINCE(6, 0) #if QT_DEPRECATED_SINCE(6, 0)
QT_WARNING_PUSH QT_WARNING_PUSH

View File

@ -211,6 +211,7 @@ QJsonArray QJsonArray::fromStringList(const QStringList &list)
return array; return array;
} }
#ifndef QT_NO_VARIANT
/*! /*!
Converts the variant list \a list to a QJsonArray. Converts the variant list \a list to a QJsonArray.
@ -235,6 +236,7 @@ QVariantList QJsonArray::toVariantList() const
{ {
return QCborArray::fromJsonArray(*this).toVariantList(); return QCborArray::fromJsonArray(*this).toVariantList();
} }
#endif // !QT_NO_VARIANT
/*! /*!

View File

@ -421,11 +421,13 @@ QJsonArray QCborArray::toJsonArray() const
return convertToJsonArray(d.data()); return convertToJsonArray(d.data());
} }
#ifndef QT_NO_VARIANT
QJsonArray QJsonPrivate::Variant::toJsonArray(const QVariantList &list) QJsonArray QJsonPrivate::Variant::toJsonArray(const QVariantList &list)
{ {
const auto cborArray = QCborArray::fromVariantList(list); const auto cborArray = QCborArray::fromVariantList(list);
return convertToJsonArray(cborArray.d.data(), ConversionMode::FromVariantToJson); return convertToJsonArray(cborArray.d.data(), ConversionMode::FromVariantToJson);
} }
#endif // !QT_NO_VARIANT
/*! /*!
Recursively converts every \l QCborValue value in this map to JSON using Recursively converts every \l QCborValue value in this map to JSON using
@ -469,6 +471,7 @@ QJsonObject QCborMap::toJsonObject() const
return convertToJsonObject(d.data()); return convertToJsonObject(d.data());
} }
#ifndef QT_NO_VARIANT
QJsonObject QJsonPrivate::Variant::toJsonObject(const QVariantMap &map) QJsonObject QJsonPrivate::Variant::toJsonObject(const QVariantMap &map)
{ {
const auto cborMap = QCborMap::fromVariantMap(map); const auto cborMap = QCborMap::fromVariantMap(map);
@ -578,6 +581,7 @@ QVariant QCborValue::toVariant() const
Q_UNREACHABLE_RETURN(QVariant()); Q_UNREACHABLE_RETURN(QVariant());
} }
#endif // !QT_NO_VARIANT
/*! /*!
Converts the JSON value contained in \a v into its corresponding CBOR value Converts the JSON value contained in \a v into its corresponding CBOR value
@ -631,6 +635,7 @@ QCborValue QCborValue::fromJsonValue(const QJsonValue &v)
return QCborValue(); return QCborValue();
} }
#ifndef QT_NO_VARIANT
static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) static void appendVariant(QCborContainerPrivate *d, const QVariant &variant)
{ {
// Handle strings and byte arrays directly, to avoid creating a temporary // Handle strings and byte arrays directly, to avoid creating a temporary
@ -831,6 +836,7 @@ QCborArray QCborArray::fromVariantList(const QVariantList &list)
appendVariant(a.d.data(), v); appendVariant(a.d.data(), v);
return a; return a;
} }
#endif // !QT_NO_VARIANT
/*! /*!
Converts all JSON items found in the \a array array to CBOR using Converts all JSON items found in the \a array array to CBOR using
@ -862,6 +868,7 @@ QCborArray QCborArray::fromJsonArray(QJsonArray &&array) noexcept
} }
#ifndef QT_NO_VARIANT
/*! /*!
Converts the CBOR values to QVariant using QCborValue::toVariant() and Converts the CBOR values to QVariant using QCborValue::toVariant() and
"stringifies" all the CBOR keys in this map, returning the QVariantMap that "stringifies" all the CBOR keys in this map, returning the QVariantMap that
@ -958,6 +965,7 @@ QCborMap QCborMap::fromVariantHash(const QVariantHash &hash)
} }
return m; return m;
} }
#endif // !QT_NO_VARIANT
/*! /*!
Converts all JSON items found in the \a obj object to CBOR using Converts all JSON items found in the \a obj object to CBOR using

View File

@ -181,6 +181,7 @@ QJsonDocument &QJsonDocument::operator =(const QJsonDocument &other)
Swaps the document \a other with this. This operation is very fast and never fails. Swaps the document \a other with this. This operation is very fast and never fails.
*/ */
#ifndef QT_NO_VARIANT
/*! /*!
Creates a QJsonDocument from the QVariant \a variant. Creates a QJsonDocument from the QVariant \a variant.
@ -231,6 +232,7 @@ QVariant QJsonDocument::toVariant() const
return QJsonArray(container).toVariantList(); return QJsonArray(container).toVariantList();
return QJsonObject(container).toVariantMap(); return QJsonObject(container).toVariantMap();
} }
#endif // !QT_NO_VARIANT
/*! /*!
\enum QJsonDocument::JsonFormat \enum QJsonDocument::JsonFormat

View File

@ -156,7 +156,7 @@ QJsonObject &QJsonObject::operator =(const QJsonObject &other) noexcept = defaul
Swaps the object \a other with this. This operation is very fast and never fails. Swaps the object \a other with this. This operation is very fast and never fails.
*/ */
#ifndef QT_NO_VARIANT
/*! /*!
Converts the variant map \a map to a QJsonObject. Converts the variant map \a map to a QJsonObject.
@ -219,6 +219,7 @@ QVariantHash QJsonObject::toVariantHash() const
{ {
return QCborMap::fromJsonObject(*this).toVariantHash(); return QCborMap::fromJsonObject(*this).toVariantHash();
} }
#endif // !QT_NO_VARIANT
/*! /*!
Returns a list of all keys in this object. Returns a list of all keys in this object.

View File

@ -345,6 +345,7 @@ void QJsonValue::swap(QJsonValue &other) noexcept
error cases as e.g. accessing a non existing key in a QJsonObject. error cases as e.g. accessing a non existing key in a QJsonObject.
*/ */
#ifndef QT_NO_VARIANT
/*! /*!
Converts \a variant to a QJsonValue and returns it. Converts \a variant to a QJsonValue and returns it.
@ -587,6 +588,7 @@ QVariant QJsonValue::toVariant() const
error condition, when trying to read an out of bounds value error condition, when trying to read an out of bounds value
in an array or a non existent key in an object. in an array or a non existent key in an object.
*/ */
#endif // !QT_NO_VARIANT
/*! /*!
Returns the type of the value. Returns the type of the value.
@ -936,10 +938,12 @@ QJsonValueRef &QJsonValueRef::operator =(const QJsonValueRef &ref)
return assignToRef(*this, d->valueAt(index), is_object); return assignToRef(*this, d->valueAt(index), is_object);
} }
#ifndef QT_NO_VARIANT
QVariant QJsonValueConstRef::toVariant() const QVariant QJsonValueConstRef::toVariant() const
{ {
return concrete(*this).toVariant(); return concrete(*this).toVariant();
} }
#endif // !QT_NO_VARIANT
QJsonArray QJsonValueConstRef::toArray() const QJsonArray QJsonValueConstRef::toArray() const
{ {

View File

@ -46,7 +46,6 @@ qt_internal_extend_target(Bootstrap
../../corelib/kernel/qmetacontainer.cpp ../../corelib/kernel/qmetacontainer.cpp
../../corelib/kernel/qmetatype.cpp ../../corelib/kernel/qmetatype.cpp
../../corelib/kernel/qsystemerror.cpp ../../corelib/kernel/qsystemerror.cpp
../../corelib/kernel/qvariant.cpp
../../corelib/plugin/quuid.cpp ../../corelib/plugin/quuid.cpp
../../corelib/serialization/qcborcommon.cpp ../../corelib/serialization/qcborcommon.cpp
../../corelib/serialization/qcborstreamwriter.cpp ../../corelib/serialization/qcborstreamwriter.cpp