Just in case somebody search for the same stuff again
here is my solution:
int count = 0;
int rowCount = model->rowCount(index);
count += rowCount;
for (int r = 0; r < rowCount; ++r)
count += rowsBelowIndex(model->index(r, 0, index));
return count;
}
int count = 0;
if (index.isValid()) {
count = (index.row()) + calculateRow(index.parent());
if (parent.isValid()) {
++count;
for (int r = 0; r < index.row(); ++r)
count += rowsBelowIndex(parent.child(r, 0));
}
}
return count;
}
return calculateRow(index);
}
int rowsBelowIndex(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 += rowsBelowIndex(model->index(r, 0, index));
return count;
}
int calculateRow(const QModelIndex & index) {
int count = 0;
if (index.isValid()) {
count = (index.row()) + calculateRow(index.parent());
const QModelIndex parent = index.parent();
if (parent.isValid()) {
++count;
for (int r = 0; r < index.row(); ++r)
count += rowsBelowIndex(parent.child(r, 0));
}
}
return count;
}
int indexOfItem(QTreeWidgetItem* item) {
QModelIndex index = indexFromItem(item);
return calculateRow(index);
}
To copy to clipboard, switch view to plain text mode
Bookmarks