From b8eb2784a1c1a9812d09fca7c8722624f12dbd1c Mon Sep 17 00:00:00 2001 From: Alexis Menard Date: Fri, 9 Oct 2009 10:19:33 +0200 Subject: Add a test case for task QTBUG-4439. Commit fc3dfc20d487cb4fd2f93bd9fa36eef85a7467a3 fixes the problem. The unpolished items list was modified in between the iteration which means that invokeMethod was never recall if you add an item inside the polishEvent handler. The invokeMethod is called in addItem only when the list is empty right before we add the item in the list. Task-number:QTBUG-4439 Reviewed-by:TrustMe --- tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 26021e0..6b5ad09 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -159,6 +159,7 @@ private slots: void ensureClipping(); void widgetSendsGeometryChanges(); void respectHFW(); + void addChildInpolishEvent(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2716,6 +2717,58 @@ void tst_QGraphicsWidget::respectHFW() #endif } +class PolishWidget : public QGraphicsWidget +{ +public: + + PolishWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : + QGraphicsWidget(parent), mColor(color) + { + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->setBrush(QBrush(mColor)); + painter->drawRect(boundingRect()); + } + + void polishEvent() + { + if (!parentWidget()) { + //We add a child in the polish event for the parent + PolishWidget *childWidget = new PolishWidget(Qt::black, this); + childWidget->setGeometry(QRectF(10,10,30,30)); + } + + QGraphicsWidget::polishEvent(); + mColor = Qt::red; + update(); + numberOfPolish++; + } + + static int numberOfPolish; + +private: + Qt::GlobalColor mColor; +}; + +int PolishWidget::numberOfPolish = 0; + +void tst_QGraphicsWidget::addChildInpolishEvent() +{ + QGraphicsScene scene; + + PolishWidget *parentWidget = new PolishWidget(Qt::white); + scene.addItem(parentWidget); + + QGraphicsView view(&scene); + view.resize(200, 200); + view.show(); + QTest::qWaitForWindowShown(&view); + QCOMPARE(PolishWidget::numberOfPolish, 2); +} + + QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" -- cgit v0.12