aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2024-11-06 14:45:29 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2024-11-08 20:22:23 +0000
commitd271e64ec3a3ce214071c7412578e7740c9e8e36 (patch)
tree5bcc8cd5c5ff4d25fd6e8e5c8d538914a6aabf17
parent3537f745090284836a5d657768b5c3f54c4acf9e (diff)
qmltc: Retrieve types of attached and group properties
We need to recurse into those in order to find components assigned to properties of attached objects. Fixes: QTBUG-130839 Change-Id: Ie08e7f992a262fa338038bae41c293229d5e3606 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> (cherry picked from commit 21cd756a401afddb8839d3daa62e62e969dfe24e) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt2
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/attachedComponentProperty.qml13
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp34
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.h2
-rw-r--r--tools/qmltc/qmltcvisitor.cpp14
5 files changed, 59 insertions, 6 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
index b26a772793..7321dc0c3d 100644
--- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
+++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt
@@ -140,6 +140,8 @@ set(qml_sources
requiredProperties.qml
hpp.qml
+
+ attachedComponentProperty.qml
)
set(js_sources
diff --git a/tests/auto/qml/qmltc/QmltcTests/attachedComponentProperty.qml b/tests/auto/qml/qmltc/QmltcTests/attachedComponentProperty.qml
new file mode 100644
index 0000000000..6fa1c4fe7e
--- /dev/null
+++ b/tests/auto/qml/qmltc/QmltcTests/attachedComponentProperty.qml
@@ -0,0 +1,13 @@
+import QtQuick
+import QtQuick.Templates
+
+Popup {
+ Overlay.modal: Rectangle {
+ color: 'grey'
+ }
+ Overlay.objectName: "foos"
+
+ property Component b: Rectangle {
+ color: 'green'
+ }
+}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index f94f15fe44..38c2f7d6ef 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -94,6 +94,8 @@
#include "hpp.h"
+#include "attachedcomponentproperty.h"
+
// Qt:
#include <QtCore/qstring.h>
#include <QtCore/qbytearray.h>
@@ -3405,4 +3407,36 @@ void tst_qmltc::hpp()
QCOMPARE(createdByQmltc.objectName(), QLatin1String("hpp"));
}
+void tst_qmltc::attachedComponentProperty()
+{
+ QQmlEngine e;
+ PREPEND_NAMESPACE(attachedComponentProperty) createdByQmltc(&e);
+
+ QObject *attached = qmlAttachedPropertiesObject<QQuickOverlay>(&createdByQmltc);
+ QVERIFY(attached);
+ QQuickOverlayAttached *overlay = qobject_cast<QQuickOverlayAttached *>(attached);
+ QVERIFY(overlay);
+
+ QCOMPARE(overlay->objectName(), QLatin1String("foos"));
+
+ QQmlComponent *modal = overlay->modal();
+ QVERIFY(modal);
+
+ QScopedPointer<QObject> overlayInstance(modal->create());
+ QVERIFY(!overlayInstance.isNull());
+
+ QQuickRectangle *rectangle = qobject_cast<QQuickRectangle *>(overlayInstance.data());
+ QVERIFY(rectangle);
+
+ QCOMPARE(rectangle->color(), QColor::fromString("grey"_L1));
+
+ QQmlComponent *b = createdByQmltc.b();
+ QVERIFY(b);
+
+ QScopedPointer<QObject> bInstance(b->create());
+ QQuickRectangle *bRectangle = qobject_cast<QQuickRectangle *>(bInstance.data());
+ QVERIFY(bRectangle);
+ QCOMPARE(bRectangle->color(), QColor::fromString("green"_L1));
+}
+
QTEST_MAIN(tst_qmltc)
diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h
index 926081f6d2..e9de54776b 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.h
+++ b/tests/auto/qml/qmltc/tst_qmltc.h
@@ -107,4 +107,6 @@ private slots:
void signalConnections();
void hpp();
+
+ void attachedComponentProperty();
};
diff --git a/tools/qmltc/qmltcvisitor.cpp b/tools/qmltc/qmltcvisitor.cpp
index c9f2cf2640..d0148a3fa9 100644
--- a/tools/qmltc/qmltcvisitor.cpp
+++ b/tools/qmltc/qmltcvisitor.cpp
@@ -318,11 +318,11 @@ void QmltcVisitor::endVisit(QQmlJS::AST::UiProgram *program)
return;
QHash<QQmlJSScope::ConstPtr, QList<QQmlJSMetaPropertyBinding>> bindings;
- for (const QQmlJSScope::ConstPtr &type : std::as_const(m_qmlTypes)) {
- if (isOrUnderComponent(type))
- continue;
+
+ // Yes, we want absolutely all bindings in the document.
+ // Not only the ones immediately assigned to QML types.
+ for (const QQmlJSScope::ConstPtr &type : std::as_const(m_scopesByIrLocation))
bindings.insert(type, type->ownPropertyBindingsInQmlIROrder());
- }
postVisitResolve(bindings);
setupAliases();
@@ -346,8 +346,10 @@ QQmlJSScope::ConstPtr fetchType(const QQmlJSMetaPropertyBinding &binding)
return binding.interceptorType();
case QQmlSA::BindingType::ValueSource:
return binding.valueSourceType();
- // TODO: AttachedProperty and GroupProperty are not supported yet,
- // but have to also be acknowledged here
+ case QQmlSA::BindingType::AttachedProperty:
+ return binding.attachingType();
+ case QQmlSA::BindingType::GroupProperty:
+ return binding.groupType();
default:
return {};
}