About QAbstractProxyModel::sort(...) method
Hi,
As you know there is method in both QAbstractProxyModel & QAbstractItemModel classes. What I want to know is - what is the first parameter of the sort method. For example;
Code:
myFilterModel->sort(0, Qt::AscendingOrder);
0 refers to column here but according to what? I mean I have custom objects in my data model with various members/fields. How '0' in the sort method associated with my highlighted custom object's field?
Re: About QAbstractProxyModel::sort(...) method
Hi,
not exactly : QAbstractItemModel has the sort method but QAbstractProxyModel has the sort method only by inheritance from QAbtractItemModel ...
AND the docs says :
Quote:
void QAbstractItemModel::sort (int column , Qt::SortOrder order=Qt::AscendingOrder ) [virtual]
Sorts the model by column in the given order.
The base class implementation does nothing.
So, it's up to you to do what you want with the "int column" parameter by reimplementing this method ...
(It would be a good idea that the column parameter refers to the same entity than the one returned by "int QModelIndex::column() const" ...)
Re: About QAbstractProxyModel::sort(...) method
Your model decides which field it maps into which column.
That's what models do: they provide an abstract interface to data. their main job is to define what a row means and what a column means in terms of the data they are working on.
Cheers,
_
Re: About QAbstractProxyModel::sort(...) method
Quote:
Your model decides which field it maps into which column.
That's what models do: they provide an abstract interface to data. their main job is to define what a row means and what a column means in terms of the data they are working on.
Cheers,
You're absolutely right but it would be much better if there is a sort method which takes a Role as a parameter.
Re: About QAbstractProxyModel::sort(...) method
You mean like calling QSortFilterProxyModel::setSortRole() before sorting?
You are, of course, quite welcome to subclass either the model or the proxy to reimplement sort() however you want. The function is virtual for a reason.
Re: About QAbstractProxyModel::sort(...) method
Quote:
Originally Posted by
zgulser
You're absolutely right but it would be much better if there is a sort method which takes a Role as a parameter.
It would still need a column.
The model can use whatever it wants for sorting, the sorting key doesn't even have to be accessible through a role.
Of course the model can always allow to set a sorting role as additional information if a single column can be sorted differently depending on what role one is using.
Cheers,
_