From 1189ebff320b8dd03637947c92df6e3ef84a3c06 Mon Sep 17 00:00:00 2001 From: Pekka Vuorela Date: Wed, 5 Oct 2011 14:39:57 +0300 Subject: [PATCH] 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 Reviewed-by: Joona Petrell Reviewed-by: Lars Knoll --- src/widgets/widgets/qwidgetlinecontrol.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/widgets/widgets/qwidgetlinecontrol.cpp b/src/widgets/widgets/qwidgetlinecontrol.cpp index ded325a121..c04671b710 100644 --- a/src/widgets/widgets/qwidgetlinecontrol.cpp +++ b/src/widgets/widgets/qwidgetlinecontrol.cpp @@ -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();