summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2009-05-26 18:23:54 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-09 07:26:52 (GMT)
commite7c7e4f57530d7b3571bf11dbe555c52f6dc3f34 (patch)
tree597929219e270919af47a0d8c02733fb36c0a157
parent6f1cca3661b794f170ed00fdc84e8ad31789aa9f (diff)
downloadQt-e7c7e4f57530d7b3571bf11dbe555c52f6dc3f34.zip
Qt-e7c7e4f57530d7b3571bf11dbe555c52f6dc3f34.tar.gz
Qt-e7c7e4f57530d7b3571bf11dbe555c52f6dc3f34.tar.bz2
Cache QGraphicsItem::childrenBoundingRect.
We'll need this later when making a smarter update mechanism.
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp15
-rw-r--r--src/gui/graphicsview/qgraphicsitem_p.h5
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index b9e462b..e09d3f0 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -925,6 +925,11 @@ void QGraphicsItemPrivate::setParentItemHelper(QGraphicsItem *newParent, bool de
*/
void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rect)
{
+ if (!dirtyChildrenBoundingRect) {
+ *rect |= x->mapRect(childrenBoundingRect);
+ return;
+ }
+
for (int i = 0; i < children.size(); ++i) {
QGraphicsItem *child = children.at(i);
QGraphicsItemPrivate *childd = child->d_ptr;
@@ -948,6 +953,9 @@ void QGraphicsItemPrivate::childrenBoundingRectHelper(QTransform *x, QRectF *rec
childd->childrenBoundingRectHelper(x, rect);
}
}
+
+ childrenBoundingRect = *rect;
+ dirtyChildrenBoundingRect = 0;
}
void QGraphicsItemPrivate::initStyleOption(QStyleOptionGraphicsItem *option, const QTransform &worldTransform,
@@ -3567,6 +3575,9 @@ void QGraphicsItem::setZValue(qreal z)
*/
QRectF QGraphicsItem::childrenBoundingRect() const
{
+ if (!d_ptr->dirtyChildrenBoundingRect)
+ return d_ptr->childrenBoundingRect;
+
QRectF childRect;
QTransform x;
d_ptr->childrenBoundingRectHelper(&x, &childRect);
@@ -6400,6 +6411,10 @@ void QGraphicsItem::prepareGeometryChange()
scenePrivate->removeFromIndex(this);
}
+ QGraphicsItem *parent = this;
+ while (parent = parent->d_ptr->parent)
+ parent->d_ptr->dirtyChildrenBoundingRect = 1;
+
if (d_ptr->inSetPosHelper)
return;
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h
index bd81fe5..200d177 100644
--- a/src/gui/graphicsview/qgraphicsitem_p.h
+++ b/src/gui/graphicsview/qgraphicsitem_p.h
@@ -160,6 +160,7 @@ public:
hasDecomposedTransform(0),
dirtyTransform(0),
dirtyTransformComponents(0),
+ dirtyChildrenBoundingRect(1),
globalStackingOrder(-1),
sceneTransformIndex(-1),
q_ptr(0)
@@ -308,6 +309,7 @@ public:
}
QPainterPath cachedClipPath;
+ QRectF childrenBoundingRect;
QPointF pos;
qreal z;
QGraphicsScene *scene;
@@ -350,7 +352,8 @@ public:
quint32 hasDecomposedTransform : 1;
quint32 dirtyTransform : 1;
quint32 dirtyTransformComponents : 1;
- quint32 padding : 18; // feel free to use
+ quint32 dirtyChildrenBoundingRect : 1;
+ quint32 padding : 17; // feel free to use
// Optional stacking order
int globalStackingOrder;