From 983941da65adda5e674ac2c2d90de55c93fda50f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mill=C3=A1n=20Soto?= Date: Fri, 3 Jun 2011 20:44:37 +0200 Subject: [PATCH] Check validator when changing text using accessibility functions. Reviewed-by: Frederik Gladhorn (cherry picked from commit 731d843b52b0a0bc387c50c2af37a71f87804f4d) Change-Id: Ieef71cea5b44f288f2f95a0765ec0b3f6d47c042 Reviewed-on: http://codereview.qt.nokia.com/3037 Reviewed-by: Qt Sanity Bot Reviewed-by: Frederik Gladhorn --- src/plugins/accessible/widgets/simplewidgets.cpp | 9 ++++++++- tests/auto/qaccessibility/tst_qaccessibility.cpp | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/plugins/accessible/widgets/simplewidgets.cpp b/src/plugins/accessible/widgets/simplewidgets.cpp index 5730b4d896..47a41b67bf 100644 --- a/src/plugins/accessible/widgets/simplewidgets.cpp +++ b/src/plugins/accessible/widgets/simplewidgets.cpp @@ -710,7 +710,14 @@ void QAccessibleLineEdit::setText(Text t, int control, const QString &text) QAccessibleWidgetEx::setText(t, control, text); return; } - lineEdit()->setText(text); + + QString newText = text; + if (lineEdit()->validator()) { + int pos = 0; + if (lineEdit()->validator()->validate(newText, pos) != QValidator::Acceptable) + return; + } + lineEdit()->setText(newText); } /*! \reimp */ diff --git a/tests/auto/qaccessibility/tst_qaccessibility.cpp b/tests/auto/qaccessibility/tst_qaccessibility.cpp index 1d99cc1dc5..d8aa382548 100644 --- a/tests/auto/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/qaccessibility/tst_qaccessibility.cpp @@ -2098,6 +2098,12 @@ void tst_QAccessibility::lineEditTest() QTestAccessibility::clearEvents(); le2->setFocus(Qt::TabFocusReason); QTRY_VERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(le2, 0, QAccessible::Focus))); + + le->setText(QLatin1String("500")); + le->setValidator(new QIntValidator()); + iface->setText(QAccessible::Value, 0, QLatin1String("This text is not a number")); + QCOMPARE(le->text(), QLatin1String("500")); + delete iface; delete le; delete le2;