summaryrefslogtreecommitdiffstats
path: root/src/gui/graphicsview
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2010-01-25 10:52:14 (GMT)
committerPrasanth Ullattil <prasanth.ullattil@nokia.com>2010-01-27 15:30:28 (GMT)
commit6a1a7d4ff16b87275a06c83e5316f778c974dba9 (patch)
tree4baf584ede252d27cafa6d7d975ef926a3cdf75f /src/gui/graphicsview
parentd867c403dfbc284e2f564939622854900ab66919 (diff)
downloadQt-6a1a7d4ff16b87275a06c83e5316f778c974dba9.zip
Qt-6a1a7d4ff16b87275a06c83e5316f778c974dba9.tar.gz
Qt-6a1a7d4ff16b87275a06c83e5316f778c974dba9.tar.bz2
Added optimization flag to QGraphicsItemPrivate.
Avoid traversing the whole child hierarchy when opacity changes unless there are children with graphics effects. Reviewed-by: Bjørn Erik Nilsen
Diffstat (limited to 'src/gui/graphicsview')
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp22
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h3
2 files changed, 25 insertions, 0 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index f4767b8..f81cb23 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1077,6 +1077,10 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, const Q
p = p->d_ptr->parent;
}
+ // Update graphics effect optimization flag
+ if (newParent && (graphicsEffect || mayHaveChildWithGraphicsEffect))
+ newParent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();
+
// Update focus scope item ptr in new scope.
QGraphicsItem *newFocusScopeItem = subFocusItem ? subFocusItem : parentFocusScopeItem;
if (newFocusScopeItem && newParent) {
@@ -2614,6 +2618,8 @@ void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)
if (d_ptr->graphicsEffect) {
delete d_ptr->graphicsEffect;
d_ptr->graphicsEffect = 0;
+ } else if (d_ptr->parent) {
+ d_ptr->parent->d_ptr->updateChildWithGraphicsEffectFlagRecursively();
}
if (effect) {
@@ -2627,6 +2633,19 @@ void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect)
}
#endif //QT_NO_GRAPHICSEFFECT
+void QGraphicsItemPrivate::updateChildWithGraphicsEffectFlagRecursively()
+{
+#ifndef QT_NO_GRAPHICSEFFECT
+ QGraphicsItemPrivate *itemPrivate = this;
+ do {
+ // parent chain already notified?
+ if (itemPrivate->mayHaveChildWithGraphicsEffect)
+ return;
+ itemPrivate->mayHaveChildWithGraphicsEffect = 1;
+ } while ((itemPrivate = itemPrivate->parent ? itemPrivate->parent->d_ptr.data() : 0));
+#endif
+}
+
/*!
\internal
\since 4.6
@@ -5094,6 +5113,9 @@ void QGraphicsItemPrivate::invalidateParentGraphicsEffectsRecursively()
void QGraphicsItemPrivate::invalidateChildGraphicsEffectsRecursively(QGraphicsItemPrivate::InvalidateReason reason)
{
+ if (!mayHaveChildWithGraphicsEffect)
+ return;
+
for (int i = 0; i < children.size(); ++i) {
QGraphicsItemPrivate *childPrivate = children.at(i)->d_ptr.data();
if (reason == OpacityChanged && (childPrivate->flags & QGraphicsItem::ItemIgnoresParentOpacity))
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index ff6e8bd..986a977 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -179,6 +179,7 @@ public:
updateDueToGraphicsEffect(0),
scenePosDescendants(0),
pendingPolish(0),
+ mayHaveChildWithGraphicsEffect(0),
globalStackingOrder(-1),
q_ptr(0)
{
@@ -196,6 +197,7 @@ public:
return item->d_ptr.data();
}
+ void updateChildWithGraphicsEffectFlagRecursively();
void updateAncestorFlag(QGraphicsItem::GraphicsItemFlag childFlag,
AncestorFlag flag = NoFlag, bool enabled = false, bool root = true);
void updateAncestorFlags();
@@ -492,6 +494,7 @@ public:
quint32 updateDueToGraphicsEffect : 1;
quint32 scenePosDescendants : 1;
quint32 pendingPolish : 1;
+ quint32 mayHaveChildWithGraphicsEffect : 1;
// Optional stacking order
int globalStackingOrder;