Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Creating a summary model from QSortFilterProxyModel
QtWS25 Last Chance

Creating a summary model from QSortFilterProxyModel

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 320 Views
  • 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.
  • Z Offline
    Z Offline
    ZeroOne
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • nageshN Offline
      nageshN Offline
      nagesh
      wrote on last edited by
      #5

      @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

      Z 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • Z Offline
          Z Offline
          ZeroOne
          wrote on last edited by ZeroOne
          #3

          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.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            How do you get all these meta data together ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • nageshN Offline
              nageshN Offline
              nagesh
              wrote on last edited by
              #5

              @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

              Z 1 Reply Last reply
              0
              • nageshN nagesh

                @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

                Z Offline
                Z Offline
                ZeroOne
                wrote on last edited by
                #6

                @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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved