summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2010-01-25 10:52:14 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2010-01-25 12:29:32 (GMT)
commita85f708449a5fb61740ec12abd4cb9df3a5265ad (patch)
tree3f656ccfec7aa5c04c7a49a3a288f0ee609348da
parente5be6baa698f4779b6af97175015856d146bc479 (diff)
downloadQt-a85f708449a5fb61740ec12abd4cb9df3a5265ad.zip
Qt-a85f708449a5fb61740ec12abd4cb9df3a5265ad.tar.gz
Qt-a85f708449a5fb61740ec12abd4cb9df3a5265ad.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
-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 b8d392d..66493b7 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -1075,6 +1075,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) {
@@ -2612,6 +2616,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) {
@@ -2625,6 +2631,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
@@ -5092,6 +5111,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;