I implemented a lazily populated tree by doing a subclass of QAbstractItemModel. The implementation looks something like this:
https://gist.github.com/gnufied/db9c4d805e2bb24d8c23
(I do not embed inline code to communicate with messages)
This is basically a tree view of hierarchical data stored in a table. Now I want users to be able to sort rows based on columns. Where the columns are: “count” or “reference count”. These values are integers.
The implementation itself works until I type QSortFilterProxyModel and I start getting a lot of blank lines in the view. The tough problem is that this only happens when I have a lot of lines (like thousands or so).
Code for implementing a sorting proxy:
rootItem = RBKit::SqlConnectionPool::getInstance()->rootOfSnapshot(snapShotVersion); model = new RBKit::HeapDataModel(rootItem, this); proxyModel = new SortObjectProxyModel(this); proxyModel->setSourceModel(model); ui->treeView->setModel(proxyModel); ui->treeView->setSortingEnabled(true);
I have a QSortFilterProxyModel subclass class and the implementation of the subclass is very simple:
https://gist.github.com/gnufied/115f1a4fae3538534511
The documentation says -
"This simple proxy mechanism may need to be redefined for source models with more complex behavior, for example, if the source model provides a custom implementation of hasChildren (), you should also specify it in the proxy model."
But also, I’m not sure what I’m missing.
source share