Deprecate the static int based API in QMetaType
And remove one of the type id to name mapping that still existed in QMetaType. QMetaTypeInterface can provide that, so there's no need to have a second copy of the data. qMetaTypeTypeInternal() can still map all the names of all builtin types to ids. That functionality is for now still required by moc and can't be removed yet. Change-Id: Ib4f8e9c71e1e7d99d52da9e44477c9a1f1805e57 Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
92b3767632
commit
1697fbdf05
@ -294,7 +294,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
|
||||
else if (type == QLatin1String("regex"))
|
||||
id = QMetaType::QRegularExpression;
|
||||
else
|
||||
id = QMetaType::type(type.toLatin1());
|
||||
id = QMetaType::fromName(type.toLatin1()).id();
|
||||
if (id == QMetaType::UnknownType) {
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML: unknown type '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
|
||||
@ -302,7 +302,7 @@ static QVariant variantFromXml(QXmlStreamReader &xml, Converter::Options options
|
||||
}
|
||||
|
||||
result = text.toString();
|
||||
if (!result.convert(id)) {
|
||||
if (!result.convert(QMetaType(id))) {
|
||||
fprintf(stderr, "%lld:%lld: Invalid XML: could not parse content as type '%s'.\n",
|
||||
xml.lineNumber(), xml.columnNumber(), qPrintable(type.toString()));
|
||||
exit(EXIT_FAILURE);
|
||||
@ -433,7 +433,7 @@ static void variantToXml(QXmlStreamWriter &xml, const QVariant &v)
|
||||
// does this convert to string?
|
||||
const char *typeName = v.typeName();
|
||||
QVariant copy = v;
|
||||
if (copy.convert(QMetaType::QString)) {
|
||||
if (copy.convert(QMetaType(QMetaType::QString))) {
|
||||
xml.writeAttribute(typeString, QString::fromLatin1(typeName));
|
||||
xml.writeCharacters(copy.toString());
|
||||
} else {
|
||||
|
@ -194,8 +194,8 @@ void Browser::showMetaData(const QString &t)
|
||||
QSqlField fld = rec.field(i);
|
||||
model->setData(model->index(i, 0), fld.name());
|
||||
model->setData(model->index(i, 1), fld.typeID() == -1
|
||||
? QString(QMetaType::typeName(fld.type()))
|
||||
: QString("%1 (%2)").arg(QMetaType::typeName(fld.type())).arg(fld.typeID()));
|
||||
? QString(fld.metaType().name())
|
||||
: QString("%1 (%2)").arg(fld.metaType().name()).arg(fld.typeID()));
|
||||
model->setData(model->index(i, 2), fld.length());
|
||||
model->setData(model->index(i, 3), fld.precision());
|
||||
model->setData(model->index(i, 4), fld.requiredStatus() == -1 ? QVariant("?")
|
||||
|
@ -334,7 +334,7 @@ void VariantDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
break;
|
||||
default:
|
||||
value = text;
|
||||
value.convert(originalValue.userType());
|
||||
value.convert(originalValue.metaType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -171,7 +171,7 @@ static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint ty
|
||||
if (typeInfo & IsUnresolvedType) {
|
||||
return rawStringData(mo, typeInfo & TypeNameIndexMask);
|
||||
} else {
|
||||
return QMetaType::typeName(typeInfo);
|
||||
return QMetaType(typeInfo).name();
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,9 +180,7 @@ static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeIn
|
||||
if (typeInfo & IsUnresolvedType) {
|
||||
return stringData(mo, typeInfo & TypeNameIndexMask);
|
||||
} else {
|
||||
// ### Use the QMetaType::typeName() that returns QByteArray
|
||||
const char *t = QMetaType::typeName(typeInfo);
|
||||
return QByteArray::fromRawData(t, qstrlen(t));
|
||||
return QMetaType(typeInfo).name();
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +188,7 @@ static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo)
|
||||
{
|
||||
if (!(typeInfo & IsUnresolvedType))
|
||||
return typeInfo;
|
||||
return QMetaType::type(rawStringData(mo, typeInfo & TypeNameIndexMask));
|
||||
return QMetaType::fromName(rawStringData(mo, typeInfo & TypeNameIndexMask)).id();
|
||||
}
|
||||
|
||||
class QMetaMethodPrivate : public QMetaMethod
|
||||
@ -1739,7 +1737,7 @@ const char *QMetaMethodPrivate::rawReturnTypeName() const
|
||||
if (typeInfo & IsUnresolvedType)
|
||||
return rawStringData(mobj, typeInfo & TypeNameIndexMask);
|
||||
else
|
||||
return QMetaType::typeName(typeInfo);
|
||||
return QMetaType(typeInfo).name();
|
||||
}
|
||||
|
||||
int QMetaMethodPrivate::returnType() const
|
||||
@ -2230,7 +2228,7 @@ bool QMetaMethod::invoke(QObject *object,
|
||||
if (qstrcmp(normalized.constData(), retType) != 0) {
|
||||
// String comparison failed, try compare the metatype.
|
||||
int t = returnType();
|
||||
if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
|
||||
if (t == QMetaType::UnknownType || t != QMetaType::fromName(normalized).id())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -2316,7 +2314,7 @@ bool QMetaMethod::invoke(QObject *object,
|
||||
|
||||
int argIndex = 0;
|
||||
for (int i = 1; i < paramCount; ++i) {
|
||||
types[i] = QMetaType::type(typeNames[i]);
|
||||
types[i] = QMetaType::fromName(typeNames[i]).id();
|
||||
if (types[i] == QMetaType::UnknownType && param[i]) {
|
||||
// Try to register the type and try again before reporting an error.
|
||||
void *argv[] = { &types[i], &argIndex };
|
||||
@ -2329,7 +2327,7 @@ bool QMetaMethod::invoke(QObject *object,
|
||||
}
|
||||
}
|
||||
if (types[i] != QMetaType::UnknownType) {
|
||||
args[i] = QMetaType::create(types[i], param[i]);
|
||||
args[i] = QMetaType(types[i]).create(param[i]);
|
||||
++argIndex;
|
||||
}
|
||||
}
|
||||
@ -2453,7 +2451,7 @@ bool QMetaMethod::invokeOnGadget(void *gadget,
|
||||
if (qstrcmp(normalized.constData(), retType) != 0) {
|
||||
// String comparison failed, try compare the metatype.
|
||||
int t = returnType();
|
||||
if (t == QMetaType::UnknownType || t != QMetaType::type(normalized))
|
||||
if (t == QMetaType::UnknownType || t != QMetaType::fromName(normalized).id())
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ enum EnumFlags {
|
||||
EnumIsScoped = 0x2
|
||||
};
|
||||
|
||||
extern int qMetaTypeTypeInternal(const char *);
|
||||
Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *);
|
||||
|
||||
class QArgumentType
|
||||
{
|
||||
@ -138,7 +138,7 @@ public:
|
||||
QByteArray name() const
|
||||
{
|
||||
if (_type && _name.isEmpty())
|
||||
const_cast<QArgumentType *>(this)->_name = QMetaType::typeName(_type);
|
||||
const_cast<QArgumentType *>(this)->_name = QMetaType(_type).name();
|
||||
return _name;
|
||||
}
|
||||
bool operator==(const QArgumentType &other) const
|
||||
|
@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE
|
||||
namespace QtPrivate {
|
||||
Q_CORE_EXPORT bool isBuiltinType(const QByteArray &type)
|
||||
{
|
||||
int id = QMetaType::type(type);
|
||||
int id = QMetaType::fromName(type).id();
|
||||
if (!id && !type.isEmpty() && type != "void")
|
||||
return false;
|
||||
return (id < QMetaType::User);
|
||||
@ -1316,7 +1316,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
||||
const QByteArray &typeName = (i < 0) ? method.returnType : paramTypeNames.at(i);
|
||||
int typeInfo;
|
||||
if (QtPrivate::isBuiltinType(typeName))
|
||||
typeInfo = QMetaType::type(typeName);
|
||||
typeInfo = QMetaType::fromName(typeName).id();
|
||||
else
|
||||
typeInfo = IsUnresolvedType | strings.enter(typeName);
|
||||
if (buf)
|
||||
@ -1343,7 +1343,7 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
||||
|
||||
int typeInfo;
|
||||
if (QtPrivate::isBuiltinType(prop.type))
|
||||
typeInfo = QMetaType::type(prop.type);
|
||||
typeInfo = QMetaType::fromName(prop.type).id();
|
||||
else
|
||||
typeInfo = IsUnresolvedType | strings.enter(prop.type);
|
||||
|
||||
@ -1438,23 +1438,23 @@ static int buildMetaObject(QMetaObjectBuilderPrivate *d, char *buf,
|
||||
if (buf) {
|
||||
meta->d.metaTypes = types;
|
||||
for (const auto &prop : d->properties) {
|
||||
QMetaType mt(QMetaType::type(prop.type));
|
||||
QMetaType mt = QMetaType::fromName(prop.type);
|
||||
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
|
||||
types++;
|
||||
}
|
||||
for (const auto &method: d->methods) {
|
||||
QMetaType mt(QMetaType::type(method.returnType));
|
||||
QMetaType mt(QMetaType::fromName(method.returnType).id());
|
||||
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
|
||||
types++;
|
||||
for (const auto ¶meterType: method.parameterTypes()) {
|
||||
QMetaType mt(QMetaType::type(parameterType));
|
||||
QMetaType mt = QMetaType::fromName(parameterType);
|
||||
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
|
||||
types++;
|
||||
}
|
||||
}
|
||||
for (const auto &constructor: d->constructors) {
|
||||
for (const auto ¶meterType: constructor.parameterTypes()) {
|
||||
QMetaType mt(QMetaType::type(parameterType));
|
||||
QMetaType mt = QMetaType::fromName(parameterType);
|
||||
*types = reinterpret_cast<QtPrivate::QMetaTypeInterface *&>(mt);
|
||||
types++;
|
||||
}
|
||||
|
@ -539,7 +539,7 @@ int QMetaType::alignOf() const
|
||||
|
||||
Returns flags of the type for which this QMetaType instance was constructed.
|
||||
|
||||
\sa QMetaType::TypeFlags, QMetaType::typeFlags()
|
||||
\sa QMetaType::TypeFlags, QMetaType::flags()
|
||||
*/
|
||||
QMetaType::TypeFlags QMetaType::flags() const
|
||||
{
|
||||
@ -566,7 +566,7 @@ QMetaType::TypeFlags QMetaType::flags() const
|
||||
returns the QMetaObject of the enclosing object if the enum was registered as a Q_ENUM or
|
||||
\nullptr otherwise
|
||||
|
||||
\sa QMetaType::metaObjectForType(), QMetaType::flags()
|
||||
\sa QMetaType::flags()
|
||||
*/
|
||||
const QMetaObject *QMetaType::metaObject() const
|
||||
{
|
||||
@ -1620,7 +1620,7 @@ bool QMetaType::registerConverterFunction(const ConverterFunction &f, int from,
|
||||
{
|
||||
if (!customTypesConversionRegistry()->insertIfNotContains(qMakePair(from, to), f)) {
|
||||
qWarning("Type conversion already registered from type %s to type %s",
|
||||
QMetaType::typeName(from), QMetaType::typeName(to));
|
||||
QMetaType(from).name(), QMetaType(to).name());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -2194,107 +2194,16 @@ bool QMetaType::hasRegisteredConverterFunction(int fromTypeId, int toTypeId)
|
||||
return customTypesConversionRegistry()->contains(qMakePair(fromTypeId, toTypeId));
|
||||
}
|
||||
|
||||
// We don't officially support constexpr in MSVC 2015, but the limited support it
|
||||
// has is enough for the code below.
|
||||
|
||||
#define STRINGIFY_TYPE_NAME(MetaTypeName, TypeId, RealName) \
|
||||
#RealName "\0"
|
||||
#define CALCULATE_TYPE_LEN(MetaTypeName, TypeId, RealName) \
|
||||
short(sizeof(#RealName)),
|
||||
#define MAP_TYPE_ID_TO_IDX(MetaTypeName, TypeId, RealName) \
|
||||
TypeId,
|
||||
|
||||
namespace {
|
||||
// All type names in one long string.
|
||||
constexpr char metaTypeStrings[] = QT_FOR_EACH_STATIC_TYPE(STRINGIFY_TYPE_NAME);
|
||||
|
||||
// The sizes of the strings in the metaTypeStrings string (including terminating null)
|
||||
constexpr short metaTypeNameSizes[] = {
|
||||
QT_FOR_EACH_STATIC_TYPE(CALCULATE_TYPE_LEN)
|
||||
};
|
||||
|
||||
// The type IDs, in the order of the metaTypeStrings data
|
||||
constexpr short metaTypeIds[] = {
|
||||
QT_FOR_EACH_STATIC_TYPE(MAP_TYPE_ID_TO_IDX)
|
||||
};
|
||||
|
||||
constexpr int MetaTypeNameCount = sizeof(metaTypeNameSizes) / sizeof(metaTypeNameSizes[0]);
|
||||
|
||||
template <typename IntegerSequence> struct MetaTypeOffsets;
|
||||
template <int... TypeIds> struct MetaTypeOffsets<QtPrivate::IndexesList<TypeIds...>>
|
||||
{
|
||||
// This would have been a lot easier if the meta types that the macro
|
||||
// QT_FOR_EACH_STATIC_TYPE declared were in sorted, ascending order, but
|
||||
// they're not (i.e., the first one declared is QMetaType::Void == 43,
|
||||
// followed by QMetaType::Bool == 1)... As a consequence, we need to use
|
||||
// the C++11 constexpr function calculateOffsetForTypeId below in order to
|
||||
// create the offset array.
|
||||
|
||||
static constexpr int findTypeId(int typeId, int i = 0)
|
||||
{
|
||||
return i >= MetaTypeNameCount ? -1 :
|
||||
metaTypeIds[i] == typeId ? i : findTypeId(typeId, i + 1);
|
||||
}
|
||||
|
||||
static constexpr short calculateOffsetForIdx(int i)
|
||||
{
|
||||
return i < 0 ? -1 :
|
||||
i == 0 ? 0 : metaTypeNameSizes[i - 1] + calculateOffsetForIdx(i - 1);
|
||||
}
|
||||
|
||||
static constexpr short calculateOffsetForTypeId(int typeId)
|
||||
{
|
||||
return calculateOffsetForIdx(findTypeId(typeId));
|
||||
#if 0
|
||||
// same as, but this is only valid in C++14:
|
||||
short offset = 0;
|
||||
for (int i = 0; i < MetaTypeNameCount; ++i) {
|
||||
if (metaTypeIds[i] == typeId)
|
||||
return offset;
|
||||
offset += metaTypeNameSizes[i];
|
||||
}
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
short offsets[sizeof...(TypeIds)];
|
||||
constexpr MetaTypeOffsets() : offsets{calculateOffsetForTypeId(TypeIds)...} {}
|
||||
|
||||
const char *operator[](int typeId) const noexcept
|
||||
{
|
||||
short o = offsets[typeId];
|
||||
return o < 0 ? nullptr : metaTypeStrings + o;
|
||||
}
|
||||
};
|
||||
} // anonymous namespace
|
||||
|
||||
constexpr MetaTypeOffsets<QtPrivate::Indexes<QMetaType::HighestInternalId + 1>::Value> metaTypeNames {};
|
||||
#undef STRINGIFY_TYPE_NAME
|
||||
#undef CALCULATE_TYPE_LEN
|
||||
#undef MAP_TYPE_ID_TO_IDX
|
||||
|
||||
/*!
|
||||
\fn const char *QMetaType::typeName(int typeId)
|
||||
\deprecated
|
||||
|
||||
Returns the type name associated with the given \a typeId, or a null
|
||||
pointer if no matching type was found. The returned pointer must not be
|
||||
deleted.
|
||||
|
||||
\sa type(), isRegistered(), Type, name()
|
||||
*/
|
||||
const char *QMetaType::typeName(int typeId)
|
||||
{
|
||||
const uint type = typeId;
|
||||
if (Q_LIKELY(type <= QMetaType::HighestInternalId)) {
|
||||
return metaTypeNames[typeId];
|
||||
} else if (Q_UNLIKELY(type < QMetaType::User)) {
|
||||
return nullptr; // It can happen when someone cast int to QVariant::Type, we should not crash...
|
||||
}
|
||||
|
||||
if (auto reg = customTypeRegistry()) {
|
||||
if (auto ti = reg->getCustomType(typeId))
|
||||
return ti->name;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\since 5.15
|
||||
@ -2305,7 +2214,7 @@ const char *QMetaType::typeName(int typeId)
|
||||
|
||||
\sa typeName()
|
||||
*/
|
||||
QByteArray QMetaType::name() const
|
||||
const char *QMetaType::name() const
|
||||
{
|
||||
return d_ptr ? d_ptr->name : nullptr;
|
||||
}
|
||||
@ -2398,15 +2307,14 @@ static inline int qMetaTypeTypeImpl(const char *typeName, int length)
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn int QMetaType::type(const char *typeName)
|
||||
\deprecated
|
||||
|
||||
Returns a handle to the type called \a typeName, or QMetaType::UnknownType if there is
|
||||
no such type.
|
||||
|
||||
\sa isRegistered(), typeName(), Type
|
||||
*/
|
||||
int QMetaType::type(const char *typeName)
|
||||
{
|
||||
return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName, qstrlen(typeName));
|
||||
}
|
||||
|
||||
/*!
|
||||
\a internal
|
||||
@ -2415,24 +2323,23 @@ int QMetaType::type(const char *typeName)
|
||||
doesn't attempt to normalize the type name (i.e., the lookup will fail
|
||||
for type names in non-normalized form).
|
||||
*/
|
||||
int qMetaTypeTypeInternal(const char *typeName)
|
||||
Q_CORE_EXPORT int qMetaTypeTypeInternal(const char *typeName)
|
||||
{
|
||||
return qMetaTypeTypeImpl</*tryNormalizedType=*/false>(typeName, qstrlen(typeName));
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn int QMetaType::type(const QByteArray &typeName)
|
||||
|
||||
\since 5.5
|
||||
\overload
|
||||
\deprecated
|
||||
|
||||
Returns a handle to the type called \a typeName, or 0 if there is
|
||||
no such type.
|
||||
|
||||
\sa isRegistered(), typeName()
|
||||
*/
|
||||
int QMetaType::type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
|
||||
{
|
||||
return qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.constData(), typeName.size());
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
/*!
|
||||
@ -2522,28 +2429,36 @@ bool QMetaType::load(QDataStream &stream, void *data) const
|
||||
#endif // QT_NO_DATASTREAM
|
||||
|
||||
/*!
|
||||
Returns a QMetaType matching \a typeName. The returned object is
|
||||
not valid if the typeName is not known to QMetaType
|
||||
*/
|
||||
QMetaType QMetaType::fromName(QByteArrayView typeName)
|
||||
{
|
||||
return QMetaType(qMetaTypeTypeImpl</*tryNormalizedType=*/true>(typeName.data(), typeName.size()));
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void *QMetaType::create(int type, const void *copy)
|
||||
\deprecated
|
||||
|
||||
Returns a copy of \a copy, assuming it is of type \a type. If \a
|
||||
copy is zero, creates a default constructed instance.
|
||||
|
||||
\sa destroy(), isRegistered(), Type
|
||||
*/
|
||||
void *QMetaType::create(int type, const void *copy)
|
||||
{
|
||||
return QMetaType(type).create(copy);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void QMetaType::destroy(int type, void *data)
|
||||
\deprecated
|
||||
Destroys the \a data, assuming it is of the \a type given.
|
||||
|
||||
\sa create(), isRegistered(), Type
|
||||
*/
|
||||
void QMetaType::destroy(int type, void *data)
|
||||
{
|
||||
QMetaType(type).destroy(data);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn void *QMetaType::construct(int type, void *where, const void *copy)
|
||||
\since 5.0
|
||||
\deprecated
|
||||
|
||||
Constructs a value of the given \a type in the existing memory
|
||||
addressed by \a where, that is a copy of \a copy, and returns
|
||||
@ -2568,14 +2483,12 @@ void QMetaType::destroy(int type, void *data)
|
||||
|
||||
\sa destruct(), sizeOf()
|
||||
*/
|
||||
void *QMetaType::construct(int type, void *where, const void *copy)
|
||||
{
|
||||
return QMetaType(type).construct(where, copy);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\fn void QMetaType::destruct(int type, void *where)
|
||||
\since 5.0
|
||||
\deprecated
|
||||
|
||||
Destructs the value of the given \a type, located at \a where.
|
||||
|
||||
@ -2584,13 +2497,11 @@ void *QMetaType::construct(int type, void *where, const void *copy)
|
||||
|
||||
\sa construct()
|
||||
*/
|
||||
void QMetaType::destruct(int type, void *where)
|
||||
{
|
||||
return QMetaType(type).destruct(where);
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn int QMetaType::sizeOf(int type)
|
||||
\since 5.0
|
||||
\deprecated
|
||||
|
||||
Returns the size of the given \a type in bytes (i.e. sizeof(T),
|
||||
where T is the actual type identified by the \a type argument).
|
||||
@ -2600,35 +2511,26 @@ void QMetaType::destruct(int type, void *where)
|
||||
|
||||
\sa construct(), QMetaType::alignOf()
|
||||
*/
|
||||
int QMetaType::sizeOf(int type)
|
||||
{
|
||||
return QMetaType(type).sizeOf();
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn QMetaType::TypeFlags QMetaType::typeFlags(int type)
|
||||
\since 5.0
|
||||
\deprecated
|
||||
|
||||
Returns flags of the given \a type.
|
||||
|
||||
\sa QMetaType::TypeFlags
|
||||
*/
|
||||
QMetaType::TypeFlags QMetaType::typeFlags(int type)
|
||||
{
|
||||
return QMetaType(type).flags();
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\fn const QMetaObject *QMetaType::metaObjectForType(int type)
|
||||
\since 5.0
|
||||
\deprecated
|
||||
|
||||
returns QMetaType::metaObject for \a type
|
||||
|
||||
\sa metaObject()
|
||||
*/
|
||||
const QMetaObject *QMetaType::metaObjectForType(int type)
|
||||
{
|
||||
return QMetaType(type).metaObject();
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn int qRegisterMetaType(const char *typeName)
|
||||
|
@ -363,18 +363,39 @@ public:
|
||||
|
||||
static void registerNormalizedTypedef(const QT_PREPEND_NAMESPACE(QByteArray) &normalizedTypeName, QMetaType type);
|
||||
|
||||
static int type(const char *typeName);
|
||||
|
||||
static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName);
|
||||
static const char *typeName(int type);
|
||||
static int sizeOf(int type);
|
||||
static TypeFlags typeFlags(int type);
|
||||
static const QMetaObject *metaObjectForType(int type);
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static int type(const char *typeName)
|
||||
{ return QMetaType::fromName(typeName).id(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static int type(const QT_PREPEND_NAMESPACE(QByteArray) &typeName)
|
||||
{ return QMetaType::fromName(typeName).id(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static const char *typeName(int type)
|
||||
{ return QMetaType(type).name(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static int sizeOf(int type)
|
||||
{ return QMetaType(type).sizeOf(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static TypeFlags typeFlags(int type)
|
||||
{ return QMetaType(type).flags(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static const QMetaObject *metaObjectForType(int type)
|
||||
{ return QMetaType(type).metaObject(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static void *create(int type, const void *copy = nullptr)
|
||||
{ return QMetaType(type).create(copy); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static void destroy(int type, void *data)
|
||||
{ return QMetaType(type).destroy(data); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static void *construct(int type, void *where, const void *copy)
|
||||
{ return QMetaType(type).construct(where, copy); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static void destruct(int type, void *where)
|
||||
{ return QMetaType(type).destruct(where); }
|
||||
#endif
|
||||
static bool isRegistered(int type);
|
||||
static void *create(int type, const void *copy = nullptr);
|
||||
static void destroy(int type, void *data);
|
||||
static void *construct(int type, void *where, const void *copy);
|
||||
static void destruct(int type, void *where);
|
||||
|
||||
explicit QMetaType(int type);
|
||||
explicit constexpr QMetaType(QtPrivate::QMetaTypeInterface *d) : d_ptr(d) {}
|
||||
@ -387,7 +408,7 @@ public:
|
||||
int alignOf() const;
|
||||
TypeFlags flags() const;
|
||||
const QMetaObject *metaObject() const;
|
||||
QT_PREPEND_NAMESPACE(QByteArray) name() const;
|
||||
const char *name() const;
|
||||
|
||||
void *create(const void *copy = nullptr) const;
|
||||
void destroy(void *data) const;
|
||||
@ -415,6 +436,7 @@ public:
|
||||
|
||||
template<typename T>
|
||||
static QMetaType fromType();
|
||||
static QMetaType fromName(QByteArrayView name);
|
||||
|
||||
friend bool operator==(const QMetaType &a, const QMetaType &b) { return a.id() == b.id(); }
|
||||
friend bool operator!=(const QMetaType &a, const QMetaType &b) { return !(a == b); }
|
||||
@ -1690,7 +1712,7 @@ struct QMetaTypeId< SINGLE_ARG_TEMPLATE<T> > \
|
||||
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
|
||||
if (const int id = metatype_id.loadRelaxed()) \
|
||||
return id; \
|
||||
const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \
|
||||
const char *tName = QMetaType::fromType<T>().name(); \
|
||||
Q_ASSERT(tName); \
|
||||
const int tNameLen = int(qstrlen(tName)); \
|
||||
QByteArray typeName; \
|
||||
@ -1725,8 +1747,8 @@ struct QMetaTypeId< DOUBLE_ARG_TEMPLATE<T, U> > \
|
||||
static QBasicAtomicInt metatype_id = Q_BASIC_ATOMIC_INITIALIZER(0); \
|
||||
if (const int id = metatype_id.loadAcquire()) \
|
||||
return id; \
|
||||
const char *tName = QMetaType::typeName(qMetaTypeId<T>()); \
|
||||
const char *uName = QMetaType::typeName(qMetaTypeId<U>()); \
|
||||
const char *tName = QMetaType::fromType<T>().name(); \
|
||||
const char *uName = QMetaType::fromType<U>().name(); \
|
||||
Q_ASSERT(tName); \
|
||||
Q_ASSERT(uName); \
|
||||
const int tNameLen = int(qstrlen(tName)); \
|
||||
|
@ -104,7 +104,7 @@ static int *queuedConnectionTypes(const QList<QByteArray> &typeNames)
|
||||
if (typeName.endsWith('*'))
|
||||
types[i] = QMetaType::VoidStar;
|
||||
else
|
||||
types[i] = QMetaType::type(typeName);
|
||||
types[i] = QMetaType::fromName(typeName).id();
|
||||
|
||||
if (!types[i]) {
|
||||
qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
|
||||
@ -129,7 +129,7 @@ static int *queuedConnectionTypes(const QArgumentType *argumentTypes, int argc)
|
||||
else if (type.name().endsWith('*'))
|
||||
types[i] = QMetaType::VoidStar;
|
||||
else
|
||||
types[i] = QMetaType::type(type.name());
|
||||
types[i] = QMetaType::fromName(type.name()).id();
|
||||
|
||||
if (!types[i]) {
|
||||
qWarning("QObject::connect: Cannot queue arguments of type '%s'\n"
|
||||
@ -591,7 +591,7 @@ QMetaCallEvent::~QMetaCallEvent()
|
||||
int *typeIDs = types();
|
||||
for (int i = 0; i < d.nargs_; ++i) {
|
||||
if (typeIDs[i] && d.args_[i])
|
||||
QMetaType::destroy(typeIDs[i], d.args_[i]);
|
||||
QMetaType(typeIDs[i]).destroy(d.args_[i]);
|
||||
}
|
||||
if (reinterpret_cast<void*>(d.args_) != reinterpret_cast<void*>(prealloc_))
|
||||
free(d.args_);
|
||||
@ -3654,7 +3654,7 @@ static void queued_activate(QObject *sender, int signal, QObjectPrivate::Connect
|
||||
types[n] = argumentTypes[n-1];
|
||||
|
||||
for (int n = 1; n < nargs; ++n)
|
||||
args[n] = QMetaType::create(types[n], argv[n]);
|
||||
args[n] = QMetaType(types[n]).create(argv[n]);
|
||||
}
|
||||
|
||||
locker.relock();
|
||||
|
@ -1065,8 +1065,7 @@ void QVariant::detach()
|
||||
*/
|
||||
const char *QVariant::typeName() const
|
||||
{
|
||||
// Cannot use d.type().name because we must return a char*
|
||||
return QMetaType::typeName(d.typeId());
|
||||
return d.type().name();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -1081,29 +1080,26 @@ void QVariant::clear()
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn const char *QVariant::typeToName(int typeId)
|
||||
\deprecated Use QMetaType instead
|
||||
|
||||
Converts the int representation of the storage type, \a typeId, to
|
||||
its string representation.
|
||||
|
||||
Returns \nullptr if the type is QMetaType::UnknownType or doesn't exist.
|
||||
*/
|
||||
const char *QVariant::typeToName(int typeId)
|
||||
{
|
||||
return QMetaType::typeName(typeId);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\fn QVariant::Type QVariant::nameToType(const char *name)
|
||||
\deprecated Use QMetaType instead
|
||||
|
||||
Converts the string representation of the storage type given in \a
|
||||
name, to its enum representation.
|
||||
|
||||
If the string representation cannot be converted to any enum
|
||||
representation, the variant is set to \c Invalid.
|
||||
*/
|
||||
QVariant::Type QVariant::nameToType(const char *name)
|
||||
{
|
||||
int metaType = QMetaType::type(name);
|
||||
return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
|
||||
}
|
||||
|
||||
#ifndef QT_NO_DATASTREAM
|
||||
enum { MapFromThreeCount = 36 };
|
||||
@ -1190,11 +1186,11 @@ void QVariant::load(QDataStream &s)
|
||||
s >> is_null;
|
||||
if (typeId == 27) {
|
||||
// used to be QRegExp in Qt 4/5
|
||||
typeId = QMetaType::type("QRegExp");
|
||||
typeId = QMetaType::fromName("QRegExp").id();
|
||||
} else if (typeId == QVariant::UserType) {
|
||||
QByteArray name;
|
||||
s >> name;
|
||||
typeId = QMetaType::type(name.constData());
|
||||
typeId = QMetaType::fromName(name).id();
|
||||
if (typeId == QMetaType::UnknownType) {
|
||||
s.setStatus(QDataStream::ReadCorruptData);
|
||||
qWarning("QVariant::load: unknown user type with name %s.", name.constData());
|
||||
@ -1273,7 +1269,7 @@ void QVariant::save(QDataStream &s) const
|
||||
}
|
||||
const char *typeName = nullptr;
|
||||
if (saveAsUserType) {
|
||||
typeName = QMetaType::typeName(d.typeId());
|
||||
typeName = d.type().name();
|
||||
if (!strcmp(typeName, "QRegExp")) {
|
||||
typeId = 27; // QRegExp in Qt 4/5
|
||||
typeName = nullptr;
|
||||
@ -1283,7 +1279,7 @@ void QVariant::save(QDataStream &s) const
|
||||
if (s.version() >= QDataStream::Qt_4_2)
|
||||
s << qint8(d.is_null);
|
||||
if (typeName)
|
||||
s << QMetaType::typeName(userType());
|
||||
s << d.type().name();
|
||||
|
||||
if (!isValid()) {
|
||||
if (s.version() < QDataStream::Qt_5_0)
|
||||
@ -1293,7 +1289,7 @@ void QVariant::save(QDataStream &s) const
|
||||
|
||||
if (!d.type().save(s, constData())) {
|
||||
qWarning("QVariant::save: unable to save type '%s' (type id: %d).\n",
|
||||
QMetaType::typeName(d.typeId()), d.typeId());
|
||||
d.type().name(), d.typeId());
|
||||
Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
|
||||
}
|
||||
}
|
||||
@ -2001,11 +1997,6 @@ bool QVariant::convert(int targetTypeId)
|
||||
if (oldValue.d.is_null && oldValue.d.typeId() != QMetaType::Nullptr)
|
||||
return false;
|
||||
|
||||
if ((QMetaType::typeFlags(oldValue.userType()) & QMetaType::PointerToQObject) && (QMetaType::typeFlags(targetTypeId) & QMetaType::PointerToQObject)) {
|
||||
create(targetTypeId, &oldValue.d.get<QObject *>());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ok = QMetaType::convert(oldValue.constData(), oldValue.d.typeId(), data(), targetTypeId);
|
||||
d.is_null = !ok;
|
||||
return ok;
|
||||
@ -2308,7 +2299,7 @@ QDebug operator<<(QDebug dbg, const QVariant &v)
|
||||
const uint typeId = v.d.typeId();
|
||||
dbg.nospace() << "QVariant(";
|
||||
if (typeId != QMetaType::UnknownType) {
|
||||
dbg << QMetaType::typeName(typeId) << ", ";
|
||||
dbg << v.d.type().name() << ", ";
|
||||
bool streamed = v.d.type().debugStream(dbg, v.d.storage());
|
||||
if (!streamed && v.canConvert<QString>())
|
||||
dbg << v.toString();
|
||||
@ -2324,7 +2315,7 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p)
|
||||
QDebugStateSaver saver(dbg);
|
||||
dbg.nospace() << "QVariant::"
|
||||
<< (int(p) != int(QMetaType::UnknownType)
|
||||
? QMetaType::typeName(p)
|
||||
? QMetaType(p).name()
|
||||
: "Invalid");
|
||||
return dbg;
|
||||
}
|
||||
|
@ -314,8 +314,17 @@ class Q_CORE_EXPORT QVariant
|
||||
void load(QDataStream &ds);
|
||||
void save(QDataStream &ds) const;
|
||||
#endif
|
||||
static const char *typeToName(int typeId);
|
||||
static Type nameToType(const char *name);
|
||||
#if QT_DEPRECATED_SINCE(6, 0)
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static const char *typeToName(int typeId)
|
||||
{ return QMetaType(typeId).name(); }
|
||||
QT_DEPRECATED_VERSION_6_0
|
||||
static Type nameToType(const char *name)
|
||||
{
|
||||
int metaType = QMetaType::fromName(name).id();
|
||||
return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType;
|
||||
}
|
||||
#endif
|
||||
|
||||
void *data();
|
||||
const void *constData() const
|
||||
|
@ -1424,7 +1424,7 @@ QtSharedPointer::ExternalRefCountData *QtSharedPointer::ExternalRefCountData::ge
|
||||
*/
|
||||
QSharedPointer<QObject> QtSharedPointer::sharedPointerFromVariant_internal(const QVariant &variant)
|
||||
{
|
||||
Q_ASSERT(QMetaType::typeFlags(variant.userType()) & QMetaType::SharedPointerToQObject);
|
||||
Q_ASSERT(variant.metaType().flags() & QMetaType::SharedPointerToQObject);
|
||||
return *reinterpret_cast<const QSharedPointer<QObject>*>(variant.constData());
|
||||
}
|
||||
|
||||
@ -1435,7 +1435,8 @@ QSharedPointer<QObject> QtSharedPointer::sharedPointerFromVariant_internal(const
|
||||
*/
|
||||
QWeakPointer<QObject> QtSharedPointer::weakPointerFromVariant_internal(const QVariant &variant)
|
||||
{
|
||||
Q_ASSERT(QMetaType::typeFlags(variant.userType()) & QMetaType::WeakPointerToQObject || QMetaType::typeFlags(variant.userType()) & QMetaType::TrackingPointerToQObject);
|
||||
Q_ASSERT(variant.metaType().flags() & QMetaType::WeakPointerToQObject ||
|
||||
variant.metaType().flags() & QMetaType::TrackingPointerToQObject);
|
||||
return *reinterpret_cast<const QWeakPointer<QObject>*>(variant.constData());
|
||||
}
|
||||
|
||||
|
@ -199,8 +199,8 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
|
||||
if (type == QMetaType::QVariant) {
|
||||
*reinterpret_cast<QVariant*>(returnValuePtr) = value;
|
||||
} else {
|
||||
QMetaType::destruct(type, returnValuePtr);
|
||||
QMetaType::construct(type, returnValuePtr, value.constData());
|
||||
QMetaType(type).destruct(returnValuePtr);
|
||||
QMetaType(type).construct(returnValuePtr, value.constData());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
|
||||
if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) {
|
||||
qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' "
|
||||
"(Did you forget to call beginStructure() ?)",
|
||||
QMetaType::typeName(id),
|
||||
QMetaType(id).name(),
|
||||
signature.isEmpty() ? "<empty>" : signature.constData());
|
||||
return "";
|
||||
} else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
|
||||
@ -94,9 +94,9 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
|
||||
signature.at(1) == DBUS_TYPE_STRING))) {
|
||||
qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) "
|
||||
"(Did you forget to call beginStructure() ?)",
|
||||
QMetaType::typeName(id),
|
||||
QMetaType(id).name(),
|
||||
signature.constData(),
|
||||
QMetaType::typeName(QDBusMetaType::signatureToType(signature)));
|
||||
QMetaType(QDBusMetaType::signatureToType(signature)).name());
|
||||
return "";
|
||||
}
|
||||
return signature;
|
||||
|
@ -960,8 +960,8 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
|
||||
} else {
|
||||
qFatal("Internal error: got invalid meta type %d (%s) "
|
||||
"when trying to convert to meta type %d (%s)",
|
||||
arg.userType(), QMetaType::typeName(arg.userType()),
|
||||
id, QMetaType::typeName(id));
|
||||
arg.userType(), arg.metaType().name(),
|
||||
id, QMetaType(id).name());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -210,9 +210,9 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
|
||||
if (!signature) {
|
||||
qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
|
||||
"Use qDBusRegisterMetaType to register it",
|
||||
QMetaType::typeName(id), id);
|
||||
QMetaType(id).name(), id);
|
||||
error(QLatin1String("Unregistered type %1 passed in arguments")
|
||||
.arg(QLatin1String(QMetaType::typeName(id))));
|
||||
.arg(QLatin1String(QMetaType(id).name())));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -252,9 +252,9 @@ inline QDBusMarshaller *QDBusMarshaller::beginArray(int id)
|
||||
if (!signature) {
|
||||
qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
|
||||
"Use qDBusRegisterMetaType to register it",
|
||||
QMetaType::typeName(id), id);
|
||||
QMetaType(id).name(), id);
|
||||
error(QLatin1String("Unregistered type %1 passed in arguments")
|
||||
.arg(QLatin1String(QMetaType::typeName(id))));
|
||||
.arg(QLatin1String(QMetaType(id).name())));
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -267,22 +267,22 @@ inline QDBusMarshaller *QDBusMarshaller::beginMap(int kid, int vid)
|
||||
if (!ksignature) {
|
||||
qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
|
||||
"Use qDBusRegisterMetaType to register it",
|
||||
QMetaType::typeName(kid), kid);
|
||||
QMetaType(kid).name(), kid);
|
||||
error(QLatin1String("Unregistered type %1 passed in arguments")
|
||||
.arg(QLatin1String(QMetaType::typeName(kid))));
|
||||
.arg(QLatin1String(QMetaType(kid).name())));
|
||||
return this;
|
||||
}
|
||||
if (ksignature[1] != 0 || !QDBusUtil::isValidBasicType(*ksignature)) {
|
||||
qWarning("QDBusMarshaller: type '%s' (%d) cannot be used as the key type in a D-BUS map.",
|
||||
QMetaType::typeName(kid), kid);
|
||||
QMetaType(kid).name(), kid);
|
||||
error(QLatin1String("Type %1 passed in arguments cannot be used as a key in a map")
|
||||
.arg(QLatin1String(QMetaType::typeName(kid))));
|
||||
.arg(QLatin1String(QMetaType(kid).name())));
|
||||
return this;
|
||||
}
|
||||
|
||||
const char *vsignature = QDBusMetaType::typeToSignature( QVariant::Type(vid) );
|
||||
if (!vsignature) {
|
||||
const char *typeName = QMetaType::typeName(vid);
|
||||
const char *typeName = QMetaType(vid).name();
|
||||
qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
|
||||
"Use qDBusRegisterMetaType to register it",
|
||||
typeName, vid);
|
||||
@ -416,9 +416,9 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
|
||||
if (!signature) {
|
||||
qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
|
||||
"Use qDBusRegisterMetaType to register it",
|
||||
QMetaType::typeName(id), id);
|
||||
QMetaType(id).name(), id);
|
||||
error(QLatin1String("Unregistered type %1 passed in arguments")
|
||||
.arg(QLatin1String(QMetaType::typeName(id))));
|
||||
.arg(QLatin1String(QMetaType(id).name())));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -134,11 +134,8 @@ static int registerComplexDBusType(const QByteArray &typeName)
|
||||
const QByteArray name;
|
||||
QDBusRawTypeHandler(const QByteArray &name)
|
||||
: QtPrivate::QMetaTypeInterface {
|
||||
0, sizeof(void *), sizeof(void *), QMetaType::MovableType, nullptr,
|
||||
name.constData(), 0, QtPrivate::RefCount{0},
|
||||
[](QtPrivate::QMetaTypeInterface *self) {
|
||||
delete static_cast<QDBusRawTypeHandler *>(self);
|
||||
},
|
||||
0, sizeof(void *), sizeof(void *), QMetaType::MovableType, 0, nullptr,
|
||||
name.constData(),
|
||||
nullptr, nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr,
|
||||
nullptr, nullptr, nullptr
|
||||
@ -148,7 +145,14 @@ static int registerComplexDBusType(const QByteArray &typeName)
|
||||
};
|
||||
|
||||
static QBasicMutex mutex;
|
||||
static QHash<QByteArray, QMetaType> hash;
|
||||
static struct Hash : QHash<QByteArray, QMetaType>
|
||||
{
|
||||
~Hash()
|
||||
{
|
||||
for (QMetaType entry : *this)
|
||||
QMetaType::unregisterMetaType(std::move(entry));
|
||||
}
|
||||
} hash;
|
||||
QMutexLocker lock(&mutex);
|
||||
QMetaType &metatype = hash[typeName];
|
||||
if (!metatype.isValid())
|
||||
@ -192,7 +196,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
|
||||
|
||||
if (!typeName.isEmpty()) {
|
||||
// type name found
|
||||
type = QMetaType::type(typeName);
|
||||
type = QMetaType::fromName(typeName).id();
|
||||
}
|
||||
|
||||
if (type == QMetaType::UnknownType || signature != QDBusMetaType::typeToSignature(type)) {
|
||||
@ -221,7 +225,7 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
|
||||
type = registerComplexDBusType(result.name);
|
||||
}
|
||||
} else {
|
||||
result.name = QMetaType::typeName(type);
|
||||
result.name = QMetaType(type).name();
|
||||
}
|
||||
|
||||
result.id = type;
|
||||
@ -501,7 +505,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
|
||||
Q_ASSERT(mm.outputTypes.size() > 1);
|
||||
type = mm.outputTypes.at(i - mm.inputTypes.size() + 1);
|
||||
// Output parameters are references; type id not available
|
||||
typeName = QMetaType::typeName(type);
|
||||
typeName = QMetaType(type).name();
|
||||
typeName.append('&');
|
||||
}
|
||||
Q_ASSERT(type != QMetaType::UnknownType);
|
||||
|
@ -164,7 +164,7 @@ int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QList<int>
|
||||
QByteArray basictype = type;
|
||||
basictype.truncate(type.length() - 1);
|
||||
|
||||
int id = QMetaType::type(basictype);
|
||||
int id = QMetaType::fromName(basictype).id();
|
||||
if (id == 0) {
|
||||
errorMsg = QLatin1String("Unregistered output type in parameter list: ") + QLatin1String(type);
|
||||
return -1;
|
||||
@ -184,7 +184,7 @@ int qDBusParametersForMethod(const QList<QByteArray> ¶meterTypes, QList<int>
|
||||
if (type.startsWith("QVector<"))
|
||||
type = "QList<" + type.mid(sizeof("QVector<") - 1);
|
||||
|
||||
int id = QMetaType::type(type);
|
||||
int id = QMetaType::fromName(type).id();
|
||||
#ifdef QT_BOOTSTRAPPED
|
||||
// in bootstrap mode QDBusMessage isn't included, thus we need to resolve it manually here
|
||||
if (type == "QDBusMessage") {
|
||||
|
@ -198,7 +198,7 @@ void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types)
|
||||
const char *typeSig = QDBusMetaType::typeToSignature(types[i]);
|
||||
if (Q_UNLIKELY(!typeSig)) {
|
||||
qFatal("QDBusPendingReply: type %s is not registered with QtDBus",
|
||||
QMetaType::typeName(types[i]));
|
||||
QMetaType(types[i]).name());
|
||||
}
|
||||
sig += typeSig;
|
||||
}
|
||||
|
@ -225,7 +225,7 @@ void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data
|
||||
} else {
|
||||
// not an argument and doesn't match?
|
||||
int type = reply.arguments().at(0).userType();
|
||||
receivedType = QMetaType::typeName(type);
|
||||
receivedType = QMetaType(type).name();
|
||||
receivedSignature = QDBusMetaType::typeToSignature(type);
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
|
||||
accessAsString(mp.isReadable(), mp.isWritable()));
|
||||
|
||||
if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
|
||||
const char *typeName = QMetaType::typeName(typeId);
|
||||
const char *typeName = QMetaType(typeId).name();
|
||||
retval += QLatin1String(">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n")
|
||||
.arg(typeNameToXml(typeName));
|
||||
} else {
|
||||
@ -163,9 +163,9 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
|
||||
// do we need to describe this argument?
|
||||
if (QDBusMetaType::signatureToType(typeName) == QMetaType::UnknownType)
|
||||
xml += QLatin1String(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
|
||||
.arg(typeNameToXml(QMetaType::typeName(typeId)));
|
||||
.arg(typeNameToXml(QMetaType(typeId).name()));
|
||||
} else {
|
||||
qWarning() << "Unsupported return type" << typeId << QMetaType::typeName(typeId) << "in method" << mm.name();
|
||||
qWarning() << "Unsupported return type" << typeId << QMetaType(typeId).name() << "in method" << mm.name();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -209,7 +209,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
|
||||
|
||||
// do we need to describe this argument?
|
||||
if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
|
||||
const char *typeName = QMetaType::typeName(types.at(j));
|
||||
const char *typeName = QMetaType(types.at(j)).name();
|
||||
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.%1%2\" value=\"%3\"/>\n")
|
||||
.arg(isOutput ? QLatin1String("Out") : QLatin1String("In"))
|
||||
.arg(isOutput && !isSignal ? j - inputCount : j - 1)
|
||||
|
@ -187,13 +187,13 @@ void QShaderGraphLoader::load()
|
||||
if (parameterValue.isObject()) {
|
||||
const QJsonObject parameterObject = parameterValue.toObject();
|
||||
const QString type = parameterObject.value(QStringLiteral("type")).toString();
|
||||
const int typeId = QMetaType::type(type.toUtf8());
|
||||
const int typeId = QMetaType::fromName(type.toUtf8()).id();
|
||||
|
||||
const QString value = parameterObject.value(QStringLiteral("value")).toString();
|
||||
auto variant = QVariant(value);
|
||||
|
||||
if (QMetaType::typeFlags(typeId) & QMetaType::IsEnumeration) {
|
||||
const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId);
|
||||
if (QMetaType(typeId).flags() & QMetaType::IsEnumeration) {
|
||||
const QMetaObject *metaObject = QMetaType(typeId).metaObject();
|
||||
const char *className = metaObject->className();
|
||||
const QByteArray enumName = type.mid(static_cast<int>(qstrlen(className)) + 2).toUtf8();
|
||||
const QMetaEnum metaEnum = metaObject->enumerator(metaObject->indexOfEnumerator(enumName));
|
||||
|
@ -160,13 +160,13 @@ void QShaderNodesLoader::load(const QJsonObject &prototypesObject)
|
||||
if (parameterValue.isObject()) {
|
||||
const QJsonObject parameterObject = parameterValue.toObject();
|
||||
const QString type = parameterObject.value(QStringLiteral("type")).toString();
|
||||
const int typeId = QMetaType::type(type.toUtf8());
|
||||
const int typeId = QMetaType::fromName(type.toUtf8()).id();
|
||||
|
||||
const QString value = parameterObject.value(QStringLiteral("value")).toString();
|
||||
auto variant = QVariant(value);
|
||||
|
||||
if (QMetaType::typeFlags(typeId) & QMetaType::IsEnumeration) {
|
||||
const QMetaObject *metaObject = QMetaType::metaObjectForType(typeId);
|
||||
if (QMetaType(typeId).flags() & QMetaType::IsEnumeration) {
|
||||
const QMetaObject *metaObject = QMetaType(typeId).metaObject();
|
||||
const char *className = metaObject->className();
|
||||
const QByteArray enumName = type.mid(static_cast<int>(qstrlen(className)) + 2).toUtf8();
|
||||
const QMetaEnum metaEnum = metaObject->enumerator(metaObject->indexOfEnumerator(enumName));
|
||||
|
@ -160,10 +160,12 @@ void QHostInfoResult::postResultsReady(const QHostInfo &info)
|
||||
Q_CHECK_PTR(metaCallEvent);
|
||||
void **args = metaCallEvent->args();
|
||||
int *types = metaCallEvent->types();
|
||||
types[0] = QMetaType::type("void");
|
||||
types[1] = QMetaType::type("QHostInfo");
|
||||
auto voidType = QMetaType::fromType<void>();
|
||||
auto hostInfoType = QMetaType::fromType<QHostInfo>();
|
||||
types[0] = voidType.id();
|
||||
types[1] = hostInfoType.id();
|
||||
args[0] = nullptr;
|
||||
args[1] = QMetaType::create(types[1], &info);
|
||||
args[1] = hostInfoType.create(&info);
|
||||
Q_CHECK_PTR(args[1]);
|
||||
qApp->postEvent(result, metaCallEvent);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ static void qSignalDumperCallback(QObject *caller, int signal_index, void **argv
|
||||
QList<QByteArray> args = member.parameterTypes();
|
||||
for (int i = 0; i < args.count(); ++i) {
|
||||
const QByteArray &arg = args.at(i);
|
||||
int typeId = QMetaType::type(args.at(i).constData());
|
||||
int typeId = QMetaType::fromName(args.at(i).constData()).id();
|
||||
if (arg.endsWith('*') || arg.endsWith('&')) {
|
||||
str += '(';
|
||||
str += arg;
|
||||
|
@ -1205,8 +1205,8 @@ void *fetchData(QTestData *data, const char *tagName, int typeId)
|
||||
|
||||
if (Q_UNLIKELY(typeId != data->parent()->elementTypeId(idx))) {
|
||||
qFatal("Requested type '%s' does not match available type '%s'.",
|
||||
QMetaType::typeName(typeId),
|
||||
QMetaType::typeName(data->parent()->elementTypeId(idx)));
|
||||
QMetaType(typeId).name(),
|
||||
QMetaType(data->parent()->elementTypeId(idx)).name());
|
||||
}
|
||||
|
||||
return data->data(idx);
|
||||
|
@ -72,7 +72,7 @@ QTestData::~QTestData()
|
||||
{
|
||||
for (int i = 0; i < d->dataCount; ++i) {
|
||||
if (d->data[i])
|
||||
QMetaType::destroy(d->parent->elementTypeId(i), d->data[i]);
|
||||
QMetaType(d->parent->elementTypeId(i)).destroy(d->data[i]);
|
||||
}
|
||||
delete [] d->data;
|
||||
delete [] d->tag;
|
||||
@ -99,12 +99,12 @@ void QTestData::append(int type, const void *data)
|
||||
}
|
||||
if (expectedType != type) {
|
||||
qDebug("expected data of type '%s', got '%s' for element %d of data with tag '%s'",
|
||||
QMetaType::typeName(expectedType),
|
||||
QMetaType::typeName(type),
|
||||
QMetaType(expectedType).name(),
|
||||
QMetaType(type).name(),
|
||||
d->dataCount, d->tag);
|
||||
QTEST_ASSERT(false);
|
||||
}
|
||||
d->data[d->dataCount] = QMetaType::create(type, data);
|
||||
d->data[d->dataCount] = QMetaType(type).create(data);
|
||||
++d->dataCount;
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,7 @@ uint nameToBuiltinType(const QByteArray &name)
|
||||
if (name.isEmpty())
|
||||
return 0;
|
||||
|
||||
uint tp = QMetaType::type(name.constData());
|
||||
uint tp = qMetaTypeTypeInternal(name.constData());
|
||||
return tp < uint(QMetaType::User) ? tp : uint(QMetaType::UnknownType);
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ uint nameToBuiltinType(const QByteArray &name)
|
||||
*/
|
||||
bool isBuiltinType(const QByteArray &type)
|
||||
{
|
||||
int id = QMetaType::type(type.constData());
|
||||
int id = qMetaTypeTypeInternal(type.constData());
|
||||
if (id == QMetaType::UnknownType)
|
||||
return false;
|
||||
return (id < QMetaType::User);
|
||||
|
@ -629,7 +629,7 @@ void tst_QMetaMethod::method()
|
||||
QVERIFY(method.typeName() != 0);
|
||||
if (QByteArray(method.typeName()) != returnTypeName) {
|
||||
// QMetaMethod should always produce a semantically equivalent typename
|
||||
QCOMPARE(QMetaType::type(method.typeName()), QMetaType::type(returnTypeName));
|
||||
QCOMPARE(QMetaType::fromName(method.typeName()), QMetaType::fromName(returnTypeName));
|
||||
}
|
||||
|
||||
if (method.parameterTypes() != parameterTypeNames) {
|
||||
@ -637,8 +637,8 @@ void tst_QMetaMethod::method()
|
||||
QList<QByteArray> actualTypeNames = method.parameterTypes();
|
||||
QCOMPARE(actualTypeNames.size(), parameterTypeNames.size());
|
||||
for (int i = 0; i < parameterTypeNames.size(); ++i) {
|
||||
QCOMPARE(QMetaType::type(actualTypeNames.at(i)),
|
||||
QMetaType::type(parameterTypeNames.at(i)));
|
||||
QCOMPARE(QMetaType::fromName(actualTypeNames.at(i)),
|
||||
QMetaType::fromName(parameterTypeNames.at(i)));
|
||||
}
|
||||
}
|
||||
QCOMPARE(method.parameterNames(), parameterNames);
|
||||
|
@ -1452,7 +1452,7 @@ void tst_QMetaObject::customPropertyType()
|
||||
QCOMPARE(prop.metaType(), QMetaType::fromType<MyStruct>());
|
||||
|
||||
qRegisterMetaType<MyStruct>("MyStruct");
|
||||
QCOMPARE(prop.userType(), QMetaType::type("MyStruct"));
|
||||
QCOMPARE(prop.userType(), QMetaType::fromName("MyStruct").id());
|
||||
|
||||
prop = metaObject()->property(metaObject()->indexOfProperty("value4"));
|
||||
QCOMPARE(prop.type(), QVariant::List);
|
||||
|
@ -211,20 +211,20 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(EnumFlagsTester::TestFlags)
|
||||
|
||||
void tst_QMetaProperty::readAndWriteWithLazyRegistration()
|
||||
{
|
||||
QCOMPARE(QMetaType::type("CustomReadObject*"), int(QMetaType::UnknownType));
|
||||
QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
|
||||
QVERIFY(!QMetaType::fromName("CustomReadObject*").isValid());
|
||||
QVERIFY(!QMetaType::fromName("CustomWriteObject*").isValid());
|
||||
|
||||
TypeLazyRegistration o;
|
||||
QVERIFY(o.property("read").isValid());
|
||||
QVERIFY(QMetaType::type("CustomReadObject*") != QMetaType::UnknownType);
|
||||
QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
|
||||
QVERIFY(QMetaType::fromName("CustomReadObject*").isValid());
|
||||
QVERIFY(!QMetaType::fromName("CustomWriteObject*").isValid());
|
||||
|
||||
CustomWriteObjectChild data;
|
||||
QVariant value = QVariant::fromValue(&data); // this register CustomWriteObjectChild
|
||||
// check if base classes are not registered automatically, otherwise this test would be meaningless
|
||||
QCOMPARE(QMetaType::type("CustomWriteObject*"), int(QMetaType::UnknownType));
|
||||
QVERIFY(!QMetaType::fromName("CustomWriteObject*").isValid());
|
||||
QVERIFY(o.setProperty("write", value));
|
||||
QVERIFY(QMetaType::type("CustomWriteObject*") != QMetaType::UnknownType);
|
||||
QVERIFY(QMetaType::fromName("CustomWriteObject*").isValid());
|
||||
QCOMPARE(o.property("write").value<CustomWriteObjectChild*>(), &data);
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ qt_add_test(tst_qmetatype
|
||||
../../../other/qvariant_common
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
TESTDATA ${test_data}
|
||||
)
|
||||
|
||||
|
@ -16,6 +16,7 @@ qt_add_test(tst_qmetatype
|
||||
../../../other/qvariant_common
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::CorePrivate
|
||||
Qt::Gui
|
||||
TESTDATA ${test_data}
|
||||
)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qmetatype
|
||||
QT = core-private testlib
|
||||
QT = core-private testlib gui
|
||||
INCLUDEPATH += $$PWD/../../../other/qvariant_common
|
||||
SOURCES = tst_qmetatype.cpp
|
||||
TESTDATA=./typeFlags.bin
|
||||
|
@ -268,8 +268,8 @@ struct GenericGadgetType : BaseGenericType
|
||||
if (_c == QMetaObject::ReadProperty) {
|
||||
if (_id < properties.size()) {
|
||||
const auto &prop = properties.at(_id);
|
||||
QMetaType::destruct(int(prop.userType()), _a[0]);
|
||||
QMetaType::construct(int(prop.userType()), _a[0], prop.constData());
|
||||
prop.metaType().destruct(_a[0]);
|
||||
prop.metaType().construct(_a[0], prop.constData());
|
||||
}
|
||||
} else if (_c == QMetaObject::WriteProperty) {
|
||||
if (_id < properties.size()) {
|
||||
@ -402,7 +402,7 @@ void tst_QMetaType::registerGadget(const char *name, const QList<GadgetPropertyT
|
||||
gadgetBuilder.setFlags(metaObjectflags);
|
||||
auto dynamicGadgetProperties = std::make_shared<GenericGadgetType>();
|
||||
for (const auto &prop : gadgetProperties) {
|
||||
int propertyType = QMetaType::type(prop.type);
|
||||
int propertyType = QMetaType::fromName(prop.type).id();
|
||||
dynamicGadgetProperties->properties.push_back(QVariant(QMetaType(propertyType)));
|
||||
auto dynamicPropery = gadgetBuilder.addProperty(prop.name, prop.type);
|
||||
dynamicPropery.setWritable(true);
|
||||
@ -715,6 +715,9 @@ void tst_QMetaType::typeName()
|
||||
QFETCH(int, aType);
|
||||
QFETCH(QString, aTypeName);
|
||||
|
||||
if (aType >= QMetaType::FirstWidgetsType)
|
||||
QSKIP("The test doesn't link against QtWidgets.");
|
||||
|
||||
const char *rawname = QMetaType::typeName(aType);
|
||||
QString name = QString::fromLatin1(rawname);
|
||||
|
||||
@ -753,6 +756,8 @@ void tst_QMetaType::type()
|
||||
QFETCH(int, aType);
|
||||
QFETCH(QByteArray, aTypeName);
|
||||
|
||||
if (aType >= QMetaType::FirstWidgetsType)
|
||||
QSKIP("The test doesn't link against QtWidgets.");
|
||||
// QMetaType::type(QByteArray)
|
||||
QCOMPARE(QMetaType::type(aTypeName), aType);
|
||||
// QMetaType::type(const char *)
|
||||
@ -1978,11 +1983,6 @@ DECLARE_NONSTREAMABLE(QPersistentModelIndex)
|
||||
DECLARE_NONSTREAMABLE(QObject*)
|
||||
DECLARE_NONSTREAMABLE(QWidget*)
|
||||
|
||||
#define DECLARE_GUI_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \
|
||||
DECLARE_NONSTREAMABLE(RealType)
|
||||
QT_FOR_EACH_STATIC_GUI_CLASS(DECLARE_GUI_CLASS_NONSTREAMABLE)
|
||||
#undef DECLARE_GUI_CLASS_NONSTREAMABLE
|
||||
|
||||
#define DECLARE_WIDGETS_CLASS_NONSTREAMABLE(MetaTypeName, MetaTypeId, RealType) \
|
||||
DECLARE_NONSTREAMABLE(RealType)
|
||||
QT_FOR_EACH_STATIC_WIDGETS_CLASS(DECLARE_WIDGETS_CLASS_NONSTREAMABLE)
|
||||
|
@ -546,10 +546,9 @@ void tst_QEasingCurve::properties()
|
||||
|
||||
void tst_QEasingCurve::metaTypes()
|
||||
{
|
||||
QVERIFY(QMetaType::type("QEasingCurve") == QMetaType::QEasingCurve);
|
||||
QVERIFY(QMetaType::fromName("QEasingCurve").id() == QMetaType::QEasingCurve);
|
||||
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QEasingCurve)),
|
||||
QByteArray("QEasingCurve"));
|
||||
QCOMPARE(QByteArray(QMetaType(QMetaType::QEasingCurve).name()), QByteArray("QEasingCurve"));
|
||||
|
||||
QVERIFY(QMetaType::isRegistered(QMetaType::QEasingCurve));
|
||||
|
||||
|
@ -1086,7 +1086,7 @@ void tst_QList::cpp17ctad() const
|
||||
#ifdef __cpp_deduction_guides
|
||||
#define QVERIFY_IS_VECTOR_OF(obj, Type) \
|
||||
QVERIFY2((std::is_same<decltype(obj), QList<Type>>::value), \
|
||||
QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>()))
|
||||
QMetaType::fromType<decltype(obj)::value_type>().name())
|
||||
#define CHECK(Type, One, Two, Three) \
|
||||
do { \
|
||||
const Type v[] = {One, Two, Three}; \
|
||||
|
@ -331,7 +331,7 @@ void tst_QSet::cpp17ctad()
|
||||
#ifdef __cpp_deduction_guides
|
||||
#define QVERIFY_IS_SET_OF(obj, Type) \
|
||||
QVERIFY2((std::is_same<decltype(obj), QSet<Type>>::value), \
|
||||
QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>()))
|
||||
QMetaType::fromType<decltype(obj)::value_type>().name())
|
||||
#define CHECK(Type, One, Two, Three) \
|
||||
do { \
|
||||
const Type v[] = {One, Two, Three}; \
|
||||
|
@ -785,7 +785,7 @@ void tst_QVarLengthArray::cpp17ctad()
|
||||
#ifdef __cpp_deduction_guides
|
||||
#define QVERIFY_IS_VLA_OF(obj, Type) \
|
||||
QVERIFY2((std::is_same<decltype(obj), QVarLengthArray<Type>>::value), \
|
||||
QMetaType::typeName(qMetaTypeId<decltype(obj)::value_type>()))
|
||||
QMetaType::fromType<decltype(obj)::value_type>().name())
|
||||
#define CHECK(Type, One, Two, Three) \
|
||||
do { \
|
||||
const Type v[] = {One, Two, Three}; \
|
||||
|
@ -522,7 +522,7 @@ bool compareToArgument(const QDBusArgument &arg, const QVariant &v2)
|
||||
|
||||
qWarning() << "Unexpected QVariant type" << v2.userType()
|
||||
<< QByteArray(QDBusMetaType::typeToSignature(v2.userType()))
|
||||
<< QMetaType::typeName(v2.userType());
|
||||
<< v2.metaType().name();
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -531,7 +531,7 @@ template<> bool compare(const QVariant &v1, const QVariant &v2)
|
||||
// v1 is the one that came from the network
|
||||
// v2 is the one that we sent
|
||||
|
||||
if (v1.userType() == qMetaTypeId<QDBusArgument>())
|
||||
if (v1.metaType() == QMetaType::fromType<QDBusArgument>())
|
||||
// this argument has been left un-demarshalled
|
||||
return compareToArgument(qvariant_cast<QDBusArgument>(v1), v2);
|
||||
|
||||
|
@ -219,7 +219,7 @@ void tst_QGuiMetaType::create_data()
|
||||
{
|
||||
QTest::addColumn<QMetaType::Type>("type");
|
||||
#define ADD_METATYPE_TEST_ROW(TYPE, ID) \
|
||||
QTest::newRow(QMetaType::typeName(QMetaType::ID)) << QMetaType::ID;
|
||||
QTest::newRow(QMetaType(QMetaType::ID).name()) << QMetaType::ID;
|
||||
FOR_EACH_GUI_METATYPE(ADD_METATYPE_TEST_ROW)
|
||||
#undef ADD_METATYPE_TEST_ROW
|
||||
}
|
||||
@ -228,11 +228,11 @@ template <int ID>
|
||||
static void testCreateHelper()
|
||||
{
|
||||
typedef typename MetaEnumToType<ID>::Type Type;
|
||||
void *actual = QMetaType::create(ID);
|
||||
void *actual = QMetaType(ID).create();
|
||||
Type *expected = DefaultValueFactory<ID>::create();
|
||||
QVERIFY(TypeComparator<ID>::equal(*static_cast<Type *>(actual), *expected));
|
||||
delete expected;
|
||||
QMetaType::destroy(ID, actual);
|
||||
QMetaType(ID).destroy(actual);
|
||||
}
|
||||
|
||||
typedef void (*TypeTestFunction)();
|
||||
@ -268,9 +268,9 @@ static void testCreateCopyHelper()
|
||||
{
|
||||
typedef typename MetaEnumToType<ID>::Type Type;
|
||||
Type *expected = TestValueFactory<ID>::create();
|
||||
void *actual = QMetaType::create(ID, expected);
|
||||
void *actual = QMetaType(ID).create(expected);
|
||||
QVERIFY(TypeComparator<ID>::equal(*static_cast<Type*>(actual), *expected));
|
||||
QMetaType::destroy(ID, actual);
|
||||
QMetaType(ID).destroy(actual);
|
||||
delete expected;
|
||||
}
|
||||
|
||||
@ -300,7 +300,7 @@ void tst_QGuiMetaType::sizeOf_data()
|
||||
QTest::addColumn<QMetaType::Type>("type");
|
||||
QTest::addColumn<int>("size");
|
||||
#define ADD_METATYPE_TEST_ROW(TYPE, ID) \
|
||||
QTest::newRow(QMetaType::typeName(QMetaType::ID)) << QMetaType::ID << int(sizeof(TYPE));
|
||||
QTest::newRow(QMetaType(QMetaType::ID).name()) << QMetaType::ID << int(sizeof(TYPE));
|
||||
FOR_EACH_GUI_METATYPE(ADD_METATYPE_TEST_ROW)
|
||||
#undef ADD_METATYPE_TEST_ROW
|
||||
}
|
||||
@ -309,7 +309,7 @@ void tst_QGuiMetaType::sizeOf()
|
||||
{
|
||||
QFETCH(QMetaType::Type, type);
|
||||
QFETCH(int, size);
|
||||
QCOMPARE(QMetaType::sizeOf(type), size);
|
||||
QCOMPARE(QMetaType(type).sizeOf(), size);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
@ -336,9 +336,9 @@ void tst_QGuiMetaType::flags()
|
||||
QFETCH(bool, isRelocatable);
|
||||
QFETCH(bool, isComplex);
|
||||
|
||||
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsConstruction), isComplex);
|
||||
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::NeedsDestruction), isComplex);
|
||||
QCOMPARE(bool(QMetaType::typeFlags(type) & QMetaType::MovableType), isRelocatable);
|
||||
QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsConstruction), isComplex);
|
||||
QCOMPARE(bool(QMetaType(type).flags() & QMetaType::NeedsDestruction), isComplex);
|
||||
QCOMPARE(bool(QMetaType(type).flags() & QMetaType::MovableType), isRelocatable);
|
||||
}
|
||||
|
||||
|
||||
@ -351,14 +351,14 @@ template <int ID>
|
||||
static void testConstructHelper()
|
||||
{
|
||||
typedef typename MetaEnumToType<ID>::Type Type;
|
||||
int size = QMetaType::sizeOf(ID);
|
||||
int size = QMetaType(ID).sizeOf();
|
||||
void *storage = qMallocAligned(size, TypeAlignment<Type>::Value);
|
||||
void *actual = QMetaType::construct(ID, storage, /*copy=*/0);
|
||||
void *actual = QMetaType(ID).construct(storage, /*copy=*/0);
|
||||
QCOMPARE(actual, storage);
|
||||
Type *expected = DefaultValueFactory<ID>::create();
|
||||
QVERIFY2(TypeComparator<ID>::equal(*static_cast<Type *>(actual), *expected), QMetaType::typeName(ID));
|
||||
QVERIFY2(TypeComparator<ID>::equal(*static_cast<Type *>(actual), *expected), QMetaType(ID).name());
|
||||
delete expected;
|
||||
QMetaType::destruct(ID, actual);
|
||||
QMetaType(ID).destruct(actual);
|
||||
qFreeAligned(storage);
|
||||
}
|
||||
|
||||
@ -393,12 +393,12 @@ static void testConstructCopyHelper()
|
||||
{
|
||||
typedef typename MetaEnumToType<ID>::Type Type;
|
||||
Type *expected = TestValueFactory<ID>::create();
|
||||
int size = QMetaType::sizeOf(ID);
|
||||
int size = QMetaType(ID).sizeOf();
|
||||
void *storage = qMallocAligned(size, TypeAlignment<Type>::Value);
|
||||
void *actual = QMetaType::construct(ID, storage, expected);
|
||||
void *actual = QMetaType(ID).construct(storage, expected);
|
||||
QCOMPARE(actual, storage);
|
||||
QVERIFY2(TypeComparator<ID>::equal(*static_cast<Type*>(actual), *expected), QMetaType::typeName(ID));
|
||||
QMetaType::destruct(ID, actual);
|
||||
QVERIFY2(TypeComparator<ID>::equal(*static_cast<Type*>(actual), *expected), QMetaType(ID).name());
|
||||
QMetaType(ID).destruct(actual);
|
||||
qFreeAligned(storage);
|
||||
delete expected;
|
||||
}
|
||||
@ -447,25 +447,25 @@ void tst_QGuiMetaType::saveAndLoadBuiltin()
|
||||
QFETCH(int, type);
|
||||
QFETCH(bool, isStreamable);
|
||||
|
||||
void *value = QMetaType::create(type);
|
||||
void *value = QMetaType(type).create();
|
||||
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::ReadWrite);
|
||||
QCOMPARE(QMetaType::save(stream, type, value), isStreamable);
|
||||
QCOMPARE(QMetaType(type).save(stream, value), isStreamable);
|
||||
QCOMPARE(stream.status(), QDataStream::Ok);
|
||||
|
||||
if (isStreamable)
|
||||
QVERIFY(QMetaType::load(stream, type, value));
|
||||
QVERIFY(QMetaType(type).load(stream, value));
|
||||
|
||||
stream.device()->seek(0);
|
||||
stream.resetStatus();
|
||||
QCOMPARE(QMetaType::load(stream, type, value), isStreamable);
|
||||
QCOMPARE(QMetaType(type).load(stream, value), isStreamable);
|
||||
QCOMPARE(stream.status(), QDataStream::Ok);
|
||||
|
||||
if (isStreamable)
|
||||
QVERIFY(QMetaType::load(stream, type, value));
|
||||
QVERIFY(QMetaType(type).load(stream, value));
|
||||
|
||||
QMetaType::destroy(type, value);
|
||||
QMetaType(type).destroy(value);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QGuiMetaType)
|
||||
|
@ -225,7 +225,7 @@ void tst_QGuiVariant::toInt()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( int, result );
|
||||
QFETCH( bool, valueOK );
|
||||
QVERIFY( value.isValid() == value.canConvert( QVariant::Int ) );
|
||||
QVERIFY(value.isValid() == value.canConvert(QMetaType(QMetaType::Int)));
|
||||
bool ok;
|
||||
int i = value.toInt( &ok );
|
||||
QCOMPARE( i, result );
|
||||
@ -255,10 +255,10 @@ void tst_QGuiVariant::toColor()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QColor, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::Color ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QColor)));
|
||||
QColor d = qvariant_cast<QColor>(value);
|
||||
QCOMPARE( d, result );
|
||||
QVERIFY(value.convert(QMetaType::QColor));
|
||||
QVERIFY(value.convert(QMetaType(QMetaType::QColor)));
|
||||
QCOMPARE(d, QColor(value.toString()));
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ void tst_QGuiVariant::toPixmap()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QPixmap, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::Pixmap ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QPixmap)));
|
||||
QPixmap d = qvariant_cast<QPixmap>(value);
|
||||
QCOMPARE( d, result );
|
||||
}
|
||||
@ -301,7 +301,7 @@ void tst_QGuiVariant::toImage()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QImage, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::Image ) );
|
||||
QVERIFY( value.canConvert(QMetaType(QMetaType::QImage)));
|
||||
QImage d = qvariant_cast<QImage>(value);
|
||||
QCOMPARE( d, result );
|
||||
}
|
||||
@ -323,7 +323,7 @@ void tst_QGuiVariant::toBrush()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QBrush, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::Brush ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QBrush)));
|
||||
QBrush d = qvariant_cast<QBrush>(value);
|
||||
QCOMPARE( d, result );
|
||||
}
|
||||
@ -342,7 +342,7 @@ void tst_QGuiVariant::toFont()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QFont, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::Font ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QFont)));
|
||||
QFont d = qvariant_cast<QFont>(value);
|
||||
QCOMPARE( d, result );
|
||||
}
|
||||
@ -366,7 +366,7 @@ void tst_QGuiVariant::toKeySequence()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QKeySequence, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::KeySequence ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QKeySequence)));
|
||||
QKeySequence d = qvariant_cast<QKeySequence>(value);
|
||||
QCOMPARE( d, result );
|
||||
}
|
||||
@ -393,7 +393,7 @@ void tst_QGuiVariant::toString()
|
||||
QFETCH( QVariant, value );
|
||||
QFETCH( QString, result );
|
||||
QVERIFY( value.isValid() );
|
||||
QVERIFY( value.canConvert( QVariant::String ) );
|
||||
QVERIFY(value.canConvert(QMetaType(QMetaType::QString)));
|
||||
QString str = value.toString();
|
||||
QCOMPARE( str, result );
|
||||
}
|
||||
@ -408,9 +408,9 @@ void tst_QGuiVariant::matrix4x4()
|
||||
variant.setValue(m);
|
||||
QCOMPARE(m, qvariant_cast<QMatrix4x4>(variant));
|
||||
|
||||
void *mmatrix = QMetaType::create(QVariant::Matrix4x4, 0);
|
||||
void *mmatrix = QMetaType(QMetaType::QMatrix4x4).create();
|
||||
QVERIFY(mmatrix);
|
||||
QMetaType::destroy(QVariant::Matrix4x4, mmatrix);
|
||||
QMetaType(QMetaType::QMatrix4x4).destroy(mmatrix);
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::transform()
|
||||
@ -421,9 +421,9 @@ void tst_QGuiVariant::transform()
|
||||
variant.setValue(QTransform().rotate(90));
|
||||
QCOMPARE(QTransform().rotate(90), qvariant_cast<QTransform>(variant));
|
||||
|
||||
void *mmatrix = QMetaType::create(QVariant::Transform, 0);
|
||||
void *mmatrix = QMetaType(QMetaType::QTransform).create();
|
||||
QVERIFY(mmatrix);
|
||||
QMetaType::destroy(QVariant::Transform, mmatrix);
|
||||
QMetaType(QMetaType::QTransform).destroy(mmatrix);
|
||||
}
|
||||
|
||||
|
||||
@ -435,9 +435,9 @@ void tst_QGuiVariant::vector2D()
|
||||
variant.setValue(QVector2D(0.1f, 0.2f));
|
||||
QCOMPARE(QVector2D(0.1f, 0.2f), qvariant_cast<QVector2D>(variant));
|
||||
|
||||
void *pvector = QMetaType::create(QVariant::Vector2D, 0);
|
||||
void *pvector = QMetaType(QMetaType::QVector2D).create();
|
||||
QVERIFY(pvector);
|
||||
QMetaType::destroy(QVariant::Vector2D, pvector);
|
||||
QMetaType(QMetaType::QVector2D).destroy(pvector);
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::vector3D()
|
||||
@ -448,9 +448,9 @@ void tst_QGuiVariant::vector3D()
|
||||
variant.setValue(QVector3D(0.1f, 0.2f, 0.3f));
|
||||
QCOMPARE(QVector3D(0.1f, 0.2f, 0.3f), qvariant_cast<QVector3D>(variant));
|
||||
|
||||
void *pvector = QMetaType::create(QVariant::Vector3D, 0);
|
||||
void *pvector = QMetaType(QMetaType::QVector3D).create();
|
||||
QVERIFY(pvector);
|
||||
QMetaType::destroy(QVariant::Vector3D, pvector);
|
||||
QMetaType(QMetaType::QVector3D).destroy(pvector);
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::vector4D()
|
||||
@ -461,9 +461,9 @@ void tst_QGuiVariant::vector4D()
|
||||
variant.setValue(QVector4D(0.1f, 0.2f, 0.3f, 0.4f));
|
||||
QCOMPARE(QVector4D(0.1f, 0.2f, 0.3f, 0.4f), qvariant_cast<QVector4D>(variant));
|
||||
|
||||
void *pvector = QMetaType::create(QVariant::Vector4D, 0);
|
||||
void *pvector = QMetaType(QMetaType::QVector4D).create();
|
||||
QVERIFY(pvector);
|
||||
QMetaType::destroy(QVariant::Vector4D, pvector);
|
||||
QMetaType(QMetaType::QVector4D).destroy(pvector);
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::quaternion()
|
||||
@ -474,9 +474,9 @@ void tst_QGuiVariant::quaternion()
|
||||
variant.setValue(QQuaternion(0.1f, 0.2f, 0.3f, 0.4f));
|
||||
QCOMPARE(QQuaternion(0.1f, 0.2f, 0.3f, 0.4f), qvariant_cast<QQuaternion>(variant));
|
||||
|
||||
void *pquaternion = QMetaType::create(QVariant::Quaternion, 0);
|
||||
void *pquaternion = QMetaType(QMetaType::QQuaternion).create();
|
||||
QVERIFY(pquaternion);
|
||||
QMetaType::destroy(QVariant::Quaternion, pquaternion);
|
||||
QMetaType(QMetaType::QQuaternion).destroy(pquaternion);
|
||||
}
|
||||
|
||||
void tst_QGuiVariant::writeToReadFromDataStream_data()
|
||||
@ -513,9 +513,9 @@ void tst_QGuiVariant::writeToReadFromDataStream_data()
|
||||
void tst_QGuiVariant::invalidQColor()
|
||||
{
|
||||
QVariant va("An invalid QColor::name() value.");
|
||||
QVERIFY(va.canConvert(QVariant::Color));
|
||||
QVERIFY(va.canConvert(QMetaType(QMetaType::QColor)));
|
||||
|
||||
QVERIFY(!va.convert(QVariant::Color));
|
||||
QVERIFY(!va.convert(QMetaType(QMetaType::QColor)));
|
||||
|
||||
QVERIFY(!qvariant_cast<QColor>(va).isValid());
|
||||
}
|
||||
@ -524,13 +524,13 @@ void tst_QGuiVariant::validQColor()
|
||||
{
|
||||
QColor col(Qt::red);
|
||||
QVariant va(col.name());
|
||||
QVERIFY(va.canConvert(QVariant::Color));
|
||||
QVERIFY(va.canConvert(QMetaType(QMetaType::QColor)));
|
||||
|
||||
QVERIFY(va.convert(QVariant::Color));
|
||||
QVERIFY(va.convert(QMetaType(QMetaType::QColor)));
|
||||
|
||||
QVERIFY(col.isValid());
|
||||
|
||||
QVERIFY(va.convert(QVariant::String));
|
||||
QVERIFY(va.convert(QMetaType(QMetaType::QString)));
|
||||
|
||||
QCOMPARE(qvariant_cast<QString>(va), col.name());
|
||||
}
|
||||
@ -538,15 +538,15 @@ void tst_QGuiVariant::validQColor()
|
||||
void tst_QGuiVariant::colorInteger()
|
||||
{
|
||||
QVariant v = QColor(Qt::red);
|
||||
QCOMPARE(v.type(), QVariant::Color);
|
||||
QCOMPARE(v.metaType(), QMetaType(QMetaType::QColor));
|
||||
QCOMPARE(v.value<QColor>(), QColor(Qt::red));
|
||||
|
||||
v.setValue(1000);
|
||||
QCOMPARE(v.type(), QVariant::Int);
|
||||
QCOMPARE(v.metaType(), QMetaType(QMetaType::Int));
|
||||
QCOMPARE(v.toInt(), 1000);
|
||||
|
||||
v.setValue(QColor(Qt::yellow));
|
||||
QCOMPARE(v.type(), QVariant::Color);
|
||||
QCOMPARE(v.metaType(), QMetaType(QMetaType::QColor));
|
||||
QCOMPARE(v.value<QColor>(), QColor(Qt::yellow));
|
||||
}
|
||||
|
||||
@ -652,7 +652,7 @@ void tst_QGuiVariant::debugStream_data()
|
||||
QTest::addColumn<QVariant>("variant");
|
||||
QTest::addColumn<int>("typeId");
|
||||
for (int id = QMetaType::FirstGuiType; id <= QMetaType::LastGuiType; ++id) {
|
||||
const char *tagName = QMetaType::typeName(id);
|
||||
const char *tagName = QMetaType(id).name();
|
||||
if (!tagName)
|
||||
continue;
|
||||
QTest::newRow(tagName) << QVariant(static_cast<QVariant::Type>(id)) << id;
|
||||
|
@ -1323,10 +1323,9 @@ void tst_QQuaternion::properties()
|
||||
|
||||
void tst_QQuaternion::metaTypes()
|
||||
{
|
||||
QCOMPARE(QMetaType::type("QQuaternion"), int(QMetaType::QQuaternion));
|
||||
QCOMPARE(QMetaType::fromName("QQuaternion").id(), int(QMetaType::QQuaternion));
|
||||
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QQuaternion)),
|
||||
QByteArray("QQuaternion"));
|
||||
QCOMPARE(QByteArray(QMetaType(QMetaType::QQuaternion).name()), QByteArray("QQuaternion"));
|
||||
|
||||
QVERIFY(QMetaType::isRegistered(QMetaType::QQuaternion));
|
||||
|
||||
|
@ -2662,15 +2662,15 @@ void tst_QVectorND::properties()
|
||||
|
||||
void tst_QVectorND::metaTypes()
|
||||
{
|
||||
QCOMPARE(QMetaType::type("QVector2D"), int(QMetaType::QVector2D));
|
||||
QCOMPARE(QMetaType::type("QVector3D"), int(QMetaType::QVector3D));
|
||||
QCOMPARE(QMetaType::type("QVector4D"), int(QMetaType::QVector4D));
|
||||
QCOMPARE(QMetaType::fromName("QVector2D").id(), int(QMetaType::QVector2D));
|
||||
QCOMPARE(QMetaType::fromName("QVector3D").id(), int(QMetaType::QVector3D));
|
||||
QCOMPARE(QMetaType::fromName("QVector4D").id(), int(QMetaType::QVector4D));
|
||||
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QVector2D)),
|
||||
QCOMPARE(QByteArray(QMetaType(QMetaType::QVector2D).name()),
|
||||
QByteArray("QVector2D"));
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QVector3D)),
|
||||
QCOMPARE(QByteArray(QMetaType(QMetaType::QVector3D).name()),
|
||||
QByteArray("QVector3D"));
|
||||
QCOMPARE(QByteArray(QMetaType::typeName(QMetaType::QVector4D)),
|
||||
QCOMPARE(QByteArray(QMetaType(QMetaType::QVector4D).name()),
|
||||
QByteArray("QVector4D"));
|
||||
|
||||
QVERIFY(QMetaType::isRegistered(QMetaType::QVector2D));
|
||||
|
@ -56,14 +56,14 @@ protected:
|
||||
QVERIFY2(ok, (QString::fromLatin1("Message is not started correctly: '") + msg + '\'').toLatin1().constData());
|
||||
ok &= (currentId == QMetaType::UnknownType
|
||||
? msg.contains("Invalid")
|
||||
: msg.contains(QMetaType::typeName(currentId)));
|
||||
: msg.contains(QMetaType(currentId).name()));
|
||||
QVERIFY2(ok, (QString::fromLatin1("Message doesn't contain type name: '") + msg + '\'').toLatin1().constData());
|
||||
if (currentId == QMetaType::Char || currentId == QMetaType::QChar) {
|
||||
// Chars insert '\0' into the qdebug stream, it is not possible to find a real string length
|
||||
return;
|
||||
}
|
||||
if (QMetaType::typeFlags(currentId) & QMetaType::IsPointer) {
|
||||
QByteArray currentName = QMetaType::typeName(currentId);
|
||||
if (QMetaType(currentId).flags() & QMetaType::IsPointer) {
|
||||
QByteArray currentName = QMetaType(currentId).name();
|
||||
ok &= msg.contains(currentName + ", 0x");
|
||||
}
|
||||
ok &= msg.endsWith(QLatin1Char(')'));
|
||||
@ -147,38 +147,38 @@ int MessageHandler::currentId;
|
||||
QFETCH(bool, ULongLongCast);
|
||||
|
||||
#define TST_QVARIANT_CANCONVERT_COMPARE_DATA \
|
||||
QCOMPARE(val.canConvert(QVariant::BitArray), BitArrayCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Bitmap), BitmapCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Bool), BoolCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Brush), BrushCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::ByteArray), ByteArrayCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Color), ColorCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Cursor), CursorCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Date), DateCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::DateTime), DateTimeCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Double), DoubleCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Type(QMetaType::Float)), DoubleCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Font), FontCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Image), ImageCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Int), IntCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Invalid), InvalidCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::KeySequence), KeySequenceCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::List), ListCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::LongLong), LongLongCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Map), MapCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Palette), PaletteCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Pen), PenCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Pixmap), PixmapCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Point), PointCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Rect), RectCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Region), RegionCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Size), SizeCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::SizePolicy), SizePolicyCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::String), StringCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::StringList), StringListCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::Time), TimeCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::UInt), UIntCast); \
|
||||
QCOMPARE(val.canConvert(QVariant::ULongLong), ULongLongCast);
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QBitArray)), BitArrayCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QBitmap)), BitmapCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::Bool)), BoolCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QBrush)), BrushCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QByteArray)), ByteArrayCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QColor)), ColorCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QCursor)), CursorCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QDate)), DateCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QDateTime)), DateTimeCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::Double)), DoubleCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::Float)), DoubleCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QFont)), FontCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QImage)), ImageCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::Int)), IntCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::UnknownType)), InvalidCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QKeySequence)), KeySequenceCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QVariantList)), ListCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::LongLong)), LongLongCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QVariantMap)), MapCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QPalette)), PaletteCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QPen)), PenCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QPixmap)), PixmapCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QPoint)), PointCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QRect)), RectCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QRegion)), RegionCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QSize)), SizeCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QSizePolicy)), SizePolicyCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QString)), StringCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QStringList)), StringListCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::QTime)), TimeCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::UInt)), UIntCast); \
|
||||
QCOMPARE(val.canConvert(QMetaType(QMetaType::ULongLong)), ULongLongCast);
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -64,10 +64,10 @@ static_assert((!QMetaTypeId2<QMap<QString,QSizePolicy> >::IsBuiltIn));
|
||||
|
||||
void tst_QWidgetMetaType::metaObject()
|
||||
{
|
||||
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QWidget*>()), &QWidget::staticMetaObject);
|
||||
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QLabel*>()), &QLabel::staticMetaObject);
|
||||
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<CustomWidget*>()), &CustomWidget::staticMetaObject);
|
||||
QCOMPARE(QMetaType::metaObjectForType(qMetaTypeId<QSizePolicy>()), &QSizePolicy::staticMetaObject);
|
||||
QCOMPARE(QMetaType::fromType<QWidget*>().metaObject(), &QWidget::staticMetaObject);
|
||||
QCOMPARE(QMetaType::fromType<QLabel*>().metaObject(), &QLabel::staticMetaObject);
|
||||
QCOMPARE(QMetaType::fromType<CustomWidget*>().metaObject(), &CustomWidget::staticMetaObject);
|
||||
QCOMPARE(QMetaType::fromType<QSizePolicy>().metaObject(), &QSizePolicy::staticMetaObject);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -93,25 +93,25 @@ void tst_QWidgetMetaType::saveAndLoadBuiltin()
|
||||
QFETCH(int, type);
|
||||
QFETCH(bool, isStreamable);
|
||||
|
||||
void *value = QMetaType::create(type);
|
||||
void *value = QMetaType(type).create();
|
||||
|
||||
QByteArray ba;
|
||||
QDataStream stream(&ba, QIODevice::ReadWrite);
|
||||
QCOMPARE(QMetaType::save(stream, type, value), isStreamable);
|
||||
QCOMPARE(QMetaType(type).save(stream, value), isStreamable);
|
||||
QCOMPARE(stream.status(), QDataStream::Ok);
|
||||
|
||||
if (isStreamable)
|
||||
QVERIFY(QMetaType::load(stream, type, value));
|
||||
QVERIFY(QMetaType(type).load(stream, value));
|
||||
|
||||
stream.device()->seek(0);
|
||||
stream.resetStatus();
|
||||
QCOMPARE(QMetaType::load(stream, type, value), isStreamable);
|
||||
QCOMPARE(QMetaType(type).load(stream, value), isStreamable);
|
||||
QCOMPARE(stream.status(), QDataStream::Ok);
|
||||
|
||||
if (isStreamable)
|
||||
QVERIFY(QMetaType::load(stream, type, value));
|
||||
QVERIFY(QMetaType(type).load(stream, value));
|
||||
|
||||
QMetaType::destroy(type, value);
|
||||
QMetaType(type).destroy(value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -176,24 +176,24 @@ void tst_QWidgetsVariant::qvariant_cast_QObject()
|
||||
if (success) {
|
||||
QCOMPARE(o->objectName(), QString::fromLatin1("Hello"));
|
||||
QVERIFY(data.canConvert<QObject*>());
|
||||
QVERIFY(data.canConvert(QMetaType::QObjectStar));
|
||||
QVERIFY(data.canConvert(::qMetaTypeId<QObject*>()));
|
||||
QVERIFY(data.canConvert(QMetaType(QMetaType::QObjectStar)));
|
||||
QVERIFY(data.canConvert(QMetaType::fromType<QObject*>()));
|
||||
QVERIFY(data.value<QObject*>());
|
||||
QVERIFY(data.convert(QMetaType::QObjectStar));
|
||||
QCOMPARE(data.userType(), int(QMetaType::QObjectStar));
|
||||
QVERIFY(data.convert(QMetaType(QMetaType::QObjectStar)));
|
||||
QCOMPARE(data.metaType().id(), int(QMetaType::QObjectStar));
|
||||
|
||||
QVERIFY(data.canConvert<QWidget*>());
|
||||
QVERIFY(data.canConvert(::qMetaTypeId<QWidget*>()));
|
||||
QVERIFY(data.canConvert(QMetaType::fromType<QWidget*>()));
|
||||
QVERIFY(data.value<QWidget*>());
|
||||
QVERIFY(data.convert(qMetaTypeId<QWidget*>()));
|
||||
QCOMPARE(data.userType(), qMetaTypeId<QWidget*>());
|
||||
QVERIFY(data.convert(QMetaType::fromType<QWidget*>()));
|
||||
QCOMPARE(data.metaType(), QMetaType::fromType<QWidget*>());
|
||||
} else {
|
||||
QVERIFY(!data.canConvert<QObject*>());
|
||||
QVERIFY(!data.canConvert(QMetaType::QObjectStar));
|
||||
QVERIFY(!data.canConvert(::qMetaTypeId<QObject*>()));
|
||||
QVERIFY(!data.canConvert(QMetaType(QMetaType::QObjectStar)));
|
||||
QVERIFY(!data.canConvert(QMetaType::fromType<QObject*>()));
|
||||
QVERIFY(!data.value<QObject*>());
|
||||
QVERIFY(!data.convert(QMetaType::QObjectStar));
|
||||
QVERIFY(data.userType() != QMetaType::QObjectStar);
|
||||
QVERIFY(!data.convert(QMetaType(QMetaType::QObjectStar)));
|
||||
QVERIFY(data.metaType().id() != QMetaType::QObjectStar);
|
||||
}
|
||||
delete o;
|
||||
}
|
||||
@ -215,7 +215,7 @@ void tst_QWidgetsVariant::debugStream_data()
|
||||
QTest::addColumn<QVariant>("variant");
|
||||
QTest::addColumn<int>("typeId");
|
||||
for (int id = QMetaType::LastGuiType + 1; id < QMetaType::User; ++id) {
|
||||
const char *tagName = QMetaType::typeName(id);
|
||||
const char *tagName = QMetaType(id).name();
|
||||
if (!tagName)
|
||||
continue;
|
||||
QTest::newRow(tagName) << QVariant(static_cast<QVariant::Type>(id)) << id;
|
||||
|
Loading…
Reference in New Issue
Block a user