From 090ff76845ca5b9c61319f359a94cc239b18846b Mon Sep 17 00:00:00 2001 From: Aleksandar Stojiljkovic Date: Fri, 19 Aug 2011 17:16:35 +0300 Subject: Avoid calling QInputMethod update when adding or removing QGraphicsItems that don't have focus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removing item from QGraphicsScene takes longer if focus is in item (and that item is not being removed) with ItemAcceptsInputMethod. update() in QInputContext or in subclasses could be expensive - usually requires inputMethodFocus and a sequence of inputMethodQuery calls to get the state. In MeeGo, additionally, dbus IPC in MInputContext makes it order of magnitude slower. Minor indentation issue in QGraphicsViewPrivate::updateInputMethodSensitivity() Reviewed-by: Samuel Rødal --- src/gui/graphicsview/qgraphicsscene.cpp | 14 ++++++++++---- src/gui/graphicsview/qgraphicsview.cpp | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 27639f9..7925c69 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2688,10 +2688,11 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Ensure that newly added items that have subfocus set, gain // focus automatically if there isn't a focus item already. - if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item) + if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item) { item->focusItem()->setFocus(); - - d->updateInputMethodSensitivityInViews(); + // Update input method only if added item got focus + d->updateInputMethodSensitivityInViews(); + } } /*! @@ -2942,6 +2943,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) { // ### Refactoring: This function shares much functionality with _q_removeItemLater() Q_D(QGraphicsScene); + + bool wasFocused(item == focusItem()); + if (!item) { qWarning("QGraphicsScene::removeItem: cannot remove 0-item"); return; @@ -2968,7 +2972,9 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) // Deliver post-change notification item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); - d->updateInputMethodSensitivityInViews(); + // Avoid calling input method update if removed item wasn't focused + if (wasFocused) + d->updateInputMethodSensitivityInViews(); } /*! diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 41b07c4..4bfcbb2 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -1101,8 +1101,8 @@ void QGraphicsViewPrivate::updateInputMethodSensitivity() if (!proxy) { q->setInputMethodHints(focusItem->inputMethodHints()); } else if (QWidget *widget = proxy->widget()) { - if (QWidget *fw = widget->focusWidget()) - widget = fw; + if (QWidget *fw = widget->focusWidget()) + widget = fw; q->setInputMethodHints(widget->inputMethodHints()); } else { q->setInputMethodHints(0); -- cgit v0.12 From 4748be8f436e2bc13b5755f2ffe2428a338f7239 Mon Sep 17 00:00:00 2001 From: Aleksandar Stojiljkovic Date: Tue, 23 Aug 2011 10:52:13 +0300 Subject: Revert "Avoid calling QInputMethod update when adding or removing QGraphicsItems that don't have focus" This reverts commit 090ff76845ca5b9c61319f359a94cc239b18846b ... due to failing unit tests. --- src/gui/graphicsview/qgraphicsscene.cpp | 14 ++++---------- src/gui/graphicsview/qgraphicsview.cpp | 4 ++-- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 7925c69..27639f9 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -2688,11 +2688,10 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Ensure that newly added items that have subfocus set, gain // focus automatically if there isn't a focus item already. - if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item) { + if (!d->focusItem && item != d->lastFocusItem && item->focusItem() == item) item->focusItem()->setFocus(); - // Update input method only if added item got focus - d->updateInputMethodSensitivityInViews(); - } + + d->updateInputMethodSensitivityInViews(); } /*! @@ -2943,9 +2942,6 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) { // ### Refactoring: This function shares much functionality with _q_removeItemLater() Q_D(QGraphicsScene); - - bool wasFocused(item == focusItem()); - if (!item) { qWarning("QGraphicsScene::removeItem: cannot remove 0-item"); return; @@ -2972,9 +2968,7 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) // Deliver post-change notification item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); - // Avoid calling input method update if removed item wasn't focused - if (wasFocused) - d->updateInputMethodSensitivityInViews(); + d->updateInputMethodSensitivityInViews(); } /*! diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 4bfcbb2..41b07c4 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -1101,8 +1101,8 @@ void QGraphicsViewPrivate::updateInputMethodSensitivity() if (!proxy) { q->setInputMethodHints(focusItem->inputMethodHints()); } else if (QWidget *widget = proxy->widget()) { - if (QWidget *fw = widget->focusWidget()) - widget = fw; + if (QWidget *fw = widget->focusWidget()) + widget = fw; q->setInputMethodHints(widget->inputMethodHints()); } else { q->setInputMethodHints(0); -- cgit v0.12