QSortFilterProxyModel and custom hierarchical mode and mapToSource / mapFromSource Implementation



  • This is in general a question from someone who is very new to model view programming.

    From the Qt examples, I have implemented a custom hierarchical model to display in a QTreeView using logic similar to the one used in Simple Tree model example. I want hide certain rows in the tree based on a criteria that I obtain from the Qt::DisplayRole.

    I plan to use a model derived from QSortFilterProxyModel and implement filterAcceptsRow method.
    However I have read on forums that the QAbstractItemModel derived indexes are not compatible with QSortFilterProxyModel Indexes.

    To make them compatible I need to implement mapToSource and mapFromSource methods respectively.
    I have no idea or hint as to what should go in there? How to map parent of proxy to model's proxy or as is the case with children.

    Could someone provide me with a hint or help or any direction???
    Any other functions that I need to implement considering the model in the Qt example???

    Thanks in advance.



  • If you goal is to just filter out some rows, you don't have to reimplement those functions. Those are used only when layout of your proxy is different than your source model, like converting a list model to a table model. If you face any problem let us know.



  • That should not be the case. The Proxy model has its own indexes and during translation from source to proxy it does a std::stablesort. It would really be helpful if you could point me to an example. I may be wrong as I am naive in MV programming. Please let me know.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.