diff options
Diffstat (limited to 'tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp')
-rw-r--r-- | tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 744 |
1 files changed, 409 insertions, 335 deletions
diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 46f1d5df5c..950f3ef670 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -26,11 +26,24 @@ ** ****************************************************************************/ +#include <QtWidgets/QApplication> +#include <QtWidgets/QDial> +#include <QtWidgets/QLabel> +#include <QtWidgets/QLineEdit> +#include <QtWidgets/QGraphicsView> +#include <QtWidgets/QGraphicsScene> +#include <QtWidgets/QGraphicsPixmapItem> +#include <QtWidgets/QStyle> +#include <QtWidgets/QStyleFactory> +#include <QtWidgets/QVBoxLayout> + +#include <QtGui/QScreen> #include <QtTest/QtTest> -#include <QtGui> -#include <QtWidgets> +#include <QtCore/QDebug> +#include <QtCore/QLoggingCategory> + #include <private/qgraphicsscene_p.h> #include <private/qgraphicssceneindex_p.h> #include <math.h> @@ -39,7 +52,7 @@ #include <private/qinputmethod_p.h> #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) -#include <windows.h> +#include <QtCore/qt_windows.h> #define Q_CHECK_PAINTEVENTS \ if (::SwitchDesktop(::GetThreadDesktop(::GetCurrentThreadId())) == 0) \ QSKIP("The Graphics View doesn't get the paint events"); @@ -51,6 +64,7 @@ Q_DECLARE_METATYPE(Qt::FocusReason) Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(Qt::AspectRatioMode) Q_DECLARE_METATYPE(Qt::ItemSelectionMode) +Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags) static const int randomX[] = {276, 40, 250, 864, -56, 426, 855, 825, 184, 955, -798, -804, 773, 282, 489, 686, 780, -220, 50, 749, -856, -205, 81, 492, -819, 518, @@ -95,14 +109,16 @@ static const int randomY[] = {603, 70, -318, 843, 450, -637, 199, -527, 407, 964 -588, 864, 234, 225, -303, 493, 246, 153, 338, -378, 377, -819, 140, 136, 467, -849, -326, -533, 166, 252, -994, -699, 904, -566, 621, -752}; +Q_LOGGING_CATEGORY(lcTests, "qt.widgets.tests") + class HoverItem : public QGraphicsRectItem { public: HoverItem() - : QGraphicsRectItem(QRectF(-10, -10, 20, 20)), isHovered(false) + : QGraphicsRectItem(QRectF(-10, -10, 20, 20)) { setAcceptHoverEvents(true); } - bool isHovered; + bool isHovered = false; protected: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) @@ -128,13 +144,13 @@ class EventSpy : public QGraphicsWidget Q_OBJECT public: EventSpy(QObject *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { watched->installEventFilter(this); } EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { scene->addItem(this); watched->installSceneEventFilter(this); @@ -143,7 +159,7 @@ public: int count() const { return _count; } protected: - bool eventFilter(QObject *watched, QEvent *event) + bool eventFilter(QObject *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -151,7 +167,7 @@ protected: return false; } - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -159,13 +175,17 @@ protected: return false; } - int _count; - QEvent::Type spied; + int _count = 0; + const QEvent::Type spied; }; class tst_QGraphicsScene : public QObject { Q_OBJECT +public: + tst_QGraphicsScene(); + static void initMain() { QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling); } + public slots: void cleanup(); @@ -268,13 +288,26 @@ private slots: void taskQTBUG_15977_renderWithDeviceCoordinateCache(); void taskQTBUG_16401_focusItem(); void taskQTBUG_42915_focusNextPrevChild(); + +private: + QRect m_availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); + QSize m_testSize; }; +tst_QGraphicsScene::tst_QGraphicsScene() +{ + const int testSize = qMax(200, m_availableGeometry.width() / 10); + m_testSize.setWidth(testSize); + m_testSize.setHeight(testSize); +} + void tst_QGraphicsScene::cleanup() { // ensure not even skipped tests with custom input context leave it dangling - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); - inputMethodPrivate->testContext = 0; + QInputMethodPrivate *inputMethodPrivate = + QInputMethodPrivate::get(QGuiApplication::inputMethod()); + inputMethodPrivate->testContext = nullptr; + QTRY_VERIFY(QApplication::topLevelWidgets().isEmpty()); } void tst_QGraphicsScene::construction() @@ -287,7 +320,7 @@ void tst_QGraphicsScene::construction() QVERIFY(scene.items(QPolygonF()).isEmpty()); QVERIFY(scene.items(QPainterPath()).isEmpty()); QTest::ignoreMessage(QtWarningMsg, "QGraphicsScene::collidingItems: cannot find collisions for null item"); - QVERIFY(scene.collidingItems(0).isEmpty()); + QVERIFY(scene.collidingItems(nullptr).isEmpty()); QVERIFY(scene.items(QPointF()).isEmpty()); QVERIFY(scene.selectedItems().isEmpty()); QVERIFY(!scene.focusItem()); @@ -301,7 +334,7 @@ static inline const QGraphicsItem *itemAt(const QGraphicsScene &scene, qreal x, void tst_QGraphicsScene::sceneRect() { QGraphicsScene scene; - QSignalSpy sceneRectChanged(&scene, SIGNAL(sceneRectChanged(QRectF))); + QSignalSpy sceneRectChanged(&scene, &QGraphicsScene::sceneRectChanged); QCOMPARE(scene.sceneRect(), QRectF()); QCOMPARE(sceneRectChanged.count(), 0); @@ -435,9 +468,9 @@ void tst_QGraphicsScene::items() scene.removeItem(items.at(5)); delete items.at(5); - QVERIFY(!scene.items().contains(0)); + QVERIFY(!scene.items().contains(nullptr)); delete items.at(7); - QVERIFY(!scene.items().contains(0)); + QVERIFY(!scene.items().contains(nullptr)); } { QGraphicsScene scene; @@ -516,7 +549,7 @@ void tst_QGraphicsScene::itemsBoundingRect() QGraphicsScene scene; - foreach (QRectF rect, rects) { + for (const auto &rect : qAsConst(rects)) { QPainterPath path; path.addRect(rect); QGraphicsPathItem *item = scene.addPath(path); @@ -581,7 +614,7 @@ void tst_QGraphicsScene::items_QPointF() int n = 0; QList<QGraphicsItem *> addedItems; - foreach(QRectF rect, items) { + for (const auto &rect : qAsConst(items)) { QPainterPath path; path.addRect(0, 0, rect.width(), rect.height()); @@ -593,7 +626,8 @@ void tst_QGraphicsScene::items_QPointF() } QList<int> itemIndexes; - foreach (QGraphicsItem *item, scene.items(point)) + const auto &actualItemsAtPoint = scene.items(point); + for (QGraphicsItem *item : actualItemsAtPoint) itemIndexes << addedItems.indexOf(item); QCOMPARE(itemIndexes, itemsAtPoint); @@ -912,12 +946,11 @@ void tst_QGraphicsScene::items_QPainterPath_2() class CustomView : public QGraphicsView { public: - CustomView() : repaints(0) - { } + using QGraphicsView::QGraphicsView; - int repaints; + int repaints = 0; protected: - void paintEvent(QPaintEvent *event) + void paintEvent(QPaintEvent *event) override { ++repaints; QGraphicsView::paintEvent(event); @@ -927,7 +960,7 @@ protected: void tst_QGraphicsScene::selectionChanged() { QGraphicsScene scene(0, 0, 1000, 1000); - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QCOMPARE(spy.count(), 0); QPainterPath path; @@ -997,7 +1030,7 @@ void tst_QGraphicsScene::selectionChanged() void tst_QGraphicsScene::selectionChanged2() { QGraphicsScene scene; - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QGraphicsItem *item1 = scene.addRect(0, 0, 100, 100); QGraphicsItem *item2 = scene.addRect(100, 100, 100, 100); @@ -1009,13 +1042,13 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1024,13 +1057,13 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(150, 150)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(150, 150)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); @@ -1040,7 +1073,7 @@ void tst_QGraphicsScene::selectionChanged2() event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); event.setModifiers(Qt::ControlModifier); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); @@ -1049,7 +1082,7 @@ void tst_QGraphicsScene::selectionChanged2() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(QPointF(50, 50)); event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1065,10 +1098,12 @@ void tst_QGraphicsScene::addItem() QGraphicsScene scene; CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); view.setScene(&scene); + view.resize(m_testSize); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - qApp->processEvents(); + QCoreApplication::processEvents(); view.repaints = 0; scene.addItem(path); @@ -1115,14 +1150,14 @@ void tst_QGraphicsScene::addEllipse() QCOMPARE(ellipse->pen(), QPen(Qt::red)); QCOMPARE(ellipse->brush(), QBrush(Qt::blue)); QCOMPARE(ellipse->rect(), QRectF(-10, -10, 20, 20)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 0, 0), ellipse); QVERIFY(scene.items(QPointF(-10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, -9.9, 0), ellipse); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)ellipse); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 0, -9.9), ellipse); + QCOMPARE(itemAt(scene, 0, 9.9), ellipse); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)ellipse); + QCOMPARE(itemAt(scene, 9.9, 0), ellipse); QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); } @@ -1136,15 +1171,15 @@ void tst_QGraphicsScene::addLine() QCOMPARE(line->pos(), QPointF()); QCOMPARE(line->pen(), pen); QCOMPARE(line->line(), QLineF(-10, -10, 20, 20)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)line); - QCOMPARE(itemAt(scene, -10, -10), (QGraphicsItem *)line); + QCOMPARE(itemAt(scene, 0, 0), line); + QCOMPARE(itemAt(scene, -10, -10), line); QVERIFY(scene.items(QPointF(-9.9, 0)).isEmpty()); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); QVERIFY(scene.items(QPointF(0, -9.9)).isEmpty()); QVERIFY(scene.items(QPointF(0, 9.9)).isEmpty()); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(9.9, 0)).isEmpty()); - QCOMPARE(itemAt(scene, 10, 10), (QGraphicsItem *)line); + QCOMPARE(itemAt(scene, 10, 10), line); } void tst_QGraphicsScene::addPath() @@ -1162,16 +1197,16 @@ void tst_QGraphicsScene::addPath() path->setPen(QPen(Qt::red, 0)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, -9.9, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 9.9, 30), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 20.1), (QGraphicsItem *)path); - QCOMPARE(itemAt(scene, 0, 39.9), (QGraphicsItem *)path); + QCOMPARE(itemAt(scene, 0, 0), path); + QCOMPARE(itemAt(scene, -9.9, 0), path); + QCOMPARE(itemAt(scene, 9.9, 0), path); + QCOMPARE(itemAt(scene, 0, -9.9), path); + QCOMPARE(itemAt(scene, 0, 9.9), path); + QCOMPARE(itemAt(scene, 0, 30), path); + QCOMPARE(itemAt(scene, -9.9, 30), path); + QCOMPARE(itemAt(scene, 9.9, 30), path); + QCOMPARE(itemAt(scene, 0, 20.1), path); + QCOMPARE(itemAt(scene, 0, 39.9), path); QVERIFY(scene.items(QPointF(-10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); @@ -1193,10 +1228,10 @@ void tst_QGraphicsScene::addPixmap() QCOMPARE(pixmap->pos(), QPointF()); QCOMPARE(pixmap->pixmap(), pix); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, pix.width() - 1, 0), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, 0, pix.height() - 1), (QGraphicsItem *)pixmap); - QCOMPARE(itemAt(scene, pix.width() - 1, pix.height() - 1), (QGraphicsItem *)pixmap); + QCOMPARE(itemAt(scene, 0, 0), pixmap); + QCOMPARE(itemAt(scene, pix.width() - 1, 0), pixmap); + QCOMPARE(itemAt(scene, 0, pix.height() - 1), pixmap); + QCOMPARE(itemAt(scene, pix.width() - 1, pix.height() - 1), pixmap); QVERIFY(scene.items(QPointF(-1, -1)).isEmpty()); QVERIFY(scene.items(QPointF(pix.width() - 1, -1)).isEmpty()); @@ -1218,14 +1253,14 @@ void tst_QGraphicsScene::addRect() rect->setPen(QPen(Qt::red, 0)); - QCOMPARE(itemAt(scene, 0, 0), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, -10, -10), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, -9.9, 0), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 0, 0),rect); + QCOMPARE(itemAt(scene, -10, -10), rect); + QCOMPARE(itemAt(scene, -9.9, 0), rect); QVERIFY(scene.items(QPointF(-10, 10)).isEmpty()); - QCOMPARE(itemAt(scene, 0, -9.9), (QGraphicsItem *)rect); - QCOMPARE(itemAt(scene, 0, 9.9), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 0, -9.9), rect); + QCOMPARE(itemAt(scene, 0, 9.9), rect); QVERIFY(scene.items(QPointF(10, -10)).isEmpty()); - QCOMPARE(itemAt(scene, 9.9, 0), (QGraphicsItem *)rect); + QCOMPARE(itemAt(scene, 9.9, 0), rect); QVERIFY(scene.items(QPointF(10, 10)).isEmpty()); } @@ -1271,6 +1306,7 @@ void tst_QGraphicsScene::removeItem() scene.setSceneRect(-50, -50, 100, 100); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setFixedSize(150, 150); view.show(); QApplication::setActiveWindow(&view); @@ -1342,7 +1378,7 @@ void tst_QGraphicsScene::focusItem() class FocusItem : public QGraphicsTextItem { protected: - void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { QVERIFY(!scene()->focusItem()); } @@ -1359,14 +1395,14 @@ void tst_QGraphicsScene::focusItemLostFocus() scene.addItem(item); item->setFocus(); - QCOMPARE(scene.focusItem(), (QGraphicsItem *)item); + QCOMPARE(scene.focusItem(), item); item->clearFocus(); } class ClearTestItem : public QGraphicsRectItem { public: - ClearTestItem(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} + using QGraphicsRectItem::QGraphicsRectItem; ~ClearTestItem() { qDeleteAll(items); } QList<QGraphicsItem *> items; }; @@ -1389,7 +1425,7 @@ void tst_QGraphicsScene::clear() scene.setItemIndexMethod(QGraphicsScene::NoIndex); scene.addItem(firstItem); scene.addItem(secondItem); - QCOMPARE(scene.items().at(0), (QGraphicsItem*)firstItem); + QCOMPARE(scene.items().at(0), firstItem); QCOMPARE(scene.items().at(1), secondItem); ClearTestItem *thirdItem = new ClearTestItem(firstItem); @@ -1441,7 +1477,7 @@ void tst_QGraphicsScene::setFocusItem() QVERIFY(item->hasFocus()); QVERIFY(!item2->hasFocus()); - scene.setFocusItem(0); + scene.setFocusItem(nullptr); QVERIFY(!item->hasFocus()); QVERIFY(!item2->hasFocus()); @@ -1562,26 +1598,26 @@ void tst_QGraphicsScene::hoverEvents_siblings() Q_CHECK_PAINTEVENTS QGraphicsScene scene; - QGraphicsItem *lastItem = 0; + QGraphicsItem *lastItem = nullptr; QList<HoverItem *> items; for (int i = 0; i < 15; ++i) { - QGraphicsItem *item = new HoverItem; + auto item = new HoverItem; scene.addItem(item); - items << (HoverItem *)item; - if (lastItem) { + items << item; + if (lastItem) item->setPos(lastItem->pos() + QPointF(sin(i / 3.0) * 17, cos(i / 3.0) * 17)); - } item->setZValue(i); lastItem = item; } QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setRenderHint(QPainter::Antialiasing, true); view.setMinimumSize(400, 300); view.rotate(10); view.scale(1.7, 1.7); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1604,8 +1640,8 @@ void tst_QGraphicsScene::hoverEvents_siblings() mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here QTRY_VERIFY(items.at(i)->isHovered); if (j && i > 0) @@ -1621,8 +1657,8 @@ void tst_QGraphicsScene::hoverEvents_siblings() mouseEvent.setScenePos(QPointF(-1000, -1000)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here } } @@ -1631,12 +1667,12 @@ void tst_QGraphicsScene::hoverEvents_parentChild() Q_CHECK_PAINTEVENTS QGraphicsScene scene; - QGraphicsItem *lastItem = 0; + QGraphicsItem *lastItem = nullptr; QList<HoverItem *> items; for (int i = 0; i < 15; ++i) { - QGraphicsItem *item = new HoverItem; + auto item = new HoverItem; scene.addItem(item); - items << (HoverItem *)item; + items << item; if (lastItem) { item->setParentItem(lastItem); item->setPos(sin(i / 3.0) * 17, cos(i / 3.0) * 17); @@ -1645,12 +1681,13 @@ void tst_QGraphicsScene::hoverEvents_parentChild() } QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setRenderHint(QPainter::Antialiasing, true); view.setMinimumSize(400, 300); view.rotate(10); view.scale(1.7, 1.7); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QGraphicsSceneMouseEvent mouseEvent(QEvent::GraphicsSceneMouseMove); @@ -1669,8 +1706,8 @@ void tst_QGraphicsScene::hoverEvents_parentChild() mouseEvent.setScenePos(items.at(i)->mapToScene(0, 0)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here QTRY_VERIFY(items.at(i)->isHovered); if (i < 14) @@ -1683,8 +1720,8 @@ void tst_QGraphicsScene::hoverEvents_parentChild() mouseEvent.setScenePos(QPointF(-1000, -1000)); QApplication::sendEvent(&scene, &mouseEvent); - qApp->processEvents(); // this posts updates from the scene to the view - qApp->processEvents(); // which trigger a repaint here + QCoreApplication::processEvents(); // this posts updates from the scene to the view + QCoreApplication::processEvents(); // which trigger a repaint here } } @@ -1712,23 +1749,23 @@ void tst_QGraphicsScene::createItemGroup() // All items in children1 are children of parent1 QGraphicsItem *parent1 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children1) + for (QGraphicsItem *item : qAsConst(children1)) item->setParentItem(parent1); QGraphicsItemGroup *group = scene.createItemGroup(children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); group = scene.createItemGroup(children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); // All items in children2 are children of parent2 QGraphicsItem *parent2 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children2) + for (QGraphicsItem *item : qAsConst(children2)) item->setParentItem(parent2); // Now make parent2 a child of parent1, so all children2 are also children @@ -1738,21 +1775,21 @@ void tst_QGraphicsScene::createItemGroup() // The children2 group should still have parent2 as their common ancestor. group = scene.createItemGroup(children2); QCOMPARE(group->parentItem(), parent2); - QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children2.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children2.first()->parentItem(), parent2); // But the set of both children2 and children1 share only parent1. group = scene.createItemGroup(children2 + children1); QCOMPARE(group->parentItem(), parent1); - QCOMPARE(children1.first()->parentItem(), (QGraphicsItem *)group); - QCOMPARE(children2.first()->parentItem(), (QGraphicsItem *)group); + QCOMPARE(children1.first()->parentItem(), group); + QCOMPARE(children2.first()->parentItem(), group); scene.destroyItemGroup(group); QCOMPARE(children1.first()->parentItem(), parent1); QCOMPARE(children2.first()->parentItem(), parent1); // Fixup the parent-child chain - foreach (QGraphicsItem *item, children2) + for (QGraphicsItem *item : qAsConst(children2)) item->setParentItem(parent2); // These share no common parent @@ -1762,7 +1799,7 @@ void tst_QGraphicsScene::createItemGroup() // Make children3 children of parent3 QGraphicsItem *parent3 = scene.addRect(QRectF(-10, -10, 20, 20)); - foreach (QGraphicsItem *item, children3) + for (QGraphicsItem *item : qAsConst(children3)) item->setParentItem(parent3); // These should have parent3 as a parent @@ -1794,15 +1831,14 @@ void tst_QGraphicsScene::createItemGroup() class EventTester : public QGraphicsEllipseItem { public: - EventTester() - : QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)), ignoreMouse(false) + EventTester() : QGraphicsEllipseItem(QRectF(-10, -10, 20, 20)) { } - bool ignoreMouse; - QList<QEvent::Type> eventTypes; + bool ignoreMouse = false; + QVector<QEvent::Type> eventTypes; protected: - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { eventTypes << QEvent::Type(event->type()); switch (event->type()) { @@ -1813,6 +1849,7 @@ protected: event->ignore(); return true; } + break; default: break; } @@ -1867,7 +1904,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.size(), 0); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); + QCOMPARE(scene.mouseGrabberItem(), d); // Send a move QApplication::sendEvent(&scene, &moveEvent); @@ -1876,7 +1913,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.size(), 0); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)d); + QCOMPARE(scene.mouseGrabberItem(), d); // Send a release QApplication::sendEvent(&scene, &releaseEvent); @@ -1898,7 +1935,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(1), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send another press, with a button that isn't actually accepted QApplication::sendEvent(&scene, &pressEvent); @@ -1908,7 +1945,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(2), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send a move QApplication::sendEvent(&scene, &moveEvent); @@ -1917,7 +1954,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(3), QEvent::GraphicsSceneMouseMove); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Send a release QApplication::sendEvent(&scene, &releaseEvent); @@ -1950,7 +1987,7 @@ void tst_QGraphicsScene::mouseEventPropagation() QCOMPARE(c->eventTypes.at(7), QEvent::GraphicsSceneMousePress); QCOMPARE(b->eventTypes.size(), 0); QCOMPARE(a->eventTypes.size(), 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)c); + QCOMPARE(scene.mouseGrabberItem(), c); // Clicking outside the items removes the mouse grabber } @@ -1999,7 +2036,7 @@ void tst_QGraphicsScene::mouseEventPropagation_ignore() QCOMPARE(d->eventTypes.at(0), QEvent::GrabMouse); QCOMPARE(d->eventTypes.at(1), QEvent::GraphicsSceneMousePress); QCOMPARE(d->eventTypes.at(2), QEvent::UngrabMouse); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)a); + QCOMPARE(scene.mouseGrabberItem(), a); a->ignoreMouse = true; @@ -2115,7 +2152,7 @@ public: QVector<QPointF> mouseMovePoints; protected: - void mouseMoveEvent(QGraphicsSceneMouseEvent *event) + void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override { mouseMovePoints << event->scenePos(); } @@ -2140,22 +2177,17 @@ void tst_QGraphicsScene::mouseEventPropagation_mouseMove() class DndTester : public QGraphicsEllipseItem { public: - DndTester(const QRectF &rect) - : QGraphicsEllipseItem(rect), lastEvent(0), - ignoresDragEnter(false), ignoresDragMove(false) - - { - } + using QGraphicsEllipseItem::QGraphicsEllipseItem; ~DndTester() { delete lastEvent; } - QGraphicsSceneDragDropEvent *lastEvent; + QGraphicsSceneDragDropEvent *lastEvent = nullptr; QList<QEvent::Type> eventList; - bool ignoresDragEnter; - bool ignoresDragMove; + bool ignoresDragEnter = false; + bool ignoresDragMove = false; protected: void dragEnterEvent(QGraphicsSceneDragDropEvent *event) @@ -2218,21 +2250,21 @@ void tst_QGraphicsScene::dragAndDrop_simple() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); } { // Move inside the item without setAcceptDrops - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2241,7 +2273,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() item->setAcceptDrops(true); { // Move inside the item with setAcceptDrops - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2255,7 +2287,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Another move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->mapToScene(5, 5)), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->mapToScene(5, 5)), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2268,7 +2300,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2281,7 +2313,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Move inside the item again - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2295,7 +2327,7 @@ void tst_QGraphicsScene::dragAndDrop_simple() } { // Drop inside the item - QDropEvent drop(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent drop(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &drop); QVERIFY(drop.isAccepted()); QCOMPARE(drop.dropAction(), Qt::CopyAction); @@ -2322,13 +2354,13 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2338,7 +2370,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() } { // Move outside the item - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2353,7 +2385,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2369,7 +2401,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() { // Move inside the item - QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(item->scenePos()), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2378,7 +2410,7 @@ void tst_QGraphicsScene::dragAndDrop_disabledOrInvisible() } // Dummy drop event to keep the Mac from crashing. - QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dropEvent); } @@ -2405,14 +2437,14 @@ void tst_QGraphicsScene::dragAndDrop_propagate() QMimeData mimeData; // Initial drag enter for the scene - QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragEnterEvent dragEnter(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragEnter); QVERIFY(dragEnter.isAccepted()); QCOMPARE(dragEnter.dropAction(), Qt::CopyAction); { // Move outside the items - QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2421,7 +2453,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move inside item1 - QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2432,7 +2464,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { // Move into the intersection item1-item2 - QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); // move does not propagate, (ignoresDragMove = true) QCOMPARE(item1->eventList.size(), 3); @@ -2443,7 +2475,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move into the item2 - QDragMoveEvent dragMove(view.mapFromScene(15, 15), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(15, 15), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(!dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::CopyAction); @@ -2453,7 +2485,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } { // Move inside item1 - QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(-5, -5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2467,7 +2499,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { item2->ignoresDragEnter = true; // Move into the intersection item1-item2 - QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDragMoveEvent dragMove(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dragMove); QVERIFY(dragMove.isAccepted()); // dragEnter propagates down to item1, which then accepts the move event. QCOMPARE(dragMove.dropAction(), Qt::IgnoreAction); @@ -2480,7 +2512,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() { item2->ignoresDragEnter = false; // Drop on the intersection item1-item2 - QDropEvent drop(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent drop(view.mapFromScene(5, 5), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &drop); QVERIFY(drop.isAccepted()); QCOMPARE(drop.dropAction(), Qt::CopyAction); @@ -2491,7 +2523,7 @@ void tst_QGraphicsScene::dragAndDrop_propagate() } // Dummy drop event to keep the Mac from crashing. - QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, 0); + QDropEvent dropEvent(QPoint(0, 0), Qt::CopyAction, &mimeData, Qt::LeftButton, {}); QApplication::sendEvent(view.viewport(), &dropEvent); } #endif @@ -2580,6 +2612,8 @@ void tst_QGraphicsScene::render() pix.fill(Qt::blue); QGraphicsView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); QGraphicsScene scene(&view); scene.addEllipse(QRectF(-10, -10, 20, 20), QPen(Qt::black, 0), QBrush(Qt::white)); scene.addEllipse(QRectF(-2, -7, 4, 4), QPen(Qt::black, 0), QBrush(Qt::yellow))->setZValue(1); @@ -2642,6 +2676,7 @@ void tst_QGraphicsScene::render() gridLayout->addWidget(newLabel, 2, 0); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(gridLayout); widget.show(); @@ -2660,33 +2695,32 @@ void tst_QGraphicsScene::renderItemsWithNegativeWidthOrHeight() #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED) || defined(Q_OS_WINRT) QSKIP("Test only works on platforms with resizable windows"); #endif - - QGraphicsScene scene(0, 0, 150, 150); + QGraphicsScene scene(0, 0, m_testSize.width(), m_testSize.height()); // Add item with negative width. - QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, -150, 50); + QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, -m_testSize.width(), 50); item1->setBrush(Qt::red); - item1->setPos(150, 50); + item1->setPos(m_testSize.width(), 50); scene.addItem(item1); // Add item with negative height. - QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 50, -150); + QGraphicsRectItem *item2 = new QGraphicsRectItem(0, 0, 50, -m_testSize.height()); item2->setBrush(Qt::blue); - item2->setPos(50, 150); + item2->setPos(50, m_testSize.height()); scene.addItem(item2); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); view.setFrameStyle(QFrame::NoFrame); - view.resize(150, 150); view.show(); - QCOMPARE(view.viewport()->size(), QSize(150, 150)); + QTRY_COMPARE(view.viewport()->size(), m_testSize); QImage expected(view.viewport()->size(), QImage::Format_RGB32); view.viewport()->render(&expected); // Make sure the scene background is the same as the viewport background. scene.setBackgroundBrush(view.viewport()->palette().brush(view.viewport()->backgroundRole())); - QImage actual(150, 150, QImage::Format_RGB32); + QImage actual(m_testSize, QImage::Format_RGB32); QPainter painter(&actual); scene.render(&painter); painter.end(); @@ -2710,6 +2744,8 @@ void tst_QGraphicsScene::contextMenuEvent() QVERIFY(scene.hasFocus()); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.show(); view.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -2726,11 +2762,11 @@ void tst_QGraphicsScene::contextMenuEvent() class ContextMenuItem : public QGraphicsRectItem { public: - ContextMenuItem() : QGraphicsRectItem(0, 0, 100, 100) + ContextMenuItem(const QSize &s) : QGraphicsRectItem(0, 0, s.width(), s.height()) { setBrush(Qt::red); } protected: - void contextMenuEvent(QGraphicsSceneContextMenuEvent *) + void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override { /* just accept */ } }; @@ -2740,26 +2776,30 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() QSKIP("Test fails on some Android devices (QTBUG-44430)"); #endif - QGraphicsScene scene(0, 0, 200, 200); - ContextMenuItem *item = new ContextMenuItem; + QGraphicsScene scene(0, 0, m_testSize.width(), m_testSize.height()); + const QSize itemSize = m_testSize / 2; + ContextMenuItem *item = new ContextMenuItem(itemSize); item->setFlag(QGraphicsItem::ItemIgnoresTransformations); scene.addItem(item); QWidget topLevel; + topLevel.setWindowTitle(QTest::currentTestFunction()); + topLevel.resize(m_testSize); QGraphicsView view(&scene, &topLevel); - view.resize(200, 200); topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); + + { - QPoint pos(50, 50); + QPoint pos(itemSize.width() / 2, itemSize.height() / 2); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { - QPoint pos(150, 150); + QPoint pos(itemSize.width() * 3 / 2, itemSize.height() * 3 / 2); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); @@ -2767,14 +2807,14 @@ void tst_QGraphicsScene::contextMenuEvent_ItemIgnoresTransformations() } view.scale(1.5, 1.5); { - QPoint pos(25, 25); + QPoint pos(itemSize.width() / 4, itemSize.height() / 4); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); } { - QPoint pos(55, 55); + QPoint pos(itemSize.width() / 2 + 5, itemSize.height() / 2 + 5); QContextMenuEvent event(QContextMenuEvent::Keyboard, pos, view.viewport()->mapToGlobal(pos)); event.ignore(); QApplication::sendEvent(view.viewport(), &event); @@ -2790,14 +2830,14 @@ void tst_QGraphicsScene::update() QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 100, 100); rect->setPen(QPen(Qt::black, 0)); scene.addItem(rect); - qApp->processEvents(); + QCoreApplication::processEvents(); rect->setPos(-100, -100); // This function forces indexing itemAt(scene, 0, 0); qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); - QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); + QSignalSpy spy(&scene, &QGraphicsScene::changed); // We update the scene. scene.update(); @@ -2806,12 +2846,13 @@ void tst_QGraphicsScene::update() itemAt(scene, 0, 0); // This will process the pending update - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); // Check that the update region is correct QCOMPARE(spy.count(), 1); QRectF region; - foreach (QRectF rectF, qvariant_cast<QList<QRectF> >(spy.at(0).at(0))) + const auto &rects = qvariant_cast<QList<QRectF> >(spy.at(0).at(0)); + for (const auto &rectF : rects) region |= rectF; QCOMPARE(region, QRectF(-100, -100, 200, 200)); } @@ -2821,9 +2862,11 @@ void tst_QGraphicsScene::update2() QGraphicsScene scene; scene.setSceneRect(-200, -200, 200, 200); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QTRY_VERIFY(view.repaints >= 1); view.repaints = 0; @@ -2831,13 +2874,13 @@ void tst_QGraphicsScene::update2() // Make sure QGraphicsScene::update only requires one event-loop iteration // before the view is updated. scene.update(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_COMPARE(view.repaints, 1); view.repaints = 0; // The same for partial scene updates. scene.update(QRectF(-100, -100, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(view.repaints, 1); } @@ -2853,7 +2896,7 @@ void tst_QGraphicsScene::views() QCOMPARE(scene.views().size(), 2); QVERIFY(scene.views().contains(&view1)); - view.setScene(0); + view.setScene(nullptr); QCOMPARE(scene.views().size(), 1); QCOMPARE(scene.views().at(0), &view1); @@ -2871,12 +2914,12 @@ void tst_QGraphicsScene::views() class CustomScene : public QGraphicsScene { public: - CustomScene() : gotTimerEvent(false) + CustomScene() { startTimer(10); } - bool gotTimerEvent; + bool gotTimerEvent = false; protected: - void timerEvent(QTimerEvent *) + void timerEvent(QTimerEvent *) override { gotTimerEvent = true; } @@ -2893,7 +2936,7 @@ void tst_QGraphicsScene::testEvent() class DisabledItemTester : public QGraphicsRectItem { public: - DisabledItemTester(const QRectF &rect, QGraphicsItem *parent = 0) + DisabledItemTester(const QRectF &rect, QGraphicsItem *parent = nullptr) : QGraphicsRectItem(rect, parent) { } @@ -2901,13 +2944,13 @@ public: QList<QEvent::Type> receivedSceneEventFilters; protected: - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { receivedSceneEventFilters << event->type(); return QGraphicsRectItem::sceneEventFilter(watched, event); } - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { receivedSceneEvents << event->type(); return QGraphicsRectItem::sceneEvent(event); @@ -2965,11 +3008,9 @@ void tst_QGraphicsScene::eventsToDisabledItems() class ExposedPixmapItem : public QGraphicsPixmapItem { public: - ExposedPixmapItem(QGraphicsItem *item = 0) - : QGraphicsPixmapItem(item) - { } + using QGraphicsPixmapItem::QGraphicsPixmapItem; - void paint(QPainter *, const QStyleOptionGraphicsItem *option, QWidget *) + void paint(QPainter *, const QStyleOptionGraphicsItem *option, QWidget *) override { exposed = option->exposedRect; } @@ -3013,8 +3054,9 @@ void tst_QGraphicsScene::tabFocus_emptyScene() QWidget widget; widget.setLayout(layout); + widget.setWindowTitle(QTest::currentTestFunction()); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3060,9 +3102,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3112,18 +3155,18 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusableItems() QVERIFY(!view->viewport()->hasFocus()); QVERIFY(!scene.hasFocus()); QVERIFY(!item->hasFocus()); - QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); + QCOMPARE(scene.focusItem(), item); // Check that the correct item regains focus. widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QVERIFY(view->hasFocus()); QTRY_VERIFY(scene.isActive()); QVERIFY(view->viewport()->hasFocus()); QVERIFY(scene.hasFocus()); - QCOMPARE(scene.focusItem(), static_cast<QGraphicsItem *>(item)); + QCOMPARE(scene.focusItem(), item); QVERIFY(item->hasFocus()); } @@ -3131,14 +3174,13 @@ class FocusWidget : public QGraphicsWidget { Q_OBJECT public: - FocusWidget(QGraphicsItem *parent = 0) - : QGraphicsWidget(parent), tabs(0), backTabs(0) + FocusWidget(QGraphicsItem *parent = nullptr) : QGraphicsWidget(parent) { setFocusPolicy(Qt::StrongFocus); resize(100, 100); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) override { if (option->state & QStyle::State_HasFocus) { painter->fillRect(rect(), Qt::blue); @@ -3152,11 +3194,11 @@ public: } } - int tabs; - int backTabs; + int tabs = 0; + int backTabs = 0; protected: - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { if (event->type() == QEvent::KeyPress) { QKeyEvent *k = static_cast<QKeyEvent *>(event); @@ -3168,9 +3210,9 @@ protected: return QGraphicsWidget::sceneEvent(event); } - void focusInEvent(QFocusEvent *) + void focusInEvent(QFocusEvent *) override { update(); } - void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { update(); } }; @@ -3195,9 +3237,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3236,7 +3279,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithFocusWidgets() widget.hide(); QTest::qWait(15); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3279,9 +3322,10 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QTest::currentTestFunction()); widget.setLayout(layout); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -3366,7 +3410,7 @@ void tst_QGraphicsScene::tabFocus_sceneWithNestedFocusWidgets() widget.hide(); QTest::qWait(12); widget.show(); - qApp->setActiveWindow(&widget); + QApplication::setActiveWindow(&widget); widget.activateWindow(); QVERIFY(QTest::qWaitForWindowActive(&widget)); QTRY_VERIFY(widget1->hasFocus()); @@ -3390,11 +3434,11 @@ void tst_QGraphicsScene::style() QCOMPARE(sceneSpy.count(), 1); QCOMPARE(proxySpy.count(), 1); QCOMPARE(editSpy.count(), 1); - QCOMPARE(scene.style(), (QStyle *)windowsStyle); - QCOMPARE(proxy->style(), (QStyle *)windowsStyle); - QCOMPARE(edit->style(), (QStyle *)windowsStyle); + QCOMPARE(scene.style(), windowsStyle.data()); + QCOMPARE(proxy->style(), windowsStyle.data()); + QCOMPARE(edit->style(), windowsStyle.data()); - scene.setStyle(0); + scene.setStyle(nullptr); QCOMPARE(sceneSpy.count(), 2); QCOMPARE(proxySpy.count(), 2); QCOMPARE(editSpy.count(), 2); @@ -3411,11 +3455,12 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() for (int i = 0; i < 2; ++i) { // trigger delayed item indexing - qApp->processEvents(); + QCoreApplication::processEvents(); scene.setSceneRect(0, 0, 10000, 10000); // delete all items in the scene - pointers are now likely to be recycled - foreach (QGraphicsItem *item, scene.items()) { + const auto &items = scene.items(); + for (QGraphicsItem *item : items) { scene.removeItem(item); delete item; } @@ -3427,7 +3472,7 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() } // trigger delayed item indexing for the first 1000 items - qApp->processEvents(); + QCoreApplication::processEvents(); // add 1000 more items - the BSP tree is now resized for (int i = 0; i < 1000; ++i) { @@ -3437,7 +3482,8 @@ void tst_QGraphicsScene::task139710_bspTreeCrash() // get items from the BSP tree and use them. there was junk in the tree // the second time this happened. - foreach (QGraphicsItem *item, scene.items(QRectF(0, 0, 1000, 1000))) + const auto &itemsWithin = scene.items(QRectF(0, 0, 1000, 1000)); + for (QGraphicsItem *item : itemsWithin) item->moveBy(0, 0); } } @@ -3446,7 +3492,7 @@ void tst_QGraphicsScene::task139782_containsItemBoundingRect() { // The item in question has a scene bounding rect of (10, 10, 50, 50) QGraphicsScene scene(0.0, 0.0, 200.0, 200.0); - QGraphicsRectItem *item = new QGraphicsRectItem(0.0, 0.0, 50.0, 50.0, 0); + QGraphicsRectItem *item = new QGraphicsRectItem(0.0, 0.0, 50.0, 50.0, nullptr); scene.addItem(item); item->setPos(10.0, 10.0); @@ -3476,7 +3522,8 @@ void tst_QGraphicsScene::task160653_selectionChanged() QGraphicsScene scene(0, 0, 100, 100); scene.addItem(new QGraphicsRectItem(0, 0, 20, 20)); scene.addItem(new QGraphicsRectItem(30, 30, 20, 20)); - foreach (QGraphicsItem *item, scene.items()) { + const auto &items = scene.items(); + for (QGraphicsItem *item : items) { item->setFlags( item->flags() | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); item->setSelected(true); @@ -3484,12 +3531,14 @@ void tst_QGraphicsScene::task160653_selectionChanged() QVERIFY(scene.items().size() > 1); QCOMPARE(scene.items().size(), scene.selectedItems().size()); - QSignalSpy spy(&scene, SIGNAL(selectionChanged())); + QSignalSpy spy(&scene, &QGraphicsScene::selectionChanged); QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); QTest::mouseClick( - view.viewport(), Qt::LeftButton, 0, view.mapFromScene(scene.items().first()->scenePos())); + view.viewport(), Qt::LeftButton, {}, view.mapFromScene(scene.items().first()->scenePos())); QCOMPARE(spy.count(), 1); } @@ -3574,17 +3623,21 @@ void tst_QGraphicsScene::sorting() scene.addItem(t_1); - foreach (QGraphicsItem *item, scene.items()) + const auto &items = scene.items(); + for (QGraphicsItem *item : items) item->setFlag(QGraphicsItem::ItemIsSelectable); // QGraphicsView view(&scene); // view.setDragMode(QGraphicsView::RubberBandDrag); // view.show(); - qDebug() << "items: {"; - foreach (QGraphicsItem *item, scene.items(QRectF(32, 31, 4, 55))) - qDebug() << "\t" << item->data(0).toString(); - qDebug() << "}"; + if (lcTests().isDebugEnabled()) { + qCDebug(lcTests) << "items: {"; + const auto &itemsWithin = scene.items(QRectF(32, 31, 4, 55)); + for (QGraphicsItem *item : itemsWithin) + qCDebug(lcTests).nospace() << '\t' << item->data(0).toString(); + qCDebug(lcTests) << '}'; + } QCOMPARE(scene.items(QRectF(32, 31, 4, 55)), QList<QGraphicsItem *>() @@ -3664,11 +3717,11 @@ void tst_QGraphicsScene::changedSignal() QFETCH(bool, withView); QGraphicsScene scene; ChangedListener cl; - connect(&scene, SIGNAL(changed(QList<QRectF>)), &cl, SLOT(changed(QList<QRectF>))); + connect(&scene, &QGraphicsScene::changed, &cl, &ChangedListener::changed); - QGraphicsView *view = 0; + QScopedPointer<QGraphicsView> view; if (withView) - view = new QGraphicsView(&scene); + view.reset(new QGraphicsView(&scene)); QGraphicsRectItem *rect = new QGraphicsRectItem(0, 0, 10, 10); rect->setPen(QPen(Qt::black, 0)); @@ -3682,16 +3735,13 @@ void tst_QGraphicsScene::changedSignal() rect->setPos(20, 0); QCOMPARE(cl.changes.size(), 1); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(cl.changes.size(), 2); QCOMPARE(cl.changes.at(1).size(), 2); QCOMPARE(cl.changes.at(1).first(), QRectF(0, 0, 10, 10)); QCOMPARE(cl.changes.at(1).last(), QRectF(20, 0, 10, 10)); QCOMPARE(scene.sceneRect(), QRectF(0, 0, 30, 10)); - - if (withView) - delete view; } void tst_QGraphicsScene::stickyFocus_data() @@ -3718,7 +3768,7 @@ void tst_QGraphicsScene::stickyFocus() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setScenePos(QPointF(-10, -10)); // outside item event.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(text->hasFocus(), sticky); } @@ -3736,43 +3786,51 @@ void tst_QGraphicsScene::sendEvent() void tst_QGraphicsScene::inputMethod_data() { - QTest::addColumn<int>("flags"); + QTest::addColumn<QGraphicsItem::GraphicsItemFlags>("flags"); QTest::addColumn<bool>("callFocusItem"); - QTest::newRow("0") << 0 << false; - QTest::newRow("1") << (int)QGraphicsItem::ItemAcceptsInputMethod << false; - QTest::newRow("2") << (int)QGraphicsItem::ItemIsFocusable << false; + QTest::newRow("0") << QGraphicsItem::GraphicsItemFlags() << false; + QTest::newRow("1") << QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemAcceptsInputMethod) << false; + QTest::newRow("2") << QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsFocusable) << false; QTest::newRow("3") << - (int)(QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true; + (QGraphicsItem::ItemAcceptsInputMethod|QGraphicsItem::ItemIsFocusable) << true; } class InputMethodTester : public QGraphicsRectItem { - void inputMethodEvent(QInputMethodEvent *) { ++eventCalls; } - QVariant inputMethodQuery(Qt::InputMethodQuery) const { ++queryCalls; return QVariant(); } + void inputMethodEvent(QInputMethodEvent *) override { ++eventCalls; } + QVariant inputMethodQuery(Qt::InputMethodQuery) const override + { + ++queryCalls; + return QVariant(); + } + public: - int eventCalls; - mutable int queryCalls; + int eventCalls = 0; + mutable int queryCalls = 0; }; void tst_QGraphicsScene::inputMethod() { PlatformInputContext inputContext; - QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + QInputMethodPrivate *inputMethodPrivate = + QInputMethodPrivate::get(QGuiApplication::inputMethod()); inputMethodPrivate->testContext = &inputContext; - QFETCH(int, flags); + QFETCH(QGraphicsItem::GraphicsItemFlags, flags); QFETCH(bool, callFocusItem); InputMethodTester *item = new InputMethodTester; - item->setFlags((QGraphicsItem::GraphicsItemFlags)flags); + item->setFlags(flags); QGraphicsScene scene; QGraphicsView view(&scene); + view.resize(m_testSize); view.show(); + view.setWindowTitle(QTest::currentTestFunction()); QApplication::setActiveWindow(&view); view.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); + QCOMPARE(QApplication::activeWindow(), &view); inputContext.m_resetCallCount = 0; inputContext.m_commitCallCount = 0; @@ -3784,25 +3842,25 @@ void tst_QGraphicsScene::inputMethod() QCOMPARE(inputContext.m_resetCallCount, 0); item->eventCalls = 0; - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item->eventCalls, callFocusItem ? 1 : 0); item->queryCalls = 0; - scene.inputMethodQuery((Qt::InputMethodQuery)0); + scene.inputMethodQuery(Qt::InputMethodQuery(0)); QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); - scene.setFocusItem(0); + scene.setFocusItem(nullptr); // the input context is reset twice, once because an item has lost focus and again because // the Qt::WA_InputMethodEnabled flag is cleared because no item has focus. QCOMPARE(inputContext.m_resetCallCount + inputContext.m_commitCallCount, callFocusItem ? 2 : 0); QCOMPARE(item->queryCalls, callFocusItem ? 1 : 0); // verify that value is unaffected item->eventCalls = 0; - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item->eventCalls, 0); item->queryCalls = 0; - scene.inputMethodQuery((Qt::InputMethodQuery)0); + scene.inputMethodQuery(Qt::InputMethodQuery(0)); QCOMPARE(item->queryCalls, 0); } @@ -3826,18 +3884,18 @@ void tst_QGraphicsScene::dispatchHoverOnPress() me.setButtons(Qt::LeftButton); QGraphicsSceneMouseEvent me2(QEvent::GraphicsSceneMouseRelease); me2.setButton(Qt::LeftButton); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverEnter << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress << QEvent::UngrabMouse); tester1->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress @@ -3852,21 +3910,21 @@ void tst_QGraphicsScene::dispatchHoverOnPress() me2.setScenePos(QPointF(30, 30)); me2.setButton(Qt::LeftButton); tester1->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - qDebug() << tester1->eventTypes; - QCOMPARE(tester1->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + qCDebug(lcTests) << tester1->eventTypes; + QCOMPARE(tester1->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverLeave); - QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() + QCOMPARE(tester2->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverEnter << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress << QEvent::UngrabMouse); tester2->eventTypes.clear(); - qApp->sendEvent(&scene, &me); - qApp->sendEvent(&scene, &me2); - QCOMPARE(tester2->eventTypes, QList<QEvent::Type>() + QCoreApplication::sendEvent(&scene, &me); + QCoreApplication::sendEvent(&scene, &me2); + QCOMPARE(tester2->eventTypes, QVector<QEvent::Type>() << QEvent::GraphicsSceneHoverMove << QEvent::GrabMouse << QEvent::GraphicsSceneMousePress @@ -3915,7 +3973,7 @@ void tst_QGraphicsScene::initialFocus() if (activeScene) { QEvent windowActivate(QEvent::WindowActivate); - qApp->sendEvent(&scene, &windowActivate); + QCoreApplication::sendEvent(&scene, &windowActivate); scene.setFocus(); } @@ -3923,7 +3981,7 @@ void tst_QGraphicsScene::initialFocus() if (!activeScene) { QEvent windowActivate(QEvent::WindowActivate); - qApp->sendEvent(&scene, &windowActivate); + QCoreApplication::sendEvent(&scene, &windowActivate); scene.setFocus(); } @@ -3933,14 +3991,13 @@ void tst_QGraphicsScene::initialFocus() class PolishItem : public QGraphicsTextItem { public: - PolishItem(QGraphicsItem *parent = 0) - : QGraphicsTextItem(parent), polished(false), deleteChildrenInPolish(true), addChildrenInPolish(false) { } + using QGraphicsTextItem::QGraphicsTextItem; - bool polished; - bool deleteChildrenInPolish; - bool addChildrenInPolish; + bool polished = false; + bool deleteChildrenInPolish = true; + bool addChildrenInPolish = false; protected: - QVariant itemChange(GraphicsItemChange change, const QVariant& value) + QVariant itemChange(GraphicsItemChange change, const QVariant& value) override { if (change == ItemVisibleChange) { polished = true; @@ -3979,19 +4036,19 @@ void tst_QGraphicsScene::polishItems2() // Wait for the polish event to be delivered. QVERIFY(!item->polished); - QApplication::sendPostedEvents(&scene, QEvent::MetaCall); + QCoreApplication::sendPostedEvents(&scene, QEvent::MetaCall); QVERIFY(item->polished); // We deleted the children we added above, but we also // added 10 new children. These should be polished in the next // event loop iteration. - QList<QGraphicsItem *> children = item->childItems(); + const QList<QGraphicsItem *> children = item->childItems(); QCOMPARE(children.count(), 10); - foreach (QGraphicsItem *child, children) + for (QGraphicsItem *child : children) QVERIFY(!static_cast<PolishItem *>(child)->polished); - QApplication::sendPostedEvents(&scene, QEvent::MetaCall); - foreach (QGraphicsItem *child, children) + QCoreApplication::sendPostedEvents(&scene, QEvent::MetaCall); + for (QGraphicsItem *child : children) QVERIFY(static_cast<PolishItem *>(child)->polished); } @@ -4008,6 +4065,8 @@ void tst_QGraphicsScene::isActive() { QWidget toplevel1; + toplevel1.setWindowTitle(QTest::currentTestFunction()); + toplevel1.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel1.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4073,8 +4132,9 @@ void tst_QGraphicsScene::isActive() { - const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry(); QWidget toplevel2; + toplevel2.setWindowTitle(QTest::currentTestFunction()); + toplevel2.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel2.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4087,7 +4147,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene1.hasFocus()); QVERIFY(!scene2.hasFocus()); - toplevel2.move(availableGeometry.topLeft() + QPoint(50, 50)); + toplevel2.move(m_availableGeometry.topLeft() + QPoint(50, 50)); toplevel2.show(); QApplication::setActiveWindow(&toplevel2); QVERIFY(QTest::qWaitForWindowActive(&toplevel2)); @@ -4136,12 +4196,13 @@ void tst_QGraphicsScene::isActive() QVERIFY(!scene2.hasFocus()); QGraphicsView topLevelView; - topLevelView.move(availableGeometry.topLeft() + QPoint(500, 50)); + topLevelView.move(toplevel2.geometry().topRight() + QPoint(100, 50)); + topLevelView.resize(m_testSize); topLevelView.show(); QApplication::setActiveWindow(&topLevelView); topLevelView.setFocus(); QVERIFY(QTest::qWaitForWindowActive(&topLevelView)); - QCOMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&topLevelView)); + QCOMPARE(QApplication::activeWindow(), &topLevelView); QVERIFY(!scene1.isActive()); QVERIFY(!scene2.isActive()); @@ -4182,6 +4243,7 @@ void tst_QGraphicsScene::isActive() { QWidget toplevel3; + toplevel3.resize(m_testSize); QHBoxLayout *layout = new QHBoxLayout; toplevel3.setLayout(layout); QGraphicsView *view1 = new QGraphicsView(&scene1); @@ -4211,7 +4273,7 @@ void tst_QGraphicsScene::isActive() QVERIFY(scene1.hasFocus()); QVERIFY(!scene2.hasFocus()); - view1->setParent(0); + view1->setParent(nullptr); QVERIFY(!scene1.isActive()); QVERIFY(scene2.isActive()); QVERIFY(!scene1.hasFocus()); @@ -4243,7 +4305,7 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() scene.addItem(parent2); //Then we make the child a top level - child->setParentItem(0); + child->setParentItem(nullptr); //This is trigerred by a repaint... QGraphicsScenePrivate::get(&scene)->index->estimateTopLevelItems(QRectF(), Qt::AscendingOrder); @@ -4259,6 +4321,8 @@ void tst_QGraphicsScene::siblingIndexAlwaysValid() scene2.setItemIndexMethod(QGraphicsScene::NoIndex); QGraphicsView view2(&scene2); + view2.setWindowTitle(QTest::currentTestFunction()); + view2.resize(m_testSize); // first add the blue rect QGraphicsRectItem* const item1 = new QGraphicsRectItem(QRect( 10, 10, 10, 10 )); @@ -4302,9 +4366,11 @@ void tst_QGraphicsScene::removeFullyTransparentItem() child->setParentItem(parent); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -4353,33 +4419,35 @@ void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() { // Test using DeviceCoordinateCache and opaque item - QWidget *w = new QWidget(); + QScopedPointer<QWidget> w(new QWidget); w->setPalette(QColor(0, 0, 255)); w->setGeometry(0, 0, 50, 50); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.resize(m_testSize); + view.setWindowTitle(QTest::currentTestFunction()); + view.setScene(scene); - QGraphicsProxyWidget *proxy = scene->addWidget(w); + QGraphicsProxyWidget *proxy = scene->addWidget(w.data()); proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); proxy->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; proxy->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(proxy); - QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view->viewport()).key, &pix)); + QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view.viewport()).key, &pix)); QTransform t = proxy->sceneTransform(); // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(proxy->boundingRect().toRect()).left(); + const int adjust = t.mapRect(proxy->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4388,8 +4456,6 @@ void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 255); } - - delete w; } void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() @@ -4403,28 +4469,30 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setParentItem(backItem); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.resize(m_testSize); + view.setWindowTitle(QTest::currentTestFunction()); + view.setScene(scene); scene->addItem(backItem); rectItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); backItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); - QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view->viewport()).key, &pix)); + QTRY_VERIFY(QPixmapCache::find(itemp->extraItemCache()->deviceData.value(view.viewport()).key, &pix)); QTransform t = rectItem->sceneTransform(); // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4434,8 +4502,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QCOMPARE(qAlpha(im.pixel(i, j)), 125); } } - - delete view; } // Test using ItemCoordinateCache and opaque item @@ -4444,18 +4510,20 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setBrush(QColor(0, 0, 255)); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); + view.setScene(scene); scene->addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); @@ -4465,7 +4533,7 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4474,8 +4542,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 255); } - - delete view; } // Test using ItemCoordinateCache and semi-transparent item @@ -4484,18 +4550,20 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setBrush(QColor(0, 0, 255, 125)); QGraphicsScene *scene = new QGraphicsScene(); - CustomView *view = new CustomView; - view->setScene(scene); + CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); + view.setScene(scene); scene->addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true); - view->show(); - QVERIFY(QTest::qWaitForWindowExposed(view)); - view->repaints = 0; + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + view.repaints = 0; rectItem->update(10, 10, 10, 10); - QTRY_VERIFY(view->repaints > 0); + QTRY_VERIFY(view.repaints > 0); QPixmap pix; QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(rectItem); @@ -4505,7 +4573,7 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() // Map from scene coordinates to pixmap coordinates. // X origin in the pixmap is the most-left point // of the item's boundingRect in the scene. - qreal adjust = t.mapRect(rectItem->boundingRect().toRect()).left(); + const int adjust = int(t.mapRect(rectItem->boundingRect().toRect()).left()); QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); QPixmap subpix = pix.copy(rect); @@ -4514,8 +4582,6 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() for(int j = 0; j < im.height(); j++) QCOMPARE(qAlpha(im.pixel(i, j)), 125); } - - delete view; } } @@ -4546,7 +4612,7 @@ void tst_QGraphicsScene::zeroScale() QGraphicsView view(&scene); ChangedListener cl; - connect(&scene, SIGNAL(changed(QList<QRectF>)), &cl, SLOT(changed(QList<QRectF>))); + connect(&scene, &QGraphicsScene::changed, &cl, &ChangedListener::changed); QGraphicsRectItem *rect1 = new QGraphicsRectItem(0, 0, 0.0000001, 0.00000001); scene.addItem(rect1); @@ -4569,13 +4635,13 @@ void tst_QGraphicsScene::focusItemChangedSignal() qRegisterMetaType<Qt::FocusReason>("Qt::FocusReason"); QGraphicsScene scene; - QSignalSpy spy(&scene, SIGNAL(focusItemChanged(QGraphicsItem *, QGraphicsItem *, Qt::FocusReason))); + QSignalSpy spy(&scene, &QGraphicsScene::focusItemChanged); QVERIFY(spy.isValid()); QCOMPARE(spy.count(), 0); scene.setFocus(); QCOMPARE(spy.count(), 0); QEvent activateEvent(QEvent::WindowActivate); - qApp->sendEvent(&scene, &activateEvent); + QCoreApplication::sendEvent(&scene, &activateEvent); QCOMPARE(spy.count(), 0); QGraphicsRectItem *topLevelItem1 = new QGraphicsRectItem; @@ -4592,7 +4658,7 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); QList<QVariant> arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), nullptr); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); QVERIFY(topLevelItem2->hasFocus()); @@ -4602,14 +4668,14 @@ void tst_QGraphicsScene::focusItemChangedSignal() arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), nullptr); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); scene.setFocus(Qt::MenuBarFocusReason); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), nullptr); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::MenuBarFocusReason); @@ -4617,15 +4683,15 @@ void tst_QGraphicsScene::focusItemChangedSignal() topLevelItem1->setFocus(Qt::TabFocusReason); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); topLevelItem2->setFocus(Qt::TabFocusReason); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem1); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); } @@ -4633,10 +4699,10 @@ void tst_QGraphicsScene::focusItemChangedSignal() // when the scene activation changes) breaks quite a few tests so leave this fix // for some future release. See QTBUG-28346. QEvent deactivateEvent(QEvent::WindowDeactivate); - qApp->sendEvent(&scene, &deactivateEvent); + QCoreApplication::sendEvent(&scene, &deactivateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); QCOMPARE(spy.count(), 1); - qApp->sendEvent(&scene, &activateEvent); + QCoreApplication::sendEvent(&scene, &activateEvent); QEXPECT_FAIL("", "QTBUG-28346", Continue); QCOMPARE(spy.count(), 1); @@ -4647,8 +4713,8 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), topLevelItem2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); QGraphicsRectItem *panel2 = new QGraphicsRectItem; @@ -4661,16 +4727,16 @@ void tst_QGraphicsScene::focusItemChangedSignal() QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel2); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), panel1); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); scene.setActivePanel(panel1); QCOMPARE(spy.count(), 1); arguments = spy.takeFirst(); QCOMPARE(arguments.size(), 3); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); - QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel2); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(0)), panel1); + QCOMPARE(qvariant_cast<QGraphicsItem *>(arguments.at(1)), panel2); QCOMPARE(qvariant_cast<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); } @@ -4679,14 +4745,15 @@ 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 ) + using QGraphicsRectItem::QGraphicsRectItem; + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget = nullptr) override { QGraphicsRectItem::paint(painter, option, widget); ++repaints; } - int repaints; + int repaints = 0; }; void tst_QGraphicsScene::minimumRenderSize() @@ -4700,10 +4767,12 @@ void tst_QGraphicsScene::minimumRenderSize() scene.addItem(bigParent); CustomView view; + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); view.setScene(&scene); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - qApp->processEvents(); + QCoreApplication::processEvents(); // Initially, everything should be repainted the same number of times int viewRepaints = 0; @@ -4716,7 +4785,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Setting a minimum render size should cause a repaint scene.setMinimumRenderSize(0.5); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4727,7 +4796,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Scaling should cause a repaint of big items only. view.scale(0.1, 0.1); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4738,7 +4807,7 @@ void tst_QGraphicsScene::minimumRenderSize() // Scaling further should cause even fewer items to be repainted view.scale(0.1, 0.1); // Stacks with previous scale - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(view.repaints > viewRepaints); viewRepaints = view.repaints; @@ -4752,6 +4821,8 @@ void tst_QGraphicsScene::focusOnTouch() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); scene.setSceneRect(0, 0, 100, 100); QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); rect->setFlag(QGraphicsItem::ItemIsFocusable, true); @@ -4809,6 +4880,7 @@ void tst_QGraphicsScene::taskQTBUG_16401_focusItem() { QGraphicsScene scene; QGraphicsView view(&scene); + view.resize(m_testSize); QGraphicsRectItem *rect = scene.addRect(0, 0, 100, 100); rect->setFlag(QGraphicsItem::ItemIsFocusable); @@ -4839,6 +4911,8 @@ void tst_QGraphicsScene::taskQTBUG_42915_focusNextPrevChild() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QTest::currentTestFunction()); + view.resize(m_testSize); scene.setSceneRect(1, 1, 198, 198); view.setFocus(); |