Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Factory for tree view
I currently have a tree model implemented in C++ as an extension of QAbstractItemModel and now I am trying to make a custom view for it. One step that I can see in the process is creating a factory to dynamically figure out which component to use, whether it be a recursive Layout object, or a view specification. Is there any prior work that I could look to for something like this?
Diracsbracket last edited by Diracsbracket
Do you mean something like a
Loadercombination as in:
or possibly simply the loader part of it?
omnitect last edited by omnitect
That looks about right, but also a bit ugly. I'm going to have a lot of possible classes (one for each possible visualization of the data), so it would be better to have a more succinct registration processes that switch case in qml. I'm hoping there is a way to do it in the c++ world. Also, the component needs to be able to instantiate itself recursively and I'm not sure if that one allows for it.
@Diracsbracket Or, since the tree model just provides positioning for real painted items, I wouldn't need the factory to be able to recursively call itself, but I would still like a more elegant way of loading in the elements, unlike in the factory example you gave.
Diracsbracket last edited by
sourceproperty takes a URL, so it is conceivable that you put all those URL's in a list, and retrieve the desired URL using its index?
As for the recursive instantiation, it seems it is not allowed in QML?
Now, it no longer crashes, but generates the following error:
QQmlComponent: Component creation is recursing - aborting
Ok, thanks. So I'll just compute the space each leaf would go into and then use a factory to instantiate the components used. I think I can actually do it from C++ more easily, because I can either create from referencing a resource or by instantiating one of my custom visualization classes.