Results 1 to 2 of 2

Thread: Help with ::mapFromSource (Proxy Model Question)

  1. #1
    Join Date
    Jul 2011
    Posts
    4
    Qt products
    Qt3
    Platforms
    Windows

    Default Help with ::mapFromSource (Proxy Model Question)

    Hi everyone. Qt Centre newbie here and I hope to be a future contributor. So here it goes:

    My input file is a csv text file. A brief example might look like this:

    Qt Code:
    1. xPos,yPos,param1,param2,param3
    2. 40,42,0.12,0.23,pass
    3. 40,43,0.45,0.67,pass
    4. 41,44,0.89,1.01,fail
    To copy to clipboard, switch view to plain text mode 

    My current high level view of the program is as follows:
    1. Store the csv in QStandardItemModel sourceModel
    2. View the sourceModel with QStandardTableView tableView.
    3. Use QSortFilterProxyModel to do some standard filtering and call it proxyModel
    4. Then subclass either QAbstractProxyModel or QSortFilterProxyModel to make a new filter which would yield waferModel. Where the row,col locations directly map to the yPos,xPos of proxyModel. The DisplayRole of each index of waferModel would be either param1, param2, or param3 (which ever the user has selected from the tableView).
    5. A custom waferView subclassed from QAbstractItemView would then be used to display waferModel.

    I've made decent progress on this project and am comfortable with nearly every step except the following. I'm currently lost on how to create the proxy model that maps yPos,xPos to row,col of the new model. It seems as if it should be fairly easy using ::mapFromSource and ::mapToSource. I suppose the preliminary question is whether or not to use QAbstractProxyModel or QSortFilterProxyModel? The source code below is as far as I got before I feared that I was heading in the completely wrong direction. All help is greatly appreciated.

    Qt Code:
    1. QModelIndex WaferFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
    2. {
    3. QModelIndex waferIndex;
    4. int sourceRow = sourceIndex.row();
    5.  
    6. // need to get row,col from x,y fields in sourceIndex
    7. // xPos and yPos have been enumerated to 0 and 1 respectively
    8. int row = data(sourceModel()->index(sourceRow, yPos, QModelIndex()));
    9. int col = data(sourceModel()->index(sourceRow, xPos, QModelIndex()));
    10.  
    11. // not really sure what is the correct way to return the desired index
    12. return waferIndex = index(row, col, QModelIndex());
    13. // or should it be like this
    14. return QModelIndex().model()->index(row, col, QModelIndex());
    15. // or maybe like this
    16. return WaferFilterProxyModel.index(row, col, QModelIndex());
    17. }
    To copy to clipboard, switch view to plain text mode 

    -Steven
    Last edited by SSurgnier; 30th July 2011 at 02:22.

  2. #2
    Join Date
    Jul 2011
    Posts
    4
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: Help with ::mapFromSource (Proxy Model Question)

    Perhaps this is the correct way to return the proxyIndex:
    Qt Code:
    1. return createIndex(row, col, sourceIndex.internalPointer());
    To copy to clipboard, switch view to plain text mode 
    Last edited by SSurgnier; 1st August 2011 at 23:04.

Similar Threads

  1. Source Model Ad Proxy Model
    By sajis997 in forum Qt Programming
    Replies: 1
    Last Post: 19th July 2011, 06:13
  2. Model/Delegate/Proxy
    By skyline2000 in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2011, 17:13
  3. Custom Model and Proxy Model
    By frank100 in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2010, 15:30
  4. A Totalling Proxy Model?
    By ChrisW67 in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2010, 04:06
  5. Model and Proxy
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 22: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.