From b07f71a53f0dad132169e6d007b7305857400e99 Mon Sep 17 00:00:00 2001 From: Jarkko Koivikko Date: Tue, 31 Jan 2017 22:25:09 +0200 Subject: Widgets: Update micro focus in QLineEdit and friends QLineEdit, QAbstractSpinBox and QComboBox did not notify micro focus changes to the input context. In particular, the updates were missed during pre-edit stage. This change adds the missing bindings to QWidget::updateMicroFocus(). Change-Id: I9a7fff962f46dbabd8fb02836c206bace115793b Reviewed-by: Richard Moe Gustavsen --- .../widgets/widgets/qcombobox/tst_qcombobox.cpp | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp') diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 3afdc0a12a..b882055888 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -64,6 +64,9 @@ #include #include +#include "../../../shared/platforminputcontext.h" +#include + static inline void setFrameless(QWidget *w) { Qt::WindowFlags flags = w->windowFlags(); @@ -80,6 +83,8 @@ public: tst_QComboBox() {} private slots: + void initTestCase(); + void cleanupTestCase(); void getSetCheck(); void ensureReturnIsIgnored(); void setEditable(); @@ -162,6 +167,10 @@ private slots: void task_QTBUG_39088_inputMethodHints(); void task_QTBUG_49831_scrollerNotActivated(); void task_QTBUG_56693_itemFontFromModel(); + void inputMethodUpdate(); + +private: + PlatformInputContext m_platformInputContext; }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -207,6 +216,18 @@ protected: QRegion visualRegionForSelection(const QItemSelection &) const { return QRegion(); } }; +void tst_QComboBox::initTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = &m_platformInputContext; +} + +void tst_QComboBox::cleanupTestCase() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; +} + // Testing get/set functions void tst_QComboBox::getSetCheck() { @@ -3324,5 +3345,59 @@ void tst_QComboBox::task_QTBUG_56693_itemFontFromModel() box.hidePopup(); } +void tst_QComboBox::inputMethodUpdate() +{ + TestWidget topLevel; + topLevel.show(); + QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + QComboBox *testWidget = topLevel.comboBox(); + // make sure we have no lineedit + QVERIFY(!testWidget->lineEdit()); + // test setEditable(true) + testWidget->setEditable(true); + QVERIFY(testWidget->lineEdit()); + + testWidget->activateWindow(); + testWidget->setFocus(); + QTRY_VERIFY(testWidget->hasFocus()); + QTRY_COMPARE(qApp->focusObject(), testWidget); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, 1, QVariant()); + QInputMethodEvent event("preedit text", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + QInputMethodEvent event("", attributes); + event.setCommitString("preedit text"); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); + QCOMPARE(testWidget->lineEdit()->text(), QString("preedit text")); + + m_platformInputContext.m_updateCallCount = 0; + { + QList attributes; + attributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 0, 0, QVariant()); + QInputMethodEvent event("", attributes); + QApplication::sendEvent(testWidget, &event); + } + QVERIFY(m_platformInputContext.m_updateCallCount >= 1); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" -- cgit v1.2.3