I am writing a C ++ application that uses Qt classes to work with specific data models. For this, I inherited from QAbstractItemModel:
class EventFragment
{
....
private:
qint32 address;
QString memo;
QDateTime dateCreated;
QVector<EventFragment*> _children;
....
};
class EventModel : public QAbstractItemModel
{
Q_OBJECT
public:
explicit EventModel (QObject *parent = 0);
....
private:
EventFragment* _rootFragment;
};
At some point, I needed the sort / filter option in my application, so I also created a class that inherits from QSortFilterProxyModel
class EventProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit EventProxyModel (QObject *parent = 0);
...
public:
virtual bool lessThan ( const QModelIndex & left, const QModelIndex & right ) const;
...
};
To achieve sorting, I used the QSortFilterProxyModel::sort()default method (I did not override it in my proxy model class) and for some time it worked.
At some point, I noticed that the actual method QSortFilterProxyModel::sort()sorts the entire model, and I need to sort only the immediate children of a specific index.
sort() EventModel, , QSortFilterProxyModel::sort() . , , , , .
, QModelIndex, .
- /, ?