I am currently working on an application that requires the visualization of isolated branches of a massive (hundreds of millions of objects) tree. Since this is a tree, it is very similar to your problem, namely, nested models.
My solution was to make a form of abstraction. Since the tree already exists and is a completely different design layer than the GUI, I use a proxy object that contains a model class that attaches to the rendered node tree. The model is just an adapter for viewing the list for access to basic data.
The model provides the "object" and "type" roles, which the "root" delegates to create the user interface element for the child nodes, and the object role is used to create a proxy for attaching to each child element, so effectively, I get indirectly nested models.
Each delegate is basically a loader (but not a Q20 Loader element) that receives a pointer to each object and its type from model roles, so it creates a proxy for this type, and the user interface element type + ".qml" attached to proxy server as a data source.
I canβt share any code, but I hope you get the picture. This approach sounds a bit complicated, but it offers several huge advantages:
- Qt heavy objects are created only for required objects
- multiple user interface elements can use the same proxy server and model.
- one delegate can create an arbitrary number of completely different user interface elements.
- it works for a tree that has an arbitrary number of different types with different properties, and only two roles are used to achieve this. Each object gets its own unique user interface element, with access to all data of the base object through a proxy. Good luck achieving this with dynamic roles.
- a proxy is also used to inform each user interface about changes in the data of each data element of the base object
dtech source share