TextInput elements not to have tentative commit in inputMethodQuery
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Tue, 15 Nov 2011 16:17:29 +0000 (18:17 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 24 Nov 2011 12:50:37 +0000 (13:50 +0100)
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 <joona.t.petrell@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
src/declarative/items/qquicktextinput.cpp
src/qtquick1/graphicsitems/qdeclarativetextinput.cpp
tests/auto/declarative/qquicktextinput/tst_qquicktextinput.cpp
tests/auto/qtquick1/qdeclarativetextinput/tst_qdeclarativetextinput.cpp

index 218a313..c9469ba 100644 (file)
@@ -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());
index 009c72a..04aa06d 100644 (file)
@@ -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:
index 7c794d6..147208e 100644 (file)
@@ -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<QInputMethodEvent::Attribute> 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;
 }
 
 /*
index 38e01eb..c84de12 100644 (file)
@@ -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<QInputMethodEvent::Attribute> 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;
 }