diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-11-26 16:56:00 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-11-27 14:19:13 +0100 |
commit | 956ee62cc24c76569ac49ab209f5f889899c53d6 (patch) | |
tree | a33c1b6a8d97df843bacf0469b378c7233ee21e3 /tests/auto | |
parent | 7811c22f8a18d14b33c04ca00e6b2b6ea5aef8df (diff) |
TextInput: call fixup() when appropriate
[ChangeLog][QtQuick] Fixed TextInput to call fixup() on its validator
when being accepted or losing focus, and the validator reports that the
input is in "intermediate" state ie. the input should be fixed up.
Task-number: QTBUG-35128
Change-Id: I4b15406c584a9647bcf892badfaf6d845868fbf1
Reviewed-by: Liang Qi <liang.qi@digia.com>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 80726720e4..b322e1c576 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -49,6 +49,7 @@ #include <QtQuick/qquickview.h> #include <QtGui/qguiapplication.h> #include <QtGui/qstylehints.h> +#include <QtGui/qvalidator.h> #include <QInputMethod> #include <private/qquicktextinput_p.h> #include <private/qquicktextinput_p_p.h> @@ -226,6 +227,7 @@ private slots: void hasAcceptableInputMask(); void maskCharacter_data(); void maskCharacter(); + void fixup(); private: void simulateKey(QWindow *, int key); @@ -6296,6 +6298,38 @@ void tst_qquicktextinput::maskCharacter() } } +class TestValidator : public QValidator +{ +public: + TestValidator(QObject *parent = 0) : QValidator(parent) { } + + State validate(QString &input, int &) const { return input == QStringLiteral("ok") ? Acceptable : Intermediate; } + void fixup(QString &input) const { input = QStringLiteral("ok"); } +}; + +void tst_qquicktextinput::fixup() +{ + QQuickWindow window; + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + + QQuickTextInput *input = new QQuickTextInput(window.contentItem()); + input->setValidator(new TestValidator(input)); + + // fixup() on accept + input->setFocus(true); + QVERIFY(input->hasActiveFocus()); + QTest::keyClick(&window, Qt::Key_Enter); + QCOMPARE(input->text(), QStringLiteral("ok")); + + // fixup() on defocus + input->setText(QString()); + input->setFocus(false); + QVERIFY(!input->hasActiveFocus()); + QCOMPARE(input->text(), QStringLiteral("ok")); +} + QTEST_MAIN(tst_qquicktextinput) #include "tst_qquicktextinput.moc" |