Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Creating a summary model from QSortFilterProxyModel



  • I have a model based on QAbstractItemModel, and a QSortFilterProxyModel that filters items. I have two views, a table view, and a view that shows a summary of the aggregated data. Assume the model is based on image files, and the summary shows the counts for .jpg files, .png files, and it shows the sum of the sizes of the filtered (shown) items, etc.

    I initially tried to sum up the aggregates in the SortFilterProxyModel::filterAcceptsRow call, however that is a const function, and therefore I cannot update any members in the class, and besides that function may be called several times for the same item, so it turned out not to be a good place to create the sums.

    Next, I overrode SortFilterProxyModel::insertRows. I was hoping that when the proxy accepts and adds a row, that insertRows would be called, but that function is not being called at all.

    I ended up implementing a custom view, and overriding rowsInserted in the view to create my summary.

    Is there a better way of implementing this? Like a mapper proxy model?



  • @ZeroOne said in Creating a summary model from QSortFilterProxyModel:

    Right now, what I am working on is to create a new model for the filter checkboxes, and I am populating items in there by emitting from the QSortFilterProxy model's filterAcceptsRow call

    @ZeroOne For the custom filtering data from the model reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions in the proxy model is the best solution.
    All the data will be populated from the source model only whether the row(item) to be displayed or not decision will be taken based on the filterAcceptsRow() or filterAcceptsColumn() function.

    Refer to the Qt example
    https://doc.qt.io/qt-5/qtwidgets-itemviews-customsortfiltermodel-example.html


  • Lifetime Qt Champion

    Hi,

    Maybe KExtraColumnsProxyModel would provide a simpler solution to create your aggregated data.

    Maybe I misunderstood your issue. How are you creating the aggregated data ?



  • Here is what I am trying to do:

    FilterModel copy.jpg

    The ListView in the center is based on a QSortFilterProxyModel, showing 6840 photos. When the user clicks on a photo, the details of that photo are shown on the right pane. In the screenshot the highlighted photo is of the Hearth Nebula, it was taken using an Ha filter, by an QHY294PROM camera, etc.

    The left pane with the group boxes is a filter, which shows how many of each properies exists. For example this user has 32 photos of the Hearth nebula (in green box), and has 4261 photos of M45, etc. He has 5963 photos taken using the QHY294PROM camera, and 675 photos using the Ha filter. The user can click on any of the checkboxes, and that will update the filter on the QSortFilterProxy model. The ListView will show only the photos matching the selected filter AND the Filter checkboxes update the Counts again, based on the Shown images.

    This is working quite well, except that the logic in the left pane (filter checkboxes) is implemented in the view, and not in any model, which I want to fix.

    Right now, what I am working on is to create a new model for the filter checkboxes, and I am populating items in there by emitting from the QSortFilterProxy model's filterAcceptsRow call. I think there must be a better way.

    By the way, to clarify the size of the data set, the average user has about 50,000 photos, the power user has about 400,000 photos, and I am stress testing the app with 1,000,000 photos.


  • Lifetime Qt Champion

    How do you get all these meta data together ?



  • @ZeroOne said in Creating a summary model from QSortFilterProxyModel:

    Right now, what I am working on is to create a new model for the filter checkboxes, and I am populating items in there by emitting from the QSortFilterProxy model's filterAcceptsRow call

    @ZeroOne For the custom filtering data from the model reimplementing the filterAcceptsRow() and filterAcceptsColumn() functions in the proxy model is the best solution.
    All the data will be populated from the source model only whether the row(item) to be displayed or not decision will be taken based on the filterAcceptsRow() or filterAcceptsColumn() function.

    Refer to the Qt example
    https://doc.qt.io/qt-5/qtwidgets-itemviews-customsortfiltermodel-example.html



  • @nagesh That is what I wanted to do initially, however filterAcceptsRow is a const function, which means I cannot edit member variables. Instead I am emitting a new signal, and handling that in a new model. Marking as solved, since this is the best solution.


Log in to reply