[Interest] Depth-first filtering for QAbstractProxyModel

Konstantin Tokarev annulen at yandex.ru
Wed Sep 7 14:26:07 CEST 2016



06.09.2016, 22:20, "Thompson, Adam B." <thompsonab at ornl.gov>:
> All,
>
> I co-develop an application that uses a QTreeView to display the hierarchical contents of external files. The contents of the tree can become quite a chore to sift through, so I added a means of filtering via a QSortFilterProxyModel. This works as expected, but the user may want to specify a pattern that matches a node deep in the model’s structure but not any of the node’s ancestors. As such, the breadth-first filtering mechanism provided in QSortFilterProxyModel isn’t appropriate for our needs.
>
> I modified filterAcceptsRow to work in a depth-first manner to verify my desired filtering effect would work, which it does. However, as expected, it yields a huge performance penalty since it performs a depth-first search for each row in the model. This is because the (recursive) depth-first logic is called for the same nodes many times. I added a crude caching scheme which really doesn’t properly mitigate the performance issue.
>
> 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.)


Doing filtering or any other complex operations on model data via QAbstractItemModel API is usually a flawed approach which may hurt you in future even if it works for you now. Data processing should be done inside model implementation (even better, in other class), and model API should be used for presentation purposes only, i.e. by corresponding View.

>
> Thanks,
>
> Adam Thompson
>
> Computer Scientist, Nuclear Engineering
>
> Oak Ridge National Laboratory
>
> +1.865.241.8062
> ,
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest


-- 
Regards,
Konstantin



More information about the Interest mailing list