Commit f32ae39a authored by Pekka Vuorela's avatar Pekka Vuorela Committed by Qt by Nokia

Remove tentative commit from editors

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: 's avatarAndrew den Exter <andrew.den-exter@nokia.com>
parent 2532c475
......@@ -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;
}
......
......@@ -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
......
......@@ -137,7 +137,6 @@ public:
QTextCursor cursor;
QTextCursor selectedWordOnDoubleClick;
QTextCursor selectedBlockOnTrippleClick;
QString tentativeCommit;
QString highlightedAnchor; // Anchor below cursor
QString anchorOnMousePress;
QString linkToCopy;
......
......@@ -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
......
......@@ -188,7 +188,6 @@ public:
QString m_text;
QString m_inputMask;
QString m_cancelText;
QString m_tentativeCommit;
QFont font;
QFont sourceFont;
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment