diff options
Diffstat (limited to 'tests/auto/widgets')
4 files changed, 207 insertions, 8 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 84466b92d1..f686b5854c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -377,6 +377,8 @@ private slots: void itemClipsChildrenToShape5(); void itemClipsTextChildToShape(); void itemClippingDiscovery(); + void itemContainsChildrenInShape(); + void itemContainsChildrenInShape2(); void ancestorFlags(); void untransformable(); void contextMenuEventPropagation(); @@ -5845,6 +5847,102 @@ void tst_QGraphicsItem::itemClippingDiscovery() QCOMPARE(scene.itemAt(90, 90), (QGraphicsItem *)0); } +class ItemCountsBoundingRectCalls : public QGraphicsRectItem +{ +public: + ItemCountsBoundingRectCalls(const QRectF & rect, QGraphicsItem *parent = 0) + : QGraphicsRectItem(rect, parent), boundingRectCalls(0) {} + QRectF boundingRect () const { + ++boundingRectCalls; + return QGraphicsRectItem::boundingRect(); + } + mutable int boundingRectCalls; +}; + +void tst_QGraphicsItem::itemContainsChildrenInShape() +{ + ItemCountsBoundingRectCalls *parent = new ItemCountsBoundingRectCalls(QRectF(0,0, 10, 10)); + ItemCountsBoundingRectCalls *childOutsideShape = new ItemCountsBoundingRectCalls(QRectF(0,0, 10, 10), parent); + childOutsideShape->setPos(20,0); + + QGraphicsScene scene; + scene.setItemIndexMethod(QGraphicsScene::NoIndex); + scene.addItem(parent); + + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + int oldParentBoundingRectCalls = parent->boundingRectCalls; + int oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // First test that both items are searched if no optimization flags are set + QGraphicsItem* item = scene.itemAt(25,5); + + QVERIFY(item == childOutsideShape); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls > oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + oldParentBoundingRectCalls = parent->boundingRectCalls; + oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // Repeat the test to make sure that no caching/indexing is in effect + item = scene.itemAt(25,5); + + QVERIFY(item == childOutsideShape); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls > oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls == childOutsideShape->boundingRectCalls); + + oldParentBoundingRectCalls = parent->boundingRectCalls; + oldChildBoundingRectCalls = childOutsideShape->boundingRectCalls; + + // Set the optimization flag and make sure that the child is not returned + // and that the child's boundingRect() method is never called. + parent->setFlag(QGraphicsItem::ItemContainsChildrenInShape); + item = scene.itemAt(25,5); + + QVERIFY(!(item)); + QVERIFY(parent->boundingRectCalls > oldParentBoundingRectCalls); + QVERIFY(childOutsideShape->boundingRectCalls == oldChildBoundingRectCalls); + QVERIFY(parent->boundingRectCalls > childOutsideShape->boundingRectCalls); +} + +void tst_QGraphicsItem::itemContainsChildrenInShape2() +{ + //The tested flag behaves almost identically to ItemClipsChildrenToShape + //in terms of optimizations but does not enforce the clip. + //This test makes sure there is no clip. + QGraphicsScene scene; + QGraphicsItem *rect = scene.addRect(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::yellow)); + + QGraphicsItem *ellipse = scene.addEllipse(0, 0, 100, 100, QPen(Qt::NoPen), QBrush(Qt::green)); + ellipse->setParentItem(rect); + + QGraphicsItem *clippedEllipse = scene.addEllipse(0, 0, 50, 50, QPen(Qt::NoPen), QBrush(Qt::blue)); + clippedEllipse->setParentItem(ellipse); + + QGraphicsItem *clippedEllipse2 = scene.addEllipse(0, 0, 25, 25, QPen(Qt::NoPen), QBrush(Qt::red)); + clippedEllipse2->setParentItem(clippedEllipse); + + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemContainsChildrenInShape)); + ellipse->setFlags(QGraphicsItem::ItemContainsChildrenInShape); + QVERIFY(!(ellipse->flags() & QGraphicsItem::ItemClipsChildrenToShape)); + QVERIFY((ellipse->flags() & QGraphicsItem::ItemContainsChildrenInShape)); + + QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); + image.fill(0); + QPainter painter(&image); + painter.setRenderHint(QPainter::Antialiasing); + scene.render(&painter); + painter.end(); + + QCOMPARE(image.pixel(2, 2), QColor(Qt::yellow).rgba()); + QCOMPARE(image.pixel(12, 12), QColor(Qt::red).rgba()); + QCOMPARE(image.pixel(2, 25), QColor(Qt::blue).rgba()); + QCOMPARE(image.pixel(2, 50), QColor(Qt::green).rgba()); +} + void tst_QGraphicsItem::ancestorFlags() { QGraphicsItem *level1 = new QGraphicsRectItem; @@ -5965,11 +6063,27 @@ void tst_QGraphicsItem::ancestorFlags() // Nobody handles child events level21->setHandlesChildEvents(false); - for (int i = 0; i < 2; ++i) { - QGraphicsItem::GraphicsItemFlag flag = !i ? QGraphicsItem::ItemClipsChildrenToShape - : QGraphicsItem::ItemIgnoresTransformations; - int ancestorFlag = !i ? QGraphicsItemPrivate::AncestorClipsChildren - : QGraphicsItemPrivate::AncestorIgnoresTransformations; + for (int i = 0; i < 3; ++i) { + QGraphicsItem::GraphicsItemFlag flag; + int ancestorFlag; + + switch (i) { + case(0): + flag = QGraphicsItem::ItemClipsChildrenToShape; + ancestorFlag = QGraphicsItemPrivate::AncestorClipsChildren; + break; + case(1): + flag = QGraphicsItem::ItemIgnoresTransformations; + ancestorFlag = QGraphicsItemPrivate::AncestorIgnoresTransformations; + break; + case(2): + flag = QGraphicsItem::ItemContainsChildrenInShape; + ancestorFlag = QGraphicsItemPrivate::AncestorContainsChildren; + break; + default: + qFatal("Unknown ancestor flag, please fix!"); + break; + } QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index dfc8465210..a4752126bc 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -267,6 +267,7 @@ private slots: void removeFullyTransparentItem(); void zeroScale(); void focusItemChangedSignal(); + void minimumRenderSize(); // task specific tests below me void task139710_bspTreeCrash(); @@ -4678,6 +4679,78 @@ void tst_QGraphicsScene::focusItemChangedSignal() } +class ItemCountsPaintCalls : public QGraphicsRectItem +{ +public: + ItemCountsPaintCalls(const QRectF & rect, QGraphicsItem *parent = 0) + : QGraphicsRectItem(rect, parent), repaints(0) {} + void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) + { + QGraphicsRectItem::paint(painter, option, widget); + ++repaints; + } + int repaints; +}; + +void tst_QGraphicsScene::minimumRenderSize() +{ + Q_CHECK_PAINTEVENTS + + ItemCountsPaintCalls *bigParent = new ItemCountsPaintCalls(QRectF(0,0,100,100)); + ItemCountsPaintCalls *smallChild = new ItemCountsPaintCalls(QRectF(0,0,10,10), bigParent); + ItemCountsPaintCalls *smallerGrandChild = new ItemCountsPaintCalls(QRectF(0,0,1,1), smallChild); + QGraphicsScene scene; + scene.addItem(bigParent); + + CustomView view; + view.setScene(&scene); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + qApp->processEvents(); + + // Initially, everything should be repainted the same number of times + int viewRepaints = 0; + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(viewRepaints == smallerGrandChild->repaints); + + // Setting a minimum render size should cause a repaint + scene.setMinimumRenderSize(0.5); + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(viewRepaints == smallerGrandChild->repaints); + + // Scaling should cause a repaint of big items only. + view.scale(0.1, 0.1); + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(viewRepaints == smallChild->repaints); + QVERIFY(smallChild->repaints > smallerGrandChild->repaints); + + // Scaling further should cause even fewer items to be repainted + view.scale(0.1, 0.1); // Stacks with previous scale + qApp->processEvents(); + + QTRY_VERIFY(view.repaints > viewRepaints); + viewRepaints = view.repaints; + + QVERIFY(viewRepaints == bigParent->repaints); + QVERIFY(bigParent->repaints > smallChild->repaints); + QVERIFY(smallChild->repaints > smallerGrandChild->repaints); +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; diff --git a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp index d6b7fc20ed..1809cdc16a 100644 --- a/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp +++ b/tests/auto/widgets/kernel/qwidget_window/tst_qwidget_window.cpp @@ -107,8 +107,7 @@ void tst_QWidget_window::cleanupTestCase() } /* Test if the maximum/minimum size constraints - * are propagated from the wid src/widgets/kernel/qwidgetwindow_qpa_p.h -get to the QWidgetWindow + * are propagated from the widget to the QWidgetWindow * independently of whether they were set before or after * window creation (QTBUG-26745). */ diff --git a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp index 21034e8f1b..350ae23d8a 100644 --- a/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp +++ b/tests/auto/widgets/widgets/qspinbox/tst_qspinbox.cpp @@ -393,18 +393,31 @@ void tst_QSpinBox::valueChangedHelper(int value) actualValues << value; } +class MySpinBox: public QSpinBox +{ +public: + MySpinBox(QWidget *parent = 0) : QSpinBox(parent) {} + + void changeEvent(QEvent *ev) { + eventsReceived.append(ev->type()); + } + QList<QEvent::Type> eventsReceived; +}; + void tst_QSpinBox::setReadOnly() { - QSpinBox spin(0); + MySpinBox spin(0); spin.show(); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 1); spin.setReadOnly(true); + QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 1); spin.stepBy(1); QCOMPARE(spin.value(), 2); spin.setReadOnly(false); + QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange << QEvent::ReadOnlyChange); QTest::keyClick(&spin, Qt::Key_Up); QCOMPARE(spin.value(), 3); } |