From 73d1476fb1397948a4d806bd921fce372bd8d63b Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 2 Dec 2019 17:54:48 +0100 Subject: Replace most use of QVariant::type and occurrences of QVariant::Type I made a clazy automated check that replaced the use of QVariant::Type by the equivalent in QMetaType. This has been deprecated since Qt 5.0, but many uses were not yet removed. In addition, there was some manual changes to fix the compilation errors. Adapted the Private API of QDateTimeParser and QMimeDataPrivate and adjust QDateTimeEdit and QSpinBox. QVariant(QVariant::Invalid) in qstylesheet made no sense. But note that in QVariant::save, we actually wanted to use the non-user type. In the SQL module, many changes were actually reverted because the API still expects QVarient::Type. Change-Id: I98c368490e4ee465ed3a3b63bda8b8eaa50ea67e Reviewed-by: Lars Knoll --- src/gui/kernel/qcursor.cpp | 2 +- src/gui/kernel/qguivariant.cpp | 62 ++++++++++++++++++------------------ src/gui/kernel/qinternalmimedata.cpp | 13 ++++---- src/gui/kernel/qkeysequence.cpp | 2 +- src/gui/kernel/qpalette.cpp | 2 +- 5 files changed, 41 insertions(+), 40 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qcursor.cpp b/src/gui/kernel/qcursor.cpp index f5a794b642..339284aa30 100644 --- a/src/gui/kernel/qcursor.cpp +++ b/src/gui/kernel/qcursor.cpp @@ -657,7 +657,7 @@ QCursor &QCursor::operator=(const QCursor &c) */ QCursor::operator QVariant() const { - return QVariant(QVariant::Cursor, this); + return QVariant(QMetaType::QCursor, this); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index 4ed9d032f6..596b7e44fd 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -178,25 +178,25 @@ static bool convert(const QVariant::Private *d, int t, void *result, bool *ok) { switch (t) { - case QVariant::ByteArray: - if (d->type == QVariant::Color) { + case QMetaType::QByteArray: + if (d->type == QMetaType::QColor) { const QColor *c = v_cast(d); *static_cast(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1(); return true; } break; - case QVariant::String: { + case QMetaType::QString: { QString *str = static_cast(result); switch (d->type) { #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: + case QMetaType::QKeySequence: *str = (*v_cast(d)).toString(QKeySequence::NativeText); return true; #endif - case QVariant::Font: + case QMetaType::QFont: *str = v_cast(d)->toString(); return true; - case QVariant::Color: { + case QMetaType::QColor: { const QColor *c = v_cast(d); *str = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb); return true; @@ -206,85 +206,85 @@ static bool convert(const QVariant::Private *d, int t, } break; } - case QVariant::Pixmap: - if (d->type == QVariant::Image) { + case QMetaType::QPixmap: + if (d->type == QMetaType::QImage) { *static_cast(result) = QPixmap::fromImage(*v_cast(d)); return true; - } else if (d->type == QVariant::Bitmap) { + } else if (d->type == QMetaType::QBitmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QVariant::Brush) { + } else if (d->type == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::TexturePattern) { *static_cast(result) = v_cast(d)->texture(); return true; } } break; - case QVariant::Image: - if (d->type == QVariant::Pixmap) { + case QMetaType::QImage: + if (d->type == QMetaType::QPixmap) { *static_cast(result) = v_cast(d)->toImage(); return true; - } else if (d->type == QVariant::Bitmap) { + } else if (d->type == QMetaType::QBitmap) { *static_cast(result) = v_cast(d)->toImage(); return true; } break; - case QVariant::Bitmap: - if (d->type == QVariant::Pixmap) { + case QMetaType::QBitmap: + if (d->type == QMetaType::QPixmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QVariant::Image) { + } else if (d->type == QMetaType::QImage) { *static_cast(result) = QBitmap::fromImage(*v_cast(d)); return true; } break; #ifndef QT_NO_SHORTCUT - case QVariant::Int: - if (d->type == QVariant::KeySequence) { + case QMetaType::Int: + if (d->type == QMetaType::QKeySequence) { const QKeySequence &seq = *v_cast(d); *static_cast(result) = seq.isEmpty() ? 0 : seq[0]; return true; } break; #endif - case QVariant::Font: - if (d->type == QVariant::String) { + case QMetaType::QFont: + if (d->type == QMetaType::QString) { QFont *f = static_cast(result); f->fromString(*v_cast(d)); return true; } break; - case QVariant::Color: - if (d->type == QVariant::String) { + case QMetaType::QColor: + if (d->type == QMetaType::QString) { static_cast(result)->setNamedColor(*v_cast(d)); return static_cast(result)->isValid(); - } else if (d->type == QVariant::ByteArray) { + } else if (d->type == QMetaType::QByteArray) { static_cast(result)->setNamedColor(QLatin1String(*v_cast(d))); return true; - } else if (d->type == QVariant::Brush) { + } else if (d->type == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::SolidPattern) { *static_cast(result) = v_cast(d)->color(); return true; } } break; - case QVariant::Brush: - if (d->type == QVariant::Color) { + case QMetaType::QBrush: + if (d->type == QMetaType::QColor) { *static_cast(result) = QBrush(*v_cast(d)); return true; - } else if (d->type == QVariant::Pixmap) { + } else if (d->type == QMetaType::QPixmap) { *static_cast(result) = QBrush(*v_cast(d)); return true; } break; #ifndef QT_NO_SHORTCUT - case QVariant::KeySequence: { + case QMetaType::QKeySequence: { QKeySequence *seq = static_cast(result); switch (d->type) { - case QVariant::String: + case QMetaType::QString: *seq = QKeySequence(*v_cast(d)); return true; - case QVariant::Int: + case QMetaType::Int: *seq = QKeySequence(d->data.i); return true; default: @@ -294,7 +294,7 @@ static bool convert(const QVariant::Private *d, int t, } #endif #ifndef QT_NO_ICON - case QVariant::Icon: { + case QMetaType::QIcon: { if (ok) *ok = false; return false; diff --git a/src/gui/kernel/qinternalmimedata.cpp b/src/gui/kernel/qinternalmimedata.cpp index 8f4da1afb5..d5cdc743ee 100644 --- a/src/gui/kernel/qinternalmimedata.cpp +++ b/src/gui/kernel/qinternalmimedata.cpp @@ -112,22 +112,23 @@ QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type { QVariant data = retrieveData_sys(mimeType, type); if (mimeType == QLatin1String("application/x-qt-image")) { - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) { + if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty())) { // try to find an image QStringList imageFormats = imageReadMimeFormats(); for (int i = 0; i < imageFormats.size(); ++i) { data = retrieveData_sys(imageFormats.at(i), type); - if (data.isNull() || (data.type() == QVariant::ByteArray && data.toByteArray().isEmpty())) + if (data.isNull() || (data.userType() == QMetaType::QByteArray && data.toByteArray().isEmpty())) continue; break; } } + int typeId = type; // we wanted some image type, but all we got was a byte array. Convert it to an image. - if (data.type() == QVariant::ByteArray - && (type == QVariant::Image || type == QVariant::Pixmap || type == QVariant::Bitmap)) + if (data.userType() == QMetaType::QByteArray + && (typeId == QMetaType::QImage || typeId == QMetaType::QPixmap || typeId == QMetaType::QBitmap)) data = QImage::fromData(data.toByteArray()); - } else if (mimeType == QLatin1String("application/x-color") && data.type() == QVariant::ByteArray) { + } else if (mimeType == QLatin1String("application/x-color") && data.userType() == QMetaType::QByteArray) { QColor c; QByteArray ba = data.toByteArray(); if (ba.size() == 8) { @@ -140,7 +141,7 @@ QVariant QInternalMimeData::retrieveData(const QString &mimeType, QVariant::Type } else { qWarning("Qt: Invalid color format"); } - } else if (data.type() != type && data.type() == QVariant::ByteArray) { + } else if (data.userType() != int(type) && data.userType() == QMetaType::QByteArray) { // try to use mime data's internal conversion stuf. QInternalMimeData *that = const_cast(this); that->setData(mimeType, data.toByteArray()); diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index e1244e1006..3a3dd42cae 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -1404,7 +1404,7 @@ QKeySequence::SequenceMatch QKeySequence::matches(const QKeySequence &seq) const */ QKeySequence::operator QVariant() const { - return QVariant(QVariant::KeySequence, this); + return QVariant(QMetaType::QKeySequence, this); } /*! \fn QKeySequence::operator int () const diff --git a/src/gui/kernel/qpalette.cpp b/src/gui/kernel/qpalette.cpp index fc063bc72c..397c50f3dc 100644 --- a/src/gui/kernel/qpalette.cpp +++ b/src/gui/kernel/qpalette.cpp @@ -714,7 +714,7 @@ QPalette &QPalette::operator=(const QPalette &p) */ QPalette::operator QVariant() const { - return QVariant(QVariant::Palette, this); + return QVariant(QMetaType::QPalette, this); } /*! -- cgit v1.2.3