[Development] QSortFilterProxyModel: recursiveFilteringEnabled

Richard Gustavsen Richard.Gustavsen at qt.io
Thu Sep 21 13:36:30 CEST 2023


You basically want top flatten a tree model into a list (or table) model, and then remove the rows that have children, and then sort the list. Note that sorting such a list of leafs would be different from how QSFPM works today, where it sorts the children of each parent node locally, without taking grandchildren or siblings into account. If the model was converted to a flat list, all the leafs would have to be sorted together. I, at least, would be very uneasy about changing QSFPM this way.

IMHO, a think flattening a tree model into a table / list model is better done in a separate proxy model (*). And then your app could just wrap this model inside a QSFPM.

(*) We do in fact have such a proxy model in QML today; qtdeclarative/src/qmlmodels/qqmltreemodeltotablemodel.cpp, used by TreeView. It could perhaps have been made public, if this is need is found to be common enough.

-Richard

> On 20 Sep 2023, at 20:31, László Papp <lpappyt at gmail.com> wrote:
> 
> Yes, I have tried that, thanks.
> 
> bool TableProxyModel::filterAcceptsRow(int sourceRow,
>                                        const QModelIndex &sourceParent) const
> {
>   QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
>   CustomModelItem* item = static_cast<CustomModelItem*>(index.internalPointer());
>   return !item->childCount();
> }
> 
> The problem is the property. It is mixing two different things, so it does not suffice when one only needs one of those.
> 
> If you filter without recursiveFilteringEnabled enabled (default, false), then it will only filter through the root node(s). So, you would not be able to filter in the children.
> 
> If you set recursiveFilteringEnabled to true, then it will filter through the children, but then it will also include the parents of those children.
> 
> So, what we need is being able to filter through children (i.e. recursive filtering), but without showing the parents.
> 
> Does that make sense?
> -- 
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development



More information about the Development mailing list