From 11bad6109606794091adc3b8a14070ac09707f45 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 10 Sep 2020 17:05:10 +0200 Subject: Deprecate QVariant::Type It's been obsolete for a long time already. Make sure the compiler now warns about it and remove all remaining uses in qtbase. Change-Id: I0ff80311184dba52d2ba5f4e2fabe0d47fdc59d7 Reviewed-by: Fabian Kosmale --- .../snippets/code/src_corelib_kernel_qvariant.cpp | 2 +- src/corelib/io/qsettings.cpp | 6 +- src/corelib/io/qsettings_mac.cpp | 30 +- src/corelib/io/qsettings_win.cpp | 16 +- src/corelib/kernel/qmetaobject.cpp | 23 +- src/corelib/kernel/qmetaobject.h | 11 +- src/corelib/kernel/qvariant.cpp | 124 ++++---- src/corelib/kernel/qvariant.h | 55 +++- src/corelib/serialization/qjsoncbor.cpp | 4 +- src/corelib/serialization/qjsondocument.cpp | 2 +- src/corelib/serialization/qjsonvalue.cpp | 2 +- src/corelib/text/qlocale.qdoc | 2 +- src/corelib/text/qlocale_mac.mm | 10 +- src/corelib/text/qlocale_win.cpp | 10 +- .../doc/snippets/code/src_qdbus_qdbusargument.cpp | 2 +- src/dbus/qdbusargument.cpp | 2 +- src/dbus/qdbusmarshaller.cpp | 4 +- src/gui/text/qtextdocument.cpp | 8 +- src/gui/text/qtextformat.cpp | 10 +- .../platforms/android/qandroidsystemlocale.cpp | 10 +- .../platforms/windows/qwindowsinternalmimedata.cpp | 2 +- .../uiautomation/qwindowsuiamainprovider.cpp | 2 +- src/plugins/sqldrivers/db2/qsql_db2.cpp | 72 ++--- src/plugins/sqldrivers/ibase/qsql_ibase.cpp | 92 +++--- src/plugins/sqldrivers/oci/qsql_oci.cpp | 344 ++++++++++----------- src/plugins/sqldrivers/odbc/qsql_odbc.cpp | 74 ++--- src/plugins/sqldrivers/psql/qsql_psql.cpp | 65 ++-- .../doc/snippets/code/src_sql_kernel_qsqlquery.cpp | 2 +- src/sql/kernel/qsqlfield.h | 14 +- src/sql/kernel/qsqlquery.cpp | 6 +- src/sql/kernel/qsqlresult.cpp | 2 +- .../doc/snippets/code/doc_src_qsignalspy.cpp | 6 +- .../code/src_gui_itemviews_qitemeditorfactory.cpp | 2 +- src/widgets/itemviews/qitemeditorfactory.cpp | 4 +- src/widgets/widgets/qcombobox.cpp | 2 +- 35 files changed, 523 insertions(+), 499 deletions(-) (limited to 'src') diff --git a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp index ca1ea21b02..1df3fa9edb 100644 --- a/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_kernel_qvariant.cpp @@ -71,7 +71,7 @@ v = QVariant(QStringList()); //! [1] QVariant x, y(QString()), z(QString("")); -x.convert(QVariant::Int); +x.convert(QMetaType::Int); // x.isNull() == true // y.isNull() == true, z.isNull() == false //! [1] diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 547f2759f5..a2888e0953 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -381,7 +381,7 @@ QString QSettingsPrivate::variantToString(const QVariant &v) { QString result; - switch (v.userType()) { + switch (v.metaType().id()) { case QMetaType::UnknownType: result = QLatin1String("@Invalid()"); break; @@ -1815,8 +1815,8 @@ bool QConfFileSettingsPrivate::writeIniFile(QIODevice &device, const ParsedSetti QVariant(QString("foo")).toList() returns an empty list, not a list containing "foo". */ - if (value.userType() == QMetaType::QStringList - || (value.userType() == QMetaType::QVariantList && value.toList().size() != 1)) { + if (value.metaType().id() == QMetaType::QStringList + || (value.metaType().id() == QMetaType::QVariantList && value.toList().size() != 1)) { iniEscapedStringList(variantListToStringList(value.toList()), block); } else { iniEscapedString(variantToString(value), block); diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index 60ef7cdb26..53715a124f 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -106,8 +106,8 @@ static QCFType macValue(const QVariant &value) { CFPropertyListRef result = 0; - switch (value.type()) { - case QVariant::ByteArray: + switch (value.metaType().id()) { + case QMetaType::QByteArray: { QByteArray ba = value.toByteArray(); result = CFDataCreate(kCFAllocatorDefault, reinterpret_cast(ba.data()), @@ -115,12 +115,12 @@ static QCFType macValue(const QVariant &value) } break; // should be same as below (look for LIST) - case QVariant::List: - case QVariant::StringList: - case QVariant::Polygon: + case QMetaType::QVariantList: + case QMetaType::QStringList: + case QMetaType::QPolygon: result = macList(value.toList()); break; - case QVariant::Map: + case QMetaType::QVariantMap: { const QVariantMap &map = value.toMap(); const int mapSize = map.size(); @@ -145,7 +145,7 @@ static QCFType macValue(const QVariant &value) &kCFTypeDictionaryValueCallBacks); } break; - case QVariant::DateTime: + case QMetaType::QDateTime: { QDateTime dateTime = value.toDateTime(); // CFDate, unlike QDateTime, doesn't store timezone information @@ -155,30 +155,30 @@ static QCFType macValue(const QVariant &value) goto string_case; } break; - case QVariant::Bool: + case QMetaType::Bool: result = value.toBool() ? kCFBooleanTrue : kCFBooleanFalse; break; - case QVariant::Int: - case QVariant::UInt: + case QMetaType::Int: + case QMetaType::UInt: { int n = value.toInt(); result = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n); } break; - case QVariant::Double: + case QMetaType::Double: { double n = value.toDouble(); result = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &n); } break; - case QVariant::LongLong: - case QVariant::ULongLong: + case QMetaType::LongLong: + case QMetaType::ULongLong: { qint64 n = value.toLongLong(); result = CFNumberCreate(0, kCFNumberLongLongType, &n); } break; - case QVariant::String: + case QMetaType::QString: string_case: default: QString string = QSettingsPrivate::variantToString(value); @@ -226,7 +226,7 @@ static QVariant qtValue(CFPropertyListRef cfvalue) bool metNonString = false; for (CFIndex i = 0; i < size; ++i) { QVariant value = qtValue(CFArrayGetValueAtIndex(cfarray, i)); - if (value.type() != QVariant::String) + if (value.typeId() != QMetaType::QString) metNonString = true; list << value; } diff --git a/src/corelib/io/qsettings_win.cpp b/src/corelib/io/qsettings_win.cpp index 43593ea25a..979b37a0be 100644 --- a/src/corelib/io/qsettings_win.cpp +++ b/src/corelib/io/qsettings_win.cpp @@ -670,9 +670,9 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) QByteArray regValueBuff; // Determine the type - switch (value.type()) { - case QVariant::List: - case QVariant::StringList: { + switch (value.typeId()) { + case QMetaType::QVariantList: + case QMetaType::QStringList: { // If none of the elements contains '\0', we can use REG_MULTI_SZ, the // native registry string list type. Otherwise we use REG_BINARY. type = REG_MULTI_SZ; @@ -700,23 +700,23 @@ void QWinSettingsPrivate::set(const QString &uKey, const QVariant &value) break; } - case QVariant::Int: - case QVariant::UInt: { + case QMetaType::Int: + case QMetaType::UInt: { type = REG_DWORD; qint32 i = value.toInt(); regValueBuff = QByteArray(reinterpret_cast(&i), sizeof(qint32)); break; } - case QVariant::LongLong: - case QVariant::ULongLong: { + case QMetaType::LongLong: + case QMetaType::ULongLong: { type = REG_QWORD; qint64 i = value.toLongLong(); regValueBuff = QByteArray(reinterpret_cast(&i), sizeof(qint64)); break; } - case QVariant::ByteArray: + case QMetaType::QByteArray: Q_FALLTHROUGH(); default: { diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 3bb3e33465..1c9c684ef7 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -2941,21 +2941,16 @@ const char *QMetaProperty::typeName() const return rawTypeNameFromTypeInfo(mobj, data.type()); } -/*! +/*! \fn QVariant::Type QMetaProperty::type() const + \deprecated + Returns this property's type. The return value is one of the values of the QVariant::Type enumeration. - \sa userType(), typeName(), name(), metaType() + \sa metaType().id(), typeName(), name(), metaType() */ -QVariant::Type QMetaProperty::type() const -{ - uint type = userType(); - if (type >= QMetaType::User) - return QVariant::UserType; - return QVariant::Type(type); -} -/*! +/*! \fn int QMetaProperty::userType() const \since 4.2 Returns this property's user type. The return value is one @@ -2965,12 +2960,6 @@ QVariant::Type QMetaProperty::type() const \sa type(), QMetaType, typeName(), metaType() */ -int QMetaProperty::userType() const -{ - if (!mobj) - return QMetaType::UnknownType; - return QMetaType(mobj->d.metaTypes[data.index(mobj)]).id(); -} /*! \since 6.0 @@ -3197,7 +3186,7 @@ bool QMetaProperty::write(QObject *object, const QVariant &value) const QVariant v = value; QMetaType t(mobj->d.metaTypes[data.index(mobj)]); if (t != QMetaType::fromType() && t != v.metaType()) { - if (isEnumType() && !t.metaObject() && v.userType() == QMetaType::QString) { + if (isEnumType() && !t.metaObject() && v.metaType().id() == QMetaType::QString) { // Assigning a string to a property of type Q_ENUMS (instead of Q_ENUM) bool ok; if (isFlagType()) diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index 08c57d5f28..686e4aeeb8 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -280,8 +280,15 @@ public: const char *name() const; const char *typeName() const; - QVariant::Type type() const; - int userType() const; +#if QT_DEPRECATED_SINCE(6, 0) + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + QT_DEPRECATED_VERSION_6_0 + QVariant::Type type() const + { int t = userType(); return t >= QMetaType::User ? QVariant::UserType : QVariant::Type(t); } + QT_WARNING_POP +#endif + int userType() const { return metaType().id(); } QMetaType metaType() const; int propertyIndex() const; int relativePropertyIndex() const; diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 56e428b052..f7652e28d4 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -765,15 +765,15 @@ QVariant::QVariant(const QVariant &p) Constructs a new variant with the regular expression value \a re. */ -/*! +/*! \fn QVariant::QVariant(Type type) + \deprecated + Constructs an uninitialized variant of type \a type. This will create a variant in a special null state that if accessed will return a default constructed value of the \a type. \sa isNull() */ -QVariant::QVariant(Type type) -{ create(type, nullptr); } /*! Constructs variant of type \a type, and initializes with @@ -793,110 +793,110 @@ QVariant::QVariant(QMetaType type, const void *copy) : d(type) } QVariant::QVariant(int val) - : d(Int) + : d(QMetaType::Int) { d.set(val); } QVariant::QVariant(uint val) - : d(UInt) + : d(QMetaType::UInt) { d.set(val); } QVariant::QVariant(qlonglong val) - : d(LongLong) + : d(QMetaType::LongLong) { d.set(val); } QVariant::QVariant(qulonglong val) - : d(ULongLong) + : d(QMetaType::ULongLong) { d.set(val); } QVariant::QVariant(bool val) - : d(Bool) + : d(QMetaType::Bool) { d.set(val); } QVariant::QVariant(double val) - : d(Double) + : d(QMetaType::Double) { d.set(val); } QVariant::QVariant(float val) : d(QMetaType::Float) { d.set(val); } QVariant::QVariant(const QByteArray &val) - : d(ByteArray) + : d(QMetaType::QByteArray) { v_construct(&d, val); } QVariant::QVariant(const QBitArray &val) - : d(BitArray) + : d(QMetaType::QBitArray) { v_construct(&d, val); } QVariant::QVariant(const QString &val) - : d(String) + : d(QMetaType::QString) { v_construct(&d, val); } QVariant::QVariant(QChar val) - : d(Char) + : d(QMetaType::QChar) { v_construct(&d, val); } QVariant::QVariant(QLatin1String val) - : d(String) + : d(QMetaType::QString) { v_construct(&d, val); } QVariant::QVariant(const QStringList &val) - : d(StringList) + : d(QMetaType::QStringList) { v_construct(&d, val); } QVariant::QVariant(QDate val) - : d(Date) + : d(QMetaType::QDate) { v_construct(&d, val); } QVariant::QVariant(QTime val) - : d(Time) + : d(QMetaType::QTime) { v_construct(&d, val); } QVariant::QVariant(const QDateTime &val) - : d(DateTime) + : d(QMetaType::QDateTime) { v_construct(&d, val); } #if QT_CONFIG(easingcurve) QVariant::QVariant(const QEasingCurve &val) - : d(EasingCurve) + : d(QMetaType::QEasingCurve) { v_construct(&d, val); } #endif QVariant::QVariant(const QList &list) - : d(List) + : d(QMetaType::QVariantList) { v_construct(&d, list); } QVariant::QVariant(const QMap &map) - : d(Map) + : d(QMetaType::QVariantMap) { v_construct(&d, map); } QVariant::QVariant(const QHash &hash) - : d(Hash) + : d(QMetaType::QVariantHash) { v_construct(&d, hash); } #ifndef QT_NO_GEOM_VARIANT QVariant::QVariant(const QPoint &pt) - : d(Point) + : d(QMetaType::QPoint) { v_construct(&d, pt); } QVariant::QVariant(const QPointF &pt) - : d(PointF) + : d(QMetaType::QPointF) { v_construct(&d, pt); } QVariant::QVariant(const QRectF &r) - : d(RectF) + : d(QMetaType::QRectF) { v_construct(&d, r); } QVariant::QVariant(const QLineF &l) - : d(LineF) + : d(QMetaType::QLineF) { v_construct(&d, l); } QVariant::QVariant(const QLine &l) - : d(Line) + : d(QMetaType::QLine) { v_construct(&d, l); } QVariant::QVariant(const QRect &r) - : d(Rect) + : d(QMetaType::QRect) { v_construct(&d, r); } QVariant::QVariant(const QSize &s) - : d(Size) + : d(QMetaType::QSize) { v_construct(&d, s); } QVariant::QVariant(const QSizeF &s) - : d(SizeF) + : d(QMetaType::QSizeF) { v_construct(&d, s); } #endif #ifndef QT_BOOTSTRAPPED QVariant::QVariant(const QUrl &u) - : d(Url) + : d(QMetaType::QUrl) { v_construct(&d, u); } #endif QVariant::QVariant(const QLocale &l) - : d(Locale) + : d(QMetaType::QLocale) { v_construct(&d, l); } #if QT_CONFIG(regularexpression) QVariant::QVariant(const QRegularExpression &re) - : d(RegularExpression) + : d(QMetaType::QRegularExpression) { v_construct(&d, re); } #endif // QT_CONFIG(regularexpression) QVariant::QVariant(const QUuid &uuid) - : d(Uuid) + : d(QMetaType::QUuid) { v_construct(&d, uuid); } #ifndef QT_BOOTSTRAPPED QVariant::QVariant(const QJsonValue &jsonValue) @@ -914,14 +914,16 @@ QVariant::QVariant(const QJsonDocument &jsonDocument) #endif // QT_BOOTSTRAPPED #if QT_CONFIG(itemmodel) QVariant::QVariant(const QModelIndex &modelIndex) - : d(ModelIndex) + : d(QMetaType::QModelIndex) { v_construct(&d, modelIndex); } QVariant::QVariant(const QPersistentModelIndex &modelIndex) - : d(PersistentModelIndex) + : d(QMetaType::QPersistentModelIndex) { v_construct(&d, modelIndex); } #endif -/*! +/*! \fn QVariant::Type QVariant::type() const + \deprecated + Returns the storage type of the value stored in the variant. Although this function is declared as returning QVariant::Type, the return value should be interpreted as QMetaType::Type. In @@ -954,21 +956,15 @@ QVariant::QVariant(const QPersistentModelIndex &modelIndex) \sa userType(), metaType() */ -QVariant::Type QVariant::type() const -{ - int type = d.typeId(); - return type >= QMetaType::User ? UserType : static_cast(type); -} -/*! - Returns the storage type of the value stored in the variant. For - non-user types, this is the same as type(). + +/*! \fn int QVariant::userType() const + \fn int QVariant::typeId() const + + Returns the storage type of the value stored in the variant. This is + the same as metaType().id(). \sa type(), metaType() */ -int QVariant::userType() const -{ - return d.typeId(); -} /*! \since 6.0 @@ -1187,7 +1183,7 @@ void QVariant::load(QDataStream &s) qint8 is_null = false; if (s.version() >= QDataStream::Qt_4_2) s >> is_null; - if (typeId == QVariant::UserType) { + if (typeId == QMetaType::User) { QByteArray name; s >> name; typeId = QMetaType::fromName(name).id(); @@ -1330,28 +1326,17 @@ QDataStream& operator<<(QDataStream &s, const QVariant &p) return s; } -/*! +/*! \fn QDataStream& operator>>(QDataStream &s, QVariant::Type &p) + \deprecated + Reads a variant type \a p in enum representation from the stream \a s. */ -QDataStream& operator>>(QDataStream &s, QVariant::Type &p) -{ - quint32 u; - s >> u; - p = (QVariant::Type)u; - return s; -} +/*! \fn QDataStream& operator<<(QDataStream &s, const QVariant::Type p) + \deprecated -/*! Writes a variant type \a p to the stream \a s. */ -QDataStream& operator<<(QDataStream &s, const QVariant::Type p) -{ - s << static_cast(p); - - return s; -} - #endif //QT_NO_DATASTREAM /*! @@ -2461,6 +2446,10 @@ QDebug QVariant::qdebugHelper(QDebug dbg) const return dbg; } +#if QT_DEPRECATED_SINCE(6, 0) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED + QDebug operator<<(QDebug dbg, const QVariant::Type p) { QDebugStateSaver saver(dbg); @@ -2470,8 +2459,11 @@ QDebug operator<<(QDebug dbg, const QVariant::Type p) : "Invalid"); return dbg; } + +QT_WARNING_POP #endif +#endif /*! \fn template void QVariant::setValue(T &&value) diff --git a/src/corelib/kernel/qvariant.h b/src/corelib/kernel/qvariant.h index 012b5c52b6..3fe7de451e 100644 --- a/src/corelib/kernel/qvariant.h +++ b/src/corelib/kernel/qvariant.h @@ -99,7 +99,9 @@ inline T qvariant_cast(const QVariant &); class Q_CORE_EXPORT QVariant { public: - enum Type { +#if QT_DEPRECATED_SINCE(6, 0) + enum QT_DEPRECATED_VERSION_X_6_0("Use QMetaType::Type instead.") Type + { Invalid = QMetaType::UnknownType, Bool = QMetaType::Bool, Int = QMetaType::Int, @@ -172,10 +174,9 @@ class Q_CORE_EXPORT QVariant UserType = QMetaType::User, LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type }; - +#endif QVariant() noexcept : d() {} ~QVariant(); - explicit QVariant(Type type); explicit QVariant(QMetaType type, const void *copy = nullptr); QVariant(const QVariant &other); @@ -241,8 +242,8 @@ class Q_CORE_EXPORT QVariant inline void swap(QVariant &other) noexcept { qSwap(d, other.d); } - Type type() const; - int userType() const; + int typeId() const { return d.typeId(); } + int userType() const { return d.typeId(); } const char *typeName() const; QMetaType metaType() const; @@ -325,6 +326,18 @@ class Q_CORE_EXPORT QVariant void save(QDataStream &ds) const; #endif #if QT_DEPRECATED_SINCE(6, 0) + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + QT_DEPRECATED_VERSION_X_6_0("Use the constructor taking a QMetaType instead.") + explicit QVariant(Type type) + : QVariant(QMetaType(int(type))) + {} + QT_DEPRECATED_VERSION_X_6_0("Use metaType().") + Type type() const + { + int type = d.typeId(); + return type >= QMetaType::User ? UserType : static_cast(type); + } QT_DEPRECATED_VERSION_6_0 static const char *typeToName(int typeId) { return QMetaType(typeId).name(); } @@ -334,6 +347,7 @@ class Q_CORE_EXPORT QVariant int metaType = QMetaType::fromName(name).id(); return metaType <= int(UserType) ? QVariant::Type(metaType) : UserType; } + QT_WARNING_POP #endif void *data(); @@ -567,8 +581,27 @@ inline bool QVariant::isValid() const #ifndef QT_NO_DATASTREAM Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant& p); Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant& p); -Q_CORE_EXPORT QDataStream& operator>> (QDataStream& s, QVariant::Type& p); -Q_CORE_EXPORT QDataStream& operator<< (QDataStream& s, const QVariant::Type p); + +#if QT_DEPRECATED_SINCE(6, 0) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +QT_DEPRECATED_VERSION_6_0 +inline QDataStream& operator>> (QDataStream& s, QVariant::Type &p) +{ + quint32 u; + s >> u; + p = static_cast(u); + return s; +} +QT_DEPRECATED_VERSION_6_0 +inline QDataStream& operator<< (QDataStream& s, const QVariant::Type p) +{ + s << static_cast(p); + return s; +} +QT_WARNING_POP +#endif + #endif inline bool QVariant::isDetached() const @@ -597,7 +630,7 @@ template inline T qvariant_cast(const QVariant &v) template<> inline QVariant qvariant_cast(const QVariant &v) { - if (v.userType() == QMetaType::QVariant) + if (v.metaType().id() == QMetaType::QVariant) return *reinterpret_cast(v.constData()); return v; } @@ -605,7 +638,13 @@ template<> inline QVariant qvariant_cast(const QVariant &v) #endif #ifndef QT_NO_DEBUG_STREAM +#if QT_DEPRECATED_SINCE(6, 0) +QT_WARNING_PUSH +QT_WARNING_DISABLE_DEPRECATED +QT_DEPRECATED_VERSION_6_0 Q_CORE_EXPORT QDebug operator<<(QDebug, const QVariant::Type); +QT_WARNING_POP +#endif #endif namespace QtPrivate { diff --git a/src/corelib/serialization/qjsoncbor.cpp b/src/corelib/serialization/qjsoncbor.cpp index 5d6f521d1b..6256028c3a 100644 --- a/src/corelib/serialization/qjsoncbor.cpp +++ b/src/corelib/serialization/qjsoncbor.cpp @@ -662,7 +662,7 @@ static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) { // Handle strings and byte arrays directly, to avoid creating a temporary // dummy container to hold their data. - int type = variant.userType(); + int type = variant.metaType().id(); if (type == QMetaType::QString) { d->append(variant.toString()); } else if (type == QMetaType::QByteArray) { @@ -728,7 +728,7 @@ static void appendVariant(QCborContainerPrivate *d, const QVariant &variant) */ QCborValue QCborValue::fromVariant(const QVariant &variant) { - switch (variant.userType()) { + switch (variant.metaType().id()) { case QMetaType::UnknownType: return {}; case QMetaType::Nullptr: diff --git a/src/corelib/serialization/qjsondocument.cpp b/src/corelib/serialization/qjsondocument.cpp index f06867341c..6ef657d50d 100644 --- a/src/corelib/serialization/qjsondocument.cpp +++ b/src/corelib/serialization/qjsondocument.cpp @@ -228,7 +228,7 @@ QJsonDocument QJsonDocument::fromVariant(const QVariant &variant) { QJsonDocument doc; - switch (variant.userType()) { + switch (variant.metaType().id()) { case QMetaType::QVariantMap: doc.setObject(QJsonObject::fromVariantMap(variant.toMap())); break; diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp index 34106da231..831a124f7b 100644 --- a/src/corelib/serialization/qjsonvalue.cpp +++ b/src/corelib/serialization/qjsonvalue.cpp @@ -463,7 +463,7 @@ void QJsonValue::swap(QJsonValue &other) noexcept */ QJsonValue QJsonValue::fromVariant(const QVariant &variant) { - switch (variant.userType()) { + switch (variant.metaType().id()) { case QMetaType::Nullptr: return QJsonValue(Null); case QMetaType::Bool: diff --git a/src/corelib/text/qlocale.qdoc b/src/corelib/text/qlocale.qdoc index c9c62d0878..0f31345152 100644 --- a/src/corelib/text/qlocale.qdoc +++ b/src/corelib/text/qlocale.qdoc @@ -1159,7 +1159,7 @@ \variable QSystemLocale::CurrencyToStringArgument::value An input value that should be converted to its string representation. - Contains one of QVariant::LongLong, QVariant::ULongLong or QVariant::Double + Contains one of QMetaType::LongLong, QMetaType::ULongLong or QMetaType::Double types. */ /*! diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index 586b68b4d8..e3593c3aff 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -366,19 +366,19 @@ static QString macFormatCurrency(const QSystemLocale::CurrencyToStringArgument & { QCFType value; switch (arg.value.type()) { - case QVariant::Int: - case QVariant::UInt: { + case QMetaType::Int: + case QMetaType::UInt: { int v = arg.value.toInt(); value = CFNumberCreate(NULL, kCFNumberIntType, &v); break; } - case QVariant::Double: { + case QMetaType::Double: { double v = arg.value.toDouble(); value = CFNumberCreate(NULL, kCFNumberDoubleType, &v); break; } - case QVariant::LongLong: - case QVariant::ULongLong: { + case QMetaType::LongLong: + case QMetaType::ULongLong: { qint64 v = arg.value.toLongLong(); value = CFNumberCreate(NULL, kCFNumberLongLongType, &v); break; diff --git a/src/corelib/text/qlocale_win.cpp b/src/corelib/text/qlocale_win.cpp index d74ae40313..a88f3e5227 100644 --- a/src/corelib/text/qlocale_win.cpp +++ b/src/corelib/text/qlocale_win.cpp @@ -519,23 +519,23 @@ QVariant QSystemLocalePrivate::toCurrencyString(const QSystemLocale::CurrencyToS { QString value; switch (arg.value.type()) { - case QVariant::Int: + case QMetaType::Int: value = QLocaleData::c()->longLongToString( arg.value.toInt(), -1, 10, -1, QLocale::OmitGroupSeparator); break; - case QVariant::UInt: + case QMetaType::UInt: value = QLocaleData::c()->unsLongLongToString( arg.value.toUInt(), -1, 10, -1, QLocale::OmitGroupSeparator); break; - case QVariant::Double: + case QMetaType::Double: value = QLocaleData::c()->doubleToString( arg.value.toDouble(), -1, QLocaleData::DFDecimal, -1, QLocale::OmitGroupSeparator); break; - case QVariant::LongLong: + case QMetaType::LongLong: value = QLocaleData::c()->longLongToString( arg.value.toLongLong(), -1, 10, -1, QLocale::OmitGroupSeparator); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: value = QLocaleData::c()->unsLongLongToString( arg.value.toULongLong(), -1, 10, -1, QLocale::OmitGroupSeparator); break; diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp index 7eb1e8b34e..cf698c79bf 100644 --- a/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp +++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp @@ -242,7 +242,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myArray) // Append a dictionary that associates ints to MyValue types QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &myDict) { - argument.beginMap(QVariant::Int, qMetaTypeId()); + argument.beginMap(QMetaType::fromType(), QMetaType::fromType()); MyDictionary::const_iterator i; for (i = myDict.cbegin(); i != myDict.cend(); ++i) { argument.beginMapEntry(); diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp index 26ecd543f1..e17b40e58c 100644 --- a/src/dbus/qdbusargument.cpp +++ b/src/dbus/qdbusargument.cpp @@ -1107,7 +1107,7 @@ bool QDBusArgument::atEnd() const argument (for example, by calling asVariant() in it). For example, if the current argument is an INT32, this function - will return a QVariant with an argument of type QVariant::Int. For + will return a QVariant with an argument of type QMetaType::Int. For an array of INT32, it will return a QVariant containing a QDBusArgument. diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp index 4977d7b265..03da1a6780 100644 --- a/src/dbus/qdbusmarshaller.cpp +++ b/src/dbus/qdbusmarshaller.cpp @@ -192,7 +192,7 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg) QMetaType id = value.metaType(); if (!id.isValid()) { qWarning("QDBusMarshaller: cannot add a null QDBusVariant"); - error(QLatin1String("Variant containing QVariant::Invalid passed in arguments")); + error(QLatin1String("Invalid QVariant passed in arguments")); return false; } @@ -386,7 +386,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg) QMetaType id = arg.metaType(); if (!id.isValid()) { qWarning("QDBusMarshaller: cannot add an invalid QVariant"); - error(QLatin1String("Variant containing QVariant::Invalid passed in arguments")); + error(QLatin1String("Invalid QVariant passed in arguments")); return false; } diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index ff142794f6..0c5872a2f2 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -2052,10 +2052,10 @@ void QTextDocument::print(QPagedPaintDevice *printer) const \value UnknownResource No resource is loaded, or the resource type is not known. \value HtmlResource The resource contains HTML. \value ImageResource The resource contains image data. - Currently supported data types are QVariant::Pixmap and - QVariant::Image. If the corresponding variant is of type - QVariant::ByteArray then Qt attempts to load the image using - QImage::loadFromData. QVariant::Icon is currently not supported. + Currently supported data types are QMetaType::QPixmap and + QMetaType::QImage. If the corresponding variant is of type + QMetaType::QByteArray then Qt attempts to load the image using + QImage::loadFromData. QMetaType::QIcon is currently not supported. The icon needs to be converted to one of the supported types first, for example using QIcon::pixmap. \value StyleSheetResource The resource contains CSS. diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 850b4ad43d..444850039b 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -1036,7 +1036,7 @@ int QTextFormat::intProperty(int propertyId) const /*! Returns the value of the property specified by \a propertyId. If the - property isn't of QVariant::Double or QMetaType::Float type, 0 is + property isn't of QMetaType::Double or QMetaType::Float type, 0 is returned instead. \sa setProperty(), boolProperty(), intProperty(), stringProperty(), colorProperty(), @@ -1054,7 +1054,7 @@ qreal QTextFormat::doubleProperty(int propertyId) const /*! Returns the value of the property given by \a propertyId; if the - property isn't of QVariant::String type, an empty string is + property isn't of QMetaType::QString type, an empty string is returned instead. \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), colorProperty(), @@ -1072,7 +1072,7 @@ QString QTextFormat::stringProperty(int propertyId) const /*! Returns the value of the property given by \a propertyId; if the - property isn't of QVariant::Color type, an invalid color is + property isn't of QMetaType::QColor type, an invalid color is returned instead. \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), @@ -1090,7 +1090,7 @@ QColor QTextFormat::colorProperty(int propertyId) const /*! Returns the value of the property given by \a propertyId; if the - property isn't of QVariant::Pen type, Qt::NoPen is + property isn't of QMetaType::QPen type, Qt::NoPen is returned instead. \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), @@ -1108,7 +1108,7 @@ QPen QTextFormat::penProperty(int propertyId) const /*! Returns the value of the property given by \a propertyId; if the - property isn't of QVariant::Brush type, Qt::NoBrush is + property isn't of QMetaType::QBrush type, Qt::NoBrush is returned instead. \sa setProperty(), boolProperty(), intProperty(), doubleProperty(), stringProperty(), diff --git a/src/plugins/platforms/android/qandroidsystemlocale.cpp b/src/plugins/platforms/android/qandroidsystemlocale.cpp index 96f461f773..9d96feb707 100644 --- a/src/plugins/platforms/android/qandroidsystemlocale.cpp +++ b/src/plugins/platforms/android/qandroidsystemlocale.cpp @@ -140,15 +140,15 @@ QVariant QAndroidSystemLocale::query(QueryType type, QVariant in) const return m_locale .currencySymbol(QLocale::CurrencySymbolFormat(in.toUInt())); case CurrencyToString: { switch (in.type()) { - case QVariant::Int: + case QMetaType::Int: return m_locale .toCurrencyString(in.toInt()); - case QVariant::UInt: + case QMetaType::UInt: return m_locale .toCurrencyString(in.toUInt()); - case QVariant::Double: + case QMetaType::Double: return m_locale .toCurrencyString(in.toDouble()); - case QVariant::LongLong: + case QMetaType::LongLong: return m_locale .toCurrencyString(in.toLongLong()); - case QVariant::ULongLong: + case QMetaType::ULongLong: return m_locale .toCurrencyString(in.toULongLong()); default: break; diff --git a/src/plugins/platforms/windows/qwindowsinternalmimedata.cpp b/src/plugins/platforms/windows/qwindowsinternalmimedata.cpp index 5f63adba52..f5e7465aff 100644 --- a/src/plugins/platforms/windows/qwindowsinternalmimedata.cpp +++ b/src/plugins/platforms/windows/qwindowsinternalmimedata.cpp @@ -104,7 +104,7 @@ QVariant QWindowsInternalMimeData::retrieveData_sys(const QString &mimeType, QMe if (QWindowsContext::verbose) { qCDebug(lcQpaMime) <<__FUNCTION__ << ' ' << mimeType << ' ' << type.name() << " returns " << result.metaType().name() - << (result.userType() != QVariant::ByteArray ? result.toString() : QStringLiteral("")); + << (result.metaType().id() != QMetaType::QByteArray ? result.toString() : QStringLiteral("")); } return result; } diff --git a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp index 9808d5481c..43a53d7cfc 100644 --- a/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp +++ b/src/plugins/platforms/windows/uiautomation/qwindowsuiamainprovider.cpp @@ -164,7 +164,7 @@ void QWindowsUiaMainProvider::notifyValueChange(QAccessibleValueChangeEvent *eve } } } - if (event->value().type() == QVariant::String) { + if (event->value().typeId() == QMetaType::QString) { if (QWindowsUiaMainProvider *provider = providerForAccessible(accessible)) { // Tries to notify the change using UiaRaiseNotificationEvent(), which is only available on diff --git a/src/plugins/sqldrivers/db2/qsql_db2.cpp b/src/plugins/sqldrivers/db2/qsql_db2.cpp index e3cfa0ae15..0e1ff6f2fc 100644 --- a/src/plugins/sqldrivers/db2/qsql_db2.cpp +++ b/src/plugins/sqldrivers/db2/qsql_db2.cpp @@ -248,25 +248,25 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type, errorCodes.join(QLatin1Char(';'))); } -static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype) +static QMetaType qDecodeDB2Type(SQLSMALLINT sqltype) { - QVariant::Type type = QVariant::Invalid; + int type = QMetaType::UnknownType; switch (sqltype) { case SQL_REAL: case SQL_FLOAT: case SQL_DOUBLE: case SQL_DECIMAL: case SQL_NUMERIC: - type = QVariant::Double; + type = QMetaType::Double; break; case SQL_SMALLINT: case SQL_INTEGER: case SQL_BIT: case SQL_TINYINT: - type = QVariant::Int; + type = QMetaType::Int; break; case SQL_BIGINT: - type = QVariant::LongLong; + type = QMetaType::LongLong; break; case SQL_BLOB: case SQL_BINARY: @@ -274,19 +274,19 @@ static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype) case SQL_LONGVARBINARY: case SQL_CLOB: case SQL_DBCLOB: - type = QVariant::ByteArray; + type = QMetaType::QByteArray; break; case SQL_DATE: case SQL_TYPE_DATE: - type = QVariant::Date; + type = QMetaType::QDate; break; case SQL_TIME: case SQL_TYPE_TIME: - type = QVariant::Time; + type = QMetaType::QTime; break; case SQL_TIMESTAMP: case SQL_TYPE_TIMESTAMP: - type = QVariant::DateTime; + type = QMetaType::QDateTime; break; case SQL_WCHAR: case SQL_WVARCHAR: @@ -294,13 +294,13 @@ static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype) case SQL_CHAR: case SQL_VARCHAR: case SQL_LONGVARCHAR: - type = QVariant::String; + type = QMetaType::QString; break; default: - type = QVariant::ByteArray; + type = QMetaType::QByteArray; break; } - return type; + return QMetaType(type); } static QSqlField qMakeFieldInfo(const QDB2ResultPrivate* d, int i) @@ -703,7 +703,7 @@ bool QDB2Result::exec() values[i].detach(); switch (values.at(i).metaType().id()) { - case QVariant::Date: { + case QMetaType::QDate: { QByteArray ba; ba.resize(sizeof(DATE_STRUCT)); DATE_STRUCT *dt = (DATE_STRUCT *)ba.constData(); @@ -723,7 +723,7 @@ bool QDB2Result::exec() *ind == SQL_NULL_DATA ? ind : NULL); tmpStorage.append(ba); break; } - case QVariant::Time: { + case QMetaType::QTime: { QByteArray ba; ba.resize(sizeof(TIME_STRUCT)); TIME_STRUCT *dt = (TIME_STRUCT *)ba.constData(); @@ -743,7 +743,7 @@ bool QDB2Result::exec() *ind == SQL_NULL_DATA ? ind : NULL); tmpStorage.append(ba); break; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { QByteArray ba; ba.resize(sizeof(TIMESTAMP_STRUCT)); TIMESTAMP_STRUCT * dt = (TIMESTAMP_STRUCT *)ba.constData(); @@ -767,7 +767,7 @@ bool QDB2Result::exec() *ind == SQL_NULL_DATA ? ind : NULL); tmpStorage.append(ba); break; } - case QVariant::Int: + case QMetaType::Int: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & 3], @@ -779,7 +779,7 @@ bool QDB2Result::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::Double: + case QMetaType::Double: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & 3], @@ -791,7 +791,7 @@ bool QDB2Result::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::ByteArray: { + case QMetaType::QByteArray: { int len = values.at(i).toByteArray().size(); if (*ind != SQL_NULL_DATA) *ind = len; @@ -806,7 +806,7 @@ bool QDB2Result::exec() len, ind); break; } - case QVariant::String: + case QMetaType::QString: { QString str(values.at(i).toString()); if (*ind != SQL_NULL_DATA) @@ -895,24 +895,24 @@ bool QDB2Result::exec() for (i = 0; i < values.count(); ++i) { switch (values[i].metaType().id()) { - case QVariant::Date: { + case QMetaType::QDate: { DATE_STRUCT ds = *((DATE_STRUCT *)tmpStorage.takeFirst().constData()); values[i] = QVariant(QDate(ds.year, ds.month, ds.day)); break; } - case QVariant::Time: { + case QMetaType::QTime: { TIME_STRUCT dt = *((TIME_STRUCT *)tmpStorage.takeFirst().constData()); values[i] = QVariant(QTime(dt.hour, dt.minute, dt.second)); break; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { TIMESTAMP_STRUCT dt = *((TIMESTAMP_STRUCT *)tmpStorage.takeFirst().constData()); values[i] = QVariant(QDateTime(QDate(dt.year, dt.month, dt.day), QTime(dt.hour, dt.minute, dt.second, dt.fraction / 1000000))); break; } - case QVariant::Int: - case QVariant::Double: - case QVariant::ByteArray: + case QMetaType::Int: + case QMetaType::Double: + case QMetaType::ByteArray: break; - case QVariant::String: + case QMetaType::QString: if (bindValueType(i) & QSql::Out) values[i] = QString((const QChar *)tmpStorage.takeFirst().constData()); break; @@ -1054,13 +1054,13 @@ QVariant QDB2Result::data(int field) QVariant *v = nullptr; switch (info.metaType().id()) { - case QVariant::LongLong: + case QMetaType::LongLong: v = new QVariant((qint64) qGetBigIntData(d->hStmt, field, isNull)); break; - case QVariant::Int: + case QMetaType::Int: v = new QVariant(qGetIntData(d->hStmt, field, isNull)); break; - case QVariant::Date: { + case QMetaType::QDate: { DATE_STRUCT dbuf; r = SQLGetData(d->hStmt, field + 1, @@ -1075,7 +1075,7 @@ QVariant QDB2Result::data(int field) isNull = true; } break; } - case QVariant::Time: { + case QMetaType::QTime: { TIME_STRUCT tbuf; r = SQLGetData(d->hStmt, field + 1, @@ -1090,7 +1090,7 @@ QVariant QDB2Result::data(int field) isNull = true; } break; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { TIMESTAMP_STRUCT dtbuf; r = SQLGetData(d->hStmt, field + 1, @@ -1106,10 +1106,10 @@ QVariant QDB2Result::data(int field) isNull = true; } break; } - case QVariant::ByteArray: + case QMetaType::QByteArray: v = new QVariant(qGetBinaryData(d->hStmt, field, lengthIndicator, isNull)); break; - case QVariant::Double: + case QMetaType::Double: { switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: @@ -1129,7 +1129,7 @@ QVariant QDB2Result::data(int field) } break; } - case QVariant::String: + case QMetaType::QString: default: v = new QVariant(qGetStringData(d->hStmt, field, info.length(), isNull)); break; @@ -1688,7 +1688,7 @@ QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const return QLatin1String("NULL"); switch (field.metaType().id()) { - case QVariant::DateTime: { + case QMetaType::QDateTime: { // Use an escape sequence for the datetime fields if (field.value().toDateTime().isValid()) { QDate dt = field.value().toDateTime().date(); @@ -1708,7 +1708,7 @@ QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const return QLatin1String("NULL"); } } - case QVariant::ByteArray: { + case QMetaType::QByteArray: { QByteArray ba = field.value().toByteArray(); QString res; res += QLatin1String("BLOB(X'"); diff --git a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp index 7be2df6dd9..b61c41735b 100644 --- a/src/plugins/sqldrivers/ibase/qsql_ibase.cpp +++ b/src/plugins/sqldrivers/ibase/qsql_ibase.cpp @@ -158,7 +158,7 @@ static void delDA(XSQLDA *&sqlda) sqlda = 0; } -static QVariant::Type qIBaseTypeName(int iType, bool hasScale) +static int qIBaseTypeName(int iType, bool hasScale) { switch (iType) { case blr_varying: @@ -166,60 +166,60 @@ static QVariant::Type qIBaseTypeName(int iType, bool hasScale) case blr_text: case blr_cstring: case blr_cstring2: - return QVariant::String; + return QMetaType::QString; case blr_sql_time: - return QVariant::Time; + return QMetaType::QTime; case blr_sql_date: - return QVariant::Date; + return QMetaType::QDate; case blr_timestamp: - return QVariant::DateTime; + return QMetaType::QDateTime; case blr_blob: - return QVariant::ByteArray; + return QMetaType::QByteArray; case blr_quad: case blr_short: case blr_long: - return (hasScale ? QVariant::Double : QVariant::Int); + return (hasScale ? QMetaType::Double : QMetaType::Int); case blr_int64: - return (hasScale ? QVariant::Double : QVariant::LongLong); + return (hasScale ? QMetaType::Double : QMetaType::LongLong); case blr_float: case blr_d_float: case blr_double: - return QVariant::Double; + return QMetaType::Double; case blr_boolean_dtype: - return QVariant::Bool; + return QMetaType::Bool; } qWarning("qIBaseTypeName: unknown datatype: %d", iType); - return QVariant::Invalid; + return QMetaType::UnknownType; } -static QVariant::Type qIBaseTypeName2(int iType, bool hasScale) +static int qIBaseTypeName2(int iType, bool hasScale) { switch(iType & ~1) { case SQL_VARYING: case SQL_TEXT: - return QVariant::String; + return QMetaType::QString; case SQL_LONG: case SQL_SHORT: - return (hasScale ? QVariant::Double : QVariant::Int); + return (hasScale ? QMetaType::Double : QMetaType::Int); case SQL_INT64: - return (hasScale ? QVariant::Double : QVariant::LongLong); + return (hasScale ? QMetaType::Double : QMetaType::LongLong); case SQL_FLOAT: case SQL_DOUBLE: - return QVariant::Double; + return QMetaType::Double; case SQL_TIMESTAMP: - return QVariant::DateTime; + return QMetaType::QDateTime; case SQL_TYPE_TIME: - return QVariant::Time; + return QMetaType::QTime; case SQL_TYPE_DATE: - return QVariant::Date; + return QMetaType::QDate; case SQL_ARRAY: - return QVariant::List; + return QMetaType::QVariantList; case SQL_BLOB: - return QVariant::ByteArray; + return QMetaType::QByteArray; case SQL_BOOLEAN: - return QVariant::Bool; + return QMetaType::Bool; default: - return QVariant::Invalid; + return QMetaType::UnknownType; } } @@ -674,7 +674,7 @@ static char* qFillBufferWithString(char *buffer, const QString& string, } static char* createArrayBuffer(char *buffer, const QList &list, - QVariant::Type type, short curDim, ISC_ARRAY_DESC *arrayDesc, + int type, short curDim, ISC_ARRAY_DESC *arrayDesc, QString& error) { int i; @@ -694,7 +694,7 @@ static char* createArrayBuffer(char *buffer, const QList &list, if (curDim != dim) { for(i = 0; i < list.size(); ++i) { - if (list.at(i).userType() != QVariant::List) { // dimensions mismatch + if (list.at(i).typeId() != QMetaType::QVariantList) { // dimensions mismatch error = QLatin1String("Array dimensons mismatch. Fieldname: %1"); return 0; } @@ -706,52 +706,52 @@ static char* createArrayBuffer(char *buffer, const QList &list, } } else { switch(type) { - case QVariant::Int: - case QVariant::UInt: + case QMetaType::Int: + case QMetaType::UInt: if (arrayDesc->array_desc_dtype == blr_short) buffer = fillList(buffer, list); else buffer = fillList(buffer, list); break; - case QVariant::Double: + case QMetaType::Double: if (arrayDesc->array_desc_dtype == blr_float) buffer = fillList(buffer, list, static_cast(0)); else buffer = fillList(buffer, list); break; - case QVariant::LongLong: + case QMetaType::LongLong: buffer = fillList(buffer, list); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: buffer = fillList(buffer, list); break; - case QVariant::String: + case QMetaType::QString: for (i = 0; i < list.size(); ++i) buffer = qFillBufferWithString(buffer, list.at(i).toString(), arrayDesc->array_desc_length, arrayDesc->array_desc_dtype == blr_varying, true); break; - case QVariant::Date: + case QMetaType::QDate: for (i = 0; i < list.size(); ++i) { *((ISC_DATE*)buffer) = toDate(list.at(i).toDate()); buffer += sizeof(ISC_DATE); } break; - case QVariant::Time: + case QMetaType::QTime: for (i = 0; i < list.size(); ++i) { *((ISC_TIME*)buffer) = toTime(list.at(i).toTime()); buffer += sizeof(ISC_TIME); } break; - case QVariant::DateTime: + case QMetaType::QDateTime: for (i = 0; i < list.size(); ++i) { *((ISC_TIMESTAMP*)buffer) = toTimeStamp(list.at(i).toDateTime()); buffer += sizeof(ISC_TIMESTAMP); } break; - case QVariant::Bool: + case QMetaType::Bool: buffer = fillList(buffer, list); break; default: @@ -1132,16 +1132,16 @@ bool QIBaseResult::gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx) // null value QVariant v; v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0)); - if (v.userType() == QVariant::Double) { + if (v.userType() == QMetaType::Double) { switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: - v.convert(QVariant::Int); + v.convert(QMetaType::Int); break; case QSql::LowPrecisionInt64: - v.convert(QVariant::LongLong); + v.convert(QMetaType::LongLong); break; case QSql::HighPrecision: - v.convert(QVariant::String); + v.convert(QMetaType::QString); break; case QSql::LowPrecisionDouble: // no conversion @@ -1214,19 +1214,19 @@ bool QIBaseResult::gotoNext(QSqlCachedResult::ValueCache& row, int rowIdx) QVariant v = row[idx]; switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: - if(v.convert(QVariant::Int)) + if (v.convert(QMetaType::Int)) row[idx]=v; break; case QSql::LowPrecisionInt64: - if(v.convert(QVariant::LongLong)) + if (v.convert(QMetaType::LongLong)) row[idx]=v; break; case QSql::LowPrecisionDouble: - if(v.convert(QVariant::Double)) + if (v.convert(QMetaType::Double)) row[idx]=v; break; case QSql::HighPrecision: - if(v.convert(QVariant::String)) + if (v.convert(QMetaType::QString)) row[idx]=v; break; } @@ -1695,7 +1695,7 @@ QSqlIndex QIBaseDriver::primaryIndex(const QString &table) const QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) const { switch (field.type()) { - case QVariant::DateTime: { + case QMetaType::QDateTime: { QDateTime datetime = field.value().toDateTime(); if (datetime.isValid()) return QLatin1Char('\'') + QString::number(datetime.date().year()) + QLatin1Char('-') + @@ -1709,7 +1709,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons else return QLatin1String("NULL"); } - case QVariant::Time: { + case QMetaType::QTime: { QTime time = field.value().toTime(); if (time.isValid()) return QLatin1Char('\'') + QString::number(time.hour()) + QLatin1Char(':') + @@ -1720,7 +1720,7 @@ QString QIBaseDriver::formatValue(const QSqlField &field, bool trimStrings) cons else return QLatin1String("NULL"); } - case QVariant::Date: { + case QMetaType::QDate: { QDate date = field.value().toDate(); if (date.isValid()) return QLatin1Char('\'') + QString::number(date.year()) + QLatin1Char('-') + diff --git a/src/plugins/sqldrivers/oci/qsql_oci.cpp b/src/plugins/sqldrivers/oci/qsql_oci.cpp index 5bf9400180..28b419e6a1 100644 --- a/src/plugins/sqldrivers/oci/qsql_oci.cpp +++ b/src/plugins/sqldrivers/oci/qsql_oci.cpp @@ -364,8 +364,8 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in int r = OCI_SUCCESS; void *data = const_cast(val.constData()); - switch (val.type()) { - case QVariant::ByteArray: + switch (val.typeId()) { + case QMetaType::QByteArray: r = OCIBindByPos(sql, hbnd, err, pos + 1, isOutValue(pos) @@ -374,9 +374,9 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in reinterpret_cast(data)->size(), SQLT_BIN, indPtr, 0, 0, 0, 0, OCI_DEFAULT); break; - case QVariant::Time: - case QVariant::Date: - case QVariant::DateTime: { + case QMetaType::QTime: + case QMetaType::QDate: + case QMetaType::QDateTime: { QOCIDateTime *ptr = new QOCIDateTime(env, err, val.toDateTime()); r = OCIBindByPos(sql, hbnd, err, pos + 1, @@ -386,7 +386,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in tmpStorage.dateTimes.append(ptr); break; } - case QVariant::Int: + case QMetaType::Int: r = OCIBindByPos(sql, hbnd, err, pos + 1, // if it's an out value, the data is already detached @@ -395,7 +395,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in sizeof(int), SQLT_INT, indPtr, 0, 0, 0, 0, OCI_DEFAULT); break; - case QVariant::UInt: + case QMetaType::UInt: r = OCIBindByPos(sql, hbnd, err, pos + 1, // if it's an out value, the data is already detached @@ -404,7 +404,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in sizeof(uint), SQLT_UIN, indPtr, 0, 0, 0, 0, OCI_DEFAULT); break; - case QVariant::LongLong: + case QMetaType::LongLong: { QByteArray ba = qMakeOCINumber(val.toLongLong(), err); r = OCIBindByPos(sql, hbnd, err, @@ -415,7 +415,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in tmpStorage.rawData.append(ba); break; } - case QVariant::ULongLong: + case QMetaType::ULongLong: { QByteArray ba = qMakeOCINumber(val.toULongLong(), err); r = OCIBindByPos(sql, hbnd, err, @@ -426,7 +426,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in tmpStorage.rawData.append(ba); break; } - case QVariant::Double: + case QMetaType::Double: r = OCIBindByPos(sql, hbnd, err, pos + 1, // if it's an out value, the data is already detached @@ -435,22 +435,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in sizeof(double), SQLT_FLT, indPtr, 0, 0, 0, 0, OCI_DEFAULT); break; - case QVariant::UserType: - if (val.canConvert() && !isOutValue(pos)) { - // use a const pointer to prevent a detach - const QOCIRowIdPointer rptr = qvariant_cast(val); - r = OCIBindByPos(sql, hbnd, err, - pos + 1, - // it's an IN value, so const_cast is ok - const_cast(&rptr->id), - -1, - SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT); - } else { - qWarning("Unknown bind variable"); - r = OCI_ERROR; - } - break; - case QVariant::String: { + case QMetaType::QString: { const QString s = val.toString(); if (isBinaryValue(pos)) { r = OCIBindByPos(sql, hbnd, err, @@ -473,27 +458,43 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in } } // fall through for OUT values default: { - const QString s = val.toString(); - // create a deep-copy - QByteArray ba(reinterpret_cast(s.utf16()), (s.length() + 1) * sizeof(QChar)); - if (isOutValue(pos)) { - ba.reserve((s.capacity() + 1) * sizeof(QChar)); - *tmpSize = ba.size(); - r = OCIBindByPos(sql, hbnd, err, - pos + 1, - ba.data(), - ba.capacity(), - SQLT_STR, indPtr, tmpSize, 0, 0, 0, OCI_DEFAULT); + if (val.typeId() >= QMetaType::User) { + if (val.canConvert() && !isOutValue(pos)) { + // use a const pointer to prevent a detach + const QOCIRowIdPointer rptr = qvariant_cast(val); + r = OCIBindByPos(sql, hbnd, err, + pos + 1, + // it's an IN value, so const_cast is ok + const_cast(&rptr->id), + -1, + SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT); + } else { + qWarning("Unknown bind variable"); + r = OCI_ERROR; + } } else { - r = OCIBindByPos(sql, hbnd, err, - pos + 1, - ba.data(), - ba.size(), - SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT); + const QString s = val.toString(); + // create a deep-copy + QByteArray ba(reinterpret_cast(s.utf16()), (s.length() + 1) * sizeof(QChar)); + if (isOutValue(pos)) { + ba.reserve((s.capacity() + 1) * sizeof(QChar)); + *tmpSize = ba.size(); + r = OCIBindByPos(sql, hbnd, err, + pos + 1, + ba.data(), + ba.capacity(), + SQLT_STR, indPtr, tmpSize, 0, 0, 0, OCI_DEFAULT); + } else { + r = OCIBindByPos(sql, hbnd, err, + pos + 1, + ba.data(), + ba.size(), + SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT); + } + if (r == OCI_SUCCESS) + setCharset(*hbnd, OCI_HTYPE_BIND); + tmpStorage.rawData.append(ba); } - if (r == OCI_SUCCESS) - setCharset(*hbnd, OCI_HTYPE_BIND); - tmpStorage.rawData.append(ba); break; } // default case } // switch @@ -523,26 +524,26 @@ int QOCIResultPrivate::bindValues(QVariantList &values, IndicatorArray &indicato // will assign out value and remove its temp storage. static void qOraOutValue(QVariant &value, TempStorage &tmpStorage, OCIEnv *env, OCIError* err) { - switch (value.type()) { - case QVariant::Time: + switch (value.typeId()) { + case QMetaType::QTime: value = QOCIDateTime::fromOCIDateTime(env, err, tmpStorage.dateTimes.takeFirst()->dateTime).time(); break; - case QVariant::Date: + case QMetaType::QDate: value = QOCIDateTime::fromOCIDateTime(env, err, tmpStorage.dateTimes.takeFirst()->dateTime).date(); break; - case QVariant::DateTime: + case QMetaType::QDateTime: value = QOCIDateTime::fromOCIDateTime(env, err, tmpStorage.dateTimes.takeFirst()->dateTime); break; - case QVariant::LongLong: + case QMetaType::LongLong: value = qMakeLongLong(tmpStorage.rawData.takeFirst(), err); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: value = qMakeULongLong(tmpStorage.rawData.takeFirst(), err); break; - case QVariant::String: + case QMetaType::String: value = QString( reinterpret_cast(tmpStorage.rawData.takeFirst().constData())); break; @@ -591,7 +592,7 @@ void QOCIDriverPrivate::allocErrorHandle() struct OraFieldInfo { QString name; - QVariant::Type type; + QMetaType type; ub1 oraIsNull; ub4 oraType; sb1 oraScale; @@ -650,53 +651,53 @@ QSqlError qMakeError(const QString& errString, QSqlError::ErrorType type, OCIErr errorCode != -1 ? QString::number(errorCode) : QString()); } -QVariant::Type qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy precisionPolicy) +QMetaType qDecodeOCIType(const QString& ocitype, QSql::NumericalPrecisionPolicy precisionPolicy) { - QVariant::Type type = QVariant::Invalid; + int type = QMetaType::UnknownType; if (ocitype == QLatin1String("VARCHAR2") || ocitype == QLatin1String("VARCHAR") || ocitype.startsWith(QLatin1String("INTERVAL")) || ocitype == QLatin1String("CHAR") || ocitype == QLatin1String("NVARCHAR2") || ocitype == QLatin1String("NCHAR")) - type = QVariant::String; + type = QMetaType::QString; else if (ocitype == QLatin1String("NUMBER") || ocitype == QLatin1String("FLOAT") || ocitype == QLatin1String("BINARY_FLOAT") || ocitype == QLatin1String("BINARY_DOUBLE")) { switch(precisionPolicy) { case QSql::LowPrecisionInt32: - type = QVariant::Int; + type = QMetaType::Int; break; case QSql::LowPrecisionInt64: - type = QVariant::LongLong; + type = QMetaType::LongLong; break; case QSql::LowPrecisionDouble: - type = QVariant::Double; + type = QMetaType::Double; break; case QSql::HighPrecision: default: - type = QVariant::String; + type = QMetaType::QString; break; } } else if (ocitype == QLatin1String("LONG") || ocitype == QLatin1String("NCLOB") || ocitype == QLatin1String("CLOB")) - type = QVariant::ByteArray; + type = QMetaType::QByteArray; else if (ocitype == QLatin1String("RAW") || ocitype == QLatin1String("LONG RAW") || ocitype == QLatin1String("ROWID") || ocitype == QLatin1String("BLOB") || ocitype == QLatin1String("CFILE") || ocitype == QLatin1String("BFILE")) - type = QVariant::ByteArray; + type = QMetaType::QByteArray; else if (ocitype == QLatin1String("DATE") || ocitype.startsWith(QLatin1String("TIME"))) - type = QVariant::DateTime; + type = QMetaType::QDateTime; else if (ocitype == QLatin1String("UNDEFINED")) - type = QVariant::Invalid; - if (type == QVariant::Invalid) + type = QMetaType::UnknownType; + if (type == QMetaType::UnknownType) qWarning("qDecodeOCIType: unknown type: %s", ocitype.toLocal8Bit().constData()); - return type; + return QMetaType(type); } -QVariant::Type qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precisionPolicy) +QMetaType qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precisionPolicy) { - QVariant::Type type = QVariant::Invalid; + int type = QMetaType::UnknownType; switch (ocitype) { case SQLT_STR: case SQLT_VST: @@ -712,10 +713,10 @@ QVariant::Type qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precis #ifdef SQLT_INTERVAL_DS case SQLT_INTERVAL_DS: #endif - type = QVariant::String; + type = QMetaType::QString; break; case SQLT_INT: - type = QVariant::Int; + type = QMetaType::Int; break; case SQLT_FLT: case SQLT_NUM: @@ -723,17 +724,17 @@ QVariant::Type qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precis case SQLT_UIN: switch(precisionPolicy) { case QSql::LowPrecisionInt32: - type = QVariant::Int; + type = QMetaType::Int; break; case QSql::LowPrecisionInt64: - type = QVariant::LongLong; + type = QMetaType::LongLong; break; case QSql::LowPrecisionDouble: - type = QVariant::Double; + type = QMetaType::Double; break; case QSql::HighPrecision: default: - type = QVariant::String; + type = QMetaType::QString; break; } break; @@ -748,21 +749,20 @@ QVariant::Type qDecodeOCIType(int ocitype, QSql::NumericalPrecisionPolicy precis case SQLT_NTY: case SQLT_REF: case SQLT_RID: - type = QVariant::ByteArray; + type = QMetaType::QByteArray; break; case SQLT_DAT: case SQLT_ODT: case SQLT_TIMESTAMP: case SQLT_TIMESTAMP_TZ: case SQLT_TIMESTAMP_LTZ: - type = QVariant::DateTime; + type = QMetaType::QDateTime; break; default: - type = QVariant::Invalid; qWarning("qDecodeOCIType: unknown OCI datatype: %d", ocitype); break; } - return type; + return QMetaType(type); } static QSqlField qFromOraInf(const OraFieldInfo &ofi) @@ -770,7 +770,7 @@ static QSqlField qFromOraInf(const OraFieldInfo &ofi) QSqlField f(ofi.name, ofi.type); f.setRequired(ofi.oraIsNull == 0); - if (ofi.type == QVariant::String && ofi.oraType != SQLT_NUM && ofi.oraType != SQLT_VNU) + if (ofi.type.id() == QMetaType::QString && ofi.oraType != SQLT_NUM && ofi.oraType != SQLT_VNU) f.setLength(ofi.oraFieldLength); else f.setLength(ofi.oraPrecision == 0 ? 38 : int(ofi.oraPrecision)); @@ -852,13 +852,13 @@ private: class OraFieldInf { public: - OraFieldInf() : data(0), len(0), ind(0), typ(QVariant::Invalid), oraType(0), def(0), lob(0), dataPtr(nullptr) + OraFieldInf() : data(0), len(0), ind(0), oraType(0), def(0), lob(0), dataPtr(nullptr) {} ~OraFieldInf(); char *data; int len; sb2 ind; - QVariant::Type typ; + QMetaType typ; ub4 oraType; OCIDefine *def; OCILobLocator *lob; @@ -879,9 +879,9 @@ QOCICols::OraFieldInf::~OraFieldInf() } if (dataPtr) { switch (typ) { - case QVariant::Date: - case QVariant::Time: - case QVariant::DateTime: { + case QMetaType::QDate: + case QMetaType::QTime: + case QMetaType::QDateTime: { int r = OCIDescriptorFree(dataPtr, OCI_DTYPE_TIMESTAMP_TZ); if (r != OCI_SUCCESS) qWarning("QOCICols: Cannot free OCIDateTime descriptor"); @@ -935,8 +935,8 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) fieldInf[idx].oraType = ofi.oraType; rec.append(qFromOraInf(ofi)); - switch (ofi.type) { - case QVariant::DateTime: + switch (ofi.type.id()) { + case QMetaType::QDateTime: r = OCIDescriptorAlloc(d->env, (void **)&fieldInf[idx].dataPtr, OCI_DTYPE_TIMESTAMP_TZ, 0, 0); if (r != OCI_SUCCESS) { qWarning("QOCICols: Unable to allocate the OCIDateTime descriptor"); @@ -952,7 +952,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) &(fieldInf[idx].ind), 0, 0, OCI_DEFAULT); break; - case QVariant::Double: + case QMetaType::Double: r = OCIDefineByPos(d->sql, &dfn, d->err, @@ -963,7 +963,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) &(fieldInf[idx].ind), 0, 0, OCI_DEFAULT); break; - case QVariant::Int: + case QMetaType::Int: r = OCIDefineByPos(d->sql, &dfn, d->err, @@ -974,7 +974,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) &(fieldInf[idx].ind), 0, 0, OCI_DEFAULT); break; - case QVariant::LongLong: + case QMetaType::LongLong: r = OCIDefineByPos(d->sql, &dfn, d->err, @@ -985,7 +985,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) &(fieldInf[idx].ind), 0, 0, OCI_DEFAULT); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: // RAW and LONG RAW fields can't be bound to LOB locators if (ofi.oraType == SQLT_BIN) { // qDebug("binding SQLT_BIN"); @@ -1032,7 +1032,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp) 0, 0, OCI_DEFAULT); } break; - case QVariant::String: + case QMetaType::QString: if (ofi.oraType == SQLT_LNG) { r = OCIDefineByPos(d->sql, &dfn, @@ -1192,7 +1192,6 @@ OraFieldInfo QOCICols::qMakeOraField(const QOCIResultPrivate* p, OCIParam* param sb2 colPrecision(0); ub1 colIsNull(0); int r(0); - QVariant::Type type(QVariant::Invalid); r = OCIAttrGet(param, OCI_DTYPE_PARAM, @@ -1269,28 +1268,26 @@ OraFieldInfo QOCICols::qMakeOraField(const QOCIResultPrivate* p, OCIParam* param if (r != 0) qOraWarning("qMakeOraField:", p->err); - type = qDecodeOCIType(colType, p->q_func()->numericalPrecisionPolicy()); + QMetaType type = qDecodeOCIType(colType, p->q_func()->numericalPrecisionPolicy()); - if (type == QVariant::Int) { - if (colLength == 22 && colPrecision == 0 && colScale == 0) - type = QVariant::String; - if (colScale > 0) - type = QVariant::String; + if (type.id() == QMetaType::Int) { + if ((colLength == 22 && colPrecision == 0 && colScale == 0) || colScale > 0) + type = QMetaType(QMetaType::QString); } // bind as double if the precision policy asks for it if (((colType == SQLT_FLT) || (colType == SQLT_NUM)) && (p->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionDouble)) { - type = QVariant::Double; + type = QMetaType(QMetaType::Double); } // bind as int32 or int64 if the precision policy asks for it if ((colType == SQLT_NUM) || (colType == SQLT_VNU) || (colType == SQLT_UIN) || (colType == SQLT_INT)) { if (p->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionInt64) - type = QVariant::LongLong; + type = QMetaType(QMetaType::LongLong); else if (p->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionInt32) - type = QVariant::Int; + type = QMetaType(QMetaType::Int); } if (colType == SQLT_BLOB) @@ -1357,11 +1354,10 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a int i; sword r; - QVarLengthArray fieldTypes; + QVarLengthArray fieldTypes; for (i = 0; i < columnCount; ++i) { - QVariant::Type tp = boundValues.at(i).type(); - fieldTypes.append(tp == QVariant::List ? boundValues.at(i).toList().value(0).type() - : tp); + QMetaType tp = boundValues.at(i).metaType(); + fieldTypes.append(tp.id() == QMetaType::QVariantList ? boundValues.at(i).toList().value(0).metaType() : tp); } SizeArray tmpSizes(columnCount); QList columns(columnCount); @@ -1371,7 +1367,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a // figuring out buffer sizes for (i = 0; i < columnCount; ++i) { - if (boundValues.at(i).type() != QVariant::List) { + if (boundValues.at(i).typeId() != QMetaType::QVariantList) { // not a list - create a deep-copy of the single value QOCIBatchColumn &singleCol = columns[i]; @@ -1399,45 +1395,40 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a col.maxarr_len = col.recordCount; col.curelep = col.recordCount; - switch (fieldTypes[i]) { - case QVariant::Time: - case QVariant::Date: - case QVariant::DateTime: + switch (fieldTypes[i].id()) { + case QMetaType::QTime: + case QMetaType::QDate: + case QMetaType::QDateTime: col.bindAs = SQLT_TIMESTAMP_TZ; col.maxLen = sizeof(OCIDateTime *); break; - case QVariant::Int: + case QMetaType::Int: col.bindAs = SQLT_INT; col.maxLen = sizeof(int); break; - case QVariant::UInt: + case QMetaType::UInt: col.bindAs = SQLT_UIN; col.maxLen = sizeof(uint); break; - case QVariant::LongLong: + case QMetaType::LongLong: col.bindAs = SQLT_VNU; col.maxLen = sizeof(OCINumber); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: col.bindAs = SQLT_VNU; col.maxLen = sizeof(OCINumber); break; - case QVariant::Double: + case QMetaType::Double: col.bindAs = SQLT_FLT; col.maxLen = sizeof(double); break; - case QVariant::UserType: - col.bindAs = SQLT_RDD; - col.maxLen = sizeof(OCIRowid*); - break; - - case QVariant::String: { + case QMetaType::QString: { col.bindAs = SQLT_STR; for (uint j = 0; j < col.recordCount; ++j) { uint len; @@ -1451,18 +1442,23 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a col.maxLen *= sizeof(QChar); break; } - case QVariant::ByteArray: + case QMetaType::QByteArray: default: { - col.bindAs = SQLT_LBI; - for (uint j = 0; j < col.recordCount; ++j) { - if(d->isOutValue(i)) - col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().capacity(); - else - col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().size(); - if (col.lengths[j] > col.maxLen) - col.maxLen = col.lengths[j]; + if (fieldTypes[i].typeId() >= QMetaType::User) { + col.bindAs = SQLT_RDD; + col.maxLen = sizeof(OCIRowid*); + } else { + col.bindAs = SQLT_LBI; + for (uint j = 0; j < col.recordCount; ++j) { + if (d->isOutValue(i)) + col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().capacity(); + else + col.lengths[j] = boundValues.at(i).toList().at(j).toByteArray().size(); + if (col.lengths[j] > col.maxLen) + col.maxLen = col.lengths[j]; + } } - break; } + break; } col.data = new char[col.maxLen * col.recordCount]; @@ -1478,26 +1474,26 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a } else { columns[i].indicators[row] = 0; char *dataPtr = columns[i].data + (columns[i].maxLen * row); - switch (fieldTypes[i]) { - case QVariant::Time: - case QVariant::Date: - case QVariant::DateTime:{ + switch (fieldTypes[i].id()) { + case QMetaType::QTime: + case QMetaType::QDate: + case QMetaType::QDateTime:{ columns[i].lengths[row] = columns[i].maxLen; QOCIDateTime *date = new QOCIDateTime(d->env, d->err, val.toDateTime()); *reinterpret_cast(dataPtr) = date->dateTime; break; } - case QVariant::Int: + case QMetaType::Int: columns[i].lengths[row] = columns[i].maxLen; *reinterpret_cast(dataPtr) = val.toInt(); break; - case QVariant::UInt: + case QMetaType::UInt: columns[i].lengths[row] = columns[i].maxLen; *reinterpret_cast(dataPtr) = val.toUInt(); break; - case QVariant::LongLong: + case QMetaType::LongLong: { columns[i].lengths[row] = columns[i].maxLen; const QByteArray ba = qMakeOCINumber(val.toLongLong(), d->err); @@ -1505,7 +1501,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a memcpy(dataPtr, ba.constData(), columns[i].maxLen); break; } - case QVariant::ULongLong: + case QMetaType::ULongLong: { columns[i].lengths[row] = columns[i].maxLen; const QByteArray ba = qMakeOCINumber(val.toULongLong(), d->err); @@ -1513,29 +1509,31 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a memcpy(dataPtr, ba.constData(), columns[i].maxLen); break; } - case QVariant::Double: + case QMetaType::Double: columns[i].lengths[row] = columns[i].maxLen; *reinterpret_cast(dataPtr) = val.toDouble(); break; - case QVariant::String: { + case QMetaType::QString: { const QString s = val.toString(); columns[i].lengths[row] = (s.length() + 1) * sizeof(QChar); memcpy(dataPtr, s.utf16(), columns[i].lengths[row]); break; } - case QVariant::UserType: - if (val.canConvert()) { - const QOCIRowIdPointer rptr = qvariant_cast(val); - *reinterpret_cast(dataPtr) = rptr->id; - columns[i].lengths[row] = 0; - break; - } - case QVariant::ByteArray: + case QMetaType::QByteArray: default: { - const QByteArray ba = val.toByteArray(); - columns[i].lengths[row] = ba.size(); - memcpy(dataPtr, ba.constData(), ba.size()); + if (fieldTypes[i].id() >= QMetaType::User) { + if (val.canConvert()) { + const QOCIRowIdPointer rptr = qvariant_cast(val); + *reinterpret_cast(dataPtr) = rptr->id; + columns[i].lengths[row] = 0; + break; + } + } else { + const QByteArray ba = val.toByteArray(); + columns[i].lengths[row] = ba.size(); + memcpy(dataPtr, ba.constData(), ba.size()); + } break; } } @@ -1618,7 +1616,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a if (!d->isOutValue(i)) continue; - if (auto tp = boundValues.at(i).metaType(); tp.id() != QVariant::List) { + if (auto tp = boundValues.at(i).metaType(); tp.id() != QMetaType::QVariantList) { qOraOutValue(boundValues[i], tmpStorage, d->env, d->err); if (*columns[i].indicators == -1) boundValues[i] = QVariant(tp); @@ -1651,11 +1649,11 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a case SQLT_VNU: { - switch (boundValues.at(i).type()) { - case QVariant::LongLong: + switch (boundValues.at(i).typeId()) { + case QMetaType::LongLong: (*list)[r] = qMakeLongLong(data + r * columns[i].maxLen, d->err); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: (*list)[r] = qMakeULongLong(data + r * columns[i].maxLen, d->err); break; default: @@ -1791,21 +1789,21 @@ void QOCICols::getValues(QVariantList &v, int index) if (fld.oraType == SQLT_BIN || fld.oraType == SQLT_LBI || fld.oraType == SQLT_LNG) continue; // already fetched piecewise - switch (fld.typ) { - case QVariant::DateTime: + switch (fld.typ.id()) { + case QMetaType::QDateTime: v[index + i] = QVariant(QOCIDateTime::fromOCIDateTime(d->env, d->err, reinterpret_cast(fld.dataPtr))); break; - case QVariant::Double: - case QVariant::Int: - case QVariant::LongLong: + case QMetaType::Double: + case QMetaType::Int: + case QMetaType::LongLong: if (d->q_func()->numericalPrecisionPolicy() != QSql::HighPrecision) { if ((d->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionDouble) - && (fld.typ == QVariant::Double)) { + && (fld.typ.id() == QMetaType::Double)) { v[index + i] = *reinterpret_cast(fld.data); break; } else if ((d->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionInt64) - && (fld.typ == QVariant::LongLong)) { + && (fld.typ.id() == QMetaType::LongLong)) { qint64 qll = 0; int r = OCINumberToInt(d->err, reinterpret_cast(fld.data), sizeof(qint64), OCI_NUMBER_SIGNED, &qll); @@ -1815,20 +1813,20 @@ void QOCICols::getValues(QVariantList &v, int index) v[index + i] = QVariant(); break; } else if ((d->q_func()->numericalPrecisionPolicy() == QSql::LowPrecisionInt32) - && (fld.typ == QVariant::Int)) { + && (fld.typ.id() == QMetaType::Int)) { v[index + i] = *reinterpret_cast(fld.data); break; } } // else fall through - case QVariant::String: + case QMetaType::QString: v[index + i] = QString(reinterpret_cast(fld.data)); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: if (fld.len > 0) v[index + i] = QByteArray(fld.data, fld.len); else - v[index + i] = QVariant(QVariant::ByteArray); + v[index + i] = QVariant(QMetaType::QByteArray); break; default: qWarning("QOCICols::value: unknown data type"); @@ -2617,11 +2615,11 @@ QSqlRecord QOCIDriver::record(const QString& tablename) const << QLatin1String("BINARY_DOUBLE"); if (buildRecordInfo) { do { - QVariant::Type ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy()); + QMetaType ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy()); QSqlField f(t.value(0).toString(), ty); f.setRequired(t.value(5).toString() == QLatin1String("N")); f.setPrecision(t.value(4).toInt()); - if (d->serverVersion >= 9 && (ty == QVariant::String) && !t.isNull(3) && !keywords.contains(t.value(1).toString())) { + if (d->serverVersion >= 9 && (ty.id() == QMetaType::QString) && !t.isNull(3) && !keywords.contains(t.value(1).toString())) { // Oracle9: data_length == size in bytes, char_length == amount of characters f.setLength(t.value(7).toInt()); } else { @@ -2704,8 +2702,8 @@ QSqlIndex QOCIDriver::primaryIndex(const QString& tablename) const QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const { - switch (field.type()) { - case QVariant::DateTime: { + switch (field.typeId()) { + case QMetaType::QDateTime: { QDateTime datetime = field.value().toDateTime(); QString datestring; if (datetime.isValid()) { @@ -2722,7 +2720,7 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const } return datestring; } - case QVariant::Time: { + case QMetaType::QTime: { QDateTime datetime = field.value().toDateTime(); QString datestring; if (datetime.isValid()) { @@ -2736,7 +2734,7 @@ QString QOCIDriver::formatValue(const QSqlField &field, bool trimStrings) const } return datestring; } - case QVariant::Date: { + case QMetaType::QDate: { QDate date = field.value().toDate(); QString datestring; if (date.isValid()) { diff --git a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp index 5a00a000f7..27766c6a95 100644 --- a/src/plugins/sqldrivers/odbc/qsql_odbc.cpp +++ b/src/plugins/sqldrivers/odbc/qsql_odbc.cpp @@ -554,7 +554,7 @@ static QVariant qGetBinaryData(SQLHANDLE hStmt, int column) if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) break; if (lengthIndicator == SQL_NULL_DATA) - return QVariant(QMetaType(QVariant::ByteArray)); + return QVariant(QMetaType(QMetaType::QByteArray)); if (lengthIndicator > SQLLEN(colSize) || lengthIndicator == SQL_NO_TOTAL) { read += colSize; colSize = 65536; @@ -1213,19 +1213,19 @@ QVariant QODBCResult::data(int field) // fetched column n+1, so cache all previous columns here const QSqlField info = d->rInf.field(i); switch (info.metaType().id()) { - case QVariant::LongLong: + case QMetaType::LongLong: d->fieldCache[i] = qGetBigIntData(d->hStmt, i); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: d->fieldCache[i] = qGetBigIntData(d->hStmt, i, false); break; - case QVariant::Int: + case QMetaType::Int: d->fieldCache[i] = qGetIntData(d->hStmt, i); break; - case QVariant::UInt: + case QMetaType::UInt: d->fieldCache[i] = qGetIntData(d->hStmt, i, false); break; - case QVariant::Date: + case QMetaType::QDate: DATE_STRUCT dbuf; r = SQLGetData(d->hStmt, i + 1, @@ -1238,7 +1238,7 @@ QVariant QODBCResult::data(int field) else d->fieldCache[i] = QVariant(QMetaType::fromType()); break; - case QVariant::Time: + case QMetaType::QTime: TIME_STRUCT tbuf; r = SQLGetData(d->hStmt, i + 1, @@ -1251,7 +1251,7 @@ QVariant QODBCResult::data(int field) else d->fieldCache[i] = QVariant(QMetaType::fromType()); break; - case QVariant::DateTime: + case QMetaType::QDateTime: TIMESTAMP_STRUCT dtbuf; r = SQLGetData(d->hStmt, i + 1, @@ -1265,13 +1265,13 @@ QVariant QODBCResult::data(int field) else d->fieldCache[i] = QVariant(QMetaType::fromType()); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: d->fieldCache[i] = qGetBinaryData(d->hStmt, i); break; - case QVariant::String: + case QMetaType::QString: d->fieldCache[i] = qGetStringData(d->hStmt, i, info.length(), d->unicode); break; - case QVariant::Double: + case QMetaType::Double: switch(numericalPrecisionPolicy()) { case QSql::LowPrecisionInt32: d->fieldCache[i] = qGetIntData(d->hStmt, i); @@ -1414,8 +1414,8 @@ bool QODBCResult::exec() SQLLEN *ind = &indicators[i]; if (val.isNull()) *ind = SQL_NULL_DATA; - switch (val.userType()) { - case QVariant::Date: { + switch (val.typeId()) { + case QMetaType::QDate: { QByteArray &ba = tmpStorage[i]; ba.resize(sizeof(DATE_STRUCT)); DATE_STRUCT *dt = (DATE_STRUCT *)const_cast(ba.constData()); @@ -1434,7 +1434,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; } - case QVariant::Time: { + case QMetaType::QTime: { QByteArray &ba = tmpStorage[i]; ba.resize(sizeof(TIME_STRUCT)); TIME_STRUCT *dt = (TIME_STRUCT *)const_cast(ba.constData()); @@ -1453,7 +1453,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { QByteArray &ba = tmpStorage[i]; ba.resize(sizeof(TIMESTAMP_STRUCT)); TIMESTAMP_STRUCT *dt = reinterpret_cast(const_cast(ba.constData())); @@ -1489,7 +1489,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; } - case QVariant::Int: + case QMetaType::Int: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1501,7 +1501,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::UInt: + case QMetaType::UInt: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1513,7 +1513,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::Double: + case QMetaType::Double: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1525,7 +1525,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::LongLong: + case QMetaType::LongLong: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1537,7 +1537,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::ULongLong: + case QMetaType::ULongLong: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1549,7 +1549,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::ByteArray: + case QMetaType::QByteArray: if (*ind != SQL_NULL_DATA) { *ind = val.toByteArray().size(); } @@ -1564,7 +1564,7 @@ bool QODBCResult::exec() val.toByteArray().size(), ind); break; - case QVariant::Bool: + case QMetaType::Bool: r = SQLBindParameter(d->hStmt, i + 1, qParamType[bindValueType(i) & QSql::InOut], @@ -1576,7 +1576,7 @@ bool QODBCResult::exec() 0, *ind == SQL_NULL_DATA ? ind : NULL); break; - case QVariant::String: + case QMetaType::QString: if (d->unicode) { QByteArray &ba = tmpStorage[i]; QString str = val.toString(); @@ -1689,31 +1689,31 @@ bool QODBCResult::exec() return true; for (i = 0; i < values.count(); ++i) { - switch (values.at(i).userType()) { - case QVariant::Date: { + switch (values.at(i).typeId()) { + case QMetaType::QDate: { DATE_STRUCT ds = *((DATE_STRUCT *)const_cast(tmpStorage.at(i).constData())); values[i] = QVariant(QDate(ds.year, ds.month, ds.day)); break; } - case QVariant::Time: { + case QMetaType::QTime: { TIME_STRUCT dt = *((TIME_STRUCT *)const_cast(tmpStorage.at(i).constData())); values[i] = QVariant(QTime(dt.hour, dt.minute, dt.second)); break; } - case QVariant::DateTime: { + case QMetaType::QDateTime: { TIMESTAMP_STRUCT dt = *((TIMESTAMP_STRUCT*) const_cast(tmpStorage.at(i).constData())); values[i] = QVariant(QDateTime(QDate(dt.year, dt.month, dt.day), QTime(dt.hour, dt.minute, dt.second, dt.fraction / 1000000))); break; } - case QVariant::Bool: - case QVariant::Int: - case QVariant::UInt: - case QVariant::Double: - case QVariant::ByteArray: - case QVariant::LongLong: - case QVariant::ULongLong: + case QMetaType::Bool: + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::Double: + case QMetaType::QByteArray: + case QMetaType::LongLong: + case QMetaType::ULongLong: //nothing to do break; - case QVariant::String: + case QMetaType::QString: if (d->unicode) { if (bindValueType(i) & QSql::Out) { const QByteArray &first = tmpStorage.at(i); @@ -2583,7 +2583,7 @@ QString QODBCDriver::formatValue(const QSqlField &field, QString r; if (field.isNull()) { r = QLatin1String("NULL"); - } else if (field.metaType().id() == QVariant::DateTime) { + } else if (field.metaType().id() == QMetaType::QDateTime) { // Use an escape sequence for the datetime fields if (field.value().toDateTime().isValid()){ QDate dt = field.value().toDateTime().date(); @@ -2599,7 +2599,7 @@ QString QODBCDriver::formatValue(const QSqlField &field, QLatin1String("' }"); } else r = QLatin1String("NULL"); - } else if (field.metaType().id() == QVariant::ByteArray) { + } else if (field.metaType().id() == QMetaType::QByteArray) { QByteArray ba = field.value().toByteArray(); QString res; static const char hexchars[] = "0123456789abcdef"; diff --git a/src/plugins/sqldrivers/psql/qsql_psql.cpp b/src/plugins/sqldrivers/psql/qsql_psql.cpp index cdc4ce7c36..e928f02ff4 100644 --- a/src/plugins/sqldrivers/psql/qsql_psql.cpp +++ b/src/plugins/sqldrivers/psql/qsql_psql.cpp @@ -364,15 +364,15 @@ bool QPSQLResultPrivate::processResults() return false; } -static QVariant::Type qDecodePSQLType(int t) +static QMetaType qDecodePSQLType(int t) { - QVariant::Type type = QVariant::Invalid; + int type = QMetaType::UnknownType; switch (t) { case QBOOLOID: - type = QVariant::Bool; + type = QMetaType::Bool; break; case QINT8OID: - type = QVariant::LongLong; + type = QMetaType::LongLong; break; case QINT2OID: case QINT4OID: @@ -380,34 +380,34 @@ static QVariant::Type qDecodePSQLType(int t) case QREGPROCOID: case QXIDOID: case QCIDOID: - type = QVariant::Int; + type = QMetaType::Int; break; case QNUMERICOID: case QFLOAT4OID: case QFLOAT8OID: - type = QVariant::Double; + type = QMetaType::Double; break; case QABSTIMEOID: case QRELTIMEOID: case QDATEOID: - type = QVariant::Date; + type = QMetaType::QDate; break; case QTIMEOID: case QTIMETZOID: - type = QVariant::Time; + type = QMetaType::QTime; break; case QTIMESTAMPOID: case QTIMESTAMPTZOID: - type = QVariant::DateTime; + type = QMetaType::QDateTime; break; case QBYTEAOID: - type = QVariant::ByteArray; + type = QMetaType::QByteArray; break; default: - type = QVariant::String; + type = QMetaType::QString; break; } - return type; + return QMetaType(type); } void QPSQLResultPrivate::deallocatePreparedStmt() @@ -632,23 +632,23 @@ QVariant QPSQLResult::data(int i) } const int currentRow = isForwardOnly() ? 0 : at(); int ptype = PQftype(d->result, i); - QVariant::Type type = qDecodePSQLType(ptype); + QMetaType type = qDecodePSQLType(ptype); if (PQgetisnull(d->result, currentRow, i)) - return QVariant(QMetaType(type), nullptr); + return QVariant(type, nullptr); const char *val = PQgetvalue(d->result, currentRow, i); - switch (type) { - case QVariant::Bool: + switch (type.id()) { + case QMetaType::Bool: return QVariant((bool)(val[0] == 't')); - case QVariant::String: + case QMetaType::QString: return d->drv_d_func()->isUtf8 ? QString::fromUtf8(val) : QString::fromLatin1(val); - case QVariant::LongLong: + case QMetaType::LongLong: if (val[0] == '-') return QByteArray::fromRawData(val, qstrlen(val)).toLongLong(); else return QByteArray::fromRawData(val, qstrlen(val)).toULongLong(); - case QVariant::Int: + case QMetaType::Int: return atoi(val); - case QVariant::Double: { + case QMetaType::Double: { if (ptype == QNUMERICOID) { if (numericalPrecisionPolicy() == QSql::HighPrecision) return QString::fromLatin1(val); @@ -675,26 +675,26 @@ QVariant QPSQLResult::data(int i) } return dbl; } - case QVariant::Date: + case QMetaType::QDate: #if QT_CONFIG(datestring) return QVariant(QDate::fromString(QString::fromLatin1(val), Qt::ISODate)); #else return QVariant(QString::fromLatin1(val)); #endif - case QVariant::Time: + case QMetaType::QTime: #if QT_CONFIG(datestring) return QVariant(QTime::fromString(QString::fromLatin1(val), Qt::ISODate)); #else return QVariant(QString::fromLatin1(val)); #endif - case QVariant::DateTime: + case QMetaType::QDateTime: #if QT_CONFIG(datestring) return QVariant(QDateTime::fromString(QString::fromLatin1(val), Qt::ISODate).toLocalTime()); #else return QVariant(QString::fromLatin1(val)); #endif - case QVariant::ByteArray: { + case QMetaType::QByteArray: { size_t len; unsigned char *data = PQunescapeBytea((const unsigned char*)val, &len); QByteArray ba(reinterpret_cast(data), int(len)); @@ -702,7 +702,6 @@ QVariant QPSQLResult::data(int i) return QVariant(ba); } default: - case QVariant::Invalid: qWarning("QPSQLResult::data: unknown data type"); } return QVariant(); @@ -805,7 +804,7 @@ QSqlRecord QPSQLResult::record() const f.setTableName(QString()); } int ptype = PQftype(d->result, i); - f.setMetaType(QMetaType(qDecodePSQLType(ptype))); + f.setMetaType(qDecodePSQLType(ptype)); f.setValue(QVariant(f.metaType())); // only set in setType() when it's invalid before int len = PQfsize(d->result, i); int precision = PQfmod(d->result, i); @@ -1477,7 +1476,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const r = nullStr(); } else { switch (field.metaType().id()) { - case QVariant::DateTime: + case QMetaType::QDateTime: #if QT_CONFIG(datestring) if (field.value().toDateTime().isValid()) { // we force the value to be considered with a timezone information, and we force it to be UTC @@ -1493,7 +1492,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const r = nullStr(); #endif // datestring break; - case QVariant::Time: + case QMetaType::QTime: #if QT_CONFIG(datestring) if (field.value().toTime().isValid()) { r = QLatin1Char('\'') + field.value().toTime().toString(u"hh:mm:ss.zzz") + QLatin1Char('\''); @@ -1503,18 +1502,18 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const r = nullStr(); } break; - case QVariant::String: + case QMetaType::QString: r = QSqlDriver::formatValue(field, trimStrings); if (d->hasBackslashEscape) r.replace(QLatin1Char('\\'), QLatin1String("\\\\")); break; - case QVariant::Bool: + case QMetaType::Bool: if (field.value().toBool()) r = QStringLiteral("TRUE"); else r = QStringLiteral("FALSE"); break; - case QVariant::ByteArray: { + case QMetaType::QByteArray: { QByteArray ba(field.value().toByteArray()); size_t len; #if defined PG_VERSION_NUM && PG_VERSION_NUM-0 >= 80200 @@ -1533,12 +1532,12 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const if (r.isEmpty()) r = QSqlDriver::formatValue(field, trimStrings); break; - case QVariant::Double: + case QMetaType::Double: assignSpecialPsqlFloatValue(field.value().toDouble(), &r); if (r.isEmpty()) r = QSqlDriver::formatValue(field, trimStrings); break; - case QVariant::Uuid: + case QMetaType::QUuid: r = QLatin1Char('\'') + field.value().toString() + QLatin1Char('\''); break; default: diff --git a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp index 496c971621..71bd6eccf0 100644 --- a/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp +++ b/src/sql/doc/snippets/code/src_sql_kernel_qsqlquery.cpp @@ -73,7 +73,7 @@ ints << 1 << 2 << 3 << 4; q.addBindValue(ints); QVariantList names; -names << "Harald" << "Boris" << "Trond" << QVariant(QVariant::String); +names << "Harald" << "Boris" << "Trond" << QVariant(QMetaType::QString); q.addBindValue(names); if (!q.execBatch()) diff --git a/src/sql/kernel/qsqlfield.h b/src/sql/kernel/qsqlfield.h index 27ad47ca35..80b412a973 100644 --- a/src/sql/kernel/qsqlfield.h +++ b/src/sql/kernel/qsqlfield.h @@ -54,13 +54,6 @@ class Q_SQL_EXPORT QSqlField public: enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 }; -#if QT_DEPRECATED_SINCE(6, 0) - QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead") - QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString()) - : QSqlField(fieldName, QMetaType(type), tableName) - {} -#endif - explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType(), const QString &tableName = QString()); QSqlField(const QSqlField& other); @@ -86,10 +79,17 @@ public: void setMetaType(QMetaType type); #if QT_DEPRECATED_SINCE(6, 0) + QT_WARNING_PUSH + QT_WARNING_DISABLE_DEPRECATED + QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead") + QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString()) + : QSqlField(fieldName, QMetaType(type), tableName) + {} QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead") QVariant::Type type() const { return QVariant::Type(metaType().id()); }; QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead") void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); } + QT_WARNING_POP #endif void setRequiredStatus(RequiredStatus status); diff --git a/src/sql/kernel/qsqlquery.cpp b/src/sql/kernel/qsqlquery.cpp index 5909709edc..d51d596d14 100644 --- a/src/sql/kernel/qsqlquery.cpp +++ b/src/sql/kernel/qsqlquery.cpp @@ -1047,7 +1047,7 @@ bool QSqlQuery::exec() To bind NULL values, a null QVariant of the relevant type has to be added to the bound QVariantList; for example, \c - {QVariant(QVariant::String)} should be used if you are using + {QVariant(QMetaType::QString)} should be used if you are using strings. \note Every bound QVariantList must contain the same amount of @@ -1085,7 +1085,7 @@ bool QSqlQuery::execBatch(BatchExecutionMode mode) the result into. To bind a NULL value, use a null QVariant; for example, use - \c {QVariant(QVariant::String)} if you are binding a string. + \c {QVariant(QMetaType::QString)} if you are binding a string. \sa addBindValue(), prepare(), exec(), boundValue(), boundValues() */ @@ -1115,7 +1115,7 @@ void QSqlQuery::bindValue(int pos, const QVariant& val, QSql::ParamType paramTyp overwritten with data from the database after the exec() call. To bind a NULL value, use a null QVariant; for example, use \c - {QVariant(QVariant::String)} if you are binding a string. + {QVariant(QMetaType::QString)} if you are binding a string. \sa bindValue(), prepare(), exec(), boundValue(), boundValues() */ diff --git a/src/sql/kernel/qsqlresult.cpp b/src/sql/kernel/qsqlresult.cpp index 5b440d704b..a948abb13e 100644 --- a/src/sql/kernel/qsqlresult.cpp +++ b/src/sql/kernel/qsqlresult.cpp @@ -935,7 +935,7 @@ void QSqlResult::virtual_hook(int, void *) contain equal amount of values (rows). NULL values are passed in as typed QVariants, for example - \c {QVariant(QVariant::Int)} for an integer NULL value. + \c {QVariant(QMetaType::Int)} for an integer NULL value. Example: diff --git a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp index 37aba2715b..42d4fe88de 100644 --- a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp +++ b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp @@ -68,9 +68,9 @@ QSignalSpy spy(myCustomObject, SIGNAL(mySignal(int,QString,double))); myCustomObject->doSomething(); // trigger emission of the signal QList arguments = spy.takeFirst(); -QVERIFY(arguments.at(0).type() == QVariant::Int); -QVERIFY(arguments.at(1).type() == QVariant::String); -QVERIFY(arguments.at(2).type() == QVariant::double); +QVERIFY(arguments.at(0).typeId() == QMetaType::Int); +QVERIFY(arguments.at(1).typeId() == QMetaType::QString); +QVERIFY(arguments.at(2).typeId() == QMetaType::Double); //! [1] diff --git a/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp b/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp index 9745700b07..30ba269ce6 100644 --- a/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp +++ b/src/widgets/doc/snippets/code/src_gui_itemviews_qitemeditorfactory.cpp @@ -64,7 +64,7 @@ QItemEditorFactory *factory = new QItemEditorFactory; //! [2] QItemEditorFactory *editorFactory = new QItemEditorFactory; QItemEditorCreatorBase *creator = new QStandardItemEditorCreator(); -editorFactory->registerEditor(QVariant::DateType, creator); +editorFactory->registerEditor(QMetaType::QDateTime, creator); //! [2] diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index b29fd373bc..4811d32ed0 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -432,7 +432,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() the creator is registered for. For example, a creator which constructs QCheckBox widgets to edit boolean values would return the \l{QCheckBox::checkable}{checkable} property name from this function, - and must be registered in the item editor factory for the QVariant::Bool + and must be registered in the item editor factory for the QMetaType::Bool type. Note: Since Qt 4.2 the item delegates query the user property of widgets, @@ -513,7 +513,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() Setting the \c editorFactory created above in an item delegate via QStyledItemDelegate::setItemEditorFactory() makes sure that all values of type - QVariant::DateTime will be edited in \c{MyFancyDateTimeEdit}. + QMetaType::QDateTime will be edited in \c{MyFancyDateTimeEdit}. The editor must provide a user property that will contain the editing data. The property is used by \l{QStyledItemDelegate}s to set diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp index 7f7bcefb7a..db65285aef 100644 --- a/src/widgets/widgets/qcombobox.cpp +++ b/src/widgets/widgets/qcombobox.cpp @@ -2232,7 +2232,7 @@ QIcon QComboBox::itemIcon(int index) const /*! Returns the data for the given \a role in the given \a index in the - combobox, or QVariant::Invalid if there is no data for this role. + combobox, or an invalid QVariant if there is no data for this role. */ QVariant QComboBox::itemData(int index, int role) const { -- cgit v1.2.3