diff options
Diffstat (limited to 'src/gui/kernel/qguivariant.cpp')
-rw-r--r-- | src/gui/kernel/qguivariant.cpp | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index c9c45ba815..e0e0d11ae3 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2020 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. @@ -45,7 +45,9 @@ #include "qcursor.h" #include "qfont.h" #include "qimage.h" -#include "qkeysequence.h" +#if QT_CONFIG(shortcut) +# include "qkeysequence.h" +#endif #include "qtransform.h" #include "qpalette.h" #include "qpen.h" @@ -99,19 +101,6 @@ struct GuiTypesFilter { }; }; -static void construct(QVariant::Private *x, const void *copy) -{ - const int type = x->type; - QVariantConstructor<GuiTypesFilter> constructor(x, copy); - QMetaTypeSwitcher::switcher<void>(constructor, type, nullptr); -} - -static void clear(QVariant::Private *d) -{ - QVariantDestructor<GuiTypesFilter> destructor(d); - QMetaTypeSwitcher::switcher<void>(destructor, d->type, nullptr); -} - // This class is a hack that customizes access to QPolygon and QPolygonF template<class Filter> class QGuiVariantIsNull : public QVariantIsNull<Filter> { @@ -129,7 +118,7 @@ public: static bool isNull(const QVariant::Private *d) { QGuiVariantIsNull<GuiTypesFilter> isNull(d); - return QMetaTypeSwitcher::switcher<bool>(isNull, d->type, nullptr); + return QMetaTypeSwitcher::switcher<bool>(isNull, d->type().id(), nullptr); } // This class is a hack that customizes access to QPixmap, QBitmap, QCursor and QIcon @@ -171,7 +160,7 @@ public: static bool compare(const QVariant::Private *a, const QVariant::Private *b) { QGuiVariantComparator<GuiTypesFilter> comparator(a, b); - return QMetaTypeSwitcher::switcher<bool>(comparator, a->type, nullptr); + return QMetaTypeSwitcher::switcher<bool>(comparator, a->type().id(), nullptr); } static bool convert(const QVariant::Private *d, int t, @@ -179,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<QColor>(d); *static_cast<QByteArray *>(result) = c->name(c->alpha() != 255 ? QColor::HexArgb : QColor::HexRgb).toLatin1(); return true; @@ -187,8 +176,8 @@ static bool convert(const QVariant::Private *d, int t, break; case QMetaType::QString: { QString *str = static_cast<QString *>(result); - switch (d->type) { -#ifndef QT_NO_SHORTCUT + switch (d->type().id()) { +#if QT_CONFIG(shortcut) case QMetaType::QKeySequence: *str = (*v_cast<QKeySequence>(d)).toString(QKeySequence::NativeText); return true; @@ -207,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<QPixmap *>(result) = QPixmap::fromImage(*v_cast<QImage>(d)); return true; - } else if (d->type == QMetaType::QBitmap) { + } else if (d->type().id() == QMetaType::QBitmap) { *static_cast<QPixmap *>(result) = *v_cast<QBitmap>(d); return true; - } else if (d->type == QMetaType::QBrush) { + } else if (d->type().id() == QMetaType::QBrush) { if (v_cast<QBrush>(d)->style() == Qt::TexturePattern) { *static_cast<QPixmap *>(result) = v_cast<QBrush>(d)->texture(); return true; @@ -221,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<QImage *>(result) = v_cast<QPixmap>(d)->toImage(); return true; - } else if (d->type == QMetaType::QBitmap) { + } else if (d->type().id() == QMetaType::QBitmap) { *static_cast<QImage *>(result) = v_cast<QBitmap>(d)->toImage(); return true; } break; case QMetaType::QBitmap: - if (d->type == QMetaType::QPixmap) { + if (d->type().id() == QMetaType::QPixmap) { *static_cast<QBitmap *>(result) = *v_cast<QPixmap>(d); return true; - } else if (d->type == QMetaType::QImage) { + } else if (d->type().id() == QMetaType::QImage) { *static_cast<QBitmap *>(result) = QBitmap::fromImage(*v_cast<QImage>(d)); return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QMetaType::Int: - if (d->type == QMetaType::QKeySequence) { + if (d->type().id() == QMetaType::QKeySequence) { const QKeySequence &seq = *v_cast<QKeySequence>(d); *static_cast<int *>(result) = seq.isEmpty() ? 0 : seq[0]; return true; @@ -248,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<QFont *>(result); f->fromString(*v_cast<QString>(d)); return true; } break; case QMetaType::QColor: - if (d->type == QMetaType::QString) { + if (d->type().id() == QMetaType::QString) { static_cast<QColor *>(result)->setNamedColor(*v_cast<QString>(d)); return static_cast<QColor *>(result)->isValid(); - } else if (d->type == QMetaType::QByteArray) { + } else if (d->type().id() == QMetaType::QByteArray) { static_cast<QColor *>(result)->setNamedColor(QLatin1String(*v_cast<QByteArray>(d))); return true; - } else if (d->type == QMetaType::QBrush) { + } else if (d->type().id() == QMetaType::QBrush) { if (v_cast<QBrush>(d)->style() == Qt::SolidPattern) { *static_cast<QColor *>(result) = v_cast<QBrush>(d)->color(); return true; @@ -269,18 +258,18 @@ 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<QBrush *>(result) = QBrush(*v_cast<QColor>(d)); return true; - } else if (d->type == QMetaType::QPixmap) { + } else if (d->type().id() == QMetaType::QPixmap) { *static_cast<QBrush *>(result) = QBrush(*v_cast<QPixmap>(d)); return true; } break; -#ifndef QT_NO_SHORTCUT +#if QT_CONFIG(shortcut) case QMetaType::QKeySequence: { QKeySequence *seq = static_cast<QKeySequence *>(result); - switch (d->type) { + switch (d->type().id()) { case QMetaType::QString: *seq = QKeySequence(*v_cast<QString>(d)); return true; @@ -311,13 +300,11 @@ static void streamDebug(QDebug dbg, const QVariant &v) { QVariant::Private *d = const_cast<QVariant::Private *>(&v.data_ptr()); QVariantDebugStream<GuiTypesFilter> stream(dbg, d); - QMetaTypeSwitcher::switcher<void>(stream, d->type, nullptr); + QMetaTypeSwitcher::switcher<void>(stream, d->type().id(), nullptr); } #endif const QVariant::Handler qt_gui_variant_handler = { - construct, - clear, isNull, #ifndef QT_NO_DATASTREAM nullptr, @@ -336,19 +323,41 @@ const QVariant::Handler qt_gui_variant_handler = { #define QT_IMPL_METATYPEINTERFACE_GUI_TYPES(MetaTypeName, MetaTypeId, RealName) \ QT_METATYPE_INTERFACE_INIT(RealName), -static const QMetaTypeInterface qVariantGuiHelper[] = { - QT_FOR_EACH_STATIC_GUI_CLASS(QT_IMPL_METATYPEINTERFACE_GUI_TYPES) -}; +static const struct : QMetaTypeModuleHelper +{ + QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override { + switch (type) { + QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_CONVERT_ID_TO_TYPE) + default: return nullptr; + } + } +#ifndef QT_NO_DATASTREAM + bool save(QDataStream &stream, int type, const void *data) const override { + switch (type) { + QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_DATASTREAM_SAVE) + default: return false; + } + } + bool load(QDataStream &stream, int type, void *data) const override { + switch (type) { + QT_FOR_EACH_STATIC_GUI_CLASS(QT_METATYPE_DATASTREAM_LOAD) + default: return false; + } + } +#endif + +} qVariantGuiHelper; + #undef QT_IMPL_METATYPEINTERFACE_GUI_TYPES } // namespace used to hide QVariant handler -extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeGuiHelper; +extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeGuiHelper; void qRegisterGuiVariant() { QVariantPrivate::registerHandler(QModulesPrivate::Gui, &qt_gui_variant_handler); - qMetaTypeGuiHelper = qVariantGuiHelper; + qMetaTypeGuiHelper = &qVariantGuiHelper; } Q_CONSTRUCTOR_FUNCTION(qRegisterGuiVariant) |