Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Best approach to create "virtual QFileSystemModel"?
QtWS25 Last Chance

Best approach to create "virtual QFileSystemModel"?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qfilesystemmode
5 Posts 4 Posters 895 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    notsofast
    wrote on 3 Mar 2020, 22:13 last edited by
    #1

    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.

    J 1 Reply Last reply 3 Mar 2020, 22:41
    0
    • N notsofast
      3 Mar 2020, 22:13

      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.

      J Offline
      J Offline
      JonB
      wrote on 3 Mar 2020, 22:41 last edited by
      #2

      @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!).

      N 1 Reply Last reply 4 Mar 2020, 23:37
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 4 Mar 2020, 20:04 last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        3
        • J JonB
          3 Mar 2020, 22:41

          @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!).

          N Offline
          N Offline
          notsofast
          wrote on 4 Mar 2020, 23:37 last edited by
          #4

          @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.

          P 1 Reply Last reply 14 Dec 2022, 06:56
          0
          • N notsofast
            4 Mar 2020, 23:37

            @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.

            P Offline
            P Offline
            PaNi
            wrote on 14 Dec 2022, 06:56 last edited by
            #5

            @notsofast I'm facing the same problem, so can I ask if you solved it?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved