summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicseffect
diff options
context:
space:
mode:
authorChristophe Oosterlynck <christophe.oosterlynck@dzine.be>2011-09-16 15:09:03 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-09-16 15:12:30 +0200
commit489661d3e69edf0c3011dcd5dd3ae800c9616617 (patch)
tree6e6286b8f5eccc8f515d47f96336ffe165744aa2 /tests/auto/qgraphicseffect
parent57240c1f931eb4c340de6e2bb17972235265f89c (diff)
Prevent unnecessary graphics item updates when graphics effect changes.
Don't invalidate a QGraphicsItem (neither its cache) when an update is triggered because of a QGraphicsEffect attached to it. Autotest for QGraphicsEffect extended with 2 cache invalidation tests Merge-request: 2681 Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
Diffstat (limited to 'tests/auto/qgraphicseffect')
-rw-r--r--tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp95
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
index 1f5563c6b7..9c189cb1bf 100644
--- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
+++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp
@@ -78,6 +78,8 @@ private slots:
void dropShadowClipping();
void childrenVisibilityShouldInvalidateCache();
void prepareGeometryChangeInvalidateCache();
+ void graphicsEffectUpdateShouldNotInvalidateGraphicsItemCache();
+ void graphicsEffectUpdateShouldInvalidateParentGraphicsEffect();
void itemHasNoContents();
};
@@ -732,6 +734,99 @@ void tst_QGraphicsEffect::prepareGeometryChangeInvalidateCache()
QCOMPARE(item->nbPaint, 0);
}
+class MyGraphicsEffect : public QGraphicsEffect
+{
+ public:
+ MyGraphicsEffect(QObject *parent = 0) :
+ QGraphicsEffect(parent), nbSourceInvalidations(0)
+ {}
+ int nbSourceInvalidations;
+ protected:
+ void draw(QPainter *painter)
+ {
+ drawSource(painter);
+ }
+
+ void sourceChanged(ChangeFlags flags)
+ {
+ if (flags == SourceInvalidated)
+ nbSourceInvalidations++;
+ }
+};
+
+void tst_QGraphicsEffect::graphicsEffectUpdateShouldNotInvalidateGraphicsItemCache()
+{
+ QGraphicsScene scene;
+ MyGraphicsItem parent;
+ parent.resize(200, 200);
+ parent.setCacheMode(QGraphicsItem::ItemCoordinateCache);
+ scene.addItem(&parent);
+
+ QGraphicsView view(&scene);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ QTRY_COMPARE(parent.nbPaint, 1);
+
+ //we set an effect on the parent
+ MyGraphicsEffect* opacityEffect = new MyGraphicsEffect(&parent);
+ opacityEffect->update();
+ parent.setGraphicsEffect(opacityEffect);
+ //flush the events
+ QApplication::processEvents();
+ //new effect applied->repaint
+ QCOMPARE(parent.nbPaint, 1);
+
+ opacityEffect->update();
+ //flush the events
+ QApplication::processEvents();
+ //A change to the effect shouldn't invalidate the graphicsitem's cache
+ // => it shouldn't trigger a paint
+ QCOMPARE(parent.nbPaint, 1);
+}
+
+void tst_QGraphicsEffect::graphicsEffectUpdateShouldInvalidateParentGraphicsEffect()
+{
+ QGraphicsScene scene;
+ // Add the parent
+ MyGraphicsItem parent;
+ parent.resize(200, 200);
+ scene.addItem(&parent);
+ // Add a child to the parent
+ MyGraphicsItem child(&parent);
+ child.resize(100, 100);
+
+ QGraphicsView view(&scene);
+ view.show();
+ QApplication::setActiveWindow(&view);
+ QTest::qWaitForWindowShown(&view);
+ //flush the events
+ QApplication::processEvents();
+ QTRY_COMPARE(parent.nbPaint, 1);
+ QTRY_COMPARE(child.nbPaint, 1);
+
+ //we set an effect on the parent and the child
+ MyGraphicsEffect* effectForParent = new MyGraphicsEffect(&parent);
+ parent.setGraphicsEffect(effectForParent);
+
+ MyGraphicsEffect* effectForChild = new MyGraphicsEffect(&child);
+ child.setGraphicsEffect(effectForChild);
+ //flush the events
+ QApplication::processEvents();
+ // Both effects should start with no source invalidations
+ QCOMPARE(effectForParent->nbSourceInvalidations, 0);
+ QCOMPARE(effectForChild->nbSourceInvalidations, 0);
+
+ // Trigger an update of the child graphics effect
+ effectForChild->update();
+ //flush the events
+ QApplication::processEvents();
+ // An update of the effect on the child shouldn't tell that effect that its source has been invalidated
+ QCOMPARE(effectForChild->nbSourceInvalidations, 0);
+ // The effect on the parent should however be notified of an invalidated source
+ QCOMPARE(effectForParent->nbSourceInvalidations, 1);
+}
+
void tst_QGraphicsEffect::itemHasNoContents()
{
QGraphicsRectItem *parent = new QGraphicsRectItem;