diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-03 14:34:58 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-09 07:33:01 (GMT) |
commit | 728179ed60b43187d28c77a2d6930a74a62791d6 (patch) | |
tree | 9b48a4077f356138ce5c536b06d9cdcda2fe7af3 /src/gui/graphicsview/qgraphicsscene.cpp | |
parent | 1598ef761a8c3f0c9cccf5318e3de30f6c50880f (diff) | |
download | Qt-728179ed60b43187d28c77a2d6930a74a62791d6.zip Qt-728179ed60b43187d28c77a2d6930a74a62791d6.tar.gz Qt-728179ed60b43187d28c77a2d6930a74a62791d6.tar.bz2 |
Add QGraphicsItem::itemChangeEnabled().
This function allows the user to disable notifications for item changes.
In QSimpleCanvasItem, all notifications are disabled by default, and
you can enable them one at a time. QGraphicsItem's behavior is to by
default enable all notifications.
A side effect of this change is that I've removed one optimization in
favor of another: by not constructing a QVariant at all when there's no
notification we get maximum performance, at the expense of constructing
it twice if there is a notification.
Diffstat (limited to 'src/gui/graphicsview/qgraphicsscene.cpp')
-rw-r--r-- | src/gui/graphicsview/qgraphicsscene.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 8641fe2..96800a3 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -666,8 +666,10 @@ void QGraphicsScenePrivate::_q_polishItems() const QVariant booleanTrueVariant(true); foreach (QGraphicsItem *item, unpolishedItems) { if (!item->d_ptr->explicitlyHidden) { - item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); - item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); + if (item->itemChangeEnabled(QGraphicsItem::ItemVisibleChange)) { + item->itemChange(QGraphicsItem::ItemVisibleChange, booleanTrueVariant); + item->itemChange(QGraphicsItem::ItemVisibleHasChanged, booleanTrueVariant); + } } if (item->isWidget()) { QEvent event(QEvent::Polish); @@ -2950,9 +2952,12 @@ void QGraphicsScene::addItem(QGraphicsItem *item) // Notify the item that its scene is changing, and allow the item to // react. - const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, - qVariantFromValue<QGraphicsScene *>(this))); - QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); + QGraphicsScene *targetScene = this; + bool notify = item->itemChangeEnabled(QGraphicsItem::ItemSceneChange); + if (notify) { + targetScene = qVariantValue<QGraphicsScene *>(item->itemChange(QGraphicsItem::ItemSceneChange, + qVariantFromValue<QGraphicsScene *>(this))); + } if (targetScene != this) { if (targetScene && item->scene() != targetScene) targetScene->addItem(item); @@ -3063,7 +3068,8 @@ void QGraphicsScene::addItem(QGraphicsItem *item) emit selectionChanged(); // Deliver post-change notification - item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); + if (notify) + item->itemChange(QGraphicsItem::ItemSceneHasChanged, qVariantFromValue<QGraphicsScene *>(targetScene)); } /*! @@ -3327,9 +3333,12 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) // Notify the item that it's scene is changing to 0, allowing the item to // react. - const QVariant newSceneVariant(item->itemChange(QGraphicsItem::ItemSceneChange, - qVariantFromValue<QGraphicsScene *>(0))); - QGraphicsScene *targetScene = qVariantValue<QGraphicsScene *>(newSceneVariant); + QGraphicsScene *targetScene = 0; + bool notify = item->itemChangeEnabled(QGraphicsItem::ItemSceneChange); + if (notify) { + targetScene = qVariantValue<QGraphicsScene *>(item->itemChange(QGraphicsItem::ItemSceneChange, + qVariantFromValue<QGraphicsScene *>(0))); + } if (targetScene != 0 && targetScene != this) { targetScene->addItem(item); return; @@ -3425,7 +3434,8 @@ void QGraphicsScene::removeItem(QGraphicsItem *item) emit selectionChanged(); // Deliver post-change notification - item->itemChange(QGraphicsItem::ItemSceneHasChanged, newSceneVariant); + if (notify) + item->itemChange(QGraphicsItem::ItemSceneHasChanged, qVariantFromValue<QGraphicsScene *>(targetScene)); } /*! |