Skip to content

Commit 37bafaf

Browse files
michaelweghornQt Cherry-pick Bot
authored andcommitted
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 b2ec0da and fixes the issue reported in QTBUG-128558. Fixes: QTBUG-128558 Change-Id: Ia2a518ac26f3c9b9ba8ab1870bb656c8e9014a77 Reviewed-by: Volker Hilsheimer <[email protected]> (cherry picked from commit 3cfabf9) Reviewed-by: Qt Cherry-pick Bot <[email protected]> (cherry picked from commit 77b8cd0)
1 parent 746c1b6 commit 37bafaf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/widgets/accessible/itemviews.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,10 @@ QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const
860860
if (logicalIndex < 0 || !theModel || !theModel->columnCount(rootIndex))
861861
return nullptr;
862862

863+
auto id = childToId.constFind(logicalIndex);
864+
if (id != childToId.constEnd())
865+
return QAccessible::accessibleInterface(id.value());
866+
863867
QAccessibleInterface *iface = nullptr;
864868
int index = logicalIndex;
865869

@@ -879,7 +883,7 @@ QAccessibleInterface *QAccessibleTree::child(int logicalIndex) const
879883
iface = new QAccessibleTableCell(view(), modelIndex, cellRole());
880884
}
881885
QAccessible::registerAccessibleInterface(iface);
882-
// ### FIXME: get interfaces from the cache instead of re-creating them
886+
childToId.insert(logicalIndex, QAccessible::uniqueId(iface));
883887
return iface;
884888
}
885889

@@ -931,7 +935,7 @@ QAccessibleInterface *QAccessibleTree::cellAt(int row, int column) const
931935
Q_ASSERT(treeView);
932936
int logicalIndex = treeView->d_func()->accessibleTable2Index(index);
933937

934-
return child(logicalIndex); // FIXME ### new QAccessibleTableCell(view(), index, cellRole());
938+
return child(logicalIndex);
935939
}
936940

937941
QString QAccessibleTree::rowDescription(int) const

0 commit comments

Comments
 (0)