Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    QSortFilterProxyModel and custom hierarchical mode and mapToSource / mapFromSource Implementation

    General and Desktop
    2
    3
    1399
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      prady_80 last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • P
        pritamghanghas last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • P
          prady_80 last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post