diff options
author | Andreas Aardal Hanssen <andreas.aardal.hanssen@nokia.com> | 2009-09-28 14:24:38 +0200 |
---|---|---|
committer | Jason McDonald <jason.mcdonald@nokia.com> | 2009-09-28 23:38:03 +1000 |
commit | 13068688035914454c82eb956c75365e73c8caa4 (patch) | |
tree | 242049f09216430b086a34d3a9350cb986505438 | |
parent | 9103021f04f7b0f15d150fca06308da60da0b8ac (diff) |
QGraphicsItem with parent flag ItemClipsChildrenToShape not visible
Regression against Qt 4.4. Children of items with ItemClipsChildrenToShape
would only be discovered if the view's expose region contained the outer
bounding rect of all items, _if_ there was at least one item in the
scene that enabled ItemIgnoresTransformations.
The reason for this bug is that the presence of an untransformable item
causes the item lookups to go through a different path
(QGraphicsViewPrivate::itemsInArea()). This function had the bug that it
didn't correctly discover children of clip-items. Because of this, in
the provided test case you could "work around" the bug by either removing
the clip flag, or the transformation flag.
Task-number: QTBUG-4151
Reviewed-by: Alexis
(cherry picked from commit f9d6862d13ae38c59ec4a58092c8126620801e0b)
-rw-r--r-- | src/gui/graphicsview/qgraphicsview.cpp | 2 | ||||
-rw-r--r-- | tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 48 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index c8c3abeb42..85bc3fed68 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -2229,7 +2229,7 @@ QList<QGraphicsItem *> QGraphicsViewPrivate::itemsInArea(const QPainterPath &pat // First build a (potentially large) list of all items in the vicinity // that might be untransformable. - QList<QGraphicsItem *> allCandidates = scene->d_func()->estimateItemsInRect(adjustedRect); + QList<QGraphicsItem *> allCandidates = scene->d_func()->items_helper(adjustedRect, mode, Qt::AscendingOrder); // Then find the minimal list of items that are inside \a path, and // convert it to a set. diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 175838f763..99b85c0855 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -63,6 +63,7 @@ #include <QtGui/QBoxLayout> #include <QtGui/QStyle> #include <QtGui/QPushButton> +#include "../../shared/util.h" //TESTED_CLASS= //TESTED_FILES= @@ -201,6 +202,8 @@ private slots: void task239047_fitInViewSmallViewport(); void task245469_itemsAtPointWithClip(); void task253415_reconnectUpdateSceneOnSceneChanged(); + void QTBUG_4151_clipAndIgnore_data(); + void QTBUG_4151_clipAndIgnore(); }; void tst_QGraphicsView::initTestCase() @@ -3068,5 +3071,50 @@ void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged() QVERIFY(wasConnected2); } +void tst_QGraphicsView::QTBUG_4151_clipAndIgnore_data() +{ + QTest::addColumn<bool>("clip"); + QTest::addColumn<bool>("ignoreTransformations"); + QTest::addColumn<int>("numItems"); + + QTest::newRow("none") << false << false << 3; + QTest::newRow("clip") << true << false << 3; + QTest::newRow("ignore") << false << true << 3; + QTest::newRow("clip+ignore") << true << true << 3; +} + +void tst_QGraphicsView::QTBUG_4151_clipAndIgnore() +{ + QFETCH(bool, clip); + QFETCH(bool, ignoreTransformations); + QFETCH(int, numItems); + + QGraphicsScene scene; + + QGraphicsRectItem *parent = new QGraphicsRectItem(QRectF(0, 0, 50, 50), 0); + QGraphicsRectItem *child = new QGraphicsRectItem(QRectF(-10, -10, 40, 40), parent); + QGraphicsRectItem *ignore = new QGraphicsRectItem(QRectF(60, 60, 50, 50), 0); + + if (clip) + parent->setFlags(QGraphicsItem::ItemClipsChildrenToShape); + if (ignoreTransformations) + ignore->setFlag(QGraphicsItem::ItemIgnoresTransformations); + + parent->setBrush(Qt::red); + child->setBrush(QColor(0, 0, 255, 128)); + ignore->setBrush(Qt::green); + + scene.addItem(parent); + scene.addItem(ignore); + + QGraphicsView view(&scene); + view.setFrameStyle(0); + view.resize(75, 75); + view.show(); + QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); + + QCOMPARE(view.items(view.rect()).size(), numItems); +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" |