summaryrefslogtreecommitdiffstats
path: root/tests/auto/other
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2023-08-29 11:47:05 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2023-09-01 18:03:29 +0200
commitc59b34b8cf1c2a087e361d4235990803d89d34ec (patch)
tree9bd0e09474bc0d0179a7ad0b3363c6997eea1608 /tests/auto/other
parentb770b0f8b98a280034b70bfd7e51e29f94ca93b6 (diff)
QAccessible: consistently respect rootIndex of item views
Accessibility implementations rely on correct information about the model dimensions when operating on item views. An item view that has a root index set needs to report it's size based on the root index, rather than for the view's model directly. Pass the rootIndex to all calls to QAbstractItemModel::column/rowCount. Refactor the code to avoid excessive dereferencing of a QPointer, apply const and fix/improve coding style in touched lines. Emit a ModelReset notification when the root index changes, or (in the case of QListView) when the model column changes. Split long Q_ASSERTs into multiple lines to be able to better trace the exact reason for an assertion, and replace the assert with an early return of nil when it's plausible that a cached cell is no longer part of the view (i.e. because the root index changed). Add a test case that verifies that changing the root index changes the dimension of the view as reported through the accessibility interface. Pick-to: 6.6 6.5 Fixes: QTBUG-114423 Change-Id: I7897b79b2e1d10c789cc866b7f5c5dabdabe6770 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'tests/auto/other')
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index 3580e3c844..d63a2dfe08 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -39,6 +39,7 @@
#include <QtTest/private/qtesthelpers_p.h>
using namespace QTestPrivate;
+using namespace Qt::StringLiterals;
static inline bool verifyChild(QWidget *child, QAccessibleInterface *interface,
int index, const QRect &domain)
@@ -213,6 +214,7 @@ private slots:
void listTest();
void treeTest();
void tableTest();
+ void rootIndexView();
void uniqueIdTest();
void calendarWidgetTest();
@@ -3405,6 +3407,51 @@ void tst_QAccessibility::tableTest()
QTestAccessibility::clearEvents();
}
+void tst_QAccessibility::rootIndexView()
+{
+ QStandardItemModel model;
+ for (int i = 0; i < 2; ++i) {
+ QStandardItem *item = new QStandardItem(u"root %1"_s.arg(i));
+ for (int j = 0; j < 5 * (i + 1); ++j) {
+ switch (i) {
+ case 0:
+ item->appendRow(new QStandardItem(u"child0/%1"_s.arg(j)));
+ break;
+ case 1:
+ item->appendRow({new QStandardItem(u"column0 1/%1"_s.arg(j)),
+ new QStandardItem(u"column1 1/%1"_s.arg(j))
+ });
+ break;
+ }
+ }
+ model.appendRow(item);
+ }
+
+ QListView view;
+ view.setModel(&model);
+ QTestAccessibility::clearEvents();
+
+ QAccessibleInterface *accView = QAccessible::queryAccessibleInterface(&view);
+ QVERIFY(accView);
+ QAccessibleTableInterface *accTable = accView->tableInterface();
+ QVERIFY(accTable);
+ QCOMPARE(accTable->rowCount(), 2);
+ QCOMPARE(accTable->columnCount(), 1);
+
+ view.setRootIndex(model.index(0, 0));
+ QAccessibleTableModelChangeEvent resetEvent(&view, QAccessibleTableModelChangeEvent::ModelReset);
+ QVERIFY(QTestAccessibility::containsEvent(&resetEvent));
+
+ QCOMPARE(accTable->rowCount(), 5);
+ QCOMPARE(accTable->columnCount(), 1);
+
+ view.setRootIndex(model.index(1, 0));
+ QCOMPARE(accTable->rowCount(), 10);
+ QCOMPARE(accTable->columnCount(), 2);
+
+ QTestAccessibility::clearEvents();
+}
+
void tst_QAccessibility::uniqueIdTest()
{
// Test that an ID isn't reassigned to another interface right away when an accessible interface