diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-05-29 06:54:31 (GMT) |
---|---|---|
committer | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-06-09 07:28:17 (GMT) |
commit | c563cff78b9606bf5869707fcbe6183198508d60 (patch) | |
tree | b069f5e172f24e3d4af4a9e89ed045ad0a484ed5 /src/gui/graphicsview/qgraphicsscene.cpp | |
parent | bea8a19742ed1decbd63464e36e57980fbde7016 (diff) | |
download | Qt-c563cff78b9606bf5869707fcbe6183198508d60.zip Qt-c563cff78b9606bf5869707fcbe6183198508d60.tar.gz Qt-c563cff78b9606bf5869707fcbe6183198508d60.tar.bz2 |
Introduce QGraphicsItem::ItemHasNoContents.
This flag helps optimize the case where an item is used only as a
transformation node in a scene graph, and where the item itself
doesn't paint anything. This is the default for FxItem (the
subclasses that do paint enable the HasContents flag). This lets
Graphics View know whether there's any point in setting up the
world transform, opacity and other things.
Reviewed-by: Lars
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 b105c9c..eaebd1a 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -295,9 +295,13 @@ static inline bool QRectF_intersects(const QRectF &s, const QRectF &r) static inline void _q_adjustRect(QRectF *rect) { Q_ASSERT(rect); - if (!rect->width()) + bool nullWidth = !rect->width(); + bool nullHeight = !rect->height(); + if (nullWidth && nullHeight) + return; + if (nullWidth) rect->adjust(-0.00001, 0, 0.00001, 0); - if (!rect->height()) + else if (nullHeight) rect->adjust(0, -0.00001, 0, 0.00001); } @@ -5079,22 +5083,23 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * } } QRectF brect = item->boundingRect(); - _q_adjustRect(&brect); - const QRect paintedViewBoundingRect = transform.mapRect(brect).toRect().adjusted(-1, -1, 1, 1); - item->d_ptr->paintedViewBoundingRects.insert(widget, paintedViewBoundingRect); - viewBoundingRect = paintedViewBoundingRect & exposedRegion.boundingRect(); + if (!brect.size().isNull()) { + // ### This does not take the clip into account. + _q_adjustRect(&brect); + const QRect paintedViewBoundingRect = transform.mapRect(brect).toRect().adjusted(-1, -1, 1, 1); + item->d_ptr->paintedViewBoundingRects.insert(widget, paintedViewBoundingRect); + viewBoundingRect = paintedViewBoundingRect & exposedRegion.boundingRect(); + } } else { transform = parentTransform; } - // Find and sort children. - QList<QGraphicsItem *> children = item ? item->d_ptr->children : topLevelItems; - qSort(children.begin(), children.end(), qt_notclosestLeaf); - bool childClip = (item && (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)); bool dontDrawItem = !item || viewBoundingRect.isEmpty(); bool dontDrawChildren = item && dontDrawItem && childClip; childClip &= !dontDrawChildren & !children.isEmpty(); + if (item && item->d_ptr->flags & QGraphicsItem::ItemHasNoContents) + dontDrawItem = true; // Clip children. if (childClip) { @@ -5103,6 +5108,11 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * painter->setClipPath(item->shape(), Qt::IntersectClip); } + // Find and sort children. + QList<QGraphicsItem *> children = item ? item->d_ptr->children : topLevelItems; + if (!dontDrawChildren) + qSort(children.begin(), children.end(), qt_notclosestLeaf); + // Draw children behind int i; if (!dontDrawChildren) { |