PDA

View Full Version : filterAcceptRows() is being called for all the top level items in the tree.



DURGAPRASAD NEELAM
20th May 2015, 20:04
I have taken editable tree model example for my application and try to implement proxyModel on top of it.
I have re-implemented filterAcceptRows() function, when i apply filter this function is calling for all the top level items.
Is it possible to call this function only for the items which are visible currently in a view & then when I scroll down Apply same filter for newly brought items into view ?

Because i have lots of data from DB (more than 20 lak top level items and child inside them), its taking much time to filter.

Or any suggestions while handling lots of data with filtering capability (I am doing lazy population too & I want my filter to be behave in this way http://www.qtcentre.org/threads/46471-QTreeView-Filter, so when I am actually iterating through all the parent and child items it is taking lots of time).

Thanks in Advance :-)

ChrisW67
20th May 2015, 21:35
Only rows that pass the filter can be visible in the view. The view it has to determine the possibly visible rows from the whole set before it can know the actually visible rows. That determination is done by filterAcceptableRows().

Every time you fetchMore() or otherwise manipulated the data the entire set of fetched rows will be refiltered because that is the only way to know if the changed data has altered what might be visible and therefore what is actually visible. This is is especially true if the view is sorting data but the source data is not sorted.

I would be surprised if the proxy filtered more rows than were currently fetched in the source model. If your source model properly implements canFetchMore() and fetchMore() then i would expect this to just work.

If you have 2 million top level items then you almost certainly should be considering filtering at the time of selection from the database rather than in the in-memory model and view.

DURGAPRASAD NEELAM
21st May 2015, 09:10
The kind of lazy loading I am doing is different here, I am not using a fetchMore concept at all. I have to build a tree based on a particular column data (there are > 50 columns in my Db).
So instead of reading entire data in data base, I am reading single column which will be used to build my tree and when data() function is being called I am reading each cell(item in case of tree) data on demand.

wysota
21st May 2015, 09:35
The kind of lazy loading I am doing is different here, I am not using a fetchMore concept at all.
It doesn't really matter. What matters is what rowCount() returns. The filter proxy will go from 0 to rowCount()-1 rows.

DURGAPRASAD NEELAM
21st May 2015, 10:10
It doesn't really matter. What matters is what rowCount() returns. The filter proxy will go from 0 to rowCount()-1 rows.

yes, I got this point. but what I want is, is there any way to stop it and Apply filter on currently viewing items and then when I move my scroll bar down apply the same filter to this new items.

ChrisW67
21st May 2015, 10:16
The kind of lazy loading I am doing is different here
Yes, you are not lazy loading the top level items, only their children. So you have more than 2 million items loaded into an in-memory model... That it takes some time to filter 2 million records using a brute force approach on un-indexed data through a generic interface is not surprising.

Filtering is the sort of thing that database engines do for a living and you should think about using that.

wysota
21st May 2015, 10:38
yes, I got this point. but what I want is, is there any way to stop it and Apply filter on currently viewing items and then when I move my scroll bar down apply the same filter to this new items.

How would you determine the size of the scrollbar then?

DURGAPRASAD NEELAM
21st May 2015, 11:09
How would you determine the size of the scrollbar then?

I am not sure exactly, but we can get a signal when we move a scroll bar, I thought of doing it by catching that signal.

If it is not possible, You could suggest some other way as well :-)

@ChrisW67 : we have tried by applying filter on data base this is also taking much time, so I am searching for the solution (like lazy loading I want lazy filtering ;) )

wysota
21st May 2015, 13:21
I am not sure exactly, but we can get a signal when we move a scroll bar, I thought of doing it by catching that signal.
Where would you move the scrollbar if you don't know how many entries the model has? If the model filtered only until the view was populated with visible items the scroll bar would think there were no more items available and the scroll bar would not be visible.

DURGAPRASAD NEELAM
21st May 2015, 17:58
1. Is it possible to call this function only for the items which are visible currently in a view & then when I scroll down Apply same filter for newly brought items into view ?

2. If it is not possible, You could suggest some other way as well :-)

wysota
21st May 2015, 18:11
[SIZE=4]
[B] 1. Is it possible to call this function only for the items which are visible currently in a view & then when I scroll down Apply same filter for newly brought items into view ?
Yes. Subclass QAbstractProxyModel and implement your own proxy.