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/widgets/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/widgets/kernel')
-rw-r--r-- | src/widgets/kernel/qwidgetsvariant.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/widgets/kernel/qwidgetsvariant.cpp b/src/widgets/kernel/qwidgetsvariant.cpp index edb166e8d5..02b426988f 100644 --- a/src/widgets/kernel/qwidgetsvariant.cpp +++ b/src/widgets/kernel/qwidgetsvariant.cpp @@ -138,23 +138,42 @@ static const QVariant::Handler widgets_handler = { #endif }; -#define QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES(MetaTypeName, MetaTypeId, RealName) \ - QT_METATYPE_INTERFACE_INIT(RealName), +static const struct : QMetaTypeModuleHelper +{ + QtPrivate::QMetaTypeInterface *interfaceForType(int type) const override { + switch (type) { + QT_FOR_EACH_STATIC_WIDGETS_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_WIDGETS_CLASS(QT_METATYPE_DATASTREAM_SAVE) + default: return false; + } + } + bool load(QDataStream &stream, int type, void *data) const override { + switch (type) { + QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_METATYPE_DATASTREAM_LOAD) + default: return false; + } + } +#endif + +} qVariantWidgetsHelper; -static const QMetaTypeInterface qVariantWidgetsHelper[] = { - QT_FOR_EACH_STATIC_WIDGETS_CLASS(QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES) -}; #undef QT_IMPL_METATYPEINTERFACE_WIDGETS_TYPES } // namespace -extern Q_CORE_EXPORT const QMetaTypeInterface *qMetaTypeWidgetsHelper; +extern Q_CORE_EXPORT const QMetaTypeModuleHelper *qMetaTypeWidgetsHelper; void qRegisterWidgetsVariant() { qRegisterMetaType<QWidget*>(); - qMetaTypeWidgetsHelper = qVariantWidgetsHelper; + qMetaTypeWidgetsHelper = &qVariantWidgetsHelper; QVariantPrivate::registerHandler(QModulesPrivate::Widgets, &widgets_handler); } Q_CONSTRUCTOR_FUNCTION(qRegisterWidgetsVariant) |