From: Pekka Vuorela Date: Tue, 15 Nov 2011 16:17:29 +0000 (+0200) Subject: TextInput elements not to have tentative commit in inputMethodQuery X-Git-Tag: qt-v5.0.0-alpha1~1035 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=38276a3d5348423a222c0fc794a28ab361d97e78;p=profile%2Fivi%2Fqtdeclarative.git TextInput elements not to have tentative commit in inputMethodQuery Tentative commit should not be part of surrounding text, it's already a property of the input method. Change-Id: I64aec9763fb20770b6729f7f59dcbe23cf5a6718 Reviewed-by: Joona Petrell Reviewed-by: Lars Knoll --- diff --git a/src/declarative/items/qquicktextinput.cpp b/src/declarative/items/qquicktextinput.cpp index 218a313..c9469ba 100644 --- a/src/declarative/items/qquicktextinput.cpp +++ b/src/declarative/items/qquicktextinput.cpp @@ -1355,7 +1355,7 @@ QVariant QQuickTextInput::inputMethodQuery(Qt::InputMethodQuery property) const && !d->control->passwordEchoEditing()) { return QVariant(displayText()); } else { - return QVariant(text()); + return QVariant(d->control->realText()); } case Qt::ImCurrentSelection: return QVariant(selectedText()); diff --git a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp index 009c72a..04aa06d 100644 --- a/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp +++ b/src/qtquick1/graphicsitems/qdeclarativetextinput.cpp @@ -1396,7 +1396,7 @@ QVariant QDeclarative1TextInput::inputMethodQuery(Qt::InputMethodQuery property) && !d->control->passwordEchoEditing()) return QVariant(displayText()); else - return QVariant(text()); + return QVariant(d->control->realText()); case Qt::ImCurrentSelection: return QVariant(selectedText()); case Qt::ImMaximumTextLength: diff --git a/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp index 7c794d6..147208e 100644 --- a/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp @@ -1565,6 +1565,28 @@ void tst_qquicktextinput::inputMethods() QGuiApplication::sendEvent(qGuiApp->inputPanel()->inputItem(), &event); QCOMPARE(input->text(), QString("Our Goodbye world!")); QCOMPARE(input->cursorPosition(), 7); + + // test that basic tentative commit gets to text property on preedit state + input->setText(""); + QList attributes; + QInputMethodEvent preeditEvent("test", attributes); + preeditEvent.setTentativeCommitString("test"); + QApplication::sendEvent(input, &preeditEvent); + QCOMPARE(input->text(), QString("test")); + + // tentative commit not allowed present in surrounding text + QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText); + QApplication::sendEvent(input, &queryEvent); + QCOMPARE(queryEvent.value(Qt::ImSurroundingText).toString(), QString("")); + + // if text with tentative commit does not validate, not allowed to be part of text property + input->setText(""); // ensure input state is reset + QValidator *validator = new QIntValidator(0, 100); + input->setValidator(validator); + QApplication::sendEvent(input, &preeditEvent); + QCOMPARE(input->text(), QString("")); + input->setValidator(0); + delete validator; } /* diff --git a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 38e01eb..c84de12 100644 --- a/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1565,6 +1565,28 @@ void tst_qdeclarativetextinput::inputMethods() QCOMPARE(input->text(), QString("Our Goodbye world!")); QCOMPARE(input->cursorPosition(), 7); + // test that basic tentative commit gets to text property on preedit state + input->setText(""); + QList attributes; + QInputMethodEvent preeditEvent("test", attributes); + preeditEvent.setTentativeCommitString("test"); + QApplication::sendEvent(canvas, &preeditEvent); + QCOMPARE(input->text(), QString("test")); + + // tentative commit not allowed present in surrounding text + QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText); + QApplication::sendEvent(canvas, &queryEvent); + QCOMPARE(queryEvent.value(Qt::ImSurroundingText).toString(), QString("")); + + // if text with tentative commit does not validate, not allowed to be part of text property + input->setText(""); // ensure input state is reset + QValidator *validator = new QIntValidator(0, 100); + input->setValidator(validator); + QApplication::sendEvent(canvas, &preeditEvent); + QCOMPARE(input->text(), QString("")); + input->setValidator(0); + delete validator; + delete canvas; }