VlJE
13th October 2006, 15:32
Hello! After the sorting of my model (derived from the abstract table model, my own file model) the selection on my table view remains on the (now false) place. The problem: my selection is on the view and my sorting is in the model.
I thought it should work automatically in the view to keep the selection of indexes and not of cells by sorting my model.
What can You recommend?
void FileModel::sort ( int column, Qt::SortOrder order )
{
bool (*compare_funk)(const BUFileInfo &a,const BUFileInfo &b)=0; //point to the compare-function
switch (column)
{
case 0:
compare_funk=(order)?BUFileInfo::biggerName:BUFile Info::lessName;
break;
case 1:
compare_funk=(order)?BUFileInfo::biggerSize:BUFile Info::lessSize;
break;
case 2:
compare_funk=(order)?BUFileInfo::biggerExt:BUFileI nfo::lessExt;
break;
case 3:
compare_funk=(order)?BUFileInfo::biggerDate:BUFile Info::lessDate;
break;
case 4:
compare_funk=(order)?BUFileInfo::biggerState:BUFil eInfo::lessState;
break;
}
if(compare_funk)
{
//std::list<BUFileInfo>::sort(fileList.begin(),fileList.end(),compare_fun k);
qSort(fileList.begin(),fileList.end(),compare_funk );
emit layoutChanged();
}
}
I thought it should work automatically in the view to keep the selection of indexes and not of cells by sorting my model.
What can You recommend?
void FileModel::sort ( int column, Qt::SortOrder order )
{
bool (*compare_funk)(const BUFileInfo &a,const BUFileInfo &b)=0; //point to the compare-function
switch (column)
{
case 0:
compare_funk=(order)?BUFileInfo::biggerName:BUFile Info::lessName;
break;
case 1:
compare_funk=(order)?BUFileInfo::biggerSize:BUFile Info::lessSize;
break;
case 2:
compare_funk=(order)?BUFileInfo::biggerExt:BUFileI nfo::lessExt;
break;
case 3:
compare_funk=(order)?BUFileInfo::biggerDate:BUFile Info::lessDate;
break;
case 4:
compare_funk=(order)?BUFileInfo::biggerState:BUFil eInfo::lessState;
break;
}
if(compare_funk)
{
//std::list<BUFileInfo>::sort(fileList.begin(),fileList.end(),compare_fun k);
qSort(fileList.begin(),fileList.end(),compare_funk );
emit layoutChanged();
}
}