PDA

View Full Version : Help with ::mapFromSource (Proxy Model Question)



SSurgnier
29th July 2011, 20:58
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:



xPos,yPos,param1,param2,param3
40,42,0.12,0.23,pass
40,43,0.45,0.67,pass
41,44,0.89,1.01,fail


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.



QModelIndex WaferFilterProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
{
QModelIndex waferIndex;
int sourceRow = sourceIndex.row();

// need to get row,col from x,y fields in sourceIndex
// xPos and yPos have been enumerated to 0 and 1 respectively
int row = data(sourceModel()->index(sourceRow, yPos, QModelIndex()));
int col = data(sourceModel()->index(sourceRow, xPos, QModelIndex()));

// not really sure what is the correct way to return the desired index
return waferIndex = index(row, col, QModelIndex());
// or should it be like this
return QModelIndex().model()->index(row, col, QModelIndex());
// or maybe like this
return WaferFilterProxyModel.index(row, col, QModelIndex());
}


-Steven

SSurgnier
1st August 2011, 18:02
Perhaps this is the correct way to return the proxyIndex:


return createIndex(row, col, sourceIndex.internalPointer());