From 37bafaf0688dfdc75d12273fab85c5ef8087b526 Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Mon, 9 Sep 2024 13:24:47 +0200 Subject: [PATCH] a11y: Remember QTreeView's a11y child interfaces In the same way that QAccessibleTable::child already does, also make use of the childToId hash in QAccessibleTree::child to remember and reuse previously created child interfaces instead of creating new ones for the same index every time the method gets called. When items in the tree view change, QTreeViewPrivate::updateAccessibility already sends a QAccessibleTableModelChangeEvent event of type QAccessibleTableModelChangeEvent::ModelReset, which ensures that the then outdated cache is cleared in the base class's QAccessibleTable::modelChange method. This addresses an old FIXME comment added in 2013 commit b2ec0da95641d9cec006fa9699e6d082ad35db0b and fixes the issue reported in QTBUG-128558. Fixes: QTBUG-128558 Change-Id: Ia2a518ac26f3c9b9ba8ab1870bb656c8e9014a77 Reviewed-by: Volker Hilsheimer (cherry picked from commit 3cfabf92b09290f71b7fafa79723dc374b807206) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 77b8cd0a45507a7efb62eb2fd615b9645ae9e4c1) --- src/widgets/accessible/itemviews.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/widgets/accessible/itemviews.cpp b/src/widgets/accessible/itemviews.cpp index 3ed4adebd83..b23ff42511e 100644 --- a/src/widgets/accessible/itemviews.cpp +++ b/src/widgets/accessible/itemviews.cpp @@ -860,6 +860,10 @@ QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const if (logicalIndex < 0 || !theModel || !theModel->columnCount(rootIndex)) return nullptr; + auto id = childToId.constFind(logicalIndex); + if (id != childToId.constEnd()) + return QAccessible::accessibleInterface(id.value()); + QAccessibleInterface *iface = nullptr; int index = logicalIndex; @@ -879,7 +883,7 @@ QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const iface = new QAccessibleTableCell(view(), modelIndex, cellRole()); } QAccessible::registerAccessibleInterface(iface); - // ### FIXME: get interfaces from the cache instead of re-creating them + childToId.insert(logicalIndex, QAccessible::uniqueId(iface)); return iface; } @@ -931,7 +935,7 @@ QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const Q_ASSERT(treeView); int logicalIndex = treeView->d_func()->accessibleTable2Index(index); - return child(logicalIndex); // FIXME ### new QAccessibleTableCell(view(), index, cellRole()); + return child(logicalIndex); } QString QAccessibleTree::rowDescription(int) const