diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2019-11-18 16:15:01 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2019-11-25 15:34:40 +0100 |
commit | f1f395b37da163bce2dc3b5fc4e298bb4f56a3e7 (patch) | |
tree | 9ce2ba89a86ed754a8ecb8f52181770853e21a08 /tests/auto/qml/qqmlproperty | |
parent | ba494aaa24defe1401f621b791891e696b308756 (diff) | |
parent | 0ee087f5a5edd7d1aa39fd15e0dc85985320c09a (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I48b9c2e4f3a75c18470c55f73f2089dc1401de54
Diffstat (limited to 'tests/auto/qml/qqmlproperty')
-rw-r--r-- | tests/auto/qml/qqmlproperty/data/interfaceBinding.qml | 27 | ||||
-rw-r--r-- | tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 100 |
2 files changed, 127 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml b/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml new file mode 100644 index 0000000000..4e72a75f42 --- /dev/null +++ b/tests/auto/qml/qqmlproperty/data/interfaceBinding.qml @@ -0,0 +1,27 @@ +import QtQuick 2.12 +import io.qt.bugreports 1.0 +Item { + InterfaceConsumer { + objectName: "a1" + i: A { + property int i: 42 + } + } + + InterfaceConsumer { + objectName: "a2" + property A a: A { + property int i: 43 + } + i: a + } + + InterfaceConsumer { + objectName: "a3" + property A a: A { + id : aa + property int i: 44 + } + i: aa + } +} diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 1a5927fa74..f039ccc110 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -40,6 +40,8 @@ #endif #include <QtCore/private/qobject_p.h> #include "../../shared/util.h" +#include "qobject.h" +#include <QtQml/QQmlPropertyMap> #include <QDebug> class MyQmlObject : public QObject @@ -148,6 +150,7 @@ private slots: void readOnlyDynamicProperties(); void aliasToIdWithMatchingQmlFileNameOnCaseInsensitiveFileSystem(); void nullPropertyBinding(); + void interfaceBinding(); void floatToStringPrecision_data(); void floatToStringPrecision(); @@ -155,6 +158,8 @@ private slots: void copy(); void bindingToAlias(); + + void nestedQQmlPropertyMap(); private: QQmlEngine engine; }; @@ -2083,6 +2088,83 @@ void tst_qqmlproperty::nullPropertyBinding() QMetaObject::invokeMethod(root.get(), "tog"); } +struct Interface { +}; + +QT_BEGIN_NAMESPACE +#define MyInterface_iid "io.qt.bugreports.Interface" +Q_DECLARE_INTERFACE(Interface, MyInterface_iid); +QT_END_NAMESPACE + +class A : public QObject, Interface { + Q_OBJECT + Q_INTERFACES(Interface) +}; + +class B : public QObject, Interface { + Q_OBJECT + Q_INTERFACES(Interface) +}; + +class C : public QObject { + Q_OBJECT +}; + +class InterfaceConsumer : public QObject { + Q_OBJECT + Q_PROPERTY(Interface* i READ interface WRITE setInterface NOTIFY interfaceChanged) + Q_PROPERTY(int testValue READ testValue NOTIFY testValueChanged) + + +public: + + Interface* interface() const + { + return m_interface; + } + void setInterface(Interface* interface) + { + QObject* object = reinterpret_cast<QObject*>(interface); + m_testValue = object->property("i").toInt(); + emit testValueChanged(); + if (m_interface == interface) + return; + + m_interface = interface; + emit interfaceChanged(); + } + + int testValue() { + return m_testValue; + } + +signals: + void interfaceChanged(); + void testValueChanged(); + +private: + Interface* m_interface = nullptr; + int m_testValue = 0; +}; +void tst_qqmlproperty::interfaceBinding() +{ + + qmlRegisterInterface<Interface>("Interface"); + qmlRegisterType<A>("io.qt.bugreports", 1, 0, "A"); + qmlRegisterType<B>("io.qt.bugreports", 1, 0, "B"); + qmlRegisterType<C>("io.qt.bugreports", 1, 0, "C"); + qmlRegisterType<InterfaceConsumer>("io.qt.bugreports", 1, 0, "InterfaceConsumer"); + + const QUrl url = testFileUrl("interfaceBinding.qml"); + QQmlEngine engine; + QQmlComponent component(&engine, url); + QScopedPointer<QObject> root(component.create()); + QVERIFY(root); + QCOMPARE(root->findChild<QObject*>("a1")->property("testValue").toInt(), 42); + QCOMPARE(root->findChild<QObject*>("a2")->property("testValue").toInt(), 43); + QCOMPARE(root->findChild<QObject*>("a3")->property("testValue").toInt(), 44); +} + void tst_qqmlproperty::floatToStringPrecision_data() { QTest::addColumn<QString>("propertyName"); @@ -2139,6 +2221,24 @@ void tst_qqmlproperty::bindingToAlias() QVERIFY(!o.isNull()); } +void tst_qqmlproperty::nestedQQmlPropertyMap() +{ + QQmlPropertyMap mainPropertyMap; + QQmlPropertyMap nestedPropertyMap; + QQmlPropertyMap deeplyNestedPropertyMap; + + mainPropertyMap.insert("nesting1", QVariant::fromValue(&nestedPropertyMap)); + nestedPropertyMap.insert("value", 42); + nestedPropertyMap.insert("nesting2", QVariant::fromValue(&deeplyNestedPropertyMap)); + deeplyNestedPropertyMap.insert("value", "success"); + + QQmlProperty value{&mainPropertyMap, "nesting1.value"}; + QCOMPARE(value.read().toInt(), 42); + + QQmlProperty success{&mainPropertyMap, "nesting1.nesting2.value"}; + QCOMPARE(success.read().toString(), QLatin1String("success")); +} + QTEST_MAIN(tst_qqmlproperty) #include "tst_qqmlproperty.moc" |