diff options
author | Aleksandar Stojiljkovic <aleksandar.stojiljkovic@nokia.com> | 2011-08-19 14:16:35 (GMT) |
---|---|---|
committer | Aleksandar Stojiljkovic <aleksandar.stojiljkovic@nokia.com> | 2011-08-19 14:16:35 (GMT) |
commit | 090ff76845ca5b9c61319f359a94cc239b18846b (patch) | |
tree | 0deaf6d8b9d9f4f64696dabd81515d38bcce6662 | |
parent | 84408e18ac5a5ccc69cf34832f31ef63b3ff9f11 (diff) | |
download | Qt-090ff76845ca5b9c61319f359a94cc239b18846b.zip Qt-090ff76845ca5b9c61319f359a94cc239b18846b.tar.gz Qt-090ff76845ca5b9c61319f359a94cc239b18846b.tar.bz2 |
Avoid calling QInputMethod update when adding or removing QGraphicsItems that don't have focus
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
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 14 | ||||
-rw-r--r-- | 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); |