I have a list of Product objects ( as rows ), each object has several data fields ( like product id, product family, etc ) - as columns. I managed to create a table model subclassing QAbstractTableModel, and display the datas in a QTableView.
What i want is provide a "grouped" view of the model in a tree-like structure. For example I want to group the products by their family id, so the tree should contain in the first level the groups ( family id ) and their childs are the product's having that family id.
Any ideas?
PS: The need of multiple groupings ( group by family id, and group them by another column, and so on ) shows me that the model should be a tree. The root nodes indicates the groups, and then the childs are the group members. The multiple grouping can be achieved by multi-level trees.
Then my transformed question is the following: How can I implement a special QTableView class that displays only the tree's leafs ( at a given level )? ( Because actually leafs are the real objects we would like to see in a grid )
I can use setRootIndex in the tableview, but it doesn't solve anything, other leafs are not displayed.
I was digging a little bit, and found that in QTableView::paintEvent, when displaying each row and column, the actual item is fetched like :
const QModelIndex index = d->model->index(row, col, d->root);
where d->root() is the root node given by setRootIndex(). This should be embedded in a tree-traversal code, and everything would be fine. But how could I avoid to reimplement the whole paintEvent method ?