Results 1 to 2 of 2

Thread: Filter Proxy Model to Autoupdate View

  1. #1
    Join Date
    May 2006
    Posts
    28
    Thanks
    8
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Filter Proxy Model to Autoupdate View

    Hi,
    I have subclassed the SortFilterProxyModel to provide custom filtering of data.
    The filtering works but I can't get the View to update with the new filters, until the user clicks on a header to sort.

    Anyone know how to update a view with a Filter Proxy automatically.
    TableView.update() doesnt work for me.
    I have probably miss understood the Model/View Concepts somewhere.
    Or have failed to find right commands in the documentation.

    Any help appreciated!

    EDIT: I got it working, but I'm really not sure if what I'm doing is a bit hackish or not.


    Qt Code:
    1. MySortFilterProxyModel *myProxyModel;
    2.  
    3. MySortFilterProxyModel::MySortFilterProxyModel(QObject *parent)
    4. {
    5. }
    6.  
    7. bool MySortFilterProxyModel::filterAcceptsRow(int sourceRow,
    8. const QModelIndex &sourceParent) const
    9. {
    10. QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent);
    11. QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent);
    12. QModelIndex index3 = sourceModel()->index(sourceRow, 3, sourceParent);
    13. QModelIndex index4 = sourceModel()->index(sourceRow, 4, sourceParent);
    14. QModelIndex index5 = sourceModel()->index(sourceRow, 5, sourceParent);
    15.  
    16. return (sourceModel()->data(index1).toString().contains(filterPlayerWhite)
    17. && sourceModel()->data(index2).toString().contains(filterRankWhite)
    18. && sourceModel()->data(index3).toString().contains(filterPlayerBlack)
    19. && sourceModel()->data(index4).toString().contains(filterRankBlack)
    20. && sourceModel()->data(index5).toString().contains(filterResult));
    21. }
    22.  
    23. connect(filters->lineEditPlayerWhite, SIGNAL(textChanged(const QString &)),
    24. this, SLOT(doFilter()));
    25.  
    26. void MainWindow::doFilter()
    27. {
    28. myProxyModel->filterPlayerWhite = lineEditPlayerWhite->text();
    29. // NEED TO UPDATE VIEW NOW
    30.  
    31. // THESE two lines work, but is it really necessary to setup these connections again. Just to display these filters right now?
    32. myProxyModel->setSourceModel(model);
    33. treeView->setModel(myProxyModel);
    34. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Big Duck; 1st June 2006 at 20:57.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Filter Proxy Model to Autoupdate View

    IMO, you need something like:
    Qt Code:
    1. void MySortFilterProxyModel::setWhitePlayerFilter( const QString& filter )
    2. {
    3. filterPlayerWhite = filter;
    4. QModelIndex topLeft( index( 0, <column> ) );
    5. QModelIndex bottomRight( index( rowCount() - 1, <column> ) );
    6. emit dataChanged( topLeft, bottomRight );
    7. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    Big Duck (2nd June 2006)

Similar Threads

  1. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 14:01
  2. Replies: 6
    Last Post: 20th April 2006, 11:23
  3. Model, view, resize to show all data
    By jcr in forum Qt Programming
    Replies: 2
    Last Post: 17th April 2006, 21:59
  4. Table model / view editing issue
    By Caius Aérobus in forum Qt Programming
    Replies: 9
    Last Post: 7th April 2006, 12:03

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.