aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrei Golubev <andrei.golubev@qt.io>2022-02-11 17:03:20 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-12 01:47:30 +0000
commit9c9d6410cae82aa5d624b7bc2654711f34d6588d (patch)
tree8ec09084fbebb32a41eefb2634e17b4953433aff
parent34f0e0b3acbf721c8872540d5a5b03d2e3f8ee2f (diff)
Extend tests for DeferredPropertyNames
Document some extra behavior details through tests Change-Id: Id05da7983406a0a61e78496a8e6483e10a7c38d1 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 4d98aa998eceb53ce616e9111553b8fdc5fad906) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
index 961efbc312..7e30dcad6c 100644
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
@@ -283,6 +283,7 @@ private slots:
void lazyDeferredSubObject();
void deferredProperties();
void executeDeferredPropertiesOnce();
+ void deferredProperties_extra();
void noChildEvents();
@@ -5132,6 +5133,82 @@ void tst_qqmllanguage::executeDeferredPropertiesOnce()
QCOMPARE(listProperty.at(&listProperty, 1)->property("wasCompleted"), QVariant(true));
}
+class GroupType : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(int foo READ getFoo WRITE setFoo BINDABLE bindableFoo)
+ Q_PROPERTY(int bar READ getBar WRITE setBar BINDABLE bindableBar)
+ Q_CLASSINFO("DeferredPropertyNames", "bar")
+
+ QProperty<int> m_foo { 0 };
+ QProperty<int> m_bar { 0 };
+
+public:
+ int getFoo() const { return m_foo; }
+ void setFoo(int v) { m_foo = v; }
+ QBindable<int> bindableFoo() const { return QBindable<int>(&m_foo); }
+
+ int getBar() const { return m_bar; }
+ void setBar(int v) { m_bar = v; }
+ QBindable<int> bindableBar() const { return QBindable<int>(&m_bar); }
+};
+
+class ExtraDeferredProperties : public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(GroupType *group READ getGroup)
+ Q_CLASSINFO("DeferredPropertyNames", "group,MyQmlObject")
+
+ GroupType m_group;
+
+public:
+ ExtraDeferredProperties(QObject *parent = nullptr) : QObject(parent) { }
+
+ GroupType *getGroup() { return &m_group; }
+};
+
+void tst_qqmllanguage::deferredProperties_extra()
+{
+ // Note: because ExtraDeferredProperties defers only a `group` property, the
+ // deferral does not actually work.
+ QTest::ignoreMessage(
+ QtMsgType::QtWarningMsg,
+ "Binding on group is not deferred as requested by the DeferredPropertyNames class info "
+ "because it constitutes a group property.");
+
+ qmlRegisterType<GroupType>("deferred.properties.extra", 1, 0, "GroupType");
+ qmlRegisterType<ExtraDeferredProperties>("deferred.properties.extra", 1, 0,
+ "ExtraDeferredProperties");
+ QQmlComponent component(&engine);
+ component.setData(R"(
+ import QtQuick
+ import Test 1.0
+ import deferred.properties.extra 1.0
+
+ ExtraDeferredProperties {
+ group.foo: 4
+ group.bar: 4
+ MyQmlObject.value: 1
+ }
+ )", QUrl());
+
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<ExtraDeferredProperties> object(
+ qobject_cast<ExtraDeferredProperties *>(component.create()));
+ QVERIFY(object);
+
+ QCOMPARE(object->getGroup()->getFoo(), 4); // not deferred (as group itself is not deferred)
+ QCOMPARE(object->getGroup()->getBar(), 0); // deferred, as per group's own deferred names
+ // but attached property is deferred:
+ QVERIFY(!qmlAttachedPropertiesObject<MyQmlObject>(object.get(), false));
+
+ qmlExecuteDeferred(object.get());
+
+ auto attached = qmlAttachedPropertiesObject<MyQmlObject>(object.get(), false);
+ QVERIFY(attached);
+ QCOMPARE(attached->property("value").toInt(), 1);
+}
+
void tst_qqmllanguage::noChildEvents()
{
QQmlComponent component(&engine);