summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Weghorn <[email protected]>2024-07-16 11:31:58 +0200
committerMichael Weghorn <[email protected]>2024-07-19 07:37:20 +0200
commitfb5e1433055f8c309ed6943078f558b8cd72ddba (patch)
tree0e83cdc1784f51ded33cd2ba39c5569c5f35a776
parentb8b7c58402740204da72e1b1f4ea7321b7bfa540 (diff)
a11y: Don't notify about name/desc/id change if there was none
Return early if the setters are called with the same string as is already set for the accessible name, description or identifier. This avoids sending an event wrongly notifying about a change when there was actually none. Extend the `tst_QAccessibility::accessibleIdentifier` autotest accordingly to test that no event is triggered when setting the same ID again. Thanks to Jan Arve Sæther for suggesting that in the previous change introducing the accessibleIdentifier property. (Implemented in a separate commit as it is a preexisting issue for accessible name and description.) Change-Id: Id3af3f0c4769e93e4970be9db87734df9ef84212 Reviewed-by: Jan Arve Sæther <[email protected]>
-rw-r--r--src/widgets/kernel/qwidget.cpp9
-rw-r--r--tests/auto/other/qaccessibility/tst_qaccessibility.cpp7
2 files changed, 16 insertions, 0 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index afa3438b682..7d8539bcdbc 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -11801,6 +11801,9 @@ QString QWidget::whatsThis() const
void QWidget::setAccessibleName(const QString &name)
{
Q_D(QWidget);
+ if (d->accessibleName == name)
+ return;
+
d->accessibleName = name;
QAccessibleEvent event(this, QAccessible::NameChanged);
QAccessible::updateAccessibility(&event);
@@ -11831,6 +11834,9 @@ QString QWidget::accessibleName() const
void QWidget::setAccessibleDescription(const QString &description)
{
Q_D(QWidget);
+ if (d->accessibleDescription == description)
+ return;
+
d->accessibleDescription = description;
QAccessibleEvent event(this, QAccessible::DescriptionChanged);
QAccessible::updateAccessibility(&event);
@@ -11856,6 +11862,9 @@ QString QWidget::accessibleDescription() const
void QWidget::setAccessibleIdentifier(const QString &identifier)
{
Q_D(QWidget);
+ if (d->accessibleIdentifier == identifier)
+ return;
+
d->accessibleIdentifier = identifier;
QAccessibleEvent event(this, QAccessible::IdentifierChanged);
QAccessible::updateAccessibility(&event);
diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
index 5eb331b9300..09ce243145c 100644
--- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
+++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp
@@ -669,6 +669,13 @@ void tst_QAccessibility::accessibleIdentifier()
QVERIFY(QTestAccessibility::containsEvent(&event));
QCOMPARE(button.accessibleIdentifier(), id);
QCOMPARE(QAccessibleBridgeUtils::accessibleId(accessible), id);
+ QTestAccessibility::clearEvents();
+
+ // verify that no event gets triggered when setting the same ID again
+ button.setAccessibleIdentifier(id);
+ QVERIFY(QTestAccessibility::events().empty());
+ QCOMPARE(button.accessibleIdentifier(), id);
+ QCOMPARE(QAccessibleBridgeUtils::accessibleId(accessible), id);
QTestAccessibility::clearEvents();
}