Remove tentative commit from editors
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Wed, 29 Feb 2012 16:43:50 +0000 (18:43 +0200)
committerQt by Nokia <qt-info@nokia.com>
Mon, 26 Mar 2012 08:36:31 +0000 (10:36 +0200)
Feature to be reimplemented simplified. Now using new
FocusAboutToChange event for using input method to commit stuff when
window is losing focus.

Change-Id: I81c96c36d9f0a1b38adb4324f3b892c33547cb50
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
src/quick/items/qquickcanvas.cpp
src/quick/items/qquicktextcontrol.cpp
src/quick/items/qquicktextcontrol_p_p.h
src/quick/items/qquicktextinput.cpp
src/quick/items/qquicktextinput_p_p.h
tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp

index 3a9820d..c9d7813 100644 (file)
@@ -532,7 +532,7 @@ void QQuickCanvasPrivate::setFocusInScope(QQuickItem *scope, QQuickItem *item, F
 
         if (oldActiveFocusItem) {
 #ifndef QT_NO_IM
-            qApp->inputMethod()->reset();
+            qApp->inputMethod()->commit();
 #endif
 
             activeFocusItem = 0;
@@ -628,7 +628,7 @@ void QQuickCanvasPrivate::clearFocusInScope(QQuickItem *scope, QQuickItem *item,
         Q_ASSERT(oldActiveFocusItem);
 
 #ifndef QT_NO_IM
-        qApp->inputMethod()->reset();
+        qApp->inputMethod()->commit();
 #endif
 
         activeFocusItem = 0;
@@ -994,6 +994,10 @@ bool QQuickCanvas::event(QEvent *e)
     case QEvent::WindowDeactivate:
         rootItem()->windowDeactivateEvent();
         break;
+    case QEvent::FocusAboutToChange:
+        if (d->activeFocusItem)
+            qGuiApp->inputMethod()->commit();
+        break;
     default:
         break;
     }
index 1846d03..eefe938 100644 (file)
@@ -1459,7 +1459,6 @@ void QQuickTextControlPrivate::inputMethodEvent(QInputMethodEvent *e)
         }
     }
     layout->setAdditionalFormats(overrides);
-    tentativeCommit = e->tentativeCommitString();
 
     cursor.endEditBlock();
 
@@ -1503,7 +1502,6 @@ void QQuickTextControlPrivate::focusEvent(QFocusEvent *e)
     if (e->gotFocus()) {
         setBlinkingCursorEnabled(interactionFlags & (Qt::TextEditable | Qt::TextSelectableByKeyboard));
     } else {
-        commitPreedit();
         setBlinkingCursorEnabled(false);
 
         if (cursorIsFocusIndicator
@@ -1732,14 +1730,12 @@ void QQuickTextControlPrivate::commitPreedit()
     if (!isPreediting())
         return;
 
-    cursor.beginEditBlock();
-    qApp->inputMethod()->reset();
+    qApp->inputMethod()->commit();
 
-    if (!tentativeCommit.isEmpty()) {
-        cursor.insertText(tentativeCommit);
-        tentativeCommit.clear();
-    }
+    if (!isPreediting())
+        return;
 
+    cursor.beginEditBlock();
     preeditCursor = 0;
     QTextBlock block = cursor.block();
     QTextLayout *layout = block.layout();
@@ -1767,17 +1763,12 @@ Qt::TextInteractionFlags QQuickTextControl::textInteractionFlags() const
 
 QString QQuickTextControl::toPlainText() const
 {
-    Q_D(const QQuickTextControl);
-    QString plainText = document()->toPlainText();
-    if (!d->tentativeCommit.isEmpty())
-        plainText.insert(textCursor().position(), d->tentativeCommit);
-    return plainText;
+    return document()->toPlainText();
 }
 
 #ifndef QT_NO_TEXTHTMLPARSER
 QString QQuickTextControl::toHtml() const
 {
-    // note: currently not including tentative commit
     return document()->toHtml();
 }
 #endif
index 9d776ce..c5a39cc 100644 (file)
@@ -137,7 +137,6 @@ public:
     QTextCursor cursor;
     QTextCursor selectedWordOnDoubleClick;
     QTextCursor selectedBlockOnTrippleClick;
-    QString tentativeCommit;
     QString highlightedAnchor; // Anchor below cursor
     QString anchorOnMousePress;
     QString linkToCopy;
index 94856b6..f2da67b 100644 (file)
@@ -119,8 +119,6 @@ QString QQuickTextInput::text() const
     Q_D(const QQuickTextInput);
 
     QString content = d->m_text;
-    if (!d->m_tentativeCommit.isEmpty())
-        content.insert(d->m_cursor, d->m_tentativeCommit);
     QString res = d->m_maskData ? d->stripString(content) : content;
     return (res.isNull() ? QString::fromLatin1("") : res);
 }
@@ -132,7 +130,6 @@ void QQuickTextInput::setText(const QString &s)
         return;
     if (d->composeMode())
         qApp->inputMethod()->reset();
-    d->m_tentativeCommit.clear();
     d->internalSetText(s, -1, false);
 }
 
@@ -2496,7 +2493,6 @@ void QQuickTextInput::itemChange(ItemChange change, const ItemChangeData &value)
         }
 
         if (!hasFocus) {
-            d->commitPreedit();
             if (!d->persistentSelection)
                 d->deselect();
             disconnect(qApp->inputMethod(), SIGNAL(inputDirectionChanged(Qt::LayoutDirection)),
@@ -2831,21 +2827,16 @@ void QQuickTextInputPrivate::paste(QClipboard::Mode clipboardMode)
 
 /*!
     \internal
-
-    Exits preedit mode and commits parts marked as tentative commit
 */
 void QQuickTextInputPrivate::commitPreedit()
 {
     if (!composeMode())
         return;
 
-    qApp->inputMethod()->reset();
+    qApp->inputMethod()->commit();
 
-    if (!m_tentativeCommit.isEmpty()) {
-        internalInsert(m_tentativeCommit);
-        m_tentativeCommit.clear();
-        finishChange(-1, true/*not used, not documented*/, false);
-    }
+    if (!composeMode())
+        return;
 
     m_preeditCursor = 0;
     m_textLayout.setPreeditArea(-1, QString());
@@ -3160,14 +3151,7 @@ void QQuickTextInputPrivate::processInputMethodEvent(QInputMethodEvent *event)
         q->updateCursorRectangle();
     }
 
-    bool tentativeCommitChanged = m_tentativeCommit != event->tentativeCommitString();
-
-    if (tentativeCommitChanged) {
-        m_textDirty = true;
-        m_tentativeCommit = event->tentativeCommitString();
-    }
-
-    if (isGettingInput || tentativeCommitChanged)
+    if (isGettingInput)
         finishChange(priorState);
 
     if (selectionChange) {
@@ -3237,15 +3221,6 @@ bool QQuickTextInputPrivate::finishChange(int validateFromState, bool update, bo
                     return true;
                 }
                 m_cursor = cursorCopy;
-
-                if (!m_tentativeCommit.isEmpty()) {
-                    textCopy.insert(m_cursor, m_tentativeCommit);
-                    bool validInput = m_validator->validate(textCopy, cursorCopy) != QValidator::Invalid;
-                    if (!validInput)
-                        m_tentativeCommit.clear();
-                }
-            } else {
-                m_tentativeCommit.clear();
             }
         }
 #endif
index 165155a..3bd34b2 100644 (file)
@@ -188,7 +188,6 @@ public:
     QString m_text;
     QString m_inputMask;
     QString m_cancelText;
-    QString m_tentativeCommit;
     QFont font;
     QFont sourceFont;
 
index 83e7e78..ab21f3b 100644 (file)
@@ -2287,16 +2287,6 @@ void tst_qquicktextedit::textInput()
     QQuickTextEditPrivate *editPrivate = static_cast<QQuickTextEditPrivate*>(QQuickItemPrivate::get(edit));
     QCOMPARE(editPrivate->text, QString("Hello world!"));
 
-    // test that tentative commit is included in text property
-    edit->setText("");
-    spy.clear();
-    QList<QInputMethodEvent::Attribute> attributes;
-    QInputMethodEvent event2("preedit", attributes);
-    event2.setTentativeCommitString("string");
-    QGuiApplication::sendEvent(qGuiApp->focusObject(), &event2);
-    QCOMPARE(spy.count(), 1);
-    QCOMPARE(edit->text(), QString("string"));
-
     QInputMethodQueryEvent queryEvent(Qt::ImEnabled);
     QGuiApplication::sendEvent(qGuiApp->focusObject(), &queryEvent);
     QCOMPARE(queryEvent.value(Qt::ImEnabled).toBool(), true);
index afe102a..1c8bff9 100644 (file)
@@ -2022,28 +2022,6 @@ void tst_qquicktextinput::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");
-    QGuiApplication::sendEvent(input, &preeditEvent);
-    QCOMPARE(input->text(), QString("test"));
-
-    // tentative commit not allowed present in surrounding text
-    QInputMethodQueryEvent queryEvent(Qt::ImSurroundingText);
-    QGuiApplication::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);
-    QGuiApplication::sendEvent(input, &preeditEvent);
-    QCOMPARE(input->text(), QString(""));
-    input->setValidator(0);
-    delete validator;
-
     // input should reset selection even if replacement parameters are out of bounds
     input->setText("text");
     input->setCursorPosition(0);