Best approach to create "virtual QFileSystemModel"?
-
I want a QTreeView that displays a "virtual file system hierarchy" that consists of disjoint subtrees from the actual file system brought together as branches in a new tree. I would think the right approach would be to make a subclass of QAbstractItemModel or QStandardItemModel and have that class own a collection of QFileSystemModels. It would need to create an index by querying the proper subtree model and returning that.
So far, my simple attempts to do that have failed. I'm not too familiar with how Items and Indexes work. I am hoping that there is a clever, simple way to do this, but I haven't hit upon it yet.
I would appreciate some suggestions as to which base classes to use as a foundation, and how best to do the conversion between internal indexes and the ones my VirtualFileSystemModel will be providing. Should I be using a QAbstractProxyModel?
I looked around but haven't seen an example that does this.
-
@notsofast said in Best approach to create "virtual QFileSystemModel"?:
Should I be using a QAbstractProxyModel?
Quite possibly. Though
QFileSystemModel
itself is sub-classsable alternatively.There was also a recent https://forum.qt.io/topic/98736/how-subclass-qfilesystemmodel, see how the OP says he solved it (shame didn't provide more detail!).
-
Hi and welcome to devnet,
You would likely need to have one QFileSystemModel by path you want to explore and then a proxy model to show the "top level" view.
KDE provides several classes that might help here. Thinking about KModelIndexProxyMapper.
-
@JonB said in Best approach to create "virtual QFileSystemModel"?:
Quite possibly. Though QFileSystemModel itself is sub-classsable alternatively.
I don't see how subclassing QFileSystemModel will let me insert virtual nodes at the top of the tree and have other QFileSystemModels as branches lower in the tree.
Thanks for the pointer to the example. I'll study it some more, but so far it's still eluding me how to manage the top of the tree but delegate things back to the QFileSystemModels lower in the tree. I'm trying to create a VirtualFileSystemNode that can hold a pathname or a QFileSystem model as its data, but no success yet.