From 3f6d82715dda8dd06f6bddf2ed89e89640f63a2e Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 30 Nov 2016 09:40:23 +0100 Subject: 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 Reviewed-by: Shawn Rutledge --- .../quick/qquicktextinput/tst_qquicktextinput.cpp | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'tests/auto/quick/qquicktextinput') 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. -- cgit v1.2.3