From 99c5b68d4af7b099f201a7b89c86209df9e9349b Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 17 Jun 2009 10:20:46 +0200 Subject: Fix QGraphicsItem::ItemHasNoContents rendering of children. The ItemHasNoContents flag was preventing items that clip their children from rendering their children at all. Fixed now. Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsscene.cpp | 5 +++-- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 27 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 1b5af07..811e0d3 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -5074,7 +5074,8 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * } // Item is invisible. - bool invisible = !item || ((item->d_ptr->flags & QGraphicsItem::ItemHasNoContents) || invisibleButChildIgnoresParentOpacity); + bool hasContents = item && !(item->d_ptr->flags & QGraphicsItem::ItemHasNoContents); + bool invisible = !hasContents || invisibleButChildIgnoresParentOpacity; // Calculate the full transform for this item. bool wasDirtyParentSceneTransform = false; @@ -5161,7 +5162,7 @@ void QGraphicsScenePrivate::drawSubtreeRecursive(QGraphicsItem *item, QPainter * } bool childClip = (item && (item->d_ptr->flags & QGraphicsItem::ItemClipsChildrenToShape)); - bool dontDrawChildren = item && dontDrawItem && childClip; + bool dontDrawChildren = item && hasContents && dontDrawItem && childClip; childClip &= !dontDrawChildren && !children->isEmpty(); if (item && invisible) dontDrawItem = true; diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 63a3f92..e8a6d10 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -229,6 +229,7 @@ private slots: void moveItem(); void sorting_data(); void sorting(); + void itemHasNoContents(); // task specific tests below me void task141694_textItemEnsureVisible(); @@ -7031,5 +7032,31 @@ void tst_QGraphicsItem::sorting() << item1 << item2); } +void tst_QGraphicsItem::itemHasNoContents() +{ + PainterItem *item1 = new PainterItem; + PainterItem *item2 = new PainterItem; + item2->setParentItem(item1); + item2->setPos(50, 50); + item1->setFlag(QGraphicsItem::ItemHasNoContents); + item1->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + + QGraphicsScene scene; + scene.addItem(item1); + + QGraphicsView view(&scene); + view.show(); +#ifdef Q_WS_X11 + qt_x11_wait_for_window_manager(&view); +#endif + QTest::qWait(100); + + _paintedItems.clear(); + + view.viewport()->repaint(); + + QCOMPARE(_paintedItems, QList() << item2); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12