Qt World Summit: Register Today!

What class of Proxy Model should I pick in the case?

  • hi,
    I have QAbstractItemModel 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

    1. Map Souce model index from Tree to Proxy Model index which converts tree index to List index.
    2. Filter data by criteria
    3. Sort data by criteria.

    So far I do not understand if QSortFilterProxyModel meets this task and is it possible to reimplement QSortFilterProxyModel::mapToSource(const QModelIndex & proxyIndex) const and QSortFilterProxyModel::mapFromSource(const QModelIndex & sourceIndex) const and do I have t o reimplement this.
    If you have experience with proxy models pls advice me.

  • Moderators

    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 reimplement mapSelectionFromSource() and mapSelectionToSource() 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.

  • Moderators

    mapFromSource() and mapToSource() are enough. The default implementation should depend on these methods only.