Hi,
Is there any recommended patters how to handle internal re-parenting of child
items?
I'll open up the scenario with a small example. Let's take imaginary QML
components as Menu and MenuItem (both derived from QML Item). The idea would be
that the application developer would be able to write:
Menu {
id: optionsMenu
MenuItem {...}
MenuItem {...}
MenuItem {...}
}
To populate the menu. Internally the Menu would like to use QML Column element
as middle-man to layout the items as:
*Menu.qml*
Item {
default property alias content: layout.children
Column { id: layout; anchors.fill: parent }
}
This works like magic until someone wants to dynamically add another MenuItem:
var newMenuItem = new MenuItem(optionsMenu) // wrong parent!
or
menuItemComponent.creatObject(optionsMenu) // wrong parent!
This fails miserably and the only way this could be achieved is that the user
of the Menu component would know the internal structure and would be able to
write something nasty.
What would be the recommended pattern?
#1 never change the default property
#2 never mix'n'match static and dynamic allocation of child items
#3 expose middle-man as 'container' property which can be used in dynamic
allocation
#4 provide always functions to add/remove dynamic stuff
#5 re-parent dynamically added children to the middle-man inside the
onChildrenChanged
#6 let the user do the nasty bit - they can make it work if they really want to
#7 something else?
Thanks,
Pekka
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml