From e72e5aa83a0a287ea7e19158b39917eb3daef1d9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 9 May 2019 10:20:57 +0200 Subject: Brush up tst_QWidget - Use nullptr - Fix C-style casts - Fix redundant bool expressions - Fix else after return - Remove unnecessary casts to int from registered enums - Fix most signedness-related warnings - Use range-based for - Use correct static invocation - Set a title on shown windows to make it possible to identify slow tests - Fix the class declarations, use override, member initializations - Use Qt 5 connection syntax - Remove unused variables - Streamline code in some cases Change-Id: I1350b382b0b7d0f3198039fdc78892cfa1dd498d Reviewed-by: Oliver Wolff Reviewed-by: Edward Welbourne --- tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp | 1058 +++++++++++---------- 1 file changed, 548 insertions(+), 510 deletions(-) diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 780cb01e40..bbaed67a36 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -83,14 +83,16 @@ using namespace QTestPrivate; #include #include +#include + static HWND winHandleOf(const QWidget *w) { static QPlatformNativeInterface *nativeInterface - = QGuiApplicationPrivate::instance()->platformIntegration()->nativeInterface(); + = QGuiApplicationPrivate::platformIntegration()->nativeInterface(); if (void *handle = nativeInterface->nativeResourceForWindow("handle", w->window()->windowHandle())) return reinterpret_cast(handle); qWarning() << "Cannot obtain native handle for " << w; - return 0; + return nullptr; } # define Q_CHECK_PAINTEVENTS \ @@ -432,9 +434,9 @@ void tst_QWidget::getSetCheck() QScopedPointer var1(QStyleFactory::create(QLatin1String("Windows"))); obj1.setStyle(var1.data()); QCOMPARE(static_cast(var1.data()), obj1.style()); - obj1.setStyle((QStyle *)0); + obj1.setStyle(nullptr); QVERIFY(var1.data() != obj1.style()); - QVERIFY(0 != obj1.style()); // style can never be 0 for a widget + QVERIFY(obj1.style() != nullptr); // style can never be 0 for a widget // int QWidget::minimumWidth() // void QWidget::setMinimumWidth(int) @@ -510,7 +512,7 @@ void tst_QWidget::getSetCheck() // void QWidget::setWindowOpacity(qreal) obj1.setWindowOpacity(0.0); QCOMPARE(0.0, obj1.windowOpacity()); - obj1.setWindowOpacity(1.1f); + obj1.setWindowOpacity(1.1); QCOMPARE(1.0, obj1.windowOpacity()); // 1.0 is the fullest opacity possible // QWidget * QWidget::focusProxy() @@ -519,16 +521,16 @@ void tst_QWidget::getSetCheck() QScopedPointer var9(new QWidget()); obj1.setFocusProxy(var9.data()); QCOMPARE(var9.data(), obj1.focusProxy()); - obj1.setFocusProxy((QWidget *)0); - QCOMPARE((QWidget *)0, obj1.focusProxy()); + obj1.setFocusProxy(nullptr); + QCOMPARE(nullptr, obj1.focusProxy()); } // const QRect & QWidget::geometry() // void QWidget::setGeometry(const QRect &) - qApp->processEvents(); + QCoreApplication::processEvents(); QRect var10(10, 10, 100, 100); obj1.setGeometry(var10); - qApp->processEvents(); + QCoreApplication::processEvents(); qDebug() << obj1.geometry(); QCOMPARE(var10, obj1.geometry()); obj1.setGeometry(QRect(0,0,0,0)); @@ -540,10 +542,10 @@ void tst_QWidget::getSetCheck() QBoxLayout *var11 = new QBoxLayout(QBoxLayout::LeftToRight); obj1.setLayout(var11); QCOMPARE(static_cast(var11), obj1.layout()); - obj1.setLayout((QLayout *)0); + obj1.setLayout(nullptr); QCOMPARE(static_cast(var11), obj1.layout()); // You cannot set a 0-pointer layout, that keeps the current delete var11; // This will remove the layout from the widget - QCOMPARE((QLayout *)0, obj1.layout()); + QCOMPARE(nullptr, obj1.layout()); // bool QWidget::acceptDrops() // void QWidget::setAcceptDrops(bool) @@ -563,7 +565,7 @@ void tst_QWidget::getSetCheck() #if defined (Q_OS_WIN) && !defined(Q_OS_WINRT) obj1.setWindowFlags(Qt::FramelessWindowHint | Qt::WindowSystemMenuHint); const HWND handle = reinterpret_cast(obj1.winId()); // explicitly create window handle - QVERIFY(GetWindowLong(handle, GWL_STYLE) & WS_POPUP); + QVERIFY(GetWindowLong(handle, GWL_STYLE) & LONG(WS_POPUP)); #endif } @@ -578,12 +580,12 @@ tst_QWidget::tst_QWidget() QFont font; font.setBold(true); font.setPointSize(42); - qApp->setFont(font, "QPropagationTestWidget"); + QApplication::setFont(font, "QPropagationTestWidget"); QPalette palette; palette.setColor(QPalette::ToolTipBase, QColor(12, 13, 14)); palette.setColor(QPalette::Text, QColor(21, 22, 23)); - qApp->setPalette(palette, "QPropagationTestWidget"); + QApplication::setPalette(palette, "QPropagationTestWidget"); } tst_QWidget::~tst_QWidget() @@ -592,16 +594,6 @@ tst_QWidget::~tst_QWidget() setWindowsAnimationsEnabled(m_windowsAnimationsEnabled); } -class BezierViewer : public QWidget { -public: - explicit BezierViewer(QWidget* parent = 0); - void paintEvent( QPaintEvent* ); - void setPoints( const QPolygonF& poly ); -private: - QPolygonF points; - -}; - void tst_QWidget::initTestCase() { // Size of reference widget, 200 for < 2000, scale up for larger screens @@ -728,9 +720,7 @@ class QPropagationTestWidget : public QWidget { Q_OBJECT public: - QPropagationTestWidget(QWidget *parent = 0) - : QWidget(parent) - { } + using QWidget::QWidget; }; void tst_QWidget::fontPropagation2() @@ -739,7 +729,7 @@ void tst_QWidget::fontPropagation2() // QFont font; // font.setBold(true); // font.setPointSize(42); - // qApp->setFont(font, "QPropagationTestWidget"); + // QApplication::setFont(font, "QPropagationTestWidget"); QScopedPointer root(new QWidget); root->setObjectName(QLatin1String("fontPropagation2")); @@ -796,7 +786,7 @@ void tst_QWidget::fontPropagation2() QFont italicSizeFont; italicSizeFont.setItalic(true); italicSizeFont.setPointSize(33); - qApp->setFont(italicSizeFont, "QPropagationTestWidget"); + QApplication::setFont(italicSizeFont, "QPropagationTestWidget"); // Check that this propagates correctly. QCOMPARE(root->font(), QApplication::font()); @@ -949,7 +939,7 @@ void tst_QWidget::palettePropagation2() // should still be ignored. The previous ToolTipBase setting is gone. QPalette buttonPalette; buttonPalette.setColor(QPalette::ToolTipText, sysPalButton); - qApp->setPalette(buttonPalette, "QPropagationTestWidget"); + QApplication::setPalette(buttonPalette, "QPropagationTestWidget"); // Check that the above settings propagate correctly. QCOMPARE(root->palette(), appPal); @@ -1136,7 +1126,7 @@ void tst_QWidget::isEnabledTo() QScopedPointer childDialog(new QMainWindow(&testWidget)); testWidget.setEnabled(false); QVERIFY(!childDialog->isEnabled()); - QVERIFY(childDialog->isEnabledTo(0)); + QVERIFY(childDialog->isEnabledTo(nullptr)); } void tst_QWidget::visible() @@ -1581,8 +1571,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedOriginalChain[8] = {&window, child1, child2, child3, child21, child22, child4, &window}; QWidget *w = &window; - for (int i = 0; i <8; ++i) { - QCOMPARE(w, expectedOriginalChain[i]); + for (auto expectedOriginal : expectedOriginalChain) { + QCOMPARE(w, expectedOriginal); w = w->nextInFocusChain(); } for (int i = 7; i >= 0; --i) { @@ -1595,8 +1585,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedNewChain[5] = {&window2, child2, child21, child22, &window2}; w = &window2; - for (int i = 0; i <5; ++i) { - QCOMPARE(w, expectedNewChain[i]); + for (auto expectedNew : expectedNewChain) { + QCOMPARE(w, expectedNew); w = w->nextInFocusChain(); } for (int i = 4; i >= 0; --i) { @@ -1606,8 +1596,8 @@ void tst_QWidget::focusChainOnReparent() QWidget *expectedOldChain[5] = {&window, child1, child3, child4, &window}; w = &window; - for (int i = 0; i <5; ++i) { - QCOMPARE(w, expectedOldChain[i]); + for (auto expectedOld : expectedOldChain) { + QCOMPARE(w, expectedOld); w = w->nextInFocusChain(); } for (int i = 4; i >= 0; --i) { @@ -1631,7 +1621,7 @@ void tst_QWidget::focusChainOnHide() QWidget::setTabOrder(child, parent.data()); parent->show(); - qApp->setActiveWindow(parent->window()); + QApplication::setActiveWindow(parent->window()); child->activateWindow(); child->setFocus(); @@ -1639,7 +1629,7 @@ void tst_QWidget::focusChainOnHide() child->hide(); QTRY_VERIFY(parent->hasFocus()); - QCOMPARE(parent.data(), qApp->focusWidget()); + QCOMPARE(parent.data(), QApplication::focusWidget()); } class Container : public QWidget @@ -1667,7 +1657,7 @@ public: class Composite : public QFrame { public: - Composite(QWidget* parent = 0, const QString &name = 0) + explicit Composite(QWidget *parent = nullptr, const QString &name = QString()) : QFrame(parent) { setObjectName(name); @@ -1706,9 +1696,10 @@ void tst_QWidget::defaultTabOrder() QLineEdit *lastEdit = new QLineEdit(); container.box->addWidget(lastEdit); + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1746,6 +1737,7 @@ void tst_QWidget::reverseTabOrder() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1765,7 +1757,7 @@ void tst_QWidget::reverseTabOrder() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1804,6 +1796,7 @@ void tst_QWidget::tabOrderWithProxy() { const int compositeCount = 2; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite* composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); @@ -1823,7 +1816,7 @@ void tst_QWidget::tabOrderWithProxy() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); QTRY_VERIFY(firstEdit->hasFocus()); @@ -1861,13 +1854,14 @@ void tst_QWidget::tabOrderWithCompoundWidgets() { const int compositeCount = 4; Container container; + container.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Composite *composite[compositeCount]; QLineEdit *firstEdit = new QLineEdit(); container.box->addWidget(firstEdit); for (int i = 0; i < compositeCount; i++) { - composite[i] = new Composite(0, QStringLiteral("Composite: ") + QString::number(i)); + composite[i] = new Composite(nullptr, QStringLiteral("Composite: ") + QString::number(i)); container.box->addWidget(composite[i]); // Let the composite handle focus, and set a child as focus proxy (use the second child, just @@ -1893,7 +1887,7 @@ void tst_QWidget::tabOrderWithCompoundWidgets() container.show(); container.activateWindow(); - qApp->setActiveWindow(&container); + QApplication::setActiveWindow(&container); QVERIFY(QTest::qWaitForWindowActive(&container)); lastEdit->setFocus(); @@ -2306,26 +2300,27 @@ void tst_QWidget::showFullScreen() class ResizeWidget : public QWidget { public: - ResizeWidget(QWidget *p = 0) : QWidget(p) + explicit ResizeWidget(QWidget *p = nullptr) : QWidget(p) { setObjectName(QLatin1String("ResizeWidget")); setWindowTitle(objectName()); - m_resizeEventCount = 0; } protected: - void resizeEvent(QResizeEvent *e){ + void resizeEvent(QResizeEvent *e) override + { QCOMPARE(size(), e->size()); ++m_resizeEventCount; } public: - int m_resizeEventCount; + int m_resizeEventCount = 0; }; void tst_QWidget::resizeEvent() { { QWidget wParent; + wParent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); wParent.resize(200, 200); ResizeWidget wChild(&wParent); wParent.show(); @@ -2343,6 +2338,7 @@ void tst_QWidget::resizeEvent() { ResizeWidget wTopLevel; + wTopLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); wTopLevel.resize(200, 200); wTopLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&wTopLevel)); @@ -2370,6 +2366,7 @@ void tst_QWidget::showMinimized() } QWidget plain; + plain.setWindowTitle(QLatin1String(QTest::currentTestFunction())); plain.move(100, 100); plain.resize(200, 200); QPoint pos = plain.pos(); @@ -2424,17 +2421,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //here we test that minimizing a widget and restoring it doesn't change the focus inside of it { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child1(&window), child2(&window); child1.setFocusPolicy(Qt::StrongFocus); child2.setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child2.setFocus(); QTRY_COMPARE(window.focusWidget(), &child2); - QTRY_COMPARE(qApp->focusWidget(), &child2); + QTRY_COMPARE(QApplication::focusWidget(), &child2); window.showMinimized(); QTRY_VERIFY(window.isMinimized()); @@ -2448,15 +2446,16 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing deletion of the focusWidget { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); delete child; QCOMPARE(window.focusWidget(), nullptr); @@ -2466,17 +2465,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing reparenting the focus widget { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); - child->setParent(0); + child->setParent(nullptr); QScopedPointer childGuard(child); QCOMPARE(window.focusWidget(), nullptr); QCOMPARE(QApplication::focusWidget(), nullptr); @@ -2485,15 +2485,16 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing setEnabled(false) { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); child->setEnabled(false); QCOMPARE(window.focusWidget(), nullptr); @@ -2503,17 +2504,18 @@ void tst_QWidget::showMinimizedKeepsFocus() //testing clearFocus { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget *firstchild = new QWidget(&window); firstchild->setFocusPolicy(Qt::StrongFocus); QWidget *child = new QWidget(&window); child->setFocusPolicy(Qt::StrongFocus); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); child->setFocus(); QTRY_COMPARE(window.focusWidget(), child); - QTRY_COMPARE(qApp->focusWidget(), child); + QTRY_COMPARE(QApplication::focusWidget(), child); child->clearFocus(); QCOMPARE(window.focusWidget(), nullptr); @@ -2526,7 +2528,7 @@ void tst_QWidget::showMinimizedKeepsFocus() QTRY_COMPARE(QApplication::focusWidget(), nullptr); window.showNormal(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowActive(&window)); #ifdef Q_OS_OSX if (!macHasAccessToWindowsServer()) @@ -2541,7 +2543,7 @@ void tst_QWidget::showMinimizedKeepsFocus() #elif defined(Q_OS_WINRT) QEXPECT_FAIL("", "Winrt fails here - QTBUG-68297", Continue); #endif - QTRY_COMPARE(qApp->focusWidget(), firstchild); + QTRY_COMPARE(QApplication::focusWidget(), firstchild); } } @@ -2553,7 +2555,7 @@ void tst_QWidget::reparent() const QPoint parentPosition = m_availableTopLeft + QPoint(300, 300); parent.setGeometry(QRect(parentPosition, m_testWidgetSize)); - QWidget child(0); + QWidget child; child.setObjectName("child"); child.setGeometry(10, 10, 180, 130); QPalette pal1; @@ -2580,7 +2582,7 @@ void tst_QWidget::reparent() QPoint childPos = parent.mapToGlobal(child.pos()); QPoint tlwPos = childTLW.pos(); - child.setParent(0, child.windowFlags() & ~Qt::WindowType_Mask); + child.setParent(nullptr, child.windowFlags() & ~Qt::WindowType_Mask); child.setGeometry(childPos.x(), childPos.y(), child.width(), child.height()); child.show(); @@ -2647,17 +2649,17 @@ void tst_QWidget::hideWhenFocusWidgetIsChild() QVERIFY(QTest::qWaitForWindowActive(testWidget.data())); QString actualFocusWidget, expectedFocusWidget; - if (!qApp->focusWidget() && m_platform == QStringLiteral("xcb")) + if (!QApplication::focusWidget() && m_platform == QStringLiteral("xcb")) QSKIP("X11: Your window manager is too broken for this test"); - QVERIFY(qApp->focusWidget()); - actualFocusWidget = QString::asprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); + QVERIFY(QApplication::focusWidget()); + actualFocusWidget = QString::asprintf("%p %s %s", QApplication::focusWidget(), QApplication::focusWidget()->objectName().toLatin1().constData(), QApplication::focusWidget()->metaObject()->className()); expectedFocusWidget = QString::asprintf("%p %s %s", edit, edit->objectName().toLatin1().constData(), edit->metaObject()->className()); QCOMPARE(actualFocusWidget, expectedFocusWidget); parentWidget->hide(); - qApp->processEvents(); - actualFocusWidget = QString::asprintf("%p %s %s", qApp->focusWidget(), qApp->focusWidget()->objectName().toLatin1().constData(), qApp->focusWidget()->metaObject()->className()); + QCoreApplication::processEvents(); + actualFocusWidget = QString::asprintf("%p %s %s", QApplication::focusWidget(), QApplication::focusWidget()->objectName().toLatin1().constData(), QApplication::focusWidget()->metaObject()->className()); expectedFocusWidget = QString::asprintf("%p %s %s", edit2, edit2->objectName().toLatin1().constData(), edit2->metaObject()->className()); QCOMPARE(actualFocusWidget, expectedFocusWidget); } @@ -2774,6 +2776,7 @@ void tst_QWidget::normalGeometry() void tst_QWidget::setGeometry() { QWidget tlw; + tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&tlw); QRect tr(100,100,200,200); @@ -2786,7 +2789,7 @@ void tst_QWidget::setGeometry() QTRY_COMPARE(tlw.geometry().size(), tr.size()); QCOMPARE(child.geometry(), cr); - tlw.setParent(0, Qt::Window|Qt::FramelessWindowHint); + tlw.setParent(nullptr, Qt::Window|Qt::FramelessWindowHint); tr = QRect(0,0,100,100); tr.moveTopLeft(QGuiApplication::primaryScreen()->availableGeometry().topLeft()); tlw.setGeometry(tr); @@ -2834,13 +2837,14 @@ void tst_QWidget::windowOpacity() class UpdateWidget : public QWidget { public: - UpdateWidget(QWidget *parent = 0) : QWidget(parent) { + explicit UpdateWidget(QWidget *parent = nullptr) : QWidget(parent) + { setObjectName(QLatin1String("UpdateWidget")); - setWindowTitle(objectName()); reset(); } - void paintEvent(QPaintEvent *e) { + void paintEvent(QPaintEvent *e) override + { paintedRegion += e->region(); ++numPaintEvents; if (resizeInPaintEvent) { @@ -2849,7 +2853,7 @@ public: } } - bool event(QEvent *event) + bool event(QEvent *event) override { switch (event->type()) { case QEvent::ZOrderChange: @@ -2872,12 +2876,10 @@ public: return QWidget::event(event); } - void reset() { - numPaintEvents = 0; - numZOrderChangeEvents = 0; - numUpdateRequestEvents = 0; - updateOnActivationChangeAndFocusIn = false; - resizeInPaintEvent = false; + void reset() + { + numPaintEvents = numZOrderChangeEvents = numUpdateRequestEvents = 0; + updateOnActivationChangeAndFocusIn = resizeInPaintEvent = false; paintedRegion = QRegion(); } @@ -2894,6 +2896,7 @@ void tst_QWidget::lostUpdatesOnHide() #ifndef Q_OS_OSX UpdateWidget widget; widget.setAttribute(Qt::WA_DontShowOnScreen); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); widget.hide(); QTest::qWait(50); @@ -2937,12 +2940,11 @@ void tst_QWidget::raise() } #endif - QList list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parentPtr->children(), list1); QCOMPARE(allChildren.count(), list1.count()); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; if (expectedPaintEvents == 0) { QCOMPARE(child->numPaintEvents, 0); @@ -2958,7 +2960,7 @@ void tst_QWidget::raise() child2->raise(); QTest::qWait(50); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child2 ? 1 : 0; int expectedZOrderChangeEvents = child == child2 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -2973,6 +2975,7 @@ void tst_QWidget::raise() // Creates a widget on top of all the children and checks that raising one of // the children underneath doesn't trigger a repaint on the covering widget. QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *parent = parentPtr.take(); parent->setParent(&topLevel); topLevel.show(); @@ -2987,7 +2990,7 @@ void tst_QWidget::raise() onTop->reset(); // Reset all the children. - foreach (UpdateWidget *child, allChildren) + for (UpdateWidget *child : qAsConst(allChildren)) child->reset(); for (int i = 0; i < 5; ++i) @@ -2997,11 +3000,10 @@ void tst_QWidget::raise() QCOMPARE(onTop->numPaintEvents, 0); QCOMPARE(onTop->numZOrderChangeEvents, 0); - QList list3; - list3 << child1 << child4 << child2 << child3; + QObjectList list3{child1, child4, child2, child3}; QCOMPARE(parent->children(), list3); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = 0; int expectedZOrderChangeEvents = child == child3 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -3037,12 +3039,11 @@ void tst_QWidget::lower() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parent->children(), list1); QCOMPARE(allChildren.count(), list1.count()); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; if (expectedPaintEvents == 0) { QCOMPARE(child->numPaintEvents, 0); @@ -3059,7 +3060,7 @@ void tst_QWidget::lower() QTest::qWait(100); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child3 ? 1 : 0; int expectedZOrderChangeEvents = child == child4 ? 1 : 0; QTRY_COMPARE(child->numZOrderChangeEvents, expectedZOrderChangeEvents); @@ -3102,11 +3103,10 @@ void tst_QWidget::stackUnder() parent->show(); QVERIFY(QTest::qWaitForWindowExposed(parent.data())); - QList list1; - list1 << child1 << child2 << child3 << child4; + QObjectList list1{child1, child2, child3, child4}; QCOMPARE(parent->children(), list1); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child4 ? 1 : 0; #if defined(Q_OS_WIN) || defined(Q_OS_OSX) if (expectedPaintEvents == 1 && child->numPaintEvents == 2) @@ -3121,11 +3121,10 @@ void tst_QWidget::stackUnder() child4->stackUnder(child2); QTest::qWait(10); - QList list2; - list2 << child1 << child4 << child2 << child3; + QObjectList list2{child1, child4, child2, child3}; QCOMPARE(parent->children(), list2); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedPaintEvents = child == child3 ? 1 : 0; int expectedZOrderChangeEvents = child == child4 ? 1 : 0; QTRY_COMPARE(child->numPaintEvents, expectedPaintEvents); @@ -3137,11 +3136,10 @@ void tst_QWidget::stackUnder() child1->stackUnder(child3); QTest::qWait(10); - QList list3; - list3 << child4 << child2 << child1 << child3; + QObjectList list3{child4, child2, child1, child3}; QCOMPARE(parent->children(), list3); - foreach (UpdateWidget *child, allChildren) { + for (UpdateWidget *child : qAsConst(allChildren)) { int expectedZOrderChangeEvents = child == child1 ? 1 : 0; if (child == child3) { #ifndef Q_OS_OSX @@ -3174,30 +3172,31 @@ class ContentsPropagationWidget : public QWidget { Q_OBJECT public: - ContentsPropagationWidget(QWidget *parent = 0) : QWidget(parent) + explicit ContentsPropagationWidget(QWidget *parent = nullptr) : QWidget(parent) { setObjectName(QLatin1String("ContentsPropagationWidget")); setWindowTitle(objectName()); QWidget *child = this; - for (int i=0; i<32; ++i) { + for (int i = 0; i < 32; ++i) { child = new QWidget(child); - child->setGeometry(i, i, 400 - i*2, 400 - i*2); + child->setGeometry(i, i, 400 - i * 2, 400 - i * 2); } } - void setContentsPropagation(bool enable) { - foreach (QObject *child, children()) + void setContentsPropagation(bool enable) + { + for (QObject *child : children()) qobject_cast(child)->setAutoFillBackground(!enable); } protected: - void paintEvent(QPaintEvent *) + void paintEvent(QPaintEvent *) override { int w = width(), h = height(); drawPolygon(this, w, h); } - QSize sizeHint() const { return QSize(500, 500); } + QSize sizeHint() const override { return {500, 500}; } }; // Scale to remove devicePixelRatio should scaling be active. @@ -3271,6 +3270,7 @@ void tst_QWidget::saveRestoreGeometry() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QByteArray empty; const QByteArray one("a"); @@ -3382,7 +3382,7 @@ void tst_QWidget::restoreVersion1Geometry_data() if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); QTest::addColumn("fileName"); - QTest::addColumn("expectedWindowState"); + QTest::addColumn("expectedWindowState"); QTest::addColumn("expectedPosition"); QTest::addColumn("expectedSize"); QTest::addColumn("expectedNormalGeometry"); @@ -3390,9 +3390,9 @@ void tst_QWidget::restoreVersion1Geometry_data() const QSize size(200, 200); const QRect normalGeometry(102, 124, 200, 200); - QTest::newRow("geometry.dat") << ":geometry.dat" << uint(Qt::WindowNoState) << position << size << normalGeometry; - QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << uint(Qt::WindowMaximized) << position << size << normalGeometry; - QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << uint(Qt::WindowFullScreen) << position << size << normalGeometry; + QTest::newRow("geometry.dat") << ":geometry.dat" << Qt::WindowNoState << position << size << normalGeometry; + QTest::newRow("geometry-maximized.dat") << ":geometry-maximized.dat" << Qt::WindowMaximized << position << size << normalGeometry; + QTest::newRow("geometry-fullscreen.dat") << ":geometry-fullscreen.dat" << Qt::WindowFullScreen << position << size << normalGeometry; } /* @@ -3402,14 +3402,14 @@ void tst_QWidget::restoreVersion1Geometry_data() void tst_QWidget::restoreVersion1Geometry() { QFETCH(QString, fileName); - QFETCH(uint, expectedWindowState); + QFETCH(Qt::WindowState, expectedWindowState); QFETCH(QPoint, expectedPosition); Q_UNUSED(expectedPosition); QFETCH(QSize, expectedSize); QFETCH(QRect, expectedNormalGeometry); // WindowActive is uninteresting for this test - const uint WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; + const Qt::WindowStates WindowStateMask = Qt::WindowFullScreen | Qt::WindowMaximized | Qt::WindowMinimized; QFile f(fileName); QVERIFY(f.exists()); @@ -3419,10 +3419,12 @@ void tst_QWidget::restoreVersion1Geometry() f.close(); QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); QVERIFY(widget.restoreGeometry(savedGeometry)); - QCOMPARE(uint(widget.windowState() & WindowStateMask), expectedWindowState); + QCOMPARE(widget.windowState() & WindowStateMask, expectedWindowState); if (expectedWindowState == Qt::WindowNoState) { QTRY_COMPARE(widget.geometry(), expectedNormalGeometry); QCOMPARE(widget.size(), expectedSize); @@ -3486,11 +3488,11 @@ void tst_QWidget::widgetAt() Q_CHECK_PAINTEVENTS const QPoint referencePos = m_availableTopLeft + QPoint(100, 100); - QScopedPointer w1(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer w1(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); w1->setGeometry(QRect(referencePos, QSize(m_testWidgetSize.width(), 150))); w1->setObjectName(QLatin1String("w1")); w1->setWindowTitle(w1->objectName()); - QScopedPointer w2(new QWidget(0, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); + QScopedPointer w2(new QWidget(nullptr, Qt::X11BypassWindowManagerHint | Qt::FramelessWindowHint)); w2->setGeometry(QRect(referencePos + QPoint(50, 50), QSize(m_testWidgetSize.width(), 100))); w2->setObjectName(QLatin1String("w2")); w2->setWindowTitle(w2->objectName()); @@ -3550,6 +3552,7 @@ void tst_QWidget::widgetAt() void tst_QWidget::task110173() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPushButton *pb1 = new QPushButton("click", &w); pb1->setFocusPolicy(Qt::ClickFocus); @@ -3567,20 +3570,20 @@ void tst_QWidget::task110173() class Widget : public QWidget { public: - Widget() : deleteThis(false) { setFocusPolicy(Qt::StrongFocus); } - void actionEvent(QActionEvent *) { if (deleteThis) delete this; } - void changeEvent(QEvent *) { if (deleteThis) delete this; } - void closeEvent(QCloseEvent *) { if (deleteThis) delete this; } - void hideEvent(QHideEvent *) { if (deleteThis) delete this; } - void focusOutEvent(QFocusEvent *) { if (deleteThis) delete this; } - void keyPressEvent(QKeyEvent *) { if (deleteThis) delete this; } - void keyReleaseEvent(QKeyEvent *) { if (deleteThis) delete this; } - void mouseDoubleClickEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mousePressEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mouseReleaseEvent(QMouseEvent *) { if (deleteThis) delete this; } - void mouseMoveEvent(QMouseEvent *) { if (deleteThis) delete this; } - - bool deleteThis; + Widget() { setFocusPolicy(Qt::StrongFocus); } + void actionEvent(QActionEvent *) override { if (deleteThis) delete this; } + void changeEvent(QEvent *) override { if (deleteThis) delete this; } + void closeEvent(QCloseEvent *) override { if (deleteThis) delete this; } + void hideEvent(QHideEvent *) override { if (deleteThis) delete this; } + void focusOutEvent(QFocusEvent *) override { if (deleteThis) delete this; } + void keyPressEvent(QKeyEvent *) override { if (deleteThis) delete this; } + void keyReleaseEvent(QKeyEvent *) override { if (deleteThis) delete this; } + void mouseDoubleClickEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mousePressEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mouseReleaseEvent(QMouseEvent *) override { if (deleteThis) delete this; } + void mouseMoveEvent(QMouseEvent *) override { if (deleteThis) delete this; } + + bool deleteThis = false; }; void tst_QWidget::testDeletionInEventHandlers() @@ -3629,7 +3632,7 @@ void tst_QWidget::testDeletionInEventHandlers() w = new Widget; w->show(); w->deleteThis = true; - QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), Qt::LeftButton, Qt::LeftButton, 0); + QMouseEvent me(QEvent::MouseButtonRelease, QPoint(1, 1), Qt::LeftButton, Qt::LeftButton, Qt::KeyboardModifiers()); qApp->notify(w, &me); QVERIFY(w.isNull()); delete w; @@ -3733,21 +3736,19 @@ class StaticWidget : public QWidget { Q_OBJECT public: - bool partial; - bool gotPaintEvent; + bool partial = false; + bool gotPaintEvent = false; QRegion paintedRegion; - StaticWidget(QWidget *parent = 0) - :QWidget(parent) + explicit StaticWidget(QWidget *parent = nullptr) : QWidget(parent) { setAttribute(Qt::WA_StaticContents); setAttribute(Qt::WA_OpaquePaintEvent); setPalette(Qt::red); // Make sure we have an opaque palette. setAutoFillBackground(true); - gotPaintEvent = false; } - void paintEvent(QPaintEvent *e) + void paintEvent(QPaintEvent *e) override { paintedRegion += e->region(); gotPaintEvent = true; @@ -3755,7 +3756,7 @@ public: // Look for a full update, set partial to false if found. for (QRect r : e->region()) { partial = (r != rect()); - if (partial == false) + if (!partial) break; } } @@ -3770,6 +3771,7 @@ void tst_QWidget::optimizedResizeMove() if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(400, 400); StaticWidget staticWidget(&parent); @@ -3851,6 +3853,7 @@ void tst_QWidget::optimizedResize_topLevel() if (QHighDpiScaling::isActive()) QSKIP("Skip due to rounding errors in the regions."); StaticWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.gotPaintEvent = false; topLevel.show(); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); @@ -3895,7 +3898,7 @@ class SiblingDeleter : public QWidget public: inline SiblingDeleter(QWidget *sibling, QWidget *parent) : QWidget(parent), sibling(sibling) {} - inline virtual ~SiblingDeleter() { delete sibling; } + inline ~SiblingDeleter() { delete sibling; } private: QPointer sibling; @@ -3904,8 +3907,8 @@ private: void tst_QWidget::childDeletesItsSibling() { - QWidget *commonParent = new QWidget(0); - QPointer child = new QWidget(0); + auto commonParent = new QWidget(nullptr); + QPointer child(new QWidget(nullptr)); QPointer siblingDeleter = new SiblingDeleter(child, commonParent); child->setParent(commonParent); delete commonParent; // don't crash @@ -4040,15 +4043,12 @@ void tst_QWidget::ensureCreated() } } -class WinIdChangeWidget : public QWidget { +class WinIdChangeWidget : public QWidget +{ public: - WinIdChangeWidget(QWidget *p = 0) - : QWidget(p) - { - - } + using QWidget::QWidget; protected: - bool event(QEvent *e) + bool event(QEvent *e) override { if (e->type() == QEvent::WinIdChange) { m_winIdList.append(internalWinId()); @@ -4142,7 +4142,7 @@ void tst_QWidget::persistentWinId() WId winId3 = w3->winId(); // reparenting should preserve the winId of the widget being reparented and of its children - w1->setParent(0); + w1->setParent(nullptr); QCOMPARE(w1->winId(), winId1); QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); @@ -4152,7 +4152,7 @@ void tst_QWidget::persistentWinId() QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); - w2->setParent(0); + w2->setParent(nullptr); QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); @@ -4164,7 +4164,7 @@ void tst_QWidget::persistentWinId() QCOMPARE(w2->winId(), winId2); QCOMPARE(w3->winId(), winId3); - w3->setParent(0); + w3->setParent(nullptr); QCOMPARE(w3->winId(), winId3); w3->setParent(w1); @@ -4205,26 +4205,20 @@ void tst_QWidget::showNativeChild() class ShowHideEventWidget : public QWidget { public: - int numberOfShowEvents, numberOfHideEvents; - int numberOfSpontaneousShowEvents, numberOfSpontaneousHideEvents; - - ShowHideEventWidget(QWidget *parent = 0) - : QWidget(parent) - , numberOfShowEvents(0), numberOfHideEvents(0) - , numberOfSpontaneousShowEvents(0), numberOfSpontaneousHideEvents(0) - { } + int numberOfShowEvents = 0, numberOfHideEvents = 0; + int numberOfSpontaneousShowEvents = 0, numberOfSpontaneousHideEvents = 0; - void create() - { QWidget::create(); } + using QWidget::QWidget; + using QWidget::create; - void showEvent(QShowEvent *e) + void showEvent(QShowEvent *e) override { ++numberOfShowEvents; if (e->spontaneous()) ++numberOfSpontaneousShowEvents; } - void hideEvent(QHideEvent *e) + void hideEvent(QHideEvent *e) override { ++numberOfHideEvents; if (e->spontaneous()) @@ -4287,6 +4281,7 @@ void tst_QWidget::showHideEvent() QFETCH(int, expectedHideEvents); ShowHideEventWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (show) widget.show(); if (hide) @@ -4349,13 +4344,14 @@ void tst_QWidget::showHideChildrenWhileMinimize_QTBUG50589() void tst_QWidget::update() { -#ifdef Q_OS_OSX +#ifdef Q_OS_MACOS QSKIP("QTBUG-52974"); #endif Q_CHECK_PAINTEVENTS UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.resize(100, 100); centerOnScreen(&w); w.show(); @@ -4607,14 +4603,14 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(250, 250)); updateWidget.showNormal(); - qApp->setActiveWindow(&updateWidget); + QApplication::setActiveWindow(&updateWidget); QVERIFY(QTest::qWaitForWindowActive(&updateWidget)); QVERIFY(updateWidget.numPaintEvents > 0); { updateWidget.reset(); updateWidget.scroll(10, 10); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, w, 10)); dirty += QRegion(QRect(0, 10, 10, h - 10)); if (m_platform == QStringLiteral("winrt")) @@ -4626,7 +4622,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 10, 10); updateWidget.scroll(0, 10); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, w, 10)); dirty += QRegion(QRect(0, 10, 10, 10)); QTRY_COMPARE(updateWidget.paintedRegion, dirty); @@ -4639,7 +4635,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 100, 100); updateWidget.scroll(10, 10, QRect(50, 50, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, 100, 50)); dirty += QRegion(QRect(0, 50, 150, 10)); dirty += QRegion(QRect(0, 60, 110, 40)); @@ -4652,7 +4648,7 @@ void tst_QWidget::scroll() updateWidget.reset(); updateWidget.update(0, 0, 100, 100); updateWidget.scroll(10, 10, QRect(100, 100, 100, 100)); - qApp->processEvents(); + QCoreApplication::processEvents(); QRegion dirty(QRect(0, 0, 100, 100)); dirty += QRegion(QRect(100, 100, 100, 10)); dirty += QRegion(QRect(100, 110, 10, 90)); @@ -4689,17 +4685,12 @@ class DestroyedSlotChecker : public QObject Q_OBJECT public: - bool wasQWidget; - - DestroyedSlotChecker() - : wasQWidget(false) - { - } + bool wasQWidget = false; public slots: void destroyedSlot(QObject *object) { - wasQWidget = (qobject_cast(object) != 0 || object->isWidgetType()); + wasQWidget = (qobject_cast(object) != nullptr || object->isWidgetType()); } }; @@ -4713,7 +4704,7 @@ void tst_QWidget::qobject_castInDestroyedSlot() QWidget *widget = new QWidget(); - QObject::connect(widget, SIGNAL(destroyed(QObject*)), &checker, SLOT(destroyedSlot(QObject*))); + QObject::connect(widget, &QObject::destroyed, &checker, &DestroyedSlotChecker::destroyedSlot); delete widget; QVERIFY(checker.wasQWidget); @@ -4722,62 +4713,53 @@ void tst_QWidget::qobject_castInDestroyedSlot() // Since X11 WindowManager operations are all async, and we have no way to know if the window // manager has finished playing with the window geometry, this test can't be reliable on X11. +using Rects = QVector; + void tst_QWidget::setWindowGeometry_data() { - QTest::addColumn >("rects"); + QTest::addColumn("rects"); QTest::addColumn("windowFlags"); - QList > rects; + QVector rects; const int width = m_testWidgetSize.width(); const int height = m_testWidgetSize.height(); const QRect availableAdjusted = QGuiApplication::primaryScreen()->availableGeometry().adjusted(100, 100, -100, -100); - rects << (QList() - << QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))) - << (QList() - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height))) - << (QList() - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted) - << (QList() - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)) - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height))) - << (QList() - << QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)) - << QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)) - << availableAdjusted - << QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)) - << QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0))); - - QList windowFlags; - windowFlags << 0 << Qt::FramelessWindowHint; + rects << Rects{QRect(m_availableTopLeft + QPoint(100, 100), m_testWidgetSize), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0))} + << Rects{availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height))} + << Rects{QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted} + << Rects{QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0)), + QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height))} + << Rects{QRect(m_availableTopLeft + QPoint(130, 50), QSize(0, 0)), + QRect(m_availableTopLeft + QPoint(100, 100), QSize(width, height)), + availableAdjusted, + QRect(m_availableTopLeft + QPoint(130, 100), QSize(0, height)), + QRect(m_availableTopLeft + QPoint(100, 50), QSize(width, 0))}; + + const Qt::WindowFlags windowFlags[] = {Qt::WindowFlags(), Qt::FramelessWindowHint}; const bool skipEmptyRects = (m_platform == QStringLiteral("windows")); - foreach (QList l, rects) { - QRect rect = l.first(); + for (Rects l : qAsConst(rects)) { if (skipEmptyRects) { - QList::iterator it = l.begin(); - while (it != l.end()) { - if (it->isEmpty()) - it = l.erase(it); - else - ++it; - } + l.erase(std::remove_if(l.begin(), l.end(), [] (const QRect &r) { return r.isEmpty(); }), + l.end()); } - foreach (int windowFlag, windowFlags) { + const QRect &rect = l.constFirst(); + for (int windowFlag : windowFlags) { QTest::newRow(QString("%1,%2 %3x%4, flags %5") .arg(rect.x()) .arg(rect.y()) @@ -4797,7 +4779,7 @@ void tst_QWidget::setWindowGeometry() else if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support setWindowGeometry"); - QFETCH(QList, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4812,7 +4794,7 @@ void tst_QWidget::setWindowGeometry() QCOMPARE(widget.geometry(), rect); // setGeometry() without showing - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(100); QCOMPARE(widget.geometry(), r); @@ -4822,6 +4804,7 @@ void tst_QWidget::setWindowGeometry() { // setGeometry() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4837,7 +4820,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4852,7 +4835,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4876,6 +4859,7 @@ void tst_QWidget::setWindowGeometry() { // show() first, then setGeometry() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -4887,7 +4871,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4902,7 +4886,7 @@ void tst_QWidget::setWindowGeometry() QTRY_COMPARE(widget.geometry(), rect); // setGeometry() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.setGeometry(r); QTest::qWait(10); QTRY_COMPARE(widget.geometry(), r); @@ -4965,7 +4949,7 @@ void tst_QWidget::windowMoveResize() if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support move/resize"); - QFETCH(QList, rects); + QFETCH(Rects, rects); QFETCH(int, windowFlags); QRect rect = rects.takeFirst(); @@ -4983,7 +4967,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() without showing - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -4995,6 +4979,7 @@ void tst_QWidget::windowMoveResize() { // move() first, then show() QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); if (windowFlags != 0) widget.setWindowFlags(Qt::WindowFlags(windowFlags)); @@ -5011,7 +4996,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() while shown - foreach (const QRect &r, rects) { + for (const QRect &r : qAsConst(rects)) { // XCB: First resize after show of zero-sized gets wrong win_gravity. const bool expectMoveFail = !windowFlags && ((widget.width() == 0 || widget.height() == 0) && r.width() != 0 && r.height() != 0) @@ -5040,7 +5025,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5091,7 +5076,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() while shown - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5111,7 +5096,7 @@ void tst_QWidget::windowMoveResize() QTRY_COMPARE(widget.size(), rect.size()); // move() after hide() - foreach (QRect r, rects) { + for (const QRect &r : qAsConst(rects)) { widget.move(r.topLeft()); widget.resize(r.size()); QApplication::processEvents(); @@ -5149,8 +5134,9 @@ void tst_QWidget::windowMoveResize() class ColorWidget : public QWidget { public: - ColorWidget(QWidget *parent = 0, Qt::WindowFlags f = 0, const QColor &c = QColor(Qt::red)) - : QWidget(parent, f), color(c), enters(0), leaves(0) + explicit ColorWidget(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags(), + const QColor &c = QColor(Qt::red)) + : QWidget(parent, f), color(c) { QPalette opaquePalette = palette(); opaquePalette.setColor(backgroundRole(), color); @@ -5158,16 +5144,18 @@ public: setAutoFillBackground(true); } - void paintEvent(QPaintEvent *e) { + void paintEvent(QPaintEvent *e) override + { r += e->region(); } - void reset() { + void reset() + { r = QRegion(); } - void enterEvent(QEvent *) { ++enters; } - void leaveEvent(QEvent *) { ++leaves; } + void enterEvent(QEvent *) override { ++enters; } + void leaveEvent(QEvent *) override { ++leaves; } void resetCounts() { @@ -5177,8 +5165,8 @@ public: QColor color; QRegion r; - int enters; - int leaves; + int enters = 0; + int leaves = 0; }; static inline QByteArray msgRgbMismatch(unsigned actual, unsigned expected) @@ -5196,7 +5184,7 @@ static QPixmap grabWindow(QWindow *window, int x, int y, int width, int height) #define VERIFY_COLOR(child, region, color) verifyColor(child, region, color, __LINE__) -bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, unsigned int callerLine) +bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, int callerLine) { QWindow *window = child.window()->windowHandle(); Q_ASSERT(window); @@ -5222,16 +5210,13 @@ bool verifyColor(QWidget &child, const QRegion ®ion, const QColor &color, uns If it succeeds: return success If it fails: do not return, but wait a bit and reiterate (retry) */ - if (firstPixel == QColor(color).rgb() - && image == expectedPixmap.toImage()) { + if (firstPixel == QColor(color).rgb() && image == expectedPixmap.toImage()) return true; + if (t == 4) { + grabBackingStore = true; + rect = r; } else { - if (t == 4) { - grabBackingStore = true; - rect = r; - } else { - QTest::qWait(200); - } + QTest::qWait(200); } } else { // Last run, report failure if it still fails @@ -5267,7 +5252,7 @@ void tst_QWidget::moveChild() QSKIP("Wayland: This fails. Figure out why."); QFETCH(QPoint, offset); - ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); + ColorWidget parent(nullptr, Qt::Window | Qt::WindowStaysOnTopHint); // prevent custom styles const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5314,7 +5299,8 @@ void tst_QWidget::showAndMoveChild() { if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); - QWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint); + QWidget parent(nullptr, Qt::Window | Qt::WindowStaysOnTopHint); + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // prevent custom styles const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); parent.setStyle(style.data()); @@ -5329,7 +5315,7 @@ void tst_QWidget::showAndMoveChild() parent.setGeometry(desktopDimensions); parent.setPalette(Qt::red); parent.show(); - qApp->setActiveWindow(&parent); + QApplication::setActiveWindow(&parent); QVERIFY(QTest::qWaitForWindowActive(&parent)); QWidget child(&parent); @@ -5341,7 +5327,7 @@ void tst_QWidget::showAndMoveChild() // NB! Do NOT processEvents() (or qWait()) in between show() and move(). child.show(); child.move(desktopDimensions.width()/2, desktopDimensions.height()/2); - qApp->processEvents(); + QCoreApplication::processEvents(); if (m_platform == QStringLiteral("winrt")) QSKIP("WinRT does not support setGeometry (and we cannot use QEXPECT_FAIL because of VERIFY_COLOR)"); @@ -5357,6 +5343,7 @@ void tst_QWidget::subtractOpaqueSiblings() #endif QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setGeometry(50, 50, 300, 300); ColorWidget *large = new ColorWidget(&w, Qt::Widget, Qt::red); @@ -5390,10 +5377,11 @@ void tst_QWidget::subtractOpaqueSiblings() void tst_QWidget::deleteStyle() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setStyle(QStyleFactory::create(QLatin1String("Windows"))); widget.show(); delete widget.style(); - qApp->processEvents(); + QCoreApplication::processEvents(); } class TopLevelFocusCheck: public QWidget @@ -5401,21 +5389,21 @@ class TopLevelFocusCheck: public QWidget Q_OBJECT public: QLineEdit* edit; - TopLevelFocusCheck(QWidget* parent = 0) : QWidget(parent) + explicit TopLevelFocusCheck(QWidget *parent = nullptr) + : QWidget(parent), edit(new QLineEdit(this)) { - edit = new QLineEdit(this); edit->hide(); edit->installEventFilter(this); } public slots: - void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) + void mouseDoubleClickEvent ( QMouseEvent * /*event*/ ) override { edit->show(); edit->setFocus(Qt::OtherFocusReason); - qApp->processEvents(); + QCoreApplication::processEvents(); } - bool eventFilter(QObject *obj, QEvent *event) + bool eventFilter(QObject *obj, QEvent *event) override { if (obj == edit && event->type()== QEvent::FocusOut) { edit->hide(); @@ -5462,7 +5450,7 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast(&w2)); QTest::mouseClick(&w2, Qt::LeftButton); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); + QTRY_COMPARE(QApplication::focusWidget(), nullptr); QTest::mouseDClick(&w2, Qt::LeftButton); QTRY_COMPARE(QApplication::focusWidget(), static_cast(w2.edit)); @@ -5479,28 +5467,28 @@ void tst_QWidget::multipleToplevelFocusCheck() QVERIFY(QTest::qWaitForWindowActive(&w2)); QCOMPARE(QApplication::activeWindow(), static_cast(&w2)); QTest::mouseClick(&w2, Qt::LeftButton); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget *)0); + QTRY_COMPARE(QApplication::focusWidget(), nullptr); } class FocusWidget: public QWidget { protected: - virtual bool event(QEvent *ev) + bool event(QEvent *ev) override { if (ev->type() == QEvent::FocusAboutToChange) - widgetDuringFocusAboutToChange = qApp->focusWidget(); + widgetDuringFocusAboutToChange = QApplication::focusWidget(); return QWidget::event(ev); } - virtual void focusInEvent(QFocusEvent *) + void focusInEvent(QFocusEvent *) override { - foucsObjectDuringFocusIn = qApp->focusObject(); - detectedBadEventOrdering = foucsObjectDuringFocusIn != mostRecentFocusObjectChange; + focusObjectDuringFocusIn = QGuiApplication::focusObject(); + detectedBadEventOrdering = focusObjectDuringFocusIn != mostRecentFocusObjectChange; } - virtual void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { - foucsObjectDuringFocusOut = qApp->focusObject(); - widgetDuringFocusOut = qApp->focusWidget(); - detectedBadEventOrdering = foucsObjectDuringFocusOut != mostRecentFocusObjectChange; + focusObjectDuringFocusOut = QGuiApplication::focusObject(); + widgetDuringFocusOut = QApplication::focusWidget(); + detectedBadEventOrdering = focusObjectDuringFocusOut != mostRecentFocusObjectChange; } void focusObjectChanged(QObject *focusObject) @@ -5509,22 +5497,19 @@ protected: } public: - FocusWidget(QWidget *parent) : QWidget(parent), - widgetDuringFocusAboutToChange(0), widgetDuringFocusOut(0), - foucsObjectDuringFocusIn(0), foucsObjectDuringFocusOut(0), - mostRecentFocusObjectChange(0), detectedBadEventOrdering(false) + explicit FocusWidget(QWidget *parent) : QWidget(parent) { connect(qGuiApp, &QGuiApplication::focusObjectChanged, this, &FocusWidget::focusObjectChanged); } - QWidget *widgetDuringFocusAboutToChange; - QWidget *widgetDuringFocusOut; + QWidget *widgetDuringFocusAboutToChange = nullptr; + QWidget *widgetDuringFocusOut = nullptr; - QObject *foucsObjectDuringFocusIn; - QObject *foucsObjectDuringFocusOut; + QObject *focusObjectDuringFocusIn = nullptr; + QObject *focusObjectDuringFocusOut = nullptr; - QObject *mostRecentFocusObjectChange; - bool detectedBadEventOrdering; + QObject *mostRecentFocusObjectChange = nullptr; + bool detectedBadEventOrdering = false; }; void tst_QWidget::setFocus() @@ -5621,7 +5606,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); child1.setFocus(); QTRY_VERIFY(child1.hasFocus()); @@ -5648,7 +5633,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5689,7 +5674,7 @@ void tst_QWidget::setFocus() window.show(); window.activateWindow(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QTRY_VERIFY(qGuiApp->focusWindow()); + QTRY_VERIFY(QGuiApplication::focusWindow()); QWidget child1(&window); child1.setFocusPolicy(Qt::StrongFocus); @@ -5730,6 +5715,7 @@ void tst_QWidget::setFocus() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); window.move(windowPos); @@ -5748,7 +5734,7 @@ void tst_QWidget::setFocus() QCOMPARE(window.focusWidget(), &child1); QCOMPARE(QApplication::focusWidget(), &child1); QCOMPARE(QApplication::focusObject(), &child1); - QCOMPARE(child1.foucsObjectDuringFocusIn, &child1); + QCOMPARE(child1.focusObjectDuringFocusIn, &child1); QVERIFY2(!child1.detectedBadEventOrdering, "focusObjectChanged should be delivered before widget focus events on setFocus"); @@ -5757,7 +5743,7 @@ void tst_QWidget::setFocus() QCOMPARE(window.focusWidget(), nullptr); QCOMPARE(QApplication::focusWidget(), nullptr); QCOMPARE(QApplication::focusObject(), &window); - QVERIFY(child1.foucsObjectDuringFocusOut != &child1); + QVERIFY(child1.focusObjectDuringFocusOut != &child1); QVERIFY2(!child1.detectedBadEventOrdering, "focusObjectChanged should be delivered before widget focus events on clearFocus"); } @@ -5767,7 +5753,7 @@ template class EventSpy : public QObject { public: EventSpy(T *widget, QEvent::Type event) - : m_widget(widget), eventToSpy(event), m_count(0) + : m_widget(widget), eventToSpy(event) { if (m_widget) m_widget->installEventFilter(this); @@ -5778,7 +5764,7 @@ public: void clear() { m_count = 0; } protected: - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { if (event->type() == eventToSpy) ++m_count; @@ -5787,8 +5773,8 @@ protected: private: T *m_widget; - QEvent::Type eventToSpy; - int m_count; + const QEvent::Type eventToSpy; + int m_count = 0; }; #ifndef QT_NO_CURSOR @@ -5811,6 +5797,7 @@ void tst_QWidget::setCursor() // do it again, but with window show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child(&window); window.show(); @@ -5839,6 +5826,7 @@ void tst_QWidget::setCursor() // same thing again, just with window show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget child(&window); @@ -5860,7 +5848,7 @@ void tst_QWidget::setCursor() window.setCursor(Qt::WaitCursor); - child.setParent(0); + child.setParent(nullptr); QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); QCOMPARE(child.cursor().shape(), QCursor().shape()); @@ -5876,6 +5864,7 @@ void tst_QWidget::setCursor() // again, with windows show()n { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(200, 200); QWidget window2; window2.resize(200, 200); @@ -5884,7 +5873,7 @@ void tst_QWidget::setCursor() window.setCursor(Qt::WaitCursor); window.show(); - child.setParent(0); + child.setParent(nullptr); QVERIFY(!child.testAttribute(Qt::WA_SetCursor)); QCOMPARE(child.cursor().shape(), QCursor().shape()); @@ -5936,7 +5925,7 @@ void tst_QWidget::setToolTip() for (int pass = 0; pass < 2; ++pass) { QCursor::setPos(m_safeCursorPos); - QScopedPointer popup(new QWidget(0, Qt::Popup)); + QScopedPointer popup(new QWidget(nullptr, Qt::Popup)); popup->setObjectName(QLatin1String("tst_qwidget setToolTip #") + QString::number(pass)); popup->setWindowTitle(popup->objectName()); popup->setGeometry(50, 50, 150, 50); @@ -5945,7 +5934,7 @@ void tst_QWidget::setToolTip() frame->setFrameStyle(QFrame::Box | QFrame::Plain); EventSpy spy1(frame, QEvent::ToolTip); EventSpy spy2(popup.data(), QEvent::ToolTip); - frame->setMouseTracking(pass == 0 ? false : true); + frame->setMouseTracking(pass != 0); frame->setToolTip(QLatin1String("TOOLTIP FRAME")); popup->setToolTip(QLatin1String("TOOLTIP POPUP")); popup->show(); @@ -5999,13 +5988,13 @@ void tst_QWidget::testWindowIconChangeEventPropagation() // Create spy lists. QList applicationEventSpies; QList widgetEventSpies; - foreach (QWidget *widget, widgets) { + for (QWidget *widget : qAsConst(widgets)) { applicationEventSpies.append(EventSpyPtr::create(widget, QEvent::ApplicationWindowIconChange)); widgetEventSpies.append(EventSpyPtr::create(widget, QEvent::WindowIconChange)); } QList appWindowEventSpies; QList windowEventSpies; - foreach (QWindow *window, windows) { + for (QWindow *window : qAsConst(windows)) { appWindowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::ApplicationWindowIconChange)); windowEventSpies.append(WindowEventSpyPtr::create(window, QEvent::WindowIconChange)); } @@ -6082,7 +6071,8 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() const QSize originalSize(desktopSize.width() / 2, desktopSize.height() * 4 / 10); { // Maximum size. - QWidget widget(0, Qt::X11BypassWindowManagerHint); + QWidget widget(nullptr, Qt::X11BypassWindowManagerHint); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QSize newMaximumSize = widget.size().boundedTo(originalSize) - QSize(10, 10); widget.setMaximumSize(newMaximumSize); @@ -6094,7 +6084,8 @@ void tst_QWidget::minAndMaxSizeWithX11BypassWindowManagerHint() } { // Minimum size. - QWidget widget(0, Qt::X11BypassWindowManagerHint); + QWidget widget(nullptr, Qt::X11BypassWindowManagerHint); + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const QSize newMinimumSize = widget.size().expandedTo(originalSize) + QSize(10, 10); widget.setMinimumSize(newMinimumSize); @@ -6110,13 +6101,12 @@ class ShowHideShowWidget : public QWidget, public QAbstractNativeEventFilter { Q_OBJECT - int state; + int state = 0; public: - bool gotExpectedMapNotify; - bool gotExpectedGlobalEvent; + bool gotExpectedMapNotify = false; + bool gotExpectedGlobalEvent = false; ShowHideShowWidget() - : state(0), gotExpectedMapNotify(false), gotExpectedGlobalEvent(false) { startTimer(1000); } @@ -6138,7 +6128,7 @@ public: enum { XCB_MAP_NOTIFY = 19 }; if (state == 1 && eventType == QByteArrayLiteral("xcb_generic_event_t")) { // XCB events have a uint8 response_type member at the beginning. - const unsigned char responseType = *(const unsigned char *)(message); + const auto responseType = *reinterpret_cast(message); return ((responseType & ~0x80) == XCB_MAP_NOTIFY); } return false; @@ -6169,6 +6159,7 @@ void tst_QWidget::showHideShowX11() QSKIP("This test is for X11 only."); ShowHideShowWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); qApp->installNativeEventFilter(&w); w.show(); @@ -6176,7 +6167,7 @@ void tst_QWidget::showHideShowX11() w.hide(); QEventLoop eventLoop; - connect(&w, SIGNAL(done()), &eventLoop, SLOT(quit())); + connect(&w, &ShowHideShowWidget::done, &eventLoop, &QEventLoop::quit); eventLoop.exec(); QVERIFY(w.gotExpectedGlobalEvent); @@ -6190,6 +6181,7 @@ void tst_QWidget::clean_qt_x11_enforce_cursor() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *w = new QWidget(&window); QWidget *child = new QWidget(w); child->setAttribute(Qt::WA_SetCursor, true); @@ -6223,11 +6215,9 @@ public: typedef QPair WidgetEventTypePair; typedef QList EventList; - EventRecorder(QObject *parent = 0) - : QObject(parent) - { } + using QObject::QObject; - EventList eventList() + EventList eventList() const { return events; } @@ -6237,7 +6227,7 @@ public: events.clear(); } - bool eventFilter(QObject *object, QEvent *event) + bool eventFilter(QObject *object, QEvent *event) override { QWidget *widget = qobject_cast(object); if (widget && !event->spontaneous()) @@ -6257,8 +6247,8 @@ private: void EventRecorder::formatEventList(const EventList &l, QDebug &d) { - QWidget *lastWidget = 0; - foreach (const WidgetEventTypePair &p, l) { + QWidget *lastWidget = nullptr; + for (const WidgetEventTypePair &p : l) { if (p.first != lastWidget) { d << p.first << ':'; lastWidget = p.first; @@ -6450,7 +6440,7 @@ void tst_QWidget::childEvents() QWidget child1(&widget); QWidget child2; child2.setParent(&widget); - child2.setParent(0); + child2.setParent(nullptr); QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); @@ -6487,7 +6477,7 @@ void tst_QWidget::childEvents() QWidget child1(&widget); QWidget child2; child2.setParent(&widget); - child2.setParent(0); + child2.setParent(nullptr); QCoreApplication::postEvent(&widget, new QEvent(QEvent::Type(QEvent::User + 2))); @@ -6567,6 +6557,7 @@ void tst_QWidget::render() { return; QCalendarWidget source; + source.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing // is enabled on the screen QFont f; @@ -6580,22 +6571,22 @@ void tst_QWidget::render() target.resize(source.size()); target.show(); - qApp->processEvents(); - qApp->sendPostedEvents(); + QCoreApplication::processEvents(); + QCoreApplication::sendPostedEvents(); QTest::qWait(250); const QImage sourceImage = source.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - qApp->processEvents(); + QCoreApplication::processEvents(); QImage targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(sourceImage, targetImage); // Fill target.rect() will Qt::red and render // QRegion(0, 0, source->width(), source->height() / 2, QRegion::Ellipse) // of source into target with offset (0, 30). target.setEllipseEnabled(); - qApp->processEvents(); - qApp->sendPostedEvents(); + QCoreApplication::processEvents(); + QCoreApplication::sendPostedEvents(); targetImage = target.grab(QRect(QPoint(0, 0), QSize(-1, -1))).toImage(); QVERIFY(sourceImage != targetImage); @@ -6606,6 +6597,7 @@ void tst_QWidget::render() // Test that a child widget properly fills its background { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(100, 100); // prevent custom styles window.setStyle(QStyleFactory::create(QLatin1String("Windows"))); @@ -6615,7 +6607,7 @@ void tst_QWidget::render() child.resize(window.size()); child.show(); - qApp->processEvents(); + QCoreApplication::processEvents(); const QPixmap childPixmap = child.grab(QRect(QPoint(0, 0), QSize(-1, -1))); const QPixmap windowPixmap = window.grab(QRect(QPoint(0, 0), QSize(-1, -1))); QCOMPARE(childPixmap, windowPixmap); @@ -6623,6 +6615,7 @@ void tst_QWidget::render() { // Check that the target offset is correct. QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); widget.setAutoFillBackground(true); widget.setPalette(Qt::red); @@ -6683,6 +6676,7 @@ void tst_QWidget::renderInvisible() QScopedPointer calendar(new QCalendarWidget); calendar->move(m_availableTopLeft + QPoint(100, 100)); + calendar->setWindowTitle(QLatin1String(QTest::currentTestFunction())); // disable anti-aliasing to eliminate potential differences when subpixel antialiasing // is enabled on the screen QFont f; @@ -6697,7 +6691,7 @@ void tst_QWidget::renderInvisible() dummyFocusWidget.move(calendar->geometry().bottomLeft() + QPoint(0, 100)); dummyFocusWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&dummyFocusWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(120); // Create normal reference image. @@ -6712,7 +6706,7 @@ void tst_QWidget::renderInvisible() // Create resized reference image. const QSize calendarSizeResized = calendar->size() + QSize(50, 50); calendar->resize(calendarSizeResized); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); QImage referenceImageResized(calendarSizeResized, QImage::Format_ARGB32); calendar->render(&referenceImageResized); @@ -6723,7 +6717,7 @@ void tst_QWidget::renderInvisible() // Explicitly hide the calendar. calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); workaroundPaletteIssue(calendar.data()); @@ -6753,7 +6747,7 @@ void tst_QWidget::renderInvisible() } calendar->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); { // Calendar explicitly hidden. @@ -6821,7 +6815,7 @@ void tst_QWidget::renderInvisible() // Navigation bar isn't explicitly hidden anymore. navigationBar->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTest::qWait(30); QVERIFY(!calendar->isVisible()); @@ -6830,7 +6824,7 @@ void tst_QWidget::renderInvisible() // make sure the layout is activated before rendering. QVERIFY(!calendar->isVisible()); calendar->resize(calendarSizeResized); - qApp->processEvents(); + QCoreApplication::processEvents(); { // Make sure we get an image equal to the resized reference image. QImage testImage(calendarSizeResized, QImage::Format_ARGB32); @@ -6883,7 +6877,7 @@ void tst_QWidget::renderInvisible() void tst_QWidget::renderWithPainter() { - QWidget widget(0, Qt::Tool); + QWidget widget(nullptr, Qt::Tool); // prevent custom styles const QScopedPointer style(QStyleFactory::create(QLatin1String("Windows"))); @@ -6999,7 +6993,7 @@ void tst_QWidget::render_task211796() { class MyWidget : public QWidget { - void resizeEvent(QResizeEvent *) + void resizeEvent(QResizeEvent *) override { QPixmap pixmap(size()); render(&pixmap); @@ -7008,6 +7002,7 @@ void tst_QWidget::render_task211796() { // Please don't die in a resize recursion. MyWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(m_testWidgetSize); centerOnScreen(&widget); widget.show(); @@ -7015,6 +7010,7 @@ void tst_QWidget::render_task211796() { // Same check with a deeper hierarchy. QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(m_testWidgetSize); centerOnScreen(&widget); widget.show(); @@ -7083,19 +7079,19 @@ void tst_QWidget::render_windowOpacity() class MyWidget : public QWidget { public: - void paintEvent(QPaintEvent *) + explicit MyWidget(qreal opacityIn) : opacity(opacityIn) {} + void paintEvent(QPaintEvent *) override { QPainter painter(this); painter.setOpacity(opacity); QCOMPARE(painter.opacity(), opacity); painter.fillRect(rect(), Qt::red); } - qreal opacity; + const qreal opacity; }; - MyWidget widget; + MyWidget widget(opacity); widget.resize(50, 50); - widget.opacity = opacity; widget.setPalette(Qt::blue); widget.setAutoFillBackground(true); @@ -7232,16 +7228,16 @@ void tst_QWidget::render_systemClip2() class MyWidget : public QWidget { public: - bool usePaintEvent; - void paintEvent(QPaintEvent *) + explicit MyWidget(bool usePaintEventIn) : usePaintEvent(usePaintEventIn) {} + const bool usePaintEvent; + void paintEvent(QPaintEvent *) override { if (usePaintEvent) QPainter(this).fillRect(rect(), Qt::green); } }; - MyWidget widget; - widget.usePaintEvent = usePaintEvent; + MyWidget widget(usePaintEvent); widget.setPalette(Qt::blue); // NB! widget.setAutoFillBackground(autoFillBackground) won't do the // trick here since the widget is a top-level. The background is filled @@ -7337,7 +7333,6 @@ void tst_QWidget::render_systemClip3() const QRegion redArea(QRegion(0, 0, size.width(), size.height()) - outerCross); const QRegion whiteArea(outerCross - innerCross); - const QRegion blueArea(innerCross); QRegion systemClip; // Okay, here's the image that should look like a Norwegian civil/war flag in the end. @@ -7363,8 +7358,9 @@ void tst_QWidget::render_systemClip3() // The outer cross (white) should be drawn when the background is auto-filled, and // the inner cross (blue) should be drawn in the paintEvent. class MyWidget : public QWidget - { public: - void paintEvent(QPaintEvent *) + { + public: + void paintEvent(QPaintEvent *) override { QPainter painter(this); // Be evil and try to paint outside the outer cross. This should not be @@ -7419,8 +7415,9 @@ void tst_QWidget::render_task252837() void tst_QWidget::render_worldTransform() { class MyWidget : public QWidget - { public: - void paintEvent(QPaintEvent *) + { + public: + void paintEvent(QPaintEvent *) override { QPainter painter(this); // Make sure world transform is identity. @@ -7514,6 +7511,7 @@ void tst_QWidget::setContentsMargins() QVERIFY2(oldSize != newSize, msgComparisonFailed(oldSize, "!=", newSize)); QLabel label2("why does it always rain on me?"); + label2.setWindowTitle(QLatin1String(QTest::currentTestFunction())); label2.show(); label2.setFrameStyle(QFrame::Sunken | QFrame::Box); QCOMPARE(newSize, label2.sizeHint()); @@ -7546,7 +7544,7 @@ void tst_QWidget::moveWindowInShowEvent() { public: QPoint position; - void showEvent(QShowEvent *) + void showEvent(QShowEvent *) override { move(position); } @@ -7577,7 +7575,8 @@ void tst_QWidget::repaintWhenChildDeleted() QTest::qWait(1000); } #endif - ColorWidget w(0, Qt::FramelessWindowHint, Qt::red); + ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; @@ -7601,7 +7600,8 @@ void tst_QWidget::repaintWhenChildDeleted() // task 175114 void tst_QWidget::hideOpaqueChildWhileHidden() { - ColorWidget w(0, Qt::FramelessWindowHint, Qt::red); + ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPoint startPoint = QApplication::desktop()->availableGeometry(&w).topLeft(); startPoint.rx() += 50; startPoint.ry() += 50; @@ -7644,6 +7644,7 @@ void tst_QWidget::updateWhileMinimized() QSKIP("Platform does not support showMinimized()"); #endif UpdateWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // Filter out activation change and focus events to avoid update() calls in QWidget. widget.updateOnActivationChangeAndFocusIn = false; widget.reset(); @@ -7678,13 +7679,10 @@ void tst_QWidget::updateWhileMinimized() class PaintOnScreenWidget: public QWidget { public: - PaintOnScreenWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) - :QWidget(parent, f) - { - } + using QWidget::QWidget; #if defined(Q_OS_WIN) // This is the only way to enable PaintOnScreen on Windows. - QPaintEngine * paintEngine () const {return 0;} + QPaintEngine *paintEngine() const override { return nullptr; } #endif }; @@ -7695,6 +7693,7 @@ void tst_QWidget::alienWidgets() qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(m_testWidgetSize); QWidget child(&parent); QWidget grandChild(&child); @@ -7729,6 +7728,7 @@ void tst_QWidget::alienWidgets() // Ensure that hide() on an ancestor of a widget with // Qt::WA_DontCreateNativeAncestors still gets unmapped QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); QWidget widget(&window); QWidget child(&widget); @@ -7772,6 +7772,7 @@ void tst_QWidget::alienWidgets() // Check that widgets with the Qt::MSWindowsOwnDC attribute set // are native. QWidget msWindowsOwnDC(&parent, Qt::MSWindowsOwnDC); + msWindowsOwnDC.setWindowTitle(QLatin1String(QTest::currentTestFunction())); msWindowsOwnDC.show(); QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_WState_Created)); QVERIFY(msWindowsOwnDC.testAttribute(Qt::WA_NativeWindow)); @@ -7800,6 +7801,7 @@ void tst_QWidget::alienWidgets() { // Make sure we create native ancestors when setting Qt::WA_PaintOnScreen before show(). QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(m_testWidgetSize); QWidget child(&topLevel); QWidget grandChild(&child); @@ -7824,6 +7826,7 @@ void tst_QWidget::alienWidgets() { // Ensure that widgets reparented into Qt::WA_PaintOnScreen widgets become native. QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(m_testWidgetSize); QWidget *widget = new PaintOnScreenWidget(&topLevel); widget->setAttribute(Qt::WA_PaintOnScreen); @@ -7857,6 +7860,7 @@ void tst_QWidget::alienWidgets() { // Ensure that ancestors of a Qt::WA_PaintOnScreen widget stay native // if they are re-created (typically in QWidgetPrivate::setParent_sys) (task 210822). QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.resize(m_testWidgetSize); QWidget child(&window); @@ -7895,6 +7899,7 @@ void tst_QWidget::alienWidgets() { // Ensure that all siblings are native unless Qt::AA_DontCreateNativeWidgetSiblings is set. qApp->setAttribute(Qt::AA_DontCreateNativeWidgetSiblings, false); QWidget mainWindow; + mainWindow.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *toolBar = new QWidget(&mainWindow); QWidget *dockWidget = new QWidget(&mainWindow); QWidget *centralWidget = new QWidget(&mainWindow); @@ -7929,7 +7934,7 @@ void tst_QWidget::alienWidgets() class ASWidget : public QWidget { public: - ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = 0) + ASWidget(QSize sizeHint, QSizePolicy sizePolicy, bool layout, bool hfwLayout, QWidget *parent = nullptr) : QWidget(parent), mySizeHint(sizeHint) { setObjectName(QStringLiteral("ASWidget")); @@ -7946,17 +7951,15 @@ public: } } - QSize sizeHint() const { + QSize sizeHint() const override + { if (layout()) return layout()->totalSizeHint(); return mySizeHint; } - int heightForWidth(int width) const { - if (sizePolicy().hasHeightForWidth()) { - return width * 2; - } else { - return -1; - } + int heightForWidth(int width) const override + { + return sizePolicy().hasHeightForWidth() ? width * 2 : -1; } QSize mySizeHint; @@ -8031,7 +8034,7 @@ void tst_QWidget::adjustSize() QSizePolicy sp = QSizePolicy(QSizePolicy::Policy(hPolicy), QSizePolicy::Policy(vPolicy)); sp.setHeightForWidth(hfwSP); - QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent.data() : 0); + QWidget *child = new ASWidget(sizeHint, sp, layout, hfwLayout, haveParent ? parent.data() : nullptr); child->resize(123, 456); child->adjustSize(); if (expectedSize == QSize(100000, 100000)) { @@ -8050,17 +8053,14 @@ class TestLayout : public QVBoxLayout { Q_OBJECT public: - TestLayout(QWidget *w = 0) : QVBoxLayout(w) - { - invalidated = false; - } + using QVBoxLayout::QVBoxLayout; - void invalidate() + void invalidate() override { invalidated = true; } - bool invalidated; + bool invalidated = false; }; void tst_QWidget::updateGeometry_data() @@ -8069,7 +8069,7 @@ void tst_QWidget::updateGeometry_data() QTest::addColumn("shouldInvalidate"); QTest::addColumn("maxSize"); QTest::addColumn("shouldInvalidate2"); - QTest::addColumn("verticalSizePolicy"); + QTest::addColumn("verticalSizePolicy"); QTest::addColumn("shouldInvalidate3"); QTest::addColumn("setVisible"); QTest::addColumn("shouldInvalidate4"); @@ -8077,32 +8077,32 @@ void tst_QWidget::updateGeometry_data() QTest::newRow("setMinimumSize") << QSize(100, 100) << true << QSize() << false - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMaximumSize") << QSize() << false << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to a different size") << QSize(100, 100) << true << QSize(300, 300) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to the same size") << QSize(100, 100) << true << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << true << false; QTest::newRow("setMinimumSize, then maximumSize to the same size and then hide it") << QSize(100, 100) << true << QSize(100, 100) << true - << int(QSizePolicy::Preferred) << false + << QSizePolicy::Preferred << false << false << true; QTest::newRow("Change sizePolicy") << QSize() << false << QSize() << false - << int(QSizePolicy::Minimum) << true + << QSizePolicy::Minimum << true << true << false; } @@ -8113,11 +8113,13 @@ void tst_QWidget::updateGeometry() QFETCH(bool, shouldInvalidate); QFETCH(QSize, maxSize); QFETCH(bool, shouldInvalidate2); - QFETCH(int, verticalSizePolicy); + QFETCH(QSizePolicy::Policy, verticalSizePolicy); QFETCH(bool, shouldInvalidate3); QFETCH(bool, setVisible); QFETCH(bool, shouldInvalidate4); QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction()) + QLatin1String("::") + + QLatin1String(QTest::currentDataTag())); parent.resize(200, 200); TestLayout *lout = new TestLayout(); parent.setLayout(lout); @@ -8137,7 +8139,7 @@ void tst_QWidget::updateGeometry() QCOMPARE(lout->invalidated, shouldInvalidate2); lout->invalidated = false; - child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, (QSizePolicy::Policy)verticalSizePolicy)); + child->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, verticalSizePolicy)); if (shouldInvalidate3) QCOMPARE(lout->invalidated, true); @@ -8150,11 +8152,12 @@ void tst_QWidget::updateGeometry() void tst_QWidget::sendUpdateRequestImmediately() { UpdateWidget updateWidget; + updateWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); updateWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&updateWidget)); - qApp->processEvents(); + QCoreApplication::processEvents(); updateWidget.reset(); QCOMPARE(updateWidget.numUpdateRequestEvents, 0); @@ -8173,6 +8176,7 @@ void tst_QWidget::doubleRepaint() QSKIP("Not having window server access causes the wrong number of repaints to be issues"); #endif UpdateWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(&widget); widget.setFocusPolicy(Qt::StrongFocus); // Filter out activation change and focus events to avoid update() calls in QWidget. @@ -8206,10 +8210,11 @@ void tst_QWidget::doubleRepaint() void tst_QWidget::resizeInPaintEvent() { QWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); UpdateWidget widget(&window); window.resize(200, 200); window.show(); - qApp->setActiveWindow(&window); + QApplication::setActiveWindow(&window); QVERIFY(QTest::qWaitForWindowExposed(&window)); QTRY_VERIFY(widget.numPaintEvents > 0); @@ -8230,6 +8235,7 @@ void tst_QWidget::resizeInPaintEvent() void tst_QWidget::opaqueChildren() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); QWidget child(&widget); @@ -8270,10 +8276,10 @@ class MaskSetWidget : public QWidget { Q_OBJECT public: - MaskSetWidget(QWidget* p =0) - : QWidget(p) {} + using QWidget::QWidget; - void paintEvent(QPaintEvent* event) { + void paintEvent(QPaintEvent *event) override + { QPainter p(this); paintedRegion += event->region(); @@ -8281,26 +8287,22 @@ public: p.fillRect(r, Qt::red); } - void resizeEvent(QResizeEvent*) { + void resizeEvent(QResizeEvent *) override + { setMask(QRegion(QRect(0, 0, width(), 10).normalized())); } QRegion paintedRegion; public slots: - void resizeDown() { - setGeometry(QRect(0, 50, 50, 50)); - } - - void resizeUp() { - setGeometry(QRect(0, 50, 150, 50)); - } - + void resizeDown() { setGeometry(QRect(0, 50, 50, 50)); } + void resizeUp() { setGeometry(QRect(0, 50, 150, 50)); } }; void tst_QWidget::setMaskInResizeEvent() { UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.reset(); w.resize(200, 200); centerOnScreen(&w); @@ -8339,19 +8341,19 @@ class MoveInResizeWidget : public QWidget { Q_OBJECT public: - MoveInResizeWidget(QWidget* p = 0) + explicit MoveInResizeWidget(QWidget *p = nullptr) : QWidget(p) { setWindowFlags(Qt::FramelessWindowHint); } - void resizeEvent(QResizeEvent*) { - + void resizeEvent(QResizeEvent *) override + { move(QPoint(100,100)); static bool firstTime = true; if (firstTime) - QTimer::singleShot(250, this, SLOT(resizeMe())); + QTimer::singleShot(250, this, &MoveInResizeWidget::resizeMe); firstTime = false; } @@ -8365,6 +8367,7 @@ public slots: void tst_QWidget::moveInResizeEvent() { MoveInResizeWidget testWidget; + testWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); testWidget.setGeometry(50, 50, 200, 200); testWidget.show(); QVERIFY(QTest::qWaitForWindowExposed(&testWidget)); @@ -8379,6 +8382,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() QSKIP("We don't support immediate repaint right after show on other platforms."); QScopedPointer widget(new UpdateWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(widget.data()); widget->show(); QVERIFY(QTest::qWaitForWindowExposed(widget.data())); @@ -8400,6 +8404,7 @@ void tst_QWidget::immediateRepaintAfterInvalidateBuffer() void tst_QWidget::effectiveWinId() { QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200, 200); QWidget child(&parent); @@ -8417,8 +8422,9 @@ void tst_QWidget::effectiveWinId2() { QWidget parent; - class MyWidget : public QWidget { - bool event(QEvent *e) + class MyWidget : public QWidget + { + bool event(QEvent *e) override { if (e->type() == QEvent::WinIdChange) { // Shouldn't crash. @@ -8433,18 +8439,19 @@ void tst_QWidget::effectiveWinId2() child.setParent(&parent); parent.show(); - child.setParent(0); + child.setParent(nullptr); child.setParent(&parent); } class CustomWidget : public QWidget { public: - mutable int metricCallCount; + mutable int metricCallCount = 0; - CustomWidget(QWidget *parent = 0) : QWidget(parent), metricCallCount(0) {} + using QWidget::QWidget; - virtual int metric(PaintDeviceMetric metric) const { + int metric(PaintDeviceMetric metric) const override + { ++metricCallCount; return QWidget::metric(metric); } @@ -8538,6 +8545,7 @@ void tst_QWidget::quitOnCloseAttribute() void tst_QWidget::moveRect() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 200); widget.setUpdatesEnabled(false); QWidget child(&widget); @@ -8558,11 +8566,12 @@ public: timer.setSingleShot(true); timer.setInterval(0); } - QPaintEngine *paintEngine() const { return 0; } + QPaintEngine *paintEngine() const override { return nullptr; } - void paintEvent(QPaintEvent *) { + void paintEvent(QPaintEvent *) override + { QPlatformNativeInterface *ni = QGuiApplication::platformNativeInterface(); - const HDC hdc = (HDC)ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle()); + const auto hdc = reinterpret_cast(ni->nativeResourceForWindow(QByteArrayLiteral("getDC"), windowHandle())); if (hdc) { const HBRUSH brush = CreateSolidBrush(RGB(255, 0, 0)); SelectObject(hdc, brush); @@ -8579,9 +8588,7 @@ public: } } - QSize sizeHint() const { - return QSize(400, 300); - } + QSize sizeHint() const override { return {400, 300}; }; private slots: void slotTimer() { @@ -8608,6 +8615,7 @@ void tst_QWidget::gdiPainting() void tst_QWidget::paintOnScreenPossible() { QWidget w1; + w1.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w1.setAttribute(Qt::WA_PaintOnScreen); QVERIFY(!w1.testAttribute(Qt::WA_PaintOnScreen)); @@ -8664,7 +8672,7 @@ void tst_QWidget::reparentStaticWidget() window2.resize(window2.size() + QSize(2, 2)); QTest::qWait(20); - child->setParent(0); + child->setParent(nullptr); child->show(); QTest::qWait(20); @@ -8734,12 +8742,13 @@ void tst_QWidget::QTBUG6883_reparentStaticWidget2() class ColorRedWidget : public QWidget { public: - ColorRedWidget(QWidget *parent = 0) + explicit ColorRedWidget(QWidget *parent = nullptr) : QWidget(parent, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint | Qt::ToolTip) { } - void paintEvent(QPaintEvent *) { + void paintEvent(QPaintEvent *) override + { QPainter p(this); p.fillRect(rect(),Qt::red); } @@ -8750,6 +8759,7 @@ void tst_QWidget::translucentWidget() QPixmap pm(16,16); pm.fill(Qt::red); ColorRedWidget label; + label.setWindowTitle(QLatin1String(QTest::currentTestFunction())); label.setFixedSize(16,16); label.setAttribute(Qt::WA_TranslucentBackground); const QPoint labelPos = QGuiApplication::primaryScreen()->availableGeometry().topLeft(); @@ -8778,12 +8788,13 @@ class MaskResizeTestWidget : public QWidget { Q_OBJECT public: - MaskResizeTestWidget(QWidget* p =0) - : QWidget(p) { + explicit MaskResizeTestWidget(QWidget* p = nullptr) : QWidget(p) + { setMask(QRegion(QRect(0, 0, 100, 100).normalized())); } - void paintEvent(QPaintEvent* event) { + void paintEvent(QPaintEvent* event) override + { QPainter p(this); paintedRegion += event->region(); @@ -8809,10 +8820,11 @@ public slots: void tst_QWidget::setClearAndResizeMask() { UpdateWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(160, 160); centerOnScreen(&topLevel); topLevel.show(); - qApp->setActiveWindow(&topLevel); + QApplication::setActiveWindow(&topLevel); QVERIFY(QTest::qWaitForWindowExposed(&topLevel)); QTRY_VERIFY(topLevel.numPaintEvents > 0); topLevel.reset(); @@ -8959,6 +8971,7 @@ void tst_QWidget::setClearAndResizeMask() void tst_QWidget::maskedUpdate() { UpdateWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(200, 200); centerOnScreen(&topLevel); const QRegion topLevelMask(50, 50, 70, 70); @@ -9112,16 +9125,17 @@ void tst_QWidget::syntheticEnterLeave() class MyWidget : public QWidget { public: - MyWidget(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numLeaveEvents(0) {} - void enterEvent(QEvent *) { ++numEnterEvents; } - void leaveEvent(QEvent *) { ++numLeaveEvents; } - int numEnterEvents; - int numLeaveEvents; + using QWidget::QWidget; + void enterEvent(QEvent *) override { ++numEnterEvents; } + void leaveEvent(QEvent *) override { ++numLeaveEvents; } + int numEnterEvents = 0; + int numLeaveEvents = 0; }; QCursor::setPos(m_safeCursorPos); MyWidget window; + window.setWindowTitle(QLatin1String(QTest::currentTestFunction())); window.setWindowFlags(Qt::WindowStaysOnTopHint); window.move(200, 200); window.resize(200, 200); @@ -9217,31 +9231,32 @@ void tst_QWidget::taskQTBUG_4055_sendSyntheticEnterLeave() class SELParent : public QWidget { public: - SELParent(QWidget *parent = 0): QWidget(parent) { } + using QWidget::QWidget; - void mousePressEvent(QMouseEvent *) { child->show(); } - QWidget *child; + void mousePressEvent(QMouseEvent *) override { child->show(); } + QWidget *child = nullptr; }; class SELChild : public QWidget - { - public: - SELChild(QWidget *parent = 0) : QWidget(parent), numEnterEvents(0), numMouseMoveEvents(0) {} - void enterEvent(QEvent *) { ++numEnterEvents; } - void mouseMoveEvent(QMouseEvent *event) - { - QCOMPARE(event->button(), Qt::NoButton); - QCOMPARE(event->buttons(), QApplication::mouseButtons()); - QCOMPARE(event->modifiers(), QApplication::keyboardModifiers()); - ++numMouseMoveEvents; - } - void reset() { numEnterEvents = numMouseMoveEvents = 0; } - int numEnterEvents, numMouseMoveEvents; - }; + { + public: + using QWidget::QWidget; + void enterEvent(QEvent *) override { ++numEnterEvents; } + void mouseMoveEvent(QMouseEvent *event) override + { + QCOMPARE(event->button(), Qt::NoButton); + QCOMPARE(event->buttons(), QApplication::mouseButtons()); + QCOMPARE(event->modifiers(), QApplication::keyboardModifiers()); + ++numMouseMoveEvents; + } + void reset() { numEnterEvents = numMouseMoveEvents = 0; } + int numEnterEvents = 0, numMouseMoveEvents = 0; + }; QCursor::setPos(m_safeCursorPos); SELParent parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.move(200, 200); parent.resize(200, 200); SELChild child(&parent); @@ -9341,9 +9356,9 @@ class MyEvilObject : public QObject { Q_OBJECT public: - MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) + explicit MyEvilObject(QWidget *widgetToCrash) : QObject(), widget(widgetToCrash) { - connect(widget, SIGNAL(destroyed(QObject*)), this, SLOT(beEvil(QObject*))); + connect(widget, &QObject::destroyed, this, &MyEvilObject::beEvil); delete widget; } QWidget *widget; @@ -9355,6 +9370,7 @@ private slots: void tst_QWidget::updateOnDestroyedSignal() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget *child = new QWidget(&widget); child->resize(m_testWidgetSize); @@ -9372,18 +9388,20 @@ void tst_QWidget::updateOnDestroyedSignal() void tst_QWidget::toplevelLineEditFocus() { QLineEdit w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setMinimumWidth(m_testWidgetSize.width()); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); - QTRY_COMPARE(QApplication::activeWindow(), (QWidget*)&w); - QTRY_COMPARE(QApplication::focusWidget(), (QWidget*)&w); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(&w)); + QTRY_COMPARE(QApplication::focusWidget(), static_cast(&w)); } void tst_QWidget::focusWidget_task254563() { //having different visibility for widget is important QWidget top; + top.setWindowTitle(QLatin1String(QTest::currentTestFunction())); top.show(); QWidget container(&top); QWidget *widget = new QWidget(&container); @@ -9400,6 +9418,7 @@ void tst_QWidget::focusWidget_task254563() void tst_QWidget::destroyBackingStore() { UpdateWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); centerOnScreen(&w); w.reset(); w.show(); @@ -9426,7 +9445,7 @@ void tst_QWidget::destroyBackingStore() // Helper function QWidgetBackingStore* backingStore(QWidget &widget) { - QWidgetBackingStore *backingStore = 0; + QWidgetBackingStore *backingStore = nullptr; #ifdef QT_BUILD_INTERNAL if (QTLWExtra *topExtra = qt_widget_private(&widget)->maybeTopData()) backingStore = topExtra->backingStoreTracker.data(); @@ -9440,7 +9459,8 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::BlankCursor); //keep the cursor out of screen grabs #endif - QWidget main(0,Qt::FramelessWindowHint); //don't get confused by the size of the window frame + QWidget main(nullptr, Qt::FramelessWindowHint); //don't get confused by the size of the window frame + main.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPalette palette; palette.setColor(QPalette::Window, Qt::red); main.setPalette(palette); @@ -9483,6 +9503,7 @@ void tst_QWidget::setGraphicsEffect() { // Check that we don't have any effect by default. QScopedPointer widget(new QWidget); + widget->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QVERIFY(!widget->graphicsEffect()); // SetGet check. @@ -9519,7 +9540,7 @@ void tst_QWidget::setGraphicsEffect() // Ensure the existing effect is uninstalled and deleted when setting a null effect blurEffect = new QGraphicsBlurEffect; widget->setGraphicsEffect(blurEffect); - widget->setGraphicsEffect(0); + widget->setGraphicsEffect(nullptr); QVERIFY(!widget->graphicsEffect()); QVERIFY(!blurEffect); } @@ -9533,6 +9554,7 @@ void tst_QWidget::activateWindow() // Create first mainwindow and set it active QScopedPointer mainwindow(new QMainWindow); + mainwindow->setWindowTitle(QLatin1String(QTest::currentTestFunction())); QLabel* label = new QLabel(mainwindow.data()); label->setMinimumWidth(m_testWidgetSize.width()); mainwindow->setWindowTitle(QStringLiteral("#1 ") + __FUNCTION__); @@ -9552,7 +9574,7 @@ void tst_QWidget::activateWindow() mainwindow2->move(mainwindow->geometry().bottomLeft() + QPoint(0, 50)); mainwindow2->setVisible(true); mainwindow2->activateWindow(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(!mainwindow->isActiveWindow()); QTRY_VERIFY(mainwindow2->isActiveWindow()); @@ -9560,7 +9582,7 @@ void tst_QWidget::activateWindow() // Revert first mainwindow back to visible active mainwindow->setVisible(true); mainwindow->activateWindow(); - qApp->processEvents(); + QCoreApplication::processEvents(); QTRY_VERIFY(mainwindow->isActiveWindow()); if (m_platform == QStringLiteral("winrt")) @@ -9596,7 +9618,8 @@ void tst_QWidget::focusProxyAndInputMethods() { if (m_platform == QStringLiteral("wayland")) QSKIP("Wayland: This fails. Figure out why."); - QScopedPointer toplevel(new QWidget(0, Qt::X11BypassWindowManagerHint)); + QScopedPointer toplevel(new QWidget(nullptr, Qt::X11BypassWindowManagerHint)); + toplevel->setWindowTitle(QLatin1String(QTest::currentTestFunction())); toplevel->resize(200, 200); toplevel->setAttribute(Qt::WA_InputMethodEnabled, true); @@ -9643,6 +9666,7 @@ public: void tst_QWidget::scrollWithoutBackingStore() { scrollWidgetWBS scrollable; + scrollable.setWindowTitle(QLatin1String(QTest::currentTestFunction())); scrollable.resize(200, 200); QLabel child(QString("@"),&scrollable); child.resize(50,50); @@ -9661,6 +9685,7 @@ void tst_QWidget::scrollWithoutBackingStore() void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setFocusPolicy(Qt::TabFocus); QWidget *fp = new QWidget(&w); fp->setFocusPolicy(Qt::TabFocus); @@ -9673,7 +9698,8 @@ void tst_QWidget::taskQTBUG_7532_tabOrderWithFocusProxy() void tst_QWidget::movedAndResizedAttributes() { // Use Qt::Tool as fully decorated windows have a minimum width of 160 on - QWidget w(0, Qt::Tool); + QWidget w(nullptr, Qt::Tool); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.show(); QVERIFY(!w.testAttribute(Qt::WA_Moved)); @@ -9721,7 +9747,8 @@ void tst_QWidget::movedAndResizedAttributes() void tst_QWidget::childAt() { - QWidget parent(0, Qt::FramelessWindowHint); + QWidget parent(nullptr, Qt::FramelessWindowHint); + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200, 200); QWidget *child = new QWidget(&parent); @@ -9801,6 +9828,7 @@ void tst_QWidget::taskQTBUG_11373() void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion() { QTableView tb; + tb.setWindowTitle(QLatin1String(QTest::currentTestFunction())); const char *s = "border: 1px solid;"; tb.setStyleSheet(s); tb.show(); @@ -9813,6 +9841,7 @@ void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion() void tst_QWidget::nativeChildFocus() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setMinimumWidth(m_testWidgetSize.width()); w.setWindowTitle(__FUNCTION__); QLayout *layout = new QVBoxLayout; @@ -9850,8 +9879,8 @@ static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) const int size = actual.width() * actual.height(); const int threshold = QPixmap::defaultDepth() == 16 ? 10 : 2; - QRgb *a = (QRgb *)actualImage.bits(); - QRgb *e = (QRgb *)expectedImage.bits(); + auto a = reinterpret_cast(actualImage.bits()); + auto e = reinterpret_cast(expectedImage.bits()); for (int i = 0; i < size; ++i) { const QColor ca(a[i]); const QColor ce(e[i]); @@ -9871,6 +9900,7 @@ void tst_QWidget::grab() { for (int opaque = 0; opaque < 2; ++opaque) { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QImage image(128, 128, opaque ? QImage::Format_RGB32 : QImage::Format_ARGB32_Premultiplied); for (int row = 0; row < image.height(); ++row) { QRgb *line = reinterpret_cast(image.scanLine(row)); @@ -9920,12 +9950,13 @@ static inline QString mouseEventLogEntry(const QString &objectName, QEvent::Type return result; } -class GrabLoggerWidget : public QWidget { +class GrabLoggerWidget : public QWidget +{ public: - explicit GrabLoggerWidget(QStringList *log, QWidget *parent = 0) : QWidget(parent), m_log(log) {} + explicit GrabLoggerWidget(QStringList *log, QWidget *parent = nullptr) : QWidget(parent), m_log(log) {} protected: - bool event(QEvent *e) + bool event(QEvent *e) override { switch (e->type()) { case QEvent::MouseButtonPress: @@ -9949,6 +9980,7 @@ void tst_QWidget::grabMouse() { QStringList log; GrabLoggerWidget w(&log); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setObjectName(QLatin1String("tst_qwidget_grabMouse")); w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); @@ -9960,7 +9992,7 @@ void tst_QWidget::grabMouse() layout->addWidget(grabber); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); + QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); QStringList expectedLog; @@ -9969,7 +10001,7 @@ void tst_QWidget::grabMouse() grabber->grabMouse(); const int step = w.height() / 5; for ( ; mousePos.y() < w.height() ; mousePos.ry() += step) { - QTest::mouseClick(w.windowHandle(), Qt::LeftButton, 0, mousePos); + QTest::mouseClick(w.windowHandle(), Qt::LeftButton, Qt::KeyboardModifiers(), mousePos); // Events should go to the grabber child using its coordinates. const QPoint expectedPos = grabber->mapFromParent(mousePos); expectedLog.push_back(mouseEventLogEntry(grabberObjectName, QEvent::MouseButtonPress, expectedPos, Qt::LeftButton)); @@ -9982,6 +10014,7 @@ void tst_QWidget::grabMouse() void tst_QWidget::grabKeyboard() { QWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.setObjectName(QLatin1String("tst_qwidget_grabKeyboard")); w.setWindowTitle(w.objectName()); QLayout *layout = new QVBoxLayout(&w); @@ -9993,7 +10026,7 @@ void tst_QWidget::grabKeyboard() layout->addWidget(nonGrabber); centerOnScreen(&w); w.show(); - qApp->setActiveWindow(&w); + QApplication::setActiveWindow(&w); QVERIFY(QTest::qWaitForWindowActive(&w)); nonGrabber->setFocus(); grabber->grabKeyboard(); @@ -10005,16 +10038,7 @@ void tst_QWidget::grabKeyboard() class TouchMouseWidget : public QWidget { public: - explicit TouchMouseWidget(QWidget *parent = 0) - : QWidget(parent), - m_touchBeginCount(0), - m_touchUpdateCount(0), - m_touchEndCount(0), - m_touchEventCount(0), - m_gestureEventCount(0), - m_acceptTouch(false), - m_mouseEventCount(0), - m_acceptMouse(true) + explicit TouchMouseWidget(QWidget *parent = nullptr) : QWidget(parent) { resize(200, 200); } @@ -10031,7 +10055,7 @@ public: } protected: - bool event(QEvent *e) + bool event(QEvent *e) override { switch (e->type()) { case QEvent::TouchBegin: @@ -10070,14 +10094,14 @@ protected: } public: - int m_touchBeginCount; - int m_touchUpdateCount; - int m_touchEndCount; - int m_touchEventCount; - int m_gestureEventCount; - bool m_acceptTouch; - int m_mouseEventCount; - bool m_acceptMouse; + int m_touchBeginCount = 0; + int m_touchUpdateCount = 0; + int m_touchEndCount = 0; + int m_touchEventCount = 0; + int m_gestureEventCount = 0; + bool m_acceptTouch = false; + int m_mouseEventCount = 0; + bool m_acceptMouse = true; QPointF m_lastMouseEventPos; }; @@ -10086,6 +10110,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // Simple case, we ignore the touch events, we get mouse events instead TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle())); QCOMPARE(widget.m_touchEventCount, 0); @@ -10108,6 +10133,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() { // We accept the touch events, no mouse event is generated TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setAcceptTouch(true); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(widget.windowHandle())); @@ -10129,6 +10155,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() // Parent accepts touch events, child ignore both mouse and touch // We should see propagation of the TouchBegin TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.setAcceptTouch(true); TouchMouseWidget child(&parent); child.move(5, 5); @@ -10151,6 +10178,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() // Parent accepts mouse events, child ignore both mouse and touch // We should see propagation of the TouchBegin into a MouseButtonPress TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); TouchMouseWidget child(&parent); const QPoint childPos(5, 5); child.move(childPos); @@ -10176,6 +10204,7 @@ void tst_QWidget::touchEventSynthesizedMouseEvent() void tst_QWidget::touchUpdateOnNewTouch() { TouchMouseWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setAcceptTouch(true); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(new QWidget); @@ -10212,6 +10241,7 @@ void tst_QWidget::touchUpdateOnNewTouch() void tst_QWidget::touchEventsForGesturePendingWidgets() { TouchMouseWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); TouchMouseWidget child(&parent); parent.grabGesture(Qt::TapAndHoldGesture); parent.show(); @@ -10250,8 +10280,9 @@ void tst_QWidget::touchEventsForGesturePendingWidgets() void tst_QWidget::styleSheetPropagation() { QTableView tw; + tw.setWindowTitle(QLatin1String(QTest::currentTestFunction())); tw.setStyleSheet("background-color: red;"); - foreach (QObject *child, tw.children()) { + for (QObject *child : tw.children()) { if (QWidget *w = qobject_cast(child)) QCOMPARE(w->style(), tw.style()); } @@ -10261,7 +10292,7 @@ class DestroyTester : public QObject { Q_OBJECT public: - DestroyTester(QObject *parent) : QObject(parent) { parentDestroyed = 0; } + explicit DestroyTester(QObject *parent = nullptr) : QObject(parent) { parentDestroyed = 0; } static int parentDestroyed; public slots: void parentDestroyedSlot() { @@ -10276,7 +10307,7 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; DestroyTester *t = new DestroyTester(w); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10285,7 +10316,7 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; DestroyTester *t = new DestroyTester(w); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); w->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; @@ -10295,7 +10326,7 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; DestroyTester *t = new DestroyTester(o); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10303,8 +10334,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(o); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); o->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; @@ -10313,8 +10344,8 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10323,8 +10354,8 @@ void tst_QWidget::destroyedSignal() { QWidget *w = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(w, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(w, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); w->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete w; @@ -10334,8 +10365,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; QCOMPARE(DestroyTester::parentDestroyed, 1); @@ -10344,8 +10375,8 @@ void tst_QWidget::destroyedSignal() { QObject *o = new QWidget; - DestroyTester *t = new DestroyTester(0); - connect(o, SIGNAL(destroyed()), t, SLOT(parentDestroyedSlot())); + auto t = new DestroyTester; + connect(o, &QObject::destroyed, t, &DestroyTester::parentDestroyedSlot); o->blockSignals(true); QCOMPARE(DestroyTester::parentDestroyed, 0); delete o; @@ -10361,10 +10392,11 @@ void tst_QWidget::underMouse() // Move the mouse cursor to a safe location QCursor::setPos(m_safeCursorPos); - ColorWidget topLevelWidget(0, Qt::FramelessWindowHint, Qt::blue); + ColorWidget topLevelWidget(nullptr, Qt::FramelessWindowHint, Qt::blue); + topLevelWidget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); ColorWidget childWidget1(&topLevelWidget, Qt::Widget, Qt::yellow); ColorWidget childWidget2(&topLevelWidget, Qt::Widget, Qt::black); - ColorWidget popupWidget(0, Qt::Popup, Qt::green); + ColorWidget popupWidget(nullptr, Qt::Popup, Qt::green); topLevelWidget.setObjectName("topLevelWidget"); childWidget1.setObjectName("childWidget1"); @@ -10553,7 +10585,7 @@ class EnterTestModalDialog : public QDialog { Q_OBJECT public: - EnterTestModalDialog() : QDialog(), button(0) + EnterTestModalDialog() { setGeometry(100, 300, 150, 100); button = new QPushButton(this); @@ -10567,7 +10599,6 @@ class EnterTestMainDialog : public QDialog { Q_OBJECT public: - EnterTestMainDialog() : QDialog(), modal(0), enters(0) {} public slots: void buttonPressed() @@ -10595,7 +10626,7 @@ public slots: modal->close(); } - bool eventFilter(QObject *o, QEvent *e) + bool eventFilter(QObject *o, QEvent *e) override { switch (e->type()) { case QEvent::Enter: @@ -10609,8 +10640,8 @@ public slots: } public: - EnterTestModalDialog *modal; - int enters; + EnterTestModalDialog *modal = nullptr; + int enters = 0; }; // A modal dialog launched by clicking a button should not trigger excess enter events @@ -10624,9 +10655,10 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() QCursor::setPos(m_safeCursorPos); EnterTestMainDialog dialog; + dialog.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QPushButton button(&dialog); - connect(&button, SIGNAL(clicked()), &dialog, SLOT(buttonPressed())); + connect(&button, &QAbstractButton::clicked, &dialog, &EnterTestMainDialog::buttonPressed); dialog.setGeometry(100, 100, 150, 100); button.setGeometry(10, 10, 100, 50); @@ -10638,7 +10670,7 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() QWindowSystemInterface::handleEnterEvent(window, overButton, window->mapToGlobal(overButton)); QTest::mouseMove(window, overButton); - QTest::mouseClick(window, Qt::LeftButton, 0, overButton, 0); + QTest::mouseClick(window, Qt::LeftButton, Qt::KeyboardModifiers(), overButton, 0); // Modal dialog opened in EnterTestMainDialog::buttonPressed()... @@ -10650,20 +10682,22 @@ void tst_QWidget::taskQTBUG_27643_enterEvents() class KeyboardWidget : public QWidget { public: - KeyboardWidget(QWidget* parent = 0) : QWidget(parent), m_eventCounter(0) {} - virtual void mousePressEvent(QMouseEvent* ev) override { + using QWidget::QWidget; + void mousePressEvent(QMouseEvent* ev) override + { m_modifiers = ev->modifiers(); m_appModifiers = QApplication::keyboardModifiers(); ++m_eventCounter; } Qt::KeyboardModifiers m_modifiers; Qt::KeyboardModifiers m_appModifiers; - int m_eventCounter; + int m_eventCounter = 0; }; void tst_QWidget::keyboardModifiers() { KeyboardWidget w; + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); w.resize(300, 300); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); @@ -10676,17 +10710,17 @@ void tst_QWidget::keyboardModifiers() class DClickWidget : public QWidget { public: - DClickWidget() : triggered(false) {} - void mouseDoubleClickEvent(QMouseEvent *) + void mouseDoubleClickEvent(QMouseEvent *) override { triggered = true; } - bool triggered; + bool triggered = false; }; void tst_QWidget::mouseDoubleClickBubbling_QTBUG29680() { DClickWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child(&parent); parent.resize(200, 200); child.resize(200, 200); @@ -10701,6 +10735,7 @@ void tst_QWidget::mouseDoubleClickBubbling_QTBUG29680() void tst_QWidget::largerThanScreen_QTBUG30142() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200, 4000); widget.show(); QVERIFY(QTest::qWaitForWindowExposed(&widget)); @@ -10718,6 +10753,7 @@ void tst_QWidget::largerThanScreen_QTBUG30142() void tst_QWidget::resizeStaticContentsChildWidget_QTBUG35282() { QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.resize(200,200); UpdateWidget childWidget(&widget); @@ -10743,11 +10779,12 @@ void tst_QWidget::qmlSetParentHelper() { #ifdef QT_BUILD_INTERNAL QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QWidget child; QVERIFY(QAbstractDeclarativeData::setWidgetParent); QAbstractDeclarativeData::setWidgetParent(&child, &parent); QCOMPARE(child.parentWidget(), &parent); - QAbstractDeclarativeData::setWidgetParent(&child, 0); + QAbstractDeclarativeData::setWidgetParent(&child, nullptr); QVERIFY(!child.parentWidget()); #else QSKIP("Needs QT_BUILD_INTERNAL"); @@ -10861,6 +10898,7 @@ protected: void tst_QWidget::tabletTracking() { QWidget parent; + parent.setWindowTitle(QLatin1String(QTest::currentTestFunction())); parent.resize(200,200); // QWidgetWindow::handleTabletEvent doesn't deliver tablet events to the window's widget, only to a child. // So it doesn't do any good to show a TabletWidget directly: it needs a parent. @@ -10879,7 +10917,7 @@ void tst_QWidget::tabletTracking() QPointF deviceGlobal = QHighDpi::toNativePixels(global, window->screen()); qint64 uid = 1234UL; - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 1); @@ -10888,7 +10926,7 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 2); @@ -10897,7 +10935,7 @@ void tst_QWidget::tabletTracking() QCoreApplication::processEvents(); QTRY_COMPARE(widget.trackingChangeEventCount, 2); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.pressEventCount, 1); @@ -10905,12 +10943,12 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::LeftButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.releaseEventCount, 1); @@ -10918,7 +10956,7 @@ void tst_QWidget::tabletTracking() local += QPoint(10, 10); deviceLocal += QPoint(10, 10); deviceGlobal += QPoint(10, 10); - QWindowSystemInterface::handleTabletEvent(window, QDateTime::currentMSecsSinceEpoch(), deviceLocal, deviceGlobal, + QWindowSystemInterface::handleTabletEvent(window, ulong(QDateTime::currentMSecsSinceEpoch()), deviceLocal, deviceGlobal, QTabletEvent::Stylus, QTabletEvent::Pen, Qt::NoButton, 0, 0, 0, 0, 0, 0, uid, Qt::NoModifier); QCoreApplication::processEvents(); QTRY_COMPARE(widget.moveEventCount, 3); -- cgit v1.2.3