Results 1 to 15 of 15

Thread: Proxy model, index mapping.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,330
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Proxy model, index mapping.

    Quote Originally Posted by wysota View Post
    You can't reimplement mapFromSource() and mapToSource() for QSortFilterProxyModel because it needs its own implementation of those methods. Subclass QAbstractProxyModel, do the mapping there and then apply your proxy on a filter proxy model or the other way round.
    So you're saying that if you want to support both sorting -and- source/proxy mapping, you need two layers of proxy model? One to handle the mapping and another handle sorting?

    In my case I have a model with many virtual columns, only a few of which need to be shown in any one table view. In each view, the order of the columns is different. In one view I'd like to support sorting.

    I derived from QSortFilterProxyModel and reimplemented mapToSource / mapFromSource and filterAcceptsColumn. All worked fine until I turned on sorting and clicked a column header. As you state, it blew up because the internal pointer in the proxy was invalid.

    OK, so I need a plain vanilla QSortFilterProxyModel with my filterAcceptsColumn method. The table uses this one. Then I need a QAbstractProxyModel that implements my mapping, and I set this as the source model for the table's proxy. Finally, I set my base model as the source model for the mapping proxy.

    Everything should cascade up and down through the proxy layers between the base model and the view, right?

    Then, what happens with the table's item selection model? Does it need to use the middle proxy instead of the base model as its source?

    Wish this were better documented somewhere. The Qt docs and examples are just too basic.
    Last edited by d_stranz; 21st November 2009 at 22:05. Reason: updated contents

Similar Threads

  1. How to filter duplicates from a proxy model.
    By kaushal_gaurav in forum Qt Programming
    Replies: 6
    Last Post: 14th October 2016, 10:21
  2. Replies: 1
    Last Post: 18th November 2009, 23:21
  3. Replies: 3
    Last Post: 31st March 2008, 21:23
  4. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  5. Model and Proxy
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 21:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.