Ok I've rewrite the test class as my own so I can debug.
Here were the problems for any1 struggling with it too...
int GenericTreeModelGroup::rowCount(const QModelIndex &parent) const {
if (parent.column() > 0) {
return 0;
}
VirtualNode *node = nodeFromIndex(parent);
return node ? node->children.size() : 0;
}
Needed to add
if (parent.column() > 0) {
return 0;
}
So that I don't return row count XX for children at column 1/2/3/4/5.
The second problem was with parent ()
QModelIndex GenericTreeModelGroup::parent(const QModelIndex &child) const {
if (!child.isValid())
return QModelIndex();
VirtualNode *childNode = nodeFromIndex(child);
if (!childNode) {
//|| childNode == mRootNode || !childNode->parent || childNode->parent == mRootNode)
return QModelIndex();
}
VirtualNode *parentNode = childNode->parent;
VirtualNode *grandParent = parentNode->parent;
int row = grandParent ? grandParent->children.indexOf(parentNode) : mRootNode->children.indexOf(parentNode);
if (row == -1) {
return QModelIndex();
}
// Use column 0 for the parent
return createIndex(row, 0, parentNode);
}
If you have a row -1, it means you have "ROOT" item, which should return QModelIndex() and not -1,-1, data QModelIndex of the model.
After these 2 changes, all started to work. Yay!