PDA

View Full Version : what parameters to be passes to beginInsertRows() when implementing tree



DURGAPRASAD NEELAM
23rd April 2015, 15:27
I have a doubt with canFetch() and fetchMore() functions. i am implementing tree structure, when i scroll till the end canfetch() will be call and if returns true fetchMore() will be called where we have to fetch the data and insert items into tree.


void model::fetchMore(const QModelIndex& f_parent)
{
//fetch the data needed and create items
beginInsertRows(f_parent, row, lastRow);
endInsertRows();
}

Please let me know In beginInsertRows, what parameters exactly we need to specify, It is confusing me..

I have fetched some data now, where I have 5 child's (previous data has remaining 5 child's) and followed by 10 parents and each parent has 10 child's. (f_parent parent has 5 childs already)

Now I need to insert 5 more children followed by 10 parents.

please let me know, what parameters I need to specify in beginInsertRows() exactly.

beginInsertRows(f_parent,5,f_parent.row()+10); ?
beginInsertRows(f_parent,f_parent.row(),f_parent.r ow()+10); ?
beginInsertRows(f_parent,5,10); ?

Documentation explained more in terms of list only(per this particular function) rather than tree.

wysota
24th April 2015, 13:00
The behavior is the same for both a list and a tree. The difference is that if you want to append child items to an existing parent, you pass this parent's index as the first parameter. When appending items to multiple parents, you need to repeat the beginInsertRows-endInsertRows sequence for each of the parents.

DURGAPRASAD NEELAM
24th April 2015, 14:29
In that case, In the above situation (I have taken hard coded values sorry for that)


//apend 5 childs to the parent
beginInsertRows(f_parent, 5, 9);
endInsertRows();

//then append remaining 10 parents
beginInsertRows(parent index of f_parent, f_parent.row(), f_parent.row()+9);
endInsertRows();


Is that right ??


Thanks.

wysota
24th April 2015, 16:57
No idea what you are doing so I cannot answer that question.

DURGAPRASAD NEELAM
25th April 2015, 10:41
I have already inserted 20 parents each parent has 10 children except last one has 5 child's, in fetchMore() method I have fetched 5 child's (remaining 5 child's for the last parent) and 10 more parents and all 10 parents have 10 child's again.

Now i need to insert 5 child's followed by 10 parents each with 10 child's.



void model::fetchMore(const QModelIndex& f_parent)
{
//fetch the data : I fetched 5 child's followed by 10 parents each with 10 childs

//apend 5 childs to the parent
beginInsertRows(f_parent, 5, 9);
endInsertRows();

//then append remaining 10 parents
beginInsertRows(parent index of f_parent, f_parent.row(), f_parent.row()+9);
endInsertRows();
}

Thanks.

wysota
25th April 2015, 15:27
You need to insert children of what? And parents of what?