Results 1 to 19 of 19

Thread: 2 subclasses of QSortFilterProxyModel behind each other.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: 2 subclasses of QSortFilterProxyModel behind each other.

    Quote Originally Posted by Santosh Reddy View Post
    createIndex() is protected, how can we call it on sourceModel()?
    As I already said, QIdentityProxyModel is declared friend of QAbstractItemModel so it can call its private methods.

    Can you give a sample implementation of mapToSouce() and mapFromSource() of the proxy (to add a column) when using QIdentityProxyModel as base class,
    It depends on where you want to add the column. If at the end then the default implementation of mapFromSource() is fine and mapToSource() needs to be adjusted to return an invalid index for the artificial column.

    if you say one does not need to implement these, then how can QIdentityProxyModel know about the extra column and there indexes?
    mapFromSource() and mapToSource() don't deal with accessing artificial columns. For that you have to reimplement index() and data().

    By the way, a problem with making a proxy derived from QAbstractItemModel and not QAbstractProxyModel (or its subclass) is that you lose the possibility of going up the chain of proxy models to reach the final model with a single loop, like so:

    Qt Code:
    1. QModelIndex idx = view->currentIndex();
    2. const QAbstractProxyModel *proxy = 0;
    3. while(proxy = qobject_cast<const QAbstractProxyModel*>(idx.model())) {
    4. idx = proxy->mapToSource(idx);
    5. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 29th May 2013 at 19:42.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 12th October 2012, 23:42
  2. Creating signals in subclasses
    By Cotlone in forum Newbie
    Replies: 2
    Last Post: 22nd June 2010, 01:16
  3. Why slots in QThread subclasses are unsafe?
    By AlphaWolf in forum Qt Programming
    Replies: 8
    Last Post: 30th May 2010, 16:39
  4. Error creating subclasses
    By agerlach in forum Qt Programming
    Replies: 2
    Last Post: 25th May 2010, 14:49
  5. declaring subclasses in C++
    By Paat in forum Newbie
    Replies: 4
    Last Post: 23rd October 2009, 09:40

Tags for this Thread

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.