QVariant::Type is marked as obsolete. It is not possible to get rid of
it completely, in a source compatible way, but at least we can remove it
safely from a method arguments list.
Change-Id: I26b58099bfa6d32f3a583a8ae0047f0bb36bcd0d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Converts \a d to type \a t, which is placed in \a result.
*/
Converts \a d to type \a t, which is placed in \a result.
*/
-static bool convert(const QVariant::Private *d, QVariant::Type t, void *result, bool *ok)
+static bool convert(const QVariant::Private *d, int t, void *result, bool *ok)
{
Q_ASSERT(d->type != uint(t));
Q_ASSERT(result);
{
Q_ASSERT(d->type != uint(t));
Q_ASSERT(result);
static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to clear an unknown type"); }
static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; }
static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; }
static void dummyClear(QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to clear an unknown type"); }
static bool dummyIsNull(const QVariant::Private *d) { Q_ASSERT_X(false, "QVariant::isNull", "Trying to call isNull on an unknown type"); return d->is_null; }
static bool dummyCompare(const QVariant::Private *, const QVariant::Private *) { Q_ASSERT_X(false, "QVariant", "Trying to compare an unknown types"); return false; }
-static bool dummyConvert(const QVariant::Private *, QVariant::Type , void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
+static bool dummyConvert(const QVariant::Private *, int, void *, bool *) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); return false; }
#if !defined(QT_NO_DEBUG_STREAM)
static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); }
#endif
#if !defined(QT_NO_DEBUG_STREAM)
static void dummyStreamDebug(QDebug, const QVariant &) { Q_ASSERT_X(false, "QVariant", "Trying to convert an unknown type"); }
#endif
return !memcmp(a_ptr, b_ptr, QMetaType::sizeOf(a->type));
}
return !memcmp(a_ptr, b_ptr, QMetaType::sizeOf(a->type));
}
-static bool customConvert(const QVariant::Private *, QVariant::Type, void *, bool *ok)
+static bool customConvert(const QVariant::Private *, int, void *, bool *ok)
- \fn QVariant::QVariant(int typeOrUserType, const void *copy)
+ \fn QVariant::QVariant(int typeId, const void *copy)
- Constructs variant of type \a typeOrUserType, and initializes with
+ Constructs variant of type \a typeId, and initializes with
\a copy if \a copy is not 0.
Note that you have to pass the address of the variable you want stored.
\a copy if \a copy is not 0.
Note that you have to pass the address of the variable you want stored.
UTF-8 encoding on the input \a val.
Note that \a val is converted to a QString for storing in the
UTF-8 encoding on the input \a val.
Note that \a val is converted to a QString for storing in the
- variant and QVariant::type() will return QMetaType::QString for
+ variant and QVariant::userType() will return QMetaType::QString for
the variant.
You can disable this operator by defining \c
the variant.
You can disable this operator by defining \c
QVariant::QVariant(Type type)
{ create(type, 0); }
QVariant::QVariant(Type type)
{ create(type, 0); }
-QVariant::QVariant(int typeOrUserType, const void *copy)
-{ create(typeOrUserType, copy); d.is_null = false; }
+QVariant::QVariant(int typeId, const void *copy)
+{ create(typeId, copy); d.is_null = false; }
/*! \internal
flags is true if it is a pointer type
*/
/*! \internal
flags is true if it is a pointer type
*/
-QVariant::QVariant(int typeOrUserType, const void *copy, uint flags)
+QVariant::QVariant(int typeId, const void *copy, uint flags)
{
if (flags) { //type is a pointer type
{
if (flags) { //type is a pointer type
- d.type = typeOrUserType;
d.data.ptr = *reinterpret_cast<void *const*>(copy);
} else {
d.data.ptr = *reinterpret_cast<void *const*>(copy);
} else {
- create(typeOrUserType, copy);
*/
const char *QVariant::typeName() const
{
*/
const char *QVariant::typeName() const
{
- return typeToName(Type(d.type));
+ return typeToName(d.type);
- Converts the enum representation of the storage type, \a typ, to
+ Converts the int representation of the storage type, \a typeId, to
its string representation.
Returns a null pointer if the type is QVariant::Invalid or doesn't exist.
*/
its string representation.
Returns a null pointer if the type is QVariant::Invalid or doesn't exist.
*/
-const char *QVariant::typeToName(Type typ)
+const char *QVariant::typeToName(int typeId)
- return QMetaType::typeName(typ);
+ return QMetaType::typeName(typeId);
template <typename T>
inline T qVariantToHelper(const QVariant::Private &d, const HandlersManager &handlerManager)
{
template <typename T>
inline T qVariantToHelper(const QVariant::Private &d, const HandlersManager &handlerManager)
{
- const QVariant::Type targetType = static_cast<const QVariant::Type>(qMetaTypeId<T>());
+ const uint targetType = qMetaTypeId<T>();
if (d.type == targetType)
return *v_cast<T>(&d);
if (d.type == targetType)
return *v_cast<T>(&d);
- if (!handlerManager[d.type]->convert(&d, QVariant::Type(t), &ret, ok) && ok)
+ if (!handlerManager[d.type]->convert(&d, t, &ret, ok) && ok)
*ok = false;
return ret;
}
*ok = false;
return ret;
}
/*!
Returns true if the variant's type can be cast to the requested
/*!
Returns true if the variant's type can be cast to the requested
- type, \a t. Such casting is done automatically when calling the
+ type, \a targetTypeId. Such casting is done automatically when calling the
toInt(), toBool(), ... methods.
The following casts are done automatically:
toInt(), toBool(), ... methods.
The following casts are done automatically:
-bool QVariant::canConvert(Type t) const
+bool QVariant::canConvert(int targetTypeId) const
{
// TODO Reimplement this function, currently it works but it is a historical mess.
const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
{
// TODO Reimplement this function, currently it works but it is a historical mess.
const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
- if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double;
+ if (uint(targetTypeId) == uint(QMetaType::Float)) targetTypeId = QVariant::Double;
- if (currentType == uint(t))
+ if (currentType == uint(targetTypeId))
return true;
// FIXME It should be LastCoreType intead of Uuid
return true;
// FIXME It should be LastCoreType intead of Uuid
- if (currentType > QVariant::Uuid || t > QVariant::Uuid) {
- switch (uint(t)) {
+ if (currentType > int(QMetaType::QUuid) || targetTypeId > int(QMetaType::QUuid)) {
+ switch (uint(targetTypeId)) {
case QVariant::Int:
return currentType == QVariant::KeySequence
|| currentType == QMetaType::ULong
case QVariant::Int:
return currentType == QVariant::KeySequence
|| currentType == QMetaType::ULong
- if(t == String && currentType == StringList)
+ if (targetTypeId == String && currentType == StringList)
return v_cast<QStringList>(&d)->count() == 1;
else
return v_cast<QStringList>(&d)->count() == 1;
else
- return qCanConvertMatrix[t] & (1 << currentType);
+ return qCanConvertMatrix[targetTypeId] & (1 << currentType);
- Casts the variant to the requested type, \a t. If the cast cannot be
+ Casts the variant to the requested type, \a targetTypeId. If the cast cannot be
done, the variant is cleared. Returns true if the current type of
the variant was successfully cast; otherwise returns false.
done, the variant is cleared. Returns true if the current type of
the variant was successfully cast; otherwise returns false.
\sa canConvert(), clear()
*/
\sa canConvert(), clear()
*/
-bool QVariant::convert(Type t)
+bool QVariant::convert(int targetTypeId)
+ if (d.type == uint(targetTypeId))
return true;
QVariant oldValue = *this;
clear();
return true;
QVariant oldValue = *this;
clear();
- if (!oldValue.canConvert(t))
+ if (!oldValue.canConvert(targetTypeId))
+ create(targetTypeId, 0);
if (oldValue.isNull())
return false;
bool isOk = true;
if (oldValue.isNull())
return false;
bool isOk = true;
- if (!handlerManager[d.type]->convert(&oldValue.d, t, data(), &isOk))
+ if (!handlerManager[d.type]->convert(&oldValue.d, targetTypeId, data(), &isOk))
isOk = false;
d.is_null = !isOk;
return isOk;
isOk = false;
d.is_null = !isOk;
return isOk;
bool QVariant::convert(const int type, void *ptr) const
{
Q_ASSERT(type < int(QMetaType::User));
bool QVariant::convert(const int type, void *ptr) const
{
Q_ASSERT(type < int(QMetaType::User));
- return handlerManager[type]->convert(&d, QVariant::Type(type), ptr, 0);
+ return handlerManager[type]->convert(&d, type, ptr, 0);
else
return toLongLong() == v.toLongLong();
}
else
return toLongLong() == v.toLongLong();
}
- if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type)))
+ if (!v2.canConvert(d.type) || !v2.convert(d.type))
return false;
}
return handlerManager[d.type]->compare(&d, &v2.d);
return false;
}
return handlerManager[d.type]->compare(&d, &v2.d);
inline QVariant();
~QVariant();
QVariant(Type type);
inline QVariant();
~QVariant();
QVariant(Type type);
- QVariant(int typeOrUserType, const void *copy);
- QVariant(int typeOrUserType, const void *copy, uint flags);
+ QVariant(int typeId, const void *copy);
+ QVariant(int typeId, const void *copy, uint flags);
QVariant(const QVariant &other);
#ifndef QT_NO_DATASTREAM
QVariant(const QVariant &other);
#ifndef QT_NO_DATASTREAM
int userType() const;
const char *typeName() const;
int userType() const;
const char *typeName() const;
- bool canConvert(Type t) const;
- bool convert(Type t);
+ bool canConvert(int targetTypeId) const;
+ bool convert(int targetTypeId);
inline bool isValid() const;
bool isNull() const;
inline bool isValid() const;
bool isNull() const;
void load(QDataStream &ds);
void save(QDataStream &ds) const;
#endif
void load(QDataStream &ds);
void save(QDataStream &ds) const;
#endif
- static const char *typeToName(Type type);
+ static const char *typeToName(int typeId);
static Type nameToType(const char *name);
void *data();
static Type nameToType(const char *name);
void *data();
template<typename T>
bool canConvert() const
template<typename T>
bool canConvert() const
- { return canConvert(Type(qMetaTypeId<T>())); }
+ { return canConvert(qMetaTypeId<T>()); }
typedef void (*f_save)(const Private *, QDataStream &);
#endif
typedef bool (*f_compare)(const Private *, const Private *);
typedef void (*f_save)(const Private *, QDataStream &);
#endif
typedef bool (*f_compare)(const Private *, const Private *);
- typedef bool (*f_convert)(const QVariant::Private *d, Type t, void *, bool *);
- typedef bool (*f_canConvert)(const QVariant::Private *d, Type t);
+ typedef bool (*f_convert)(const QVariant::Private *d, int t, void *, bool *);
+ typedef bool (*f_canConvert)(const QVariant::Private *d, int t);
typedef void (*f_debugStream)(QDebug, const QVariant &);
struct Handler {
f_construct construct;
typedef void (*f_debugStream)(QDebug, const QVariant &);
struct Handler {
f_construct construct;
return *reinterpret_cast<const T *>(v.constData());
if (vid < int(QMetaType::User)) {
T t;
return *reinterpret_cast<const T *>(v.constData());
if (vid < int(QMetaType::User)) {
T t;
- if (v.convert(QVariant::Type(vid), &t))
+ if (v.convert(vid, &t))
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() ?)",
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() ?)",
- QVariant::typeToName( QVariant::Type(id) ),
+ QMetaType::typeName(id),
signature.isEmpty() ? "<empty>" : signature.constData());
return "";
} else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
signature.isEmpty() ? "<empty>" : signature.constData());
return "";
} else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
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() ?)",
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() ?)",
- QVariant::typeToName( QVariant::Type(id) ),
+ QMetaType::typeName(id),
- QVariant::typeToName( QVariant::Type(QDBusMetaType::signatureToType(signature))) );
+ QMetaType::typeName(QDBusMetaType::signatureToType(signature)));
return "";
}
return signature;
return "";
}
return signature;
return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
}
return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, 0);
}
-static bool convert(const QVariant::Private *d, QVariant::Type t,
+static bool convert(const QVariant::Private *d, int t,
void *result, bool *ok)
{
switch (t) {
void *result, bool *ok)
{
switch (t) {
-static bool convert(const QVariant::Private *d, QVariant::Type type, void *result, bool *ok)
+static bool convert(const QVariant::Private *d, int type, void *result, bool *ok)
{
Q_UNUSED(d);
Q_UNUSED(type);
{
Q_UNUSED(d);
Q_UNUSED(type);
dbg.nospace() << *v_cast<QSizePolicy>(d);
break;
default:
dbg.nospace() << *v_cast<QSizePolicy>(d);
break;
default:
- dbg.nospace() << "QVariant::Type(" << d->type << ")";
+ dbg.nospace() << "QMetaType::Type(" << d->type << ")";
qWarning() << "Unexpected QVariant type" << v2.userType()
<< QByteArray(QDBusMetaType::typeToSignature(v2.userType()))
qWarning() << "Unexpected QVariant type" << v2.userType()
<< QByteArray(QDBusMetaType::typeToSignature(v2.userType()))
- << QVariant::typeToName(QVariant::Type(v2.userType()));
+ << QMetaType::typeName(v2.userType());