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. ProxyModel to filter a Model from an item that is not the root? or subModel from an Item?

ProxyModel to filter a Model from an item that is not the root? or subModel from an Item?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.5k 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.
  • mbruelM Offline
    mbruelM Offline
    mbruel
    wrote on last edited by
    #1

    Hello,
    I'm having one main QStandardItemModel and I would like to filter it via a Proxy but not from the root item of my model.
    For example, let's say my model is this:

    + Project
       + DataSet
           + Type 1 (2 elems)
               + Elem 1_1
               + Elem 1_1
           + Type 2 (1 elem)
               + Elem 2_1
           + Type 3 (1 elem)
              + Elem 3_1
    

    I would like to be able to filter a certain Types but without displaying the Project and DataSet.
    Instead of this:

    + Project
       + DataSet
           + Type 1 (2 elems)
               + Elem 1_1
               + Elem 1_1
           + Type 2 (1 elem)
               + Elem 2_1
    

    I'd like this:

    + Type 1 (2 elems)
        + Elem 1_1
        + Elem 1_1
    + Type 2 (1 elem)
        + Elem 2_1  
    

    Do I have to create a new Model with a subset of main one or could I achieve this with a Proxy?

    Can we have a "sub" model of a QStandardItemModel that uses the same QStandardItem but a different root?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Is the structure of your tree fixed? i.e. will you always filter based by the grand-grand-children of root?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      mbruelM 1 Reply Last reply
      0
      • mbruelM Offline
        mbruelM Offline
        mbruel
        wrote on last edited by
        #3

        Yes kind of, basically I've a main View that can modify the model, just adding / deleting grand-grand-grand children but the root, the first child and the types (grand-grand children) are fixed.

        When I would use the proxy model to show a sub-model as explained, it is for selection only and the Model itself will be fixed during the whole operation.

        1 Reply Last reply
        0
        • VRoninV VRonin

          Is the structure of your tree fixed? i.e. will you always filter based by the grand-grand-children of root?

          mbruelM Offline
          mbruelM Offline
          mbruel
          wrote on last edited by
          #4

          @VRonin
          So do you think I could just use a Proxy or do I have to create a copy of the model without the first 2 root items?

          1 Reply Last reply
          0
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            I thought about it but I can't think of an easy solution at the moment. I added it to my to-do list

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            mbruelM 1 Reply Last reply
            1
            • VRoninV VRonin

              I thought about it but I can't think of an easy solution at the moment. I added it to my to-do list

              mbruelM Offline
              mbruelM Offline
              mbruel
              wrote on last edited by
              #6

              @VRonin
              I've just found a solution playing with the QTreeView.
              Basically, I can just use a proxy to exclude the Items I don't want (Type 3 in my example)
              Then it is in the TreeView that I'll hide the two first item by setting the root item:

              _ui->treeView->setRootIndex(_treeModel->index(0, 0, _treeModel->index(0, 0)));
              

              In fact it is kind of logic that the View could select what part of a Model it wishes to display

              VRoninV 1 Reply Last reply
              0
              • mbruelM mbruel

                @VRonin
                I've just found a solution playing with the QTreeView.
                Basically, I can just use a proxy to exclude the Items I don't want (Type 3 in my example)
                Then it is in the TreeView that I'll hide the two first item by setting the root item:

                _ui->treeView->setRootIndex(_treeModel->index(0, 0, _treeModel->index(0, 0)));
                

                In fact it is kind of logic that the View could select what part of a Model it wishes to display

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by VRonin
                #7

                @mbruel That only works if you only have 1 dataset:

                • Project
                  • DataSet 1
                    • Type 1 (2 elems)
                      • Elem 1_1
                      • Elem 1_2
                    • Type 2 (1 elem)
                      • Elem 2_1
                  • DataSet 2
                    • Type 3 (2 elems)
                      • Elem 3_1
                      • Elem 3_2
                    • Type 4 (1 elem)
                      • Elem 4_1

                Would not work

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                mbruelM 1 Reply Last reply
                0
                • VRoninV VRonin

                  @mbruel That only works if you only have 1 dataset:

                  • Project
                    • DataSet 1
                      • Type 1 (2 elems)
                        • Elem 1_1
                        • Elem 1_2
                      • Type 2 (1 elem)
                        • Elem 2_1
                    • DataSet 2
                      • Type 3 (2 elems)
                        • Elem 3_1
                        • Elem 3_2
                      • Type 4 (1 elem)
                        • Elem 4_1

                  Would not work

                  mbruelM Offline
                  mbruelM Offline
                  mbruel
                  wrote on last edited by
                  #8

                  @VRonin
                  Yep I'd only have one DataSet.
                  I guess if I had several I would want to keep the DataSets in the Tree and just remove the Project so my view would set the root to the index : _ui->treeView->setRootIndex(_treeModel->index(0, 0));

                  I could get something like this if I filter let's say Type2 and Type 4 in the proxy

                  • DataSet 1
                    • Type 1 (2 elems)
                      • Elem 1_1
                      • Elem 1_2
                  • DataSet 2
                    • Type 3 (2 elems)
                      • Elem 3_1
                      • Elem 3_2
                  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