diff options
author | Christophe Oosterlynck <christophe.oosterlynck@dzine.be> | 2011-11-02 09:00:12 (GMT) |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-11-02 09:01:05 (GMT) |
commit | 7925f107814e46deb0848d9e6016721ceebfb521 (patch) | |
tree | cc3dbee045b4cca33eecf7b531f4766ecc2bdfa3 /tests | |
parent | 582dec4b753b84cc69eb140290ceff346bce76b9 (diff) | |
download | Qt-7925f107814e46deb0848d9e6016721ceebfb521.zip Qt-7925f107814e46deb0848d9e6016721ceebfb521.tar.gz Qt-7925f107814e46deb0848d9e6016721ceebfb521.tar.bz2 |
Correction for effectiveBoundingRect() calculation for QGraphicsItem
QGraphicsItemPrivate::effectiveBoundingRect() should use ItemClipsChildrenToShape
flag from the parent while looping to check for clipping and not use
its own AncestorClipsChildren flag.
By using AncestorClipsChildren, you're checking if one of your ancestors
clips you, but you really want to know if your direct parent clips you.
Merge-request: 1419
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index 9c189cb..3d45a07 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -68,6 +68,7 @@ private slots: void boundingRectFor(); void boundingRect(); void boundingRect2(); + void boundingRect3(); void draw(); void opacity(); void grayscale(); @@ -319,6 +320,39 @@ void tst_QGraphicsEffect::boundingRect2() QCOMPARE(effect->boundingRect(), effect->boundingRectFor(childRect | grandChildRect)); } +void tst_QGraphicsEffect::boundingRect3() +{ + QGraphicsScene scene; + QGraphicsRectItem *root = new QGraphicsRectItem; + scene.addItem(root); + QRectF rootRect(0, 0, 100, 100); + root->setFlag(QGraphicsItem::ItemClipsChildrenToShape); + root->setRect(rootRect); + + QGraphicsRectItem *child = new QGraphicsRectItem; + child->setPos(5,5); + child->setParentItem(root); + CustomEffect *effect1 = new CustomEffect; + child->setGraphicsEffect(effect1); + + QGraphicsRectItem *grandChild = new QGraphicsRectItem; + QRectF grandChildRect(0, 0, 50, 50); + grandChild->setRect(grandChildRect); + grandChild->setPos(10,10); + grandChild->setParentItem(child); + CustomEffect *effect2 = new CustomEffect; + grandChild->setGraphicsEffect(effect2); + + QRectF effectiveBoundingRectGrandChild = effect2->boundingRectFor(grandChildRect); + QCOMPARE(effect2->boundingRect(), effectiveBoundingRectGrandChild); + + QRectF effectiveBoundingRectChildAndGrandChild = effect1->boundingRectFor(child->mapRectFromItem(grandChild, effectiveBoundingRectGrandChild)); + QCOMPARE(effect1->boundingRect(),effectiveBoundingRectChildAndGrandChild); + + // The children bounding rect of the root should be the rectangle of the grandChild enlarged twice by the CustomEffect on the grandChild and the child, but clipped by the root item + QCOMPARE(root->childrenBoundingRect(), root->boundingRect().intersected(root->mapRectFromItem(child, effectiveBoundingRectChildAndGrandChild))); +} + void tst_QGraphicsEffect::draw() { QGraphicsScene scene; |