From a68e4f3b96a82a93898f381e8ddc7f50f9c89d40 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 9 Dec 2019 10:37:28 +0100 Subject: Use the new QMetaType API in QVariant Change-Id: I5495ee1159864ebd64083fadbfac7e07177ed406 Reviewed-by: Thiago Macieira --- src/gui/kernel/qguivariant.cpp | 55 +++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 35 deletions(-) (limited to 'src/gui/kernel') diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index f0d74f590b..e0e0d11ae3 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -101,19 +101,6 @@ struct GuiTypesFilter { }; }; -static void construct(QVariant::Private *x, const void *copy) -{ - const int type = x->type; - QVariantConstructor constructor(x, copy); - QMetaTypeSwitcher::switcher(constructor, type, nullptr); -} - -static void clear(QVariant::Private *d) -{ - QVariantDestructor destructor(d); - QMetaTypeSwitcher::switcher(destructor, d->type, nullptr); -} - // This class is a hack that customizes access to QPolygon and QPolygonF template class QGuiVariantIsNull : public QVariantIsNull { @@ -131,7 +118,7 @@ public: static bool isNull(const QVariant::Private *d) { QGuiVariantIsNull isNull(d); - return QMetaTypeSwitcher::switcher(isNull, d->type, nullptr); + return QMetaTypeSwitcher::switcher(isNull, d->type().id(), nullptr); } // This class is a hack that customizes access to QPixmap, QBitmap, QCursor and QIcon @@ -173,7 +160,7 @@ public: static bool compare(const QVariant::Private *a, const QVariant::Private *b) { QGuiVariantComparator comparator(a, b); - return QMetaTypeSwitcher::switcher(comparator, a->type, nullptr); + return QMetaTypeSwitcher::switcher(comparator, a->type().id(), nullptr); } static bool convert(const QVariant::Private *d, int t, @@ -181,7 +168,7 @@ static bool convert(const QVariant::Private *d, int t, { switch (t) { case QMetaType::QByteArray: - if (d->type == QMetaType::QColor) { + if (d->type().id() == QMetaType::QColor) { const QColor *c = v_cast(d); *static_cast(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1(); return true; @@ -189,7 +176,7 @@ static bool convert(const QVariant::Private *d, int t, break; case QMetaType::QString: { QString *str = static_cast(result); - switch (d->type) { + switch (d->type().id()) { #if QT_CONFIG(shortcut) case QMetaType::QKeySequence: *str = (*v_cast(d)).toString(QKeySequence::NativeText); @@ -209,13 +196,13 @@ static bool convert(const QVariant::Private *d, int t, break; } case QMetaType::QPixmap: - if (d->type == QMetaType::QImage) { + if (d->type().id() == QMetaType::QImage) { *static_cast(result) = QPixmap::fromImage(*v_cast(d)); return true; - } else if (d->type == QMetaType::QBitmap) { + } else if (d->type().id() == QMetaType::QBitmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QMetaType::QBrush) { + } else if (d->type().id() == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::TexturePattern) { *static_cast(result) = v_cast(d)->texture(); return true; @@ -223,26 +210,26 @@ static bool convert(const QVariant::Private *d, int t, } break; case QMetaType::QImage: - if (d->type == QMetaType::QPixmap) { + if (d->type().id() == QMetaType::QPixmap) { *static_cast(result) = v_cast(d)->toImage(); return true; - } else if (d->type == QMetaType::QBitmap) { + } else if (d->type().id() == QMetaType::QBitmap) { *static_cast(result) = v_cast(d)->toImage(); return true; } break; case QMetaType::QBitmap: - if (d->type == QMetaType::QPixmap) { + if (d->type().id() == QMetaType::QPixmap) { *static_cast(result) = *v_cast(d); return true; - } else if (d->type == QMetaType::QImage) { + } else if (d->type().id() == QMetaType::QImage) { *static_cast(result) = QBitmap::fromImage(*v_cast(d)); return true; } break; #if QT_CONFIG(shortcut) case QMetaType::Int: - if (d->type == QMetaType::QKeySequence) { + if (d->type().id() == QMetaType::QKeySequence) { const QKeySequence &seq = *v_cast(d); *static_cast(result) = seq.isEmpty() ? 0 : seq[0]; return true; @@ -250,20 +237,20 @@ static bool convert(const QVariant::Private *d, int t, break; #endif case QMetaType::QFont: - if (d->type == QMetaType::QString) { + if (d->type().id() == QMetaType::QString) { QFont *f = static_cast(result); f->fromString(*v_cast(d)); return true; } break; case QMetaType::QColor: - if (d->type == QMetaType::QString) { + if (d->type().id() == QMetaType::QString) { static_cast(result)->setNamedColor(*v_cast(d)); return static_cast(result)->isValid(); - } else if (d->type == QMetaType::QByteArray) { + } else if (d->type().id() == QMetaType::QByteArray) { static_cast(result)->setNamedColor(QLatin1String(*v_cast(d))); return true; - } else if (d->type == QMetaType::QBrush) { + } else if (d->type().id() == QMetaType::QBrush) { if (v_cast(d)->style() == Qt::SolidPattern) { *static_cast(result) = v_cast(d)->color(); return true; @@ -271,10 +258,10 @@ static bool convert(const QVariant::Private *d, int t, } break; case QMetaType::QBrush: - if (d->type == QMetaType::QColor) { + if (d->type().id() == QMetaType::QColor) { *static_cast(result) = QBrush(*v_cast(d)); return true; - } else if (d->type == QMetaType::QPixmap) { + } else if (d->type().id() == QMetaType::QPixmap) { *static_cast(result) = QBrush(*v_cast(d)); return true; } @@ -282,7 +269,7 @@ static bool convert(const QVariant::Private *d, int t, #if QT_CONFIG(shortcut) case QMetaType::QKeySequence: { QKeySequence *seq = static_cast(result); - switch (d->type) { + switch (d->type().id()) { case QMetaType::QString: *seq = QKeySequence(*v_cast(d)); return true; @@ -313,13 +300,11 @@ static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast(&v.data_ptr()); QVariantDebugStream stream(dbg, d); - QMetaTypeSwitcher::switcher(stream, d->type, nullptr); + QMetaTypeSwitcher::switcher(stream, d->type().id(), nullptr); } #endif const QVariant::Handler qt_gui_variant_handler = { - construct, - clear, isNull, #ifndef QT_NO_DATASTREAM nullptr, -- cgit v1.2.3