Skip to content

Commit

Permalink
a11y: Remember QTreeView's a11y child interfaces
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
michaelweghorn authored and Qt Cherry-pick Bot committed Sep 18, 2024
1 parent 746c1b6 commit 37bafaf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/widgets/accessible/itemviews.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 37bafaf

Please sign in to comment.