summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew den Exter <andrew.den-exter@nokia.com>2011-07-25 16:58:46 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 11:02:16 +0200
commit4f59b5b5308011fdc4bb08bc179d5298077fd9ad (patch)
tree524fb6b07d89c5ecc4c76cbe27c365e077d70ebc
parenta7860d8bf18d1330718fd0dfdc694c92ec69f069 (diff)
Emit selectionChanged signals when input method alters selection.
Mark the selection as dirty if an input method event contains a selection and emit selectionChanged() if it's not emitted by finishChange(). Task-number: QTBUG-19731 Change-Id: Ief6f06f40071f64dae4db0ba365676c059a39c7e Reviewed-on: http://codereview.qt.nokia.com/2081 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
-rw-r--r--src/gui/widgets/qlinecontrol.cpp17
-rw-r--r--tests/auto/qlineedit/tst_qlineedit.cpp24
2 files changed, 36 insertions, 5 deletions
diff --git a/src/gui/widgets/qlinecontrol.cpp b/src/gui/widgets/qlinecontrol.cpp
index 550b5cf947..59374466d6 100644
--- a/src/gui/widgets/qlinecontrol.cpp
+++ b/src/gui/widgets/qlinecontrol.cpp
@@ -494,6 +494,7 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
if (m_selend < m_selstart) {
qSwap(m_selstart, m_selend);
}
+ m_selDirty = true;
} else {
m_selstart = m_selend = 0;
}
@@ -525,12 +526,18 @@ void QLineControl::processInputMethodEvent(QInputMethodEvent *event)
}
m_textLayout.setAdditionalFormats(formats);
updateDisplayText(/*force*/ true);
- if (cursorPositionChanged)
- emitCursorPositionChanged();
- else if (m_preeditCursor != oldPreeditCursor)
- emit updateMicroFocus();
- if (isGettingInput)
+ if (isGettingInput) {
finishChange(priorState);
+ } else {
+ if (cursorPositionChanged)
+ emitCursorPositionChanged();
+ else if (m_preeditCursor != oldPreeditCursor)
+ emit updateMicroFocus();
+ if (m_selDirty) {
+ m_selDirty = false;
+ emit selectionChanged();
+ }
+ }
}
/*!
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp
index 72b402f69d..68e88a87ed 100644
--- a/tests/auto/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/qlineedit/tst_qlineedit.cpp
@@ -290,6 +290,7 @@ private slots:
void bidiLogicalMovement();
void selectAndCursorPosition();
+ void inputMethodSelection();
protected slots:
void editingFinished();
@@ -3883,5 +3884,28 @@ void tst_QLineEdit::selectAndCursorPosition()
QCOMPARE(testWidget->cursorPosition(), 0);
}
+void tst_QLineEdit::inputMethodSelection()
+{
+ testWidget->setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.");
+ testWidget->setSelection(0,0);
+ QSignalSpy selectionSpy(testWidget, SIGNAL(selectionChanged()));
+
+ QCOMPARE(selectionSpy.count(), 0);
+ QCOMPARE(testWidget->selectionStart(), -1);
+
+ testWidget->setSelection(0,5);
+
+ QCOMPARE(selectionSpy.count(), 1);
+ QCOMPARE(testWidget->selectionStart(), 0);
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 12, 5, QVariant());
+ QInputMethodEvent event("", attributes);
+ QApplication::sendEvent(testWidget, &event);
+
+ QCOMPARE(selectionSpy.count(), 2);
+ QCOMPARE(testWidget->selectionStart(), 12);
+}
+
QTEST_MAIN(tst_QLineEdit)
#include "tst_qlineedit.moc"