PDA

View Full Version : hierarchical model in a flat view



gniking
8th June 2006, 11:58
I have a hierarchical model (subclassed QAbstractItemModel) and want to display it in different itemviews. One of these views is a standard QTreeView. For another view I would like to display the hierarchical model as a flat model. With this I mean, I would like to display only leaf items (those that have no children) in either a QTableView or QListView.

Does anyone know how to accomplish this? I do not want to make a new flat model class for this, because I want to use the same model and selection model between all views. I only want to view my hierarchical model as a flat leaf model.

tnx in advance

fullmetalcoder
8th June 2006, 13:11
As far as I understood the docs QAbstractProxyModel, once subclassed and used wisely, should fit your needs...

wysota
8th June 2006, 14:08
As far as I understood the docs QAbstractProxyModel, once subclassed and used wisely, should fit your needs...

Yes, I can confirm that. Subclass it and reimplement pure abstract methods. Just do it wisely, because you have to know all the leaves of the tree upfront. You might have to cache the data from the underlying model and connect to its signals to update the cache when the underlying model changes.

gniking
9th June 2006, 10:31
Yep, subclassing QAbstractProxyModel did the trick. Too bad I can't couple selectionModels anymore, because the models are different now. Now why isn't there a QAbstractProxySelectionModel class :confused: Oh well I guess I'll just have to make one myself.

msopanen
10th November 2009, 20:17
Hi,

I have a similar problem. Can you give any examples how to map tree model nodes for flat view? Simplest way would of course give a root index for a view but I would like to do it in proxy.