PDA

View Full Version : MVC - canFetchMore() is not working as expected



prasad_N
8th October 2015, 18:33
I have implemented customized model for lazily loading data, so I have reimplemented canfetchMore() & fetchMore().

- they are working fine for root item, when i scroll down these functions are getting called and I am loading data & population it.
- But in case of child's its not working as expected (may be my understanding is wrong). I have many rows (more than million) child's for the top level items, so I decided to load them also on demand or lazily. but canFetchMore() is calling only one time when I expand the item (when I expand the item i am reading top 100 immediate child's and inserting them, so that entire view is full with these child's & then when I scroll down my expectation is canFetchMore() should be called with parent as that child to which i inserted 100 child's but once i insert 100/some items into that item canFetchMore() is not calling until I collapse & expand it again.)
because of this I am not able to fetch more/remaining child's & insert them.

In one line: canfetchMore() is calling only when expand the item, Its not getting called when I expand & insert few items and then scroll down.

Is this bug ? or Can i manage this in some other way. ???

wysota
8th October 2015, 23:01
It's a bug that ended up being a feature. It is theoretically possible to use the model the way you want (which seems reasonable) but Qt's QTreeView implementation does not offer such functionality.

prasad_N
9th October 2015, 04:22
It's a bug that ended up being a feature..
Strange feature, did somebody report this bug already ? (or can i report this as bug ?).


It is theoretically possible to use the model the way you want
Could you please let me know one way (more if possible :-) ) to handle this situation.

prasad_N
9th October 2015, 20:28
I tried to get the last element with the help of view geometry while scrolling, But It did not work at all.


scroolingDown(int val)
{
QModelIndex index = itemAt(rect().bottomLeft());
}


any other suggestions/way to achieve this ??

prasad_N
10th October 2015, 22:16
Any help or suggestions from Qt experts please ??

prasad_N
12th October 2015, 16:57
I did in the way I am not supposed to do.

in data() function I am checking If it is last child Of a valid parent item(non root item) & This parent still have some items than I am fetching some more data and inserting.

I know this is the stupid way as I am fetching & inserting data in data() function & I should not do it here, But did this at this point of of time nothing flashes in my mind.
May be I need to go through QTreeView source code to get some pointers to work on this feature.

wysota
13th October 2015, 11:41
Strange feature, did somebody report this bug already ? (or can i report this as bug ?).
Feel free to do that.


Could you please let me know one way (more if possible :-) ) to handle this situation.

You would have to reimplement the view to do it properly. You have to detect a situation where the view is scrolled to a point where the last populated item is visible on a certain level and then ask the model to update itself.