diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-16 16:41:27 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-09-23 14:54:46 +0200 |
commit | 8e222a70d19d5eef616e1d6306415da64fbab4cb (patch) | |
tree | 535e4cd02c2dbca0289bc6ec39f2699856554737 /src/qml/qml/qqmlvaluetype.cpp | |
parent | 90b5d7fa03f9818fa5edc897ee6a109fcc182b9e (diff) |
Allow proper registration of value types
You can now have an extension object on a value type that offers
additional properties. This is how we model the QtQuick value types. It
allows us to retrieve the extension's metaobject without using the
virtual functions in the value type provider.
As before, this mechanism is still rather dangerous and not fit for
public consumption. It relies on the extension object having exactly the
same layout as the original value type, and it hides any properties the
original value type might expose.
Furthermore we enforce now that gadgets should have lowercase names.
The ones that didn't before are split up into an anonymous value type
and a namespace that contains all the addressable bits.
Task-number: QTBUG-82443
Change-Id: Ic93d6764538d6ccc0774b3c5648eee08ba0939c0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/qml/qqmlvaluetype.cpp')
-rw-r--r-- | src/qml/qml/qqmlvaluetype.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlvaluetype.cpp b/src/qml/qml/qqmlvaluetype.cpp index d385013ff4..e996717051 100644 --- a/src/qml/qml/qqmlvaluetype.cpp +++ b/src/qml/qml/qqmlvaluetype.cpp @@ -149,14 +149,30 @@ const QMetaObject *QQmlValueTypeFactoryImpl::metaObjectForMetaType(int t) #endif if (t == qMetaTypeId<QQmlProperty>()) return &QQmlPropertyValueType::staticMetaObject; - if (const QMetaObject *mo = QQml_valueTypeProvider()->metaObjectForMetaType(t)) - return mo; break; } - QMetaType metaType(t); + const QMetaType metaType(t); + + // It doesn't have to be a gadget for a QML type to exist, but we don't want to + // call QObject pointers value types. Explicitly registered types also override + // the implicit use of gadgets. + if (!(metaType.flags() & QMetaType::PointerToQObject)) { + const QQmlType qmlType = QQmlMetaType::qmlType(t, QQmlMetaType::TypeIdCategory::MetaType); + + // Prefer the extension meta object. + // Extensions allow registration of non-gadget value types. + if (const QMetaObject *extensionMetaObject = qmlType.extensionMetaObject()) + return extensionMetaObject; + + if (const QMetaObject *qmlTypeMetaObject = qmlType.metaObject()) + return qmlTypeMetaObject; + } + + // If it _is_ a gadget, we can just use it. if (metaType.flags() & QMetaType::IsGadget) return metaType.metaObject(); + return nullptr; } @@ -525,9 +541,9 @@ int QQmlRectValueType::bottom() const } #if QT_CONFIG(easingcurve) -QQmlEasingValueType::Type QQmlEasingValueType::type() const +QQmlEasingEnums::Type QQmlEasingValueType::type() const { - return (QQmlEasingValueType::Type)v.type(); + return (QQmlEasingEnums::Type)v.type(); } qreal QQmlEasingValueType::amplitude() const @@ -545,7 +561,7 @@ qreal QQmlEasingValueType::period() const return v.period(); } -void QQmlEasingValueType::setType(QQmlEasingValueType::Type type) +void QQmlEasingValueType::setType(QQmlEasingEnums::Type type) { v.setType((QEasingCurve::Type)type); } |