diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2019-12-02 09:52:41 +0100 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2020-02-20 16:11:02 +0100 |
commit | 33cd680ddbaccf6139e215d851a39e657ae36394 (patch) | |
tree | 85f0fe036e840221ee3e3a91c2e9423bd61f8d43 /src/gui/kernel | |
parent | 14f1ec186f87ce50037044ccb079463676518ec5 (diff) |
New QMetaType representation
the QMetaType is represented as a pointer to a "vtable" in the form of
a QtPrivate::QMetaTypeInterface*
The recomanded use of QMetaType is to construct an object with
QMetaType::fromType. This does not require any registration.
There is still an id() function which will do some registration
for compatibility with Qt5. Also the patch does not really touch
the other extra things that can be registered (data stream operator,
comparison operator, iteratable, ...) and this still uses the previous
system.
This is only the change in QMetaType, other changes to use it in QVariant
and QMetaObject will follow
Change-Id: Iffad20085cf33f33447f58a68236013a8b60fdbf
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qguivariant.cpp | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/gui/kernel/qguivariant.cpp b/src/gui/kernel/qguivariant.cpp index f06a3721a1..f0d74f590b 100644 --- a/src/gui/kernel/qguivariant.cpp +++ b/src/gui/kernel/qguivariant.cpp @@ -338,19 +338,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) |