Results 1 to 6 of 6

Thread: SortFilterProxyModel data

  1. #1
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question SortFilterProxyModel data

    Hi I cant think of a way how to get the whole rows of QSortFilterProxyModel...
    The thing is...I need to get to the values of the "data storage" for that model...
    Ill explain:
    I have a model that has a list of objects...objectList...
    then this model is is set as a source model of mentioned ProxyModel...
    I need to get to actual items of objectList when I have indexes of ProxyModel...
    Is there any way how to do that ??
    Problem is that I need to get the whole row of view that has this ProxyModel set...
    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: SortFilterProxyModel data

    Make the source model return those "actual objects" for a custom role.
    J-P Nurmi

  3. #3
    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: SortFilterProxyModel data

    You can call data() on ProxyModel to get each item in the row or you can map the model index to source model index and access the source model directly.

  4. #4
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SortFilterProxyModel data

    if anyone was interested...heres my code storing those data...yes it could be written better way...but it solves the problem

    Qt Code:
    1. QTextStream out(&file);
    2. for(int row=0; row<filterModel->rowCount();row++){
    3. QModelIndex index0 = filterModel->index(row, 0);
    4. QModelIndex sourceIndex0 = filterModel->mapToSource(index0);
    5. out << sourceIndex0.data().toInt()<<"\t";
    6. QModelIndex index1 = filterModel->index(row, 1);
    7. QModelIndex sourceIndex1 = filterModel->mapToSource(index1);
    8. out << sourceIndex1.data().toInt()<<"\t";
    9. QModelIndex index2 = filterModel->index(row, 2);
    10. QModelIndex sourceIndex2 = filterModel->mapToSource(index2);
    11. out << sourceIndex2.data().toString()<<"\t"<<endl;
    12. }
    To copy to clipboard, switch view to plain text mode 

    although it assumes that model has 3 columns...
    Last edited by gyre; 5th December 2007 at 20:50. Reason: updated contents

  5. #5
    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: SortFilterProxyModel data

    This should be enough:
    Qt Code:
    1. QTextStream out( &file );
    2. for( int row=0; row < filterModel->rowCount(); ++row ) {
    3. QModelIndex index0 = filterModel->index( row, 0 );
    4. QModelIndex index1 = filterModel->index( row, 1 );
    5. QModelIndex index2 = filterModel->index( row, 2 );
    6. out << index0.data().toInt() << "\t";
    7. out << index1.data().toInt() << "\t";
    8. out << index2.data().toString() << endl;
    9. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Sep 2007
    Posts
    99
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: SortFilterProxyModel data

    Quote Originally Posted by jacek View Post
    This should be enough:
    Qt Code:
    1. QTextStream out( &file );
    2. for( int row=0; row < filterModel->rowCount(); ++row ) {
    3. QModelIndex index0 = filterModel->index( row, 0 );
    4. QModelIndex index1 = filterModel->index( row, 1 );
    5. QModelIndex index2 = filterModel->index( row, 2 );
    6. out << index0.data().toInt() << "\t";
    7. out << index1.data().toInt() << "\t";
    8. out << index2.data().toString() << endl;
    9. }
    To copy to clipboard, switch view to plain text mode 
    nice...thats definitely programmatically better man...thanks

Similar Threads

  1. Replies: 4
    Last Post: 19th October 2007, 19:47
  2. Data model
    By steg90 in forum Qt Programming
    Replies: 3
    Last Post: 17th September 2007, 12:14
  3. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  4. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.