Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5
-
None
Description
When you open multiple levels and then try to collapse a node that is more than one level up the last opened node (but not at the top level). You hit this function:
int QQuickTreeModelAdaptor::lastChildIndex(const QModelIndex &index) { if (!m_expandedItems.contains(index)) return itemIndex(index); QModelIndex parent = index.parent(); QModelIndex nextSiblingIndex; while (parent.isValid()) { nextSiblingIndex = parent.sibling(parent.row() + 1, 0); if (nextSiblingIndex.isValid()) break; parent = parent.parent(); } int firstIndex = nextSiblingIndex.isValid() ? itemIndex(nextSiblingIndex) : m_items.count(); return firstIndex - 1; }
Specifically this line: `nextSiblingIndex = parent.sibling(parent.row() + 1, 0);` has the possibility to request an invalid index (one that is out of range). Since the model adaptor can just call `rowCount` I don't see immediately what is the reason to request an invalid index here.
I would like to throw an exception if an invalid index is requested because I assume Qt code will be careful not to do that so I want to catch any bugs in my own code where I might be requesting an invalid index.