Hello,
I have a QStandardItemModel structure that I've set up to be displayed in a tree view. The first item of each record contains several children, with each child having multiple children of it's own.
Thus, the tree structure looks something like:
Top-Level Reccord 1| ----> Record-level list 1
| ----> Record-level list 2
| ----> List-level item 1
| ----> List-level item 2
| ----> Record Level list 3
Top-Level Record 2
Top-Level Record 3
...
It's easiest to think of it as each record having several different lists of information, thus the first-level children described the list name / type, and the second level children are the list items.
What I want to do is create a proxy model that operates *only* on one set of second-level children (a model that manipulates list items directly).
For example, if I have a record with three lists, and I want to create a model that manages the items in the second list, I should be able to write something like:
MyListProxyModel listProxyModel();
listProxyModel.setSourceModel (mainModel);
QModelIndex secondListIndex
= mainModel.
indexFromItem (secondListItem
);
listProxyModel.setRootIndex (secondListIndex);
qDebug() << "The second list has " << listProxyModel.rowCount() << " records...";
MyListProxyModel listProxyModel();
listProxyModel.setSourceModel (mainModel);
QStandardItem secondListItem = mainModel.item(0, 0)->child(1);
QModelIndex secondListIndex = mainModel.indexFromItem (secondListItem);
listProxyModel.setRootIndex (secondListIndex);
qDebug() << "The second list has " << listProxyModel.rowCount() << " records...";
To copy to clipboard, switch view to plain text mode
Output: "The second list has 2 records..." (assuming above example structure).
I can think of a way to implement this in a custom proxy model, but it's not a very appealing approach, and I'd rather not write a custom class to encapsulate this functionality if I don't have to.
Is there a reasonably clean way to go about accomplishing this?
Bookmarks