diff options
author | Alexis Menard <alexis.menard@nokia.com> | 2010-04-22 06:57:07 (GMT) |
---|---|---|
committer | Alexis Menard <alexis.menard@nokia.com> | 2010-04-27 03:43:49 (GMT) |
commit | 4b2293fe1dbb82a0767fff155cef9e33cde3faeb (patch) | |
tree | b814de4181cf967b3db5925d9bb41520313ee1a3 | |
parent | 8ed0a827298776ef2574b1298f24071c61dc8b07 (diff) | |
download | Qt-4b2293fe1dbb82a0767fff155cef9e33cde3faeb.zip Qt-4b2293fe1dbb82a0767fff155cef9e33cde3faeb.tar.gz Qt-4b2293fe1dbb82a0767fff155cef9e33cde3faeb.tar.bz2 |
Fix update issue when an item has an effect and child.
When a child marks its parent as dirty (and the parent has an effect) and they are
not in a scene, they must not set fullUpdatePending to 1 because if the scene
is in fullUpdate (not yet painted) then the item will not be processed by
processDirtyItemRecursive so the fullUpdatePending flag will never be
reset by resetDirtyItem. Any calls to update() will be then discarded
because it will think that a full update is pending for the item. A full
update will be done anyway by the scene and if not then markDirty will do
its job when the parent will be added to the scene.
Task-number:QTBUG-10037
Reviewed-by:bnilsen
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 2 | ||||
-rw-r--r-- | tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 47 |
2 files changed, 48 insertions, 1 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 8c7fbb4..6b22607 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -861,7 +861,7 @@ inline void QGraphicsItemPrivate::markParentDirty(bool updateBoundingRect) static_cast<QGraphicsItemEffectSourcePrivate *>(parentp->graphicsEffect->d_func() ->source->d_func())->invalidateCache(); } - if (parentp->graphicsEffect->isEnabled()) { + if (parentp->scene && parentp->graphicsEffect->isEnabled()) { parentp->dirty = 1; parentp->fullUpdatePending = 1; } diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index e1c4791..055ae80 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -446,6 +446,7 @@ private slots: void QT_2653_fullUpdateDiscardingOpacityUpdate(); void QT_2649_focusScope(); void sortItemsWhileAdding(); + void doNotMarkFullUpdateIfNotInScene(); private: QList<QGraphicsItem *> paintedItems; @@ -10431,5 +10432,51 @@ void tst_QGraphicsItem::sortItemsWhileAdding() grandParent.setParentItem(&grandGrandParent); } +void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() +{ + struct Item : public QGraphicsTextItem + { + int painted; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) + { + painted++; + QGraphicsTextItem::paint(painter, opt, wid); + } + }; + QGraphicsScene scene; + MyGraphicsView view(&scene); + Item *item = new Item; + item->painted = 0; + item->setPlainText("Grandparent"); + Item *item2 = new Item; + item2->setPlainText("parent"); + item2->painted = 0; + Item *item3 = new Item; + item3->setPlainText("child"); + item3->painted = 0; + QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect; + effect->setOpacity(0.5); + item2->setGraphicsEffect(effect); + item3->setParentItem(item2); + item2->setParentItem(item); + scene.addItem(item); + view.show(); + QTest::qWaitForWindowShown(&view); + QTRY_COMPARE(view.repaints, 1); + QTRY_COMPARE(item->painted, 1); + QTRY_COMPARE(item2->painted, 1); + QTRY_COMPARE(item3->painted, 1); + item2->update(); + QApplication::processEvents(); + QTRY_COMPARE(item->painted, 2); + QTRY_COMPARE(item2->painted, 2); + QTRY_COMPARE(item3->painted, 2); + item2->update(); + QApplication::processEvents(); + QTRY_COMPARE(item->painted, 3); + QTRY_COMPARE(item2->painted, 3); + QTRY_COMPARE(item3->painted, 3); +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" |