From 8bd40fef0733a4796a308b3bc137a05296e142c4 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Wed, 12 Oct 2011 11:08:00 +0300 Subject: Support tentative commit string with input method. Tentative commit string allows input method to notify editor what is expected to be committed in the place of preedit. This commit adds such support in QLineEdit. Change-Id: If855619bc6843652db0d6254f7e7063bb8ad0936 Reviewed-by: Lars Knoll --- .../widgets/widgets/qlineedit/tst_qlineedit.cpp | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp index 841fbbd955..0804f1241c 100644 --- a/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp @@ -279,6 +279,7 @@ private slots: void selectAndCursorPosition(); void inputMethodSelection(); + void inputMethodTentativeCommit(); protected slots: void editingFinished(); @@ -3831,5 +3832,30 @@ void tst_QLineEdit::inputMethodSelection() QCOMPARE(testWidget->selectionStart(), 12); } +void tst_QLineEdit::inputMethodTentativeCommit() +{ + // test that basic tentative commit gets to text property on preedit state + QList attributes; + QInputMethodEvent event("test", attributes); + event.setTentativeCommitString("test"); + QApplication::sendEvent(testWidget, &event); + QCOMPARE(testWidget->text(), QString("test")); + + // tentative commit not allowed present in surrounding text + QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText); + QApplication::sendEvent(testWidget, &queryEvent); + QCOMPARE(queryEvent.value(Qt::ImSurroundingText).toString(), QString("")); + + // if text with tentative commit does not validate, not allowed to be part of text property + testWidget->setText(""); // ensure input state is reset + QValidator *validator = new QIntValidator(0, 100); + testWidget->setValidator(validator); + QApplication::sendEvent(testWidget, &event); + QCOMPARE(testWidget->text(), QString("")); + testWidget->setValidator(0); + delete validator; +} + + QTEST_MAIN(tst_QLineEdit) #include "tst_qlineedit.moc" -- cgit v1.2.3