Instantiator: don't interfere with delegates that assign parents
[ChangeLog][QtQml][Instantiator] Instantiator now avoids re-assigning a delegate object's parent to itself if it was already set; thus, you can now declare a parent assignment. Task-number: QTBUG-64546 Task-number: QTBUG-84730 Change-Id: I7d95fa76e71c363b4cb5b7a512c2e984488c8af4 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
cd5d62e999
commit
8326ff2ac1
|
@ -83,13 +83,10 @@ Rectangle {
|
||||||
z: 10000
|
z: 10000
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
||||||
// TODO use Instantiator to create these... but we need to be able to set their parents to glassPane somehow (QTBUG-64546)
|
Instantiator {
|
||||||
TouchpointFeedbackSprite { }
|
model: 10
|
||||||
TouchpointFeedbackSprite { }
|
delegate: TouchpointFeedbackSprite { parent: glassPane }
|
||||||
TouchpointFeedbackSprite { }
|
}
|
||||||
TouchpointFeedbackSprite { }
|
|
||||||
TouchpointFeedbackSprite { }
|
|
||||||
TouchpointFeedbackSprite { }
|
|
||||||
|
|
||||||
MouseFeedbackSprite { }
|
MouseFeedbackSprite { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,6 +128,7 @@ void QQmlInstantiatorPrivate::_q_createdItem(int idx, QObject* item)
|
||||||
return;
|
return;
|
||||||
if (requestedIndex != idx) // Asynchronous creation, reference the object
|
if (requestedIndex != idx) // Asynchronous creation, reference the object
|
||||||
(void)instanceModel->object(idx);
|
(void)instanceModel->object(idx);
|
||||||
|
if (!item->parent())
|
||||||
item->setParent(q);
|
item->setParent(q);
|
||||||
if (objects.size() < idx + 1) {
|
if (objects.size() < idx + 1) {
|
||||||
int modelCount = instanceModel->count();
|
int modelCount = instanceModel->count();
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Item {
|
||||||
|
id: root
|
||||||
|
Instantiator {
|
||||||
|
model: 2
|
||||||
|
delegate: PointHandler {
|
||||||
|
objectName: "pointHandler"
|
||||||
|
parent: root
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -56,6 +56,8 @@ private slots:
|
||||||
|
|
||||||
void asynchronous_data();
|
void asynchronous_data();
|
||||||
void asynchronous();
|
void asynchronous();
|
||||||
|
|
||||||
|
void handlerWithParent();
|
||||||
};
|
};
|
||||||
|
|
||||||
tst_qqmlinstantiator::tst_qqmlinstantiator()
|
tst_qqmlinstantiator::tst_qqmlinstantiator()
|
||||||
|
@ -276,6 +278,19 @@ void tst_qqmlinstantiator::asynchronous()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_qqmlinstantiator::handlerWithParent()
|
||||||
|
{
|
||||||
|
QQmlEngine engine;
|
||||||
|
QQmlComponent component(&engine, testFileUrl("handlerWithParent.qml"));
|
||||||
|
QObject *rootObject = component.create();
|
||||||
|
QVERIFY(rootObject != nullptr);
|
||||||
|
const auto handlers = rootObject->findChildren<QObject *>("pointHandler");
|
||||||
|
QCOMPARE(handlers.count(), 2);
|
||||||
|
for (const auto *h : handlers) {
|
||||||
|
QCOMPARE(h->parent(), rootObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_qqmlinstantiator)
|
QTEST_MAIN(tst_qqmlinstantiator)
|
||||||
|
|
||||||
#include "tst_qqmlinstantiator.moc"
|
#include "tst_qqmlinstantiator.moc"
|
||||||
|
|
Loading…
Reference in New Issue