What class of Proxy Model should I pick in the case?
-
hi,
I haveQAbstractItemModel
where I embody tree data structure and I need a proxy model with List data structure.
I need to find suitable proxy model class to be able to- Map Souce model index from Tree to Proxy Model index which converts tree index to List index.
- Filter data by criteria
- Sort data by criteria.
So far I do not understand if
QSortFilterProxyModel
meets this task and is it possible to reimplementQSortFilterProxyModel::mapToSource(const QModelIndex & proxyIndex) const
andQSortFilterProxyModel::mapFromSource(const QModelIndex & sourceIndex) const
and do I have t o reimplement this.
If you have experience with proxy models pls advice me. -
@Kofr
actually in your case you need to reimplement the whole logic by yourself, since you want to merge different data sources and map tree structure to a list structure.
A QSortFitlerProxyModel is rather a 1:1 relation to the source model. So you need to subclass QAbstractProxyModel.
In indexes your model creates you can store an internal pointer to your internal data source which helps you identify the QModelIndex. -
@raven-worx
Shall I reimplementmapSelectionFromSource()
andmapSelectionToSource()
in case of Converting tree to List?
Is it enough to impementat just index mapping methods?
I really spend so much time with Qt documentation. It is unclear. -
@Kofr
mapFromSource() and mapToSource() are enough. The default implementation should depend on these methods only.