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. QAbstractProxyModel , mapToSource() and mapFromSource()
Qt 6.11 is out! See what's new in the release blog

QAbstractProxyModel , mapToSource() and mapFromSource()

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 8.7k Views 1 Watching
  • 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.
  • sajis997S Offline
    sajis997S Offline
    sajis997
    wrote on last edited by
    #1

    Hi forum,

    I would like to browse through an example where QAbstractProxyModel is sub-classed and the above mentioned functions are over-ridden. I have checked the examples that come along with the qt installation, but did not find any. Let me know if i miss.

    If any one aware of any open source examples , please refer them to me.

    I really like to have some idea of this concept. I already have tree model shown in the tree view. i would like to create a proxy model that flatten down the source tree model and user the proxy model in the completer to provide user hint.

    Again , it has been quite a while i am stuck with this issue. So please let me know anyone knows anything about this issue!!!!

    Regards
    Sajjad

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      Hi Sajjad,

      what exactly is your problem, I did not get it. I already iomplemented proxy models and have overwritten mapToSource/mapFromSource. It works.

      So can you please give us moire details about your problem?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hmuelner
        wrote on last edited by
        #3

        Like "this":http://qt-project.org/wiki/Proxy_model_example_code ?

        Helmut Mülner

        1 Reply Last reply
        0
        • sajis997S Offline
          sajis997S Offline
          sajis997
          wrote on last edited by
          #4

          Hi

          Please Check the following link:

          !http://www.student.itn.liu.se/~sajis997/nodetree.png(Node Hierarchy tree)!

          As you an see the tree view is loaded. I have another line edit widget which helps the users to find the node using the QCompleter. QCompleter works level by level in the tree view and i want to provide the user with the hint for all levels and i thought about flattening the tree down in the proxy model.

          The manual also sys the if i sub-class the proxy model i must over-ride the following two functions :

          mapToSource() and mapFromSource()

          I am not sure how to over-ride these two functions and specifically, once i say about flattening down i mean that all the tree item will be under QModelIndex(). For the time being, i can browse through my customized tree recursively and print the tree item. I want to re-assign all the tree item under the QModelIndex() - which is the invisible root item. I believe all my requirements will have to be implemented to the above mentioned functions.

          Am i addressing the issue properly ?

          Will be looking forward to more on this issue.

          Thanks
          Sajjad

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            Hi Sajjad,

            I think I got it. The problem you have is, you need a mapping of the flat proxy items to the hierarchical tree items. This is what must be done in mapToSource/mapFromSource.

            If you know, you tree will not be deeper than 4 levels and no level will contain more then 255 elements, you could go something like:

            Each QModelIndex has a custom data (I think an int?)
            This could contain in each byte the index of the corresponding tree item in the level, like:

            Tree item: X3DNode --> 0x01FFFFFF (FF would mean not used!)
            Tree Item: BooleanFilter --> 0x0103FFFF (FF would mean not used!)
            Tree Item: PointNormalClipPane --> 0x010801FF (FF would mean not used!)

            If these restrictions do not work for you, you must find some other mapping that fits.

            mapToSouce is called with a QModelIndex of the proxy and must return a QModelIndex of the source model. You additionaly MUST handle the correct QModelIndex creation.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            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