Fixed QLineEdit to emit selectionChanged
authorPekka Vuorela <pekka.ta.vuorela@nokia.com>
Wed, 21 Mar 2012 14:23:33 +0000 (16:23 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 22 Mar 2012 23:41:38 +0000 (00:41 +0100)
Was not emitted when removed by input method event.

Change-Id: Ia2c0dcb09d42826188d4612f4c1705a41874a31d
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
src/widgets/widgets/qwidgetlinecontrol.cpp
tests/auto/widgets/widgets/qlineedit/tst_qlineedit.cpp

index 7d97f6d..ca30c7e 100644 (file)
@@ -552,6 +552,8 @@ void QWidgetLineControl::processInputMethodEvent(QInputMethodEvent *event)
                 }
                 selectionChange = true;
             } else {
+                if (m_selstart != m_selend)
+                    selectionChange = true;
                 m_selstart = m_selend = 0;
             }
             cursorPositionChanged = true;
index 81dc940..f67f7ce 100644 (file)
@@ -3846,13 +3846,26 @@ void tst_QLineEdit::inputMethodSelection()
     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);
+    // selection gained
+    {
+        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);
+
+    // selection removed
+    {
+        QList<QInputMethodEvent::Attribute> attributes;
+        attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant());
+        QInputMethodEvent event("", attributes);
+        QApplication::sendEvent(testWidget, &event);
+    }
+
+    QCOMPARE(selectionSpy.count(), 3);
 }
 
 void tst_QLineEdit::inputMethodTentativeCommit()