Make QLineEdit unit test pass again

Widget failed to update cursor position if selection remained the same, but
changed direction, and did not emit selectionChanged if change resulted
from input method event.

Change-Id: I6a4ae48d41efa5e126980749f89982f92e3ec499
Reviewed-on: http://codereview.qt-project.org/6131
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Joona Petrell <joona.t.petrell@nokia.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
bb10
Pekka Vuorela 2011-10-05 14:39:57 +03:00 committed by Qt by Nokia
parent bb1f50b7b1
commit 1189ebff32
1 changed files with 8 additions and 4 deletions

View File

@ -265,13 +265,13 @@ void QWidgetLineControl::setSelection(int start, int length)
}
if (length > 0) {
if (start == m_selstart && start + length == m_selend)
if (start == m_selstart && start + length == m_selend && m_cursor == m_selend)
return;
m_selstart = start;
m_selend = qMin(start + length, (int)m_text.length());
m_cursor = m_selend;
} else if (length < 0){
if (start == m_selend && start + length == m_selstart)
if (start == m_selend && start + length == m_selstart && m_cursor == m_selstart)
return;
m_selstart = qMax(start + length, 0);
m_selend = start;
@ -434,6 +434,7 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event)
|| event->preeditString() != preeditAreaText()
|| event->replacementLength() > 0;
bool cursorPositionChanged = false;
bool selectionChange = false;
if (isGettingInput) {
// If any text is being input, remove selected text.
@ -477,6 +478,7 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event)
if (m_selend < m_selstart) {
qSwap(m_selstart, m_selend);
}
selectionChange = true;
} else {
m_selstart = m_selend = 0;
}
@ -514,6 +516,8 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event)
emit updateMicroFocus();
if (isGettingInput)
finishChange(priorState);
if (selectionChange)
emit selectionChanged();
}
/*!
@ -601,7 +605,7 @@ void QWidgetLineControl::selectWordAtPos(int cursor)
bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool edited)
{
Q_UNUSED(update)
bool lineDirty = m_selDirty;
if (m_textDirty) {
// do validation
bool wasValidInput = m_validInput;
@ -632,7 +636,7 @@ bool QWidgetLineControl::finishChange(int validateFromState, bool update, bool e
m_textDirty = false;
}
updateDisplayText();
lineDirty |= m_textDirty;
if (m_textDirty) {
m_textDirty = false;
QString actualText = text();