diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-02 14:11:24 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-02 14:32:35 +0100 |
commit | 1b93a1d86549347566e1a7645c0501e5c9f6aa0a (patch) | |
tree | 25bab0d6ef18650576864ed245ba95a628169816 /tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | |
parent | ecd54e68b90ad7022d1bdb71f1c1640ab392adae (diff) |
qmltyperegistrar: Fix handling of default properties
Default properties are always local. There is no way to declare a
default property for a foreign type as the default property is queried
directly from the classinfo at runtime.
Change-Id: I30efb6fba190957ac2a4ad86da437f209cd1f3ad
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h')
-rw-r--r-- | tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h index 40569879ec..eb3b680e82 100644 --- a/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h +++ b/tests/auto/qml/qmltyperegistrar/tst_qmltyperegistrar.h @@ -116,11 +116,61 @@ public: void setWidth(int width) { v.setWidth(width); } }; +class ForeignWithoutDefault : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *d READ d WRITE setD NOTIFY dChanged) +public: + QObject *d() const { return m_d; } + + void setD(QObject *d) + { + if (m_d != d) { + m_d = d; + emit dChanged(); + } + } + +signals: + void dChanged(); + +private: + QObject *m_d = nullptr; +}; + +class LocalWithDefault : public QObject +{ + Q_OBJECT + Q_PROPERTY(QObject *d READ d WRITE setD NOTIFY dChanged) + QML_NAMED_ELEMENT(ForeignWithoutDefault) + QML_FOREIGN(ForeignWithoutDefault) + Q_CLASSINFO("DefaultProperty", "d") + +public: + LocalWithDefault(QObject *parent = nullptr) : QObject(parent) {} + QObject *d() const { return m_d; } + + void setD(QObject *d) + { + if (m_d != d) { + m_d = d; + emit dChanged(); + } + } + +signals: + void dChanged(); + +private: + QObject *m_d = nullptr; +}; + class Local : public Foreign { Q_OBJECT QML_ELEMENT Q_PROPERTY(int someProperty MEMBER someProperty BINDABLE bindableSomeProperty) + QML_EXTENDED(LocalWithDefault) public: enum Flag { Flag1 = 0x1, @@ -216,6 +266,7 @@ private slots: void derivedFromForeign(); void metaTypesRegistered(); void multiExtensions(); + void localDefault(); private: QByteArray qmltypesData; |