[Interest] Depth-first filtering for QAbstractProxyModel

Adam Light aclight at gmail.com
Wed Sep 7 18:56:45 CEST 2016


On Tue, Sep 6, 2016 at 12:20 PM, Thompson, Adam B. <thompsonab at ornl.gov>
wrote:

>
> My question: can anyone provide some tips on how to properly subclass
> QAbstractProxyModel so I can provide some custom depth-first filtering
> capabilities? (Sorting isn’t really necessary at the moment, really just
> filtering.)
>
>
>
Our application does something similar to what you describe. We have
several item types: folders (which may have children), and waves,
variables, and strings, which may not contain children.

Our custom QSortFilterProxyModel class allows sorting and filtering by item
type and/or name. In order to get around the issue you describe, our
filterAcceptsRow method essentially always returns true for items of type
folder. For other item types, we actually test whether the type is
appropriate for the filter settings and whether the name matches the
specified pattern.

This isn't optimal, because it can be difficult to wade through all of the
empty folders displayed in the view, but in most cases the number of
non-folder items greatly outnumbers the number of folder items so the
filtering is still quite useful. It's also very fast since we're not
inspecting all descendants of each item when determining if it should be
filtered out or not.

Adam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160907/815fa345/attachment.html>


More information about the Interest mailing list