From a704040dc4dd312e6d0552e6d9e6715f988ea39a Mon Sep 17 00:00:00 2001 From: Jocelyn Turcotte Date: Thu, 15 Jan 2015 16:05:26 +0100 Subject: Avoid an incorrect warning when dynamically parenting a Window "Created graphical object was not placed in the graphics scene." QQuickWindow is the root of a graphics scene and doesn't need to be inside another one. It is already suggested in the Window documentation that Window can be an inline child of a top-level QtObject. This patch fixer the warning when dynamically creating a Window component. Change-Id: Ie6d9d37b9e9ffdb61101aaaad6f4b722216ec759 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp | 79 ++++++++++++++++++---- 1 file changed, 66 insertions(+), 13 deletions(-) (limited to 'tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp') diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index 3e681b1b84..4eb9c2b635 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -105,7 +105,8 @@ private slots: void null(); void loadEmptyUrl(); void qmlCreateWindow(); - void qmlCreateObject(); + void qmlCreateObjectAutoParent_data(); + void qmlCreateObjectAutoParent(); void qmlCreateObjectWithProperties(); void qmlIncubateObject(); void qmlCreateParentReference(); @@ -172,21 +173,73 @@ void tst_qqmlcomponent::qmlCreateWindow() QVERIFY(window); } -void tst_qqmlcomponent::qmlCreateObject() +void tst_qqmlcomponent::qmlCreateObjectAutoParent_data() { - QQmlEngine engine; - QQmlComponent component(&engine, testFileUrl("createObject.qml")); - QObject *object = component.create(); - QVERIFY(object != 0); + QTest::addColumn("testFile"); - QObject *testObject1 = object->property("qobject").value(); - QVERIFY(testObject1); - QVERIFY(testObject1->parent() == object); + QTest::newRow("createObject") << QStringLiteral("createObject.qml"); + QTest::newRow("createQmlObject") << QStringLiteral("createQmlObject.qml"); +} - QObject *testObject2 = object->property("declarativeitem").value(); - QVERIFY(testObject2); - QVERIFY(testObject2->parent() == object); - QCOMPARE(testObject2->metaObject()->className(), "QQuickItem"); + +void tst_qqmlcomponent::qmlCreateObjectAutoParent() +{ + QFETCH(QString, testFile); + + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl(testFile)); + QQuickItem *root = qobject_cast(component.create()); + QVERIFY(root); + QObject *qtobjectParent = root->property("qtobjectParent").value(); + QQuickItem *itemParent = qobject_cast(root->property("itemParent").value()); + QQuickWindow *windowParent = qobject_cast(root->property("windowParent").value()); + QVERIFY(qtobjectParent); + QVERIFY(itemParent); + QVERIFY(windowParent); + + QObject *qtobject_qtobject = root->property("qtobject_qtobject").value(); + QObject *qtobject_item = root->property("qtobject_item").value(); + QObject *qtobject_window = root->property("qtobject_window").value(); + QObject *item_qtobject = root->property("item_qtobject").value(); + QObject *item_item = root->property("item_item").value(); + QObject *item_window = root->property("item_window").value(); + QObject *window_qtobject = root->property("window_qtobject").value(); + QObject *window_item = root->property("window_item").value(); + QObject *window_window = root->property("window_window").value(); + + QVERIFY(qtobject_qtobject); + QVERIFY(qtobject_item); + QVERIFY(qtobject_window); + QVERIFY(item_qtobject); + QVERIFY(item_item); + QVERIFY(item_window); + QVERIFY(window_qtobject); + QVERIFY(window_item); + QVERIFY(window_window); + + QCOMPARE(qtobject_item->metaObject()->className(), "QQuickItem"); + QCOMPARE(qtobject_window->metaObject()->className(), "QQuickWindow"); + QCOMPARE(item_item->metaObject()->className(), "QQuickItem"); + QCOMPARE(item_window->metaObject()->className(), "QQuickWindow"); + QCOMPARE(window_item->metaObject()->className(), "QQuickItem"); + QCOMPARE(window_window->metaObject()->className(), "QQuickWindow"); + + QCOMPARE(qtobject_qtobject->parent(), qtobjectParent); + QCOMPARE(qtobject_item->parent(), qtobjectParent); + QCOMPARE(qtobject_window->parent(), qtobjectParent); + QCOMPARE(item_qtobject->parent(), itemParent); + QCOMPARE(item_item->parent(), itemParent); + QCOMPARE(item_window->parent(), itemParent); + QCOMPARE(window_qtobject->parent(), windowParent); + QCOMPARE(window_item->parent(), windowParent); + QCOMPARE(window_window->parent(), windowParent); + + QCOMPARE(qobject_cast(qtobject_item)->parentItem(), (QQuickItem *)0); + QCOMPARE(qobject_cast(qtobject_window)->transientParent(), (QQuickWindow *)0); + QCOMPARE(qobject_cast(item_item)->parentItem(), itemParent); + QCOMPARE(qobject_cast(item_window)->transientParent(), itemParent->window()); + QCOMPARE(qobject_cast(window_item)->parentItem(), windowParent->contentItem()); + QCOMPARE(qobject_cast(window_window)->transientParent(), windowParent); } void tst_qqmlcomponent::qmlCreateObjectWithProperties() -- cgit v1.2.3