PDA

View Full Version : catch Left most down element in QTreeView



prasad_N
12th November 2015, 18:58
Hi, My previous post related to this question is here, , I reported bug also : http://www.qtcentre.org/threads/63911-MVC-canFetchMore()-is-not-working-as-expected?highlight= & Bug Report: https://bugreports.qt.io/browse/QTBUG-48725

Again : I wanted to load data with lazy population for my tree view, But lazy population (canFetchMore() & fetchMore()) doesn't works as expected, this functions are not getting called during scroll down for non root Items. (For non root items this functions are getting called only when collapse & expand not during scroll down). So some how I am finding a way to load data incrementally for non root items also.

So during a scroll I wanted to find left most last (down) tree item, with which i will find whether it has more children or not & then based this I wanted to add children (If it expanded because lazy population works for root item & top level items gets added on fly).

But I really don't have an idea How to find last element while scroll, I tried connecting to scrollBar move signal & them in a slot I tried to find last element something like
ItemAt(viewPort()->rect()->bottomLeft()), But with this approach Items are getting skipped (Not able to find last items If scroll little fast).

Then I tried doing same thing in data() function (I found this is the place where no items get skipped even If I scroll fast), here I am checking each Item (Not exactly, checking only left most items) how many children It has & based on that I am Loading few more children (Lazy population for child items). (But some how I felt this is not a good way, doing some calculations adding children in data() function).

Can somebody help me how to find out the leftmost down element when I am scrolling in view port with what ever the speed. OR any other idea how to do lazy population for children also.

Thanks a lot for reading long post :-)

wysota
20th November 2015, 16:25
Why is speed an issue? Your model can "lag behind" if you scroll too fast but it should work. If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.

prasad_N
21st November 2015, 20:06
If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.

Got the point but, ItemAt(viewPort()->rect()->bottomLeft()) (I put it in the slot connected to vertical scroll bar moved) But it is not able to find the element when i scroll the element too fast, But it is able to find this element when I scroll slowly. I really couldn't get where to put this statement ItemAt(viewPort()->rect()->bottomLeft()) (Or looking for an another way to get the element).

prasad_N
22nd November 2015, 07:43
Why is speed an issue? Your model can "lag behind" if you scroll too fast but it should work. If the last index you loaded children for is e.g. row 100 and the last visible row is 120 then you need to load children for rows 101-120.


misunderstanding might be : I am not talking about top level items they can be load with canFetchMore() & fetchMore(). This functions are not working properly for non top level & root items (Can see my links above).

The prob is, I have 100 top level items loaded in my view, And now I expanded 1st top level item which as 1000 child's, Now what I did I loaded only 500 child's Now my view has Top level 1st item & its child's (hardly 30 to 40 child's) visible. Now if i scroll my view down My idea is to catch 500th child Of 1st top level Item & add remaining 500 child's but I am not able to find it with ItemAt(viewPort()->rect()->bottomLeft()).
When I scroll little fast, this function is not able to find that (basically its not able to find all items which are coming from down entry point, skipping some). & I am using this statement in slot connected to vertical scroll bar moved.

Hopes it clear.

wysota
23rd November 2015, 10:23
Got the point but, ItemAt(viewPort()->rect()->bottomLeft()) (I put it in the slot connected to vertical scroll bar moved) But it is not able to find the element when i scroll the element too fast, But it is able to find this element when I scroll slowly. I really couldn't get where to put this statement ItemAt(viewPort()->rect()->bottomLeft()) (Or looking for an another way to get the element).

So what does itemAt() return if it "isn't able to find the element"?


misunderstanding might be : I am not talking about top level items they can be load with canFetchMore() & fetchMore(). This functions are not working properly for non top level & root items (Can see my links above).

The prob is, I have 100 top level items loaded in my view, And now I expanded 1st top level item which as 1000 child's, Now what I did I loaded only 500 child's Now my view has Top level 1st item & its child's (hardly 30 to 40 child's) visible. Now if i scroll my view down My idea is to catch 500th child Of 1st top level Item & add remaining 500 child's but I am not able to find it with ItemAt(viewPort()->rect()->bottomLeft()).
When I scroll little fast, this function is not able to find that (basically its not able to find all items which are coming from down entry point, skipping some). & I am using this statement in slot connected to vertical scroll bar moved.

If itemAt() returns top-level index with row = 2 and previously you fetched items with parent set to row = 1 then based on that you can deduce you should fetch those missing items from first top-level row.

prasad_N
24th November 2015, 07:24
So what does itemAt() return if it "isn't able to find the element"?

When I scroll down IndexAt() (very sorry It is IndexAt() not ItemAt()) is returning some items randomly (As I scroll down All the items should come into view from down & I thought IndexAt() can recognize all the items, But as I said it is skipping some items & its is happening randomly, there is no particular pattern even).



If itemAt() returns top-level index with row = 2 and previously you fetched items with parent set to row = 1 then based on that you can deduce you should fetch those missing items from first top-level row.



I just attached a result to make clear what is the exact problem. 11537


- In attachement, 20 is child of my 1st top level Item but this has more siblings down which I did not load initially.
- Now when I scroll down I wanted to find this items (which has data as 20) & find out if its more siblings & add them

For that I did some thing like this


QScrollBar* l_vScroll = verticalScrollBar();
if(l_vScroll)
{
connect(l_vScroll, SIGNAL(valueChanged(int)), this, SLOT(verticallScrollBarMoved(int)), Qt::DirectConnection);
}


void TreeView::verticallScrollBarMoved(int f_val)
{
QModelIndex index = this->indexAt(this->viewport()->rect().bottomLeft());

//Now my assumption is as I scroll down in this function index of last child (which has data 20) should get caught (correct me If i am wrong) & with this index I can add more siblings to it

//But here I am not able to get all the indexes which are coming from down when I am scrolling
}

prasad_N
4th December 2015, 12:18
Still looking for the solution....