[Qt-interest] How to just show tree model _leaf nodes_ in a table view?

Patricia Santana Cruz patriciasc at openismus.com
Mon Apr 4 13:05:58 CEST 2011


On Mon, 2011-04-04 at 11:17 +0200, Andre Somers wrote:
> You are not telling us anything about your table proxy model. You can do 
> this with a proxy model, and it is in this table proxy model that this 
> should happen.
> 
> A little bit of googling already turned up useful code. I used the 
> keywords 'qt proxy flatten tree' in my search. I have found several 
> implementations you could use as a base for your implementation...
> 
> André

Thank you for your answer André.

My table proxy model is just giving the logic to show in the table view,
the children of the element clicked in the tree view doing the
following:

void WhchTableProxyModel::onItemClicked(const QModelIndex &index)
{
    emit retrieve_children(mapFromSource(index));
}

SOURCE:
https://github.com/Patriciasc/WHCH/blob/TreeModel/src/whchTableProxyModel.cpp#L9

So if we look again at the example I wrote:
--------
 | Root |
 --------
      |
      |__Year1
      |  |
      |  |__Week1
      |  |  |
      |  |  |__Day1
      |  |     |
      |  |     |_Task1
      |  |     |
      |  |     |_Task2
      |  |     |
      |  |     |_Task3
      |  |
      |  |__Week2
      |     |
      |     |__Day1
      |     |  |
      |     |  |_Task1


What happens is:
If I click on Year 1, then Week 1 and Week2 are displayed.
If I click on Week1, then Day 1 is displayed.
If I click on Day 1, then Task1, Task2 and Task3 are displayed.

So it just displays the leaf-nodes for the 'Day' elements, but what I
need is to display the leaf-nodes for 'Year', 'Week' and 'Day' elements,
and not just for the 'Day' elements. That means:

If I click on Year 1, display Task1, Task2, Task 3 and Task1.
If i click on Week 1, display Task1, Task2 and Task3.
If I click on Day1, display Task1, Task2 and Task3.

You said you found some code examples that could help and that I would
have to make some changes in my table proxy model, but I did not find
those examples and do not understand how can I make this happen. Could
you be a little bit more explicit please?. Or paste the link with the
example you saw?

Thank you in advance,
Patricia.

-- 
patriciasc at openismus.com
http://psconboard.blogspot.com/
www.openismus.com




More information about the Qt-interest-old mailing list