diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-17 08:32:43 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2019-09-17 08:32:43 +0200 |
commit | d49d076431d7579ecb33147187fe07eb148112ba (patch) | |
tree | 668370fb9a2eec50000e371125136921ef4518ab /tests | |
parent | b01e69684b9b36492cc43472edeb72058be9f706 (diff) | |
parent | 35cdcddd605d8823b7b57129e8d7279133a3ca89 (diff) |
Merge remote-tracking branch 'origin/5.15' into dev
Change-Id: Ic1fd51143f903b7e9086fc19ca960dfd9654ee00
Diffstat (limited to 'tests')
27 files changed, 2193 insertions, 1978 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 921847a087..16fcafa248 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -2098,8 +2098,7 @@ void tst_QFileInfo::owner() DWORD bufSize = 1024; if (GetUserNameW(usernameBuf, &bufSize)) { userName = QString::fromWCharArray(usernameBuf); - if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista - && IsUserAdmin()) { + if (IsUserAdmin()) { // Special case : If the user is a member of Administrators group, all files // created by the current user are owned by the Administrators group. LPLOCALGROUP_USERS_INFO_0 pBuf = NULL; diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 3123c42326..ef4325d2ea 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3389,8 +3389,15 @@ void tst_QUrl::acceptEmptyAuthoritySegments() void tst_QUrl::effectiveTLDs_data() { + // See also: tst_QNetworkCookieJar::setCookiesFromUrl(). + // in tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp QTest::addColumn<QUrl>("domain"); QTest::addColumn<QString>("TLD"); + // TODO: autogenerate test-cases from: + // https://raw.githubusercontent.com/publicsuffix/list/master/tests/test_psl.txt + // checkPublicSuffix(domain, tail) appears in the list if + // either tail is null and domain is public or + // tail is the "registrable" part of domain; i.e. its minimal non-public tail. QTest::newRow("yes0") << QUrl::fromEncoded("http://test.co.uk") << ".co.uk"; QTest::newRow("yes1") << QUrl::fromEncoded("http://test.com") << ".com"; diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp index ac1b903aa1..531ac2995f 100644 --- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp @@ -3352,6 +3352,14 @@ void tst_QDateTime::timeZones() const QCOMPARE(dt3.timeSpec(), dt1.timeSpec()); QCOMPARE(dt3.timeZone(), dt1.timeZone()); + // The start of year 1 should be *describable* in any zone (QTBUG-78051) + dt3 = QDateTime(QDate(1, 1, 1), QTime(0, 0, 0), ausTz); + QVERIFY(dt3.isValid()); + // Likewise the end of year -1 (a.k.a. 1 BCE). + dt3 = dt3.addMSecs(-1); + QVERIFY(dt3.isValid()); + QCOMPARE(dt3, QDateTime(QDate(-1, 12, 31), QTime(23, 59, 59, 999), ausTz)); + // Check datastream serialises the time zone QByteArray tmp; { diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp index 9904719f7c..5b1bde8ea3 100644 --- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp +++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -49,6 +49,8 @@ private slots: void dataStreamTest(); void isTimeZoneIdAvailable(); void availableTimeZoneIds(); + void utcOffsetId_data(); + void utcOffsetId(); void specificTransition_data(); void specificTransition(); void transitionEachZone_data(); @@ -375,33 +377,121 @@ void tst_QTimeZone::dataStreamTest() void tst_QTimeZone::isTimeZoneIdAvailable() { QList<QByteArray> available = QTimeZone::availableTimeZoneIds(); - foreach (const QByteArray &id, available) + foreach (const QByteArray &id, available) { QVERIFY(QTimeZone::isTimeZoneIdAvailable(id)); + QVERIFY(QTimeZone(id).isValid()); + } +} -#ifdef QT_BUILD_INTERNAL - // a-z, A-Z, 0-9, '.', '-', '_' are valid chars - // Can't start with '-' - // Parts separated by '/', each part min 1 and max of 14 chars - QCOMPARE(QTimeZonePrivate::isValidId("az"), true); - QCOMPARE(QTimeZonePrivate::isValidId("AZ"), true); - QCOMPARE(QTimeZonePrivate::isValidId("09"), true); - QCOMPARE(QTimeZonePrivate::isValidId("a/z"), true); - QCOMPARE(QTimeZonePrivate::isValidId("a.z"), true); - QCOMPARE(QTimeZonePrivate::isValidId("a-z"), true); - QCOMPARE(QTimeZonePrivate::isValidId("a_z"), true); - QCOMPARE(QTimeZonePrivate::isValidId(".z"), true); - QCOMPARE(QTimeZonePrivate::isValidId("_z"), true); - QCOMPARE(QTimeZonePrivate::isValidId("12345678901234"), true); - QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/12345678901234"), true); - QCOMPARE(QTimeZonePrivate::isValidId("a z"), false); - QCOMPARE(QTimeZonePrivate::isValidId("a\\z"), false); - QCOMPARE(QTimeZonePrivate::isValidId("a,z"), false); - QCOMPARE(QTimeZonePrivate::isValidId("/z"), false); - QCOMPARE(QTimeZonePrivate::isValidId("-z"), false); - QCOMPARE(QTimeZonePrivate::isValidId("123456789012345"), false); - QCOMPARE(QTimeZonePrivate::isValidId("123456789012345/12345678901234"), false); - QCOMPARE(QTimeZonePrivate::isValidId("12345678901234/123456789012345"), false); -#endif // QT_BUILD_INTERNAL +void tst_QTimeZone::utcOffsetId_data() +{ + QTest::addColumn<QByteArray>("id"); + QTest::addColumn<bool>("valid"); + QTest::addColumn<int>("offset"); // ignored unless valid + + // Some of these are actual CLDR zone IDs, some are known Windows IDs; the + // rest rely on parsing the offset. Since CLDR and Windows may add to their + // known IDs, which fall in which category may vary. Only the CLDR and + // Windows ones are known to isTimeZoneAvailable() or listed in + // availableTimeZoneIds(). +#define ROW(name, valid, offset) \ + QTest::newRow(name) << QByteArray(name) << valid << offset + + // See qtbase/util/locale_database/cldr2qtimezone.py for source + // CLDR v35.1 IDs: + ROW("UTC", true, 0); + ROW("UTC-14:00", true, -50400); + ROW("UTC-13:00", true, -46800); + ROW("UTC-12:00", true, -43200); + ROW("UTC-11:00", true, -39600); + ROW("UTC-10:00", true, -36000); + ROW("UTC-09:00", true, -32400); + ROW("UTC-08:00", true, -28800); + ROW("UTC-07:00", true, -25200); + ROW("UTC-06:00", true, -21600); + ROW("UTC-05:00", true, -18000); + ROW("UTC-04:30", true, -16200); + ROW("UTC-04:00", true, -14400); + ROW("UTC-03:30", true, -12600); + ROW("UTC-03:00", true, -10800); + ROW("UTC-02:00", true, -7200); + ROW("UTC-01:00", true, -3600); + ROW("UTC-00:00", true, 0); + ROW("UTC+00:00", true, 0); + ROW("UTC+01:00", true, 3600); + ROW("UTC+02:00", true, 7200); + ROW("UTC+03:00", true, 10800); + ROW("UTC+03:30", true, 12600); + ROW("UTC+04:00", true, 14400); + ROW("UTC+04:30", true, 16200); + ROW("UTC+05:00", true, 18000); + ROW("UTC+05:30", true, 19800); + ROW("UTC+05:45", true, 20700); + ROW("UTC+06:00", true, 21600); + ROW("UTC+06:30", true, 23400); + ROW("UTC+07:00", true, 25200); + ROW("UTC+08:00", true, 28800); + ROW("UTC+08:30", true, 30600); + ROW("UTC+09:00", true, 32400); + ROW("UTC+09:30", true, 34200); + ROW("UTC+10:00", true, 36000); + ROW("UTC+11:00", true, 39600); + ROW("UTC+12:00", true, 43200); + ROW("UTC+13:00", true, 46800); + ROW("UTC+14:00", true, 50400); + // Windows IDs known to CLDR v35.1: + ROW("UTC-11", true, -39600); + ROW("UTC-09", true, -32400); + ROW("UTC-08", true, -28800); + ROW("UTC-02", true, -7200); + ROW("UTC+12", true, 43200); + ROW("UTC+13", true, 46800); + // Encountered in bug reports: + ROW("UTC+10", true, 36000); // QTBUG-77738 + + // Bounds: + ROW("UTC+23", true, 82800); + ROW("UTC-23", true, -82800); + ROW("UTC+23:59", true, 86340); + ROW("UTC-23:59", true, -86340); + ROW("UTC+23:59:59", true, 86399); + ROW("UTC-23:59:59", true, -86399); + + // Out of range + ROW("UTC+24:0:0", false, 0); + ROW("UTC-24:0:0", false, 0); + ROW("UTC+0:60:0", false, 0); + ROW("UTC-0:60:0", false, 0); + ROW("UTC+0:0:60", false, 0); + ROW("UTC-0:0:60", false, 0); + + // Malformed + ROW("UTC+", false, 0); + ROW("UTC-", false, 0); + ROW("UTC10", false, 0); + ROW("UTC:10", false, 0); + ROW("UTC+cabbage", false, 0); + ROW("UTC+10:rice", false, 0); + ROW("UTC+9:3:oat", false, 0); + ROW("UTC+9+3", false, 0); + ROW("UTC+9-3", false, 0); + ROW("UTC+9:3-4", false, 0); + ROW("UTC+9:3:4:more", false, 0); + ROW("UTC+9:3:4:5", false, 0); +} + +void tst_QTimeZone::utcOffsetId() +{ + QFETCH(QByteArray, id); + QFETCH(bool, valid); + QTimeZone zone(id); + QCOMPARE(zone.isValid(), valid); + if (valid) { + QDateTime epoch(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::UTC); + QFETCH(int, offset); + QCOMPARE(zone.offsetFromUtc(epoch), offset); + QVERIFY(!zone.hasDaylightTime()); + } } void tst_QTimeZone::specificTransition_data() @@ -733,10 +823,16 @@ void tst_QTimeZone::isValidId_data() QTest::newRow(name " middle") << QByteArray("xyz/" section "/xyz") << valid; \ QTest::newRow(name " back") << QByteArray("xyz/xyz/" section) << valid + // a-z, A-Z, 0-9, '.', '-', '_' are valid chars + // Can't start with '-' + // Parts separated by '/', each part min 1 and max of 14 chars TESTSET("empty", "", false); TESTSET("minimal", "m", true); TESTSET("maximal", "12345678901234", true); + TESTSET("maximal twice", "12345678901234/12345678901234", true); TESTSET("too long", "123456789012345", false); + TESTSET("too-long/maximal", "123456789012345/12345678901234", false); + TESTSET("maximal/too-long", "12345678901234/123456789012345", false); TESTSET("bad hyphen", "-hyphen", false); TESTSET("good hyphen", "hy-phen", true); @@ -752,6 +848,22 @@ void tst_QTimeZone::isValidId_data() TESTSET("valid char 0", "0", true); TESTSET("valid char 9", "9", true); + TESTSET("valid pair az", "az", true); + TESTSET("valid pair AZ", "AZ", true); + TESTSET("valid pair 09", "09", true); + TESTSET("valid pair .z", ".z", true); + TESTSET("valid pair _z", "_z", true); + TESTSET("invalid pair -z", "-z", false); + + TESTSET("valid triple a/z", "a/z", true); + TESTSET("valid triple a.z", "a.z", true); + TESTSET("valid triple a-z", "a-z", true); + TESTSET("valid triple a_z", "a_z", true); + TESTSET("invalid triple a z", "a z", false); + TESTSET("invalid triple a\\z", "a\\z", false); + TESTSET("invalid triple a,z", "a,z", false); + + TESTSET("invalid space", " ", false); TESTSET("invalid char ^", "^", false); TESTSET("invalid char \"", "\"", false); TESTSET("invalid char $", "$", false); @@ -760,6 +872,7 @@ void tst_QTimeZone::isValidId_data() TESTSET("invalid char (", "(", false); TESTSET("invalid char )", ")", false); TESTSET("invalid char =", "=", false); + TESTSET("invalid char -", "-", false); TESTSET("invalid char ?", "?", false); TESTSET("invalid char ß", "ß", false); TESTSET("invalid char \\x01", "\x01", false); @@ -824,10 +937,6 @@ void tst_QTimeZone::utcTest() QCOMPARE(tz.standardTimeOffset(now), 36000); QCOMPARE(tz.daylightTimeOffset(now), 0); - // Test invalid UTC ID, must be in available list - tz = QTimeZone("UTC+00:01"); - QCOMPARE(tz.isValid(), false); - // Test create custom zone tz = QTimeZone("QST", 123456, "Qt Standard Time", "QST", QLocale::Norway, "Qt Testing"); QCOMPARE(tz.isValid(), true); diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 4f26950192..1290347eab 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -1025,6 +1025,23 @@ public: Qt::MouseButtons buttonStateInGeneratedMove; }; +static void simulateMouseClick(QWindow *target, const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + +static void simulateMouseClick(QWindow *target, ulong &timeStamp, + const QPointF &local, const QPointF &global) +{ + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + {}, Qt::LeftButton, QEvent::MouseButtonPress); + QWindowSystemInterface::handleMouseEvent(target, timeStamp++, local, global, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseButtonRelease); +} + void tst_QWindow::testInputEvents() { InputTestWindow window; @@ -1066,15 +1083,13 @@ void tst_QWindow::testInputEvents() window.mousePressButton = window.mouseReleaseButton = 0; const QPointF nonWindowGlobal(window.geometry().topRight() + QPoint(200, 50)); // not inside the window const QPointF deviceNonWindowGlobal = QHighDpi::toNativePixels(nonWindowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceNonWindowGlobal, deviceNonWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, 0); QCOMPARE(window.mouseReleaseButton, 0); const QPointF windowGlobal = window.mapToGlobal(local.toPoint()); const QPointF deviceWindowGlobal = QHighDpi::toNativePixels(windowGlobal, window.screen()); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(nullptr, deviceWindowGlobal, deviceWindowGlobal, Qt::NoButton); + simulateMouseClick(nullptr, deviceWindowGlobal, deviceWindowGlobal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressButton, int(Qt::LeftButton)); QCOMPARE(window.mouseReleaseButton, int(Qt::LeftButton)); @@ -1198,8 +1213,7 @@ void tst_QWindow::mouseToTouchTranslation() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1211,8 +1225,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = false; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1223,8 +1236,7 @@ void tst_QWindow::mouseToTouchTranslation() window.ignoreMouse = true; - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); // touch event synthesis disabled @@ -1249,8 +1261,7 @@ void tst_QWindow::mouseToTouchLoop() window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, QPoint(10, 10), window.mapToGlobal(QPoint(10, 10)), Qt::NoButton); + QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(10, 10)); QCoreApplication::processEvents(); QCoreApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, false); @@ -1545,8 +1556,8 @@ void tst_QWindow::mouseEventSequence() ulong timestamp = 0; QPointF local(12, 34); const QPointF deviceLocal = QHighDpi::toNativePixels(local, &window); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, deviceLocal, deviceLocal, Qt::NoButton); + + simulateMouseClick(&window, timestamp, deviceLocal, deviceLocal); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 1); QCOMPARE(window.mouseReleasedCount, 1); @@ -1558,10 +1569,8 @@ void tst_QWindow::mouseEventSequence() // A double click must result in press, release, press, doubleclick, release. // Check that no unexpected event suppression occurs and that the order is correct. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 2); QCOMPARE(window.mouseReleasedCount, 2); @@ -1572,12 +1581,9 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Triple click = double + single click - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 3); QCOMPARE(window.mouseReleasedCount, 3); @@ -1588,14 +1594,10 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Two double clicks. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); + simulateMouseClick(&window, timestamp, local, local); QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); QCOMPARE(window.mouseReleasedCount, 4); @@ -1606,17 +1608,13 @@ void tst_QWindow::mouseEventSequence() window.resetCounters(); // Four clicks, none of which qualifies as a double click. - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, timestamp++, local, local, Qt::NoButton); + simulateMouseClick(&window, timestamp, local, local); timestamp += doubleClickInterval; QCoreApplication::processEvents(); QCOMPARE(window.mousePressedCount, 4); @@ -1668,10 +1666,13 @@ void tst_QWindow::inputReentrancy() // Queue three events. QPointF local(12, 34); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, {}, + Qt::LeftButton, QEvent::MouseButtonPress); local += QPointF(2, 2); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::NoButton); + QWindowSystemInterface::handleMouseEvent(&window, local, local, + Qt::LeftButton, Qt::LeftButton, QEvent::MouseMove); + QWindowSystemInterface::handleMouseEvent(&window, local, local, Qt::LeftButton, + Qt::LeftButton, QEvent::MouseButtonRelease); // Process them. However, the event handler for the press will also call // processEvents() so the move and release will be delivered before returning // from mousePressEvent(). The point is that no events should get lost. @@ -1741,12 +1742,14 @@ void tst_QWindow::tabletEvents() const QPoint global = window.mapToGlobal(local); const QPoint deviceLocal = QHighDpi::toNativeLocalPosition(local, &window); const QPoint deviceGlobal = QHighDpi::toNativePixels(global, window.screen()); - QWindowSystemInterface::handleTabletEvent(&window, true, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, + 1, 2, Qt::LeftButton, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_VERIFY(window.eventType == QEvent::TabletPress); QTRY_COMPARE(window.eventGlobal.toPoint(), global); QTRY_COMPARE(window.eventLocal.toPoint(), local); - QWindowSystemInterface::handleTabletEvent(&window, false, deviceLocal, deviceGlobal, 1, 2, 0.5, 1, 2, 0.1, 0, 0, 0); + QWindowSystemInterface::handleTabletEvent(&window, deviceLocal, deviceGlobal, 1, 2, + {}, 0.5, 1, 2, 0.1, 0, 0, 0); QCoreApplication::processEvents(); QTRY_COMPARE(window.eventType, QEvent::TabletRelease); @@ -1782,11 +1785,9 @@ void tst_QWindow::windowModality_QTBUG27039() modalB.setModality(Qt::ApplicationModal); modalB.show(); - QPointF local(5, 5); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalB, local, local, Qt::NoButton); + QPoint local(5, 5); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); + QTest::mouseClick(&modalB, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal A should be blocked since it was shown first, but modal B should not be blocked @@ -1794,8 +1795,7 @@ void tst_QWindow::windowModality_QTBUG27039() QCOMPARE(modalA.mousePressedCount, 0); modalB.hide(); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::LeftButton); - QWindowSystemInterface::handleMouseEvent(&modalA, local, local, Qt::NoButton); + QTest::mouseClick(&modalA, Qt::LeftButton, {}, local); QCoreApplication::processEvents(); // modal B has been hidden, modal A should be unblocked again diff --git a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp index d51cfdee2f..531e14d25b 100644 --- a/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp +++ b/tests/auto/gui/painting/qcolorspace/tst_qcolorspace.cpp @@ -123,9 +123,6 @@ void tst_QColorSpace::namedColorSpaces_data() QTest::newRow("ProPhoto RGB") << QColorSpace::ProPhotoRgb << QColorSpace::Primaries::ProPhotoRgb << QColorSpace::TransferFunction::ProPhotoRgb; - QTest::newRow("BT.2020") << QColorSpace::Bt2020 - << QColorSpace::Primaries::Bt2020 - << QColorSpace::TransferFunction::Bt2020; } void tst_QColorSpace::namedColorSpaces() @@ -220,7 +217,6 @@ void tst_QColorSpace::imageConversion_data() QTest::newRow("Display-P3 -> sRGB") << QColorSpace::DisplayP3 << QColorSpace::SRgb << 0; QTest::newRow("Adobe RGB -> sRGB") << QColorSpace::AdobeRgb << QColorSpace::SRgb << 2; QTest::newRow("Display-P3 -> Adobe RGB") << QColorSpace::DisplayP3 << QColorSpace::AdobeRgb << 2; - QTest::newRow("Display-P3 -> BT.2020") << QColorSpace::DisplayP3 << QColorSpace::Bt2020 << 4; QTest::newRow("sRGB -> sRGB Linear") << QColorSpace::SRgb << QColorSpace::SRgbLinear << 0; } @@ -351,14 +347,12 @@ void tst_QColorSpace::primariesXyz() QColorSpace adobeRgb = QColorSpace::AdobeRgb; QColorSpace displayP3 = QColorSpace::DisplayP3; QColorSpace proPhotoRgb = QColorSpace::ProPhotoRgb; - QColorSpace bt2020 = QColorSpace::Bt2020; // Check if our calculated matrices, match the precalculated ones. QCOMPARE(QColorSpacePrivate::get(sRgb)->toXyz, QColorMatrix::toXyzFromSRgb()); QCOMPARE(QColorSpacePrivate::get(adobeRgb)->toXyz, QColorMatrix::toXyzFromAdobeRgb()); QCOMPARE(QColorSpacePrivate::get(displayP3)->toXyz, QColorMatrix::toXyzFromDciP3D65()); QCOMPARE(QColorSpacePrivate::get(proPhotoRgb)->toXyz, QColorMatrix::toXyzFromProPhotoRgb()); - QCOMPARE(QColorSpacePrivate::get(bt2020)->toXyz, QColorMatrix::toXyzFromBt2020()); } #ifdef QT_BUILD_INTERNAL @@ -370,7 +364,6 @@ void tst_QColorSpace::primaries2_data() QTest::newRow("DCI-P3 (D65)") << QColorSpace::Primaries::DciP3D65; QTest::newRow("Adobe RGB (1998)") << QColorSpace::Primaries::AdobeRgb; QTest::newRow("ProPhoto RGB") << QColorSpace::Primaries::ProPhotoRgb; - QTest::newRow("BT.2020") << QColorSpace::Primaries::Bt2020; } void tst_QColorSpace::primaries2() diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 96f3b1c1d7..1ee9105cd2 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -539,10 +539,10 @@ void tst_QFont::defaultFamily_data() QTest::addColumn<QStringList>("acceptableFamilies"); QTest::newRow("serif") << QFont::Serif << (QStringList() << "Times New Roman" << "Times" << "Droid Serif" << getPlatformGenericFont("serif").split(",")); - QTest::newRow("monospace") << QFont::Monospace << (QStringList() << "Courier New" << "Monaco" << "Droid Sans Mono" << getPlatformGenericFont("monospace").split(",")); + QTest::newRow("monospace") << QFont::Monospace << (QStringList() << "Courier New" << "Monaco" << "Menlo" << "Droid Sans Mono" << getPlatformGenericFont("monospace").split(",")); QTest::newRow("cursive") << QFont::Cursive << (QStringList() << "Comic Sans MS" << "Apple Chancery" << "Roboto" << "Droid Sans" << getPlatformGenericFont("cursive").split(",")); QTest::newRow("fantasy") << QFont::Fantasy << (QStringList() << "Impact" << "Zapfino" << "Roboto" << "Droid Sans" << getPlatformGenericFont("fantasy").split(",")); - QTest::newRow("sans-serif") << QFont::SansSerif << (QStringList() << "Arial" << "Lucida Grande" << "Roboto" << "Droid Sans" << "Segoe UI" << getPlatformGenericFont("sans-serif").split(",")); + QTest::newRow("sans-serif") << QFont::SansSerif << (QStringList() << "Arial" << "Lucida Grande" << "Helvetica" << "Roboto" << "Droid Sans" << "Segoe UI" << getPlatformGenericFont("sans-serif").split(",")); } void tst_QFont::defaultFamily() diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index aee2f970fe..a474acd790 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -139,6 +139,7 @@ private slots: void superscriptCrash_qtbug53911(); void showLineAndParagraphSeparatorsCrash(); void koreanWordWrap(); + void tooManyDirectionalCharctersCrash_qtbug77819(); private: QFont testFont; @@ -2330,5 +2331,21 @@ void tst_QTextLayout::koreanWordWrap() QCOMPARE(layout.lineAt(1).textLength(), 4); } +void tst_QTextLayout::tooManyDirectionalCharctersCrash_qtbug77819() +{ + QString data; + data += QString::fromUtf8("\xe2\x81\xa8"); // U+2068 FSI character + data += QString::fromUtf8("\xe2\x81\xa7"); // U+2067 RLI character + + // duplicating the text + for (int i = 0; i < 10; i++) + data += data; + + // Nothing to test. It must not crash in beginLayout(). + QTextLayout tl(data); + tl.beginLayout(); + tl.endLayout(); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" diff --git a/tests/auto/network/access/http2/tst_http2.cpp b/tests/auto/network/access/http2/tst_http2.cpp index e24a06bc34..c264956d7b 100644 --- a/tests/auto/network/access/http2/tst_http2.cpp +++ b/tests/auto/network/access/http2/tst_http2.cpp @@ -477,6 +477,9 @@ void tst_Http2::goaway_data() // - server waits for some time (enough for ur to init several streams on a // client side); then suddenly it replies with GOAWAY, never processing any // request. + if (clearTextHTTP2) + QSKIP("This test requires TLS with ALPN to work"); + QTest::addColumn<int>("responseTimeoutMS"); QTest::newRow("ImmediateGOAWAY") << 0; QTest::newRow("DelayedGOAWAY") << 1000; diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 1ef2c118b9..0924b1e223 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -166,6 +166,10 @@ void tst_QNetworkCookieJar::setCookiesFromUrl_data() // 2. anything .ck is an effective TLD ('*.ck'), but 'www.ck' is an exception result.clear(); preset.clear(); + cookie.setDomain(".ck"); + QTest::newRow("effective-tld.ck-denied") << preset << cookie << "http://foo.ck" << result << false; + result.clear(); + preset.clear(); cookie.setDomain(".foo.ck"); result += cookie; QTest::newRow("effective-tld2-accepted2") << preset << cookie << "http://foo.ck" << result << true; diff --git a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp index fc5a7d1fab..849d8b0ed1 100644 --- a/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp +++ b/tests/auto/network/socket/qtcpserver/tst_qtcpserver.cpp @@ -881,11 +881,6 @@ void tst_QTcpServer::serverAddress_data() { QTest::addColumn<QHostAddress>("listenAddress"); QTest::addColumn<QHostAddress>("serverAddress"); -#ifdef Q_OS_WIN - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista) - QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4); //windows XP doesn't support dual stack sockets - else -#endif if (QtNetworkSettings::hasIPv6()) QTest::newRow("Any") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::Any); else diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp index 032580e0f6..fbf906b55d 100644 --- a/tests/auto/other/lancelot/paintcommands.cpp +++ b/tests/auto/other/lancelot/paintcommands.cpp @@ -1010,7 +1010,10 @@ void PaintCommands::command_drawPixmap(QRegularExpressionMatch re) qPrintable(re.captured(1)), pm.width(), pm.height(), pm.depth(), tx, ty, tw, th, sx, sy, sw, sh); - m_painter->drawPixmap(QRectF(tx, ty, tw, th), pm, QRectF(sx, sy, sw, sh)); + if (!re.capturedLength(4)) // at most two coordinates specified + m_painter->drawPixmap(QPointF(tx, ty), pm); + else + m_painter->drawPixmap(QRectF(tx, ty, tw, th), pm, QRectF(sx, sy, sw, sh)); } /***************************************************************************************************/ @@ -1057,7 +1060,10 @@ void PaintCommands::command_drawImage(QRegularExpressionMatch re) printf(" -(lance) drawImage('%s' dim=(%d, %d), (%f, %f, %f, %f), (%f, %f, %f, %f)\n", qPrintable(re.captured(1)), im.width(), im.height(), tx, ty, tw, th, sx, sy, sw, sh); - m_painter->drawImage(QRectF(tx, ty, tw, th), im, QRectF(sx, sy, sw, sh), Qt::OrderedDither | Qt::OrderedAlphaDither); + if (!re.capturedLength(4)) // at most two coordinates specified + m_painter->drawImage(QPointF(tx, ty), im); + else + m_painter->drawImage(QRectF(tx, ty, tw, th), im, QRectF(sx, sy, sw, sh)); } /***************************************************************************************************/ diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 1326b96177..331ae48135 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -685,9 +685,6 @@ static inline QByteArray msgProcessError(const QString &binary, const QStringLis void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& loggers, QStringList const& arguments, bool crashes) { - if (EmulationDetector::isRunningArmOnX86() && (subdir == "crashes")) - QSKIP("Skipping \"crashes\" due to QTBUG-71915"); - #if defined(__GNUC__) && defined(__i386) && defined(Q_OS_LINUX) if (arguments.contains("-callgrind")) { QProcess checkProcess; diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 0b08586f7d..5d380c899b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -56,9 +56,16 @@ #include <QLineEdit> #include <QGraphicsLinearLayout> #include <QTransform> +#include <QSharedPointer> #include <float.h> #include <QStyleHints> +using AbstractGraphicsShapeItemPtr = QSharedPointer<QAbstractGraphicsShapeItem>; +using GraphicsItems = QVector<QGraphicsItem *>; +using GraphicsItemsList = QList<QGraphicsItem *>; + +Q_DECLARE_METATYPE(AbstractGraphicsShapeItemPtr) +Q_DECLARE_METATYPE(QGraphicsItem::GraphicsItemFlags) Q_DECLARE_METATYPE(QPainterPath) Q_DECLARE_METATYPE(QSizeF) Q_DECLARE_METATYPE(QTransform) @@ -88,17 +95,17 @@ static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::Mous event.setScenePos(point); event.setButton(button); event.setButtons(button); - QApplication::sendEvent(scene, &event); + QCoreApplication::sendEvent(scene, &event); } static void sendMouseMove(QGraphicsScene *scene, const QPointF &point, - Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = 0) + Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons /* buttons */ = {}) { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setScenePos(point); event.setButton(button); event.setButtons(button); - QApplication::sendEvent(scene, &event); + QCoreApplication::sendEvent(scene, &event); } static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) @@ -106,7 +113,7 @@ static void sendMouseRelease(QGraphicsScene *scene, const QPointF &point, Qt::Mo QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(point); event.setButton(button); - QApplication::sendEvent(scene, &event); + QCoreApplication::sendEvent(scene, &event); } static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) @@ -118,13 +125,13 @@ static void sendMouseClick(QGraphicsScene *scene, const QPointF &point, Qt::Mous static void sendKeyPress(QGraphicsScene *scene, Qt::Key key) { QKeyEvent keyEvent(QEvent::KeyPress, key, Qt::NoModifier); - QApplication::sendEvent(scene, &keyEvent); + QCoreApplication::sendEvent(scene, &keyEvent); } static void sendKeyRelease(QGraphicsScene *scene, Qt::Key key) { QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier); - QApplication::sendEvent(scene, &keyEvent); + QCoreApplication::sendEvent(scene, &keyEvent); } static void sendKeyClick(QGraphicsScene *scene, Qt::Key key) @@ -138,13 +145,13 @@ class EventSpy : public QGraphicsWidget Q_OBJECT public: EventSpy(QObject *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { watched->installEventFilter(this); } EventSpy(QGraphicsScene *scene, QGraphicsItem *watched, QEvent::Type type) - : _count(0), spied(type) + : spied(type) { scene->addItem(this); watched->installSceneEventFilter(this); @@ -153,7 +160,7 @@ public: int count() const { return _count; } protected: - bool eventFilter(QObject *watched, QEvent *event) + bool eventFilter(QObject *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -161,7 +168,7 @@ protected: return false; } - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { Q_UNUSED(watched); if (event->type() == spied) @@ -169,8 +176,8 @@ protected: return false; } - int _count; - QEvent::Type spied; + int _count = 0; + const QEvent::Type spied; }; class EventSpy2 : public QGraphicsWidget @@ -191,14 +198,14 @@ public: QMap<QEvent::Type, int> counts; protected: - bool eventFilter(QObject *watched, QEvent *event) + bool eventFilter(QObject *watched, QEvent *event) override { Q_UNUSED(watched); ++counts[event->type()]; return false; } - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { Q_UNUSED(watched); ++counts[event->type()]; @@ -209,8 +216,7 @@ protected: class EventTester : public QGraphicsItem { public: - EventTester(QGraphicsItem *parent = 0) : QGraphicsItem(parent), repaints(0) - { br = QRectF(-10, -10, 20, 20); } + using QGraphicsItem::QGraphicsItem; void setGeometry(const QRectF &rect) { @@ -219,10 +225,10 @@ public: update(); } - QRectF boundingRect() const + QRectF boundingRect() const override { return br; } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *o, QWidget *) override { hints = painter->renderHints(); painter->setBrush(brush); @@ -231,7 +237,7 @@ public: ++repaints; } - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { events << event->type(); return QGraphicsItem::sceneEvent(event); @@ -240,32 +246,39 @@ public: void reset() { events.clear(); - hints = QPainter::RenderHints(0); + hints = QPainter::RenderHints{}; repaints = 0; lastExposedRect = QRectF(); } - QList<QEvent::Type> events; + QVector<QEvent::Type> events; QPainter::RenderHints hints; - int repaints; - QRectF br; + int repaints = 0; + QRectF br = QRectF(-10, -10, 20, 20); QRectF lastExposedRect; QBrush brush; }; class MyGraphicsView : public QGraphicsView { + Q_OBJECT public: - int repaints; QRegion paintedRegion; - MyGraphicsView(QGraphicsScene *scene, QWidget *parent=0) : QGraphicsView(scene,parent), repaints(0) {} - void paintEvent(QPaintEvent *e) + int repaints = 0; + + using QGraphicsView::QGraphicsView; + + void paintEvent(QPaintEvent *e) override { paintedRegion += e->region(); ++repaints; QGraphicsView::paintEvent(e); } - void reset() { repaints = 0; paintedRegion = QRegion(); } + void reset() + { + repaints = 0; + paintedRegion = QRegion(); + } }; class tst_QGraphicsItem : public QObject @@ -276,6 +289,7 @@ public: static void initMain(); private slots: + void cleanup(); void construction(); void constructionWithParent(); void destruction(); @@ -473,7 +487,7 @@ private slots: void QTBUG_21618_untransformable_sceneTransform(); private: - QList<QGraphicsItem *> paintedItems; + GraphicsItems paintedItems; QTouchDevice *m_touchDevice = nullptr; }; @@ -485,69 +499,76 @@ void tst_QGraphicsItem::initMain() #endif } +void tst_QGraphicsItem::cleanup() +{ + QVERIFY(QApplication::topLevelWidgets().isEmpty()); +} + +template <class I> +static inline I *createBlackShapeItem() +{ + auto result = new I; + result->setPen(QPen(Qt::black, 0)); + return result; +} + void tst_QGraphicsItem::construction() { for (int i = 0; i < 7; ++i) { QGraphicsItem *item = nullptr; switch (i) { case 0: - item = new QGraphicsEllipseItem; - ((QGraphicsEllipseItem *)item)->setPen(QPen(Qt::black, 0)); - QCOMPARE(int(item->type()), int(QGraphicsEllipseItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), (QGraphicsEllipseItem *)item); + item = createBlackShapeItem<QGraphicsEllipseItem>(); + QCOMPARE(item->type(), int(QGraphicsEllipseItem::Type)); + QCOMPARE(qgraphicsitem_cast<QGraphicsEllipseItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 1: - item = new QGraphicsLineItem; - ((QGraphicsLineItem *)item)->setPen(QPen(Qt::black, 0)); + item = createBlackShapeItem<QGraphicsLineItem>(); QCOMPARE(int(item->type()), int(QGraphicsLineItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), (QGraphicsLineItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 2: - item = new QGraphicsPathItem; - ((QGraphicsPathItem *)item)->setPen(QPen(Qt::black, 0)); + item = createBlackShapeItem<QGraphicsPathItem>(); QCOMPARE(int(item->type()), int(QGraphicsPathItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), (QGraphicsPathItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsPathItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 3: item = new QGraphicsPixmapItem; QCOMPARE(int(item->type()), int(QGraphicsPixmapItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), (QGraphicsPixmapItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsPixmapItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 4: - item = new QGraphicsPolygonItem; - ((QGraphicsPolygonItem *)item)->setPen(QPen(Qt::black, 0)); + item = createBlackShapeItem<QGraphicsPolygonItem>(); QCOMPARE(int(item->type()), int(QGraphicsPolygonItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), (QGraphicsPolygonItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsPolygonItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 5: - item = new QGraphicsRectItem; - ((QGraphicsRectItem *)item)->setPen(QPen(Qt::black, 0)); + item = createBlackShapeItem<QGraphicsRectItem>(); QCOMPARE(int(item->type()), int(QGraphicsRectItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), (QGraphicsRectItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsLineItem *>(item), nullptr); QCOMPARE(item->flags(), 0); break; case 6: item = new QGraphicsTextItem; QCOMPARE(int(item->type()), int(QGraphicsTextItem::Type)); - QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), (QGraphicsTextItem *)item); + QCOMPARE(qgraphicsitem_cast<QGraphicsTextItem *>(item), item); QCOMPARE(qgraphicsitem_cast<QGraphicsRectItem *>(item), nullptr); // This is the only item that uses an extended style option. QCOMPARE(item->flags(), QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemUsesExtendedStyleOption)); break; default: qFatal("You broke the logic, please fix!"); - break; } QCOMPARE(item->scene(), nullptr); @@ -569,10 +590,10 @@ void tst_QGraphicsItem::construction() QCOMPARE(item->sceneBoundingRect(), QRectF()); QCOMPARE(item->shape(), QPainterPath()); QVERIFY(!item->contains(QPointF(0, 0))); - QVERIFY(!item->collidesWithItem(0)); + QVERIFY(!item->collidesWithItem(nullptr)); QVERIFY(item->collidesWithItem(item)); QVERIFY(!item->collidesWithPath(QPainterPath())); - QVERIFY(!item->isAncestorOf(0)); + QVERIFY(!item->isAncestorOf(nullptr)); QVERIFY(!item->isAncestorOf(item)); QCOMPARE(item->data(0), QVariant()); delete item; @@ -582,17 +603,18 @@ void tst_QGraphicsItem::construction() class BoundingRectItem : public QGraphicsRectItem { public: - BoundingRectItem(QGraphicsItem *parent = 0) + BoundingRectItem(QGraphicsItem *parent = nullptr) : QGraphicsRectItem(0, 0, parent ? 200 : 100, parent ? 200 : 100, parent) { setPen(QPen(Qt::black, 0)); } - QRectF boundingRect() const + QRectF boundingRect() const override { QRectF tmp = QGraphicsRectItem::boundingRect(); - foreach (QGraphicsItem *child, childItems()) + const auto children = childItems(); + for (QGraphicsItem *child : children) tmp |= child->boundingRect(); // <- might be pure virtual return tmp; } @@ -608,11 +630,11 @@ void tst_QGraphicsItem::constructionWithParent() scene.addItem(item0); scene.addItem(item1); QGraphicsItem *item2 = new BoundingRectItem(item1); - QCOMPARE(item1->childItems(), QList<QGraphicsItem *>() << item2); + QCOMPARE(item1->childItems(), GraphicsItemsList{item2}); QCOMPARE(item1->boundingRect(), QRectF(0, 0, 200, 200)); item2->setParentItem(item0); - QCOMPARE(item0->childItems(), QList<QGraphicsItem *>() << item2); + QCOMPARE(item0->childItems(), GraphicsItemsList{item2}); QCOMPARE(item0->boundingRect(), QRectF(0, 0, 200, 200)); } @@ -760,7 +782,7 @@ void tst_QGraphicsItem::destruction() QGraphicsScene scene; QGraphicsItem *root = new QGraphicsRectItem; QGraphicsItem *parent = root; - QGraphicsItem *middleItem = 0; + QGraphicsItem *middleItem = nullptr; for (int i = 0; i < 99; ++i) { Item *child = new Item; child->setParentItem(parent); @@ -801,7 +823,7 @@ void tst_QGraphicsItem::deleteChildItem() QGraphicsItem *child3 = new QGraphicsRectItem(rect); Q_UNUSED(child3); delete child1; - child2->setParentItem(0); + child2->setParentItem(nullptr); delete child2; } @@ -812,11 +834,11 @@ void tst_QGraphicsItem::scene() QGraphicsScene scene; scene.addItem(item); - QCOMPARE(item->scene(), (QGraphicsScene *)&scene); + QCOMPARE(item->scene(), &scene); QGraphicsScene scene2; scene2.addItem(item); - QCOMPARE(item->scene(), (QGraphicsScene *)&scene2); + QCOMPARE(item->scene(), &scene2); scene2.removeItem(item); QCOMPARE(item->scene(), nullptr); @@ -830,10 +852,10 @@ void tst_QGraphicsItem::parentItem() QCOMPARE(item.parentItem(), nullptr); QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item); - QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item); + QCOMPARE(item2->parentItem(), &item); item2->setParentItem(&item); - QCOMPARE(item2->parentItem(), (QGraphicsItem *)&item); - item2->setParentItem(0); + QCOMPARE(item2->parentItem(), &item); + item2->setParentItem(nullptr); QCOMPARE(item2->parentItem(), nullptr); delete item2; @@ -853,7 +875,7 @@ void tst_QGraphicsItem::setParentItem() QCOMPARE(child->scene(), &scene); // This just makes it a toplevel - child->setParentItem(0); + child->setParentItem(nullptr); QCOMPARE(child->scene(), &scene); // Add the child back to the parent, then remove the parent from the scene @@ -869,7 +891,7 @@ void tst_QGraphicsItem::children() QGraphicsRectItem *item2 = new QGraphicsRectItem(QRectF(), &item); QCOMPARE(item.childItems().size(), 1); - QCOMPARE(item.childItems().first(), (QGraphicsItem *)item2); + QCOMPARE(item.childItems().constFirst(), item2); QVERIFY(item2->childItems().isEmpty()); delete item2; @@ -883,7 +905,7 @@ void tst_QGraphicsItem::flags() QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); scene.addItem(item); @@ -925,20 +947,20 @@ void tst_QGraphicsItem::flags() event.setScenePos(QPointF(0, 0)); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(scene.mouseGrabberItem(), nullptr); // mouse grabber is reset QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); event2.setScenePos(QPointF(10, 10)); event2.setButton(Qt::LeftButton); event2.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event2); + QCoreApplication::sendEvent(&scene, &event2); QCOMPARE(item->pos(), QPointF()); QGraphicsSceneMouseEvent event3(QEvent::GraphicsSceneMouseRelease); event3.setScenePos(QPointF(10, 10)); - event3.setButtons(0); - QApplication::sendEvent(&scene, &event3); + event3.setButtons({}); + QCoreApplication::sendEvent(&scene, &event3); QCOMPARE(scene.mouseGrabberItem(), nullptr); item->setFlag(QGraphicsItem::ItemIsMovable, true); @@ -946,13 +968,13 @@ void tst_QGraphicsItem::flags() event4.setScenePos(QPointF(0, 0)); event4.setButton(Qt::LeftButton); event4.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event4); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCoreApplication::sendEvent(&scene, &event4); + QCOMPARE(scene.mouseGrabberItem(), item); QGraphicsSceneMouseEvent event5(QEvent::GraphicsSceneMouseMove); event5.setScenePos(QPointF(10, 10)); event5.setButton(Qt::LeftButton); event5.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event5); + QCoreApplication::sendEvent(&scene, &event5); QCOMPARE(item->pos(), QPointF(10, 10)); } { @@ -975,8 +997,8 @@ void tst_QGraphicsItem::flags() class ImhTester : public QGraphicsItem { - QRectF boundingRect() const { return QRectF(); } - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {} + QRectF boundingRect() const override { return QRectF(); } + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override {} }; void tst_QGraphicsItem::inputMethodHints() @@ -996,6 +1018,7 @@ void tst_QGraphicsItem::inputMethodHints() scene.addItem(item2); QGraphicsView view(&scene); QApplication::setActiveWindow(&view); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1045,6 +1068,7 @@ void tst_QGraphicsItem::toolTip() scene.addItem(item); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(200, 200); view.show(); QApplication::setActiveWindow(&view); @@ -1053,12 +1077,13 @@ void tst_QGraphicsItem::toolTip() { QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); - QApplication::sendEvent(view.viewport(), &helpEvent); + QCoreApplication::sendEvent(view.viewport(), &helpEvent); QTest::qWait(250); bool foundView = false; bool foundTipLabel = false; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const auto topLevels = QApplication::topLevelWidgets(); + for (auto widget : topLevels) { if (widget == &view) foundView = true; if (widget->inherits("QTipLabel")) @@ -1071,12 +1096,13 @@ void tst_QGraphicsItem::toolTip() { QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().center(), view.viewport()->mapToGlobal(view.viewport()->rect().center())); - QApplication::sendEvent(view.viewport(), &helpEvent); + QCoreApplication::sendEvent(view.viewport(), &helpEvent); QTest::qWait(250); bool foundView = false; bool foundTipLabel = false; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const auto topLevels = QApplication::topLevelWidgets(); + for (auto widget : topLevels) { if (widget == &view) foundView = true; if (widget->inherits("QTipLabel")) @@ -1089,12 +1115,13 @@ void tst_QGraphicsItem::toolTip() { QHelpEvent helpEvent(QEvent::ToolTip, view.viewport()->rect().topLeft(), view.viewport()->mapToGlobal(view.viewport()->rect().topLeft())); - QApplication::sendEvent(view.viewport(), &helpEvent); + QCoreApplication::sendEvent(view.viewport(), &helpEvent); QTest::qWait(1000); bool foundView = false; bool foundTipLabel = false; - foreach (QWidget *widget, QApplication::topLevelWidgets()) { + const auto topLevels = QApplication::topLevelWidgets(); + for (auto widget : topLevels) { if (widget == &view) foundView = true; if (widget->inherits("QTipLabel") && widget->isVisible()) @@ -1117,7 +1144,7 @@ void tst_QGraphicsItem::visible() QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); scene.addItem(item); QVERIFY(item->isVisible()); @@ -1130,7 +1157,7 @@ void tst_QGraphicsItem::visible() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setButton(Qt::LeftButton); event.setScenePos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(scene.mouseGrabberItem(), item); item->setVisible(false); QCOMPARE(scene.mouseGrabberItem(), nullptr); @@ -1161,14 +1188,14 @@ void tst_QGraphicsItem::isVisibleTo() QVERIFY(grandChild->isVisibleTo(grandChild)); QVERIFY(grandChild->isVisibleTo(child)); QVERIFY(grandChild->isVisibleTo(parent)); - QVERIFY(grandChild->isVisibleTo(0)); + QVERIFY(grandChild->isVisibleTo(nullptr)); QVERIFY(child->isVisible()); QVERIFY(child->isVisibleTo(child)); QVERIFY(child->isVisibleTo(parent)); - QVERIFY(child->isVisibleTo(0)); + QVERIFY(child->isVisibleTo(nullptr)); QVERIFY(parent->isVisible()); QVERIFY(parent->isVisibleTo(parent)); - QVERIFY(parent->isVisibleTo(0)); + QVERIFY(parent->isVisibleTo(nullptr)); QVERIFY(!parent->isVisibleTo(child)); QVERIFY(!child->isVisibleTo(grandChild)); QVERIFY(!grandChild->isVisibleTo(stranger)); @@ -1185,14 +1212,14 @@ void tst_QGraphicsItem::isVisibleTo() QVERIFY(grandChild->isVisibleTo(grandChild)); QVERIFY(grandChild->isVisibleTo(child)); QVERIFY(grandChild->isVisibleTo(parent)); - QVERIFY(!grandChild->isVisibleTo(0)); + QVERIFY(!grandChild->isVisibleTo(nullptr)); QVERIFY(!child->isVisible()); QVERIFY(child->isVisibleTo(child)); QVERIFY(child->isVisibleTo(parent)); - QVERIFY(!child->isVisibleTo(0)); + QVERIFY(!child->isVisibleTo(nullptr)); QVERIFY(!parent->isVisible()); QVERIFY(!parent->isVisibleTo(parent)); - QVERIFY(!parent->isVisibleTo(0)); + QVERIFY(!parent->isVisibleTo(nullptr)); QVERIFY(!parent->isVisibleTo(child)); QVERIFY(!child->isVisibleTo(grandChild)); QVERIFY(!grandChild->isVisibleTo(stranger)); @@ -1210,14 +1237,14 @@ void tst_QGraphicsItem::isVisibleTo() QVERIFY(grandChild->isVisibleTo(grandChild)); QVERIFY(grandChild->isVisibleTo(child)); QVERIFY(!grandChild->isVisibleTo(parent)); - QVERIFY(!grandChild->isVisibleTo(0)); + QVERIFY(!grandChild->isVisibleTo(nullptr)); QVERIFY(!child->isVisible()); QVERIFY(!child->isVisibleTo(child)); QVERIFY(!child->isVisibleTo(parent)); - QVERIFY(!child->isVisibleTo(0)); + QVERIFY(!child->isVisibleTo(nullptr)); QVERIFY(parent->isVisible()); QVERIFY(parent->isVisibleTo(parent)); - QVERIFY(parent->isVisibleTo(0)); + QVERIFY(parent->isVisibleTo(nullptr)); QVERIFY(!parent->isVisibleTo(child)); QVERIFY(!child->isVisibleTo(grandChild)); QVERIFY(!grandChild->isVisibleTo(stranger)); @@ -1235,14 +1262,14 @@ void tst_QGraphicsItem::isVisibleTo() QVERIFY(!grandChild->isVisibleTo(grandChild)); QVERIFY(!grandChild->isVisibleTo(child)); QVERIFY(!grandChild->isVisibleTo(parent)); - QVERIFY(!grandChild->isVisibleTo(0)); + QVERIFY(!grandChild->isVisibleTo(nullptr)); QVERIFY(child->isVisible()); QVERIFY(child->isVisibleTo(child)); QVERIFY(child->isVisibleTo(parent)); - QVERIFY(child->isVisibleTo(0)); + QVERIFY(child->isVisibleTo(nullptr)); QVERIFY(parent->isVisible()); QVERIFY(parent->isVisibleTo(parent)); - QVERIFY(parent->isVisibleTo(0)); + QVERIFY(parent->isVisibleTo(nullptr)); QVERIFY(!parent->isVisibleTo(child)); QVERIFY(!child->isVisibleTo(grandChild)); QVERIFY(!grandChild->isVisibleTo(stranger)); @@ -1349,7 +1376,7 @@ void tst_QGraphicsItem::explicitlyVisible() // Reparent implicitly hidden child to root. parent2->hide(); QVERIFY(!child->isVisible()); - child->setParentItem(0); + child->setParentItem(nullptr); QVERIFY(child->isVisible()); // Reparent an explicitly hidden child to root. @@ -1357,7 +1384,7 @@ void tst_QGraphicsItem::explicitlyVisible() child->setParentItem(parent2); parent2->show(); QVERIFY(!child->isVisible()); - child->setParentItem(0); + child->setParentItem(nullptr); QVERIFY(!child->isVisible()); } @@ -1374,7 +1401,7 @@ void tst_QGraphicsItem::enabled() item->setFlag(QGraphicsItem::ItemIsFocusable); QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); scene.addItem(item); item->setFocus(); @@ -1388,11 +1415,11 @@ void tst_QGraphicsItem::enabled() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setButton(Qt::LeftButton); event.setScenePos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(scene.mouseGrabberItem(), nullptr); item->setEnabled(true); - QApplication::sendEvent(&scene, &event); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCoreApplication::sendEvent(&scene, &event); + QCOMPARE(scene.mouseGrabberItem(), item); item->setEnabled(false); QCOMPARE(scene.mouseGrabberItem(), nullptr); } @@ -1493,7 +1520,7 @@ void tst_QGraphicsItem::explicitlyEnabled() // Reparent implicitly hidden child to root. parent2->setEnabled(false); QVERIFY(!child->isEnabled()); - child->setParentItem(0); + child->setParentItem(nullptr); QVERIFY(child->isEnabled()); // Reparent an explicitly hidden child to root. @@ -1501,7 +1528,7 @@ void tst_QGraphicsItem::explicitlyEnabled() child->setParentItem(parent2); parent2->setEnabled(true); QVERIFY(!child->isEnabled()); - child->setParentItem(0); + child->setParentItem(nullptr); QVERIFY(!child->isEnabled()); } @@ -1509,10 +1536,10 @@ class SelectChangeItem : public QGraphicsRectItem { public: SelectChangeItem() : QGraphicsRectItem(-50, -50, 100, 100) { setBrush(Qt::blue); } - QList<bool> values; + QVector<bool> values; protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value) + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override { if (change == ItemSelectedChange) values << value.toBool(); @@ -1528,70 +1555,71 @@ void tst_QGraphicsItem::selected() QVERIFY(item->values.isEmpty()); item->setSelected(true); QCOMPARE(item->values.size(), 1); - QCOMPARE(item->values.last(), true); + QCOMPARE(item->values.constLast(), true); QVERIFY(item->isSelected()); item->setSelected(false); QCOMPARE(item->values.size(), 2); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); item->setSelected(true); QCOMPARE(item->values.size(), 3); item->setEnabled(false); QCOMPARE(item->values.size(), 4); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); item->setEnabled(true); QCOMPARE(item->values.size(), 4); item->setSelected(true); QCOMPARE(item->values.size(), 5); - QCOMPARE(item->values.last(), true); + QCOMPARE(item->values.constLast(), true); QVERIFY(item->isSelected()); item->setVisible(false); QCOMPARE(item->values.size(), 6); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); item->setVisible(true); QCOMPARE(item->values.size(), 6); item->setSelected(true); QCOMPARE(item->values.size(), 7); - QCOMPARE(item->values.last(), true); + QCOMPARE(item->values.constLast(), true); QVERIFY(item->isSelected()); QGraphicsScene scene(-100, -100, 200, 200); scene.addItem(item); - QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item); + QCOMPARE(scene.selectedItems(), GraphicsItemsList{item}); item->setSelected(false); QVERIFY(scene.selectedItems().isEmpty()); item->setSelected(true); - QCOMPARE(scene.selectedItems(), QList<QGraphicsItem *>() << item); + QCOMPARE(scene.selectedItems(), GraphicsItemsList{item}); item->setSelected(false); QVERIFY(scene.selectedItems().isEmpty()); // Interactive selection QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(250, 250); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - qApp->processEvents(); - qApp->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); scene.clearSelection(); QCOMPARE(item->values.size(), 10); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); // Click inside and check that it's selected QTest::mouseMove(view.viewport()); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos())); QCOMPARE(item->values.size(), 11); - QCOMPARE(item->values.last(), true); + QCOMPARE(item->values.constLast(), true); QVERIFY(item->isSelected()); // Click outside and check that it's not selected - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height()))); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos() + QPointF(item->boundingRect().width(), item->boundingRect().height()))); QCOMPARE(item->values.size(), 12); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); SelectChangeItem *item2 = new SelectChangeItem; @@ -1600,18 +1628,18 @@ void tst_QGraphicsItem::selected() scene.addItem(item2); // Click inside and check that it's selected - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos())); QCOMPARE(item->values.size(), 13); - QCOMPARE(item->values.last(), true); + QCOMPARE(item->values.constLast(), true); QVERIFY(item->isSelected()); // Click inside item2 and check that it's selected, and item is not - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos())); QCOMPARE(item->values.size(), 14); - QCOMPARE(item->values.last(), false); + QCOMPARE(item->values.constLast(), false); QVERIFY(!item->isSelected()); QCOMPARE(item2->values.size(), 1); - QCOMPARE(item2->values.last(), true); + QCOMPARE(item2->values.constLast(), true); QVERIFY(item2->isSelected()); } @@ -1632,7 +1660,7 @@ void tst_QGraphicsItem::selected2() QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress); mousePress.setScenePos(QPointF(50, 50)); mousePress.setButton(Qt::LeftButton); - QApplication::sendEvent(&scene, &mousePress); + QCoreApplication::sendEvent(&scene, &mousePress); QVERIFY(mousePress.isAccepted()); } { @@ -1640,7 +1668,7 @@ void tst_QGraphicsItem::selected2() mouseMove.setScenePos(QPointF(60, 60)); mouseMove.setButton(Qt::LeftButton); mouseMove.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &mouseMove); + QCoreApplication::sendEvent(&scene, &mouseMove); QVERIFY(mouseMove.isAccepted()); } } @@ -1657,10 +1685,11 @@ void tst_QGraphicsItem::selected_group() leaf->setFlag(QGraphicsItem::ItemIsSelectable); leaf->setParentItem(item2); - QGraphicsItemGroup *group = scene.createItemGroup(QList<QGraphicsItem *>() << item1 << item2); + QGraphicsItemGroup *group = scene.createItemGroup(GraphicsItemsList{item1, item2}); QCOMPARE(group->scene(), &scene); group->setFlag(QGraphicsItem::ItemIsSelectable); - foreach (QGraphicsItem *item, scene.items()) { + const auto items = scene.items(); + for (QGraphicsItem *item : items) { if (item == group) QVERIFY(!item->group()); else @@ -1673,18 +1702,16 @@ void tst_QGraphicsItem::selected_group() QVERIFY(!group->isSelected()); group->setSelected(true); QVERIFY(group->isSelected()); - foreach (QGraphicsItem *item, scene.items()) - QVERIFY(item->isSelected()); + + const auto itemIsSelected = [](const QGraphicsItem *item) { return item->isSelected(); }; + QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected)); group->setSelected(false); QVERIFY(!group->isSelected()); - foreach (QGraphicsItem *item, scene.items()) - QVERIFY(!item->isSelected()); + QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected)); leaf->setSelected(true); - foreach (QGraphicsItem *item, scene.items()) - QVERIFY(item->isSelected()); + QVERIFY(std::all_of(items.cbegin(), items.cend(), itemIsSelected)); leaf->setSelected(false); - foreach (QGraphicsItem *item, scene.items()) - QVERIFY(!item->isSelected()); + QVERIFY(std::none_of(items.cbegin(), items.cend(), itemIsSelected)); leaf->setSelected(true); QGraphicsScene scene2; @@ -1700,18 +1727,19 @@ void tst_QGraphicsItem::selected_textItem() text->setFlag(QGraphicsItem::ItemIsSelectable); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(!text->isSelected()); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(text->mapToScene(0, 0))); QTRY_VERIFY(text->isSelected()); text->setSelected(false); text->setTextInteractionFlags(Qt::TextEditorInteraction); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(text->mapToScene(0, 0))); QTRY_VERIFY(text->isSelected()); } @@ -1733,6 +1761,7 @@ void tst_QGraphicsItem::selected_multi() // Create and show a view QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); view.fitInView(scene.sceneRect()); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -1741,12 +1770,12 @@ void tst_QGraphicsItem::selected_multi() QVERIFY(!item2->isSelected()); // Click on item1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos())); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item2 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos())); QVERIFY(item2->isSelected()); QVERIFY(!item1->isSelected()); @@ -1766,17 +1795,17 @@ void tst_QGraphicsItem::selected_multi() QVERIFY(!item1->isSelected()); // Click on item1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos())); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on scene - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0)); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos())); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1786,27 +1815,27 @@ void tst_QGraphicsItem::selected_multi() QVERIFY(!item2->isSelected()); // Click on scene - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(0, 0)); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(0, 0)); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); // Click on item1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos())); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); // Press on item2 - QTest::mousePress(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); + QTest::mousePress(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos())); QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); // Release on item2 - QTest::mouseRelease(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item2->scenePos())); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item2->scenePos())); QVERIFY(!item1->isSelected()); QVERIFY(item2->isSelected()); // Click on item1 - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item1->scenePos())); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item1->scenePos())); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); @@ -1824,7 +1853,7 @@ void tst_QGraphicsItem::selected_multi() // Ctrl-move on item1 const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); - QApplication::sendEvent(view.viewport(), &event); + QCoreApplication::sendEvent(view.viewport(), &event); QVERIFY(!item1->isSelected()); QVERIFY(!item2->isSelected()); } @@ -1846,7 +1875,7 @@ void tst_QGraphicsItem::selected_multi() // Ctrl-move on item1 const QPoint item1Point = view.mapFromScene(item1->scenePos()) + QPoint(1, 0); QMouseEvent event(QEvent::MouseMove, item1Point, view.viewport()->mapToGlobal(item1Point), Qt::LeftButton, Qt::LeftButton, Qt::ControlModifier); - QApplication::sendEvent(view.viewport(), &event); + QCoreApplication::sendEvent(view.viewport(), &event); QVERIFY(item1->isSelected()); QVERIFY(!item2->isSelected()); } @@ -1873,33 +1902,30 @@ void tst_QGraphicsItem::acceptedMouseButtons() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setButton(Qt::LeftButton); event.setScenePos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &event); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item2); - item2->setAcceptedMouseButtons(0); + QCoreApplication::sendEvent(&scene, &event); + QCOMPARE(scene.mouseGrabberItem(), item2); + item2->setAcceptedMouseButtons(nullptr); QCOMPARE(scene.mouseGrabberItem(), nullptr); - QApplication::sendEvent(&scene, &event); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item1); + QCoreApplication::sendEvent(&scene, &event); + QCOMPARE(scene.mouseGrabberItem(), item1); } class HoverItem : public QGraphicsRectItem { public: - HoverItem(const QRectF &rect) - : QGraphicsRectItem(rect), hoverInCount(0), - hoverMoveCount(0), hoverOutCount(0) - { } + HoverItem(const QRectF &rect) : QGraphicsRectItem(rect) { } - int hoverInCount; - int hoverMoveCount; - int hoverOutCount; + int hoverInCount = 0; + int hoverMoveCount = 0; + int hoverOutCount = 0; protected: - void hoverEnterEvent(QGraphicsSceneHoverEvent *) + void hoverEnterEvent(QGraphicsSceneHoverEvent *) override { ++hoverInCount; } - void hoverMoveEvent(QGraphicsSceneHoverEvent *) + void hoverMoveEvent(QGraphicsSceneHoverEvent *) override { ++hoverMoveCount; } - void hoverLeaveEvent(QGraphicsSceneHoverEvent *) + void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override { ++hoverOutCount; } }; @@ -1919,9 +1945,9 @@ void tst_QGraphicsItem::acceptHoverEvents() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setScenePos(QPointF(-100, -100)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); event.setScenePos(QPointF(-2.5, -2.5)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item1->hoverInCount, 0); QCOMPARE(item2->hoverInCount, 1); @@ -1930,9 +1956,9 @@ void tst_QGraphicsItem::acceptHoverEvents() item2->setAcceptHoverEvents(false); event.setScenePos(QPointF(-100, -100)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); event.setScenePos(QPointF(-2.5, -2.5)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item1->hoverInCount, 0); QCOMPARE(item2->hoverInCount, 1); @@ -1941,9 +1967,9 @@ void tst_QGraphicsItem::acceptHoverEvents() item2->setAcceptHoverEvents(false); event.setScenePos(QPointF(-100, -100)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); event.setScenePos(QPointF(-2.5, -2.5)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item1->hoverInCount, 1); QCOMPARE(item2->hoverInCount, 1); @@ -1962,7 +1988,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setScenePos(QPointF(-100, -100)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 0); QCOMPARE(item2->hoverMoveCount, 0); QCOMPARE(item2->hoverOutCount, 0); @@ -1971,7 +1997,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() QCOMPARE(item1->hoverOutCount, 0); event.setScenePos(QPointF(-2.5, -2.5)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 1); QCOMPARE(item2->hoverMoveCount, 1); @@ -1981,7 +2007,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() QCOMPARE(item1->hoverOutCount, 0); event.setScenePos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 1); QCOMPARE(item2->hoverMoveCount, 2); @@ -1991,7 +2017,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() QCOMPARE(item1->hoverOutCount, 0); event.setScenePos(QPointF(-7, -7)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 1); QCOMPARE(item2->hoverMoveCount, 2); @@ -2001,7 +2027,7 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() QCOMPARE(item1->hoverOutCount, 0); event.setScenePos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 2); QCOMPARE(item2->hoverMoveCount, 3); @@ -2016,10 +2042,10 @@ void tst_QGraphicsItem::childAcceptsHoverEvents() item0->setAcceptHoverEvents(true); event.setScenePos(QPointF(-100, -100)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); event.setScenePos(QPointF(-15, -15)); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(item2->hoverInCount, 2); QCOMPARE(item2->hoverMoveCount, 3); @@ -2041,7 +2067,7 @@ void tst_QGraphicsItem::hasFocus() QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); scene.addItem(line); @@ -2052,7 +2078,7 @@ void tst_QGraphicsItem::hasFocus() QVERIFY(line->hasFocus()); QGraphicsScene scene2; - QApplication::sendEvent(&scene2, &activate); + QCoreApplication::sendEvent(&scene2, &activate); scene2.addItem(line); QVERIFY(!line->hasFocus()); @@ -2193,13 +2219,13 @@ void tst_QGraphicsItem::sceneTransform() void tst_QGraphicsItem::setTransform() { QGraphicsScene scene; - QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); + QSignalSpy spy(&scene, &QGraphicsScene::changed); QRectF unrotatedRect(-12, -34, 56, 78); - QGraphicsRectItem item(unrotatedRect, 0); + QGraphicsRectItem item(unrotatedRect, nullptr); item.setPen(QPen(Qt::black, 0)); scene.addItem(&item); scene.update(scene.sceneRect()); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(spy.count(), 1); @@ -2207,14 +2233,14 @@ void tst_QGraphicsItem::setTransform() QRectF rotatedRect = scene.sceneRect(); QVERIFY(unrotatedRect != rotatedRect); scene.update(scene.sceneRect()); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(spy.count(), 2); item.setTransform(QTransform()); scene.update(scene.sceneRect()); - QApplication::instance()->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(spy.count(), 3); QList<QRectF> rlist = qvariant_cast<QList<QRectF> >(spy.last().at(0)); @@ -2226,15 +2252,18 @@ void tst_QGraphicsItem::setTransform() QCOMPARE(rlist.at(1), unrotatedRect); // From post-update (update current state) } -static QList<QGraphicsItem *> _paintedItems; +static GraphicsItems _paintedItems; class PainterItem : public QGraphicsItem { protected: - QRectF boundingRect() const + QRectF boundingRect() const override { return QRectF(-10, -10, 20, 20); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) - { _paintedItems << this; painter->fillRect(boundingRect(), Qt::red); } + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override + { + _paintedItems << this; + painter->fillRect(boundingRect(), Qt::red); + } }; void tst_QGraphicsItem::zValue() @@ -2257,6 +2286,7 @@ void tst_QGraphicsItem::zValue() item3->setZValue(0); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -2467,12 +2497,12 @@ void tst_QGraphicsItem::collidesWith_item() { QGraphicsScene scene; - QGraphicsRectItem rect(20, 20, 100, 100, 0); + QGraphicsRectItem rect(20, 20, 100, 100, nullptr); scene.addItem(&rect); - QGraphicsRectItem rect2(40, 40, 50, 50, 0); + QGraphicsRectItem rect2(40, 40, 50, 50, nullptr); scene.addItem(&rect2); rect2.setZValue(1); - QGraphicsLineItem line(0, 0, 200, 200, 0); + QGraphicsLineItem line(0, 0, 200, 200, nullptr); scene.addItem(&line); line.setZValue(2); @@ -2480,18 +2510,18 @@ void tst_QGraphicsItem::collidesWith_item() QList<QGraphicsItem *> col1 = rect.collidingItems(); QCOMPARE(col1.size(), 2); - QCOMPARE(col1.first(), static_cast<QGraphicsItem *>(&line)); - QCOMPARE(col1.last(), static_cast<QGraphicsItem *>(&rect2)); + QCOMPARE(col1.constFirst(), &line); + QCOMPARE(col1.constLast(), &rect2); QList<QGraphicsItem *> col2 = rect2.collidingItems(); QCOMPARE(col2.size(), 2); - QCOMPARE(col2.first(), static_cast<QGraphicsItem *>(&line)); - QCOMPARE(col2.last(), static_cast<QGraphicsItem *>(&rect)); + QCOMPARE(col2.constFirst(), &line); + QCOMPARE(col2.constLast(), &rect); QList<QGraphicsItem *> col3 = line.collidingItems(); QCOMPARE(col3.size(), 2); - QCOMPARE(col3.first(), static_cast<QGraphicsItem *>(&rect2)); - QCOMPARE(col3.last(), static_cast<QGraphicsItem *>(&rect)); + QCOMPARE(col3.constFirst(), &rect2); + QCOMPARE(col3.constLast(), &rect); } } @@ -2574,42 +2604,35 @@ void tst_QGraphicsItem::collidesWithItemWithClip() class MyItem : public QGraphicsEllipseItem { public: - bool isObscuredBy(const QGraphicsItem *item) const - { - const MyItem *myItem = qgraphicsitem_cast<const MyItem *>(item); - if (myItem) { - if (item->zValue() > zValue()) { - QRectF r = rect(); - QPointF topMid = (r.topRight()+r.topLeft())/2; - QPointF botMid = (r.bottomRight()+r.bottomLeft())/2; - QPointF leftMid = (r.topLeft()+r.bottomLeft())/2; - QPointF rightMid = (r.topRight()+r.bottomRight())/2; - - QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea()); - - if (mappedShape.contains(topMid) && - mappedShape.contains(botMid) && - mappedShape.contains(leftMid) && - mappedShape.contains(rightMid)) - return true; - else - return false; - } - else return false; - } - else - return QGraphicsItem::isObscuredBy(item); + bool isObscuredBy(const QGraphicsItem *item) const override + { + auto myItem = qgraphicsitem_cast<const MyItem *>(item); + if (!myItem) + return QGraphicsEllipseItem::isObscuredBy(item); + + if (item->zValue() <= zValue()) + return false; + + QRectF r = rect(); + QPointF topMid = (r.topRight() + r.topLeft()) / 2; + QPointF botMid = (r.bottomRight() + r.bottomLeft()) / 2; + QPointF leftMid = (r.topLeft() + r.bottomLeft()) / 2; + QPointF rightMid = (r.topRight() + r.bottomRight()) / 2; + + QPainterPath mappedShape = item->mapToItem(this, item->opaqueArea()); + + return mappedShape.contains(topMid) && mappedShape.contains(botMid) + && mappedShape.contains(leftMid) && mappedShape.contains(rightMid); } - QPainterPath opaqueArea() const + QPainterPath opaqueArea() const override { return shape(); } - enum { - Type = UserType+1 - }; - int type() const { return Type; } + enum { Type = UserType + 1 }; + + int type() const override { return Type; } }; void tst_QGraphicsItem::isObscuredBy() @@ -2662,7 +2685,7 @@ void tst_QGraphicsItem::isObscuredBy() class OpaqueItem : public QGraphicsRectItem { protected: - QPainterPath opaqueArea() const + QPainterPath opaqueArea() const override { return shape(); } @@ -2977,14 +3000,14 @@ void tst_QGraphicsItem::mapFromToItem() QCOMPARE(item3->mapFromItem(item2, 10, -5), QPointF(-190, -5)); QCOMPARE(item4->mapFromItem(item3, 10, -5), QPointF(10, -205)); - QCOMPARE(item1->mapFromItem(0, 10, -5), item1->mapFromScene(10, -5)); - QCOMPARE(item2->mapFromItem(0, 10, -5), item2->mapFromScene(10, -5)); - QCOMPARE(item3->mapFromItem(0, 10, -5), item3->mapFromScene(10, -5)); - QCOMPARE(item4->mapFromItem(0, 10, -5), item4->mapFromScene(10, -5)); - QCOMPARE(item1->mapToItem(0, 10, -5), item1->mapToScene(10, -5)); - QCOMPARE(item2->mapToItem(0, 10, -5), item2->mapToScene(10, -5)); - QCOMPARE(item3->mapToItem(0, 10, -5), item3->mapToScene(10, -5)); - QCOMPARE(item4->mapToItem(0, 10, -5), item4->mapToScene(10, -5)); + QCOMPARE(item1->mapFromItem(nullptr, 10, -5), item1->mapFromScene(10, -5)); + QCOMPARE(item2->mapFromItem(nullptr, 10, -5), item2->mapFromScene(10, -5)); + QCOMPARE(item3->mapFromItem(nullptr, 10, -5), item3->mapFromScene(10, -5)); + QCOMPARE(item4->mapFromItem(nullptr, 10, -5), item4->mapFromScene(10, -5)); + QCOMPARE(item1->mapToItem(nullptr, 10, -5), item1->mapToScene(10, -5)); + QCOMPARE(item2->mapToItem(nullptr, 10, -5), item2->mapToScene(10, -5)); + QCOMPARE(item3->mapToItem(nullptr, 10, -5), item3->mapToScene(10, -5)); + QCOMPARE(item4->mapToItem(nullptr, 10, -5), item4->mapToScene(10, -5)); delete item1; delete item2; @@ -3079,8 +3102,8 @@ void tst_QGraphicsItem::isAncestorOf() QGraphicsItem *parent = new QGraphicsRectItem; QGraphicsItem *child = new QGraphicsRectItem; - QVERIFY(!parent->isAncestorOf(0)); - QVERIFY(!child->isAncestorOf(0)); + QVERIFY(!parent->isAncestorOf(nullptr)); + QVERIFY(!child->isAncestorOf(nullptr)); QVERIFY(!parent->isAncestorOf(child)); QVERIFY(!child->isAncestorOf(parent)); QVERIFY(!parent->isAncestorOf(parent)); @@ -3098,7 +3121,7 @@ void tst_QGraphicsItem::isAncestorOf() QVERIFY(!parent->isAncestorOf(parent)); QVERIFY(!grandPa->isAncestorOf(grandPa)); - parent->setParentItem(0); + parent->setParentItem(nullptr); delete child; delete parent; @@ -3126,7 +3149,7 @@ void tst_QGraphicsItem::commonAncestorItem() grandPa->setParentItem(ancestor); QCOMPARE(grandMa->commonAncestorItem(grandMa), grandMa); - QCOMPARE(grandMa->commonAncestorItem(0), nullptr); + QCOMPARE(grandMa->commonAncestorItem(nullptr), nullptr); QCOMPARE(grandMa->commonAncestorItem(grandPa), ancestor); QCOMPARE(grandPa->commonAncestorItem(grandMa), ancestor); QCOMPARE(grandPa->commonAncestorItem(husband), grandPa); @@ -3230,7 +3253,7 @@ void tst_QGraphicsItem::graphicsitem_cast() QVERIFY(!qgraphicsitem_cast<const QGraphicsTextItem *>(pPolygonItem)); // and this shouldn't crash - QGraphicsItem *ptr = 0; + QGraphicsItem *ptr = nullptr; QVERIFY(!qgraphicsitem_cast<QGraphicsTextItem *>(ptr)); QVERIFY(!qgraphicsitem_cast<QGraphicsItem *>(ptr)); } @@ -3241,6 +3264,7 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -3256,48 +3280,48 @@ void tst_QGraphicsItem::hoverEventsGenerateRepaints() QGraphicsSceneHoverEvent hoverEnterEvent(QEvent::GraphicsSceneHoverEnter); hoverEnterEvent.setScenePos(QPointF(0, 0)); hoverEnterEvent.setPos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &hoverEnterEvent); + QCoreApplication::sendEvent(&scene, &hoverEnterEvent); // Check that we get a repaint int npaints = tester->repaints; - qApp->processEvents(); - qApp->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); QCOMPARE(tester->events.size(), 2); // enter + move QCOMPARE(tester->repaints, npaints + 1); - QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove); + QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove); // Send a hover move event QGraphicsSceneHoverEvent hoverMoveEvent(QEvent::GraphicsSceneHoverMove); hoverMoveEvent.setScenePos(QPointF(0, 0)); hoverMoveEvent.setPos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &hoverMoveEvent); + QCoreApplication::sendEvent(&scene, &hoverMoveEvent); // Check that we don't get a repaint - qApp->processEvents(); - qApp->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); QCOMPARE(tester->events.size(), 3); QCOMPARE(tester->repaints, npaints + 1); - QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverMove); + QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverMove); // Send a hover leave event QGraphicsSceneHoverEvent hoverLeaveEvent(QEvent::GraphicsSceneHoverLeave); hoverLeaveEvent.setScenePos(QPointF(-100, -100)); hoverLeaveEvent.setPos(QPointF(0, 0)); - QApplication::sendEvent(&scene, &hoverLeaveEvent); + QCoreApplication::sendEvent(&scene, &hoverLeaveEvent); // Check that we get a repaint - qApp->processEvents(); - qApp->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); QCOMPARE(tester->events.size(), 4); QCOMPARE(tester->repaints, npaints + 2); - QCOMPARE(tester->events.last(), QEvent::GraphicsSceneHoverLeave); + QCOMPARE(tester->events.constLast(), QEvent::GraphicsSceneHoverLeave); } void tst_QGraphicsItem::boundingRects_data() { - QTest::addColumn<QGraphicsItem *>("item"); + QTest::addColumn<AbstractGraphicsShapeItemPtr>("item"); QTest::addColumn<QRectF>("boundingRect"); QRectF rect(0, 0, 100, 100); @@ -3306,18 +3330,18 @@ void tst_QGraphicsItem::boundingRects_data() QRectF adjustedRect(-0.5, -0.5, 101, 101); - QTest::newRow("path") << (QGraphicsItem *)new QGraphicsPathItem(path) << adjustedRect; - QTest::newRow("rect") << (QGraphicsItem *)new QGraphicsRectItem(rect) << adjustedRect; - QTest::newRow("ellipse") << (QGraphicsItem *)new QGraphicsEllipseItem(rect) << adjustedRect; - QTest::newRow("polygon") << (QGraphicsItem *)new QGraphicsPolygonItem(rect) << adjustedRect; + QTest::newRow("path") << AbstractGraphicsShapeItemPtr(new QGraphicsPathItem(path)) << adjustedRect; + QTest::newRow("rect") << AbstractGraphicsShapeItemPtr(new QGraphicsRectItem(rect)) << adjustedRect; + QTest::newRow("ellipse") << AbstractGraphicsShapeItemPtr(new QGraphicsEllipseItem(rect)) << adjustedRect; + QTest::newRow("polygon") << AbstractGraphicsShapeItemPtr(new QGraphicsPolygonItem(rect)) << adjustedRect; } void tst_QGraphicsItem::boundingRects() { - QFETCH(QGraphicsItem *, item); + QFETCH(AbstractGraphicsShapeItemPtr, item); QFETCH(QRectF, boundingRect); - ((QAbstractGraphicsShapeItem *)item)->setPen(QPen(Qt::black, 1)); + item->setPen(QPen(Qt::black, 1)); QCOMPARE(item->boundingRect(), boundingRect); } @@ -3373,6 +3397,7 @@ void tst_QGraphicsItem::childrenBoundingRect() scene.addPolygon(parent->mapToScene(parent->boundingRect() | parent->childrenBoundingRect()))->setPen(QPen(Qt::red));; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -3488,6 +3513,7 @@ void tst_QGraphicsItem::childrenBoundingRect4() rect3->setParentItem(rect); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -3515,6 +3541,7 @@ void tst_QGraphicsItem::childrenBoundingRect5() child->setPen(QPen(Qt::black, 0)); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -3551,6 +3578,7 @@ void tst_QGraphicsItem::group() QCOMPARE(child->group(), nullptr); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -3563,7 +3591,7 @@ void tst_QGraphicsItem::group() QCOMPARE(parent->group(), group); QCOMPARE(parent->sceneBoundingRect(), parentSceneBoundingRect); - QCOMPARE(parent->parentItem(), (QGraphicsItem *)group); + QCOMPARE(parent->parentItem(), group); QCOMPARE(group->childItems().size(), 1); QCOMPARE(scene.items().size(), 4); QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 3); @@ -3574,12 +3602,13 @@ void tst_QGraphicsItem::group() QCOMPARE(parent2->group(), group); QCOMPARE(parent2->sceneBoundingRect(), parent2SceneBoundingRect); - QCOMPARE(parent2->parentItem(), (QGraphicsItem *)group); + QCOMPARE(parent2->parentItem(), group); QCOMPARE(group->childItems().size(), 2); QCOMPARE(scene.items().size(), 4); QCOMPARE(scene.items(group->sceneBoundingRect()).size(), 4); - QList<QGraphicsItem *> newItems; + GraphicsItems newItems; + newItems.reserve(100); for (int i = 0; i < 100; ++i) { QGraphicsItem *item = scene.addRect(QRectF(-25, -25, 50, 50), QPen(Qt::black, 0), QBrush(QColor(QRandomGenerator::global()->bounded(255), QRandomGenerator::global()->bounded(255), @@ -3592,7 +3621,7 @@ void tst_QGraphicsItem::group() view.fitInView(scene.itemsBoundingRect()); - foreach (QGraphicsItem *item, newItems) { + for (QGraphicsItem *item : qAsConst(newItems)) { group->addToGroup(item); QCOMPARE(item->group(), group); } @@ -3608,11 +3637,11 @@ void tst_QGraphicsItem::setGroup() QCOMPARE(rect->parentItem(), nullptr); rect->setGroup(&group1); QCOMPARE(rect->group(), &group1); - QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group1); + QCOMPARE(rect->parentItem(), &group1); rect->setGroup(&group2); QCOMPARE(rect->group(), &group2); - QCOMPARE(rect->parentItem(), (QGraphicsItem *)&group2); - rect->setGroup(0); + QCOMPARE(rect->parentItem(), &group2); + rect->setGroup(nullptr); QCOMPARE(rect->group(), nullptr); QCOMPARE(rect->parentItem(), nullptr); } @@ -3642,7 +3671,7 @@ void tst_QGraphicsItem::setGroup2() rect->setScale(0.8); oldSceneTransform = rect->sceneTransform(); - rect->setGroup(0); + rect->setGroup(nullptr); qFuzzyCompare(rect->sceneTransform(), oldSceneTransform); } @@ -3715,21 +3744,22 @@ void tst_QGraphicsItem::removeFromGroup() rect2->setSelected(true); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->processEvents(); // index items - qApp->processEvents(); // emit changed + QCoreApplication::processEvents(); // index items + QCoreApplication::processEvents(); // emit changed QGraphicsItemGroup *group = scene.createItemGroup(scene.selectedItems()); QVERIFY(group); QCOMPARE(group->childItems().size(), 2); - qApp->processEvents(); // index items - qApp->processEvents(); // emit changed + QCoreApplication::processEvents(); // index items + QCoreApplication::processEvents(); // emit changed scene.destroyItemGroup(group); // calls removeFromGroup. - qApp->processEvents(); // index items - qApp->processEvents(); // emit changed + QCoreApplication::processEvents(); // index items + QCoreApplication::processEvents(); // emit changed QCOMPARE(scene.items().size(), 2); QVERIFY(!rect1->group()); @@ -3739,20 +3769,18 @@ void tst_QGraphicsItem::removeFromGroup() class ChildEventTester : public QGraphicsRectItem { public: - ChildEventTester(const QRectF &rect, QGraphicsItem *parent = 0) - : QGraphicsRectItem(rect, parent), counter(0) - { } + using QGraphicsRectItem::QGraphicsRectItem; - int counter; + int counter = 0; protected: - void focusInEvent(QFocusEvent *event) + void focusInEvent(QFocusEvent *event) override { ++counter; QGraphicsRectItem::focusInEvent(event); } - void mousePressEvent(QGraphicsSceneMouseEvent *) + void mousePressEvent(QGraphicsSceneMouseEvent *) override { ++counter; } - void mouseMoveEvent(QGraphicsSceneMouseEvent *) + void mouseMoveEvent(QGraphicsSceneMouseEvent *) override { ++counter; } - void mouseReleaseEvent(QGraphicsSceneMouseEvent *) + void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override { ++counter; } }; @@ -3782,16 +3810,17 @@ void tst_QGraphicsItem::handlesChildEvents() scene.addItem(blue); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); // Pull out the items, closest item first QList<QGraphicsItem *> items = scene.items(scene.itemsBoundingRect()); - QCOMPARE(items.at(0), (QGraphicsItem *)yellow); - QCOMPARE(items.at(1), (QGraphicsItem *)gray); - QCOMPARE(items.at(2), (QGraphicsItem *)green); - QCOMPARE(items.at(3), (QGraphicsItem *)red); - QCOMPARE(items.at(4), (QGraphicsItem *)blue); + QCOMPARE(items.at(0), yellow); + QCOMPARE(items.at(1), gray); + QCOMPARE(items.at(2), green); + QCOMPARE(items.at(3), red); + QCOMPARE(items.at(4), blue); QCOMPARE(blue->counter, 0); @@ -3805,8 +3834,8 @@ void tst_QGraphicsItem::handlesChildEvents() releaseEvent.setButton(Qt::LeftButton); releaseEvent.setScenePos(blue->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 2); @@ -3815,8 +3844,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(red->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 2); QCOMPARE(red->counter, 2); @@ -3826,8 +3855,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(green->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 2); QCOMPARE(red->counter, 2); @@ -3840,8 +3869,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(red->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 4); QCOMPARE(red->counter, 2); @@ -3851,8 +3880,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(green->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 6); QCOMPARE(red->counter, 2); @@ -3865,8 +3894,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(red->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 6); QCOMPARE(red->counter, 4); @@ -3876,8 +3905,8 @@ void tst_QGraphicsItem::handlesChildEvents() pressEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); releaseEvent.setScenePos(green->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(releaseEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(blue->counter, 6); QCOMPARE(red->counter, 4); @@ -3905,13 +3934,14 @@ void tst_QGraphicsItem::handlesChildEvents2() scene.addItem(root); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QApplication::processEvents(); QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5), - view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); QTRY_COMPARE(root->counter, 1); } @@ -3920,9 +3950,9 @@ void tst_QGraphicsItem::handlesChildEvents3() { QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); - ChildEventTester *group2 = new ChildEventTester(QRectF(), 0); + ChildEventTester *group2 = new ChildEventTester(QRectF(), nullptr); ChildEventTester *group1 = new ChildEventTester(QRectF(), group2); ChildEventTester *leaf = new ChildEventTester(QRectF(), group1); scene.addItem(group2); @@ -3962,14 +3992,14 @@ void tst_QGraphicsItem::handlesChildEvents3() class ChildEventFilterTester : public ChildEventTester { public: - ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = 0) - : ChildEventTester(rect, parent), filter(QEvent::None) + ChildEventFilterTester(const QRectF &rect, QGraphicsItem *parent = nullptr) + : ChildEventTester(rect, parent) { } - QEvent::Type filter; + QEvent::Type filter = QEvent::None; protected: - bool sceneEventFilter(QGraphicsItem *item, QEvent *event) + bool sceneEventFilter(QGraphicsItem *item, QEvent *event) override { Q_UNUSED(item); if (event->type() == filter) { @@ -3994,6 +4024,7 @@ void tst_QGraphicsItem::filtersChildEvents() scene.addItem(root); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -4007,8 +4038,8 @@ void tst_QGraphicsItem::filtersChildEvents() releaseEvent.setButton(Qt::LeftButton); releaseEvent.setScenePos(QPointF(25, 25));//child->mapToScene(5, 5)); releaseEvent.setScreenPos(view.mapFromScene(pressEvent.scenePos())); - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QTRY_COMPARE(child->counter, 1); // mouse release is not filtered QCOMPARE(filter->counter, 1); // mouse press is filtered @@ -4019,8 +4050,8 @@ void tst_QGraphicsItem::filtersChildEvents() root->filter = QEvent::GraphicsSceneMouseRelease; // send event to child - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(child->counter, 1); QCOMPARE(filter->counter, 2); // mouse press is filtered @@ -4031,8 +4062,8 @@ void tst_QGraphicsItem::filtersChildEvents() child->setParentItem(parent); // send event to child - QApplication::sendEvent(&scene, &pressEvent); - QApplication::sendEvent(&scene, &releaseEvent); + QCoreApplication::sendEvent(&scene, &pressEvent); + QCoreApplication::sendEvent(&scene, &releaseEvent); QCOMPARE(child->counter, 2); // mouse press is _not_ filtered QCOMPARE(parent->counter, 0); @@ -4063,14 +4094,15 @@ void tst_QGraphicsItem::filtersChildEvents2() scene.addItem(root); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QApplication::processEvents(); QMouseEvent event(QEvent::MouseButtonPress, view.mapFromScene(5, 5), - view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + view.viewport()->mapToGlobal(view.mapFromScene(5, 5)), Qt::LeftButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); QTRY_COMPARE(root->counter, 1); QCOMPARE(child->counter, 0); @@ -4082,10 +4114,10 @@ void tst_QGraphicsItem::filtersChildEvents2() class CustomItem : public QGraphicsItem { public: - QRectF boundingRect() const + QRectF boundingRect() const override { return QRectF(-110, -110, 220, 220); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { for (int x = -100; x <= 100; x += 25) painter->drawLine(x, -100, x, 100); @@ -4111,6 +4143,7 @@ void tst_QGraphicsItem::ensureVisible() scene.addItem(item); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(300, 300); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -4198,37 +4231,37 @@ void tst_QGraphicsItem::cursor() QPoint item2Center = view.mapFromScene(item2->sceneBoundingRect().center()); { - QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.viewport()->cursor().shape(), viewportShape); { - QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.viewport()->cursor().shape(), item1->cursor().shape()); { - QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + QMouseEvent event(QEvent::MouseMove, item2Center, view.viewport()->mapToGlobal(item2Center), Qt::NoButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.viewport()->cursor().shape(), item2->cursor().shape()); { - QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + QMouseEvent event(QEvent::MouseMove, viewCenter, view.viewport()->mapToGlobal(viewCenter), Qt::NoButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.viewport()->cursor().shape(), viewportShape); item1->setEnabled(false); { - QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, 0, 0); - QApplication::sendEvent(view.viewport(), &event); + QMouseEvent event(QEvent::MouseMove, item1Center, view.viewport()->mapToGlobal(item1Center), Qt::NoButton, {}, {}); + QCoreApplication::sendEvent(view.viewport(), &event); } QCOMPARE(view.viewport()->cursor().shape(), viewportShape); @@ -4342,7 +4375,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem() QVERIFY(!text->openExternalLinks()); QVERIFY(text->textCursor().isNull()); QCOMPARE(text->defaultTextColor(), QPalette().color(QPalette::Text)); - QVERIFY(text->document() != 0); + QVERIFY(text->document() != nullptr); QCOMPARE(text->font(), QApplication::font()); QCOMPARE(text->textInteractionFlags(), Qt::TextInteractionFlags(Qt::NoTextInteraction)); QCOMPARE(text->textWidth(), -1.0); @@ -4358,12 +4391,12 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem() event.setScenePos(QPointF(1, 1)); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); event2.setScenePos(QPointF(11, 11)); event2.setButton(Qt::LeftButton); event2.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event2); + QCoreApplication::sendEvent(&scene, &event2); } QCOMPARE(text->pos(), QPointF(10, 10)); @@ -4379,7 +4412,7 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsTextItem() event2.setScenePos(QPointF(21, 21)); event2.setButton(Qt::LeftButton); event2.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event2); + QCoreApplication::sendEvent(&scene, &event2); } QCOMPARE(text->pos(), QPointF(20, 20)); // clicked on edge, item moved @@ -4420,15 +4453,16 @@ void tst_QGraphicsItem::defaultItemTest_QGraphicsEllipseItem() class ItemChangeTester : public QGraphicsRectItem { public: - ItemChangeTester() - { setFlag(ItemSendsGeometryChanges); clear(); } - ItemChangeTester(QGraphicsItem *parent) : QGraphicsRectItem(parent) - { setFlag(ItemSendsGeometryChanges); clear(); } + ItemChangeTester(QGraphicsItem *parent = nullptr) : QGraphicsRectItem(parent) + { + setFlag(ItemSendsGeometryChanges); + clear(); + } void clear() { itemChangeReturnValue = QVariant(); - itemSceneChangeTargetScene = 0; + itemSceneChangeTargetScene = nullptr; changes.clear(); values.clear(); oldValues.clear(); @@ -4437,11 +4471,11 @@ public: QVariant itemChangeReturnValue; QGraphicsScene *itemSceneChangeTargetScene; - QList<GraphicsItemChange> changes; - QList<QVariant> values; - QList<QVariant> oldValues; + QVector<GraphicsItemChange> changes; + QVariantList values; + QVariantList oldValues; protected: - QVariant itemChange(GraphicsItemChange change, const QVariant &value) + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override { changes << change; values << value; @@ -4560,7 +4594,7 @@ QT_WARNING_POP void tst_QGraphicsItem::itemChange() { ItemChangeTester tester; - tester.itemSceneChangeTargetScene = 0; + tester.itemSceneChangeTargetScene = nullptr; ItemChangeTester testerHelper; QVERIFY(tester.changes.isEmpty()); @@ -4578,7 +4612,7 @@ void tst_QGraphicsItem::itemChange() QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemEnabledHasChanged); QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(false)); QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true)); - QCOMPARE(tester.oldValues.last(), QVariant(true)); + QCOMPARE(tester.oldValues.constLast(), QVariant(true)); QCOMPARE(tester.isEnabled(), true); } #if QT_DEPRECATED_SINCE(5, 13) @@ -4594,10 +4628,10 @@ QT_WARNING_DISABLE_DEPRECATED // QDesktopWidget::screen() QCOMPARE(int(tester.changes.last()), int(QGraphicsItem::ItemTransformHasChanged)); QCOMPARE(qvariant_cast<QMatrix>(tester.values.at(tester.values.size() - 2)), QMatrix().translate(50, 0)); - QCOMPARE(tester.values.last(), QVariant(QTransform(QMatrix().rotate(90)))); + QCOMPARE(tester.values.constLast(), QVariant(QTransform(QMatrix().rotate(90)))); QVariant variant; variant.setValue<QMatrix>(QMatrix()); - QCOMPARE(tester.oldValues.last(), variant); + QCOMPARE(tester.oldValues.constLast(), variant); QCOMPARE(tester.matrix(), QMatrix().rotate(90)); QT_WARNING_POP } @@ -4621,7 +4655,7 @@ QT_WARNING_POP QTransform().rotate(90)); QVariant variant; variant.setValue<QTransform>(QTransform()); - QCOMPARE(tester.oldValues.last(), variant); + QCOMPARE(tester.oldValues.constLast(), variant); QCOMPARE(tester.transform(), QTransform().rotate(90)); } { @@ -4635,7 +4669,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemPositionHasChanged); QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(0, 42))); QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(42, 0))); - QCOMPARE(tester.oldValues.last(), QVariant(QPointF())); + QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF())); QCOMPARE(tester.pos(), QPointF(42, 0)); } { @@ -4649,7 +4683,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemZValueHasChanged); QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.0))); QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0))); - QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0))); + QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0))); QCOMPARE(tester.zValue(), qreal(2.0)); } { @@ -4663,7 +4697,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemRotationHasChanged); QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(10.0))); QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(15.0))); - QCOMPARE(tester.oldValues.last(), QVariant(qreal(0.0))); + QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(0.0))); QCOMPARE(tester.rotation(), qreal(15.0)); } { @@ -4677,7 +4711,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemScaleHasChanged); QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(qreal(1.5))); QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(qreal(2.0))); - QCOMPARE(tester.oldValues.last(), QVariant(qreal(1.0))); + QCOMPARE(tester.oldValues.constLast(), QVariant(qreal(1.0))); QCOMPARE(tester.scale(), qreal(2.0)); } { @@ -4691,7 +4725,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemTransformOriginPointHasChanged); QCOMPARE(tester.values.at(tester.changes.size() - 2), QVariant(QPointF(1.0, 1.0))); QCOMPARE(tester.values.at(tester.changes.size() - 1), QVariant(QPointF(2.0, 2.0))); - QCOMPARE(tester.oldValues.last(), QVariant(QPointF(0.0, 0.0))); + QCOMPARE(tester.oldValues.constLast(), QVariant(QPointF(0.0, 0.0))); QCOMPARE(tester.transformOriginPoint(), QPointF(2.0, 2.0)); } { @@ -4707,7 +4741,8 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemFlagsHaveChanged); QVariant expectedFlags = QVariant::fromValue<quint32>(QGraphicsItem::GraphicsItemFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges)); QCOMPARE(tester.values.at(tester.values.size() - 2), expectedFlags); - QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant::fromValue<quint32>((quint32)QGraphicsItem::ItemIsSelectable)); + QCOMPARE(tester.values.at(tester.values.size() - 1), + QVariant::fromValue<quint32>(quint32(QGraphicsItem::ItemIsSelectable))); } { // ItemSelectedChange @@ -4722,7 +4757,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSelectedHasChanged); QCOMPARE(tester.values.at(tester.values.size() - 2), QVariant(true)); QCOMPARE(tester.values.at(tester.values.size() - 1), QVariant(true)); - QCOMPARE(tester.oldValues.last(), QVariant(false)); + QCOMPARE(tester.oldValues.constLast(), QVariant(false)); QCOMPARE(tester.isSelected(), true); tester.itemChangeReturnValue = false; @@ -4754,11 +4789,11 @@ QT_WARNING_POP } { // ItemParentChange - tester.itemChangeReturnValue.setValue<QGraphicsItem *>(0); + tester.itemChangeReturnValue.setValue<QGraphicsItem *>(nullptr); tester.setParentItem(&testerHelper); QCOMPARE(tester.changes.size(), ++changeCount); - QCOMPARE(tester.changes.last(), QGraphicsItem::ItemParentChange); - QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); + QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemParentChange); + QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper); QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.oldValues.last()), nullptr); QCOMPARE(tester.parentItem(), nullptr); } @@ -4767,7 +4802,7 @@ QT_WARNING_POP tester.itemChangeReturnValue = 1.0; tester.setOpacity(0.7); QCOMPARE(tester.changes.size(), ++changeCount); - QCOMPARE(tester.changes.last(), QGraphicsItem::ItemOpacityChange); + QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemOpacityChange); QVERIFY(qFuzzyCompare(qreal(tester.values.last().toDouble()), qreal(0.7))); QCOMPARE(tester.oldValues.last().toDouble(), double(1.0)); QCOMPARE(tester.opacity(), qreal(1.0)); @@ -4785,19 +4820,19 @@ QT_WARNING_POP tester.itemChangeReturnValue.clear(); testerHelper.setParentItem(&tester); QCOMPARE(tester.changes.size(), ++changeCount); - QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildAddedChange); - QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); + QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildAddedChange); + QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper); } { // ItemChildRemovedChange 1 - testerHelper.setParentItem(0); + testerHelper.setParentItem(nullptr); QCOMPARE(tester.changes.size(), ++changeCount); - QCOMPARE(tester.changes.last(), QGraphicsItem::ItemChildRemovedChange); - QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), (QGraphicsItem *)&testerHelper); + QCOMPARE(tester.changes.constLast(), QGraphicsItem::ItemChildRemovedChange); + QCOMPARE(qvariant_cast<QGraphicsItem *>(tester.values.last()), &testerHelper); // ItemChildRemovedChange 1 ItemChangeTester *test = new ItemChangeTester; - test->itemSceneChangeTargetScene = 0; + test->itemSceneChangeTargetScene = nullptr; int count = 0; QGraphicsScene *scene = new QGraphicsScene; scene->addItem(test); @@ -4806,11 +4841,11 @@ QT_WARNING_POP QGraphicsRectItem *child = new QGraphicsRectItem(test); //We received ItemChildAddedChange QCOMPARE(test->changes.size(), ++count); - QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildAddedChange); + QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildAddedChange); delete child; - child = 0; + child = nullptr; QCOMPARE(test->changes.size(), ++count); - QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); + QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange); ItemChangeTester *childTester = new ItemChangeTester(test); //Changes contains all sceneHasChanged and so on, we don't want to test that @@ -4820,12 +4855,12 @@ QT_WARNING_POP child = new QGraphicsRectItem(childTester); //We received ItemChildAddedChange QCOMPARE(childTester->changes.size(), ++childCount); - QCOMPARE(childTester->changes.last(), QGraphicsItem::ItemChildAddedChange); + QCOMPARE(childTester->changes.constLast(), QGraphicsItem::ItemChildAddedChange); //Delete the child of the top level with all its children delete childTester; //Only one removal QCOMPARE(test->changes.size(), ++count); - QCOMPARE(test->changes.last(), QGraphicsItem::ItemChildRemovedChange); + QCOMPARE(test->changes.constLast(), QGraphicsItem::ItemChildRemovedChange); delete scene; } { @@ -4833,11 +4868,11 @@ QT_WARNING_POP ItemChangeTester parent; ItemChangeTester *child = new ItemChangeTester; child->setParentItem(&parent); - QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildAddedChange); - QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child); + QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildAddedChange); + QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child); delete child; - QCOMPARE(parent.changes.last(), QGraphicsItem::ItemChildRemovedChange); - QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), (QGraphicsItem *)child); + QCOMPARE(parent.changes.constLast(), QGraphicsItem::ItemChildRemovedChange); + QCOMPARE(qvariant_cast<QGraphicsItem *>(parent.values.last()), child); } { // !!! Note: If this test crashes because of double-deletion, there's @@ -4857,7 +4892,7 @@ QT_WARNING_POP // Item's old value was 0 // Item's current value is scene QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene); scene2.addItem(&tester); ++changeCount; // ItemSceneChange (0) was: (scene) ++changeCount; // ItemSceneHasChanged (0) @@ -4873,16 +4908,16 @@ QT_WARNING_POP // Item's last old value was scene // Item's last current value is 0 - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), (QGraphicsScene *)&scene); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 2)), &scene); QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.at(tester.oldValues.size() - 1)), nullptr); QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 4)), nullptr); QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), nullptr); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene2); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene2); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene2); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene2); // Item's last old value was 0 // Item's last current value is scene2 QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), nullptr); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), (QGraphicsScene *)&scene2); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.last()), &scene2); scene2.removeItem(&tester); ++changeCount; // ItemSceneChange (0) was: (scene2) @@ -4894,7 +4929,7 @@ QT_WARNING_POP QCOMPARE(tester.changes.at(tester.changes.size() - 1), QGraphicsItem::ItemSceneHasChanged); // Item's last old value was scene2 // Item's last current value is 0 - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), (QGraphicsScene *)&scene2); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.oldValues.last()), &scene2); QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), nullptr); QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), nullptr); @@ -4905,12 +4940,12 @@ QT_WARNING_POP ++changeCount; // ItemSceneHasChanged (scene) QCOMPARE(tester.values.size(), changeCount); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), (QGraphicsScene *)&scene2); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), (QGraphicsScene *)&scene); - QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), (QGraphicsScene *)&scene); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 3)), &scene2); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 2)), &scene); + QCOMPARE(qvariant_cast<QGraphicsScene *>(tester.values.at(tester.values.size() - 1)), &scene); QCOMPARE(tester.scene(), &scene); - tester.itemSceneChangeTargetScene = 0; + tester.itemSceneChangeTargetScene = nullptr; tester.itemChangeReturnValue = QVariant(); scene.removeItem(&tester); ++changeCount; // ItemSceneChange @@ -4938,23 +4973,20 @@ QT_WARNING_POP class EventFilterTesterItem : public QGraphicsLineItem { public: - QList<QEvent::Type> filteredEvents; - QList<QGraphicsItem *> filteredEventReceivers; - bool handlesSceneEvents; - - QList<QEvent::Type> receivedEvents; - - EventFilterTesterItem() : handlesSceneEvents(false) {} + QVector<QEvent::Type> filteredEvents; + GraphicsItems filteredEventReceivers; + QVector<QEvent::Type> receivedEvents; + bool handlesSceneEvents = false; protected: - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { filteredEvents << event->type(); filteredEventReceivers << watched; return handlesSceneEvents; } - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { return QGraphicsLineItem::sceneEvent(event); } @@ -4965,6 +4997,7 @@ void tst_QGraphicsItem::sceneEventFilter() QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -5066,16 +5099,16 @@ void tst_QGraphicsItem::prepareGeometryChange() class PaintTester : public QGraphicsRectItem { public: - PaintTester() : widget(NULL), painted(0) { setRect(QRectF(10, 10, 20, 20));} + PaintTester() { setRect(QRectF(10, 10, 20, 20));} - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w) + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *w) override { widget = w; painted++; } - QWidget* widget; - int painted; + QWidget *widget = nullptr; + int painted = 0; }; void tst_QGraphicsItem::paint() @@ -5086,6 +5119,7 @@ void tst_QGraphicsItem::paint() scene.addItem(&paintTester); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QApplication::processEvents(); @@ -5102,6 +5136,7 @@ void tst_QGraphicsItem::paint() QGraphicsScene scene2; QGraphicsView view2(&scene2); + view2.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view2.show(); QVERIFY(QTest::qWaitForWindowExposed(&view2)); QCoreApplication::processEvents(); // Process all queued paint events @@ -5135,194 +5170,194 @@ class HarakiriItem : public QGraphicsRectItem public: HarakiriItem(int harakiriPoint) : QGraphicsRectItem(QRectF(0, 0, 100, 100)), harakiri(harakiriPoint) - { dead = 0; } + { dead = false; } - static int dead; + static bool dead; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { QGraphicsRectItem::paint(painter, option, widget); if (harakiri == 0) { // delete unsupported since 4.5 /* - dead = 1; + dead = true; delete this; */ } } - void advance(int n) + void advance(int n) override { if (harakiri == 1 && n == 0) { // delete unsupported /* - dead = 1; + dead = true; delete this; */ } if (harakiri == 2 && n == 1) { - dead = 1; + dead = true; delete this; } } protected: #ifndef QT_NO_CONTEXTMENU - void contextMenuEvent(QGraphicsSceneContextMenuEvent *) + void contextMenuEvent(QGraphicsSceneContextMenuEvent *) override { if (harakiri == 3) { - dead = 1; + dead = true; delete this; } } #endif // QT_NO_CONTEXTMENU - void dragEnterEvent(QGraphicsSceneDragDropEvent *event) + void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override { // ?? QGraphicsRectItem::dragEnterEvent(event); } - void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) + void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override { // ?? QGraphicsRectItem::dragLeaveEvent(event); } - void dragMoveEvent(QGraphicsSceneDragDropEvent *event) + void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override { // ?? QGraphicsRectItem::dragMoveEvent(event); } - void dropEvent(QGraphicsSceneDragDropEvent *event) + void dropEvent(QGraphicsSceneDragDropEvent *event) override { // ?? QGraphicsRectItem::dropEvent(event); } - void focusInEvent(QFocusEvent *) + void focusInEvent(QFocusEvent *) override { if (harakiri == 4) { - dead = 1; + dead = true; delete this; } } - void focusOutEvent(QFocusEvent *) + void focusOutEvent(QFocusEvent *) override { if (harakiri == 5) { - dead = 1; + dead = true; delete this; } } - void hoverEnterEvent(QGraphicsSceneHoverEvent *) + void hoverEnterEvent(QGraphicsSceneHoverEvent *) override { if (harakiri == 6) { - dead = 1; + dead = true; delete this; } } - void hoverLeaveEvent(QGraphicsSceneHoverEvent *) + void hoverLeaveEvent(QGraphicsSceneHoverEvent *) override { if (harakiri == 7) { - dead = 1; + dead = true; delete this; } } - void hoverMoveEvent(QGraphicsSceneHoverEvent *) + void hoverMoveEvent(QGraphicsSceneHoverEvent *) override { if (harakiri == 8) { - dead = 1; + dead = true; delete this; } } - void inputMethodEvent(QInputMethodEvent *event) + void inputMethodEvent(QInputMethodEvent *event) override { // ?? QGraphicsRectItem::inputMethodEvent(event); } - QVariant inputMethodQuery(Qt::InputMethodQuery query) const + QVariant inputMethodQuery(Qt::InputMethodQuery query) const override { // ?? return QGraphicsRectItem::inputMethodQuery(query); } - QVariant itemChange(GraphicsItemChange change, const QVariant &value) + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override { // deletion not supported return QGraphicsRectItem::itemChange(change, value); } - void keyPressEvent(QKeyEvent *) + void keyPressEvent(QKeyEvent *) override { if (harakiri == 9) { - dead = 1; + dead = true; delete this; } } - void keyReleaseEvent(QKeyEvent *) + void keyReleaseEvent(QKeyEvent *) override { if (harakiri == 10) { - dead = 1; + dead = true; delete this; } } - void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) + void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) override { if (harakiri == 11) { - dead = 1; + dead = true; delete this; } } - void mouseMoveEvent(QGraphicsSceneMouseEvent *) + void mouseMoveEvent(QGraphicsSceneMouseEvent *) override { if (harakiri == 12) { - dead = 1; + dead = true; delete this; } } - void mousePressEvent(QGraphicsSceneMouseEvent *) + void mousePressEvent(QGraphicsSceneMouseEvent *) override { if (harakiri == 13) { - dead = 1; + dead = true; delete this; } } - void mouseReleaseEvent(QGraphicsSceneMouseEvent *) + void mouseReleaseEvent(QGraphicsSceneMouseEvent *) override { if (harakiri == 14) { - dead = 1; + dead = true; delete this; } } - bool sceneEvent(QEvent *event) + bool sceneEvent(QEvent *event) override { // deletion not supported return QGraphicsRectItem::sceneEvent(event); } - bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) + bool sceneEventFilter(QGraphicsItem *watched, QEvent *event) override { // deletion not supported return QGraphicsRectItem::sceneEventFilter(watched, event); } - void wheelEvent(QGraphicsSceneWheelEvent *) + void wheelEvent(QGraphicsSceneWheelEvent *) override { if (harakiri == 16) { - dead = 1; + dead = true; delete this; } } @@ -5331,7 +5366,7 @@ private: int harakiri; }; -int HarakiriItem::dead; +bool HarakiriItem::dead; void tst_QGraphicsItem::deleteItemInEventHandlers() { @@ -5346,44 +5381,45 @@ void tst_QGraphicsItem::deleteItemInEventHandlers() item->installSceneEventFilter(item); // <- ehey! QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - qApp->processEvents(); - qApp->processEvents(); + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); - if (!item->dead) + if (!HarakiriItem::dead) scene.advance(); #ifndef QT_NO_CONTEXTMENU - if (!item->dead) { + if (!HarakiriItem::dead) { QContextMenuEvent event(QContextMenuEvent::Other, view.mapFromScene(item->scenePos())); QCoreApplication::sendEvent(view.viewport(), &event); } #endif // QT_NO_CONTEXTMENU - if (!item->dead) + if (!HarakiriItem::dead) QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos())); - if (!item->dead) - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); - if (!item->dead) - QTest::mouseDClick(view.viewport(), Qt::LeftButton, 0, view.mapFromScene(item->scenePos())); - if (!item->dead) - QTest::mouseClick(view.viewport(), Qt::RightButton, 0, view.mapFromScene(item->scenePos())); - if (!item->dead) + if (!HarakiriItem::dead) + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos())); + if (!HarakiriItem::dead) + QTest::mouseDClick(view.viewport(), Qt::LeftButton, {}, view.mapFromScene(item->scenePos())); + if (!HarakiriItem::dead) + QTest::mouseClick(view.viewport(), Qt::RightButton, {}, view.mapFromScene(item->scenePos())); + if (!HarakiriItem::dead) QTest::mouseMove(view.viewport(), view.mapFromScene(item->scenePos() + QPointF(20, -20))); - if (!item->dead) + if (!HarakiriItem::dead) item->setFocus(); - if (!item->dead) + if (!HarakiriItem::dead) item->clearFocus(); - if (!item->dead) + if (!HarakiriItem::dead) item->setFocus(); - if (!item->dead) + if (!HarakiriItem::dead) QTest::keyPress(view.viewport(), Qt::Key_A); - if (!item->dead) + if (!HarakiriItem::dead) QTest::keyRelease(view.viewport(), Qt::Key_A); - if (!item->dead) + if (!HarakiriItem::dead) QTest::keyPress(view.viewport(), Qt::Key_A); - if (!item->dead) + if (!HarakiriItem::dead) QTest::keyRelease(view.viewport(), Qt::Key_A); } } @@ -5391,12 +5427,12 @@ void tst_QGraphicsItem::deleteItemInEventHandlers() class ItemPaintsOutsideShape : public QGraphicsItem { public: - QRectF boundingRect() const + QRectF boundingRect() const override { return QRectF(0, 0, 100, 100); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->fillRect(-50, -50, 200, 200, Qt::red); painter->fillRect(0, 0, 100, 100, Qt::blue); @@ -5492,16 +5528,16 @@ void tst_QGraphicsItem::itemClipsChildrenToShape2() QGraphicsScene scene; scene.addItem(parent); - QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), (QGraphicsItem *)parent); + QCOMPARE(scene.items(QPointF(5, 5)).value(0, nullptr), parent); QVERIFY(scene.items(QPointF(15, 5)).isEmpty()); QVERIFY(scene.items(QPointF(5, 15)).isEmpty()); QVERIFY(scene.items(QPointF(60, 60)).isEmpty()); QVERIFY(scene.items(QPointF(140, 60)).isEmpty()); QVERIFY(scene.items(QPointF(60, 140)).isEmpty()); QVERIFY(scene.items(QPointF(140, 140)).isEmpty()); - QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child2); - QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), (QGraphicsItem *)child1); - QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), (QGraphicsItem *)child1); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child2); + QCOMPARE(scene.items(QPointF(75, 100)).value(0, nullptr), child1); + QCOMPARE(scene.items(QPointF(100, 75)).value(0, nullptr), child1); QImage image(100, 100, QImage::Format_ARGB32_Premultiplied); image.fill(0); @@ -5536,9 +5572,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3() grandchild->setPos( 50, 50 ); parent->setFlag(QGraphicsItem::ItemClipsChildrenToShape); - QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)parent); - QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)child); - QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild); + QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), parent); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), child); + QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild); QVERIFY(scene.items(QPointF(175, 175)).isEmpty()); // Move child to fully overlap the parent. The grandchild should @@ -5546,26 +5582,24 @@ void tst_QGraphicsItem::itemClipsChildrenToShape3() child->prepareGeometryChange(); child->setPos( 0, 0 ); - QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), (QGraphicsItem *)child); - QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), (QGraphicsItem *)grandchild); - QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), (QGraphicsItem *)grandchild); + QCOMPARE(scene.items(QPointF(25, 25)).value(0, nullptr), child); + QCOMPARE(scene.items(QPointF(75, 75)).value(0, nullptr), grandchild); + QCOMPARE(scene.items(QPointF(125, 125)).value(0, nullptr), grandchild); QVERIFY(scene.items(QPointF(175, 175)).isEmpty()); } class MyProxyWidget : public QGraphicsProxyWidget { public: - MyProxyWidget(QGraphicsItem *parent) : QGraphicsProxyWidget(parent) - { - painted = false; - } + using QGraphicsProxyWidget::QGraphicsProxyWidget; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { QGraphicsProxyWidget::paint(painter, option, widget); painted = true; } - bool painted; + + bool painted = false; }; void tst_QGraphicsItem::itemClipsChildrenToShape4() @@ -5586,8 +5620,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape4() //now the label is shown outerWidget->setFlag(QGraphicsItem::ItemClipsChildrenToShape, false ); QApplication::setActiveWindow(&view); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); - QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); + QTRY_COMPARE(QApplication::activeWindow(), &view); QTRY_COMPARE(innerWidget->painted, true); } @@ -5610,10 +5645,9 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5() class ParentItem : public QGraphicsRectItem { public: - ParentItem(qreal x, qreal y, qreal width, qreal height) - : QGraphicsRectItem(x, y, width, height) {} + using QGraphicsRectItem::QGraphicsRectItem; - QPainterPath shape() const + QPainterPath shape() const override { QPainterPath path; path.addRect(50, 50, 200, 200); @@ -5668,12 +5702,12 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5() bottomRightChild->setPos(200, 200); childRegion += QRect(200, 200, 100, 100); - QPoint controlPoints[17] = { - QPoint(5, 5) , QPoint(95, 5) , QPoint(205, 5) , QPoint(295, 5) , - QPoint(5, 95) , QPoint(95, 95) , QPoint(205, 95) , QPoint(295, 95) , - QPoint(150, 150), - QPoint(5, 205), QPoint(95, 205), QPoint(205, 205), QPoint(295, 205), - QPoint(5, 295), QPoint(95, 295), QPoint(205, 295), QPoint(295, 295), + const QPoint controlPoints[17] = { + {5, 5}, {95, 5}, {205, 5}, {295, 5}, + {5, 95}, {95, 95}, {205, 95}, {295, 95}, + {150, 150}, + {5, 205}, {95, 205}, {205, 205}, {295, 205}, + {5, 295}, {95, 295}, {205, 295}, {295, 295}, }; const QRegion clippedChildRegion = childRegion & QRect(50, 50, 200, 200); @@ -5684,8 +5718,7 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5() QImage sceneImage(300, 300, QImage::Format_ARGB32); #define VERIFY_CONTROL_POINTS(pRegion, cRegion, gRegion) \ - for (int i = 0; i < 17; ++i) { \ - QPoint controlPoint = controlPoints[i]; \ + for (const QPoint &controlPoint : controlPoints) { \ QRgb pixel = sceneImage.pixel(controlPoint.x(), controlPoint.y()); \ if (pRegion.contains(controlPoint)) \ QVERIFY(qBlue(pixel) != 0); \ @@ -5711,13 +5744,13 @@ void tst_QGraphicsItem::itemClipsChildrenToShape5() case 0: // All children stacked in front. childString = QLatin1String("ChildrenInFront.png"); - foreach (QGraphicsItem *child, children) + for (QGraphicsItem *child : children) child->setFlag(QGraphicsItem::ItemStacksBehindParent, false); break; case 1: // All children stacked behind. childString = QLatin1String("ChildrenBehind.png"); - foreach (QGraphicsItem *child, children) + for (QGraphicsItem *child : children) child->setFlag(QGraphicsItem::ItemStacksBehindParent, true); break; case 2: @@ -5821,8 +5854,8 @@ void tst_QGraphicsItem::itemClippingDiscovery() rightRectItem->setParentItem(clipItem); // The rects item are both visible at these points. - QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), (QGraphicsItem *)leftRectItem); - QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), (QGraphicsItem *)rightRectItem); + QCOMPARE(scene.items(QPointF(10, 10)).value(0, nullptr), leftRectItem); + QCOMPARE(scene.items(QPointF(90, 90)).value(0, nullptr), rightRectItem); // The ellipse clips the rects now. clipItem->setFlag(QGraphicsItem::ItemClipsChildrenToShape); @@ -5837,13 +5870,15 @@ void tst_QGraphicsItem::itemClippingDiscovery() class ItemCountsBoundingRectCalls : public QGraphicsRectItem { public: - ItemCountsBoundingRectCalls(const QRectF & rect, QGraphicsItem *parent = 0) - : QGraphicsRectItem(rect, parent), boundingRectCalls(0) {} - QRectF boundingRect () const { + using QGraphicsRectItem::QGraphicsRectItem; + + QRectF boundingRect () const override + { ++boundingRectCalls; return QGraphicsRectItem::boundingRect(); } - mutable int boundingRectCalls; + + mutable int boundingRectCalls = 0; }; void tst_QGraphicsItem::itemContainsChildrenInShape() @@ -6006,7 +6041,7 @@ void tst_QGraphicsItem::ancestorFlags() QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); // Reparent the child to root - level21->setParentItem(0); + level21->setParentItem(nullptr); QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); QCOMPARE(int(level31->d_ptr->ancestorFlags), 1); @@ -6030,7 +6065,7 @@ void tst_QGraphicsItem::ancestorFlags() QCOMPARE(int(level32->d_ptr->ancestorFlags), 1); // Reparenting level31 back to level21. - level31->setParentItem(0); + level31->setParentItem(nullptr); QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); level31->setParentItem(level21); QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); @@ -6069,7 +6104,6 @@ void tst_QGraphicsItem::ancestorFlags() break; default: qFatal("Unknown ancestor flag, please fix!"); - break; } QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); @@ -6136,7 +6170,7 @@ void tst_QGraphicsItem::ancestorFlags() QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); // Reparent the child to root - level21->setParentItem(0); + level21->setParentItem(nullptr); QCOMPARE(int(level21->d_ptr->ancestorFlags), 0); QCOMPARE(int(level22->d_ptr->ancestorFlags), 0); QCOMPARE(int(level31->d_ptr->ancestorFlags), ancestorFlag); @@ -6160,7 +6194,7 @@ void tst_QGraphicsItem::ancestorFlags() QCOMPARE(int(level32->d_ptr->ancestorFlags), ancestorFlag); // Reparenting level31 back to level21. - level31->setParentItem(0); + level31->setParentItem(nullptr); QCOMPARE(int(level31->d_ptr->ancestorFlags), 0); level31->setParentItem(level21); QCOMPARE(int(level1->d_ptr->ancestorFlags), 0); @@ -6191,28 +6225,29 @@ void tst_QGraphicsItem::ancestorFlags() void tst_QGraphicsItem::untransformable() { - QGraphicsItem *item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); + auto item1 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); item1->setZValue(1); item1->setFlag(QGraphicsItem::ItemIgnoresTransformations); item1->setTransform(QTransform().rotate(45), true); - ((QGraphicsEllipseItem *)item1)->setBrush(Qt::red); + item1->setBrush(Qt::red); - QGraphicsItem *item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); + auto item2 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); item2->setParentItem(item1); item2->setTransform(QTransform().rotate(45), true); item2->setPos(100, 0); - ((QGraphicsEllipseItem *)item2)->setBrush(Qt::green); + item2->setBrush(Qt::green); - QGraphicsItem *item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); + auto item3 = new QGraphicsEllipseItem(QRectF(-50, -50, 100, 100)); item3->setParentItem(item2); item3->setPos(100, 0); - ((QGraphicsEllipseItem *)item3)->setBrush(Qt::blue); + item3->setBrush(Qt::blue); QGraphicsScene scene(-500, -500, 1000, 1000); scene.addItem(item1); QWidget topLevel; QGraphicsView view(&scene,&topLevel); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.resize(300, 300); topLevel.show(); view.scale(8, 8); @@ -6257,14 +6292,14 @@ void tst_QGraphicsItem::untransformable() class ContextMenuItem : public QGraphicsRectItem { public: - ContextMenuItem() - : ignoreEvent(true), gotEvent(false), eventWasAccepted(false) - { } - bool ignoreEvent; - bool gotEvent; - bool eventWasAccepted; + using QGraphicsRectItem::QGraphicsRectItem; + + bool ignoreEvent = true; + bool gotEvent = false; + bool eventWasAccepted = false; + protected: - void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override { gotEvent = true; eventWasAccepted = event->isAccepted(); @@ -6284,6 +6319,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation() QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setAlignment(Qt::AlignLeft | Qt::AlignTop); view.show(); view.resize(200, 200); @@ -6292,14 +6328,14 @@ void tst_QGraphicsItem::contextMenuEventPropagation() QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(10, 10), view.viewport()->mapToGlobal(QPoint(10, 10))); event.ignore(); - QApplication::sendEvent(view.viewport(), &event); + QCoreApplication::sendEvent(view.viewport(), &event); QVERIFY(!event.isAccepted()); scene.addItem(bottomItem); topItem->ignoreEvent = true; bottomItem->ignoreEvent = true; - QApplication::sendEvent(view.viewport(), &event); + QCoreApplication::sendEvent(view.viewport(), &event); QVERIFY(!event.isAccepted()); QCOMPARE(topItem->gotEvent, true); QCOMPARE(topItem->eventWasAccepted, true); @@ -6310,7 +6346,7 @@ void tst_QGraphicsItem::contextMenuEventPropagation() topItem->gotEvent = false; bottomItem->gotEvent = false; - QApplication::sendEvent(view.viewport(), &event); + QCoreApplication::sendEvent(view.viewport(), &event); QVERIFY(event.isAccepted()); QCOMPARE(topItem->gotEvent, true); QCOMPARE(bottomItem->gotEvent, false); @@ -6330,34 +6366,34 @@ void tst_QGraphicsItem::itemIsMovable() QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QCOMPARE(rect->pos(), QPointF(0, 0)); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setButtons(Qt::LeftButton); event.setScenePos(QPointF(10, 10)); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QCOMPARE(rect->pos(), QPointF(10, 10)); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setButtons(Qt::RightButton); event.setScenePos(QPointF(20, 20)); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QCOMPARE(rect->pos(), QPointF(10, 10)); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseMove); event.setButtons(Qt::LeftButton); event.setScenePos(QPointF(30, 30)); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } QCOMPARE(rect->pos(), QPointF(30, 30)); } @@ -6368,14 +6404,14 @@ class ItemAddScene : public QGraphicsScene public: ItemAddScene() { - QTimer::singleShot(500, this, SLOT(newTextItem())); + QTimer::singleShot(500, this, &ItemAddScene::newTextItem); } public slots: void newTextItem() { // Add a text item - QGraphicsItem *item = new QGraphicsTextItem("This item will not ensure that it's visible", 0); + QGraphicsItem *item = addText("This item will not ensure that it's visible"); item->setPos(.0, .0); item->show(); } @@ -6387,6 +6423,7 @@ void tst_QGraphicsItem::task141694_textItemEnsureVisible() scene.setSceneRect(-1000, -1000, 2000, 2000); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(200, 200); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -6414,6 +6451,7 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable() scene.addItem(item); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFixedSize(200, 200); view.show(); @@ -6421,14 +6459,14 @@ void tst_QGraphicsItem::task128696_textItemEnsureMovable() event1.setScenePos(QPointF(0, 0)); event1.setButton(Qt::LeftButton); event1.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCoreApplication::sendEvent(&scene, &event1); + QCOMPARE(scene.mouseGrabberItem(), item); QGraphicsSceneMouseEvent event2(QEvent::GraphicsSceneMouseMove); event2.setScenePos(QPointF(10, 10)); event2.setButton(Qt::LeftButton); event2.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event2); + QCoreApplication::sendEvent(&scene, &event2); QCOMPARE(item->pos(), QPointF(10, 10)); } @@ -6447,33 +6485,45 @@ void tst_QGraphicsItem::task177918_lineItemUndetected() void tst_QGraphicsItem::task240400_clickOnTextItem_data() { - QTest::addColumn<int>("flags"); - QTest::addColumn<int>("textFlags"); - QTest::newRow("editor, noflags") << 0 << int(Qt::TextEditorInteraction); - QTest::newRow("editor, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::TextEditorInteraction); - QTest::newRow("editor, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::TextEditorInteraction); - QTest::newRow("editor, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) - << int(Qt::TextEditorInteraction); - QTest::newRow("noninteractive, noflags") << 0 << int(Qt::NoTextInteraction); - QTest::newRow("noninteractive, movable") << int(QGraphicsItem::ItemIsMovable) << int(Qt::NoTextInteraction); - QTest::newRow("noninteractive, selectable") << int(QGraphicsItem::ItemIsSelectable) << int(Qt::NoTextInteraction); - QTest::newRow("noninteractive, movable | selectable") << int(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) - << int(Qt::NoTextInteraction); + using Flags = QGraphicsItem::GraphicsItemFlags; + QTest::addColumn<Flags>("flags"); + QTest::addColumn<Qt::TextInteractionFlags>("textFlags"); + QTest::newRow("editor, noflags") + << Flags{} + << Qt::TextInteractionFlags(Qt::TextEditorInteraction); + QTest::newRow("editor, movable") + << Flags(QGraphicsItem::ItemIsMovable) + << Qt::TextInteractionFlags(Qt::TextEditorInteraction); + QTest::newRow("editor, selectable") + << Flags(QGraphicsItem::ItemIsSelectable) + << Qt::TextInteractionFlags(Qt::TextEditorInteraction); + QTest::newRow("editor, movable | selectable") + << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) + << Qt::TextInteractionFlags(Qt::TextEditorInteraction); + QTest::newRow("noninteractive, noflags") + << Flags{} << Qt::TextInteractionFlags(Qt::NoTextInteraction); + QTest::newRow("noninteractive, movable") + << Flags(QGraphicsItem::ItemIsMovable) << Qt::TextInteractionFlags(Qt::NoTextInteraction); + QTest::newRow("noninteractive, selectable") + << Flags(QGraphicsItem::ItemIsSelectable) << Qt::TextInteractionFlags(Qt::NoTextInteraction); + QTest::newRow("noninteractive, movable | selectable") + << Flags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable) + << Qt::TextInteractionFlags(Qt::NoTextInteraction); } void tst_QGraphicsItem::task240400_clickOnTextItem() { - QFETCH(int, flags); - QFETCH(int, textFlags); + QFETCH(QGraphicsItem::GraphicsItemFlags, flags); + QFETCH(Qt::TextInteractionFlags, textFlags); QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QGraphicsTextItem *item = scene.addText("Hello"); - item->setFlags(QGraphicsItem::GraphicsItemFlags(flags)); - item->setTextInteractionFlags(Qt::TextInteractionFlags(textFlags)); - bool focusable = (item->flags() & QGraphicsItem::ItemIsFocusable); + item->setFlags(flags); + item->setTextInteractionFlags(textFlags); + const bool focusable = item->flags().testFlag(QGraphicsItem::ItemIsFocusable); QVERIFY(textFlags ? focusable : !focusable); int column = item->textCursor().columnNumber(); @@ -6487,25 +6537,25 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1)); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } if (flags || textFlags) - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCOMPARE(scene.mouseGrabberItem(), item); else QCOMPARE(scene.mouseGrabberItem(), nullptr); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(item->sceneBoundingRect().topLeft() + QPointF(0.1, 0.1)); event.setButton(Qt::LeftButton); - event.setButtons(0); - QApplication::sendEvent(&scene, &event); + event.setButtons({}); + QCoreApplication::sendEvent(&scene, &event); } if (textFlags) QVERIFY(item->hasFocus()); else QVERIFY(!item->hasFocus()); QVERIFY(!scene.mouseGrabberItem()); - bool selectable = (flags & QGraphicsItem::ItemIsSelectable); + bool selectable = flags.testFlag(QGraphicsItem::ItemIsSelectable); QVERIFY(selectable ? item->isSelected() : !item->isSelected()); // Now click in the middle and check that the cursor moved. @@ -6514,18 +6564,18 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() event.setScenePos(item->sceneBoundingRect().center()); event.setButton(Qt::LeftButton); event.setButtons(Qt::LeftButton); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); } if (flags || textFlags) - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *)item); + QCOMPARE(scene.mouseGrabberItem(), item); else QCOMPARE(scene.mouseGrabberItem(), nullptr); { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMouseRelease); event.setScenePos(item->sceneBoundingRect().center()); event.setButton(Qt::LeftButton); - event.setButtons(0); - QApplication::sendEvent(&scene, &event); + event.setButtons({}); + QCoreApplication::sendEvent(&scene, &event); } if (textFlags) QVERIFY(item->hasFocus()); @@ -6536,7 +6586,7 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() QVERIFY(selectable ? item->isSelected() : !item->isSelected()); // - if (textFlags & Qt::TextEditorInteraction) + if (textFlags.testFlag(Qt::TextEditorInteraction)) QVERIFY(item->textCursor().columnNumber() > column); else QCOMPARE(item->textCursor().columnNumber(), 0); @@ -6545,24 +6595,22 @@ void tst_QGraphicsItem::task240400_clickOnTextItem() class TextItem : public QGraphicsSimpleTextItem { public: - TextItem(const QString& text) : QGraphicsSimpleTextItem(text) - { - updates = 0; - } + using QGraphicsSimpleTextItem::QGraphicsSimpleTextItem; - void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) + void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) override { updates++; QGraphicsSimpleTextItem::paint(painter, option, widget); } - int updates; + int updates = 0; }; void tst_QGraphicsItem::ensureUpdateOnTextItem() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -6836,6 +6884,7 @@ void tst_QGraphicsItem::opacity2() scene.addItem(parent); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -6910,6 +6959,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() scene.addItem(parent); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -6939,18 +6989,18 @@ void tst_QGraphicsItem::opacityZeroUpdates() class StacksBehindParentHelper : public QGraphicsRectItem { public: - StacksBehindParentHelper(QList<QGraphicsItem *> *paintedItems, const QRectF &rect, QGraphicsItem *parent = 0) - : QGraphicsRectItem(rect, parent), paintedItems(paintedItems) + StacksBehindParentHelper(GraphicsItems *paintedItems, const QRectF &rect, QGraphicsItem *parent = nullptr) + : QGraphicsRectItem(rect, parent), m_paintedItems(paintedItems) { } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override { QGraphicsRectItem::paint(painter, option, widget); - paintedItems->append(this); + m_paintedItems->append(this); } private: - QList<QGraphicsItem *> *paintedItems; + GraphicsItems *m_paintedItems; }; void tst_QGraphicsItem::itemStacksBehindParent() @@ -6988,6 +7038,7 @@ void tst_QGraphicsItem::itemStacksBehindParent() scene.addItem(parent2); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(!paintedItems.isEmpty()); @@ -6995,55 +7046,47 @@ void tst_QGraphicsItem::itemStacksBehindParent() view.viewport()->update(); QApplication::processEvents(); QRectF rect(0, 0, 100, 100); - QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() - << grandChild111 << child11 - << grandChild121 << child12 << parent1 - << grandChild211 << child21 - << grandChild221 << child22 << parent2)); - QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() - << parent2 << child22 << grandChild221 - << child21 << grandChild211 - << parent1 << child12 << grandChild121 - << child11 << grandChild111); + const GraphicsItemsList expected1{grandChild111, child11, grandChild121, child12, parent1, + grandChild211, child21, grandChild221, child22, parent2}; + QTRY_COMPARE(scene.items(rect), expected1); + + const GraphicsItems expected2{parent2, child22, grandChild221, child21, grandChild211, + parent1, child12, grandChild121, child11, grandChild111}; + QTRY_COMPARE(paintedItems, expected2); child11->setFlag(QGraphicsItem::ItemStacksBehindParent); scene.update(); paintedItems.clear(); - QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() - << grandChild121 << child12 << parent1 - << grandChild111 << child11 - << grandChild211 << child21 - << grandChild221 << child22 << parent2)); - QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() - << parent2 << child22 << grandChild221 - << child21 << grandChild211 - << child11 << grandChild111 - << parent1 << child12 << grandChild121); + const GraphicsItemsList expected3{grandChild121, child12, parent1, grandChild111, child11, + grandChild211, child21, grandChild221, child22, parent2}; + + QTRY_COMPARE(scene.items(rect), expected3); + const GraphicsItems expected4{parent2, child22, grandChild221, child21, grandChild211, child11, grandChild111, + parent1, child12, grandChild121}; + QTRY_COMPARE(paintedItems, expected4); child12->setFlag(QGraphicsItem::ItemStacksBehindParent); paintedItems.clear(); scene.update(); - QTRY_COMPARE(scene.items(rect), (QList<QGraphicsItem *>() - << parent1 << grandChild111 << child11 - << grandChild121 << child12 - << grandChild211 << child21 - << grandChild221 << child22 << parent2)); - QTRY_COMPARE(paintedItems, QList<QGraphicsItem *>() - << parent2 << child22 << grandChild221 - << child21 << grandChild211 - << child12 << grandChild121 - << child11 << grandChild111 << parent1); + const GraphicsItemsList expected5{parent1, grandChild111, child11, grandChild121, child12, + grandChild211, child21, grandChild221, child22, parent2}; + QTRY_COMPARE(scene.items(rect), expected5); + + const GraphicsItems expected6{parent2, child22, grandChild221, child21, grandChild211, + child12, grandChild121, child11, grandChild111, parent1}; + QTRY_COMPARE(paintedItems, expected6); } class ClippingAndTransformsScene : public QGraphicsScene { + Q_OBJECT public: - QList<QGraphicsItem *> drawnItems; + GraphicsItems drawnItems; protected: void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], - const QStyleOptionGraphicsItem options[], QWidget *widget = 0) + const QStyleOptionGraphicsItem options[], QWidget *widget = nullptr) override { drawnItems.clear(); for (int i = 0; i < numItems; ++i) @@ -7084,11 +7127,11 @@ void tst_QGraphicsItem::nestedClipping() QGraphicsView view(&scene); view.setOptimizationFlag(QGraphicsView::IndirectPainting); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QList<QGraphicsItem *> expected; - expected << root << l1 << l2 << l3; + GraphicsItems expected{root, l1, l2, l3}; QTRY_COMPARE(scene.drawnItems, expected); QImage image(200, 200, QImage::Format_ARGB32_Premultiplied); @@ -7126,7 +7169,7 @@ public: QTransform x; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, - QWidget *widget = 0) + QWidget *widget = nullptr) override { x = painter->worldTransform(); QGraphicsRectItem::paint(painter, option, widget); @@ -7195,6 +7238,7 @@ void tst_QGraphicsItem::sceneTransformCache() rect2->setTransform(QTransform().rotate(90), true); rect->setTransform(QTransform::fromTranslate(0, 50), true); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); rect->setTransform(QTransform::fromTranslate(0, 100), true); @@ -7271,6 +7315,7 @@ void tst_QGraphicsItem::tabChangesFocus() layout->addWidget(dial2); QWidget widget; + widget.setWindowTitle(QLatin1String(QTest::currentTestFunction())); widget.setLayout(layout); widget.show(); QVERIFY(QTest::qWaitForWindowActive(&widget)); @@ -7301,6 +7346,7 @@ void tst_QGraphicsItem::cacheMode() { QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.resize(150, 150); view.show(); QApplication::setActiveWindow(&view); @@ -7481,6 +7527,7 @@ void tst_QGraphicsItem::cacheMode2() { QGraphicsScene scene(0, 0, 100, 100); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.resize(150, 150); view.show(); QApplication::setActiveWindow(&view); @@ -7552,6 +7599,7 @@ void tst_QGraphicsItem::updateCachedItemAfterMove() QGraphicsScene scene; scene.addItem(tester); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -7589,7 +7637,7 @@ public: setAcceptHoverEvents(true); } - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override { QGraphicsRectItem::paint(painter, option, widget); const QString text = QString::number(p.x()) + QLatin1Char('x') + QString::number(p.y()) @@ -7598,7 +7646,7 @@ public: } protected: - void hoverMoveEvent(QGraphicsSceneHoverEvent *event) + void hoverMoveEvent(QGraphicsSceneHoverEvent *event) override { p = event->pos(); sp = event->widget()->mapFromGlobal(event->screenPos()); @@ -7695,6 +7743,7 @@ void tst_QGraphicsItem::update() QGraphicsScene scene; scene.setSceneRect(-100, -100, 200, 200); QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); MyGraphicsView view(&scene,&topLevel); topLevel.resize(300, 300); @@ -7732,7 +7781,7 @@ void tst_QGraphicsItem::update() view.reset(); item->repaints = 0; item->update(-15, -15, 5, 5); // Item's brect: (-10, -10, 20, 20) - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 0); @@ -7741,7 +7790,7 @@ void tst_QGraphicsItem::update() item->repaints = 0; item->update(); // Full update; all sub-sequent update requests are discarded. item->hide(); // visible set to 0. ignoreVisible must be set to 1; the item won't be processed otherwise. - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 1); // The entire item's bounding rect (adjusted for antialiasing) should have been painted. @@ -7751,7 +7800,7 @@ void tst_QGraphicsItem::update() view.reset(); item->repaints = 0; item->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); // The entire item's bounding rect (adjusted for antialiasing) should have been painted. @@ -7759,21 +7808,21 @@ void tst_QGraphicsItem::update() item->repaints = 0; item->hide(); - qApp->processEvents(); + QCoreApplication::processEvents(); view.reset(); const QPointF originalPos = item->pos(); item->setPos(5000, 5000); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 0); - qApp->processEvents(); + QCoreApplication::processEvents(); item->setPos(originalPos); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 0); item->show(); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); // The entire item's bounding rect (adjusted for antialiasing) should have been painted. @@ -7804,14 +7853,14 @@ void tst_QGraphicsItem::update() view.reset(); item->repaints = 0; parent->setTransform(QTransform::fromTranslate(-400, 0), true); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 0); QCOMPARE(view.repaints, 1); QCOMPARE(view.paintedRegion, expectedRegion); view.reset(); item->repaints = 0; parent->setTransform(QTransform::fromTranslate(400, 0), true); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); QCOMPARE(view.paintedRegion, expectedRegion); @@ -7933,11 +7982,9 @@ void tst_QGraphicsItem::setTransformProperties() class MyStyleOptionTester : public QGraphicsRectItem { public: - MyStyleOptionTester(const QRectF &rect) - : QGraphicsRectItem(rect), startTrack(false) - {} + using QGraphicsRectItem::QGraphicsRectItem; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override { ++repaints; if (startTrack) { @@ -7953,7 +8000,7 @@ public: } QGraphicsRectItem::paint(painter, option, widget); } - bool startTrack; + bool startTrack = false; int repaints = 0; }; @@ -7971,6 +8018,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption() scene.addItem(rect); rect->setPos(200, 200); QWidget topLevel; + topLevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); topLevel.resize(200, 200); QGraphicsView view(&scene, &topLevel); topLevel.setWindowFlags(Qt::X11BypassWindowManagerHint); @@ -7998,7 +8046,7 @@ void tst_QGraphicsItem::itemUsesExtendedStyleOption() void tst_QGraphicsItem::itemSendsGeometryChanges() { ItemChangeTester item; - item.setFlags(0); + item.setFlags(nullptr); item.clear(); QTransform x = QTransform().rotate(45); @@ -8038,21 +8086,21 @@ void tst_QGraphicsItem::itemSendsGeometryChanges() QCOMPARE(item.scale(), qreal(1.0)); QCOMPARE(item.transformOriginPoint(), QPointF(0.0, 0.0)); - QCOMPARE(item.changes, QList<QGraphicsItem::GraphicsItemChange>() - << QGraphicsItem::ItemOpacityChange - << QGraphicsItem::ItemOpacityHasChanged - << QGraphicsItem::ItemFlagsChange - << QGraphicsItem::ItemFlagsHaveChanged - << QGraphicsItem::ItemTransformChange - << QGraphicsItem::ItemTransformHasChanged - << QGraphicsItem::ItemPositionChange - << QGraphicsItem::ItemPositionHasChanged - << QGraphicsItem::ItemRotationChange - << QGraphicsItem::ItemRotationHasChanged - << QGraphicsItem::ItemScaleChange - << QGraphicsItem::ItemScaleHasChanged - << QGraphicsItem::ItemTransformOriginPointChange - << QGraphicsItem::ItemTransformOriginPointHasChanged); + const QVector<QGraphicsItem::GraphicsItemChange> expected{QGraphicsItem::ItemOpacityChange, + QGraphicsItem::ItemOpacityHasChanged, + QGraphicsItem::ItemFlagsChange, + QGraphicsItem::ItemFlagsHaveChanged, + QGraphicsItem::ItemTransformChange, + QGraphicsItem::ItemTransformHasChanged, + QGraphicsItem::ItemPositionChange, + QGraphicsItem::ItemPositionHasChanged, + QGraphicsItem::ItemRotationChange, + QGraphicsItem::ItemRotationHasChanged, + QGraphicsItem::ItemScaleChange, + QGraphicsItem::ItemScaleHasChanged, + QGraphicsItem::ItemTransformOriginPointChange, + QGraphicsItem::ItemTransformOriginPointHasChanged}; + QCOMPARE(item.changes, expected); } // Make sure we update moved items correctly. @@ -8062,6 +8110,7 @@ void tst_QGraphicsItem::moveItem() scene.setSceneRect(-50, -50, 200, 200); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QCoreApplication::processEvents(); // Process all queued paint events @@ -8088,7 +8137,7 @@ void tst_QGraphicsItem::moveItem() .adjusted(-2, -2, 2, 2); // Adjusted for antialiasing. parent->setPos(20, 20); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(parent->repaints, 1); QCOMPARE(view.repaints, 1); QRegion expectedParentRegion = parentDeviceBoundingRect; // old position @@ -8099,7 +8148,7 @@ void tst_QGraphicsItem::moveItem() RESET_COUNTERS child->setPos(20, 20); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); QCOMPARE(view.repaints, 1); @@ -8109,7 +8158,7 @@ void tst_QGraphicsItem::moveItem() RESET_COUNTERS grandChild->setPos(20, 20); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); QCOMPARE(grandChild->repaints, 1); @@ -8120,7 +8169,7 @@ void tst_QGraphicsItem::moveItem() RESET_COUNTERS parent->setTransform(QTransform::fromTranslate(20, 20), true); - qApp->processEvents(); + QCoreApplication::processEvents(); QCOMPARE(parent->repaints, 1); QCOMPARE(child->repaints, 1); QCOMPARE(grandChild->repaints, 1); @@ -8140,6 +8189,7 @@ void tst_QGraphicsItem::moveLineItem() scene.addItem(item); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -8148,9 +8198,9 @@ void tst_QGraphicsItem::moveLineItem() QRectF brect = item->boundingRect(); // Do same adjustments as in qgraphicsscene.cpp - if (!brect.width()) + if (qFuzzyIsNull(brect.width())) brect.adjust(qreal(-0.00001), 0, qreal(0.00001), 0); - if (!brect.height()) + if (qFuzzyIsNull(brect.height())) brect.adjust(0, qreal(-0.00001), 0, qreal(0.00001)); const QRect itemDeviceBoundingRect = item->deviceTransform(view.viewportTransform()) .mapRect(brect).toAlignedRect(); @@ -8206,6 +8256,7 @@ void tst_QGraphicsItem::sorting() scene.addItem(item2); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); // Use Qt::Tool as fully decorated windows have a minimum width of 160 on Windows. view.setWindowFlags(view.windowFlags() | Qt::Tool); view.setResizeAnchor(QGraphicsView::NoAnchor); @@ -8227,13 +8278,13 @@ void tst_QGraphicsItem::sorting() QTest::qWait(100); #endif - QCOMPARE(_paintedItems, QList<QGraphicsItem *>() - << grid[0][0] << grid[0][1] << grid[0][2] << grid[0][3] - << grid[1][0] << grid[1][1] << grid[1][2] << grid[1][3] - << grid[2][0] << grid[2][1] << grid[2][2] << grid[2][3] - << grid[3][0] << grid[3][1] << grid[3][2] << grid[3][3] - << grid[4][0] << grid[4][1] << grid[4][2] << grid[4][3] - << item1 << item2); + const GraphicsItems expected{grid[0][0], grid[0][1], grid[0][2], grid[0][3], + grid[1][0], grid[1][1], grid[1][2], grid[1][3], + grid[2][0], grid[2][1], grid[2][2], grid[2][3], + grid[3][0], grid[3][1], grid[3][2], grid[3][3], + grid[4][0], grid[4][1], grid[4][2], grid[4][3], + item1, item2}; + QCOMPARE(_paintedItems, expected); } void tst_QGraphicsItem::itemHasNoContents() @@ -8249,6 +8300,7 @@ void tst_QGraphicsItem::itemHasNoContents() scene.addItem(item1); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -8264,7 +8316,7 @@ void tst_QGraphicsItem::itemHasNoContents() QTest::qWait(10); #endif - QTRY_COMPARE(_paintedItems, QList<QGraphicsItem *>() << item2); + QTRY_COMPARE(_paintedItems, GraphicsItems{item2}); } void tst_QGraphicsItem::hitTestUntransformableItem() @@ -8273,6 +8325,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem() scene.setSceneRect(-100, -100, 200, 200); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -8303,7 +8356,7 @@ void tst_QGraphicsItem::hitTestUntransformableItem() QList<QGraphicsItem *> items = scene.items(QPointF(80, 80)); QCOMPARE(items.size(), 1); - QCOMPARE(items.at(0), static_cast<QGraphicsItem*>(item3)); + QCOMPARE(items.at(0), item3); scene.setItemIndexMethod(QGraphicsScene::NoIndex); QTest::qWait(100); @@ -8319,6 +8372,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() scene.setSceneRect(-100, -100, 200, 200); QWidget toplevel; + toplevel.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QGraphicsView view(&scene, &toplevel); toplevel.resize(300, 300); @@ -8379,7 +8433,7 @@ void tst_QGraphicsItem::hitTestGraphicsEffectItem() QVERIFY(items.isEmpty()); items = scene.items(QPointF(80, 80)); QCOMPARE(items.size(), 1); - QCOMPARE(items.at(0), static_cast<QGraphicsItem *>(item3)); + QCOMPARE(items.at(0), item3); scene.setItemIndexMethod(QGraphicsScene::NoIndex); QTest::qWait(100); @@ -8395,7 +8449,7 @@ void tst_QGraphicsItem::focusProxy() { QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QGraphicsItem *item = scene.addRect(0, 0, 10, 10); item->setFlag(QGraphicsItem::ItemIsFocusable); @@ -8414,27 +8468,27 @@ void tst_QGraphicsItem::focusProxy() QString err; QTextStream stream(&err); stream << "QGraphicsItem::setFocusProxy: " - << (void*)item << " is already in the focus proxy chain" << Qt::flush; + << static_cast<const void*>(item) << " is already in the focus proxy chain" << Qt::flush; QTest::ignoreMessage(QtWarningMsg, err.toLatin1().constData()); item2->setFocusProxy(item); // fails - QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); + QCOMPARE(item->focusProxy(), item2); QCOMPARE(item2->focusProxy(), nullptr); // Try to assign self as focus proxy QTest::ignoreMessage(QtWarningMsg, "QGraphicsItem::setFocusProxy: cannot assign self as focus proxy"); item->setFocusProxy(item); // fails - QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); + QCOMPARE(item->focusProxy(), item2); QCOMPARE(item2->focusProxy(), nullptr); // Reset the focus proxy - item->setFocusProxy(0); + item->setFocusProxy(nullptr); QCOMPARE(item->focusProxy(), nullptr); QVERIFY(!item->hasFocus()); QVERIFY(item2->hasFocus()); // Test deletion item->setFocusProxy(item2); - QCOMPARE(item->focusProxy(), (QGraphicsItem *)item2); + QCOMPARE(item->focusProxy(), item2); delete item2; QCOMPARE(item->focusProxy(), nullptr); @@ -8485,7 +8539,7 @@ void tst_QGraphicsItem::subFocus() QVERIFY(!text->hasFocus()); text->setFocus(); QVERIFY(!text->hasFocus()); - QCOMPARE(text->focusItem(), (QGraphicsItem *)text); + QCOMPARE(text->focusItem(), text); // Add a sibling. QGraphicsTextItem *text2 = new QGraphicsTextItem("Hi"); @@ -8496,7 +8550,7 @@ void tst_QGraphicsItem::subFocus() // got input focus. QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); scene.addItem(text); scene.addItem(text2); @@ -8510,10 +8564,10 @@ void tst_QGraphicsItem::subFocus() scene.removeItem(text2); text2->setFocus(); scene.addItem(text2); - QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); + QCOMPARE(text2->focusItem(), text2); text2->setParentItem(text); - QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); - QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); + QCOMPARE(text->focusItem(), text2); + QCOMPARE(text2->focusItem(), text2); QVERIFY(!text->hasFocus()); QVERIFY(text2->hasFocus()); @@ -8524,12 +8578,12 @@ void tst_QGraphicsItem::subFocus() QCOMPARE(text->focusItem(), nullptr); QCOMPARE(text2->focusItem(), nullptr); text2->setFocus(); - QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); - QCOMPARE(text2->focusItem(), (QGraphicsItem *)text2); + QCOMPARE(text->focusItem(), text2); + QCOMPARE(text2->focusItem(), text2); scene.addItem(text); // Hiding and showing text should pass focus to text2. - QCOMPARE(text->focusItem(), (QGraphicsItem *)text2); + QCOMPARE(text->focusItem(), text2); QVERIFY(text2->hasFocus()); // Subfocus should repropagate to root when reparenting. @@ -8546,15 +8600,15 @@ void tst_QGraphicsItem::subFocus() rect3->setFocus(); QVERIFY(!rect3->hasFocus()); - QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3); + QCOMPARE(rect->focusItem(), rect3); + QCOMPARE(rect2->focusItem(), rect3); + QCOMPARE(rect3->focusItem(), rect3); rect->setParentItem(text2); - QCOMPARE(text->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(text2->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(rect->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(rect2->focusItem(), (QGraphicsItem *)rect3); - QCOMPARE(rect3->focusItem(), (QGraphicsItem *)rect3); + QCOMPARE(text->focusItem(), rect3); + QCOMPARE(text2->focusItem(), rect3); + QCOMPARE(rect->focusItem(), rect3); + QCOMPARE(rect2->focusItem(), rect3); + QCOMPARE(rect3->focusItem(), rect3); QVERIFY(!rect->hasFocus()); QVERIFY(!rect2->hasFocus()); QVERIFY(rect3->hasFocus()); @@ -8570,7 +8624,7 @@ void tst_QGraphicsItem::focusProxyDeletion() QGraphicsRectItem *rect = new QGraphicsRectItem; QGraphicsRectItem *rect2 = new QGraphicsRectItem; rect->setFocusProxy(rect2); - QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); + QCOMPARE(rect->focusProxy(), rect2); delete rect2; QCOMPARE(rect->focusProxy(), nullptr); @@ -8595,13 +8649,13 @@ void tst_QGraphicsItem::focusProxyDeletion() QCOMPARE(rect->focusProxy(), nullptr); scene->addItem(rect2); rect->setFocusProxy(rect2); - QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); + QCOMPARE(rect->focusProxy(), rect2); delete rect; // don't crash rect = new QGraphicsRectItem; rect2 = new QGraphicsRectItem; rect->setFocusProxy(rect2); - QCOMPARE(rect->focusProxy(), (QGraphicsItem *)rect2); + QCOMPARE(rect->focusProxy(), rect2); scene->addItem(rect); scene->addItem(rect2); rect->setFocusProxy(rect2); @@ -8673,7 +8727,7 @@ void tst_QGraphicsItem::setGraphicsEffect() // Ensure the existing effect is uninstalled and deleted when setting a null effect blurEffect = new QGraphicsBlurEffect; item->setGraphicsEffect(blurEffect); - item->setGraphicsEffect(0); + item->setGraphicsEffect(nullptr); QVERIFY(!item->graphicsEffect()); QVERIFY(!blurEffect); @@ -8733,11 +8787,11 @@ void tst_QGraphicsItem::panel() QEvent activate(QEvent::WindowActivate); QEvent deactivate(QEvent::WindowDeactivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); // No previous activation, so the scene is active. QVERIFY(scene.isActive()); - QCOMPARE(scene.activePanel(), (QGraphicsItem *)panel1); + QCOMPARE(scene.activePanel(), panel1); QVERIFY(panel1->isActive()); QVERIFY(!panel2->isActive()); QVERIFY(!panel3->isActive()); @@ -8752,7 +8806,7 @@ void tst_QGraphicsItem::panel() QCOMPARE(spy_activate_panel4.count(), 0); // Switch back to scene. - scene.setActivePanel(0); + scene.setActivePanel(nullptr); QVERIFY(!scene.activePanel()); QVERIFY(!panel1->isActive()); QVERIFY(!panel2->isActive()); @@ -8764,7 +8818,7 @@ void tst_QGraphicsItem::panel() QCOMPARE(spy_activate_notPanel2.count(), 1); // Deactivate the scene - QApplication::sendEvent(&scene, &deactivate); + QCoreApplication::sendEvent(&scene, &deactivate); QVERIFY(!scene.activePanel()); QVERIFY(!panel1->isActive()); QVERIFY(!panel2->isActive()); @@ -8776,7 +8830,7 @@ void tst_QGraphicsItem::panel() QCOMPARE(spy_deactivate_notPanel2.count(), 1); // Reactivate the scene - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QVERIFY(!scene.activePanel()); QVERIFY(!panel1->isActive()); QVERIFY(!panel2->isActive()); @@ -8795,23 +8849,23 @@ void tst_QGraphicsItem::panel() QCOMPARE(spy_activate_panel1.count(), 2); // Deactivate the scene - QApplication::sendEvent(&scene, &deactivate); + QCoreApplication::sendEvent(&scene, &deactivate); QVERIFY(!panel1->isActive()); QCOMPARE(spy_deactivate_panel1.count(), 2); // Reactivate the scene - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QVERIFY(panel1->isActive()); QCOMPARE(spy_activate_panel1.count(), 3); // Deactivate the scene - QApplication::sendEvent(&scene, &deactivate); + QCoreApplication::sendEvent(&scene, &deactivate); QVERIFY(!panel1->isActive()); QVERIFY(!scene.activePanel()); - scene.setActivePanel(0); + scene.setActivePanel(nullptr); // Reactivate the scene - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QVERIFY(!panel1->isActive()); } @@ -8821,12 +8875,18 @@ void tst_QGraphicsItem::panelWithFocusItems() { QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); bool widget = (i == 1); - QGraphicsItem *parentPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; - QGraphicsItem *parentPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; - QGraphicsItem *parentPanelFocusItemSibling = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; + auto parentPanel = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); + auto parentPanelFocusItem = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); + auto parentPanelFocusItemSibling = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); parentPanel->setFlag(QGraphicsItem::ItemIsPanel); parentPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable); parentPanelFocusItemSibling->setFlag(QGraphicsItem::ItemIsFocusable); @@ -8841,21 +8901,28 @@ void tst_QGraphicsItem::panelWithFocusItems() QVERIFY(parentPanel->isActive()); QVERIFY(parentPanelFocusItem->hasFocus()); - QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - - QGraphicsItem *childPanel = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; - QGraphicsItem *childPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; - QGraphicsItem *grandChildPanelFocusItem = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; - QGraphicsItem *grandChildPanelFocusItem2 = widget ? (QGraphicsItem *)new QGraphicsWidget : (QGraphicsItem *)new QGraphicsRectItem; + QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem); + QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem); + + auto childPanel = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); + auto childPanelFocusItem = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); + auto grandChildPanelFocusItem = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); + auto grandChildPanelFocusItem2 = widget + ? static_cast<QGraphicsItem *>(new QGraphicsWidget) + : static_cast<QGraphicsItem *>(new QGraphicsRectItem); childPanel->setFlag(QGraphicsItem::ItemIsPanel); childPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable); grandChildPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable); grandChildPanelFocusItem2->setFlag(QGraphicsItem::ItemIsFocusable); - if (widget) - { + if (widget) { static_cast<QGraphicsWidget *>(childPanelFocusItem)->setFocusPolicy(Qt::StrongFocus); static_cast<QGraphicsWidget *>(grandChildPanelFocusItem)->setFocusPolicy(Qt::StrongFocus); static_cast<QGraphicsWidget *>(grandChildPanelFocusItem2)->setFocusPolicy(Qt::StrongFocus); @@ -8866,45 +8933,45 @@ void tst_QGraphicsItem::panelWithFocusItems() grandChildPanelFocusItem->setFocus(); QVERIFY(!grandChildPanelFocusItem->hasFocus()); - QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); - QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); - QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); + QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem); + QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem); + QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem); childPanel->setParentItem(parentPanel); QVERIFY(!parentPanel->isActive()); QVERIFY(!parentPanelFocusItem->hasFocus()); - QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); + QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem); + QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem); QVERIFY(childPanel->isActive()); QVERIFY(!childPanelFocusItem->hasFocus()); QVERIFY(grandChildPanelFocusItem->hasFocus()); - QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); - QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); + QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem); + QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem); childPanel->hide(); - QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); + QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem); QVERIFY(!childPanel->focusItem()->hasFocus()); QVERIFY(parentPanel->isActive()); QVERIFY(parentPanelFocusItem->hasFocus()); - QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); + QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem); + QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem); + QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem); childPanel->show(); QVERIFY(childPanel->isActive()); QVERIFY(grandChildPanelFocusItem->hasFocus()); - QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); - QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); - QCOMPARE(grandChildPanelFocusItem->focusItem(), (QGraphicsItem *)grandChildPanelFocusItem); + QCOMPARE(childPanel->focusItem(), grandChildPanelFocusItem); + QCOMPARE(childPanelFocusItem->focusItem(), grandChildPanelFocusItem); + QCOMPARE(grandChildPanelFocusItem->focusItem(), grandChildPanelFocusItem); childPanel->hide(); QVERIFY(parentPanel->isActive()); QVERIFY(parentPanelFocusItem->hasFocus()); - QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); - QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); + QCOMPARE(parentPanel->focusItem(), parentPanelFocusItem); + QCOMPARE(parentPanelFocusItem->focusItem(), parentPanelFocusItem); } } @@ -8921,7 +8988,7 @@ void tst_QGraphicsItem::addPanelToActiveScene() QEvent activate(QEvent::WindowActivate); QEvent deactivate(QEvent::WindowDeactivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QVERIFY(scene.isActive()); scene.addItem(rect); QVERIFY(rect->isActive()); @@ -8930,12 +8997,12 @@ void tst_QGraphicsItem::addPanelToActiveScene() rect->setFlag(QGraphicsItem::ItemIsPanel); scene.addItem(rect); QVERIFY(rect->isActive()); - QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect); + QCOMPARE(scene.activePanel(), rect); QGraphicsRectItem *rect2 = new QGraphicsRectItem; scene.addItem(rect2); QVERIFY(rect->isActive()); - QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect); + QCOMPARE(scene.activePanel(), rect); } void tst_QGraphicsItem::activate() @@ -8947,7 +9014,7 @@ void tst_QGraphicsItem::activate() QEvent activate(QEvent::WindowActivate); QEvent deactivate(QEvent::WindowDeactivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); // Non-panel item (active when scene is active). QVERIFY(rect->isActive()); @@ -8993,14 +9060,14 @@ void tst_QGraphicsItem::activate() QGraphicsRectItem *rect5 = new QGraphicsRectItem(rect4); QGraphicsRectItem *rect6 = new QGraphicsRectItem(rect5); scene.addItem(rect4); - QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect3); + QCOMPARE(scene.activePanel(), rect3); scene.removeItem(rect4); rect6->setActive(true); scene.addItem(rect4); QVERIFY(rect4->isActive()); QVERIFY(rect5->isActive()); QVERIFY(rect6->isActive()); - QCOMPARE(scene.activePanel(), (QGraphicsItem *)rect4); + QCOMPARE(scene.activePanel(), rect4); scene.removeItem(rect4); // no active panel rect6->setActive(false); scene.addItem(rect4); @@ -9011,11 +9078,11 @@ void tst_QGraphicsItem::activate() // Controlling auto-activation when the scene changes activation. rect4->setActive(true); - QApplication::sendEvent(&scene, &deactivate); + QCoreApplication::sendEvent(&scene, &deactivate); QVERIFY(!scene.isActive()); QVERIFY(!rect4->isActive()); rect4->setActive(false); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QVERIFY(scene.isActive()); QVERIFY(!scene.activePanel()); QVERIFY(!rect4->isActive()); @@ -9047,7 +9114,7 @@ void tst_QGraphicsItem::activationOnShowHide() { QGraphicsScene scene; QEvent activate(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &activate); + QCoreApplication::sendEvent(&scene, &activate); QGraphicsRectItem *rootPanel = scene.addRect(QRectF()); rootPanel->setFlag(QGraphicsItem::ItemIsPanel); @@ -9109,18 +9176,19 @@ void tst_QGraphicsItem::activationOnShowHide() class MoveWhileDying : public QGraphicsRectItem { public: - MoveWhileDying(QGraphicsItem *parent = 0) - : QGraphicsRectItem(parent) - { } + using QGraphicsRectItem::QGraphicsRectItem; + ~MoveWhileDying() { - foreach (QGraphicsItem *c, childItems()) { - foreach (QGraphicsItem *cc, c->childItems()) { + const auto children = childItems(); + for (QGraphicsItem *c : children) { + const auto grandChildren = c->childItems(); + for (QGraphicsItem *cc : grandChildren) cc->moveBy(10, 10); - } c->moveBy(10, 10); } - if (QGraphicsItem *p = parentItem()) { p->moveBy(10, 10); } + if (QGraphicsItem *p = parentItem()) + p->moveBy(10, 10); } }; @@ -9134,7 +9202,7 @@ void tst_QGraphicsItem::deactivateInactivePanel() panel2->setFlag(QGraphicsItem::ItemIsPanel); QEvent event(QEvent::WindowActivate); - qApp->sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); panel1->setActive(true); QVERIFY(scene.isActive()); @@ -9172,6 +9240,7 @@ void tst_QGraphicsItem::moveWhileDeleting() child = new QGraphicsRectItem(silly); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -9200,12 +9269,9 @@ class MyRectItem : public QGraphicsWidget { Q_OBJECT public: - MyRectItem(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) - { + using QGraphicsWidget::QGraphicsWidget; - } - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->setBrush(brush); painter->drawRect(boundingRect()); @@ -9216,7 +9282,7 @@ public: topLevel->collidingItems(Qt::IntersectsItemBoundingRect); } public: - QGraphicsItem *topLevel; + QGraphicsItem *topLevel = nullptr; QBrush brush; }; @@ -9258,6 +9324,7 @@ void tst_QGraphicsItem::ensureDirtySceneTransform() child3->brush = QBrush(QColor(Qt::gray)); QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -9292,7 +9359,7 @@ void tst_QGraphicsItem::focusScope() scope3->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); scope3->setFocus(); QVERIFY(!scope3->focusScopeItem()); - QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); + QCOMPARE(scope3->focusItem(), scope3); QGraphicsRectItem *scope2 = new QGraphicsRectItem; scope2->setData(0, "scope2"); @@ -9300,8 +9367,8 @@ void tst_QGraphicsItem::focusScope() scope2->setFocus(); QVERIFY(!scope2->focusScopeItem()); scope3->setParentItem(scope2); - QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); + QCOMPARE(scope2->focusScopeItem(), scope3); + QCOMPARE(scope2->focusItem(), scope3); QGraphicsRectItem *scope1 = new QGraphicsRectItem; scope1->setData(0, "scope1"); @@ -9310,11 +9377,11 @@ void tst_QGraphicsItem::focusScope() QVERIFY(!scope1->focusScopeItem()); scope2->setParentItem(scope1); - QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2); - QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); + QCOMPARE(scope1->focusItem(), scope3); + QCOMPARE(scope2->focusItem(), scope3); + QCOMPARE(scope3->focusItem(), scope3); + QCOMPARE(scope1->focusScopeItem(), scope2); + QCOMPARE(scope2->focusScopeItem(), scope3); QCOMPARE(scope3->focusScopeItem(), nullptr); scene.addItem(scope1); @@ -9323,11 +9390,11 @@ void tst_QGraphicsItem::focusScope() qApp->sendEvent(&scene, &windowActivate); scene.setFocus(); - QCOMPARE(scope1->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope2->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope3->focusItem(), (QGraphicsItem *)scope3); - QCOMPARE(scope1->focusScopeItem(), (QGraphicsItem *)scope2); - QCOMPARE(scope2->focusScopeItem(), (QGraphicsItem *)scope3); + QCOMPARE(scope1->focusItem(), scope3); + QCOMPARE(scope2->focusItem(), scope3); + QCOMPARE(scope3->focusItem(), scope3); + QCOMPARE(scope1->focusScopeItem(), scope2); + QCOMPARE(scope2->focusScopeItem(), scope3); QCOMPARE(scope3->focusScopeItem(), nullptr); QVERIFY(scope3->hasFocus()); @@ -9405,10 +9472,10 @@ void tst_QGraphicsItem::focusScope() rect5->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); rect5->setFocus(); rect5->setParentItem(rect4); - QCOMPARE(scope3->focusScopeItem(), (QGraphicsItem *)rect5); + QCOMPARE(scope3->focusScopeItem(), rect5); QVERIFY(rect5->hasFocus()); - rect4->setParentItem(0); + rect4->setParentItem(nullptr); QVERIFY(rect5->hasFocus()); QCOMPARE(scope3->focusScopeItem(), nullptr); QCOMPARE(scope3->focusItem(), nullptr); @@ -9428,7 +9495,7 @@ void tst_QGraphicsItem::focusScope() scopeA->setFocus(); QVERIFY(scopeB->hasFocus()); - QCOMPARE(scopeB->focusItem(), (QGraphicsItem *)scopeB); + QCOMPARE(scopeB->focusItem(), scopeB); } void tst_QGraphicsItem::focusScope2() @@ -9436,7 +9503,7 @@ void tst_QGraphicsItem::focusScope2() QGraphicsRectItem *child1 = new QGraphicsRectItem; child1->setFlags(QGraphicsItem::ItemIsFocusable); child1->setFocus(); - QCOMPARE(child1->focusItem(), (QGraphicsItem *)child1); + QCOMPARE(child1->focusItem(), child1); QGraphicsRectItem *child2 = new QGraphicsRectItem; child2->setFlags(QGraphicsItem::ItemIsFocusable); @@ -9444,13 +9511,13 @@ void tst_QGraphicsItem::focusScope2() QGraphicsRectItem *rootFocusScope = new QGraphicsRectItem; rootFocusScope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); rootFocusScope->setFocus(); - QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)rootFocusScope); + QCOMPARE(rootFocusScope->focusItem(), rootFocusScope); child1->setParentItem(rootFocusScope); child2->setParentItem(rootFocusScope); - QCOMPARE(rootFocusScope->focusScopeItem(), (QGraphicsItem *)child1); - QCOMPARE(rootFocusScope->focusItem(), (QGraphicsItem *)child1); + QCOMPARE(rootFocusScope->focusScopeItem(), child1); + QCOMPARE(rootFocusScope->focusItem(), child1); QGraphicsRectItem *siblingChild1 = new QGraphicsRectItem; siblingChild1->setFlags(QGraphicsItem::ItemIsFocusable); @@ -9465,14 +9532,14 @@ void tst_QGraphicsItem::focusScope2() siblingChild1->setParentItem(siblingFocusScope); siblingChild2->setParentItem(siblingFocusScope); - QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild1); + QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild1); QCOMPARE(siblingFocusScope->focusItem(), nullptr); QGraphicsItem *root = new QGraphicsRectItem; rootFocusScope->setParentItem(root); siblingFocusScope->setParentItem(root); - QCOMPARE(root->focusItem(), (QGraphicsItem *)child1); + QCOMPARE(root->focusItem(), child1); QGraphicsScene scene; scene.addItem(root); @@ -9481,7 +9548,7 @@ void tst_QGraphicsItem::focusScope2() qApp->sendEvent(&scene, &activate); scene.setFocus(); - QCOMPARE(scene.focusItem(), (QGraphicsItem *)child1); + QCOMPARE(scene.focusItem(), child1); // You cannot set focus on a descendant of a focus scope directly; // this will only change the scope's focus scope item pointer. If @@ -9490,15 +9557,15 @@ void tst_QGraphicsItem::focusScope2() siblingChild2->setFocus(); QVERIFY(!siblingChild2->hasFocus()); QVERIFY(!siblingChild2->focusItem()); - QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2); + QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2); QCOMPARE(siblingFocusScope->focusItem(), nullptr); // Set focus on the scope; focus is forwarded to the focus scope item. siblingFocusScope->setFocus(); QVERIFY(siblingChild2->hasFocus()); QVERIFY(siblingChild2->focusItem()); - QCOMPARE(siblingFocusScope->focusScopeItem(), (QGraphicsItem *)siblingChild2); - QCOMPARE(siblingFocusScope->focusItem(), (QGraphicsItem *)siblingChild2); + QCOMPARE(siblingFocusScope->focusScopeItem(), siblingChild2); + QCOMPARE(siblingFocusScope->focusItem(), siblingChild2); } class FocusScopeItemPrivate; @@ -9506,11 +9573,11 @@ class FocusScopeItem : public QGraphicsItem { Q_DECLARE_PRIVATE(FocusScopeItem) public: - FocusScopeItem(QGraphicsItem *parent = 0); - QRectF boundingRect() const { return QRectF(); } - void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) { } + FocusScopeItem(QGraphicsItem *parent = nullptr); + QRectF boundingRect() const override { return QRectF(); } + void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override { } - int focusScopeChanged; + int focusScopeChanged = 0; FocusScopeItemPrivate *d_ptr; }; @@ -9518,12 +9585,12 @@ class FocusScopeItemPrivate : QGraphicsItemPrivate { Q_DECLARE_PUBLIC(FocusScopeItem) public: - void focusScopeItemChange(bool) + void focusScopeItemChange(bool) override { ++q_func()->focusScopeChanged; } }; FocusScopeItem::FocusScopeItem(QGraphicsItem *parent) - : QGraphicsItem(*new FocusScopeItemPrivate, parent), focusScopeChanged(0) + : QGraphicsItem(*new FocusScopeItemPrivate, parent) { setFlag(ItemIsFocusable); } @@ -9540,15 +9607,15 @@ void tst_QGraphicsItem::focusScopeItemChangedWhileScopeDoesntHaveFocus() QCOMPARE(child1->focusScopeChanged, 0); QCOMPARE(child2->focusScopeChanged, 0); child1->setFocus(); - QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1); + QCOMPARE(rect.focusScopeItem(), child1); QCOMPARE(child1->focusScopeChanged, 1); QCOMPARE(child2->focusScopeChanged, 0); child2->setFocus(); - QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child2); + QCOMPARE(rect.focusScopeItem(), child2); QCOMPARE(child1->focusScopeChanged, 2); QCOMPARE(child2->focusScopeChanged, 1); child1->setFocus(); - QCOMPARE(rect.focusScopeItem(), (QGraphicsItem *)child1); + QCOMPARE(rect.focusScopeItem(), child1); QCOMPARE(child1->focusScopeChanged, 3); QCOMPARE(child2->focusScopeChanged, 2); child1->clearFocus(); @@ -9564,75 +9631,81 @@ void tst_QGraphicsItem::stackBefore() QGraphicsRectItem *child2 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); QGraphicsRectItem *child3 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); QGraphicsRectItem *child4 = new QGraphicsRectItem(QRectF(0, 0, 5, 5), &parent); - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + const GraphicsItemsList expected1234{child1, child2, child3, child4}; + QCOMPARE(parent.childItems(), expected1234); child1->setData(0, "child1"); child2->setData(0, "child2"); child3->setData(0, "child3"); child4->setData(0, "child4"); // Remove and append - child2->setParentItem(0); + child2->setParentItem(nullptr); child2->setParentItem(&parent); - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2)); + const GraphicsItemsList expected1342{child1, child3, child4, child2}; + QCOMPARE(parent.childItems(), expected1342); // Move child2 before child1 child2->stackBefore(child1); // 2134 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); + const GraphicsItemsList expected2134{child2, child1, child3, child4}; + QCOMPARE(parent.childItems(), expected2134); child2->stackBefore(child2); // 2134 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); + QCOMPARE(parent.childItems(), expected2134); child1->setZValue(1); // 2341 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); + const GraphicsItemsList expected2341{child2, child3, child4, child1}; + QCOMPARE(parent.childItems(), expected2341); child1->stackBefore(child2); // 2341 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); + QCOMPARE(parent.childItems(), expected2341); child1->setZValue(0); // 1234 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + QCOMPARE(parent.childItems(), expected1234); child4->stackBefore(child1); // 4123 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3)); + const GraphicsItemsList expected4123{child4, child1, child2, child3}; + QCOMPARE(parent.childItems(), expected4123); child4->setZValue(1); // 1234 (4123) - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + QCOMPARE(parent.childItems(), expected1234); child3->stackBefore(child1); // 3124 (4312) - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4)); + const GraphicsItemsList expected3124{child3, child1, child2, child4}; + QCOMPARE(parent.childItems(), expected3124); child4->setZValue(0); // 4312 - QCOMPARE(parent.childItems(), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2)); + const GraphicsItemsList expected4312{child4, child3, child1, child2}; + QCOMPARE(parent.childItems(), expected4312); // Make them all toplevels - child1->setParentItem(0); - child2->setParentItem(0); - child3->setParentItem(0); - child4->setParentItem(0); + child1->setParentItem(nullptr); + child2->setParentItem(nullptr); + child3->setParentItem(nullptr); + child4->setParentItem(nullptr); QGraphicsScene scene; scene.addItem(child1); scene.addItem(child2); scene.addItem(child3); scene.addItem(child4); - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), - (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234); // Remove and append scene.removeItem(child2); scene.addItem(child2); - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child3 << child4 << child2)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1342); // Move child2 before child1 child2->stackBefore(child1); // 2134 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134); child2->stackBefore(child2); // 2134 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child1 << child3 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2134); child1->setZValue(1); // 2341 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341); child1->stackBefore(child2); // 2341 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child2 << child3 << child4 << child1)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected2341); child1->setZValue(0); // 1234 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234); child4->stackBefore(child1); // 4123 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child1 << child2 << child3)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4123); child4->setZValue(1); // 1234 (4123) - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child1 << child2 << child3 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected1234); child3->stackBefore(child1); // 3124 (4312) - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child3 << child1 << child2 << child4)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected3124); child4->setZValue(0); // 4312 - QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), (QList<QGraphicsItem *>() << child4 << child3 << child1 << child2)); + QCOMPARE(scene.items(QPointF(2, 2), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder), expected4312); } void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() @@ -9645,24 +9718,25 @@ void tst_QGraphicsItem::QTBUG_4233_updateCachedWithSceneRect() scene.setSceneRect(-100, -100, 200, 200); // contains the tester item QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), (QWidget *)&view); + QCOMPARE(QApplication::activeWindow(), &view); QTRY_COMPARE(tester->repaints, 1); scene.update(); // triggers "updateAll" optimization - qApp->processEvents(); - qApp->processEvents(); // in 4.6 only one processEvents is necessary + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary QCOMPARE(tester->repaints, 1); scene.update(); // triggers "updateAll" optimization tester->update(); - qApp->processEvents(); - qApp->processEvents(); // in 4.6 only one processEvents is necessary + QCoreApplication::processEvents(); + QCoreApplication::processEvents(); // in 4.6 only one processEvents is necessary QCOMPARE(tester->repaints, 2); } @@ -10203,7 +10277,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.mouseGrabberItem(), rect1); // grab lost when rect1 is modally shadowed rect2->setPanelModality(QGraphicsItem::SceneModal); @@ -10243,7 +10317,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.mouseGrabberItem(), rect1); // grab lost to rect2 when rect1 is modally shadowed rect2->setPanelModality(QGraphicsItem::SceneModal); @@ -10283,7 +10357,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 0); QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.mouseGrabberItem(), rect1); // grab lost when rect1 is modally shadowed rect2->setPanelModality(QGraphicsItem::PanelModal); @@ -10323,7 +10397,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect1Spy.counts[QEvent::UngrabMouse], 1); QCOMPARE(rect2Spy.counts[QEvent::GrabMouse], 1); QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.mouseGrabberItem(), rect1); // grab lost to rect2 when rect1 is modally shadowed rect2->setPanelModality(QGraphicsItem::PanelModal); @@ -10375,7 +10449,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1); QCOMPARE(rect3Spy.counts[QEvent::GraphicsSceneMousePress], 1); QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); + QCOMPARE(scene.mouseGrabberItem(), rect3); // grab is *not* lost when rect1 is modally shadowed by rect2 rect2->setPanelModality(QGraphicsItem::PanelModal); @@ -10385,7 +10459,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 1); QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 0); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); + QCOMPARE(scene.mouseGrabberItem(), rect3); // releasing goes to rect3 sendMouseRelease(&scene, QPoint(150, 50)); @@ -10408,7 +10482,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); + QCOMPARE(scene.mouseGrabberItem(), rect3); // grab is not lost rect2->setPanelModality(QGraphicsItem::PanelModal); @@ -10418,7 +10492,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); + QCOMPARE(scene.mouseGrabberItem(), rect3); // grab stays on rect3 rect2->setPanelModality(QGraphicsItem::NonModal); @@ -10428,7 +10502,7 @@ void tst_QGraphicsItem::modality_mouseGrabber() QCOMPARE(rect2Spy.counts[QEvent::UngrabMouse], 0); QCOMPARE(rect3Spy.counts[QEvent::GrabMouse], 2); QCOMPARE(rect3Spy.counts[QEvent::UngrabMouse], 1); - QCOMPARE(scene.mouseGrabberItem(), (QGraphicsItem *) rect3); + QCOMPARE(scene.mouseGrabberItem(), rect3); // release goes to rect3 sendMouseRelease(&scene, QPoint(150, 50)); @@ -10458,18 +10532,18 @@ void tst_QGraphicsItem::modality_clickFocus() rect2->setData(0, "rect2"); QEvent windowActivateEvent(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &windowActivateEvent); + QCoreApplication::sendEvent(&scene, &windowActivateEvent); EventSpy2 rect1Spy(&scene, rect1); EventSpy2 rect2Spy(&scene, rect2); // activate rect1, it should get focus rect1->setActive(true); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.focusItem(), rect1); // focus stays when rect2 becomes modal rect2->setPanelModality(QGraphicsItem::SceneModal); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.focusItem(), rect1); QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); @@ -10487,7 +10561,7 @@ void tst_QGraphicsItem::modality_clickFocus() // clicking on rect2 gives it focus rect2->setActive(true); sendMouseClick(&scene, QPointF(75, 75)); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2); + QCOMPARE(scene.focusItem(), rect2); QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); @@ -10513,7 +10587,7 @@ void tst_QGraphicsItem::modality_clickFocus() // click on rect1, it should get focus now sendMouseClick(&scene, QPointF(-25, -25)); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); + QCOMPARE(scene.focusItem(), rect1); QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 3); QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); @@ -10546,7 +10620,7 @@ void tst_QGraphicsItem::modality_keyEvents() rect2child->setData(0, "rect2child1"); QEvent windowActivateEvent(QEvent::WindowActivate); - QApplication::sendEvent(&scene, &windowActivateEvent); + QCoreApplication::sendEvent(&scene, &windowActivateEvent); EventSpy2 rect1Spy(&scene, rect1); EventSpy2 rect1childSpy(&scene, rect1child); @@ -10556,11 +10630,11 @@ void tst_QGraphicsItem::modality_keyEvents() // activate rect1 and give it rect1child focus rect1->setActive(true); rect1child->setFocus(); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); + QCOMPARE(scene.focusItem(), rect1child); // focus stays on rect1child when rect2 becomes modal rect2->setPanelModality(QGraphicsItem::SceneModal); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); + QCOMPARE(scene.focusItem(), rect1child); // but key events to rect1child should be neither delivered nor propagated sendKeyClick(&scene, Qt::Key_A); @@ -10574,7 +10648,7 @@ void tst_QGraphicsItem::modality_keyEvents() // change to panel modality, rect1child1 keeps focus rect2->setPanelModality(QGraphicsItem::PanelModal); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1child); + QCOMPARE(scene.focusItem(), rect1child); // still no key events sendKeyClick(&scene, Qt::Key_J); @@ -10629,14 +10703,7 @@ void tst_QGraphicsItem::itemIsInFront() QCOMPARE(qt_closestItemFirst(rect1child1_2, rect2child1), false); } -class ScenePosChangeTester : public ItemChangeTester -{ -public: - ScenePosChangeTester() - { } - ScenePosChangeTester(QGraphicsItem *parent) : ItemChangeTester(parent) - { } -}; +using ScenePosChangeTester = ItemChangeTester; void tst_QGraphicsItem::scenePosChange() { @@ -10695,7 +10762,7 @@ void tst_QGraphicsItem::scenePosChange() // remove scene.removeItem(grandChild1.data()); - delete grandChild2; grandChild2 = 0; + delete grandChild2; grandChild2 = nullptr; QCoreApplication::processEvents(); // QGraphicsScenePrivate::_q_updateScenePosDescendants() root->moveBy(1.0, 1.0); QCOMPARE(child1->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 4); @@ -10716,13 +10783,13 @@ void tst_QGraphicsItem::scenePosChange() void tst_QGraphicsItem::textItem_shortcuts() { QWidget w; - QVBoxLayout l; - w.setLayout(&l); + w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); + auto l = new QVBoxLayout(&w); QGraphicsScene scene; QGraphicsView view(&scene); - l.addWidget(&view); + l->addWidget(&view); QPushButton b("Push Me"); - l.addWidget(&b); + l->addWidget(&b); QGraphicsTextItem *item = scene.addText("Troll Text"); item->setFlag(QGraphicsItem::ItemIsFocusable); @@ -10776,6 +10843,7 @@ void tst_QGraphicsItem::scroll() scene.addItem(item2); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.setFrameStyle(0); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -10859,7 +10927,7 @@ void tst_QGraphicsItem::focusHandling() { public: MyItem() : QGraphicsRectItem(0, 0, 100, 100) {} - void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override { painter->fillRect(boundingRect(), hasFocus() ? QBrush(Qt::red) : brush()); } @@ -10924,6 +10992,8 @@ void tst_QGraphicsItem::focusHandling() class TouchEventTestee : public QGraphicsRectItem { public: + using TouchPoints = QVector<QTouchEvent::TouchPoint>; + TouchEventTestee(const QSizeF &size = QSizeF(100, 100)) : QGraphicsRectItem(QRectF(QPointF(), size)) { @@ -10931,10 +11001,10 @@ public: setFlag(QGraphicsItem::ItemIsFocusable, false); } - QList<QTouchEvent::TouchPoint> touchBeginPoints() const { return m_touchBeginPoints; } + TouchPoints touchBeginPoints() const { return m_touchBeginPoints; } int touchBeginEventCount() const { return m_touchBeginPoints.size(); } - QList<QTouchEvent::TouchPoint> touchUpdatePoints() const { return m_touchUpdatePoints; } + TouchPoints touchUpdatePoints() const { return m_touchUpdatePoints; } int touchUpdateEventCount() const { return m_touchUpdatePoints.size(); } protected: @@ -10957,8 +11027,8 @@ protected: } private: - QList<QTouchEvent::TouchPoint> m_touchBeginPoints; - QList<QTouchEvent::TouchPoint> m_touchUpdatePoints; + TouchPoints m_touchBeginPoints; + TouchPoints m_touchUpdatePoints; }; static QList<QTouchEvent::TouchPoint> @@ -11157,6 +11227,7 @@ void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations() scene.addItem(item); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); QTRY_VERIFY(view.repaints > 0); @@ -11224,7 +11295,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() struct Item : public QGraphicsTextItem { int painted; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) + void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override { painted++; QGraphicsTextItem::paint(painter, opt, wid); @@ -11237,6 +11308,7 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); scene.addItem(i); @@ -11264,9 +11336,9 @@ void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() for (int x = 0; x < image.width(); ++x) { // Because of antialiasing we allow a certain range of errors here. QRgb pixel = image.pixel(x, y); - if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + - qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + - qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { + if (qAbs(int(pixel & 0xff) - int(rgb & 0xff)) + + qAbs(int((pixel & 0xff00) >> 8) - int((rgb & 0xff00) >> 8)) + + qAbs(int((pixel & 0xff0000) >> 16) - int((rgb & 0xff0000) >> 16)) <= 50) { if (++numRedPixel >= 10) { return; } @@ -11299,6 +11371,7 @@ void tst_QGraphicsItem::QTBUG_6738_missingUpdateWithSetParent() scene.addItem(parent); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); view.show(); qApp->setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -11332,6 +11405,7 @@ void tst_QGraphicsItem::QT_2653_fullUpdateDiscardingOpacityUpdate() { QGraphicsScene scene(0, 0, 200, 200); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); EventTester *parentGreen = new EventTester(); parentGreen->setGeometry(QRectF(20, 20, 100, 100)); @@ -11373,6 +11447,7 @@ void tst_QGraphicsItem::QTBUG_7714_fullUpdateDiscardingOpacityUpdate2() { QGraphicsScene scene(0, 0, 200, 200); MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); MyGraphicsView origView(&scene); EventTester *parentGreen = new EventTester(); @@ -11423,26 +11498,26 @@ void tst_QGraphicsItem::QT_2649_focusScope() QGraphicsRectItem *subFocusItem = new QGraphicsRectItem; subFocusItem->setFlags(QGraphicsItem::ItemIsFocusable); subFocusItem->setFocus(); - QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(subFocusItem->focusItem(), subFocusItem); QGraphicsRectItem *scope = new QGraphicsRectItem; scope->setFlags(QGraphicsItem::ItemIsFocusable | QGraphicsItem::ItemIsFocusScope); scope->setFocus(); subFocusItem->setParentItem(scope); - QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(subFocusItem->focusItem(), subFocusItem); QCOMPARE(subFocusItem->focusScopeItem(), nullptr); - QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(scope->focusItem(), subFocusItem); + QCOMPARE(scope->focusScopeItem(), subFocusItem); QGraphicsRectItem *rootItem = new QGraphicsRectItem; rootItem->setFlags(QGraphicsItem::ItemIsFocusable); scope->setParentItem(rootItem); - QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(rootItem->focusItem(), subFocusItem); QCOMPARE(rootItem->focusScopeItem(), nullptr); - QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(subFocusItem->focusItem(), subFocusItem); QCOMPARE(subFocusItem->focusScopeItem(), nullptr); - QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(scope->focusItem(), subFocusItem); + QCOMPARE(scope->focusScopeItem(), subFocusItem); scene->addItem(rootItem); @@ -11450,11 +11525,11 @@ void tst_QGraphicsItem::QT_2649_focusScope() qApp->sendEvent(scene, &windowActivate); scene->setFocus(); - QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(rootItem->focusItem(), subFocusItem); + QCOMPARE(scope->focusItem(), subFocusItem); + QCOMPARE(subFocusItem->focusItem(), subFocusItem); QCOMPARE(rootItem->focusScopeItem(), nullptr); - QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(scope->focusScopeItem(), subFocusItem); QCOMPARE(subFocusItem->focusScopeItem(), nullptr); QVERIFY(subFocusItem->hasFocus()); @@ -11464,17 +11539,17 @@ void tst_QGraphicsItem::QT_2649_focusScope() QCOMPARE(scope->focusItem(), nullptr); QCOMPARE(subFocusItem->focusItem(), nullptr); QCOMPARE(rootItem->focusScopeItem(), nullptr); - QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(scope->focusScopeItem(), subFocusItem); QCOMPARE(subFocusItem->focusScopeItem(), nullptr); QVERIFY(!subFocusItem->hasFocus()); scope->show(); - QCOMPARE(rootItem->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(scope->focusItem(), (QGraphicsItem *)subFocusItem); - QCOMPARE(subFocusItem->focusItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(rootItem->focusItem(), subFocusItem); + QCOMPARE(scope->focusItem(), subFocusItem); + QCOMPARE(subFocusItem->focusItem(), subFocusItem); QCOMPARE(rootItem->focusScopeItem(), nullptr); - QCOMPARE(scope->focusScopeItem(), (QGraphicsItem *)subFocusItem); + QCOMPARE(scope->focusScopeItem(), subFocusItem); QCOMPARE(subFocusItem->focusScopeItem(), nullptr); QVERIFY(subFocusItem->hasFocus()); @@ -11486,16 +11561,14 @@ void tst_QGraphicsItem::QT_2649_focusScope() class MyGraphicsItemWithItemChange : public QGraphicsWidget { public: - MyGraphicsItemWithItemChange(QGraphicsItem *parent = 0) : QGraphicsWidget(parent) - {} + using QGraphicsWidget::QGraphicsWidget; - QVariant itemChange(GraphicsItemChange change, const QVariant &value) + QVariant itemChange(GraphicsItemChange change, const QVariant &value) override { if (change == QGraphicsItem::ItemSceneHasChanged) { - foreach (QGraphicsView *view, scene()->views()) { - //We trigger a sort of unindexed items in the BSP + const auto views = scene()->views(); + for (QGraphicsView *view : views) // We trigger a sort of unindexed items in the BSP view->sceneRect(); - } } return QGraphicsWidget::itemChange(change, value); } @@ -11520,8 +11593,8 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() { struct Item : public QGraphicsTextItem { - int painted; - void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) + int painted = 0; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) override { painted++; QGraphicsTextItem::paint(painter, opt, wid); @@ -11529,15 +11602,13 @@ void tst_QGraphicsItem::doNotMarkFullUpdateIfNotInScene() }; QGraphicsScene scene; MyGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); Item *item = new Item; - item->painted = 0; item->setPlainText("Grandparent"); Item *item2 = new Item; item2->setPlainText("parent"); - item2->painted = 0; Item *item3 = new Item; item3->setPlainText("child"); - item3->painted = 0; QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect; effect->setOpacity(0.5); item2->setGraphicsEffect(effect); @@ -11572,6 +11643,7 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QGraphicsRectItem *item = new QGraphicsRectItem(QRectF(0, 0, 100, 100)); item->setFlag(QGraphicsItem::ItemIsMovable); item->setAcceptDrops(true); @@ -11580,13 +11652,13 @@ void tst_QGraphicsItem::itemDiesDuringDraggingOperation() QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), (QWidget *)&view); + QCOMPARE(QApplication::activeWindow(), &view); QGraphicsSceneDragDropEvent dragEnter(QEvent::GraphicsSceneDragEnter); dragEnter.setScenePos(item->boundingRect().center()); - QApplication::sendEvent(&scene, &dragEnter); + QCoreApplication::sendEvent(&scene, &dragEnter); QGraphicsSceneDragDropEvent event(QEvent::GraphicsSceneDragMove); event.setScenePos(item->boundingRect().center()); - QApplication::sendEvent(&scene, &event); + QCoreApplication::sendEvent(&scene, &event); QCOMPARE(QGraphicsScenePrivate::get(&scene)->dragDropItem, item); delete item; QVERIFY(!QGraphicsScenePrivate::get(&scene)->dragDropItem); @@ -11596,6 +11668,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20); item1->setFlag(QGraphicsItem::ItemIsFocusable); QGraphicsRectItem *item2 = new QGraphicsRectItem(20, 20, 20, 20); @@ -11608,7 +11681,7 @@ void tst_QGraphicsItem::QTBUG_12112_focusItem() QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowExposed(&view)); QVERIFY(QTest::qWaitForWindowActive(&view)); - QCOMPARE(QApplication::activeWindow(), (QWidget *)&view); + QCOMPARE(QApplication::activeWindow(), &view); QVERIFY(item1->focusItem()); QVERIFY(!item2->focusItem()); @@ -11644,11 +11717,11 @@ void tst_QGraphicsItem::QTBUG_13473_sceneposchange() QCOMPARE(child->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 2); } -class MyGraphicsWidget : public QGraphicsWidget { -Q_OBJECT +class MyGraphicsWidget : public QGraphicsWidget +{ + Q_OBJECT public: - MyGraphicsWidget() - : QGraphicsWidget(0) + MyGraphicsWidget() : QGraphicsWidget(nullptr) { QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical); QLatin1String wiseWords("AZ BUKI VEDI"); @@ -11660,21 +11733,19 @@ public: proxy->setWidget(label); proxy->setFocusPolicy(Qt::StrongFocus); proxy->setFlag(QGraphicsItem::ItemAcceptsInputMethod, true); - if (i%2 == 0) + if (i % 2 == 0) proxy->setVisible(false); proxy->setFocus(); lay->addItem(proxy); } setLayout(lay); } - }; class MyWidgetWindow : public QGraphicsWidget { public: - MyWidgetWindow() - : QGraphicsWidget(0, Qt::Window) + MyWidgetWindow() : QGraphicsWidget(nullptr, Qt::Window) { QGraphicsLinearLayout *lay = new QGraphicsLinearLayout(Qt::Vertical); MyGraphicsWidget *widget = new MyGraphicsWidget(); @@ -11687,6 +11758,7 @@ void tst_QGraphicsItem::QTBUG_16374_crashInDestructor() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); MyWidgetWindow win; scene.addItem(&win); @@ -11699,6 +11771,7 @@ void tst_QGraphicsItem::QTBUG_20699_focusScopeCrash() { QGraphicsScene scene; QGraphicsView view(&scene); + view.setWindowTitle(QLatin1String(QTest::currentTestFunction())); QGraphicsPixmapItem fs; fs.setFlags(QGraphicsItem::ItemIsFocusScope | QGraphicsItem::ItemIsFocusable); scene.addItem(&fs); diff --git a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index 5ac3834aef..e21b1b889a 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -2610,11 +2610,6 @@ void tst_QGraphicsView::optimizationFlags() QGraphicsView view; QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlag(QGraphicsView::DontClipPainter); - QVERIFY(view.optimizationFlags() & QGraphicsView::DontClipPainter); - view.setOptimizationFlag(QGraphicsView::DontClipPainter, false); - QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlag(QGraphicsView::DontSavePainterState); QVERIFY(view.optimizationFlags() & QGraphicsView::DontSavePainterState); view.setOptimizationFlag(QGraphicsView::DontSavePainterState, false); @@ -2625,10 +2620,8 @@ void tst_QGraphicsView::optimizationFlags() view.setOptimizationFlag(QGraphicsView::DontAdjustForAntialiasing, false); QVERIFY(!view.optimizationFlags()); - view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing - | QGraphicsView::DontClipPainter); - QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing - | QGraphicsView::DontClipPainter)); + view.setOptimizationFlags(QGraphicsView::DontAdjustForAntialiasing); + QCOMPARE(view.optimizationFlags(), QGraphicsView::OptimizationFlags(QGraphicsView::DontAdjustForAntialiasing)); } class MessUpPainterItem : public QGraphicsRectItem diff --git a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp index 35c0c6c606..09990ab70a 100644 --- a/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp +++ b/tests/auto/widgets/itemviews/qtableview/tst_qtableview.cpp @@ -26,19 +26,24 @@ ** ****************************************************************************/ - -#include <QtGui/QtGui> -#include <QtWidgets/QtWidgets> +#include <QIdentityProxyModel> +#include <QLabel> +#include <QLineEdit> +#include <QScrollBar> +#include <QSignalSpy> +#include <QSortFilterProxyModel> +#include <QStandardItemModel> +#include <QStringListModel> +#include <QStyledItemDelegate> +#include <QTableView> +#include <QTest> +#include <private/qapplication_p.h> #include <private/qtablewidget_p.h> -#include <QtTest/QtTest> -#include "private/qapplication_p.h" +#include <private/qtesthelpers_p.h> #if QT_CONFIG(textmarkdownwriter) -#include "private/qtextmarkdownwriter_p.h" +#include <private/qtextmarkdownwriter_p.h> #endif -#include <algorithm> - -#include <QtTest/private/qtesthelpers_p.h> using namespace QTestPrivate; @@ -49,14 +54,241 @@ using namespace QTestPrivate; #define VERIFY_SPANS_CONSISTENCY(TEST_VIEW_) (void)false #endif -typedef QList<int> IntList; +Q_DECLARE_METATYPE(Qt::Key); +Q_DECLARE_METATYPE(Qt::KeyboardModifier); +Q_DECLARE_METATYPE(QItemSelectionModel::SelectionFlag); +using BoolList = QVector<bool>; +using IntList = QVector<int>; +using KeyList = QVector<Qt::Key>; +using SpanList = QVector<QRect>; + +class QtTestTableModel: public QAbstractTableModel +{ + Q_OBJECT + +signals: + void invalidIndexEncountered() const; + +public slots: + bool submit() override { ++submit_count; return QAbstractTableModel::submit(); } + +public: + QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = nullptr) + : QAbstractTableModel(parent), row_count(rows), column_count(columns) + {} + + int rowCount(const QModelIndex& = QModelIndex()) const override + { + return row_count; + } + + int columnCount(const QModelIndex& = QModelIndex()) const override + { + return column_count; + } + + bool isEditable(const QModelIndex &) const { return true; } + + Qt::ItemFlags flags(const QModelIndex &index) const override + { + Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); + if (disabled_rows.contains(index.row()) + || disabled_columns.contains(index.column())) + index_flags &= ~Qt::ItemIsEnabled; + return index_flags; + } + + void disableRow(int row) + { + disabled_rows.insert(row); + } + + void enableRow(int row) + { + disabled_rows.remove(row); + } + + void disableColumn(int column) + { + disabled_columns.insert(column); + } + + void enableColumn(int column) + { + disabled_columns.remove(column); + } + + QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const override + { + if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { + qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; + emit invalidIndexEncountered(); + return QVariant(); + } + + if (role == Qt::DisplayRole || role == Qt::EditRole) { + return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') + + QString::number(idx.column()) + QLatin1String(",0]"); + } + + return QVariant(); + } + + bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start > row_count) + return false; + + beginInsertRows(parent, start, start + count - 1); + row_count += count; + endInsertRows(); + return true; + } + + bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start >= row_count || row_count < count) + return false; + + beginRemoveRows(parent, start, start + count - 1); + row_count -= count; + endRemoveRows(); + return true; + } + + void removeLastRow() + { + beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); + --row_count; + endRemoveRows(); + } + + void removeAllRows() + { + beginRemoveRows(QModelIndex(), 0, row_count - 1); + row_count = 0; + endRemoveRows(); + } + + bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start > column_count) + return false; + + beginInsertColumns(parent, start, start + count - 1); + column_count += count; + endInsertColumns(); + return true; + } + + bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) override + { + if (start < 0 || start >= column_count || column_count < count) + return false; + + beginRemoveColumns(parent, start, start + count - 1); + column_count -= count; + endRemoveColumns(); + return true; + } + + void removeLastColumn() + { + beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); + --column_count; + endRemoveColumns(); + } + + void removeAllColumns() + { + beginRemoveColumns(QModelIndex(), 0, column_count - 1); + column_count = 0; + endRemoveColumns(); + } + + bool canFetchMore(const QModelIndex &) const override + { + return can_fetch_more; + } + + void fetchMore(const QModelIndex &) override + { + ++fetch_more_count; + } -typedef QList<bool> BoolList; + QSet<int> disabled_rows; + QSet<int> disabled_columns; + int row_count; + int column_count; + int submit_count = 0; + int fetch_more_count = 0; + bool can_fetch_more = false; +}; + +class QtTestTableView : public QTableView +{ + Q_OBJECT +public: + using QTableView::QTableView; + + void setModel(QAbstractItemModel *model) override + { + QTableView::setModel(model); + connect(selectionModel(), &QItemSelectionModel::currentChanged, + this, &QtTestTableView::slotCurrentChanged); + connect(selectionModel(), &QItemSelectionModel::selectionChanged, + this, &QtTestTableView::itemSelectionChanged); + // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes. + horizontalHeader()->setMinimumSectionSize(0); + verticalHeader()->setMinimumSectionSize(0); + } + + using QTableView::moveCursor; + using QTableView::isIndexHidden; + using QTableView::setSelection; + using QTableView::selectedIndexes; + using QTableView::sizeHintForRow; + using QTableView::viewOptions; + + bool checkSignalOrder = false; +public slots: + void slotCurrentChanged(QModelIndex, QModelIndex) { + hasCurrentChanged++; + if (checkSignalOrder) + QVERIFY(hasCurrentChanged > hasSelectionChanged); + } + + void itemSelectionChanged(QItemSelection , QItemSelection ) { + hasSelectionChanged++; + if (checkSignalOrder) + QVERIFY(hasCurrentChanged >= hasSelectionChanged); + } +private: + int hasCurrentChanged = 0; + int hasSelectionChanged = 0; + + friend class tst_QTableView; + friend struct QMetaTypeId<QtTestTableView::CursorAction>; +}; +Q_DECLARE_METATYPE(QtTestTableView::CursorAction); + +class QtTestItemDelegate : public QStyledItemDelegate +{ +public: + QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override + { + return hint; + } + + QSize hint; +}; class tst_QTableView : public QObject { Q_OBJECT +private: + using CursorActionList = QVector<QtTestTableView::CursorAction>; private slots: void getSetCheck(); @@ -236,14 +468,14 @@ void tst_QTableView::getSetCheck() QHeaderView *var1 = new QHeaderView(Qt::Horizontal); obj1.setHorizontalHeader(var1); QCOMPARE(var1, obj1.horizontalHeader()); - obj1.setHorizontalHeader((QHeaderView *)0); + obj1.setHorizontalHeader(nullptr); QCOMPARE(var1, obj1.horizontalHeader()); delete var1; QHeaderView *var2 = new QHeaderView(Qt::Vertical); obj1.setVerticalHeader(var2); QCOMPARE(var2, obj1.verticalHeader()); - obj1.setVerticalHeader((QHeaderView *)0); + obj1.setVerticalHeader(nullptr); QCOMPARE(var2, obj1.verticalHeader()); delete var2; @@ -251,283 +483,12 @@ void tst_QTableView::getSetCheck() obj1.setCornerButtonEnabled(false); QCOMPARE(obj1.isCornerButtonEnabled(), false); } - -class QtTestTableModel: public QAbstractTableModel -{ - Q_OBJECT - -signals: - void invalidIndexEncountered() const; - -public slots: - bool submit() { ++submit_count; return QAbstractTableModel::submit(); } - -public: - QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) - : QAbstractTableModel(parent), - row_count(rows), - column_count(columns), - submit_count(0), - can_fetch_more(false), - fetch_more_count(0), - disabled_rows(), - disabled_columns() {} - - int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } - int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } - bool isEditable(const QModelIndex &) const { return true; } - - Qt::ItemFlags flags(const QModelIndex &index) const - { - Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); - if (disabled_rows.contains(index.row()) - || disabled_columns.contains(index.column())) - index_flags &= ~Qt::ItemIsEnabled; - return index_flags; - } - - void disableRow(int row) - { - disabled_rows.insert(row); - } - - void enableRow(int row) - { - disabled_rows.remove(row); - } - - void disableColumn(int column) - { - disabled_columns.insert(column); - } - - void enableColumn(int column) - { - disabled_columns.remove(column); - } - - QVariant data(const QModelIndex &idx, int role) const - { - if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { - qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; - emit invalidIndexEncountered(); - return QVariant(); - } - - if (role == Qt::DisplayRole || role == Qt::EditRole) { - return QLatin1Char('[') + QString::number(idx.row()) + QLatin1Char(',') - + QString::number(idx.column()) + QLatin1String(",0]"); - } - - return QVariant(); - } - - bool insertRows(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start > row_count) - return false; - - beginInsertRows(parent, start, start + count - 1); - row_count += count; - endInsertRows(); - return true; - } - - bool removeRows(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start >= row_count || row_count < count) - return false; - - beginRemoveRows(parent, start, start + count - 1); - row_count -= count; - endRemoveRows(); - return true; - } - - void removeLastRow() - { - beginRemoveRows(QModelIndex(), row_count - 1, row_count - 1); - --row_count; - endRemoveRows(); - } - - void removeAllRows() - { - beginRemoveRows(QModelIndex(), 0, row_count - 1); - row_count = 0; - endRemoveRows(); - } - - bool insertColumns(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start > column_count) - return false; - - beginInsertColumns(parent, start, start + count - 1); - column_count += count; - endInsertColumns(); - return true; - } - - bool removeColumns(int start, int count, const QModelIndex &parent = QModelIndex()) - { - if (start < 0 || start >= column_count || column_count < count) - return false; - - beginRemoveColumns(parent, start, start + count - 1); - column_count -= count; - endRemoveColumns(); - return true; - } - - void removeLastColumn() - { - beginRemoveColumns(QModelIndex(), column_count - 1, column_count - 1); - --column_count; - endRemoveColumns(); - } - - void removeAllColumns() - { - beginRemoveColumns(QModelIndex(), 0, column_count - 1); - column_count = 0; - endRemoveColumns(); - } - - bool canFetchMore(const QModelIndex &) const - { - return can_fetch_more; - } - - void fetchMore(const QModelIndex &) - { - ++fetch_more_count; - } - - void reset() - { - beginResetModel(); - endResetModel(); - } - - int row_count; - int column_count; - int submit_count; - bool can_fetch_more; - int fetch_more_count; - QSet<int> disabled_rows; - QSet<int> disabled_columns; -}; - -class QtTestTableView : public QTableView -{ -Q_OBJECT - -public: - QtTestTableView(QWidget *parent = 0) : QTableView(parent), checkSignalOrder(false), hasCurrentChanged(0), hasSelectionChanged(0) {} - - void setModel(QAbstractItemModel *model) - { - QTableView::setModel(model); - connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), - this, SLOT(slotCurrentChanged(QModelIndex,QModelIndex))); - connect(selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), - this, SLOT(itemSelectionChanged(QItemSelection,QItemSelection))); - // Allow small sections in this test, since this test was made before we correctly enforced minimum sizes. - horizontalHeader()->setMinimumSectionSize(0); - verticalHeader()->setMinimumSectionSize(0); - } - - // enum CursorAction and moveCursor() are protected in QTableView. - enum CursorAction { - MoveUp = QAbstractItemView::MoveUp, - MoveDown = QAbstractItemView::MoveDown, - MoveLeft = QAbstractItemView::MoveLeft, - MoveRight = QAbstractItemView::MoveRight, - MoveHome = QAbstractItemView::MoveHome, - MoveEnd = QAbstractItemView::MoveEnd, - MovePageUp = QAbstractItemView::MovePageUp, - MovePageDown = QAbstractItemView::MovePageDown, - MoveNext = QAbstractItemView::MoveNext, - MovePrevious = QAbstractItemView::MovePrevious - }; - - QModelIndex doMoveCursor(QtTestTableView::CursorAction cursorAction, - Qt::KeyboardModifiers modifiers) - { - return QTableView::moveCursor((QAbstractItemView::CursorAction)cursorAction, modifiers); - } - - int columnWidthHint(int column) const - { - return sizeHintForColumn(column); - } - - int rowHeightHint(int row) const - { - return sizeHintForRow(row); - } - - bool isIndexHidden(const QModelIndex &index) const - { - return QTableView::isIndexHidden(index); - } - - void setSelection(const QRect &rect, QItemSelectionModel::SelectionFlags command) - { - QTableView::setSelection(rect, command); - } - - QModelIndexList selectedIndexes() const - { - return QTableView::selectedIndexes(); - } - - int sizeHintForRow(int row) const - { - return QTableView::sizeHintForRow(row); - } - - QStyleOptionViewItem viewOptions() const { - return QTableView::viewOptions(); - } - - bool checkSignalOrder; -public slots: - void slotCurrentChanged(QModelIndex, QModelIndex) { - hasCurrentChanged++; - if (checkSignalOrder) - QVERIFY(hasCurrentChanged > hasSelectionChanged); - } - - void itemSelectionChanged(QItemSelection , QItemSelection ) { - hasSelectionChanged++; - if (checkSignalOrder) - QVERIFY(hasCurrentChanged >= hasSelectionChanged); - } -private: - int hasCurrentChanged; - int hasSelectionChanged; - -}; - -class QtTestItemDelegate : public QItemDelegate -{ -public: - QSize sizeHint(const QStyleOptionViewItem&, const QModelIndex&) const - { - return hint; - } - - QSize hint; -}; - void tst_QTableView::noDelegate() { QtTestTableModel model(3, 3); QTableView view; view.setModel(&model); - view.setItemDelegate(0); + view.setItemDelegate(nullptr); view.show(); } @@ -541,7 +502,7 @@ void tst_QTableView::emptyModel() { QtTestTableModel model; QTableView view; - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); view.setModel(&model); view.show(); QCOMPARE(spy.count(), 0); @@ -562,7 +523,7 @@ void tst_QTableView::removeRows() QFETCH(int, columnCount); QtTestTableModel model(rowCount, columnCount); - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); QTableView view; view.setModel(&model); @@ -590,7 +551,7 @@ void tst_QTableView::removeColumns() QFETCH(int, columnCount); QtTestTableModel model(rowCount, columnCount); - QSignalSpy spy(&model, SIGNAL(invalidIndexEncountered())); + QSignalSpy spy(&model, &QtTestTableModel::invalidIndexEncountered); QTableView view; view.setModel(&model); @@ -608,58 +569,18 @@ void tst_QTableView::keyboardNavigation_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<bool>("tabKeyNavigation"); - QTest::addColumn<IntList>("keyPresses"); - - QTest::newRow("16x16 model") << 16 << 16 << true - << (IntList() - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Right - << Qt::Key_Right - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Down - << Qt::Key_Tab - << Qt::Key_Backtab); - - - QTest::newRow("no tab") << 8 << 8 << false - << (IntList() - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Right - << Qt::Key_Right - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Up - << Qt::Key_Left - << Qt::Key_Left - << Qt::Key_Up - << Qt::Key_Down - << Qt::Key_Down - << Qt::Key_Tab - << Qt::Key_Backtab); + QTest::addColumn<KeyList>("keyPresses"); + + const KeyList keyList { + Qt::Key_Up, Qt::Key_Up, Qt::Key_Right, Qt::Key_Right, + Qt::Key_Up, Qt::Key_Left, Qt::Key_Left, Qt::Key_Up, + Qt::Key_Down, Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, + Qt::Key_Up, Qt::Key_Up, Qt::Key_Up, Qt::Key_Left, + Qt::Key_Left, Qt::Key_Up, Qt::Key_Down, Qt::Key_Down, + Qt::Key_Tab, Qt::Key_Backtab}; + + QTest::newRow("16x16 model") << 16 << 16 << true << keyList; + QTest::newRow("no tab") << 8 << 8 << false << keyList; } void tst_QTableView::keyboardNavigation() @@ -667,7 +588,7 @@ void tst_QTableView::keyboardNavigation() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(bool, tabKeyNavigation); - QFETCH(IntList, keyPresses); + QFETCH(const KeyList, keyPresses); QtTestTableModel model(rowCount, columnCount); QTableView view; @@ -678,14 +599,12 @@ void tst_QTableView::keyboardNavigation() view.setCurrentIndex(index); view.show(); - qApp->setActiveWindow(&view); + QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); int row = rowCount - 1; int column = columnCount - 1; - for (int i = 0; i < keyPresses.count(); ++i) { - - Qt::Key key = (Qt::Key)keyPresses.at(i); + for (Qt::Key key : keyPresses) { switch (key) { case Qt::Key_Up: @@ -785,8 +704,8 @@ void tst_QTableView::moveCursor_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("startColumn"); - QTest::addColumn<int>("cursorMoveAction"); - QTest::addColumn<int>("modifier"); + QTest::addColumn<QtTestTableView::CursorAction>("cursorMoveAction"); + QTest::addColumn<Qt::KeyboardModifier>("modifier"); QTest::addColumn<int>("expectedRow"); QTest::addColumn<int>("expectedColumn"); @@ -797,346 +716,346 @@ void tst_QTableView::moveCursor_data() QTest::newRow("MoveRight (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight (3,0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 3 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); // ### QTest::newRow("MoveRight, hidden column 1 (0,0)") << 4 << 4 << -1 << 1 << 0 << 0 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveRight, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MoveRight) << int(Qt::NoModifier) + << QtTestTableView::MoveRight << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); // ### // MoveNext should in addition wrap QTest::newRow("MoveNext (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext (0,2)") << 4 << 4 << -1 << -1 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, hidden column 1 (0,0)") << 4 << 4 << -1 << 1 << 0 << 0 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 3 (3,2)") << 4 << 4 << -1 << 3 << 3 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrapy, wrapx, hidden column 3, hidden row 3 (2,2)") << 4 << 4 << 3 << 3 << 2 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveNext, wrap, hidden column 2, moved column from 3 to 0. (0,2)") << 4 << 4 << -1 << 2 << 0 << 2 - << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) + << QtTestTableView::MoveNext << Qt::NoModifier << 1 << 3 << IntPair(0,0) << IntPair(3,0); // MoveLeft QTest::newRow("MoveLeft (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft (1,0)") << 4 << 4 << -1 << -1 << 1 << 0 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft, hidden column 0 (0,2)") << 4 << 4 << -1 << 1 << 0 << 2 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveLeft, hidden column 0 (0,1)") << 4 << 4 << -1 << 0 << 0 << 1 - << int(QtTestTableView::MoveLeft) << int(Qt::NoModifier) + << QtTestTableView::MoveLeft << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); // MovePrevious should in addition wrap QTest::newRow("MovePrevious (0,3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious (0,1)") << 4 << 4 << -1 << -1 << 0 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap (1,0)") << 4 << 4 << -1 << -1 << 1 << 0 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, hidden column 1 (0,2)") << 4 << 4 << -1 << 1 << 0 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 3 (0,2)") << 4 << 4 << -1 << 3 << 0 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrapy, hidden column 0 (0,1)") << 4 << 4 << -1 << 0 << 0 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 0, hidden row 0 (1,1)") << 4 << 4 << 0 << 0 << 1 << 1 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePrevious, wrap, hidden column 1, moved column from 0 to 3. (1,2)") << 4 << 4 << -1 << 1 << 1 << 2 - << int(QtTestTableView::MovePrevious) << int(Qt::NoModifier) + << QtTestTableView::MovePrevious << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,3); // MoveDown QTest::newRow("MoveDown (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown (3,0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 3 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 1 (0,0)") << 4 << 4 << 1 << -1 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 3 (2,0)") << 4 << 4 << 3 << -1 << 2 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveDown, hidden row 0 hidden column 0 (0,0)") << 4 << 4 << 0 << 0 << 0 << 0 - << int(QtTestTableView::MoveDown) << int(Qt::NoModifier) + << QtTestTableView::MoveDown << Qt::NoModifier << 1 << 1 << IntPair(0,0) << IntPair(0,0); // MoveUp QTest::newRow("MoveUp (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp (3, 0)") << 4 << 4 << -1 << -1 << 3 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 2 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp (0,1)") << 4 << 4 << -1 << -1 << 0 << 1 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 1 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp, hidden row 1 (2,0)") << 4 << 4 << 1 << -1 << 2 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveUp, hidden row (1,0)") << 4 << 4 << 0 << -1 << 1 << 0 - << int(QtTestTableView::MoveUp) << int(Qt::NoModifier) + << QtTestTableView::MoveUp << Qt::NoModifier << 1 << 0 << IntPair(0,0) << IntPair(0,0); // MoveHome QTest::newRow("MoveHome (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 3 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome, hidden column 0 (3,3)") << 4 << 4 << -1 << 0 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::NoModifier) + << QtTestTableView::MoveHome << Qt::NoModifier << 3 << 1 << IntPair(0,0) << IntPair(0,0); // Use Ctrl modifier QTest::newRow("MoveHome + Ctrl (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome + Ctrl (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveHome + Ctrl, hidden column 0, hidden row 0 (3,3)") << 4 << 4 << 0 << 0 << 3 << 3 - << int(QtTestTableView::MoveHome) << int(Qt::ControlModifier) + << QtTestTableView::MoveHome << Qt::ControlModifier << 1 << 1 << IntPair(0,0) << IntPair(0,0); // MoveEnd QTest::newRow("MoveEnd (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd, hidden column (0,0)") << 4 << 4 << -1 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::NoModifier) + << QtTestTableView::MoveEnd << Qt::NoModifier << 0<< 2 << IntPair(0,0) << IntPair(0,0); // Use Ctrl modifier QTest::newRow("MoveEnd + Ctrl (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl, hidden column 3 (0,0)") << 4 << 4 << -1 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 3 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MoveEnd + Ctrl, hidden column 3, hidden row 3 (0,0)") << 4 << 4 << 3 << 3 << 0 << 0 - << int(QtTestTableView::MoveEnd) << int(Qt::ControlModifier) + << QtTestTableView::MoveEnd << Qt::ControlModifier << 2 << 2 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageUp (0,0)") << 4 << 4 << -1 << -1 << 0 << 0 - << int(QtTestTableView::MovePageUp) << 0 + << QtTestTableView::MovePageUp << Qt::NoModifier << 0 << 0 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageUp (3,3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MovePageUp) << 0 + << QtTestTableView::MovePageUp << Qt::NoModifier << 0 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageDown (3, 3)") << 4 << 4 << -1 << -1 << 3 << 3 - << int(QtTestTableView::MovePageDown) << 0 + << QtTestTableView::MovePageDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); QTest::newRow("MovePageDown (0, 3)") << 4 << 4 << -1 << -1 << 0 << 3 - << int(QtTestTableView::MovePageDown) << 0 + << QtTestTableView::MovePageDown << Qt::NoModifier << 3 << 3 << IntPair(0,0) << IntPair(0,0); } @@ -1148,8 +1067,8 @@ void tst_QTableView::moveCursor() QFETCH(int, hideColumn); QFETCH(int, startRow); QFETCH(int, startColumn); - QFETCH(int, cursorMoveAction); - QFETCH(int, modifier); + QFETCH(QtTestTableView::CursorAction, cursorMoveAction); + QFETCH(Qt::KeyboardModifier, modifier); QFETCH(int, expectedRow); QFETCH(int, expectedColumn); QFETCH(IntPair, moveRow); @@ -1174,8 +1093,7 @@ void tst_QTableView::moveCursor() QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); - QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, - (Qt::KeyboardModifiers)modifier); + QModelIndex newIndex = view.moveCursor(cursorMoveAction, modifier); // expected fails, task 119433 if(newIndex.row() == -1) return; @@ -1193,7 +1111,7 @@ void tst_QTableView::moveCursorStrikesBack_data() QTest::addColumn<int>("startRow"); QTest::addColumn<int>("startColumn"); - QTest::addColumn<IntList>("cursorMoveActions"); + QTest::addColumn<CursorActionList>("cursorMoveActions"); QTest::addColumn<int>("expectedRow"); QTest::addColumn<int>("expectedColumn"); @@ -1201,70 +1119,84 @@ void tst_QTableView::moveCursorStrikesBack_data() << IntList() << (IntList() << 6) << QRect() - << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext)) + << 0 << 5 + << CursorActionList{QtTestTableView::MoveNext} << 1 << 0; QTest::newRow("Last column disabled 2. Task QTBUG-3878") << -1 << -1 << IntList() << (IntList() << 6) << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << 1 << 0 + << CursorActionList{QtTestTableView::MovePrevious} << 0 << 5; QTest::newRow("Span, anchor column hidden") << -1 << 1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 0 + << CursorActionList{QtTestTableView::MoveNext} << 2 << 1; QTest::newRow("Span, anchor column disabled") << -1 << -1 << IntList() << (IntList() << 1) << QRect(1, 2, 2, 3) - << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 0 + << CursorActionList{QtTestTableView::MoveNext} << 2 << 1; QTest::newRow("Span, anchor row hidden") << 2 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown} << 2 << 1; QTest::newRow("Span, anchor row disabled") << -1 << -1 << (IntList() << 2) << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown} << 2 << 1; QTest::newRow("Move through span right") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight)) + << 3 << 0 + << CursorActionList{QtTestTableView::MoveRight, + QtTestTableView::MoveRight} << 3 << 3; QTest::newRow("Move through span left") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft)) + << 3 << 3 + << CursorActionList{QtTestTableView::MoveLeft, + QtTestTableView::MoveLeft} << 3 << 0; QTest::newRow("Move through span down") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown)) + << 1 << 2 + << CursorActionList{QtTestTableView::MoveDown, + QtTestTableView::MoveDown} << 5 << 2; QTest::newRow("Move through span up") << -1 << -1 << IntList() << IntList() << QRect(1, 2, 2, 3) - << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp)) + << 5 << 2 + << CursorActionList{QtTestTableView::MoveUp, + QtTestTableView::MoveUp} << 1 << 2; IntList fullList; @@ -1275,42 +1207,48 @@ void tst_QTableView::moveCursorStrikesBack_data() << fullList << fullList << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 1 << 0 + << CursorActionList{QtTestTableView::MoveNext} << -1 << -1; QTest::newRow("All disabled, wrap backwards. => invalid index") << -1 << -1 << fullList << fullList << QRect() - << 1 << 0 << (IntList() << int(QtTestTableView::MovePrevious)) + << 1 << 0 + << CursorActionList{QtTestTableView::MovePrevious} << -1 << -1; QTest::newRow("Last column disabled, MoveEnd. QTBUG-72400") << -1 << -1 << IntList() << (IntList() << 6) << QRect() - << 0 << 0 << (IntList() << int(QtTestTableView::MoveEnd)) + << 0 << 0 + << CursorActionList{QtTestTableView::MoveEnd} << 0 << 5; QTest::newRow("First column disabled, MoveHome. QTBUG-72400") << -1 << -1 << IntList() << (IntList() << 0) << QRect() - << 0 << 6 << (IntList() << int(QtTestTableView::MoveHome)) + << 0 << 6 + << CursorActionList{QtTestTableView::MoveHome} << 0 << 1; QTest::newRow("First row disabled, MovePageUp. QTBUG-72400") << -1 << -1 << (IntList() << 0) << IntList() << QRect() - << 2 << 0 << (IntList() << int(QtTestTableView::MovePageUp)) + << 2 << 0 + << CursorActionList{QtTestTableView::MovePageUp} << 1 << 0; QTest::newRow("Last row disabled, MovePageDown. QTBUG-72400") << -1 << -1 << (IntList() << 6) << IntList() << QRect() - << 4 << 0 << (IntList() << int(QtTestTableView::MovePageDown)) + << 4 << 0 + << CursorActionList{QtTestTableView::MovePageDown} << 5 << 0; } @@ -1318,13 +1256,13 @@ void tst_QTableView::moveCursorStrikesBack() { QFETCH(int, hideRow); QFETCH(int, hideColumn); - QFETCH(IntList, disableRows); - QFETCH(IntList, disableColumns); + QFETCH(const IntList, disableRows); + QFETCH(const IntList, disableColumns); QFETCH(QRect, span); QFETCH(int, startRow); QFETCH(int, startColumn); - QFETCH(IntList, cursorMoveActions); + QFETCH(const CursorActionList, cursorMoveActions); QFETCH(int, expectedRow); QFETCH(int, expectedColumn); @@ -1344,15 +1282,15 @@ void tst_QTableView::moveCursorStrikesBack() QModelIndex index = model.index(startRow, startColumn); view.setCurrentIndex(index); - foreach (int row, disableRows) + for (int row : disableRows) model.disableRow(row); - foreach (int column, disableColumns) + for (int column : disableColumns) model.disableColumn(column); int newRow = -1; int newColumn = -1; - foreach (int cursorMoveAction, cursorMoveActions) { - QModelIndex newIndex = view.doMoveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0); + for (auto cursorMoveAction : cursorMoveActions) { + QModelIndex newIndex = view.moveCursor(cursorMoveAction, nullptr); view.setCurrentIndex(newIndex); newRow = newIndex.row(); newColumn = newIndex.column(); @@ -1523,7 +1461,7 @@ void tst_QTableView::selection_data() QTest::addColumn<int>("y"); QTest::addColumn<int>("width"); QTest::addColumn<int>("height"); - QTest::addColumn<int>("command"); + QTest::addColumn<QItemSelectionModel::SelectionFlag>("command"); QTest::addColumn<int>("selectedCount"); // ### make this more detailed QTest::newRow("no span, no hidden, no moved, 3x3 select") @@ -1535,7 +1473,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("row span, no hidden, no moved, 3x3 select") @@ -1547,7 +1485,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 8; // selected count QTest::newRow("col span, no hidden, no moved, 3x3 select") @@ -1559,7 +1497,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 8; // selected count QTest::newRow("no span, row hidden, no moved, 3x3 select") @@ -1571,7 +1509,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, col hidden, no moved, 3x3 select") @@ -1583,7 +1521,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, no hidden, row moved, 3x3 select") @@ -1595,7 +1533,7 @@ void tst_QTableView::selection_data() << -1 << -1 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count QTest::newRow("no span, no hidden, col moved, 3x3 select") @@ -1607,7 +1545,7 @@ void tst_QTableView::selection_data() << 1 << 3 // move col << 40 << 40 // cell size << 20 << 20 << 80 << 80 // rect - << int(QItemSelectionModel::Select) // command + << QItemSelectionModel::Select // command << 9; // selected count } @@ -1631,7 +1569,7 @@ void tst_QTableView::selection() QFETCH(int, y); QFETCH(int, width); QFETCH(int, height); - QFETCH(int, command); + QFETCH(QItemSelectionModel::SelectionFlag, command); QFETCH(int, selectedCount); QtTestTableModel model(rowCount, columnCount); @@ -1653,8 +1591,7 @@ void tst_QTableView::selection() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - view.setSelection(QRect(x, y, width, height), - QItemSelectionModel::SelectionFlags(command)); + view.setSelection(QRect(x, y, width, height), command); QCOMPARE(view.selectedIndexes().count(), selectedCount); } @@ -1664,92 +1601,92 @@ void tst_QTableView::selectRow_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("row"); - QTest::addColumn<int>("mode"); - QTest::addColumn<int>("behavior"); + QTest::addColumn<QAbstractItemView::SelectionMode>("mode"); + QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior"); QTest::addColumn<int>("selectedItems"); QTest::newRow("SingleSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectItems << 0; QTest::newRow("SingleSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("SingleSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("MultiSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("MultiSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("MultiSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("ExtendedSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ExtendedSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("ExtendedSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectColumns << 0; QTest::newRow("ContiguousSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ContiguousSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectRows << 10; QTest::newRow("ContiguousSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectColumns << 0; } @@ -1758,16 +1695,16 @@ void tst_QTableView::selectRow() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, row); - QFETCH(int, mode); - QFETCH(int, behavior); + QFETCH(QAbstractItemView::SelectionMode, mode); + QFETCH(QAbstractItemView::SelectionBehavior, behavior); QFETCH(int, selectedItems); QtTestTableModel model(rowCount, columnCount); QTableView view; view.setModel(&model); - view.setSelectionMode((QAbstractItemView::SelectionMode)mode); - view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); + view.setSelectionMode(mode); + view.setSelectionBehavior(behavior); QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); @@ -1785,92 +1722,92 @@ void tst_QTableView::selectColumn_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("column"); - QTest::addColumn<int>("mode"); - QTest::addColumn<int>("behavior"); + QTest::addColumn<QAbstractItemView::SelectionMode>("mode"); + QTest::addColumn<QAbstractItemView::SelectionBehavior>("behavior"); QTest::addColumn<int>("selectedItems"); QTest::newRow("SingleSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectItems << 0; QTest::newRow("SingleSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("SingleSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::SingleSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::SingleSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("MultiSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("MultiSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("MultiSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::MultiSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::MultiSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("ExtendedSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ExtendedSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("ExtendedSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ExtendedSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ExtendedSelection + << QAbstractItemView::SelectColumns << 10; QTest::newRow("ContiguousSelection and SelectItems") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectItems + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectItems << 10; QTest::newRow("ContiguousSelection and SelectRows") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectRows + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectRows << 0; QTest::newRow("ContiguousSelection and SelectColumns") << 10 << 10 << 0 - << (int)QAbstractItemView::ContiguousSelection - << (int)QAbstractItemView::SelectColumns + << QAbstractItemView::ContiguousSelection + << QAbstractItemView::SelectColumns << 10; } @@ -1879,16 +1816,16 @@ void tst_QTableView::selectColumn() QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, column); - QFETCH(int, mode); - QFETCH(int, behavior); + QFETCH(QAbstractItemView::SelectionMode, mode); + QFETCH(QAbstractItemView::SelectionBehavior, behavior); QFETCH(int, selectedItems); QtTestTableModel model(rowCount, columnCount); QTableView view; view.setModel(&model); - view.setSelectionMode((QAbstractItemView::SelectionMode)mode); - view.setSelectionBehavior((QAbstractItemView::SelectionBehavior)behavior); + view.setSelectionMode(mode); + view.setSelectionBehavior(behavior); QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); @@ -1988,9 +1925,9 @@ void tst_QTableView::selectall_data() << 100; // selected count } -void QTest__keySequence(QWidget* widget, QKeySequence ks) +void QTest__keySequence(QWidget* widget, const QKeySequence &ks) { - for (int i=0; i<ks.count(); ++i) + for (int i = 0; i < ks.count(); ++i) { Qt::Key key = Qt::Key(ks[i] & ~Qt::KeyboardModifierMask); Qt::KeyboardModifiers modifiers = Qt::KeyboardModifiers(ks[i] & Qt::KeyboardModifierMask); @@ -2228,7 +2165,7 @@ void tst_QTableView::resizeRowsToContents() QFETCH(int, cellHeight); QFETCH(int, rowHeight); QFETCH(int, columnWidth); - Q_UNUSED(columnWidth); + Q_UNUSED(columnWidth) QtTestTableModel model(rowCount, columnCount); QtTestTableView view; @@ -2240,13 +2177,12 @@ void tst_QTableView::resizeRowsToContents() delegate.hint = QSize(cellWidth, cellHeight); - QSignalSpy resizedSpy(view.verticalHeader(), SIGNAL(sectionResized(int,int,int))); + QSignalSpy resizedSpy(view.verticalHeader(), &QHeaderView::sectionResized); view.resizeRowsToContents(); QCOMPARE(resizedSpy.count(), model.rowCount()); - for (int r = 0; r < model.rowCount(); ++r) { + for (int r = 0; r < model.rowCount(); ++r) QCOMPARE(view.rowHeight(r), rowHeight); - } } void tst_QTableView::resizeColumnsToContents_data() @@ -2275,7 +2211,7 @@ void tst_QTableView::resizeColumnsToContents() QFETCH(int, cellHeight); QFETCH(int, rowHeight); QFETCH(int, columnWidth); - Q_UNUSED(rowHeight); + Q_UNUSED(rowHeight) QtTestTableModel model(rowCount, columnCount); QtTestTableView view; @@ -2287,7 +2223,7 @@ void tst_QTableView::resizeColumnsToContents() delegate.hint = QSize(cellWidth, cellHeight); - QSignalSpy resizedSpy(view.horizontalHeader(), SIGNAL(sectionResized(int,int,int))); + QSignalSpy resizedSpy(view.horizontalHeader(), &QHeaderView::sectionResized); view.resizeColumnsToContents(); QCOMPARE(resizedSpy.count(), model.columnCount()); @@ -2300,51 +2236,51 @@ void tst_QTableView::rowViewportPosition_data() QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("rowHeight"); QTest::addColumn<int>("row"); - QTest::addColumn<int>("verticalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode"); QTest::addColumn<int>("verticalScrollValue"); QTest::addColumn<int>("rowViewportPosition"); QTest::newRow("row 0, scroll per item 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0; QTest::newRow("row 1, scroll per item, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40; QTest::newRow("row 1, scroll per item, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0; QTest::newRow("row 5, scroll per item, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40; QTest::newRow("row 5, scroll per item, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0; QTest::newRow("row 9, scroll per item, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40; QTest::newRow("row 9, scroll per item, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40; QTest::newRow("row 0, scroll per pixel 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0; QTest::newRow("row 1, scroll per pixel, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40; QTest::newRow("row 1, scroll per pixel, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0; QTest::newRow("row 5, scroll per pixel, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40; QTest::newRow("row 5, scroll per pixel, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0; QTest::newRow("row 9, scroll per pixel, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40; QTest::newRow("row 9, scroll per pixel, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40; } void tst_QTableView::rowViewportPosition() @@ -2352,7 +2288,7 @@ void tst_QTableView::rowViewportPosition() QFETCH(int, rowCount); QFETCH(int, rowHeight); QFETCH(int, row); - QFETCH(int, verticalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode); QFETCH(int, verticalScrollValue); QFETCH(int, rowViewportPosition); @@ -2366,7 +2302,7 @@ void tst_QTableView::rowViewportPosition() for (int r = 0; r < rowCount; ++r) view.setRowHeight(r, rowHeight); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); + view.setVerticalScrollMode(verticalScrollMode); view.verticalScrollBar()->setValue(verticalScrollValue); #ifdef Q_OS_WINRT @@ -2471,51 +2407,51 @@ void tst_QTableView::columnViewportPosition_data() QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("columnWidth"); QTest::addColumn<int>("column"); - QTest::addColumn<int>("horizontalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode"); QTest::addColumn<int>("horizontalScrollValue"); QTest::addColumn<int>("columnViewportPosition"); QTest::newRow("column 0, scroll per item 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerItem) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerItem << 0 << 0; QTest::newRow("column 1, scroll per item, 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 0 << 1 * 40; QTest::newRow("column 1, scroll per item, 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerItem) << 1 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerItem << 1 << 0; QTest::newRow("column 5, scroll per item, 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 0 << 5 * 40; QTest::newRow("column 5, scroll per item, 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerItem) << 5 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerItem << 5 << 0; QTest::newRow("column 9, scroll per item, 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 0 << 9 * 40; QTest::newRow("column 9, scroll per item, 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerItem) << 5 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerItem << 5 << 4 * 40; QTest::newRow("column 0, scroll per pixel 0") - << 10 << 40 << 0 << int(QAbstractItemView::ScrollPerPixel) << 0 << 0; + << 10 << 40 << 0 << QAbstractItemView::ScrollPerPixel << 0 << 0; QTest::newRow("column 1, scroll per pixel 0") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 0 << 1 * 40; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 0 << 1 * 40; QTest::newRow("column 1, scroll per pixel 1") - << 10 << 40 << 1 << int(QAbstractItemView::ScrollPerPixel) << 1 * 40 << 0; + << 10 << 40 << 1 << QAbstractItemView::ScrollPerPixel << 1 * 40 << 0; QTest::newRow("column 5, scroll per pixel 0") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 0 << 5 * 40; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 0 << 5 * 40; QTest::newRow("column 5, scroll per pixel 5") - << 10 << 40 << 5 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 0; + << 10 << 40 << 5 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 0; QTest::newRow("column 9, scroll per pixel 0") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 0 << 9 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 0 << 9 * 40; QTest::newRow("column 9, scroll per pixel 5") - << 10 << 40 << 9 << int(QAbstractItemView::ScrollPerPixel) << 5 * 40 << 4 * 40; + << 10 << 40 << 9 << QAbstractItemView::ScrollPerPixel << 5 * 40 << 4 * 40; } void tst_QTableView::columnViewportPosition() @@ -2523,7 +2459,7 @@ void tst_QTableView::columnViewportPosition() QFETCH(int, columnCount); QFETCH(int, columnWidth); QFETCH(int, column); - QFETCH(int, horizontalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode); QFETCH(int, horizontalScrollValue); QFETCH(int, columnViewportPosition); @@ -2537,7 +2473,7 @@ void tst_QTableView::columnViewportPosition() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); + view.setHorizontalScrollMode(horizontalScrollMode); view.horizontalScrollBar()->setValue(horizontalScrollValue); #ifdef Q_OS_WINRT @@ -2737,8 +2673,8 @@ void tst_QTableView::sortingEnabled() void tst_QTableView::scrollTo_data() { - QTest::addColumn<int>("verticalScrollMode"); - QTest::addColumn<int>("horizontalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("verticalScrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("horizontalScrollMode"); QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); QTest::addColumn<int>("rowHeight"); @@ -2751,51 +2687,51 @@ void tst_QTableView::scrollTo_data() QTest::addColumn<int>("columnSpan"); QTest::addColumn<int>("horizontalScroll"); QTest::addColumn<int>("verticalScroll"); - QTest::addColumn<int>("scrollHint"); + QTest::addColumn<QAbstractItemView::ScrollHint>("scrollHint"); QTest::addColumn<int>("expectedHorizontalScroll"); QTest::addColumn<int>("expectedVerticalScroll"); QTest::newRow("no hidden, no span, no scroll, per item") - << (int)QAbstractItemView::ScrollPerItem - << (int)QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem << 10 << 10 // table << 80 << 80 // size << -1 << -1 // hide << 0 << 0 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 0 << 0; // expected QTest::newRow("no hidden, no span, no scroll, per pixel") - << (int)QAbstractItemView::ScrollPerPixel - << (int)QAbstractItemView::ScrollPerPixel + << QAbstractItemView::ScrollPerPixel + << QAbstractItemView::ScrollPerPixel << 10 << 10 // table << 80 << 80 // size << -1 << -1 // hide << 0 << 0 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 0 << 0; // expected QTest::newRow("hidden, no span, no scroll, per item") - << (int)QAbstractItemView::ScrollPerItem - << (int)QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem + << QAbstractItemView::ScrollPerItem << 10 << 10 // table << 80 << 80 // size << 3 << 3 // hide << 5 << 5 // cell << 1 << 1 // span << 0 << 0 // scroll - << (int)QAbstractItemView::PositionAtTop + << QAbstractItemView::PositionAtTop << 4 << 4; // expected } void tst_QTableView::scrollTo() { - QFETCH(int, horizontalScrollMode); - QFETCH(int, verticalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, horizontalScrollMode); + QFETCH(QAbstractItemView::ScrollMode, verticalScrollMode); QFETCH(int, rowCount); QFETCH(int, columnCount); QFETCH(int, rowHeight); @@ -2808,7 +2744,7 @@ void tst_QTableView::scrollTo() QFETCH(int, columnSpan); QFETCH(int, horizontalScroll); QFETCH(int, verticalScroll); - QFETCH(int, scrollHint); + QFETCH(QAbstractItemView::ScrollHint, scrollHint); QFETCH(int, expectedHorizontalScroll); QFETCH(int, expectedVerticalScroll); @@ -2828,8 +2764,8 @@ void tst_QTableView::scrollTo() view.setSpan(row, column, rowSpan, columnSpan); view.hideRow(hiddenRow); view.hideColumn(hiddenColumn); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)horizontalScrollMode); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)verticalScrollMode); + view.setHorizontalScrollMode(horizontalScrollMode); + view.setVerticalScrollMode(verticalScrollMode); for (int r = 0; r < rowCount; ++r) view.setRowHeight(r, rowHeight); @@ -2841,7 +2777,7 @@ void tst_QTableView::scrollTo() QModelIndex index = model.index(row, column); QVERIFY(index.isValid()); - view.scrollTo(index, (QAbstractItemView::ScrollHint)scrollHint); + view.scrollTo(index, scrollHint); QTRY_COMPARE(view.verticalScrollBar()->value(), expectedVerticalScroll); QTRY_COMPARE(view.horizontalScrollBar()->value(), expectedHorizontalScroll); } @@ -3146,8 +3082,6 @@ void tst_QTableView::span() VERIFY_SPANS_CONSISTENCY(&view); } -typedef QVector<QRect> SpanList; - void tst_QTableView::spans_data() { QTest::addColumn<int>("rows"); @@ -3275,7 +3209,7 @@ void tst_QTableView::spans() { QFETCH(int, rows); QFETCH(int, columns); - QFETCH(SpanList, spans); + QFETCH(const SpanList, spans); QFETCH(bool, hideRowLastRowOfFirstSpan); QFETCH(QPoint, pos); QFETCH(int, expectedRowSpan); @@ -3287,10 +3221,8 @@ void tst_QTableView::spans() view.setModel(&model); view.show(); - for (int i = 0; i < spans.count(); ++i) { - QRect sp = spans.at(i); + for (const auto &sp : spans) view.setSpan(sp.x(), sp.y(), sp.width(), sp.height()); - } if (hideRowLastRowOfFirstSpan) { view.setRowHidden(spans.at(0).bottom(), true); @@ -3384,32 +3316,34 @@ void tst_QTableView::spansAfterRowRemoval() QtTestTableView view; view.setModel(&model); - QList<QRect> spans; - spans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 2) - << QRect(2, 2, 1, 5) - << QRect(2, 8, 1, 2) - << QRect(3, 4, 1, 2) - << QRect(4, 4, 1, 4) - << QRect(5, 6, 1, 3) - << QRect(6, 7, 1, 3); - foreach (QRect span, spans) + static const QRect spans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 2}, + {2, 2, 1, 5}, + {2, 8, 1, 2}, + {3, 4, 1, 2}, + {4, 4, 1, 4}, + {5, 6, 1, 3}, + {6, 7, 1, 3} + }; + for (const QRect &span : spans) view.setSpan(span.top(), span.left(), span.height(), span.width()); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeRows(3, 3); - QList<QRect> expectedSpans; - expectedSpans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 1) - << QRect(2, 2, 1, 2) - << QRect(2, 5, 1, 2) - << QRect(3, 4, 1, 1) - << QRect(4, 3, 1, 2) - << QRect(5, 3, 1, 3) - << QRect(6, 4, 1, 3); - foreach (QRect span, expectedSpans) { + static const QRect expectedSpans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 1}, + {2, 2, 1, 2}, + {2, 5, 1, 2}, + {3, 4, 1, 1}, + {4, 3, 1, 2}, + {5, 3, 1, 3}, + {6, 4, 1, 3} + }; + for (const QRect &span : expectedSpans) { QCOMPARE(view.columnSpan(span.top(), span.left()), span.width()); QCOMPARE(view.rowSpan(span.top(), span.left()), span.height()); } @@ -3424,32 +3358,34 @@ void tst_QTableView::spansAfterColumnRemoval() view.setModel(&model); // Same set as above just swapping columns and rows. - QList<QRect> spans; - spans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 2) - << QRect(2, 2, 1, 5) - << QRect(2, 8, 1, 2) - << QRect(3, 4, 1, 2) - << QRect(4, 4, 1, 4) - << QRect(5, 6, 1, 3) - << QRect(6, 7, 1, 3); - foreach (QRect span, spans) - view.setSpan(span.left(), span.top(), span.width(), span.height()); + static const QRect spans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 2}, + {2, 2, 1, 5}, + {2, 8, 1, 2}, + {3, 4, 1, 2}, + {4, 4, 1, 4}, + {5, 6, 1, 3}, + {6, 7, 1, 3} + }; + for (const QRect &span : spans) + view.setSpan(span.left(), span.top(), span.width(), span.height()); view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); view.model()->removeColumns(3, 3); - QList<QRect> expectedSpans; - expectedSpans << QRect(0, 1, 1, 2) - << QRect(1, 2, 1, 1) - << QRect(2, 2, 1, 2) - << QRect(2, 5, 1, 2) - << QRect(3, 4, 1, 1) - << QRect(4, 3, 1, 2) - << QRect(5, 3, 1, 3) - << QRect(6, 4, 1, 3); - foreach (QRect span, expectedSpans) { + static const QRect expectedSpans[] = { + {0, 1, 1, 2}, + {1, 2, 1, 1}, + {2, 2, 1, 2}, + {2, 5, 1, 2}, + {3, 4, 1, 1}, + {4, 3, 1, 2}, + {5, 3, 1, 3}, + {6, 4, 1, 3} + }; + for (const QRect &span : expectedSpans) { QCOMPARE(view.columnSpan(span.left(), span.top()), span.height()); QCOMPARE(view.rowSpan(span.left(), span.top()), span.width()); } @@ -3457,12 +3393,10 @@ void tst_QTableView::spansAfterColumnRemoval() VERIFY_SPANS_CONSISTENCY(&view); } -Q_DECLARE_METATYPE(Qt::Key) - void tst_QTableView::editSpanFromDirections_data() { - QTest::addColumn<QList<Qt::Key> >("keyPresses"); - QTest::addColumn<QSharedPointer<QStandardItemModel> >("model"); + QTest::addColumn<KeyList>("keyPresses"); + QTest::addColumn<QSharedPointer<QStandardItemModel>>("model"); QTest::addColumn<int>("row"); QTest::addColumn<int>("column"); QTest::addColumn<int>("rowSpan"); @@ -3481,8 +3415,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+ | | ^ | +---+---+ */ - QList<Qt::Key> keyPresses; - keyPresses << Qt::Key_Right << Qt::Key_PageDown << Qt::Key_Up; + KeyList keyPresses {Qt::Key_Right, Qt::Key_PageDown, Qt::Key_Up}; QSharedPointer<QStandardItemModel> model(new QStandardItemModel(4, 2)); QTest::newRow("row span, bottom up") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); @@ -3496,8 +3429,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+ | | | +---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_Right << Qt::Key_Down; + keyPresses = {Qt::Key_Right, Qt::Key_Down}; model = QSharedPointer<QStandardItemModel>::create(4, 2); QTest::newRow("row span, top down") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); @@ -3509,8 +3441,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+ +---+ | | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_End << Qt::Key_Down << Qt::Key_Left; + keyPresses = {Qt::Key_End, Qt::Key_Down, Qt::Key_Left}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("row span, right to left") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(1, 1) << model->index(1, 1); @@ -3522,8 +3453,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+ +---+ | > | c | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Right; + keyPresses = {Qt::Key_PageDown, Qt::Key_Right}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("row span, left to right") << keyPresses << model << 1 << 1 << 2 << 1 << model->index(2, 1) << model->index(1, 1); @@ -3535,8 +3465,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | ^ | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Up; + keyPresses = {Qt::Key_PageDown, Qt::Key_Up}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, bottom up") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 0) << model->index(1, 0); @@ -3548,8 +3477,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | | ^ | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_PageDown << Qt::Key_Right << Qt::Key_Up; + keyPresses = {Qt::Key_PageDown, Qt::Key_Right, Qt::Key_Up}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, bottom up #2") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 1) << model->index(1, 0); @@ -3561,8 +3489,7 @@ void tst_QTableView::editSpanFromDirections_data() +---+---+---+ | | | | +---+---+---+ */ - keyPresses.clear(); - keyPresses << Qt::Key_End << Qt::Key_Down; + keyPresses = {Qt::Key_End, Qt::Key_Down}; model = QSharedPointer<QStandardItemModel>::create(3, 3); QTest::newRow("col span, top down") << keyPresses << model << 1 << 0 << 1 << 3 << model->index(1, 2) << model->index(1, 0); @@ -3571,12 +3498,10 @@ void tst_QTableView::editSpanFromDirections_data() class TableViewWithCursorExposed : public QTableView { public: - TableViewWithCursorExposed() : - QTableView() { - } + using QTableView::QTableView; -public: - QModelIndex visualCursorIndex() { + QModelIndex visualCursorIndex() + { QTableViewPrivate *d = static_cast<QTableViewPrivate*>(qt_widget_private(this)); return d->model->index(d->visualCursor.y(), d->visualCursor.x()); } @@ -3584,7 +3509,7 @@ public: void tst_QTableView::editSpanFromDirections() { - QFETCH(QList<Qt::Key>, keyPresses); + QFETCH(const KeyList, keyPresses); QFETCH(QSharedPointer<QStandardItemModel>, model); QFETCH(int, row); QFETCH(int, column); @@ -3602,9 +3527,8 @@ void tst_QTableView::editSpanFromDirections() view.show(); QVERIFY(QTest::qWaitForWindowActive(&view)); - foreach (Qt::Key key, keyPresses) { + for (Qt::Key key : keyPresses) QTest::keyClick(&view, key); - } QCOMPARE(view.visualCursorIndex(), expectedVisualCursorIndex); QCOMPARE(view.selectionModel()->currentIndex(), expectedEditedIndex); @@ -3613,21 +3537,21 @@ void tst_QTableView::editSpanFromDirections() QTRY_COMPARE(view.model()->data(expectedEditedIndex).toString(), QLatin1String("x")); } -class Model : public QAbstractTableModel { - -Q_OBJECT - +class Model : public QAbstractTableModel +{ + Q_OBJECT public: - Model(QObject * parent = 0) : QAbstractTableModel(parent) { - } + using QAbstractTableModel::QAbstractTableModel; - int rowCount(const QModelIndex &) const { + int rowCount(const QModelIndex &) const override + { return rows; } - int columnCount(const QModelIndex &) const { + int columnCount(const QModelIndex &) const override + { return columns; } - QVariant data(const QModelIndex &, int) const + QVariant data(const QModelIndex &, int) const override { return QVariant(); } @@ -3637,8 +3561,8 @@ public: endResetModel(); } - int rows; - int columns; + int rows = 0; + int columns = 0; }; void tst_QTableView::checkHeaderReset() @@ -3662,7 +3586,7 @@ void tst_QTableView::checkHeaderMinSize() //viewport. QTableView view; QStringListModel m; - m.setStringList( QStringList() << QLatin1String("one cell is enough")); + m.setStringList({QLatin1String("one cell is enough")}); view.setModel(&m); //setting the minimum height on the horizontal header @@ -3693,31 +3617,29 @@ void tst_QTableView::resizeToContents() table2.verticalHeader()->setVisible(false); - for(int i = 0;i<table.columnCount();i++) { + for (int i = 0; i < table.columnCount(); i++) table.resizeColumnToContents(i); - } - for(int i = 0;i<table.rowCount();i++) { + for (int i = 0; i < table.rowCount(); i++) table.resizeRowToContents(i); - } table2.resizeColumnsToContents(); table2.resizeRowsToContents(); table3.resizeColumnsToContents(); table3.resizeRowsToContents(); //now let's check the row/col sizes - for(int i = 0;i<table.columnCount();i++) { - QCOMPARE( table.columnWidth(i), table2.columnWidth(i)); - QCOMPARE( table2.columnWidth(i), table3.columnWidth(i)); + for (int i = 0; i < table.columnCount(); i++) { + QCOMPARE(table.columnWidth(i), table2.columnWidth(i)); + QCOMPARE(table2.columnWidth(i), table3.columnWidth(i)); } - for(int i = 0;i<table.rowCount();i++) { - QCOMPARE( table.rowHeight(i), table2.rowHeight(i)); - QCOMPARE( table2.rowHeight(i), table3.rowHeight(i)); + for (int i = 0; i < table.rowCount(); i++) { + QCOMPARE(table.rowHeight(i), table2.rowHeight(i)); + QCOMPARE(table2.rowHeight(i), table3.rowHeight(i)); } } QT_BEGIN_NAMESPACE -extern bool Q_GUI_EXPORT qt_tab_all_widgets(); // qapplication.cpp +extern bool Q_WIDGETS_EXPORT qt_tab_all_widgets(); // qapplication.cpp QT_END_NAMESPACE void tst_QTableView::tabFocus() @@ -3747,57 +3669,57 @@ void tst_QTableView::tabFocus() for (int i = 0; i < 2; ++i) { // tab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(!window.hasFocus()); QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); // tab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); } // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QStandardItemModel *model = new QStandardItemModel; - view->setModel(model); + QStandardItemModel model; + view->setModel(&model); // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - model->insertRow(0, new QStandardItem("Hei")); - model->insertRow(0, new QStandardItem("Hei")); - model->insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); + model.insertRow(0, new QStandardItem("Hei")); // backtab to view - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(view->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!edit->hasFocus()); // backtab to edit doesn't work - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QVERIFY(!window.hasFocus()); QVERIFY(view->hasFocus()); QVERIFY(!edit->hasFocus()); @@ -3805,41 +3727,38 @@ void tst_QTableView::tabFocus() view->setTabKeyNavigation(false); // backtab to edit - QTest::keyPress(qApp->focusWidget(), Qt::Key_Backtab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Backtab); QTRY_VERIFY(edit->hasFocus()); QVERIFY(!window.hasFocus()); QVERIFY(!view->hasFocus()); - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(view->hasFocus()); - QTest::keyPress(qApp->focusWidget(), Qt::Key_Tab); + QTest::keyPress(QApplication::focusWidget(), Qt::Key_Tab); QTRY_VERIFY(edit->hasFocus()); - - delete model; } class BigModel : public QAbstractTableModel { Q_OBJECT public: - virtual QVariant data(const QModelIndex &index, - int role = Qt::DisplayRole) const + QVariant data(const QModelIndex &index, + int role = Qt::DisplayRole) const override { if (role == Qt::DisplayRole) return QString::number(index.column()) + QLatin1String(" - ") + QString::number(index.row()); return QVariant(); } - - int rowCount(const QModelIndex & parent = QModelIndex()) const + int rowCount(const QModelIndex &parent = QModelIndex()) const override { - Q_UNUSED(parent); + Q_UNUSED(parent) return 10000000; } - int columnCount(const QModelIndex & parent = QModelIndex()) const + int columnCount(const QModelIndex &parent = QModelIndex()) const override { - Q_UNUSED(parent); + Q_UNUSED(parent) return 20000000; } }; @@ -3868,7 +3787,7 @@ void tst_QTableView::selectionSignal() view.resize(200, 200); view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); - QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, view.visualRect(model.index(2, 0)).center()); + QTest::mouseClick(view.viewport(), Qt::LeftButton, {}, view.visualRect(model.index(2, 0)).center()); } void tst_QTableView::setCurrentIndex() @@ -3894,14 +3813,14 @@ void tst_QTableView::setCurrentIndex() class task173773_EventFilter : public QObject { - int paintEventCount_; + int paintEventCount_ = 0; public: - task173773_EventFilter() : paintEventCount_(0) {} + using QObject::QObject; int paintEventCount() const { return paintEventCount_; } private: - bool eventFilter(QObject *obj, QEvent *e) + bool eventFilter(QObject *obj, QEvent *e) override { - Q_UNUSED(obj); + Q_UNUSED(obj) if (e->type() == QEvent::Paint) ++paintEventCount_; return false; @@ -4030,25 +3949,25 @@ void tst_QTableView::task248688_autoScrollNavigation() #if QT_CONFIG(wheelevent) void tst_QTableView::mouseWheel_data() { - QTest::addColumn<int>("scrollMode"); + QTest::addColumn<QAbstractItemView::ScrollMode>("scrollMode"); QTest::addColumn<int>("delta"); QTest::addColumn<int>("horizontalPositon"); QTest::addColumn<int>("verticalPosition"); QTest::newRow("scroll up per item") - << int(QAbstractItemView::ScrollPerItem) << 120 - << 10 - qApp->wheelScrollLines() << 10 - qApp->wheelScrollLines(); + << QAbstractItemView::ScrollPerItem << 120 + << 10 - QApplication::wheelScrollLines() << 10 - QApplication::wheelScrollLines(); QTest::newRow("scroll down per item") - << int(QAbstractItemView::ScrollPerItem) << -120 - << 10 + qApp->wheelScrollLines() << 10 + qApp->wheelScrollLines(); + << QAbstractItemView::ScrollPerItem << -120 + << 10 + QApplication::wheelScrollLines() << 10 + QApplication::wheelScrollLines(); QTest::newRow("scroll down per pixel") - << int(QAbstractItemView::ScrollPerPixel) << -120 - << 10 + qApp->wheelScrollLines() * 91 << 10 + qApp->wheelScrollLines() * 46; + << QAbstractItemView::ScrollPerPixel << -120 + << 10 + QApplication::wheelScrollLines() * 91 << 10 + QApplication::wheelScrollLines() * 46; } void tst_QTableView::mouseWheel() { - QFETCH(int, scrollMode); + QFETCH(QAbstractItemView::ScrollMode, scrollMode); QFETCH(int, delta); QFETCH(int, horizontalPositon); QFETCH(int, verticalPosition); @@ -4068,8 +3987,8 @@ void tst_QTableView::mouseWheel() for (int c = 0; c < 100; ++c) view.setColumnWidth(c, 100); - view.setHorizontalScrollMode((QAbstractItemView::ScrollMode)scrollMode); - view.setVerticalScrollMode((QAbstractItemView::ScrollMode)scrollMode); + view.setHorizontalScrollMode(scrollMode); + view.setVerticalScrollMode(scrollMode); view.horizontalScrollBar()->setValue(10); view.verticalScrollBar()->setValue(10); @@ -4168,15 +4087,15 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *vHeaderVp = vHeader->viewport(); QPoint rowPos(cellRect.center()); QMouseEvent rowPressEvent(QEvent::MouseButtonPress, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &rowPressEvent); + QCoreApplication::sendEvent(vHeaderVp, &rowPressEvent); for (int i = 0; i < 4; ++i) { rowPos.setY(rowPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, rowPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &moveEvent); + QCoreApplication::sendEvent(vHeaderVp, &moveEvent); } QMouseEvent rowReleaseEvent(QEvent::MouseButtonRelease, rowPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(vHeaderVp, &rowReleaseEvent); + QCoreApplication::sendEvent(vHeaderVp, &rowReleaseEvent); for (int i = 0; i < 4; ++i) { QModelIndex index = model.index(3 + i, 0, table.rootIndex()); @@ -4190,15 +4109,15 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *hHeaderVp = hHeader->viewport(); QPoint colPos((cellRect.left() + cellRect.right()) / 2, 5); QMouseEvent colPressEvent(QEvent::MouseButtonPress, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &colPressEvent); + QCoreApplication::sendEvent(hHeaderVp, &colPressEvent); for (int i = 0; i < 4; ++i) { colPos.setX(colPos.x() + cellRect.width()); QMouseEvent moveEvent(QEvent::MouseMove, colPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &moveEvent); + QCoreApplication::sendEvent(hHeaderVp, &moveEvent); } QMouseEvent colReleaseEvent(QEvent::MouseButtonRelease, colPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(hHeaderVp, &colReleaseEvent); + QCoreApplication::sendEvent(hHeaderVp, &colReleaseEvent); for (int i = 0; i < 4; ++i) { QModelIndex index = model.index(0, 3 + i, table.rootIndex()); @@ -4211,22 +4130,23 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *tableVp = table.viewport(); QPoint cellPos = cellRect.center(); QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellPressEvent); + QCoreApplication::sendEvent(tableVp, &cellPressEvent); for (int i = 0; i < 6; ++i) { cellPos.setX(cellPos.x() + cellRect.width()); cellPos.setY(cellPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &moveEvent); + QCoreApplication::sendEvent(tableVp, &moveEvent); } QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellReleaseEvent); + QCoreApplication::sendEvent(tableVp, &cellReleaseEvent); - for (int i = 0; i < 6; ++i) + for (int i = 0; i < 6; ++i) { for (int j = 0; j < 6; ++j) { QModelIndex index = model.index(2 + i, 2 + j, table.rootIndex()); QVERIFY(table.selectionModel()->isSelected(index)); } + } } { @@ -4234,23 +4154,24 @@ void tst_QTableView::task191545_dragSelectRows() QWidget *tableVp = table.viewport(); QPoint cellPos = cellRect.center(); QMouseEvent cellPressEvent(QEvent::MouseButtonPress, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellPressEvent); + QCoreApplication::sendEvent(tableVp, &cellPressEvent); for (int i = 0; i < 6; ++i) { cellPos.setX(cellPos.x() + cellRect.width()); cellPos.setY(cellPos.y() + cellRect.height()); QMouseEvent moveEvent(QEvent::MouseMove, cellPos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &moveEvent); + QCoreApplication::sendEvent(tableVp, &moveEvent); } QMouseEvent cellReleaseEvent(QEvent::MouseButtonRelease, cellPos, Qt::LeftButton, Qt::NoButton, Qt::ControlModifier); - qApp->sendEvent(tableVp, &cellReleaseEvent); + QCoreApplication::sendEvent(tableVp, &cellReleaseEvent); QTest::qWait(200); - for (int i = 0; i < 6; ++i) + for (int i = 0; i < 6; ++i) { for (int j = 0; j < 6; ++j) { QModelIndex index = model.index(3 + i, 3 + j, table.rootIndex()); QVERIFY(!table.selectionModel()->isSelected(index)); } + } } } @@ -4328,8 +4249,6 @@ void tst_QTableView::taskQTBUG_4516_clickOnRichTextLabel() QTest::mouseClick(&label, Qt::LeftButton); QCOMPARE(view.currentIndex(), model.index(1,1)); - - } @@ -4371,14 +4290,14 @@ void tst_QTableView::taskQTBUG_5237_wheelEventOnHeader() } #endif -class TestTableView : public QTableView { -Q_OBJECT +class TestTableView : public QTableView +{ + Q_OBJECT public: - TestTableView(QWidget *parent = 0) : QTableView(parent) + TestTableView(QWidget *parent = nullptr) : QTableView(parent) { - connect(this, SIGNAL(entered(QModelIndex)), this, SLOT(openEditor(QModelIndex))); + connect(this, &QTableView::entered, this, &TestTableView::openPersistentEditor); } - ~TestTableView(){} public slots: void onDataChanged() { @@ -4386,9 +4305,6 @@ public slots: setRowHidden(i, model()->data(model()->index(i, 0)).toBool()); } } - - void openEditor(const QModelIndex& index) - { openPersistentEditor(index); } }; @@ -4396,15 +4312,13 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() { QStandardItemModel model; model.insertColumn(0, QModelIndex()); - for(int i = 0; i < 20; i++) - { + for (int i = 0; i < 20; i++) model.insertRow(i); - } TestTableView w; w.setMouseTracking(true); w.setModel(&model); - connect(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), &w, SLOT(onDataChanged())); + connect(&model, &QStandardItemModel::dataChanged, &w, &TestTableView::onDataChanged); w.show(); QVERIFY(QTest::qWaitForWindowExposed(&w)); for (int i = 0; i < 10; i++) @@ -4418,10 +4332,7 @@ void tst_QTableView::taskQTBUG_8585_crashForNoGoodReason() class TableView7774 : public QTableView { public: - QRegion visualRegionForSelection(const QItemSelection &selection) const - { - return QTableView::visualRegionForSelection(selection); - } + using QTableView::visualRegionForSelection; }; void tst_QTableView::taskQTBUG_7774_RtoLVisualRegionForSelection() diff --git a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp index 6184962d93..f640996690 100644 --- a/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/widgets/itemviews/qtablewidget/tst_qtablewidget.cpp @@ -26,15 +26,12 @@ ** ****************************************************************************/ - -#include <QtTest/QtTest> -#include <qeventloop.h> -#include <qlist.h> -#include <qpair.h> -#include <qheaderview.h> -#include <qlineedit.h> - -#include <qtablewidget.h> +#include <QHeaderView> +#include <QLineEdit> +#include <QMimeData> +#include <QSignalSpy> +#include <QTableWidget> +#include <QTest> class QObjectTableItem : public QObject, public QTableWidgetItem { @@ -46,11 +43,10 @@ class tst_QTableWidget : public QObject Q_OBJECT public: - tst_QTableWidget(); + using QObject::QObject; private slots: void initTestCase(); - void cleanupTestCase(); void init(); void getSetCheck(); void clear(); @@ -97,12 +93,12 @@ private slots: #endif private: - QTableWidget *testWidget; + std::unique_ptr<QTableWidget> testWidget; }; -typedef QPair<int, int> IntPair; -typedef QList<int> IntList; -typedef QList<IntPair> IntIntList; +using IntPair = QPair<int, int>; +using IntList = QVector<int>; +using IntIntList = QVector<IntPair>; Q_DECLARE_METATYPE(QTableWidgetSelectionRange) @@ -143,45 +139,36 @@ void tst_QTableWidget::getSetCheck() obj1.setItem(3, 3, new QTableWidgetItem("3,3")); obj1.setCurrentItem(var3); QCOMPARE(var3, obj1.currentItem()); - obj1.setCurrentItem((QTableWidgetItem *)0); - QCOMPARE((QTableWidgetItem *)0, obj1.currentItem()); - obj1.setItem(0, 0, 0); - QCOMPARE((QTableWidgetItem *)0, obj1.item(0, 0)); + obj1.setCurrentItem(nullptr); + QCOMPARE(obj1.currentItem(), nullptr); + obj1.setItem(0, 0, nullptr); + QCOMPARE(obj1.item(0, 0), nullptr); // const QTableWidgetItem * QTableWidget::itemPrototype() // void QTableWidget::setItemPrototype(const QTableWidgetItem *) const QTableWidgetItem *var4 = new QTableWidgetItem; obj1.setItemPrototype(var4); QCOMPARE(var4, obj1.itemPrototype()); - obj1.setItemPrototype((QTableWidgetItem *)0); - QCOMPARE((const QTableWidgetItem *)0, obj1.itemPrototype()); -} - -tst_QTableWidget::tst_QTableWidget(): testWidget(0) -{ + obj1.setItemPrototype(nullptr); + QCOMPARE(obj1.itemPrototype(), nullptr); } void tst_QTableWidget::initTestCase() { - testWidget = new QTableWidget(); + testWidget.reset(new QTableWidget); testWidget->show(); QApplication::setKeyboardInputInterval(100); } -void tst_QTableWidget::cleanupTestCase() -{ - delete testWidget; -} - void tst_QTableWidget::init() { testWidget->clear(); testWidget->setRowCount(5); testWidget->setColumnCount(5); - for (int row=0; row < testWidget->rowCount(); ++row) + for (int row = 0; row < testWidget->rowCount(); ++row) testWidget->showRow(row); - for (int column=0; column < testWidget->columnCount(); ++column) + for (int column = 0; column < testWidget->columnCount(); ++column) testWidget->showColumn(column); } @@ -319,13 +306,15 @@ void tst_QTableWidget::item() QCOMPARE(testWidget->rowCount(), rowCount); QCOMPARE(testWidget->columnCount(), columnCount); - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c))); + } - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c)); + } QTableWidgetItem *item = testWidget->item(row, column); QCOMPARE(!!item, expectItem); @@ -361,15 +350,17 @@ void tst_QTableWidget::takeItem() QCOMPARE(testWidget->rowCount(), rowCount); QCOMPARE(testWidget->columnCount(), columnCount); - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) testWidget->setItem(r, c, new QTableWidgetItem(QString::number(r * c + c))); + } - for (int r = 0; r < testWidget->rowCount(); ++r) + for (int r = 0; r < testWidget->rowCount(); ++r) { for (int c = 0; c < testWidget->columnCount(); ++c) QCOMPARE(testWidget->item(r, c)->text(), QString::number(r * c + c)); + } - QSignalSpy spy(testWidget, &QTableWidget::cellChanged); + QSignalSpy spy(testWidget.get(), &QTableWidget::cellChanged); QTableWidgetItem *item = testWidget->takeItem(row, column); QCOMPARE(!!item, expectItem); if (expectItem) { @@ -516,11 +507,11 @@ void tst_QTableWidget::selectedItems() { QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(IntIntList, createItems); - QFETCH(IntList, hiddenRows); - QFETCH(IntList, hiddenColumns); - QFETCH(QTableWidgetSelectionRange, selectionRange); - QFETCH(IntIntList, expectedItems); + QFETCH(const IntIntList, createItems); + QFETCH(const IntList, hiddenRows); + QFETCH(const IntList, hiddenColumns); + QFETCH(const QTableWidgetSelectionRange, selectionRange); + QFETCH(const IntIntList, expectedItems); // set dimensions and test they are ok testWidget->setRowCount(rowCount); @@ -529,15 +520,15 @@ void tst_QTableWidget::selectedItems() QCOMPARE(testWidget->columnCount(), columnCount); // create and set items - foreach (IntPair intPair, createItems) { + for (const auto &intPair : createItems) { testWidget->setItem(intPair.first, intPair.second, new QTableWidgetItem(QString("Item %1 %2") .arg(intPair.first).arg(intPair.second))); } // hide rows/columns - foreach (int row, hiddenRows) + for (int row : hiddenRows) testWidget->setRowHidden(row, true); - foreach (int column, hiddenColumns) + for (int column : hiddenColumns) testWidget->setColumnHidden(column, true); // make sure we don't have any previous selections hanging around @@ -557,31 +548,18 @@ void tst_QTableWidget::selectedItems() } // check that the correct number of items and the expected items are there - QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems(); + const QList<QTableWidgetItem *> selectedItems = testWidget->selectedItems(); QCOMPARE(selectedItems.count(), expectedItems.count()); - foreach (IntPair intPair, expectedItems) + for (const auto &intPair : expectedItems) QVERIFY(selectedItems.contains(testWidget->item(intPair.first, intPair.second))); // check that setItemSelected agrees with selectedItems - for (int row = 0; row<testWidget->rowCount(); ++row) { - bool hidden = false; - foreach (int hiddenRow, hiddenRows){ - if(hiddenRow == row){ - hidden = true; - break; - } - } - if (hidden) + for (int row = 0; row < testWidget->rowCount(); ++row) { + if (hiddenRows.contains(row)) continue; - for (int column = 0; column<testWidget->columnCount(); ++column) { - foreach (int hiddenColumn, hiddenColumns){ - if(hiddenColumn == column){ - hidden = true; - break; - } - } - if (hidden) + for (int column = 0; column < testWidget->columnCount(); ++column) { + if (hiddenColumns.contains(column)) continue; QTableWidgetItem *item = testWidget->item(row, column); @@ -621,11 +599,13 @@ void tst_QTableWidget::removeRow() QCOMPARE(testWidget->columnCount(), columnCount); // fill table with items - for (int r = 0; r < rowCount; ++r) - for (int c = 0; c < columnCount; ++c) + for (int r = 0; r < rowCount; ++r) { + const QString rRow = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < columnCount; ++c) { testWidget->setItem(r, c, - new QTableWidgetItem( - QString::number(r) + ":" + QString::number(c))); + new QTableWidgetItem(rRow + QString::number(c))); + } + } // remove and compare the results testWidget->removeRow(row); @@ -633,14 +613,18 @@ void tst_QTableWidget::removeRow() QCOMPARE(testWidget->columnCount(), expectedColumnCount); // check if the correct items were removed - for (int r = 0; r < expectedRowCount; ++r) - for (int c = 0; c < expectedColumnCount; ++c) + for (int r = 0; r < expectedRowCount; ++r) { + const QString rRow = QString::number(r < row ? r : r + 1) + + QLatin1Char(':'); + for (int c = 0; c < expectedColumnCount; ++c) { if (r < row) QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c)); + rRow + QString::number(c)); else QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r + 1) + ":" + QString::number(c)); + rRow + QString::number(c)); + } + } } void tst_QTableWidget::removeColumn_data() @@ -673,11 +657,14 @@ void tst_QTableWidget::removeColumn() QCOMPARE(testWidget->columnCount(), columnCount); // fill table with items - for (int r = 0; r < rowCount; ++r) - for (int c = 0; c < columnCount; ++c) + for (int r = 0; r < rowCount; ++r) { + const QString rStr = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < columnCount; ++c) { testWidget->setItem(r, c, new QTableWidgetItem( - QString::number(r) + ":" + QString::number(c))); + rStr + QString::number(c))); + } + } // remove and compare the results testWidget->removeColumn(column); @@ -686,14 +673,17 @@ void tst_QTableWidget::removeColumn() // check if the correct items were removed - for (int r = 0; r < expectedRowCount; ++r) - for (int c = 0; c < expectedColumnCount; ++c) + for (int r = 0; r < expectedRowCount; ++r) { + const QString rStr = QString::number(r) + QLatin1Char(':'); + for (int c = 0; c < expectedColumnCount; ++c) { if (c < column) QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c)); + rStr + QString::number(c)); else QCOMPARE(testWidget->item(r, c)->text(), - QString::number(r) + ":" + QString::number(c + 1)); + rStr + QString::number(c + 1)); + } + } } void tst_QTableWidget::insertRow_data() @@ -819,7 +809,7 @@ void tst_QTableWidget::itemOwnership() item = new QObjectTableItem(); testWidget->setItem(0, 0, item); delete item; - QCOMPARE(testWidget->item(0, 0), (QTableWidgetItem *)0); + QCOMPARE(testWidget->item(0, 0), nullptr); //delete vertical headeritem from outside headerItem = new QObjectTableItem(); @@ -887,7 +877,7 @@ void tst_QTableWidget::sortItems_data() { QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<int>("sortColumn"); QTest::addColumn<QStringList>("initial"); QTest::addColumn<QStringList>("expected"); @@ -897,7 +887,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("ascending") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -915,7 +905,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("descending") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -933,154 +923,151 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("empty table") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << IntList() << IntList() << IntList(); - QTest::newRow("half-empty table") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (IntList() << 0 << 2 << 1) << IntList() << IntList(); QTest::newRow("empty column, should not sort.") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 3 << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << (QStringList() - << "0" << 0 << 0 << 0 << 0 - << "3" << "d" << 0 << 0 << 0 - << "2" << "c" << 0 << 0 << 0 - << 0 << 0 << 0 << 0 << 0) + << "0" << QString() << QString() << QString() << QString() + << "3" << "d" << QString() << QString() << QString() + << "2" << "c" << QString() << QString() << QString() + << QString() << QString() << QString() << QString() << QString()) << IntList() << IntList() << IntList(); QTest::newRow("descending with null cell, the null cell should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << "0" << "a" << "o" << "8" << "k" - << 0 << "b" << "7" << "3" << "u") + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << "0" << "a" << "o" << "8" << "k" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 2 << 0 << 1) << IntList() << IntList(); QTest::newRow("ascending with null cell, the null cell should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << "2" << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << "2" << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "2" << "c" << "9" << "y" << "8" - << "3" << "d" << "k" << "o" << "6" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "2" << "c" << "9" << "y" << "8" + << "3" << "d" << "k" << "o" << "6" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 0 << 2 << 1) << IntList() << IntList(); QTest::newRow("ascending with null cells, the null cells should be placed at the bottom") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << "3" << "d" << "k" << "o" << "6" - << "0" << "a" << "o" << "8" << "k" - << 0 << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "3" << "d" << "k" << "o" << "6" + << "0" << "a" << "o" << "8" << "k" + << QString() << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (QStringList() - << "0" << "a" << "o" << "8" << "k" - << "3" << "d" << "k" << "o" << "6" - << 0 << "c" << "9" << "y" << "8" - << 0 << "b" << "7" << "3" << "u") + << "0" << "a" << "o" << "8" << "k" + << "3" << "d" << "k" << "o" << "6" + << QString() << "c" << "9" << "y" << "8" + << QString() << "b" << "7" << "3" << "u") << (IntList() << 1 << 0) << IntList() << IntList(); QTest::newRow("ascending... Check a bug in PersistentIndexes") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "3" << "c" << "9" << "y" << "8" << "2" << "b" << "7" << "3" << "u" << "4" << "d" << "k" << "o" << "6" - << "1" << "a" << "o" << "8" << "k" - ) + << "1" << "a" << "o" << "8" << "k") << (QStringList() << "1" << "a" << "o" << "8" << "k" << "2" << "b" << "7" << "3" << "u" << "3" << "c" << "9" << "y" << "8" - << "4" << "d" << "k" << "o" << "6" - ) + << "4" << "d" << "k" << "o" << "6") << (IntList() << 2 << 1 << 3 << 0) << IntList() << IntList(); QTest::newRow("ascending with some null cells inbetween") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() - << 0 << "a" << "o" << "8" << "k" - << "2" << "c" << "9" << "y" << "8" - << 0 << "d" << "k" << "o" << "6" - << "1" << "b" << "7" << "3" << "u") + << QString() << "a" << "o" << "8" << "k" + << "2" << "c" << "9" << "y" << "8" + << QString() << "d" << "k" << "o" << "6" + << "1" << "b" << "7" << "3" << "u") << (QStringList() - << "1" << "b" << "7" << "3" << "u" - << "2" << "c" << "9" << "y" << "8" - << 0 << "a" << "o" << "8" << "k" - << 0 << "d" << "k" << "o" << "6") + << "1" << "b" << "7" << "3" << "u" + << "2" << "c" << "9" << "y" << "8" + << QString() << "a" << "o" << "8" << "k" + << QString() << "d" << "k" << "o" << "6") << (IntList() << 1 << 0) << IntList() << IntList(); QTest::newRow("ascending hidden") << 4 << 5 - << static_cast<int>(Qt::AscendingOrder) + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -1098,7 +1085,7 @@ void tst_QTableWidget::sortItems_data() QTest::newRow("descending hidden") << 4 << 5 - << static_cast<int>(Qt::DescendingOrder) + << Qt::DescendingOrder << 0 << (QStringList() << "0" << "a" << "o" << "8" << "k" @@ -1119,7 +1106,7 @@ void tst_QTableWidget::sortItems() { QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(int, sortOrder); + QFETCH(Qt::SortOrder, sortOrder); QFETCH(int, sortColumn); QFETCH(QStringList, initial); QFETCH(QStringList, expected); @@ -1131,13 +1118,13 @@ void tst_QTableWidget::sortItems() testWidget->setColumnCount(columnCount); QAbstractItemModel *model = testWidget->model(); - QList<QPersistentModelIndex> persistent; + QVector<QPersistentModelIndex> persistent; int ti = 0; for (int r = 0; r < rowCount; ++r) { for (int c = 0; c < columnCount; ++c) { - QString str = initial.at(ti++); - if (!str.isNull()) { + QString str = initial.at(ti++); + if (!str.isEmpty()) { testWidget->setItem(r, c, new QTableWidgetItem(str)); } } @@ -1150,7 +1137,7 @@ void tst_QTableWidget::sortItems() QCOMPARE(testWidget->verticalHeader()->hiddenSectionCount(), initialHidden.count()); - testWidget->sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder)); + testWidget->sortItems(sortColumn, sortOrder); int te = 0; for (int i = 0; i < rows.count(); ++i) { @@ -1175,7 +1162,7 @@ void tst_QTableWidget::setItemWithSorting_data() { QTest::addColumn<int>("rowCount"); QTest::addColumn<int>("columnCount"); - QTest::addColumn<int>("sortOrder"); + QTest::addColumn<Qt::SortOrder>("sortOrder"); QTest::addColumn<int>("sortColumn"); QTest::addColumn<QStringList>("initialValues"); QTest::addColumn<int>("row"); @@ -1187,7 +1174,7 @@ void tst_QTableWidget::setItemWithSorting_data() QTest::newRow("2x1 no change (ascending)") << 2 << 1 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "1") << 1 << 0 << "2" << (QStringList() << "0" << "2") @@ -1195,7 +1182,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x1 no change (descending)") << 2 << 1 - << static_cast<int>(Qt::DescendingOrder) << 0 + << Qt::DescendingOrder << 0 << (QStringList() << "1" << "0") << 0 << 0 << "2" << (QStringList() << "2" << "0") @@ -1203,7 +1190,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x1 reorder (ascending)") << 2 << 1 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "1") << 0 << 0 << "2" << (QStringList() << "1" << "2") @@ -1211,7 +1198,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x1 reorder (descending)") << 2 << 1 - << static_cast<int>(Qt::DescendingOrder) << 0 + << Qt::DescendingOrder << 0 << (QStringList() << "1" << "0") << 1 << 0 << "2" << (QStringList() << "2" << "1") @@ -1219,7 +1206,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 no change (ascending)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "00" << "1" << "11") @@ -1231,7 +1218,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("2x2 reorder (ascending)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 0 + << Qt::AscendingOrder << 0 << (QStringList() << "0" << "00" << "1" << "11") @@ -1243,7 +1230,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 reorder (ascending, sortColumn = 1)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 1 + << Qt::AscendingOrder << 1 << (QStringList() << "00" << "0" << "11" << "1") @@ -1255,7 +1242,7 @@ void tst_QTableWidget::setItemWithSorting_data() << true; QTest::newRow("2x2 no change (column != sortColumn)") << 2 << 2 - << static_cast<int>(Qt::AscendingOrder) << 1 + << Qt::AscendingOrder << 1 << (QStringList() << "00" << "0" << "11" << "1") @@ -1267,7 +1254,7 @@ void tst_QTableWidget::setItemWithSorting_data() << false; QTest::newRow("8x4 reorder (ascending, sortColumn = 3)") << 8 << 4 - << static_cast<int>(Qt::AscendingOrder) << 3 + << Qt::AscendingOrder << 3 << (QStringList() << "q" << "v" << "u" << "0" << "e" << "j" << "i" << "10" @@ -1293,9 +1280,13 @@ void tst_QTableWidget::setItemWithSorting_data() void tst_QTableWidget::setItemWithSorting() { + static int dummy1 = qRegisterMetaType<QList<QPersistentModelIndex>>(); + static int dummy2 = qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>(); + Q_UNUSED(dummy1); + Q_UNUSED(dummy2); QFETCH(int, rowCount); QFETCH(int, columnCount); - QFETCH(int, sortOrder); + QFETCH(Qt::SortOrder, sortOrder); QFETCH(int, sortColumn); QFETCH(QStringList, initialValues); QFETCH(int, row); @@ -1309,7 +1300,7 @@ void tst_QTableWidget::setItemWithSorting() QTableWidget w(rowCount, columnCount); QAbstractItemModel *model = w.model(); - QList<QPersistentModelIndex> persistent; + QVector<QPersistentModelIndex> persistent; int ti = 0; for (int r = 0; r < rowCount; ++r) { @@ -1320,11 +1311,11 @@ void tst_QTableWidget::setItemWithSorting() persistent << model->index(r, sortColumn); } - w.sortItems(sortColumn, static_cast<Qt::SortOrder>(sortOrder)); + w.sortItems(sortColumn, sortOrder); w.setSortingEnabled(true); - QSignalSpy dataChangedSpy(model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); - QSignalSpy layoutChangedSpy(model, SIGNAL(layoutChanged())); + QSignalSpy dataChangedSpy(model, &QAbstractItemModel::dataChanged); + QSignalSpy layoutChangedSpy(model, &QAbstractItemModel::layoutChanged); if (i == 0) { // set a new item @@ -1376,7 +1367,7 @@ public: void tst_QTableWidget::itemData() { QTableWidgetDataChanged widget(2, 2); - widget.setItem(0, 0, new QTableWidgetItem()); + widget.setItem(0, 0, new QTableWidgetItem); QTableWidgetItem *item = widget.item(0, 0); QVERIFY(item); item->setFlags(item->flags() | Qt::ItemIsEditable); @@ -1399,7 +1390,7 @@ void tst_QTableWidget::setItemData() { QTableWidgetDataChanged table(10, 10); table.setSortingEnabled(false); - QSignalSpy dataChangedSpy(table.model(), SIGNAL(dataChanged(QModelIndex,QModelIndex))); + QSignalSpy dataChangedSpy(table.model(), &QAbstractItemModel::dataChanged); QTableWidgetItem *item = new QTableWidgetItem; table.setItem(0, 0, item); @@ -1432,11 +1423,11 @@ void tst_QTableWidget::cellWidget() QTableWidget table(10, 10); QWidget widget; - QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0)); + QCOMPARE(table.cellWidget(5, 5), nullptr); table.setCellWidget(5, 5, &widget); QCOMPARE(table.cellWidget(5, 5), &widget); table.removeCellWidget(5, 5); - QCOMPARE(table.cellWidget(5, 5), static_cast<QWidget*>(0)); + QCOMPARE(table.cellWidget(5, 5), nullptr); } void tst_QTableWidget::cellWidgetGeometry() @@ -1463,27 +1454,29 @@ void tst_QTableWidget::cellWidgetGeometry() void tst_QTableWidget::sizeHint_data() { - QTest::addColumn<int>("scrollBarPolicy"); + QTest::addColumn<Qt::ScrollBarPolicy>("scrollBarPolicy"); QTest::addColumn<QSize>("viewSize"); - QTest::newRow("ScrollBarAlwaysOn") << static_cast<int>(Qt::ScrollBarAlwaysOn) << QSize(); - QTest::newRow("ScrollBarAlwaysOff") << static_cast<int>(Qt::ScrollBarAlwaysOff) << QSize(); + QTest::newRow("ScrollBarAlwaysOn") << Qt::ScrollBarAlwaysOn << QSize(); + QTest::newRow("ScrollBarAlwaysOff") << Qt::ScrollBarAlwaysOff << QSize(); // make sure the scrollbars are shown by resizing the view to 40x40 - QTest::newRow("ScrollBarAsNeeded (40x40)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(40, 40); - QTest::newRow("ScrollBarAsNeeded (1000x1000)") << static_cast<int>(Qt::ScrollBarAsNeeded) << QSize(1000, 1000); + QTest::newRow("ScrollBarAsNeeded (40x40)") << Qt::ScrollBarAsNeeded << QSize(40, 40); + QTest::newRow("ScrollBarAsNeeded (1000x1000)") << Qt::ScrollBarAsNeeded << QSize(1000, 1000); } void tst_QTableWidget::sizeHint() { - QFETCH(int, scrollBarPolicy); + QFETCH(Qt::ScrollBarPolicy, scrollBarPolicy); QFETCH(QSize, viewSize); QTableWidget view(2, 2); view.setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents); - view.setVerticalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); - view.setHorizontalScrollBarPolicy(static_cast<Qt::ScrollBarPolicy>(scrollBarPolicy)); - for (int r = 0 ; r < view.rowCount(); ++r) + view.setVerticalScrollBarPolicy(scrollBarPolicy); + view.setHorizontalScrollBarPolicy(scrollBarPolicy); + for (int r = 0 ; r < view.rowCount(); ++r) { + const QString rStr = QString::number(r) + QLatin1Char('/'); for (int c = 0 ; c < view.columnCount(); ++c) - view.setItem(r, c, new QTableWidgetItem(QString("%1/%2").arg(r).arg(c))); + view.setItem(r, c, new QTableWidgetItem(rStr + QString::number(c))); + } view.show(); QVERIFY(QTest::qWaitForWindowExposed(&view)); @@ -1520,7 +1513,7 @@ void tst_QTableWidget::task231094() if (y == 1) twi->setFlags(Qt::ItemIsEnabled); else - twi->setFlags(0); + twi->setFlags({}); tw.setItem(y, x, twi); } } @@ -1558,15 +1551,15 @@ void tst_QTableWidget::task262056_sortDuplicate() testWidget->setColumnCount(2); testWidget->setRowCount(8); testWidget->setSortingEnabled(true); - QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\ - << "EEE" << "FFF" << "GGG"); - for (int i = 0; i<8; i++ ) { + const QStringList items({"AAA", "BBB", "CCC", "CCC", "DDD", + "EEE", "FFF", "GGG"}); + for (int i = 0; i < 8; i++ ) { QTableWidgetItem *twi = new QTableWidgetItem(items.at(i)); - testWidget->setItem(i,0,twi); - testWidget->setItem(i,1,new QTableWidgetItem(QLatin1String("item ") + QString::number(i))); + testWidget->setItem(i, 0, twi); + testWidget->setItem(i, 1, new QTableWidgetItem(QLatin1String("item ") + QString::number(i))); } testWidget->sortItems(0, Qt::AscendingOrder); - QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); + QSignalSpy layoutChangedSpy(testWidget->model(), &QAbstractItemModel::layoutChanged); testWidget->item(3,0)->setBackground(Qt::red); QCOMPARE(layoutChangedSpy.count(),0); @@ -1586,18 +1579,14 @@ void tst_QTableWidget::itemWithHeaderItems() QTableWidgetItem *item1_0 = new QTableWidgetItem(QTableWidgetItem::UserType); table.setItem(1, 0, item1_0); - QCOMPARE(table.item(0, 1), static_cast<QTableWidgetItem *>(0)); + QCOMPARE(table.item(0, 1), nullptr); } class TestTableWidget : public QTableWidget { Q_OBJECT public: - TestTableWidget(int rows, int columns, QWidget *parent = 0) - : QTableWidget(rows, columns, parent) - { - } - + using QTableWidget::QTableWidget; using QTableWidget::mimeData; using QTableWidget::indexFromItem; using QTableWidget::keyPressEvent; @@ -1661,18 +1650,19 @@ void tst_QTableWidget::selectedRowAfterSorting() { TestTableWidget table(3,3); table.setSelectionBehavior(QAbstractItemView::SelectRows); - for (int r = 0; r < 3; r++) + for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) - table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0"))); + table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0"))); + } QHeaderView *localHorizontalHeader = table.horizontalHeader(); localHorizontalHeader->setSortIndicator(1,Qt::DescendingOrder); table.setProperty("sortingEnabled",true); table.selectRow(1); table.item(1,1)->setText("9"); QCOMPARE(table.selectedItems().count(),3); - foreach (QTableWidgetItem *item, table.selectedItems()) { - QCOMPARE(item->row(),0); - } + const auto selectedItems = table.selectedItems(); + for (QTableWidgetItem *item : selectedItems) + QCOMPARE(item->row(), 0); } void tst_QTableWidget::search() @@ -1717,10 +1707,11 @@ void tst_QTableWidget::search() #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) void tst_QTableWidget::clearItemData() { - QTableWidget table(3,3); - for (int r = 0; r < 3; r++) + QTableWidget table(3, 3); + for (int r = 0; r < 3; r++) { for (int c = 0; c < 3; c++) - table.setItem(r,c,new QTableWidgetItem(QStringLiteral("0"))); + table.setItem(r, c, new QTableWidgetItem(QStringLiteral("0"))); + } QSignalSpy dataChangeSpy(table.model(), &QAbstractItemModel::dataChanged); QVERIFY(dataChangeSpy.isValid()); QVERIFY(!table.model()->clearItemData(QModelIndex())); diff --git a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp index 8c262ff3a5..84120c70e9 100644 --- a/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp +++ b/tests/auto/widgets/kernel/qshortcut/tst_qshortcut.cpp @@ -115,6 +115,7 @@ private slots: void context(); void duplicatedShortcutOverride(); void shortcutToFocusProxy(); + void deleteLater(); protected: static Qt::KeyboardModifiers toButtons( int key ); @@ -1263,5 +1264,14 @@ void tst_QShortcut::shortcutToFocusProxy() QCOMPARE(le.text(), QString()); } +void tst_QShortcut::deleteLater() +{ + QWidget w; + QPointer<QShortcut> sc(new QShortcut(QKeySequence(Qt::Key_1), &w)); + sc->deleteLater(); + QTRY_VERIFY(!sc); +} + + QTEST_MAIN(tst_QShortcut) #include "tst_qshortcut.moc" diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp index 51049ecd81..3e372b76f5 100644 --- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp +++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp @@ -7704,9 +7704,7 @@ void tst_QWidget::moveWindowInShowEvent() void tst_QWidget::repaintWhenChildDeleted() { #ifdef Q_OS_WIN - if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) { - QTest::qWait(1000); - } + QTest::qWait(1000); #endif ColorWidget w(nullptr, Qt::FramelessWindowHint, Qt::red); w.setWindowTitle(QLatin1String(QTest::currentTestFunction())); @@ -8903,13 +8901,13 @@ void tst_QWidget::translucentWidget() #ifdef Q_OS_WIN QWidget *desktopWidget = QApplication::desktop()->screen(0); - if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::WindowsVista) - widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height()); - else + widgetSnapshot = grabWindow(desktopWidget->windowHandle(), labelPos.x(), labelPos.y(), label.width(), label.height()); +#else + widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size())); #endif - widgetSnapshot = label.grab(QRect(QPoint(0, 0), label.size())); const QImage actual = widgetSnapshot.toImage().convertToFormat(QImage::Format_RGB32); - const QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size()); + QImage expected = pm.toImage().scaled(label.devicePixelRatioF() * pm.size()); + expected.setDevicePixelRatio(label.devicePixelRatioF()); if (m_platform == QStringLiteral("winrt")) QEXPECT_FAIL("", "WinRT: This fails. QTBUG-68297.", Abort); QCOMPARE(actual.size(),expected.size()); diff --git a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp index 3408fc0946..f2f9cfc009 100644 --- a/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp +++ b/tests/auto/widgets/widgets/qprogressbar/tst_qprogressbar.cpp @@ -171,11 +171,8 @@ void tst_QProgressBar::format() bar.setFormat("%v of %m (%p%)"); qApp->processEvents(); -#ifndef Q_OS_MAC +#if !defined(Q_OS_MACOS) && !defined(Q_OS_WIN) // Animated scroll bars get paint events all the time -#ifdef Q_OS_WIN - if (QOperatingSystemVersion::current() < QOperatingSystemVersion::WindowsVista) -#endif QVERIFY(!bar.repainted); #endif diff --git a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp index 91a9c49b00..64e4582366 100644 --- a/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp +++ b/tests/auto/widgets/widgets/qsplashscreen/tst_qsplashscreen.cpp @@ -36,6 +36,7 @@ class tst_QSplashScreen : public QObject private slots: void checkCloseTime(); + void checkScreenConstructor(); }; class CloseEventSplash : public QSplashScreen @@ -69,5 +70,16 @@ void tst_QSplashScreen::checkCloseTime() QVERIFY(w.windowHandle()->isExposed()); } +void tst_QSplashScreen::checkScreenConstructor() +{ + for (const auto screen : QGuiApplication::screens()) { + QSplashScreen splash(screen); + splash.show(); + QCOMPARE(splash.screen(), screen); + QVERIFY(splash.windowHandle()); + QCOMPARE(splash.windowHandle()->screen(), screen); + } +} + QTEST_MAIN(tst_QSplashScreen) #include "tst_qsplashscreen.moc" diff --git a/tests/baselineserver/shared/qbaselinetest.cpp b/tests/baselineserver/shared/qbaselinetest.cpp index 11fb208f20..3587cd01ea 100644 --- a/tests/baselineserver/shared/qbaselinetest.cpp +++ b/tests/baselineserver/shared/qbaselinetest.cpp @@ -28,10 +28,8 @@ #include "qbaselinetest.h" #include "baselineprotocol.h" -#if QT_CONFIG(process) -# include <QtCore/QProcess> -#endif #include <QtCore/QDir> +#include <QFile> #define MAXCMDLINEARGS 128 @@ -146,20 +144,15 @@ void addClientProperty(const QString& key, const QString& value) */ void fetchCustomClientProperties() { -#if !QT_CONFIG(process) - QSKIP("This test requires QProcess support"); -#else - QString script = "hostinfo.sh"; //### TBD: Windows implementation (hostinfo.bat) - - QProcess runScript; - runScript.setWorkingDirectory(QCoreApplication::applicationDirPath()); - runScript.start("sh", QStringList() << script, QIODevice::ReadOnly); - if (!runScript.waitForFinished(5000) || runScript.error() != QProcess::UnknownError) { - qWarning() << "QBaselineTest: Error running script" << runScript.workingDirectory() + QDir::separator() + script << ":" << runScript.errorString(); - qDebug() << " stderr:" << runScript.readAllStandardError().trimmed(); - } - while (!runScript.atEnd()) { - QByteArray line = runScript.readLine().trimmed(); // ###local8bit? utf8? + QFile file("hostinfo.txt"); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + return; + QTextStream in(&file); + + while (!in.atEnd()) { + QString line = in.readLine().trimmed(); // ###local8bit? utf8? + if (line.startsWith(QLatin1Char('#'))) // Ignore comments in file + continue; QString key, val; int colonPos = line.indexOf(':'); if (colonPos > 0) { @@ -171,7 +164,6 @@ void fetchCustomClientProperties() else qDebug() << "Unparseable script output ignored:" << line; } -#endif // QT_CONFIG(process) } diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro b/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro index 86102adecd..a1827d0276 100644 --- a/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro +++ b/tests/benchmarks/corelib/thread/qreadwritelock/qreadwritelock.pro @@ -1,6 +1,7 @@ TEMPLATE = app TARGET = tst_bench_qreadwritelock -QT = core testlib +QT = core-private testlib SOURCES += tst_qreadwritelock.cpp CONFIG += c++14 # for std::shared_timed_mutex +CONFIG += c++1z # for std::shared_mutex diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index fcf600a059..1d47d98657 100644 --- a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -28,12 +28,14 @@ #include <QtCore/QtCore> #include <QtTest/QtTest> +#include <QtCore/private/qmemory_p.h> #include <mutex> #if QT_HAS_INCLUDE(<shared_mutex>) #if __cplusplus > 201103L #include <shared_mutex> #endif #endif +#include <vector> // Wrapers that take pointers instead of reference to have the same interface as Qt template <typename T> @@ -63,6 +65,8 @@ private slots: void uncontended(); void readOnly_data(); void readOnly(); + void writeOnly_data(); + void writeOnly(); // void readWrite(); }; @@ -106,6 +110,14 @@ void tst_QReadWriteLock::uncontended_data() << FunctionPtrHolder(testUncontended<QReadWriteLock, QWriteLocker>); QTest::newRow("std::mutex") << FunctionPtrHolder( testUncontended<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex, read") << FunctionPtrHolder( + testUncontended<std::shared_mutex, + LockerWrapper<std::shared_lock<std::shared_mutex>>>); + QTest::newRow("std::shared_mutex, write") << FunctionPtrHolder( + testUncontended<std::shared_mutex, + LockerWrapper<std::unique_lock<std::shared_mutex>>>); +#endif #if defined __cpp_lib_shared_timed_mutex QTest::newRow("std::shared_timed_mutex, read") << FunctionPtrHolder( testUncontended<std::shared_timed_mutex, @@ -130,7 +142,7 @@ void testReadOnly() struct Thread : QThread { Mutex *lock; - void run() + void run() override { for (int i = 0; i < Iterations; ++i) { QString s = QString::number(i); // Do something outside the lock @@ -140,21 +152,20 @@ void testReadOnly() } }; Mutex lock; - QVector<QThread *> threads; + std::vector<std::unique_ptr<Thread>> threads; for (int i = 0; i < threadCount; ++i) { - auto t = new Thread; + auto t = qt_make_unique<Thread>(); t->lock = &lock; - threads.append(t); + threads.push_back(std::move(t)); } QBENCHMARK { - for (auto t : threads) { + for (auto &t : threads) { t->start(); } - for (auto t : threads) { + for (auto &t : threads) { t->wait(); } } - qDeleteAll(threads); } void tst_QReadWriteLock::readOnly_data() @@ -166,6 +177,11 @@ void tst_QReadWriteLock::readOnly_data() QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testReadOnly<QReadWriteLock, QReadLocker>); QTest::newRow("std::mutex") << FunctionPtrHolder( testReadOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex") << FunctionPtrHolder( + testReadOnly<std::shared_mutex, + LockerWrapper<std::shared_lock<std::shared_mutex>>>); +#endif #if defined __cpp_lib_shared_timed_mutex QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( testReadOnly<std::shared_timed_mutex, @@ -179,5 +195,66 @@ void tst_QReadWriteLock::readOnly() holder.value(); } +static QString global_string; + +template <typename Mutex, typename Locker> +void testWriteOnly() +{ + struct Thread : QThread + { + Mutex *lock; + void run() override + { + for (int i = 0; i < Iterations; ++i) { + QString s = QString::number(i); // Do something outside the lock + Locker locker(lock); + global_string = s; + } + } + }; + Mutex lock; + std::vector<std::unique_ptr<Thread>> threads; + for (int i = 0; i < threadCount; ++i) { + auto t = qt_make_unique<Thread>(); + t->lock = &lock; + threads.push_back(std::move(t)); + } + QBENCHMARK { + for (auto &t : threads) { + t->start(); + } + for (auto &t : threads) { + t->wait(); + } + } +} + +void tst_QReadWriteLock::writeOnly_data() +{ + QTest::addColumn<FunctionPtrHolder>("holder"); + + // QTest::newRow("nothing") << FunctionPtrHolder(testWriteOnly<int, FakeLock>); + QTest::newRow("QMutex") << FunctionPtrHolder(testWriteOnly<QMutex, QMutexLocker>); + QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testWriteOnly<QReadWriteLock, QWriteLocker>); + QTest::newRow("std::mutex") << FunctionPtrHolder( + testWriteOnly<std::mutex, LockerWrapper<std::unique_lock<std::mutex>>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex") << FunctionPtrHolder( + testWriteOnly<std::shared_mutex, + LockerWrapper<std::unique_lock<std::shared_mutex>>>); +#endif +#if defined __cpp_lib_shared_timed_mutex + QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( + testWriteOnly<std::shared_timed_mutex, + LockerWrapper<std::unique_lock<std::shared_timed_mutex>>>); +#endif +} + +void tst_QReadWriteLock::writeOnly() +{ + QFETCH(FunctionPtrHolder, holder); + holder.value(); +} + QTEST_MAIN(tst_QReadWriteLock) #include "tst_qreadwritelock.moc" diff --git a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp index b88669e9ce..b8afb3bc05 100644 --- a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp +++ b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp @@ -342,6 +342,7 @@ void tst_QImageConversion::convertGenericInplace_data() QImage argb6666 = argb32.convertToFormat(QImage::Format_ARGB6666_Premultiplied); QImage argb4444 = argb32.convertToFormat(QImage::Format_ARGB4444_Premultiplied); QImage rgb16 = argb32.convertToFormat(QImage::Format_RGB16); + QImage rgb30 = argb32.convertToFormat(QImage::Format_RGB30); QImage rgb888 = argb32.convertToFormat(QImage::Format_RGB888); QTest::newRow("argb32 -> argb32pm -> argb32") << argb32 << QImage::Format_ARGB32_Premultiplied; @@ -370,6 +371,7 @@ void tst_QImageConversion::convertGenericInplace_data() QTest::newRow("rgb16 -> rgb444 -> rgb16") << rgb16 << QImage::Format_RGB444; QTest::newRow("rgb16 -> argb4444pm -> rgb16") << rgb16 << QImage::Format_ARGB4444_Premultiplied; + QTest::newRow("rgb30 -> bgr30 -> rgb30") << rgb30 << QImage::Format_BGR30; QTest::newRow("rgb888 -> bgr888 -> rgb888") << rgb888 << QImage::Format_BGR888; } diff --git a/tests/manual/qgraphicslayout/flicker/window.h b/tests/manual/qgraphicslayout/flicker/window.h index 3e7bc61731..c49b82704e 100644 --- a/tests/manual/qgraphicslayout/flicker/window.h +++ b/tests/manual/qgraphicslayout/flicker/window.h @@ -107,7 +107,7 @@ public: Q_UNUSED(option); Q_UNUSED(widget); painter->setBrush(m_brush); - painter->drawRoundedRect(rect(), Qt::RelativeSize); + painter->drawRoundedRect(rect(), 25, 25, Qt::RelativeSize); painter->drawLine(rect().topLeft(), rect().bottomRight()); painter->drawLine(rect().bottomLeft(), rect().topRight()); } diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h index 1a29ef5f7e..4bd087473b 100644 --- a/tests/manual/rhi/shared/examplefw.h +++ b/tests/manual/rhi/shared/examplefw.h @@ -126,6 +126,7 @@ int sampleCount = 1; QRhiSwapChain::Flags scFlags = 0; QRhi::BeginFrameFlags beginFrameFlags = 0; QRhi::EndFrameFlags endFrameFlags = 0; +int framesUntilTdr = -1; class Window : public QWindow { @@ -278,6 +279,10 @@ void Window::init() if (graphicsApi == D3D11) { QRhiD3D11InitParams params; params.enableDebugLayer = true; + if (framesUntilTdr > 0) { + params.framesUntilKillingDeviceViaTdr = framesUntilTdr; + params.repeatDeviceKill = true; + } m_r = QRhi::create(QRhi::D3D11, ¶ms, rhiFlags); } #endif @@ -461,8 +466,17 @@ int main(int argc, char **argv) // Testing cleanup both with QWindow::close() (hitting X or Alt-F4) and // QCoreApplication::quit() (e.g. what a menu widget would do) is important. // Use this parameter for the latter. - QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self destruct after 5 seconds")); + QCommandLineOption sdOption({ "s", "self-destruct" }, QLatin1String("Self-destruct after 5 seconds.")); cmdLineParser.addOption(sdOption); + // Attempt testing device lost situations on D3D at least. + QCommandLineOption tdrOption(QLatin1String("curse"), QLatin1String("Curse the graphics device. " + "(generate a device reset every <count> frames when on D3D11)"), + QLatin1String("count")); + cmdLineParser.addOption(tdrOption); + // Allow testing preferring the software adapter (D3D). + QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. " + "Only applicable with some APIs and platforms.")); + cmdLineParser.addOption(swOption); cmdLineParser.process(app); if (cmdLineParser.isSet(nullOption)) @@ -521,6 +535,12 @@ int main(int argc, char **argv) } #endif + if (cmdLineParser.isSet(tdrOption)) + framesUntilTdr = cmdLineParser.value(tdrOption).toInt(); + + if (cmdLineParser.isSet(swOption)) + rhiFlags |= QRhi::PreferSoftwareRenderer; + // Create and show the window. Window w; #if QT_CONFIG(vulkan) |