PDA

View Full Version : SortFilterProxyModel data



gyre
5th December 2007, 20:03
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

jpn
5th December 2007, 20:08
Make the source model return those "actual objects" for a custom role.

jacek
5th December 2007, 20:16
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.

gyre
5th December 2007, 20:49
if anyone was interested...heres my code storing those data...yes it could be written better way...but it solves the problem :)



QTextStream out(&file);
for(int row=0; row<filterModel->rowCount();row++){
QModelIndex index0 = filterModel->index(row, 0);
QModelIndex sourceIndex0 = filterModel->mapToSource(index0);
out << sourceIndex0.data().toInt()<<"\t";
QModelIndex index1 = filterModel->index(row, 1);
QModelIndex sourceIndex1 = filterModel->mapToSource(index1);
out << sourceIndex1.data().toInt()<<"\t";
QModelIndex index2 = filterModel->index(row, 2);
QModelIndex sourceIndex2 = filterModel->mapToSource(index2);
out << sourceIndex2.data().toString()<<"\t"<<endl;
}


although it assumes that model has 3 columns...

jacek
6th December 2007, 19:19
This should be enough:
QTextStream out( &file );
for( int row=0; row < filterModel->rowCount(); ++row ) {
QModelIndex index0 = filterModel->index( row, 0 );
QModelIndex index1 = filterModel->index( row, 1 );
QModelIndex index2 = filterModel->index( row, 2 );
out << index0.data().toInt() << "\t";
out << index1.data().toInt() << "\t";
out << index2.data().toString() << endl;
}

gyre
6th December 2007, 22:09
This should be enough:
QTextStream out( &file );
for( int row=0; row < filterModel->rowCount(); ++row ) {
QModelIndex index0 = filterModel->index( row, 0 );
QModelIndex index1 = filterModel->index( row, 1 );
QModelIndex index2 = filterModel->index( row, 2 );
out << index0.data().toInt() << "\t";
out << index1.data().toInt() << "\t";
out << index2.data().toString() << endl;
}

nice...thats definitely programmatically better man...thanks