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
|
||||
anchors.fill: parent
|
||||
|
||||
// TODO use Instantiator to create these... but we need to be able to set their parents to glassPane somehow (QTBUG-64546)
|
||||
TouchpointFeedbackSprite { }
|
||||
TouchpointFeedbackSprite { }
|
||||
TouchpointFeedbackSprite { }
|
||||
TouchpointFeedbackSprite { }
|
||||
TouchpointFeedbackSprite { }
|
||||
TouchpointFeedbackSprite { }
|
||||
Instantiator {
|
||||
model: 10
|
||||
delegate: TouchpointFeedbackSprite { parent: glassPane }
|
||||
}
|
||||
|
||||
MouseFeedbackSprite { }
|
||||
}
|
||||
|
|
|
@ -128,7 +128,8 @@ void QQmlInstantiatorPrivate::_q_createdItem(int idx, QObject* item)
|
|||
return;
|
||||
if (requestedIndex != idx) // Asynchronous creation, reference the object
|
||||
(void)instanceModel->object(idx);
|
||||
item->setParent(q);
|
||||
if (!item->parent())
|
||||
item->setParent(q);
|
||||
if (objects.size() < idx + 1) {
|
||||
int modelCount = instanceModel->count();
|
||||
if (objects.capacity() < modelCount)
|
||||
|
|
|
@ -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();
|
||||
|
||||
void handlerWithParent();
|
||||
};
|
||||
|
||||
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)
|
||||
|
||||
#include "tst_qqmlinstantiator.moc"
|
||||
|
|
Loading…
Reference in New Issue