diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2009-08-04 11:05:05 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2009-08-04 11:08:26 (GMT) |
commit | 232569c52844a4f661fe55001015ad5da5097ce7 (patch) | |
tree | 4910c9f681369796f4a6c780b766e4874911ae86 | |
parent | e83f77cbc22be5e37de1e7a8ec2c55e66f7b51d9 (diff) | |
download | Qt-232569c52844a4f661fe55001015ad5da5097ce7.zip Qt-232569c52844a4f661fe55001015ad5da5097ce7.tar.gz Qt-232569c52844a4f661fe55001015ad5da5097ce7.tar.bz2 |
Fix ancestor flags that are not correctly update when reparenting.
updateAncestorFlags was not reseting the flags if you change the parent
that have for instance itemsClipChildrenToShape to a new one that
doesn't have that flag.
Task-number:258956
Reviewed-by:bnilsen
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 23 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 16 |
2 files changed, 28 insertions, 11 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index aa37981..7b650d2 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -638,18 +638,19 @@ void QGraphicsItemPrivate::updateAncestorFlag(QGraphicsItem::GraphicsItemFlag ch return; } - // Inherit the enabled-state from our parents. - if ((parent && ((parent->d_ptr->ancestorFlags & flag) - || (int(parent->d_ptr->flags & childFlag) == childFlag) - || (childFlag == -1 && parent->d_ptr->handlesChildEvents)))) { - enabled = true; - ancestorFlags |= flag; - } - - // Top-level root items don't have any ancestors, so there are no - // ancestor flags either. - if (!parent) + if (parent) { + // Inherit the enabled-state from our parents. + if ((parent->d_ptr->ancestorFlags & flag) || (int(parent->d_ptr->flags & childFlag) == childFlag) || (childFlag == -1 && parent->d_ptr->handlesChildEvents)) { + enabled = true; + ancestorFlags |= flag; + } else { + ancestorFlags &= ~flag; + } + } else { + // Top-level root items don't have any ancestors, so there are no + // ancestor flags either. ancestorFlags = 0; + } } else { // Don't set or propagate the ancestor flag if it's already correct. if (((ancestorFlags & flag) && enabled) || (!(ancestorFlags & flag) && !enabled)) diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 90c4636..ded8aca 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -665,6 +665,22 @@ void tst_QGraphicsItem::flags() QApplication::sendEvent(&scene, &event5); QCOMPARE(item->pos(), QPointF(10, 10)); } + { + QGraphicsItem* clippingParent = new QGraphicsRectItem; + clippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, true); + + QGraphicsItem* nonClippingParent = new QGraphicsRectItem; + nonClippingParent->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false); + + QGraphicsItem* child = new QGraphicsRectItem(nonClippingParent); + QVERIFY(!child->isClipped()); + + child->setParentItem(clippingParent); + QVERIFY(child->isClipped()); + + child->setParentItem(nonClippingParent); + QVERIFY(!child->isClipped()); + } } void tst_QGraphicsItem::toolTip() |