Unsolved 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?
-
@omnitect
Do you mean something like aComponent
+Loader
combination as in:
https://forum.qt.io/topic/93180/updating-qabstractitemmodel-model-is-null-although-begin-endresetmodel-have-been-called/4
or possibly simply the loader part of it? -
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.
-
@omnitect
TheLoader
'ssource
property 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?
https://bugreports.qt.io/browse/QTBUG-25439
Now, it no longer crashes, but generates the following error:QQmlComponent: Component creation is recursing - aborting
-
@Diracsbracket
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.