diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2016-11-30 09:40:23 +0100 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2016-12-30 17:46:15 +0000 |
commit | 3f6d82715dda8dd06f6bddf2ed89e89640f63a2e (patch) | |
tree | f72bea692402d7774b1e8a38d091db85c103b4e7 /tests/auto/quick/qquicktextinput | |
parent | bb594453f9cb96bf8f2975d4a8aa5379cfc46e23 (diff) |
Add TextInput::textEdited()
[ChangeLog][QtQuick][TextInput] Added textEdited() signal to
distinguish user edits from programmatical text changes.
Change-Id: I1d78499e3e11f9f1cab80ce3b0a6d9f2713219f4
Task-number: QTBUG-57203
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicktextinput')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 1451f8e2fc..67921e1fd0 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -135,6 +135,7 @@ private slots: void signal_accepted(); void signal_editingfinished(); + void signal_textEdited(); void passwordCharacter(); void cursorDelegate_data(); @@ -2441,6 +2442,57 @@ void tst_qquicktextinput::signal_editingfinished() QTRY_COMPARE(editingFinished2Spy.count(), 1); } +void tst_qquicktextinput::signal_textEdited() +{ + QQuickWindow window; + window.show(); + window.requestActivate(); + QTest::qWaitForWindowActive(&window); + + QQuickTextInput *input = new QQuickTextInput(window.contentItem()); + QVERIFY(input); + + QSignalSpy textChangedSpy(input, SIGNAL(textChanged())); + QVERIFY(textChangedSpy.isValid()); + + QSignalSpy textEditedSpy(input, SIGNAL(textEdited())); + QVERIFY(textEditedSpy.isValid()); + + input->forceActiveFocus(); + QTRY_VERIFY(input->hasActiveFocus()); + + int textChanges = 0; + int textEdits = 0; + + QTest::keyClick(&window, Qt::Key_A); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), ++textEdits); + + QTest::keyClick(&window, Qt::Key_B); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), ++textEdits); + + QTest::keyClick(&window, Qt::Key_C); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), ++textEdits); + + QTest::keyClick(&window, Qt::Key_Space); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), ++textEdits); + + QTest::keyClick(&window, Qt::Key_Backspace); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), ++textEdits); + + input->clear(); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), textEdits); + + input->setText("TextInput"); + QCOMPARE(textChangedSpy.count(), ++textChanges); + QCOMPARE(textEditedSpy.count(), textEdits); +} + /* TextInput element should only handle left/right keys until the cursor reaches the extent of the text, then they should ignore the keys. |