From b7ea50145c6dc443e15d9f3f1e1dd1737a5135cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 29 Apr 2010 09:11:02 +0200 Subject: Ensured that WA_InputMethodEnabled was set before FocusInEvent was sent. When focusInEvent is called we need to ensure that WA_InputMethodEnabled is set, since FocusInEvent might lead to that QInputContext::setFocusWidget is called (with the QGraphicsView as the widget parameter). However, if the widget still does not have WA_InputMethodEnabled set yet it will assert in QInputContext::setFocusWidget (it requires that the widget has the flag set). This was a problem for the morbit bridge, where Dui requires the attribute to be set (while Orbit actually does not require) Task-number: QTBUG-10276 Reviewed-by: jasplin Reviewed-by: Alexis Menard --- src/gui/graphicsview/qgraphicsscene.cpp | 6 +++--- tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index b368a82..98fc10f 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -808,13 +808,13 @@ void QGraphicsScenePrivate::setFocusItemHelper(QGraphicsItem *item, #endif //QT_NO_IM } - if (item) { + if (item) focusItem = item; + updateInputMethodSensitivityInViews(); + if (item) { QFocusEvent event(QEvent::FocusIn, focusReason); sendEvent(item, &event); } - - updateInputMethodSensitivityInViews(); } /*! diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 1c19fab..e3c699b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -3664,6 +3664,22 @@ void tst_QGraphicsView::update() #endif } +class FocusItem : public QGraphicsRectItem +{ +public: + FocusItem() : QGraphicsRectItem(0, 0, 20, 20) { + m_viewHasIMEnabledInFocusInEvent = false; + } + + void focusInEvent(QFocusEvent *event) + { + QGraphicsView *view = scene()->views().first(); + m_viewHasIMEnabledInFocusInEvent = view->testAttribute(Qt::WA_InputMethodEnabled); + } + + bool m_viewHasIMEnabledInFocusInEvent; +}; + void tst_QGraphicsView::inputMethodSensitivity() { QGraphicsScene scene; @@ -3673,7 +3689,7 @@ void tst_QGraphicsView::inputMethodSensitivity() QApplication::setActiveWindow(&view); QTRY_COMPARE(QApplication::activeWindow(), static_cast(&view)); - QGraphicsRectItem *item = new QGraphicsRectItem; + FocusItem *item = new FocusItem; view.setAttribute(Qt::WA_InputMethodEnabled, true); @@ -3702,6 +3718,7 @@ void tst_QGraphicsView::inputMethodSensitivity() scene.setFocusItem(item); QCOMPARE(scene.focusItem(), static_cast(item)); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); item->setFlag(QGraphicsItem::ItemAcceptsInputMethod, false); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); @@ -3710,15 +3727,17 @@ void tst_QGraphicsView::inputMethodSensitivity() QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); // introduce another item that is focusable but does not accept input methods - QGraphicsRectItem *item2 = new QGraphicsRectItem; + FocusItem *item2 = new FocusItem; item2->setFlag(QGraphicsItem::ItemIsFocusable); scene.addItem(item2); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); + QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); QCOMPARE(scene.focusItem(), static_cast(item2)); scene.setFocusItem(item); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast(item)); view.setScene(0); @@ -3727,10 +3746,12 @@ void tst_QGraphicsView::inputMethodSensitivity() view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast(item)); scene.setFocusItem(item2); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), false); + QCOMPARE(item2->m_viewHasIMEnabledInFocusInEvent, false); QCOMPARE(scene.focusItem(), static_cast(item2)); view.setScene(0); @@ -3743,6 +3764,7 @@ void tst_QGraphicsView::inputMethodSensitivity() view.setScene(&scene); QCOMPARE(view.testAttribute(Qt::WA_InputMethodEnabled), true); + QCOMPARE(item->m_viewHasIMEnabledInFocusInEvent, true); QCOMPARE(scene.focusItem(), static_cast(item)); } -- cgit v0.12