1116301
From 5652923d99166e942385eb35b778d26b55ab4b0a Mon Sep 17 00:00:00 2001
1116301
From: Fabian Kosmale <fabian.kosmale@qt.io>
1116301
Date: Tue, 27 Oct 2020 16:54:01 +0100
1116301
Subject: [PATCH 02/28] Inline components: Fix custom parser support
1116301
1116301
Fixes: QTBUG-85713
1116301
Fixes: QTBUG-87464
1116301
Change-Id: I5c190ad2d02190de90260042cc06e51c1da01c63
1116301
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
1116301
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
1116301
(cherry picked from commit 2425cd478138c52694aaa20b7f7eb4a91d97b51c)
1116301
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
1116301
---
1116301
 src/qml/qml/qqmltypecompiler.cpp                    |  6 ++++++
1116301
 .../qml/qqmllanguage/data/customParserTypeInIC.qml  | 13 +++++++++++++
1116301
 tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp    | 11 +++++++++++
1116301
 3 files changed, 30 insertions(+)
1116301
 create mode 100644 tests/auto/qml/qqmllanguage/data/customParserTypeInIC.qml
1116301
1116301
diff --git a/src/qml/qml/qqmltypecompiler.cpp b/src/qml/qml/qqmltypecompiler.cpp
1116301
index 058bf8848c..f1a6b3bff2 100644
1116301
--- a/src/qml/qml/qqmltypecompiler.cpp
1116301
+++ b/src/qml/qml/qqmltypecompiler.cpp
1116301
@@ -683,6 +683,9 @@ QQmlCustomParserScriptIndexer::QQmlCustomParserScriptIndexer(QQmlTypeCompiler *t
1116301
 void QQmlCustomParserScriptIndexer::annotateBindingsWithScriptStrings()
1116301
 {
1116301
     scanObjectRecursively(/*root object*/0);
1116301
+    for (int i = 0; i < qmlObjects.size(); ++i)
1116301
+        if (qmlObjects.at(i)->isInlineComponent)
1116301
+            scanObjectRecursively(i);
1116301
 }
1116301
 
1116301
 void QQmlCustomParserScriptIndexer::scanObjectRecursively(int objectIndex, bool annotateScriptBindings)
1116301
@@ -1223,6 +1226,9 @@ QQmlDeferredAndCustomParserBindingScanner::QQmlDeferredAndCustomParserBindingSca
1116301
 
1116301
 bool QQmlDeferredAndCustomParserBindingScanner::scanObject()
1116301
 {
1116301
+    for (int i = 0; i < qmlObjects->size(); ++i)
1116301
+        if (qmlObjects->at(i)->isInlineComponent)
1116301
+            scanObject(i);
1116301
     return scanObject(/*root object*/0);
1116301
 }
1116301
 
1116301
diff --git a/tests/auto/qml/qqmllanguage/data/customParserTypeInIC.qml b/tests/auto/qml/qqmllanguage/data/customParserTypeInIC.qml
1116301
new file mode 100644
1116301
index 0000000000..a29d87caa0
1116301
--- /dev/null
1116301
+++ b/tests/auto/qml/qqmllanguage/data/customParserTypeInIC.qml
1116301
@@ -0,0 +1,13 @@
1116301
+import QtQuick 2.15
1116301
+
1116301
+Item {
1116301
+    property int count: myModel.count
1116301
+    component MyModel : ListModel {
1116301
+        ListElement { a: 10 }
1116301
+        ListElement { a: 12 }
1116301
+    }
1116301
+
1116301
+    MyModel {
1116301
+        id: myModel
1116301
+    }
1116301
+}
1116301
diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
1116301
index e32fa884a2..8adcbc1837 100644
1116301
--- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
1116301
+++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp
1116301
@@ -111,6 +111,7 @@ private slots:
1116301
     void bindJSValueToType();
1116301
     void bindTypeToJSValue();
1116301
     void customParserTypes();
1116301
+    void customParserTypeInInlineComponent();
1116301
     void rootAsQmlComponent();
1116301
     void rootItemIsComponent();
1116301
     void inlineQmlComponents();
1116301
@@ -1313,6 +1314,16 @@ void tst_qqmllanguage::customParserTypes()
1116301
     QCOMPARE(object->property("count"), QVariant(2));
1116301
 }
1116301
 
1116301
+// Tests that custom pursor types can be instantiated in ICs
1116301
+void tst_qqmllanguage::customParserTypeInInlineComponent()
1116301
+{
1116301
+    QQmlComponent component(&engine, testFileUrl("customParserTypeInIC.qml"));
1116301
+    VERIFY_ERRORS(0);
1116301
+    QScopedPointer<QObject> object(component.create());
1116301
+    QVERIFY(object != nullptr);
1116301
+    QCOMPARE(object->property("count"), 2);
1116301
+}
1116301
+
1116301
 // Tests that the root item can be a custom component
1116301
 void tst_qqmllanguage::rootAsQmlComponent()
1116301
 {
1116301
-- 
1116301
2.31.1
1116301