I am dealing with a Qt application in which I would like to retrieve the total number of navigatable rows in a Directory/Filesystem model-like tree. That means if a folder is expanded its count is added, if a folder is collapsed its count is not added. As a whole, I want to be able to retrieve the number of every row that is expanded and available. As far as I could see, there is not such an implementation easy to find online. Two solutions that did not work yet:
int MainWindow::countRowsOfIndex_treeview( const QModelIndex & index )
{
int count = 0;
const QAbstractItemModel* model = index.model();
int rowCount = model->rowCount(index);
count += rowCount;
for( int r = 0; r < rowCount; ++r )
count += countRowsOfIndex_treeview( model->index(r,0,index) );
return count;
}
This is not even close to what I want to achieve as it does not consider the unexpanded folders.
So far, I have been dealing with the one-level row count using:
ui->treeView->model()->rowCount(ui->treeView->currentIndex().parent())
However, this does not count the unexpanded childs and so on. I hope my question is clear. Any help is appreciated. I'm willing to give any more information if requested. Thanks.