QFileSystemModel and QSortFilterProxyModel - root index is not preserved
-
@MasterBLB
Hi
Well you just go there and login with the credentials you use here.
A good read is
https://wiki.qt.io/Reporting_Bugs -
Personally, I didn't. Since you found it, the honour is yours :)
-
Hi
nope, if i had made report, i would have linked url here :)
So please do. -
I don't think it's a bug.
setRootIndex
is a method of the view. The model has no way of knowing (and shouldn't know) what a view is using as root. The filter set on the proxy applies to the whole model. If the index used as root by a view gets filtered out it's only natural for a view to revert to usingQModelIndex()
as root.What you need is a proxy model that implements the
setRootIndex
functionality at the model level. This is on the list of nice-things-I-would-like-to-add-to-Qt-models and it's a fairly easy one to do but I need to find time for it :( -
In the way such behavior breaks SOLID substitute rule - I can't use descendant class QFileSystemModel like it was its base class QAbstractItemModel in QSortFilterProxyModel. While not a 100% bug it's definitely a serious design flaw, and worth to be reported. But where?
-
@MasterBLB said in QFileSystemModel and QSortFilterProxyModel - root index is not preserved:
But where?
In Qt bug tracker https://bugreports.qt.io/secure/Dashboard.jspa
Also you can talk to Qt developers on their mailing list. -
breaks SOLID
It doesn't. In fact, if it worked as you expected it would break SOLID
it's definitely a serious design flaw
Sorry to be brutal: No, it's not a flaw, you just didn't understand the design of model/views.
To help you get a better idea of what is going on, try use the same model with 2 different treeviews. In only one of the view callsetRootIndex
, and then trigger the filtering.