PDA

View Full Version : Need advice regarding hierarchy view



high_flyer
8th July 2008, 15:10
Hi,

I need to implement a widget that shows a hierarchy in the manner shown in the attached image.
Those of you who know, it is very similar to the way that KProfiler shows the profiling graph.
My question is, which base class should I use?
In a way its exactly like a treeview, only the graphical representation is different (and there is no way to collapse/ expand), so I am thinking to subclass QAbstractItemView, but would like to hear (read) your opinions, may be you know a better class, or a better way.

Thanks in advance.

caduel
8th July 2008, 15:18
depends:
* would you like (or do you have) to interface to a QAbstractItemModel? a (bit of a) problem. QGraphicsView does not work with models out of the box; the QAbstractItemViews present don't do what you want.
* you could implement a custom view

no model needed:
* do you want to interact with that hierarchy? take a look at QGraphicsView
* just a read-only view of data that does not change anymore after displaying? then a simple QWidget with a custom paint() implementation might be enough

So, tell us more about your requirements, please.

high_flyer
8th July 2008, 15:57
depends:
* would you like (or do you have) to interface to a QAbstractItemModel?
Now that you asked, yes I do.
Namely, I want to be able to receive a model, say, a model of a tree view, and display it in the way seen in the attached image (previous post).
This alone probably will force me to use/derive QAbstractItemModel.


a (bit of a) problem. QGraphicsView does not work with models out of the box;
No, it wont be a QGraphicsView thing, just "plain" widgets.
All though, now that I think of it, I need to weigh the advantages/disadvantages of QGraphicsView for this.


the QAbstractItemViews present don't do what you want.
There is no Qt class that is doing what I want, but I am looking for base class that will fit the best.
As far as I see it, my widget and treeview only differ in the graphical presentation, and since QTreeView is derived from QAbstractItemModel, I thought it might be good for me too.


* you could implement a custom view
This is certain, but I am looking for good base class to manage my data



no model needed:
* do you want to interact with that hierarchy? take a look at QGraphicsView
I will, but I have the feeling it is an over kill for what I need, but I'll see.


* just a read-only view of data that does not change anymore after displaying? then a simple QWidget with a custom paint() implementation might be enough
No, this will not be enough in my case, since I have real objects and drag/drop, and doing all of that in custom painting is not the way.


So, tell us more about your requirements, please.
Well actually you helped quite a bit with your suggestion and questions.
What I really needed was a to push to "jog" my gray cells a bit :-)

Thanks.

wysota
8th July 2008, 19:04
Hi Dani,

I would go for a custom view. You'll have problems with defining/using visualRect() and working with selections as different items don't occupy disjoint rectangles so the problem is how to implement indexAt() - I guess the most trivial approach is to return the deepest item colliding with a point. If you decide what's best for you, the rest should be easy.

An alternative would be to use graphics view as suggested. The advantage is that it is easy to group items this way using parent-child relationship and the fact that child items are always in front of their parents, so you'd always pick the deepest item out of the box without any additional effort. Unfortunately apart from that and the fact that GV allows to operate on graphics easily I don't see any advantages of using graphics view. And a certain disadvantage is that it is not trivial to display the same hierarchy using a different view (like a real tree or a table). With the model-view approach, you'd have that for free.

high_flyer
9th July 2008, 09:42
Thanks for the input guys.
I will have to see what I do, I think I can't get away from experimenting.

Cheers.