summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-02 10:39:02 (GMT)
committerAndreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com>2009-06-09 07:30:42 (GMT)
commit99318bd50bf044c8202f670b667dc990ce90cfe1 (patch)
treeaef7c848a353b74c96869e56da6bf834a365c0fd
parent1fc2406f35594706a9aafa9374694cf0a65cee30 (diff)
downloadQt-99318bd50bf044c8202f670b667dc990ce90cfe1.zip
Qt-99318bd50bf044c8202f670b667dc990ce90cfe1.tar.gz
Qt-99318bd50bf044c8202f670b667dc990ce90cfe1.tar.bz2
Fix sorting bug and ensure render functions work. Make direct default.
Mark the children list for sorting when the Z value for items changes. Change the signature of the recursive draw function slightly so that the expose region is optional, and ensure we don't intersect with this region if it's not available. This change also flips the direct painting so that the default is to use the recursive approach.
-rw-r--r--src/gui/graphicsview/qgraphicsitem.cpp1
-rw-r--r--src/gui/graphicsview/qgraphicsscene.cpp24
-rw-r--r--src/gui/graphicsview/qgraphicsscene_p.h2
-rw-r--r--src/gui/graphicsview/qgraphicsview.cpp4
4 files changed, 15 insertions, 16 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp
index e1389b5..17cab45 100644
--- a/src/gui/graphicsview/qgraphicsitem.cpp
+++ b/src/gui/graphicsview/qgraphicsitem.cpp
@@ -3151,6 +3151,7 @@ void QGraphicsItem::setZValue(qreal z)
if (newZ == d_ptr->z)
return;
d_ptr->z = newZ;
+ d_ptr->needSortChildren = 1;
if (d_ptr->scene) {
d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/true);
diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp
index b1d1742..fcb6352 100644
--- a/src/gui/graphicsview/qgraphicsscene.cpp
+++ b/src/gui/graphicsview/qgraphicsscene.cpp
@@ -2522,7 +2522,6 @@ QList<QGraphicsItem *> QGraphicsScene::items(const QPointF &pos) const
return d->items_helper(pos);
}
-
/*!
\fn QList<QGraphicsItem *> QGraphicsScene::items(const QRectF &rectangle, Qt::ItemSelectionMode mode) const
@@ -5046,7 +5045,7 @@ void QGraphicsScenePrivate::drawItemHelper(QGraphicsItem *item, QPainter *painte
void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform &parentTransform,
const QTransform &viewTransform,
- const QRegion &exposedRegion, QWidget *widget,
+ QRegion *exposedRegion, QWidget *widget,
QGraphicsView::OptimizationFlags optimizationFlags,
QList<QGraphicsItem *> *topLevelItems,
qreal parentOpacity)
@@ -5084,10 +5083,11 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
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();
- }
+ viewBoundingRect = transform.mapRect(brect).toRect().adjusted(-1, -1, 1, 1);
+ item->d_ptr->paintedViewBoundingRects.insert(widget, viewBoundingRect);
+ if (exposedRegion)
+ viewBoundingRect &= exposedRegion->boundingRect();
+ }
}
bool childClip = (item && (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape));
@@ -5132,7 +5132,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
// Draw item
if (!dontDrawItem) {
QStyleOptionGraphicsItem option;
- item->d_ptr->initStyleOption(&option, transform, exposedRegion);
+ item->d_ptr->initStyleOption(&option, transform, exposedRegion ? *exposedRegion : QRegion(), exposedRegion == 0);
bool clipsToShape = (item->d_ptr->flags & QGraphicsItem::ItemClipsToShape);
bool savePainter = clipsToShape || !(optimizationFlags & QGraphicsView::DontSavePainterState);
@@ -5143,7 +5143,6 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter *
if (clipsToShape)
painter->setClipPath(item->shape(), Qt::IntersectClip);
painter->setOpacity(opacity);
-
drawItemHelper(item, painter, &option, widget, false);
if (savePainter)
@@ -5318,20 +5317,19 @@ void QGraphicsScene::drawItems(QPainter *painter,
// Determine view, expose and flags.
QGraphicsView *view = widget ? qobject_cast<QGraphicsView *>(widget->parentWidget()) : 0;
- QRegion expose;
+ QRegion *expose = 0;
QGraphicsView::OptimizationFlags flags;
if (view) {
- expose = view->d_func()->exposedRegion;
+ expose = &view->d_func()->exposedRegion;
flags = view->optimizationFlags();
}
- // Draw each toplevel recursively.
+ // Find all toplevels, they are already sorted.
QList<QGraphicsItem *> topLevelItems;
for (int i = 0; i < numItems; ++i) {
QGraphicsItem *item = items[i]->topLevelItem();
- topLevelItems << item;
-
if (!item->d_ptr->itemDiscovered) {
+ topLevelItems << item;
item->d_ptr->itemDiscovered = 1;
d->drawSubtreeRecursive(item, painter, viewTransform, viewTransform,
expose, widget, flags);
diff --git a/src/gui/graphicsview/qgraphicsscene_p.h b/src/gui/graphicsview/qgraphicsscene_p.h
index 2a036e3..2e82a4a 100644
--- a/src/gui/graphicsview/qgraphicsscene_p.h
+++ b/src/gui/graphicsview/qgraphicsscene_p.h
@@ -256,7 +256,7 @@ public:
void drawSubtreeRecursive(QGraphicsItem *item, QPainter *painter, const QTransform &parentTransform,
const QTransform &viewTransform,
- const QRegion &exposedRegion, QWidget *widget, QGraphicsView::OptimizationFlags optimizationFlags,
+ QRegion *exposedRegion, QWidget *widget, QGraphicsView::OptimizationFlags optimizationFlags,
QList<QGraphicsItem *> *topLevelItems = 0, qreal parentOpacity = qreal(1.0));
void markDirty(QGraphicsItem *item, const QRectF &rect = QRectF(), bool invalidateChildren = false,
bool maybeDirtyClipPath = false, bool force = false, bool ignoreOpacity = false);
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp
index d410a53..caa3ffc 100644
--- a/src/gui/graphicsview/qgraphicsview.cpp
+++ b/src/gui/graphicsview/qgraphicsview.cpp
@@ -3300,8 +3300,8 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
}
// Items
- if ((d->optimizationFlags & IndirectPainting)) {
- d->scene->d_func()->drawSubtreeRecursive(0, &painter, viewTransform, viewTransform, d->exposedRegion,
+ if (!(d->optimizationFlags & IndirectPainting)) {
+ d->scene->d_func()->drawSubtreeRecursive(0, &painter, viewTransform, viewTransform, &d->exposedRegion,
viewport(), d->optimizationFlags, 0);
} else {
// Find all exposed items