summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-10-02 01:01:20 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2019-10-02 08:39:15 +0200
commit4c8814a341aace34f9a6011e9ec16048dc0f18b6 (patch)
tree3f3193c51c0883ae70de3ae3a3b225b3c7b9b8cc /tests
parent009d86da2d5a928865819fe44b4d1c78d455bbb9 (diff)
parent8791a8398ac232a8daab98601f1bef88bdf7638f (diff)
Merge remote-tracking branch 'origin/5.15' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp15
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp6
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp2
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp6
-rw-r--r--tests/auto/corelib/tools/collections/BLACKLIST2
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/BLACKLIST6
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro2
-rw-r--r--tests/auto/gui/kernel/qwindow/tst_qwindow.cpp8
-rw-r--r--tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp4
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp21
-rw-r--r--tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp52
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp9
-rw-r--r--tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp687
-rw-r--r--tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp141
-rw-r--r--tests/auto/widgets/itemviews/qitemview/viewstotest.cpp21
-rw-r--r--tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp84
-rw-r--r--tests/manual/highdpi/main.cpp2
-rw-r--r--tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp2
-rw-r--r--tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp2
-rw-r--r--tests/manual/rhi/computebuffer/computebuffer.cpp2
-rw-r--r--tests/manual/rhi/computeimage/computeimage.cpp2
-rw-r--r--tests/manual/rhi/cubemap/cubemap.cpp2
-rw-r--r--tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp241
-rw-r--r--tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro8
-rw-r--r--tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc7
-rw-r--r--tests/manual/rhi/floattexture/floattexture.cpp2
-rw-r--r--tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp10
-rw-r--r--tests/manual/rhi/instancing/instancing.cpp2
-rw-r--r--tests/manual/rhi/mrt/mrt.cpp12
-rw-r--r--tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp2
-rw-r--r--tests/manual/rhi/msaatexture/msaatexture.cpp4
-rw-r--r--tests/manual/rhi/multiwindow/multiwindow.cpp8
-rw-r--r--tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp8
-rw-r--r--tests/manual/rhi/rhi.pro1
-rw-r--r--tests/manual/rhi/shadowmap/shadowmap.cpp2
-rw-r--r--tests/manual/rhi/shared/examplefw.h30
-rw-r--r--tests/manual/rhi/texuploads/texuploads.cpp27
-rw-r--r--tests/manual/rhi/triquadcube/trianglerenderer.cpp4
-rw-r--r--tests/manual/rhi/triquadcube/triquadcube.cpp2
39 files changed, 857 insertions, 591 deletions
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
index 5697d21547..a6d600e125 100644
--- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
+++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
@@ -44,6 +44,9 @@ private slots:
void fuzzyCompare();
void rawNaN_data();
void rawNaN();
+#if QT_CONFIG(signaling_nan)
+ void distinctNaN();
+#endif
void generalNaN_data();
void generalNaN();
void infinity();
@@ -139,6 +142,9 @@ void tst_QNumeric::rawNaN_data()
QTest::addColumn<double>("nan");
QTest::newRow("quiet") << qQNaN();
+#if QT_CONFIG(signaling_nan)
+ QTest::newRow("signaling") << qSNaN();
+#endif
}
void tst_QNumeric::rawNaN()
@@ -147,6 +153,15 @@ void tst_QNumeric::rawNaN()
checkNaN(nan);
}
+#if QT_CONFIG(signaling_nan)
+void tst_QNumeric::distinctNaN()
+{
+ const double qnan = qQNaN();
+ const double snan = qSNaN();
+ QVERIFY(memcmp(&qnan, &snan, sizeof(double)) != 0);
+}
+#endif
+
void tst_QNumeric::generalNaN_data()
{
QTest::addColumn<int>("most");
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index e238be1de3..6f9dcc08f9 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -320,7 +320,7 @@ void tst_QRandomGenerator::generate32_data()
QTest::newRow("fixed") << (RandomValue32 & RandomDataMask);
QTest::newRow("global") << 0U;
#ifdef QT_BUILD_INTERNAL
- if (qt_has_hwrng())
+ if (qHasHwrng())
QTest::newRow("hwrng") << uint(UseSystemRNG);
QTest::newRow("system") << uint(UseSystemRNG | SkipHWRNG);
# ifdef HAVE_FALLBACK_ENGINE
@@ -755,7 +755,7 @@ void tst_QRandomGenerator::stdUniformIntDistribution_data()
auto newRow = [&](quint32 max) {
#ifdef QT_BUILD_INTERNAL
- if (qt_has_hwrng())
+ if (qHasHwrng())
QTest::addRow("hwrng:%u", max) << uint(UseSystemRNG) << max;
QTest::addRow("system:%u", max) << uint(UseSystemRNG | SkipHWRNG) << max;
# ifdef HAVE_FALLBACK_ENGINE
@@ -868,7 +868,7 @@ void tst_QRandomGenerator::stdUniformRealDistribution_data()
auto newRow = [&](double min, double sup) {
#ifdef QT_BUILD_INTERNAL
- if (qt_has_hwrng())
+ if (qHasHwrng())
QTest::addRow("hwrng:%g-%g", min, sup) << uint(UseSystemRNG) << min << sup;
QTest::addRow("system:%g-%g", min, sup) << uint(UseSystemRNG | SkipHWRNG) << min << sup;
# ifdef HAVE_FALLBACK_ENGINE
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index 6fa82ea681..c6733205e5 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -1413,10 +1413,12 @@ void tst_QCborValue::toCbor_data()
// The rest of these tests are conversions whose decoding does not yield
// back the same QCborValue.
+#if QT_CONFIG(signaling_nan)
// Signalling NaN get normalized to quiet ones
QTest::newRow("Double:snan") << QCborValue(qSNaN()) << raw("\xfb\x7f\xf8\0""\0\0\0\0\0") << QCborValue::EncodingOptions();
QTest::newRow("Float:snan") << QCborValue(qSNaN()) << raw("\xfa\x7f\xc0\0\0") << QCborValue::EncodingOptions(QCborValue::UseFloat);
QTest::newRow("Float16:snan") << QCborValue(qSNaN()) << raw("\xf9\x7e\0") << QCborValue::EncodingOptions(QCborValue::UseFloat16);
+#endif
// Floating point written as integers are read back as integers
QTest::newRow("UseInteger:0") << QCborValue(0.) << raw("\x00") << QCborValue::EncodingOptions(QCborValue::UseIntegers);
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 531ac2995f..99176dc68d 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -3468,6 +3468,9 @@ void tst_QDateTime::timeZones() const
void tst_QDateTime::systemTimeZoneChange() const
{
+#ifdef Q_OS_WINRT
+ QSKIP("UWP applications cannot change the system`s time zone (sandboxing)");
+#endif
// Set the timezone to Brisbane time
TimeZoneRollback useZone(QByteArray("AEST-10:00"));
@@ -3485,9 +3488,6 @@ void tst_QDateTime::systemTimeZoneChange() const
useZone.reset(QByteArray("IST-05:30"));
QCOMPARE(localDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::LocalTime));
-#ifdef Q_OS_WINRT
- QEXPECT_FAIL("", "WinRT gets this wrong, QTBUG-71185", Continue);
-#endif
QVERIFY(localMsecs != localDate.toMSecsSinceEpoch());
QCOMPARE(utcDate, QDateTime(QDate(2012, 6, 1), QTime(2, 15, 30), Qt::UTC));
QCOMPARE(utcDate.toMSecsSinceEpoch(), utcMsecs);
diff --git a/tests/auto/corelib/tools/collections/BLACKLIST b/tests/auto/corelib/tools/collections/BLACKLIST
deleted file mode 100644
index c6e289aadb..0000000000
--- a/tests/auto/corelib/tools/collections/BLACKLIST
+++ /dev/null
@@ -1,2 +0,0 @@
-[insert_remove_loop]
-msvc-2019
diff --git a/tests/auto/gui/kernel/qopenglwindow/BLACKLIST b/tests/auto/gui/kernel/qopenglwindow/BLACKLIST
new file mode 100644
index 0000000000..3ce78abee8
--- /dev/null
+++ b/tests/auto/gui/kernel/qopenglwindow/BLACKLIST
@@ -0,0 +1,6 @@
+[basic]
+winrt
+[resize]
+winrt
+[painter]
+winrt
diff --git a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
index d09af5084b..759b608c93 100644
--- a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
+++ b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
@@ -4,5 +4,3 @@ TARGET = tst_qopenglwindow
QT += core-private gui-private testlib
SOURCES += tst_qopenglwindow.cpp
-
-win32:CONFIG+=insignificant_test # QTBUG-46452, QTBUG-49630
diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
index 1290347eab..34de756ab5 100644
--- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
+++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp
@@ -893,7 +893,13 @@ void tst_QWindow::isActive()
QTRY_COMPARE(QGuiApplication::focusWindow(), &window);
QCoreApplication::processEvents();
QTRY_COMPARE(dialog.received(QEvent::FocusOut), 1);
- QTRY_COMPARE(window.received(QEvent::FocusIn), 3);
+ // We should be checking for exactly three, but since this is a try-compare _loop_, we might
+ // loose and regain focus multiple times in the event of a system popup. This has been observed
+ // to fail on Windows, see QTBUG-77769.
+ QTRY_VERIFY2(window.received(QEvent::FocusIn) >= 3,
+ qPrintable(
+ QStringLiteral("Expected more than three focus in events, received: %1")
+ .arg(window.received(QEvent::FocusIn))));
QVERIFY(window.isActive());
diff --git a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
index 67cf9a321a..86a8965cec 100644
--- a/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
+++ b/tests/auto/gui/painting/qpainterpath/tst_qpainterpath.cpp
@@ -88,7 +88,9 @@ private slots:
void testToFillPolygons();
+#if QT_CONFIG(signaling_nan)
void testNaNandInfinites();
+#endif
void closing();
@@ -1228,6 +1230,7 @@ void tst_QPainterPath::testToFillPolygons()
QCOMPARE(polygons.first().count(QPointF(70, 50)), 0);
}
+#if QT_CONFIG(signaling_nan)
void tst_QPainterPath::testNaNandInfinites()
{
QPainterPath path1;
@@ -1271,6 +1274,7 @@ void tst_QPainterPath::testNaNandInfinites()
path1.lineTo(QPointF(1, 1));
QVERIFY(path1 != path2);
}
+#endif // signaling_nan
void tst_QPainterPath::connectPathDuplicatePoint()
{
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 1ee9105cd2..d722856366 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -66,6 +66,8 @@ private slots:
void defaultFamily();
void toAndFromString();
void fromStringWithoutStyleName();
+ void fromDegenerateString_data();
+ void fromDegenerateString();
void sharing();
void familyNameWithCommaQuote_data();
@@ -604,6 +606,25 @@ void tst_QFont::fromStringWithoutStyleName()
QCOMPARE(font2.toString(), str);
}
+void tst_QFont::fromDegenerateString_data()
+{
+ QTest::addColumn<QString>("string");
+
+ QTest::newRow("empty") << QString();
+ QTest::newRow("justAComma") << ",";
+ QTest::newRow("commasAndSpaces") << " , , ";
+ QTest::newRow("spaces") << " ";
+ QTest::newRow("spacesTabsAndNewlines") << " \t \n";
+}
+
+void tst_QFont::fromDegenerateString()
+{
+ QFETCH(QString, string);
+ QFont f;
+ QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Invalid description.*"));
+ QCOMPARE(f.fromString(string), false);
+ QCOMPARE(f, QFont());
+}
void tst_QFont::sharing()
{
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
index 4e02320362..2fef31cdc2 100644
--- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -823,7 +823,9 @@ void tst_QSslSocket::connectToHostEncrypted()
socket->setProtocol(QSsl::SslProtocol::TlsV1_1);
#endif
this->socket = socket.data();
- QVERIFY(socket->addCaCertificates(httpServerCertChainPath()));
+ auto config = socket->sslConfiguration();
+ QVERIFY(config.addCaCertificates(httpServerCertChainPath()));
+ socket->setSslConfiguration(config);
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@@ -860,7 +862,9 @@ void tst_QSslSocket::connectToHostEncryptedWithVerificationPeerName()
#endif
this->socket = socket.data();
- socket->addCaCertificates(httpServerCertChainPath());
+ auto config = socket->sslConfiguration();
+ config.addCaCertificates(httpServerCertChainPath());
+ socket->setSslConfiguration(config);
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@@ -965,7 +969,9 @@ void tst_QSslSocket::peerCertificateChain()
this->socket = socket.data();
QList<QSslCertificate> caCertificates = QSslCertificate::fromPath(httpServerCertChainPath());
QCOMPARE(caCertificates.count(), 1);
- socket->addCaCertificates(caCertificates);
+ auto config = socket->sslConfiguration();
+ config.addCaCertificates(caCertificates);
+ socket->setSslConfiguration(config);
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)),
this, SLOT(untrustedWorkaroundSlot(QList<QSslError>)));
@@ -1224,10 +1230,10 @@ signals:
protected:
void incomingConnection(qintptr socketDescriptor)
{
+ QSslConfiguration configuration = config;
socket = new QSslSocket(this);
- socket->setSslConfiguration(config);
- socket->setPeerVerifyMode(peerVerifyMode);
- socket->setProtocol(protocol);
+ configuration.setPeerVerifyMode(peerVerifyMode);
+ configuration.setProtocol(protocol);
if (ignoreSslErrors)
connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SIGNAL(socketError(QAbstractSocket::SocketError)));
@@ -1236,14 +1242,14 @@ protected:
QVERIFY(file.open(QIODevice::ReadOnly));
QSslKey key(file.readAll(), QSsl::Rsa, QSsl::Pem, QSsl::PrivateKey);
QVERIFY(!key.isNull());
- socket->setPrivateKey(key);
+ configuration.setPrivateKey(key);
// Add CA certificates to verify client certificate
if (!addCaCertificates.isEmpty()) {
QList<QSslCertificate> caCert = QSslCertificate::fromPath(addCaCertificates);
QVERIFY(!caCert.isEmpty());
QVERIFY(!caCert.first().isNull());
- socket->addCaCertificates(caCert);
+ configuration.addCaCertificates(caCert);
}
// If we have a cert issued directly from the CA
@@ -1251,9 +1257,8 @@ protected:
QList<QSslCertificate> localCert = QSslCertificate::fromPath(m_certFile);
QVERIFY(!localCert.isEmpty());
QVERIFY(!localCert.first().isNull());
- socket->setLocalCertificate(localCert.first());
- }
- else {
+ configuration.setLocalCertificate(localCert.first());
+ } else {
QList<QSslCertificate> localCert = QSslCertificate::fromPath(m_certFile);
QVERIFY(!localCert.isEmpty());
QVERIFY(!localCert.first().isNull());
@@ -1262,14 +1267,12 @@ protected:
QVERIFY(!interCert.isEmpty());
QVERIFY(!interCert.first().isNull());
- socket->setLocalCertificateChain(localCert + interCert);
+ configuration.setLocalCertificateChain(localCert + interCert);
}
- if (!ciphers.isEmpty()) {
- auto sslConfig = socket->sslConfiguration();
- sslConfig.setCiphers(ciphers);
- socket->setSslConfiguration(sslConfig);
- }
+ if (!ciphers.isEmpty())
+ configuration.setCiphers(ciphers);
+ socket->setSslConfiguration(configuration);
QVERIFY(socket->setSocketDescriptor(socketDescriptor, QAbstractSocket::ConnectedState));
QVERIFY(!socket->peerAddress().isNull());
@@ -1748,7 +1751,8 @@ void tst_QSslSocket::addDefaultCaCertificate()
QCOMPARE(flukeCerts.size(), 1);
QList<QSslCertificate> globalCerts = QSslConfiguration::defaultConfiguration().caCertificates();
QVERIFY(!globalCerts.contains(flukeCerts.first()));
- QSslSocket::addDefaultCaCertificate(flukeCerts.first());
+ sslConfig.addCaCertificate(flukeCerts.first());
+ QSslConfiguration::setDefaultConfiguration(sslConfig);
QCOMPARE(QSslConfiguration::defaultConfiguration().caCertificates().size(),
globalCerts.size() + 1);
QVERIFY(QSslConfiguration::defaultConfiguration().caCertificates()
@@ -1941,7 +1945,9 @@ void tst_QSslSocket::wildcard()
// responds with the wildcard, and QSslSocket should accept that as a
// valid connection. This was broken in 4.3.0.
QSslSocketPtr socket = newSocket();
- socket->addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt"));
+ auto config = socket->sslConfiguration();
+ config.addCaCertificates(QLatin1String("certs/aspiriniks.ca.crt"));
+ socket->setSslConfiguration(config);
this->socket = socket.data();
#ifdef QSSLSOCKET_CERTUNTRUSTED_WORKAROUND
connect(socket, SIGNAL(sslErrors(QList<QSslError>)),
@@ -2572,7 +2578,9 @@ void tst_QSslSocket::resetProxy()
// make sure the connection works, and then set a nonsense proxy, and then
// make sure it does not work anymore
QSslSocket socket;
- socket.addCaCertificates(httpServerCertChainPath());
+ auto config = socket.sslConfiguration();
+ config.addCaCertificates(httpServerCertChainPath());
+ socket.setSslConfiguration(config);
socket.setProxy(goodProxy);
socket.connectToHostEncrypted(QtNetworkSettings::httpServerName(), 443);
QVERIFY2(socket.waitForConnected(10000), qPrintable(socket.errorString()));
@@ -2591,7 +2599,9 @@ void tst_QSslSocket::resetProxy()
// set the nonsense proxy and make sure the connection does not work,
// and then set the right proxy and make sure it works
QSslSocket socket2;
- socket2.addCaCertificates(httpServerCertChainPath());
+ auto config2 = socket.sslConfiguration();
+ config2.addCaCertificates(httpServerCertChainPath());
+ socket2.setSslConfiguration(config2);
socket2.setProxy(badProxy);
socket2.connectToHostEncrypted(QtNetworkSettings::httpServerName(), 443);
QVERIFY(! socket2.waitForConnected(10000));
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index 243cb6483e..6091975acb 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -2712,13 +2712,8 @@ void tst_QWizard::taskQTBUG_46894_nextButtonShortcut()
wizard.show();
QVERIFY(QTest::qWaitForWindowExposed(&wizard));
- if (wizard.button(QWizard::NextButton)->text() == "&Next") {
- QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
- QKeySequence(Qt::ALT | Qt::Key_Right));
- } else {
- QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
- QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text()));
- }
+ QCOMPARE(wizard.button(QWizard::NextButton)->shortcut(),
+ QKeySequence::mnemonic(wizard.button(QWizard::NextButton)->text()));
}
}
diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
index df02815eb2..df1b271f2a 100644
--- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp
@@ -27,32 +27,28 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
+#include <QDesktopWidget>
+#include <QHeaderView>
+#include <QProxyStyle>
+#include <QSignalSpy>
+#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QStringListModel>
-#include <QSortFilterProxyModel>
#include <QTableView>
-#include <QProxyStyle>
+#include <QTest>
+#include <QTreeWidget>
+#include <QtWidgets/private/qheaderview_p.h>
-#include <qabstractitemmodel.h>
-#include <qapplication.h>
-#include <qheaderview.h>
-#include <private/qheaderview_p.h>
-#include <qitemdelegate.h>
-#include <qtreewidget.h>
-#include <qdebug.h>
-#include <qscreen.h>
-#include <qdesktopwidget.h>
-
-typedef QList<int> IntList;
-
-typedef QList<bool> BoolList;
+using BoolList = QVector<bool>;
+using IntList = QVector<int>;
+using ResizeVec = QVector<QHeaderView::ResizeMode>;
class TestStyle : public QProxyStyle
{
+ Q_OBJECT
public:
- void drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
+ void drawControl(ControlElement element, const QStyleOption *option,
+ QPainter *painter, const QWidget *widget) const override
{
if (element == CE_HeaderSection) {
if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option))
@@ -60,16 +56,17 @@ public:
}
QProxyStyle::drawControl(element, option, painter, widget);
}
- mutable QStyleOptionHeader::SectionPosition lastPosition;
+ mutable QStyleOptionHeader::SectionPosition lastPosition = QStyleOptionHeader::Beginning;
};
class protected_QHeaderView : public QHeaderView
{
Q_OBJECT
public:
- protected_QHeaderView(Qt::Orientation orientation) : QHeaderView(orientation) {
+ protected_QHeaderView(Qt::Orientation orientation) : QHeaderView(orientation)
+ {
resizeSections();
- };
+ }
void testEvent();
void testhorizontalOffset();
@@ -80,7 +77,9 @@ public:
class XResetModel : public QStandardItemModel
{
- virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
+ Q_OBJECT
+public:
+ bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
{
blockSignals(true);
bool r = QStandardItemModel::removeRows(row, count, parent);
@@ -89,7 +88,7 @@ class XResetModel : public QStandardItemModel
endResetModel();
return r;
}
- virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
+ bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override
{
blockSignals(true);
bool r = QStandardItemModel::insertRows(row, count, parent);
@@ -276,16 +275,14 @@ void tst_QHeaderView::initMain()
class QtTestModel: public QAbstractTableModel
{
-
-Q_OBJECT
-
+ Q_OBJECT
public:
- QtTestModel(QObject *parent = 0): QAbstractTableModel(parent),
- cols(0), rows(0), wrongIndex(false), m_bMultiLine(false) {}
- int rowCount(const QModelIndex&) const override { return rows; }
- int columnCount(const QModelIndex&) const override { return cols; }
+ QtTestModel(int rc, int cc, QObject *parent = nullptr)
+ : QAbstractTableModel(parent), rows(rc), cols(cc) {}
+ int rowCount(const QModelIndex &) const override { return rows; }
+ int columnCount(const QModelIndex &) const override { return cols; }
bool isEditable(const QModelIndex &) const { return true; }
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
+ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override
{
if (section < 0 || (role != Qt::DisplayRole && role != Qt::StatusTipRole))
return QVariant();
@@ -394,9 +391,10 @@ public:
endResetModel();
}
- int cols, rows;
- mutable bool wrongIndex;
- bool m_bMultiLine;
+ int rows = 0;
+ int cols = 0;
+ mutable bool wrongIndex = false;
+ bool m_bMultiLine = false;
};
// Testing get/set functions
@@ -442,16 +440,16 @@ void tst_QHeaderView::getSetCheck()
// void QHeaderView::setOffset(int)
obj1.setOffset(0);
QCOMPARE(0, obj1.offset());
- obj1.setOffset(INT_MIN);
- QCOMPARE(INT_MIN, obj1.offset());
- obj1.setOffset(INT_MAX);
- QCOMPARE(INT_MAX, obj1.offset());
+ obj1.setOffset(std::numeric_limits<int>::min());
+ QCOMPARE(std::numeric_limits<int>::min(), obj1.offset());
+ obj1.setOffset(std::numeric_limits<int>::max());
+ QCOMPARE(std::numeric_limits<int>::max(), obj1.offset());
}
tst_QHeaderView::tst_QHeaderView()
{
- qRegisterMetaType<int>("Qt::SortOrder");
+ qRegisterMetaType<Qt::SortOrder>("Qt::SortOrder");
}
void tst_QHeaderView::initTestCase()
@@ -472,8 +470,8 @@ void tst_QHeaderView::cleanupTestCase()
void tst_QHeaderView::init()
{
- topLevel = new QWidget();
- view = new QHeaderView(Qt::Vertical,topLevel);
+ topLevel = new QWidget;
+ view = new QHeaderView(Qt::Vertical, topLevel);
// Some initial value tests before a model is added
QCOMPARE(view->length(), 0);
QCOMPARE(view->sizeHint(), QSize(0,0));
@@ -499,7 +497,7 @@ void tst_QHeaderView::init()
}
*/
- QSignalSpy spy(view, SIGNAL(sectionCountChanged(int,int)));
+ QSignalSpy spy(view, &QHeaderView::sectionCountChanged);
view->setModel(model);
QCOMPARE(spy.count(), 1);
view->resize(200,200);
@@ -510,11 +508,11 @@ void tst_QHeaderView::cleanup()
m_tableview->setUpdatesEnabled(true);
if (view && view->parent() != m_tableview)
delete view;
- view = 0;
+ view = nullptr;
delete model;
- model = 0;
+ model = nullptr;
delete topLevel;
- topLevel = 0;
+ topLevel = nullptr;
}
void tst_QHeaderView::noModel()
@@ -525,7 +523,7 @@ void tst_QHeaderView::noModel()
void tst_QHeaderView::emptyModel()
{
- QtTestModel testmodel;
+ QtTestModel testmodel(0, 0);
view->setModel(&testmodel);
QVERIFY(!testmodel.wrongIndex);
QCOMPARE(view->count(), testmodel.rows);
@@ -534,8 +532,7 @@ void tst_QHeaderView::emptyModel()
void tst_QHeaderView::removeRows()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QHeaderView vertical(Qt::Vertical);
QHeaderView horizontal(Qt::Horizontal);
@@ -561,8 +558,7 @@ void tst_QHeaderView::removeRows()
void tst_QHeaderView::removeCols()
{
- QtTestModel model;
- model.rows = model.cols = 10;
+ QtTestModel model(10, 10);
QHeaderView vertical(Qt::Vertical);
QHeaderView horizontal(Qt::Horizontal);
@@ -644,14 +640,12 @@ void tst_QHeaderView::hidden()
view->setSectionHidden(i, true);
view->setModel(&model2);
QVERIFY(view->sectionsHidden());
- for (int i = 0; i < model2.rowCount(); ++i) {
+ for (int i = 0; i < model2.rowCount(); ++i)
QVERIFY(view->isSectionHidden(i));
- }
view->setModel(model);
- for (int i = 0; i < model2.rowCount(); ++i) {
+ for (int i = 0; i < model2.rowCount(); ++i)
QVERIFY(view->isSectionHidden(i));
- }
QCOMPARE(view->isSectionHidden(model->rowCount() - 1), false);
for (int i = 0; i < model->rowCount(); ++i)
view->setSectionHidden(i, false);
@@ -680,14 +674,12 @@ void tst_QHeaderView::oneSectionSize()
{
//this ensures that if there is only one section, it gets a correct width (more than 0)
QHeaderView view (Qt::Vertical);
- QtTestModel model;
- model.cols = 1;
- model.rows = 1;
+ QtTestModel model(1, 1);
view.setSectionResizeMode(QHeaderView::Interactive);
view.setModel(&model);
-
view.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&view));
QVERIFY(view.sectionSize(0) > 0);
}
@@ -695,15 +687,15 @@ void tst_QHeaderView::oneSectionSize()
void tst_QHeaderView::sectionSize_data()
{
- QTest::addColumn<QList<int> >("boundsCheck");
- QTest::addColumn<QList<int> >("defaultSizes");
+ QTest::addColumn<IntList>("boundsCheck");
+ QTest::addColumn<IntList>("defaultSizes");
QTest::addColumn<int>("initialDefaultSize");
QTest::addColumn<int>("lastVisibleSectionSize");
QTest::addColumn<int>("persistentSectionSize");
QTest::newRow("data set one")
- << (QList<int>() << -1 << 0 << 4 << 9999)
- << (QList<int>() << 10 << 30 << 30)
+ << (IntList{ -1, 0, 4, 9999 })
+ << (IntList{ 10, 30, 30 })
<< 30
<< 300
<< 20;
@@ -716,19 +708,19 @@ void tst_QHeaderView::sectionSize()
#elif defined Q_OS_WINRT
QSKIP("Fails on WinRT - QTBUG-68297");
#endif
- QFETCH(QList<int>, boundsCheck);
- QFETCH(QList<int>, defaultSizes);
+ QFETCH(const IntList, boundsCheck);
+ QFETCH(const IntList, defaultSizes);
QFETCH(int, initialDefaultSize);
QFETCH(int, lastVisibleSectionSize);
QFETCH(int, persistentSectionSize);
// bounds check
- foreach (int val, boundsCheck)
+ for (int val : boundsCheck)
view->sectionSize(val);
// default size
QCOMPARE(view->defaultSectionSize(), initialDefaultSize);
- foreach (int def, defaultSizes) {
+ for (int def : defaultSizes) {
view->setDefaultSectionSize(def);
QCOMPARE(view->defaultSectionSize(), def);
}
@@ -757,9 +749,7 @@ void tst_QHeaderView::sectionSize()
int sectionCount = view->count();
for (int i = 0; i < sectionCount; ++i)
view->resizeSection(i, persistentSectionSize);
- QtTestModel model;
- model.cols = sectionCount * 2;
- model.rows = sectionCount * 2;
+ QtTestModel model(sectionCount * 2, sectionCount * 2);
view->setModel(&model);
for (int j = 0; j < sectionCount; ++j)
QCOMPARE(view->sectionSize(j), persistentSectionSize);
@@ -784,35 +774,34 @@ void tst_QHeaderView::visualIndex()
void tst_QHeaderView::visualIndexAt_data()
{
- QTest::addColumn<QList<int> >("hidden");
- QTest::addColumn<QList<int> >("from");
- QTest::addColumn<QList<int> >("to");
- QTest::addColumn<QList<int> >("coordinate");
- QTest::addColumn<QList<int> >("visual");
+ QTest::addColumn<IntList>("hidden");
+ QTest::addColumn<IntList>("from");
+ QTest::addColumn<IntList>("to");
+ QTest::addColumn<IntList>("coordinate");
+ QTest::addColumn<IntList>("visual");
- QList<int> coordinateList;
- coordinateList << -1 << 0 << 31 << 91 << 99999;
+ const IntList coordinateList{ -1, 0, 31, 91, 99999 };
QTest::newRow("no hidden, no moved sections")
- << QList<int>()
- << QList<int>()
- << QList<int>()
+ << IntList()
+ << IntList()
+ << IntList()
<< coordinateList
- << (QList<int>() << -1 << 0 << 1 << 3 << -1);
+ << (IntList{ -1, 0, 1, 3, -1 });
QTest::newRow("no hidden, moved sections")
- << QList<int>()
- << (QList<int>() << 0)
- << (QList<int>() << 1)
+ << IntList()
+ << (IntList{ 0 })
+ << (IntList{ 1 })
<< coordinateList
- << (QList<int>() << -1 << 0 << 1 << 3 << -1);
+ << (IntList{ -1, 0, 1, 3, -1 });
QTest::newRow("hidden, no moved sections")
- << (QList<int>() << 0)
- << QList<int>()
- << QList<int>()
+ << (IntList{ 0 })
+ << IntList()
+ << IntList()
<< coordinateList
- << (QList<int>() << -1 << 1 << 2 << 3 << -1);
+ << (IntList{ -1, 1, 2, 3, -1 });
}
void tst_QHeaderView::visualIndexAt()
@@ -822,26 +811,24 @@ void tst_QHeaderView::visualIndexAt()
#elif defined Q_OS_WINRT
QSKIP("Fails on WinRT - QTBUG-68297");
#endif
- QFETCH(QList<int>, hidden);
- QFETCH(QList<int>, from);
- QFETCH(QList<int>, to);
- QFETCH(QList<int>, coordinate);
- QFETCH(QList<int>, visual);
+ QFETCH(const IntList, hidden);
+ QFETCH(const IntList, from);
+ QFETCH(const IntList, to);
+ QFETCH(const IntList, coordinate);
+ QFETCH(const IntList, visual);
view->setStretchLastSection(true);
topLevel->show();
QVERIFY(QTest::qWaitForWindowExposed(topLevel));
- for (int i = 0; i < hidden.count(); ++i)
- view->setSectionHidden(hidden.at(i), true);
+ for (int i : hidden)
+ view->setSectionHidden(i, true);
for (int j = 0; j < from.count(); ++j)
view->moveSection(from.at(j), to.at(j));
- QTest::qWait(100);
-
for (int k = 0; k < coordinate.count(); ++k)
- QCOMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k));
+ QTRY_COMPARE(view->visualIndexAt(coordinate.at(k)), visual.at(k));
}
void tst_QHeaderView::length()
@@ -852,9 +839,8 @@ void tst_QHeaderView::length()
//minimumSectionSize should be the size of the last section of the widget is not tall enough
int length = view->minimumSectionSize();
- for (int i=0; i < view->count()-1; i++) {
+ for (int i = 0; i < view->count() - 1; i++)
length += view->sectionSize(i);
- }
length = qMax(length, view->viewport()->height());
QCOMPARE(length, view->length());
@@ -866,9 +852,7 @@ void tst_QHeaderView::length()
QVERIFY(length != view->length());
// layoutChanged might mean rows have been removed
- QtTestModel model;
- model.cols = 10;
- model.rows = 10;
+ QtTestModel model(10, 10);
view->setModel(&model);
int oldLength = view->length();
model.cleanup();
@@ -942,9 +926,9 @@ void tst_QHeaderView::swapSections()
view->swapSections(1, -1);
view->swapSections(1, 99999);
- QVector<int> logical = (QVector<int>() << 0 << 1 << 2 << 3);
+ IntList logical{ 0, 1, 2, 3 };
- QSignalSpy spy1(view, SIGNAL(sectionMoved(int,int,int)));
+ QSignalSpy spy1(view, &QHeaderView::sectionMoved);
QCOMPARE(view->sectionsMoved(), false);
view->swapSections(1, 1);
@@ -957,7 +941,7 @@ void tst_QHeaderView::swapSections()
QCOMPARE(view->logicalIndex(i), logical.at(i));
QCOMPARE(spy1.count(), 4);
- logical = (QVector<int>() << 3 << 1 << 2 << 0);
+ logical = { 3, 1, 2, 0 };
view->swapSections(3, 0);
QCOMPARE(view->sectionsMoved(), true);
for (int j = 0; j < view->count(); ++j)
@@ -967,56 +951,56 @@ void tst_QHeaderView::swapSections()
void tst_QHeaderView::moveSection_data()
{
- QTest::addColumn<QList<int> >("hidden");
- QTest::addColumn<QList<int> >("from");
- QTest::addColumn<QList<int> >("to");
- QTest::addColumn<QList<bool> >("moved");
- QTest::addColumn<QList<int> >("logical");
+ QTest::addColumn<IntList>("hidden");
+ QTest::addColumn<IntList>("from");
+ QTest::addColumn<IntList>("to");
+ QTest::addColumn<BoolList>("moved");
+ QTest::addColumn<IntList>("logical");
QTest::addColumn<int>("count");
QTest::newRow("bad args, no hidden")
- << QList<int>()
- << (QList<int>() << -1 << 1 << 99999 << 1)
- << (QList<int>() << 1 << -1 << 1 << 99999)
- << (QList<bool>() << false << false << false << false)
- << (QList<int>() << 0 << 1 << 2 << 3)
+ << IntList()
+ << (IntList{ -1, 1, 99999, 1 })
+ << (IntList{ 1, -1, 1, 99999 })
+ << (BoolList{ false, false, false, false })
+ << (IntList{ 0, 1, 2, 3 })
<< 0;
QTest::newRow("good args, no hidden")
- << QList<int>()
- << (QList<int>() << 1 << 1 << 2 << 1)
- << (QList<int>() << 1 << 2 << 1 << 2)
- << (QList<bool>() << false << true << true << true)
- << (QList<int>() << 0 << 2 << 1 << 3)
+ << IntList()
+ << (IntList{ 1, 1, 2, 1 })
+ << (IntList{ 1, 2, 1, 2 })
+ << (BoolList{ false, true, true, true })
+ << (IntList{ 0, 2, 1, 3 })
<< 3;
QTest::newRow("hidden sections")
- << (QList<int>() << 0 << 3)
- << (QList<int>() << 1 << 1 << 2 << 1)
- << (QList<int>() << 1 << 2 << 1 << 2)
- << (QList<bool>() << false << true << true << true)
- << (QList<int>() << 0 << 2 << 1 << 3)
+ << (IntList{ 0, 3 })
+ << (IntList{ 1, 1, 2, 1 })
+ << (IntList{ 1, 2, 1, 2 })
+ << (BoolList{ false, true, true, true })
+ << (IntList{ 0, 2, 1, 3 })
<< 3;
}
void tst_QHeaderView::moveSection()
{
- QFETCH(QList<int>, hidden);
- QFETCH(QList<int>, from);
- QFETCH(QList<int>, to);
- QFETCH(QList<bool>, moved);
- QFETCH(QList<int>, logical);
+ QFETCH(const IntList, hidden);
+ QFETCH(const IntList, from);
+ QFETCH(const IntList, to);
+ QFETCH(const BoolList, moved);
+ QFETCH(const IntList, logical);
QFETCH(int, count);
QCOMPARE(from.count(), to.count());
QCOMPARE(from.count(), moved.count());
QCOMPARE(view->count(), logical.count());
- QSignalSpy spy1(view, SIGNAL(sectionMoved(int,int,int)));
+ QSignalSpy spy1(view, &QHeaderView::sectionMoved);
QCOMPARE(view->sectionsMoved(), false);
- for (int h = 0; h < hidden.count(); ++h)
- view->setSectionHidden(hidden.at(h), true);
+ for (int h : hidden)
+ view->setSectionHidden(h, true);
for (int i = 0; i < from.count(); ++i) {
view->moveSection(from.at(i), to.at(i));
@@ -1037,42 +1021,42 @@ void tst_QHeaderView::resizeAndMoveSection_data()
QTest::addColumn<int>("logicalTo");
QTest::newRow("resizeAndMove-1")
- << (IntList() << 0 << 1)
- << (IntList() << 20 << 40)
+ << (IntList{ 0, 1 })
+ << (IntList{ 20, 40 })
<< 0 << 1;
QTest::newRow("resizeAndMove-2")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 20 << 60 << 10 << 80)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 20, 60, 10, 80 })
<< 0 << 2;
QTest::newRow("resizeAndMove-3")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 100 << 60 << 40 << 10)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 100, 60, 40, 10 })
<< 0 << 3;
QTest::newRow("resizeAndMove-4")
- << (IntList() << 0 << 1 << 2 << 3)
- << (IntList() << 10 << 40 << 80 << 30)
+ << (IntList{ 0, 1, 2, 3 })
+ << (IntList{ 10, 40, 80, 30 })
<< 1 << 2;
QTest::newRow("resizeAndMove-5")
- << (IntList() << 2 << 3)
- << (IntList() << 100 << 200)
+ << (IntList{ 2, 3 })
+ << (IntList{ 100, 200})
<< 3 << 2;
}
void tst_QHeaderView::resizeAndMoveSection()
{
- QFETCH(IntList, logicalIndexes);
- QFETCH(IntList, sizes);
+ QFETCH(const IntList, logicalIndexes);
+ QFETCH(const IntList, sizes);
QFETCH(int, logicalFrom);
QFETCH(int, logicalTo);
// Save old visual indexes and sizes
IntList oldVisualIndexes;
IntList oldSizes;
- foreach (int logical, logicalIndexes) {
+ for (int logical : logicalIndexes) {
oldVisualIndexes.append(view->visualIndex(logical));
oldSizes.append(view->sectionSize(logical));
}
@@ -1188,31 +1172,32 @@ void tst_QHeaderView::resizeAndInsertSection()
void tst_QHeaderView::resizeWithResizeModes_data()
{
QTest::addColumn<int>("size");
- QTest::addColumn<QList<int> >("sections");
- QTest::addColumn<QList<int> >("modes");
- QTest::addColumn<QList<int> >("expected");
+ QTest::addColumn<IntList>("sections");
+ QTest::addColumn<ResizeVec>("modes");
+ QTest::addColumn<IntList>("expected");
QTest::newRow("stretch first section")
<< 600
- << (QList<int>() << 100 << 100 << 100 << 100)
- << (QList<int>() << ((int)QHeaderView::Stretch)
- << ((int)QHeaderView::Interactive)
- << ((int)QHeaderView::Interactive)
- << ((int)QHeaderView::Interactive))
- << (QList<int>() << 300 << 100 << 100 << 100);
+ << (IntList{ 100, 100, 100, 100 })
+ << (ResizeVec
+ { QHeaderView::Stretch,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive })
+ << (IntList{ 300, 100, 100, 100 });
}
void tst_QHeaderView::resizeWithResizeModes()
{
QFETCH(int, size);
- QFETCH(QList<int>, sections);
- QFETCH(QList<int>, modes);
- QFETCH(QList<int>, expected);
+ QFETCH(const IntList, sections);
+ QFETCH(const ResizeVec, modes);
+ QFETCH(const IntList, expected);
view->setStretchLastSection(false);
for (int i = 0; i < sections.count(); ++i) {
view->resizeSection(i, sections.at(i));
- view->setSectionResizeMode(i, (QHeaderView::ResizeMode)modes.at(i));
+ view->setSectionResizeMode(i, modes.at(i));
}
topLevel->show();
QVERIFY(QTest::qWaitForWindowExposed(topLevel));
@@ -1226,10 +1211,10 @@ void tst_QHeaderView::moveAndInsertSection_data()
QTest::addColumn<int>("from");
QTest::addColumn<int>("to");
QTest::addColumn<int>("insert");
- QTest::addColumn<QList<int> >("mapping");
+ QTest::addColumn<IntList>("mapping");
QTest::newRow("move from 1 to 3, insert 0")
- << 1 << 3 << 0 <<(QList<int>() << 0 << 1 << 3 << 4 << 2);
+ << 1 << 3 << 0 <<(IntList{ 0, 1, 3, 4, 2 });
}
@@ -1238,12 +1223,10 @@ void tst_QHeaderView::moveAndInsertSection()
QFETCH(int, from);
QFETCH(int, to);
QFETCH(int, insert);
- QFETCH(QList<int>, mapping);
+ QFETCH(IntList, mapping);
view->setStretchLastSection(false);
-
view->moveSection(from, to);
-
model->insertRow(insert);
for (int i = 0; i < mapping.count(); ++i)
@@ -1266,12 +1249,12 @@ void tst_QHeaderView::resizeMode()
// test when sections have been moved
view->setStretchLastSection(false);
- for (int i=0; i < (view->count() - 1); ++i)
+ for (int i = 0; i < (view->count() - 1); ++i)
view->setSectionResizeMode(i, QHeaderView::Interactive);
int logicalIndex = view->count() / 2;
view->setSectionResizeMode(logicalIndex, QHeaderView::Stretch);
view->moveSection(view->visualIndex(logicalIndex), 0);
- for (int i=0; i < (view->count() - 1); ++i) {
+ for (int i = 0; i < (view->count() - 1); ++i) {
if (i == logicalIndex)
QCOMPARE(view->sectionResizeMode(i), QHeaderView::Stretch);
else
@@ -1282,34 +1265,33 @@ void tst_QHeaderView::resizeMode()
void tst_QHeaderView::resizeSection_data()
{
QTest::addColumn<int>("initial");
- QTest::addColumn<QList<int> >("logical");
- QTest::addColumn<QList<int> >("size");
- QTest::addColumn<QList<int> >("mode");
+ QTest::addColumn<IntList>("logical");
+ QTest::addColumn<IntList>("size");
+ QTest::addColumn<ResizeVec>("mode");
QTest::addColumn<int>("resized");
- QTest::addColumn<QList<int> >("expected");
+ QTest::addColumn<IntList>("expected");
QTest::newRow("bad args")
<< 100
- << (QList<int>() << -1 << -1 << 99999 << 99999 << 4)
- << (QList<int>() << -1 << 0 << 99999 << -1 << -1)
- << (QList<int>()
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive)
- << int(QHeaderView::Interactive))
+ << (IntList{ -1, -1, 99999, 99999, 4 })
+ << (IntList{ -1, 0, 99999, -1, -1 })
+ << (ResizeVec{
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive,
+ QHeaderView::Interactive })
<< 0
- << (QList<int>() << 0 << 0 << 0 << 0 << 0);
+ << (IntList{ 0, 0, 0, 0, 0 });
}
void tst_QHeaderView::resizeSection()
{
-
QFETCH(int, initial);
- QFETCH(QList<int>, logical);
- QFETCH(QList<int>, size);
- QFETCH(QList<int>, mode);
+ QFETCH(const IntList, logical);
+ QFETCH(const IntList, size);
+ QFETCH(const ResizeVec, mode);
QFETCH(int, resized);
- QFETCH(QList<int>, expected);
+ QFETCH(const IntList, expected);
view->resize(400, 400);
@@ -1320,12 +1302,12 @@ void tst_QHeaderView::resizeSection()
for (int i = 0; i < logical.count(); ++i)
if (logical.at(i) > -1 && logical.at(i) < view->count()) // for now
- view->setSectionResizeMode(logical.at(i), (QHeaderView::ResizeMode)mode.at(i));
+ view->setSectionResizeMode(logical.at(i), mode.at(i));
for (int j = 0; j < logical.count(); ++j)
view->resizeSection(logical.at(j), initial);
- QSignalSpy spy(view, SIGNAL(sectionResized(int,int,int)));
+ QSignalSpy spy(view, &QHeaderView::sectionResized);
for (int k = 0; k < logical.count(); ++k)
view->resizeSection(logical.at(k), size.at(k));
@@ -1366,9 +1348,7 @@ void tst_QHeaderView::showSortIndicator()
void tst_QHeaderView::sortIndicatorTracking()
{
- QtTestModel model;
- model.rows = model.cols = 10;
-
+ QtTestModel model(10, 10);
QHeaderView hv(Qt::Horizontal);
hv.setModel(&model);
@@ -1399,51 +1379,44 @@ void tst_QHeaderView::removeAndInsertRow()
{
// Check if logicalIndex returns the correct value after we have removed a row
// we might as well te
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
while (model->removeRow(0)) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
- int pass = 0;
- for (pass = 0; pass < 5; pass++) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int pass = 0; pass < 5; pass++) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
model->insertRow(0);
}
while (model->removeRows(0, 2)) {
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
model->insertRows(0, 2);
for (int i = 0; i < model->rowCount(); ++i) {
QCOMPARE(i, view->logicalIndex(i));
}
}
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
model->insertRows(3, 2);
- for (int i = 0; i < model->rowCount(); ++i) {
+ for (int i = 0; i < model->rowCount(); ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
// Insert at end
- for (pass = 0; pass < 3; pass++) {
+ for (int pass = 0; pass < 3; pass++) {
int rowCount = model->rowCount();
model->insertRows(rowCount, 1);
- for (int i = 0; i < rowCount; ++i) {
+ for (int i = 0; i < rowCount; ++i)
QCOMPARE(i, view->logicalIndex(i));
- }
}
}
@@ -1490,7 +1463,7 @@ void protected_QHeaderView::testEvent()
void tst_QHeaderView::headerDataChanged()
{
- // This shouldn't asserver because view is Vertical
+ // This shouldn't assert because view is Vertical
view->headerDataChanged(Qt::Horizontal, -1, -1);
#if 0
// This will assert
@@ -1525,19 +1498,18 @@ void tst_QHeaderView::verticalOffset()
void protected_QHeaderView::testhorizontalOffset()
{
- if(orientation() == Qt::Horizontal){
+ if (orientation() == Qt::Horizontal) {
QCOMPARE(horizontalOffset(), 0);
setOffset(10);
QCOMPARE(horizontalOffset(), 10);
}
else
QCOMPARE(horizontalOffset(), 0);
-
}
void protected_QHeaderView::testverticalOffset()
{
- if(orientation() == Qt::Vertical){
+ if (orientation() == Qt::Vertical) {
QCOMPARE(verticalOffset(), 0);
setOffset(10);
QCOMPARE(verticalOffset(), 10);
@@ -1562,7 +1534,7 @@ void tst_QHeaderView::hiddenSectionCount()
model->clear();
model->insertRows(0, 10);
// Hide every other one
- for (int i=0; i<10; i++)
+ for (int i = 0; i < 10; i++)
view->setSectionHidden(i, (i & 1) == 0);
QCOMPARE(view->hiddenSectionCount(), 5);
@@ -1577,7 +1549,7 @@ void tst_QHeaderView::hiddenSectionCount()
model->removeRow(6);
QCOMPARE(view->count(), 6);
QCOMPARE(view->hiddenSectionCount(), 3);
- model->removeRows(0,5);
+ model->removeRows(0, 5);
QCOMPARE(view->count(), 1);
QCOMPARE(view->hiddenSectionCount(), 0);
QVERIFY(view->count() >= view->hiddenSectionCount());
@@ -1610,8 +1582,8 @@ void tst_QHeaderView::focusPolicy()
QTest::keyPress(&widget, Qt::Key_Tab);
- qApp->processEvents();
- qApp->processEvents();
+ QCoreApplication::processEvents();
+ QCoreApplication::processEvents();
QVERIFY(!widget.hasFocus());
QVERIFY(!widget.header()->hasFocus());
@@ -1621,47 +1593,37 @@ class SimpleModel : public QAbstractItemModel
{
Q_OBJECT
public:
-
- SimpleModel( QObject* parent=0)
- : QAbstractItemModel(parent),
- m_col_count(3) {}
-
- QModelIndex parent(const QModelIndex &/*child*/) const
+ using QAbstractItemModel::QAbstractItemModel;
+ QModelIndex parent(const QModelIndex &/*child*/) const override
{
return QModelIndex();
}
- QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const
+ QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override
{
return hasIndex(row, column, parent) ? createIndex(row, column) : QModelIndex();
}
- int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const
+ int rowCount(const QModelIndex & /*parent*/ = QModelIndex()) const override
{
return 8;
}
- int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const
+ int columnCount(const QModelIndex &/*parent*/ = QModelIndex()) const override
{
return m_col_count;
}
-
- QVariant data(const QModelIndex &index, int role) const
+ QVariant data(const QModelIndex &index, int role) const override
{
if (!index.isValid())
- {
return QVariant();
- }
- if (role == Qt::DisplayRole) {
+ if (role == Qt::DisplayRole)
return QString::number(index.row()) + QLatin1Char(',') + QString::number(index.column());
- }
return QVariant();
}
-
- void setColumnCount( int c )
+ void setColumnCount(int c)
{
m_col_count = c;
}
-
private:
- int m_col_count;
+ int m_col_count = 3;
};
void tst_QHeaderView::moveSectionAndReset()
@@ -1678,9 +1640,8 @@ void tst_QHeaderView::moveSectionAndReset()
v.moveSection(movefrom, moveto);
m.setColumnCount(cc - 1);
v.reset();
- for (int i = 0; i < cc - 1; ++i) {
+ for (int i = 0; i < cc - 1; ++i)
QCOMPARE(v.logicalIndex(v.visualIndex(i)), i);
- }
}
}
}
@@ -1719,7 +1680,7 @@ void tst_QHeaderView::saveRestore()
const QByteArray s1 = savedState();
QHeaderView h2(Qt::Vertical);
- QSignalSpy spy(&h2, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)));
+ QSignalSpy spy(&h2, &QHeaderView::sortIndicatorChanged);
h2.setModel(&m);
QVERIFY(h2.restoreState(s1));
@@ -1745,6 +1706,7 @@ void tst_QHeaderView::saveRestore()
void tst_QHeaderView::restoreQt4State()
{
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// QTBUG-40462
// Setting from Qt4, where information about multiple sections were grouped together in one
// sectionItem object
@@ -1777,6 +1739,9 @@ void tst_QHeaderView::restoreQt4State()
// Check nothing has been actually restored
QCOMPARE(h2.length(), old_length);
QCOMPARE(h2.saveState(), old_state);
+#else
+ QSKIP("Qt4 compatibility no longer needed in Qt6");
+#endif
}
void tst_QHeaderView::restoreToMoreColumns()
@@ -1910,16 +1875,18 @@ void tst_QHeaderView::defaultSectionSizeTest()
class TestHeaderViewStyle : public QProxyStyle
{
+ Q_OBJECT
public:
- TestHeaderViewStyle() : horizontalSectionSize(100) {}
- int pixelMetric(PixelMetric metric, const QStyleOption *option = 0, const QWidget *widget = 0) const override
+ using QProxyStyle::QProxyStyle;
+ int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr,
+ const QWidget *widget = nullptr) const override
{
if (metric == QStyle::PM_HeaderDefaultSectionSizeHorizontal)
return horizontalSectionSize;
else
return QProxyStyle::pixelMetric(metric, option, widget);
}
- int horizontalSectionSize;
+ int horizontalSectionSize = 100;
};
void tst_QHeaderView::defaultSectionSizeTestStyles()
@@ -1946,107 +1913,107 @@ void tst_QHeaderView::defaultSectionSizeTestStyles()
void tst_QHeaderView::defaultAlignment_data()
{
- QTest::addColumn<int>("direction");
- QTest::addColumn<int>("initial");
- QTest::addColumn<int>("alignment");
+ QTest::addColumn<Qt::Orientation>("direction");
+ QTest::addColumn<Qt::Alignment>("initial");
+ QTest::addColumn<Qt::Alignment>("alignment");
QTest::newRow("horizontal right aligned")
- << int(Qt::Horizontal)
- << int(Qt::AlignCenter)
- << int(Qt::AlignRight);
+ << Qt::Horizontal
+ << Qt::Alignment(Qt::AlignCenter)
+ << Qt::Alignment(Qt::AlignRight);
QTest::newRow("horizontal left aligned")
- << int(Qt::Horizontal)
- << int(Qt::AlignCenter)
- << int(Qt::AlignLeft);
+ << Qt::Horizontal
+ << Qt::Alignment(Qt::AlignCenter)
+ << Qt::Alignment(Qt::AlignLeft);
QTest::newRow("vertical right aligned")
- << int(Qt::Vertical)
- << int(Qt::AlignLeft|Qt::AlignVCenter)
- << int(Qt::AlignRight);
+ << Qt::Vertical
+ << Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter)
+ << Qt::Alignment(Qt::AlignRight);
QTest::newRow("vertical left aligned")
- << int(Qt::Vertical)
- << int(Qt::AlignLeft|Qt::AlignVCenter)
- << int(Qt::AlignLeft);
+ << Qt::Vertical
+ << Qt::Alignment(Qt::AlignLeft|Qt::AlignVCenter)
+ << Qt::Alignment(Qt::AlignLeft);
}
void tst_QHeaderView::defaultAlignment()
{
- QFETCH(int, direction);
- QFETCH(int, initial);
- QFETCH(int, alignment);
+ QFETCH(Qt::Orientation, direction);
+ QFETCH(Qt::Alignment, initial);
+ QFETCH(Qt::Alignment, alignment);
SimpleModel m;
- QHeaderView header((Qt::Orientation)direction);
+ QHeaderView header(direction);
header.setModel(&m);
- QCOMPARE(header.defaultAlignment(), (Qt::Alignment)initial);
- header.setDefaultAlignment((Qt::Alignment)alignment);
- QCOMPARE(header.defaultAlignment(), (Qt::Alignment)alignment);
+ QCOMPARE(header.defaultAlignment(), initial);
+ header.setDefaultAlignment(alignment);
+ QCOMPARE(header.defaultAlignment(), alignment);
}
void tst_QHeaderView::globalResizeMode_data()
{
- QTest::addColumn<int>("direction");
- QTest::addColumn<int>("mode");
+ QTest::addColumn<Qt::Orientation>("direction");
+ QTest::addColumn<QHeaderView::ResizeMode>("mode");
QTest::addColumn<int>("insert");
QTest::newRow("horizontal ResizeToContents 0")
- << int(Qt::Horizontal)
- << int(QHeaderView::ResizeToContents)
+ << Qt::Horizontal
+ << QHeaderView::ResizeToContents
<< 0;
}
void tst_QHeaderView::globalResizeMode()
{
- QFETCH(int, direction);
- QFETCH(int, mode);
+ QFETCH(Qt::Orientation, direction);
+ QFETCH(QHeaderView::ResizeMode, mode);
QFETCH(int, insert);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
- h.setSectionResizeMode((QHeaderView::ResizeMode)mode);
+ h.setSectionResizeMode(mode);
m.insertRow(insert);
for (int i = 0; i < h.count(); ++i)
- QCOMPARE(h.sectionResizeMode(i), (QHeaderView::ResizeMode)mode);
+ QCOMPARE(h.sectionResizeMode(i), mode);
}
void tst_QHeaderView::sectionPressedSignal_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<bool>("clickable");
QTest::addColumn<int>("count");
QTest::newRow("horizontal unclickable 0")
- << int(Qt::Horizontal)
+ << Qt::Horizontal
<< false
<< 0;
QTest::newRow("horizontal clickable 1")
- << int(Qt::Horizontal)
+ << Qt::Horizontal
<< true
<< 1;
}
void tst_QHeaderView::sectionPressedSignal()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(bool, clickable);
QFETCH(int, count);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.show();
h.setSectionsClickable(clickable);
- QSignalSpy spy(&h, SIGNAL(sectionPressed(int)));
+ QSignalSpy spy(&h, &QHeaderView::sectionPressed);
QCOMPARE(spy.count(), 0);
QTest::mousePress(h.viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(5, 5));
@@ -2055,20 +2022,20 @@ void tst_QHeaderView::sectionPressedSignal()
void tst_QHeaderView::sectionClickedSignal()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(bool, clickable);
QFETCH(int, count);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.show();
h.setSectionsClickable(clickable);
h.setSortIndicatorShown(true);
- QSignalSpy spy(&h, SIGNAL(sectionClicked(int)));
- QSignalSpy spy2(&h, SIGNAL(sortIndicatorChanged(int,Qt::SortOrder)));
+ QSignalSpy spy(&h, &QHeaderView::sectionClicked);
+ QSignalSpy spy2(&h, &QHeaderView::sortIndicatorChanged);
QCOMPARE(spy.count(), 0);
QCOMPARE(spy2.count(), 0);
@@ -2087,24 +2054,24 @@ void tst_QHeaderView::sectionClickedSignal()
void tst_QHeaderView::defaultSectionSize_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<int>("oldDefaultSize");
QTest::addColumn<int>("newDefaultSize");
//QTest::newRow("horizontal,-5") << int(Qt::Horizontal) << 100 << -5;
- QTest::newRow("horizontal, 0") << int(Qt::Horizontal) << 100 << 0;
- QTest::newRow("horizontal, 5") << int(Qt::Horizontal) << 100 << 5;
- QTest::newRow("horizontal,25") << int(Qt::Horizontal) << 100 << 5;
+ QTest::newRow("horizontal, 0") << Qt::Horizontal << 100 << 0;
+ QTest::newRow("horizontal, 5") << Qt::Horizontal << 100 << 5;
+ QTest::newRow("horizontal,25") << Qt::Horizontal << 100 << 5;
}
void tst_QHeaderView::defaultSectionSize()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(int, oldDefaultSize);
QFETCH(int, newDefaultSize);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
+ QHeaderView h(direction);
h.setModel(&m);
h.setMinimumSectionSize(0);
@@ -2119,26 +2086,24 @@ void tst_QHeaderView::defaultSectionSize()
void tst_QHeaderView::hideAndInsert_data()
{
- QTest::addColumn<int>("direction");
+ QTest::addColumn<Qt::Orientation>("direction");
QTest::addColumn<int>("hide");
QTest::addColumn<int>("insert");
QTest::addColumn<int>("hidden");
- QTest::newRow("horizontal, 0, 0") << int(Qt::Horizontal) << 0 << 0 << 1;
+ QTest::newRow("horizontal, 0, 0") << Qt::Horizontal << 0 << 0 << 1;
}
void tst_QHeaderView::hideAndInsert()
{
- QFETCH(int, direction);
+ QFETCH(Qt::Orientation, direction);
QFETCH(int, hide);
QFETCH(int, insert);
QFETCH(int, hidden);
QStandardItemModel m(4, 4);
- QHeaderView h((Qt::Orientation)direction);
-
+ QHeaderView h(direction);
h.setModel(&m);
-
h.setSectionHidden(hide, true);
if (direction == Qt::Vertical)
@@ -2147,20 +2112,14 @@ void tst_QHeaderView::hideAndInsert()
m.insertColumn(insert);
for (int i = 0; i < h.count(); ++i)
- if (i != hidden)
- QCOMPARE(h.isSectionHidden(i), false);
- else
- QCOMPARE(h.isSectionHidden(i), true);
+ QCOMPARE(h.isSectionHidden(i), i == hidden);
}
void tst_QHeaderView::removeSection()
{
-//test that removing a hidden section gives the expected result: the next row should be hidden
-//(see task
const int hidden = 3; //section that will be hidden
- const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5" << "6";
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3", "4", "5", "6" });
QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.hideSection(hidden);
@@ -2169,7 +2128,7 @@ void tst_QHeaderView::removeSection()
view.show();
for(int i = 0; i < view.count(); i++) {
- if (i == (hidden-1)) { //-1 because we removed a row in the meantime
+ if (i == (hidden - 1)) { //-1 because we removed a row in the meantime
QCOMPARE(view.sectionSize(i), 0);
QVERIFY(view.isSectionHidden(i));
} else {
@@ -2181,9 +2140,7 @@ void tst_QHeaderView::removeSection()
void tst_QHeaderView::preserveHiddenSectionWidth()
{
- const QStringList list = QStringList() << "0" << "1" << "2" << "3";
-
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3" });
QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.resizeSection(0, 100);
@@ -2249,38 +2206,36 @@ void tst_QHeaderView::emptySectionSpan()
void tst_QHeaderView::task236450_hidden_data()
{
- QTest::addColumn<QList<int> >("hide1");
- QTest::addColumn<QList<int> >("hide2");
+ QTest::addColumn<IntList>("hide1");
+ QTest::addColumn<IntList>("hide2");
- QTest::newRow("set 1") << (QList<int>() << 1 << 3)
- << (QList<int>() << 1 << 5);
+ QTest::newRow("set 1") << (IntList{ 1, 3 })
+ << (IntList{ 1, 5 });
- QTest::newRow("set 2") << (QList<int>() << 2 << 3)
- << (QList<int>() << 1 << 5);
+ QTest::newRow("set 2") << (IntList{ 2, 3 })
+ << (IntList{ 1, 5 });
- QTest::newRow("set 3") << (QList<int>() << 0 << 2 << 4)
- << (QList<int>() << 2 << 3 << 5);
+ QTest::newRow("set 3") << (IntList{ 0, 2, 4 })
+ << (IntList{ 2, 3, 5 });
}
void tst_QHeaderView::task236450_hidden()
{
- QFETCH(QList<int>, hide1);
- QFETCH(QList<int>, hide2);
- const QStringList list = QStringList() << "0" << "1" << "2" << "3" << "4" << "5";
+ QFETCH(const IntList, hide1);
+ QFETCH(const IntList, hide2);
- QStringListModel model( list );
+ QStringListModel model({ "0", "1", "2", "3", "4", "5" });
protected_QHeaderView view(Qt::Vertical);
view.setModel(&model);
view.show();
- foreach (int i, hide1)
+ for (int i : hide1)
view.hideSection(i);
QCOMPARE(view.hiddenSectionCount(), hide1.count());
- for (int i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide1.contains(i));
- }
view.setDefaultSectionSize(2);
view.scheduleDelayedItemsLayout();
@@ -2293,10 +2248,8 @@ void tst_QHeaderView::task236450_hidden()
}
QCOMPARE(view.hiddenSectionCount(), hide2.count());
- for (int i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++)
QCOMPARE(!view.isSectionHidden(i), !hide2.contains(i));
- }
-
}
void tst_QHeaderView::task248050_hideRow()
@@ -2324,7 +2277,7 @@ void tst_QHeaderView::task248050_hideRow()
//returns 0 if everything is fine.
-static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected)
+static int checkHeaderViewOrder(const QHeaderView *view, const IntList &expected)
{
if (view->count() != expected.count())
return 1;
@@ -2341,8 +2294,8 @@ static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected)
void tst_QHeaderView::QTBUG6058_reset()
{
- QStringListModel model1( QStringList() << "0" << "1" << "2" << "3" << "4" << "5" );
- QStringListModel model2( QStringList() << "a" << "b" << "c" );
+ QStringListModel model1({ "0", "1", "2", "3", "4", "5" });
+ QStringListModel model2({ "a", "b", "c" });
QSortFilterProxyModel proxy;
QHeaderView view(Qt::Vertical);
@@ -2352,9 +2305,9 @@ void tst_QHeaderView::QTBUG6058_reset()
QVERIFY(QTest::qWaitForWindowActive(&view));
proxy.setSourceModel(&model1);
- view.swapSections(0,2);
- view.swapSections(1,4);
- QVector<int> expectedOrder{2, 4, 0, 3, 1, 5};
+ view.swapSections(0, 2);
+ view.swapSections(1, 4);
+ IntList expectedOrder{2, 4, 0, 3, 1, 5};
QTRY_COMPARE(checkHeaderViewOrder(&view, expectedOrder) , 0);
proxy.setSourceModel(&model2);
@@ -2376,11 +2329,11 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
QList<QStandardItem *> row;
- for (int i = 0; i < 12; i++)
+ for (char i = 0; i < 12; i++)
row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
sim->appendRow(row);
row.clear();
- for (int i = 12; i > 0; i--)
+ for (char i = 12; i > 0; i--)
row.append(new QStandardItem(QString(QLatin1Char('A' + i))));
sim->appendRow(row);
@@ -2410,19 +2363,21 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(tv.horizontalHeader()->sectionSize(5), section5Size);
tv.setColumnHidden(5, true);
- QSignalSpy clickedSpy(tv.horizontalHeader(), SIGNAL(sectionClicked(int)));
- QSignalSpy pressedSpy(tv.horizontalHeader(), SIGNAL(sectionPressed(int)));
+ QSignalSpy clickedSpy(tv.horizontalHeader(), &QHeaderView::sectionClicked);
+ QSignalSpy pressedSpy(tv.horizontalHeader(), &QHeaderView::sectionPressed);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(11) + tv.horizontalHeader()->sectionSize(11)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(11) +
+ tv.horizontalHeader()->sectionSize(11) / 2, 5));
QCOMPARE(clickedSpy.count(), 1);
QCOMPARE(pressedSpy.count(), 1);
QCOMPARE(clickedSpy.at(0).at(0).toInt(), 11);
QCOMPARE(pressedSpy.at(0).at(0).toInt(), 11);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(8) + tv.horizontalHeader()->sectionSize(0)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(8) +
+ tv.horizontalHeader()->sectionSize(0) / 2, 5));
QCOMPARE(clickedSpy.count(), 2);
QCOMPARE(pressedSpy.count(), 2);
@@ -2430,7 +2385,8 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
QCOMPARE(pressedSpy.at(1).at(0).toInt(), 8);
QTest::mouseClick(tv.horizontalHeader()->viewport(), Qt::LeftButton, Qt::NoModifier,
- QPoint(tv.horizontalHeader()->sectionViewportPosition(0) + tv.horizontalHeader()->sectionSize(0)/2, 5));
+ QPoint(tv.horizontalHeader()->sectionViewportPosition(0) +
+ tv.horizontalHeader()->sectionSize(0) / 2, 5));
QCOMPARE(clickedSpy.count(), 3);
QCOMPARE(pressedSpy.count(), 3);
@@ -2440,8 +2396,7 @@ void tst_QHeaderView::QTBUG7833_sectionClicked()
void tst_QHeaderView::checkLayoutChangeEmptyModel()
{
- QtTestModel tm;
- tm.cols = 11;
+ QtTestModel tm(0, 11);
QTableView tv;
tv.verticalHeader()->setStretchLastSection(true);
tv.setModel(&tm);
@@ -2488,14 +2443,12 @@ void tst_QHeaderView::QTBUG8650_crashOnInsertSections()
{
QStringList headerLabels;
QHeaderView view(Qt::Horizontal);
- QStandardItemModel model(2,2);
+ QStandardItemModel model(2, 2);
view.setModel(&model);
view.moveSection(1, 0);
view.hideSection(0);
- QList<QStandardItem *> items;
- items << new QStandardItem("c");
- model.insertColumn(0, items);
+ model.insertColumn(0, { new QStandardItem("c") });
}
static void setModelTexts(QStandardItemModel *model)
@@ -2511,9 +2464,9 @@ static void setModelTexts(QStandardItemModel *model)
void tst_QHeaderView::QTBUG12268_hiddenMovedSectionSorting()
{
QTableView view; // ### this test fails on QTableView &view = *m_tableview; !? + shadowing view member
- QStandardItemModel *model = new QStandardItemModel(4,3, &view);
- setModelTexts(model);
- view.setModel(model);
+ QStandardItemModel model(4, 3);
+ setModelTexts(&model);
+ view.setModel(&model);
view.horizontalHeader()->setSectionsMovable(true);
view.setSortingEnabled(true);
view.sortByColumn(1, Qt::AscendingOrder);
@@ -2549,9 +2502,7 @@ void tst_QHeaderView::QTBUG14242_hideSectionAutoSize()
void tst_QHeaderView::QTBUG50171_visualRegionForSwappedItems()
{
protected_QHeaderView headerView(Qt::Horizontal);
- QtTestModel model;
- model.rows = 2;
- model.cols = 3;
+ QtTestModel model(2, 3);
headerView.setModel(&model);
headerView.swapSections(1, 2);
headerView.hideSection(0);
@@ -2560,17 +2511,17 @@ void tst_QHeaderView::QTBUG50171_visualRegionForSwappedItems()
class QTBUG53221_Model : public QAbstractItemModel
{
+ Q_OBJECT
public:
void insertRowAtBeginning()
{
Q_EMIT layoutAboutToBeChanged();
m_displayNames.insert(0, QStringLiteral("Item %1").arg(m_displayNames.count()));
// Rows are always inserted at the beginning, so move all others.
- foreach (const QModelIndex &persIndex, persistentIndexList())
- {
- // The vertical header view will have a persistent index stored here on the second call to insertRowAtBeginning.
+ const auto pl = persistentIndexList();
+ // The vertical header view will have a persistent index stored here on the second call to insertRowAtBeginning.
+ for (const QModelIndex &persIndex : pl)
changePersistentIndex(persIndex, index(persIndex.row() + 1, persIndex.column(), persIndex.parent()));
- }
Q_EMIT layoutChanged();
}
@@ -2653,15 +2604,15 @@ void tst_QHeaderView::offsetConsistent()
void tst_QHeaderView::initialSortOrderRole()
{
QTableView view; // ### Shadowing member view (of type QHeaderView)
- QStandardItemModel *model = new QStandardItemModel(4, 3, &view);
- setModelTexts(model);
+ QStandardItemModel model(4, 3);
+ setModelTexts(&model);
QStandardItem *ascendingItem = new QStandardItem();
QStandardItem *descendingItem = new QStandardItem();
ascendingItem->setData(Qt::AscendingOrder, Qt::InitialSortOrderRole);
descendingItem->setData(Qt::DescendingOrder, Qt::InitialSortOrderRole);
- model->setHorizontalHeaderItem(1, ascendingItem);
- model->setHorizontalHeaderItem(2, descendingItem);
- view.setModel(model);
+ model.setHorizontalHeaderItem(1, ascendingItem);
+ model.setHorizontalHeaderItem(2, descendingItem);
+ view.setModel(&model);
view.setSortingEnabled(true);
view.sortByColumn(0, Qt::AscendingOrder);
view.show();
@@ -2687,7 +2638,7 @@ const bool block_some_signals = true; // The test should also work with this set
const int rowcount = 500;
const int colcount = 10;
-QString istr(int n, bool comma = true)
+static inline QString istr(int n, bool comma = true)
{
QString s;
s.setNum(n);
@@ -3433,9 +3384,7 @@ void tst_QHeaderView::testMinMaxSectionSize()
void tst_QHeaderView::testResetCachedSizeHint()
{
- QtTestModel model;
- model.rows = model.cols = 10;
-
+ QtTestModel model(10, 10);
QTableView tv;
tv.setModel(&model);
tv.show();
@@ -3453,13 +3402,13 @@ void tst_QHeaderView::testResetCachedSizeHint()
class StatusTipHeaderView : public QHeaderView
{
+ Q_OBJECT
public:
- StatusTipHeaderView(Qt::Orientation orientation = Qt::Horizontal, QWidget *parent = 0) :
- QHeaderView(orientation, parent), gotStatusTipEvent(false) {}
- bool gotStatusTipEvent;
+ using QHeaderView::QHeaderView;
QString statusTipText;
+ bool gotStatusTipEvent = false;
protected:
- bool event(QEvent *e)
+ bool event(QEvent *e) override
{
if (e->type() == QEvent::StatusTip) {
gotStatusTipEvent = true;
@@ -3471,15 +3420,14 @@ protected:
void tst_QHeaderView::statusTips()
{
- StatusTipHeaderView headerView;
- QtTestModel model;
- model.rows = model.cols = 5;
+ StatusTipHeaderView headerView(Qt::Horizontal);
+ QtTestModel model(5, 5);
headerView.setModel(&model);
headerView.viewport()->setMouseTracking(true);
headerView.setGeometry(QRect(QPoint(QApplication::desktop()->geometry().center() - QPoint(250, 250)),
QSize(500, 500)));
headerView.show();
- qApp->setActiveWindow(&headerView);
+ QApplication::setActiveWindow(&headerView);
QVERIFY(QTest::qWaitForWindowActive(&headerView));
// Ensure it is moved away first and then moved to the relevant section
@@ -3504,8 +3452,7 @@ void tst_QHeaderView::testRemovingColumnsViaLayoutChanged()
{
const int persistentSectionSize = 101;
- QtTestModel model;
- model.rows = model.cols = 5;
+ QtTestModel model(5, 5);
view->setModel(&model);
for (int i = 0; i < model.cols; ++i)
view->resizeSection(i, persistentSectionSize + i);
diff --git a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
index 071665a5e3..10beacbe75 100644
--- a/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/tst_qitemview.cpp
@@ -26,9 +26,10 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QtCore>
+#include <QRandomGenerator>
+#include <QStack>
+#include <QStandardItemModel>
+#include <QTest>
#include "viewstotest.cpp"
/*!
@@ -89,17 +90,19 @@ class CheckerModel : public QStandardItemModel
Q_OBJECT
public:
- CheckerModel() : QStandardItemModel() {};
+ using QStandardItemModel::QStandardItemModel;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole ) const {
+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return QVariant();
}
return QStandardItemModel::data(index, role);
- };
+ }
- Qt::ItemFlags flags(const QModelIndex & index) const {
+ Qt::ItemFlags flags(const QModelIndex &index) const override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return Qt::ItemFlags();
@@ -107,21 +110,24 @@ public:
if (index.row() == 2 || index.row() == rowCount() - 3
|| index.column() == 2 || index.column() == columnCount() - 3) {
Qt::ItemFlags f = QStandardItemModel::flags(index);
- f &= ~Qt::ItemIsEnabled;
+ f.setFlag(Qt::ItemIsEnabled, false);
return f;
}
return QStandardItemModel::flags(index);
- };
+ }
- QModelIndex parent ( const QModelIndex & child ) const {
+ QModelIndex parent(const QModelIndex &child) const override
+ {
if (!child.isValid()) {
qWarning("%s: child index is not valid", Q_FUNC_INFO);
return QModelIndex();
}
return QStandardItemModel::parent(child);
- };
+ }
- QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const {
+ QVariant headerData(int section, Qt::Orientation orientation,
+ int role = Qt::DisplayRole) const override
+ {
if (orientation == Qt::Horizontal
&& (section < 0 || section > columnCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
@@ -137,11 +143,9 @@ public:
return QStandardItemModel::headerData(section, orientation, role);
}
- QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const {
- return QStandardItemModel::index(row, column, parent);
- };
-
- bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole ) {
+ bool setData(const QModelIndex &index, const QVariant &value,
+ int role = Qt::EditRole) override
+ {
if (!index.isValid()) {
qWarning("%s: index is not valid", Q_FUNC_INFO);
return false;
@@ -149,15 +153,19 @@ public:
return QStandardItemModel::setData(index, value, role);
}
- void sort( int column, Qt::SortOrder order = Qt::AscendingOrder ) {
+ void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override
+ {
if (column < 0 || column > columnCount())
qWarning("%s: invalid column %d, must be in range 0..%d",
Q_FUNC_INFO, column, columnCount());
else
QStandardItemModel::sort(column, order);
- };
+ }
- QModelIndexList match ( const QModelIndex & start, int role, const QVariant & value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap ) ) const {
+ QModelIndexList match(const QModelIndex &start, int role,
+ const QVariant &value, int hits = 1,
+ Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override
+ {
if (hits <= 0) {
qWarning("%s: hits must be greater than zero", Q_FUNC_INFO);
return QModelIndexList();
@@ -167,9 +175,11 @@ public:
return QModelIndexList();
}
return QAbstractItemModel::match(start, role, value, hits, flags);
- };
+ }
- bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole ) {
+ bool setHeaderData(int section, Qt::Orientation orientation,
+ const QVariant &value, int role = Qt::EditRole) override
+ {
if (orientation == Qt::Horizontal
&& (section < 0 || section > columnCount())) {
qWarning("%s: invalid section %d, must be in range 0..%d",
@@ -183,7 +193,7 @@ public:
return false;
}
return QAbstractItemModel::setHeaderData(section, orientation, value, role);
- };
+ }
};
void tst_QItemView::init()
@@ -197,9 +207,9 @@ void tst_QItemView::cleanup()
delete testViews;
delete view;
delete treeModel;
- view = 0;
- testViews = 0;
- treeModel = 0;
+ view = nullptr;
+ testViews = nullptr;
+ treeModel = nullptr;
}
void tst_QItemView::setupWithNoTestData()
@@ -207,15 +217,15 @@ void tst_QItemView::setupWithNoTestData()
ViewsToTest testViews;
QTest::addColumn<QString>("viewType");
QTest::addColumn<bool>("displays");
- QTest::addColumn<int>("vscroll");
- QTest::addColumn<int>("hscroll");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("vscroll");
+ QTest::addColumn<QAbstractItemView::ScrollMode>("hscroll");
for (int i = 0; i < testViews.tests.size(); ++i) {
QString view = testViews.tests.at(i).viewType;
QString test = view + " ScrollPerPixel";
bool displayIndexes = (testViews.tests.at(i).display == ViewsToTest::DisplayRoot);
QTest::newRow(test.toLatin1().data()) << view << displayIndexes
- << (int)QAbstractItemView::ScrollPerPixel
- << (int)QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
+ << QAbstractItemView::ScrollPerPixel
;
}
for (int i = 0; i < testViews.tests.size(); ++i) {
@@ -223,8 +233,8 @@ void tst_QItemView::setupWithNoTestData()
QString test = view + " ScrollPerItem";
bool displayIndexes = (testViews.tests.at(i).display == ViewsToTest::DisplayRoot);
QTest::newRow(test.toLatin1().data()) << view << displayIndexes
- << (int)QAbstractItemView::ScrollPerItem
- << (int)QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
+ << QAbstractItemView::ScrollPerItem
;
}
}
@@ -267,13 +277,13 @@ void tst_QItemView::nonDestructiveBasicTest_data()
void tst_QItemView::nonDestructiveBasicTest()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
// setSelectionModel() will assert
//view->setSelectionModel(0);
@@ -396,7 +406,8 @@ void tst_QItemView::spider_data()
setupWithNoTestData();
}
-void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
+void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress)
+{
int width = widget->width();
int height = widget->height();
for (int i = 0; i < 5; ++i) {
@@ -409,7 +420,7 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
QTest::mousePress(widget, Qt::LeftButton, modifier, press);
QTest::mouseMove(widget, releasePoint);
if (QRandomGenerator::global()->bounded(1) == 0)
- QTest::mouseRelease(widget, Qt::LeftButton, 0, releasePoint);
+ QTest::mouseRelease(widget, Qt::LeftButton, {}, releasePoint);
else
QTest::mouseRelease(widget, Qt::LeftButton, modifier, releasePoint);
QTest::keyClick(widget, keyPress);
@@ -425,13 +436,13 @@ void touch(QWidget *widget, Qt::KeyboardModifier modifier, Qt::Key keyPress){
void tst_QItemView::spider()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
QVERIFY(QTest::qWaitForWindowActive(view));
@@ -454,21 +465,21 @@ void tst_QItemView::resize()
QSKIP("This test needs to be re-thought out, it takes too long and doesn't really catch the problem.");
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
- for (int w = 100; w < 400; w+=10) {
- for (int h = 100; h < 400; h+=10) {
+ for (int w = 100; w < 400; w += 10) {
+ for (int h = 100; h < 400; h += 10) {
view->resize(w, h);
QTest::qWait(1);
- qApp->processEvents();
+ QCoreApplication::processEvents();
}
}
}
@@ -481,13 +492,13 @@ void tst_QItemView::visualRect_data()
void tst_QItemView::visualRect()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
QCOMPARE(view->visualRect(QModelIndex()), QRect());
// Add model
@@ -617,13 +628,13 @@ void tst_QItemView::indexAt_data()
void tst_QItemView::indexAt()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->show();
view->setModel(treeModel);
checkChildren(view);
@@ -648,13 +659,13 @@ void tst_QItemView::scrollTo_data()
void tst_QItemView::scrollTo()
{
QFETCH(QString, viewType);
- QFETCH(int, vscroll);
- QFETCH(int, hscroll);
+ QFETCH(QAbstractItemView::ScrollMode, vscroll);
+ QFETCH(QAbstractItemView::ScrollMode, hscroll);
view = testViews->createView(viewType);
QVERIFY(view);
- view->setVerticalScrollMode((QAbstractItemView::ScrollMode)vscroll);
- view->setHorizontalScrollMode((QAbstractItemView::ScrollMode)hscroll);
+ view->setVerticalScrollMode(vscroll);
+ view->setHorizontalScrollMode(hscroll);
view->setModel(treeModel);
view->show();
@@ -682,10 +693,10 @@ void tst_QItemView::moveCursor_data()
setupWithNoTestData();
}
-class Event {
-public:
- Event(){}
- Event(Qt::Key k, QModelIndex s, QModelIndex e, QString n) : key(k), start(s), end(e), name(n){}
+struct Event
+{
+ Event(Qt::Key k, const QModelIndex &s, const QModelIndex &e, const QString &n)
+ : key(k), start(s), end(e), name(n){}
Qt::Key key;
QModelIndex start;
QModelIndex end;
diff --git a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
index f1da2f4fe7..c55cc865fc 100644
--- a/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
+++ b/tests/auto/widgets/itemviews/qitemview/viewstotest.cpp
@@ -26,11 +26,10 @@
**
****************************************************************************/
-
-#include <QtTest/QtTest>
-#include <QtCore/QtCore>
-#include <QtGui/QtGui>
-#include <QtWidgets/QtWidgets>
+#include <QHeaderView>
+#include <QListView>
+#include <QTableView>
+#include <QTreeView>
/*
To add a view to be tested add the header file to the includes
@@ -54,12 +53,12 @@ public:
enum Display { DisplayNone, DisplayRoot };
struct test {
- test(QString m, Display d) : viewType(m), display(d){};
+ test(const QString &m, Display d) : viewType(m), display(d) {}
QString viewType;
Display display;
};
- QList<test> tests;
+ QVector<test> tests;
};
@@ -84,7 +83,7 @@ ViewsToTest::ViewsToTest()
*/
QAbstractItemView *ViewsToTest::createView(const QString &viewType)
{
- QAbstractItemView *view = 0;
+ QAbstractItemView *view = nullptr;
if (viewType == "QListView_ScrollPerItem") {
view = new QListView();
view->setObjectName("QListView");
@@ -137,16 +136,16 @@ void ViewsToTest::hideIndexes(QAbstractItemView *view)
if (QTableView *tableView = qobject_cast<QTableView *>(view)) {
tableView->setColumnHidden(1, true);
tableView->setRowHidden(1, true);
- tableView->setRowHidden(tableView->model()->rowCount()-2, true);
+ tableView->setRowHidden(tableView->model()->rowCount() - 2, true);
}
if (QTreeView *treeView = qobject_cast<QTreeView *>(view)) {
treeView->setColumnHidden(1, true);
treeView->setRowHidden(1, QModelIndex(), true);
- treeView->setRowHidden(treeView->model()->rowCount()-2, QModelIndex(), true);
+ treeView->setRowHidden(treeView->model()->rowCount() - 2, QModelIndex(), true);
}
if (QListView *listView = qobject_cast<QListView *>(view)) {
listView->setRowHidden(1, true);
- listView->setRowHidden(listView->model()->rowCount()-2, true);
+ listView->setRowHidden(listView->model()->rowCount() - 2, true);
}
}
diff --git a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
index e02986b712..aef2d26137 100644
--- a/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
+++ b/tests/auto/widgets/itemviews/qlistview/tst_qlistview.cpp
@@ -87,7 +87,7 @@ public:
using QListView::viewOptions;
QRegion getVisualRegionForSelection() const
{
- return QListView::visualRegionForSelection(selectionModel()->selection());
+ return QListView::visualRegionForSelection(selectionModel()->selection());
}
friend class tst_QListView;
@@ -527,7 +527,7 @@ void tst_QListView::moveCursor2()
vu.setGridSize(QSize(34,56));
//Standard framesize is 1. If Framesize > 2 increase size
int frameSize = qApp->style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
- vu.resize(300 + frameSize * 2,300);
+ vu.resize(300 + frameSize * 2, 300);
vu.setFlow(QListView::LeftToRight);
vu.setMovement(QListView::Static);
vu.setWrapping(true);
@@ -552,7 +552,7 @@ void tst_QListView::moveCursor3()
QStandardItem *i1 = new QStandardItem("First item, long name");
QStandardItem *i2 = new QStandardItem("2nd item");
QStandardItem *i3 = new QStandardItem("Third item, long name");
- i1->setSizeHint(QSize(200,32));
+ i1->setSizeHint(QSize(200, 32));
model.appendRow(i1);
model.appendRow(i2);
model.appendRow(i3);
@@ -581,10 +581,10 @@ public:
{
QListView::showEvent(e);
int columnwidth = sizeHintForColumn(0);
- QSize sz = sizeHintForIndex(model()->index(0,0));
+ QSize sz = sizeHintForIndex(model()->index(0, 0));
// This should retrieve a model index in the 2nd section
- m_index = indexAt(QPoint(columnwidth +2, sz.height()/2));
+ m_index = indexAt(QPoint(columnwidth +2, sz.height() / 2));
m_shown = true;
}
@@ -601,17 +601,17 @@ void tst_QListView::indexAt()
view.setViewMode(QListView::ListMode);
view.setFlow(QListView::TopToBottom);
- QSize sz = view.sizeHintForIndex(model.index(0,0));
+ QSize sz = view.sizeHintForIndex(model.index(0, 0));
QModelIndex index;
- index = view.indexAt(QPoint(20,0));
+ index = view.indexAt(QPoint(20, 0));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 0);
- index = view.indexAt(QPoint(20,sz.height()));
+ index = view.indexAt(QPoint(20, sz.height()));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 1);
- index = view.indexAt(QPoint(20,2 * sz.height()));
+ index = view.indexAt(QPoint(20, 2 * sz.height()));
QVERIFY(!index.isValid());
// Check when peeking out of the viewport bounds
@@ -1058,9 +1058,9 @@ void tst_QListView::selection()
QFETCH(bool, wrapping);
QFETCH(int, spacing);
QFETCH(QSize, gridSize);
- QFETCH(IntList, hiddenRows);
+ QFETCH(const IntList, hiddenRows);
QFETCH(QRect, selectionRect);
- QFETCH(IntList, expectedItems);
+ QFETCH(const IntList, expectedItems);
QWidget topLevel;
PublicListView v(&topLevel);
@@ -1079,21 +1079,20 @@ void tst_QListView::selection()
v.setSpacing(spacing);
if (gridSize.isValid())
v.setGridSize(gridSize);
- for (int j = 0; j < hiddenRows.count(); ++j)
- v.setRowHidden(hiddenRows.at(j), true);
+ for (int row : hiddenRows)
+ v.setRowHidden(row, true);
- v.resize(525,525);
+ v.resize(525, 525);
topLevel.show();
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
v.setSelection(selectionRect, QItemSelectionModel::ClearAndSelect);
- QModelIndexList selected = v.selectionModel()->selectedIndexes();
-
+ const QModelIndexList selected = v.selectionModel()->selectedIndexes();
QCOMPARE(selected.count(), expectedItems.count());
- for (int i = 0; i < selected.count(); ++i)
- QVERIFY(expectedItems.contains(selected.at(i).row()));
+ for (const auto &idx : selected)
+ QVERIFY(expectedItems.contains(idx.row()));
}
void tst_QListView::scrollTo()
@@ -1141,7 +1140,7 @@ void tst_QListView::scrollTo()
QVERIFY(QTest::qWaitForWindowExposed(&topLevel));
//by default, the list view scrolls per item and has no wrapping
- QModelIndex index = model.index(6,0);
+ QModelIndex index = model.index(6, 0);
//we save the size of the item for later comparisons
const QSize itemsize = lv.visualRect(index).size();
@@ -1152,15 +1151,14 @@ void tst_QListView::scrollTo()
QPoint p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed
- QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).y(),0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//we scroll down. As the item is to tall for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).y(), -itemsize.height());
+ QTRY_COMPARE(lv.visualRect(index).y(), -itemsize.height());
QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).y(), 0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//Let's enable wrapping
@@ -1170,22 +1168,20 @@ void tst_QListView::scrollTo()
//we click the item
p = lv.visualRect(index).center();
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
- //let's wait because the scrolling is delayed
- QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).x(),0);
+ QTRY_COMPARE(lv.visualRect(index).x(), 0);
//we scroll right. As the item is too wide for the view, it will disappear
QTest::keyClick(lv.viewport(), Qt::Key_Right, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).x(), -itemsize.width());
+ QTRY_COMPARE(lv.visualRect(index).x(), -itemsize.width());
QTest::keyClick(lv.viewport(), Qt::Key_Left, Qt::NoModifier);
- QCOMPARE(lv.visualRect(index).x(), 0);
+ QTRY_COMPARE(lv.visualRect(index).x(), 0);
lv.setWrapping(false);
QCoreApplication::processEvents(); //let the layout happen
//Let's try with scrolling per pixel
- lv.setHorizontalScrollMode( QListView::ScrollPerPixel);
+ lv.setHorizontalScrollMode(QListView::ScrollPerPixel);
lv.verticalScrollBar()->setValue(0); //scrolls back to the first item
//we click the item
@@ -1193,11 +1189,11 @@ void tst_QListView::scrollTo()
QTest::mouseClick(lv.viewport(), Qt::LeftButton, Qt::NoModifier, p);
//let's wait because the scrolling is delayed
QTest::qWait(QApplication::doubleClickInterval() + 150);
- QTRY_COMPARE(lv.visualRect(index).y(),0);
+ QTRY_COMPARE(lv.visualRect(index).y(), 0);
//we scroll down. As the item is too tall for the view, it will partially disappear
QTest::keyClick(lv.viewport(), Qt::Key_Down, Qt::NoModifier);
- QVERIFY(lv.visualRect(index).y()<0);
+ QVERIFY(lv.visualRect(index).y() < 0);
QTest::keyClick(lv.viewport(), Qt::Key_Up, Qt::NoModifier);
QCOMPARE(lv.visualRect(index).y(), 0);
@@ -1498,7 +1494,7 @@ void tst_QListView::task203585_selectAll()
//we make sure that "select all" doesn't select the hidden items
QListView view;
view.setSelectionMode(QAbstractItemView::ExtendedSelection);
- view.setModel(new QStringListModel(QStringList() << "foo", &view));
+ view.setModel(new QStringListModel({"foo"}, &view));
view.setRowHidden(0, true);
view.selectAll();
QVERIFY(view.selectionModel()->selectedIndexes().isEmpty());
@@ -1641,13 +1637,13 @@ void tst_QListView::keyboardSearch()
QVERIFY(QTest::qWaitForWindowActive(&view));
QTest::keyClick(&view, Qt::Key_K);
- QTRY_COMPARE(view.currentIndex() , model.index(5,0)); //KAFEINE
+ QTRY_COMPARE(view.currentIndex() , model.index(5, 0)); //KAFEINE
QTest::keyClick(&view, Qt::Key_O);
- QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+ QTRY_COMPARE(view.currentIndex() , model.index(6, 0)); //KONQUEROR
QTest::keyClick(&view, Qt::Key_N);
- QTRY_COMPARE(view.currentIndex() , model.index(6,0)); //KONQUEROR
+ QTRY_COMPARE(view.currentIndex() , model.index(6, 0)); //KONQUEROR
}
void tst_QListView::shiftSelectionWithNonUniformItemSizes()
@@ -1796,9 +1792,9 @@ void tst_QListView::task262152_setModelColumnNavigate()
QVERIFY(QTest::qWaitForWindowActive(&view));
QCOMPARE(&view, QApplication::activeWindow());
QTest::keyClick(&view, Qt::Key_Down);
- QTRY_COMPARE(view.currentIndex(), model.index(1,1));
+ QTRY_COMPARE(view.currentIndex(), model.index(1, 1));
QTest::keyClick(&view, Qt::Key_Down);
- QTRY_COMPARE(view.currentIndex(), model.index(2,1));
+ QTRY_COMPARE(view.currentIndex(), model.index(2, 1));
}
void tst_QListView::taskQTBUG_2233_scrollHiddenItems_data()
@@ -1831,7 +1827,7 @@ void tst_QListView::taskQTBUG_2233_scrollHiddenItems()
(view.flow() == QListView::TopToBottom
? view.verticalScrollBar()
: view.horizontalScrollBar())->setValue(i);
- QModelIndex index = view.indexAt(QPoint(0,0));
+ QModelIndex index = view.indexAt(QPoint(0, 0));
QVERIFY(index.isValid());
QCOMPARE(index.row(), 2 * i + 1);
}
@@ -2403,13 +2399,13 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
QWheelEvent wheelLeftDownEvent(pos, globalPos, QPoint(0, 0), QPoint(120, -120), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
int hValue = lv.horizontalScrollBar()->value();
- QApplication::sendEvent(lv.viewport(), &wheelDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.horizontalScrollBar()->value() > hValue);
- QApplication::sendEvent(lv.viewport(), &wheelUpEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelUpEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
- QApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelLeftDownEvent);
QCOMPARE(lv.horizontalScrollBar()->value(), hValue);
// ensure that vertical wheel events are not converted when vertical
@@ -2419,7 +2415,7 @@ void tst_QListView::horizontalScrollingByVerticalWheelEvents()
QCoreApplication::processEvents();
int vValue = lv.verticalScrollBar()->value();
- QApplication::sendEvent(lv.viewport(), &wheelDownEvent);
+ QCoreApplication::sendEvent(lv.viewport(), &wheelDownEvent);
QVERIFY(lv.verticalScrollBar()->value() > vValue);
#else
QSKIP("Built with --no-feature-wheelevent");
@@ -2553,9 +2549,9 @@ void tst_QListView::internalDragDropMove()
{
const QPoint pos = list.rect().center();
QMouseEvent mouseMove(QEvent::MouseMove, pos, list.mapToGlobal(pos), Qt::NoButton, {}, {});
- QApplication::sendEvent(&list, &mouseMove);
+ QCoreApplication::sendEvent(&list, &mouseMove);
QMouseEvent mouseRelease(QEvent::MouseButtonRelease, pos, list.mapToGlobal(pos), Qt::LeftButton, {}, {});
- QApplication::sendEvent(&list, &mouseRelease);
+ QCoreApplication::sendEvent(&list, &mouseRelease);
});
const int expectedCount = data.rowCount();
list.startDrag(Qt::MoveAction|Qt::CopyAction);
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index 8884c5feed..51a7026e85 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -379,7 +379,7 @@ void TiledPixmapPainter::paintEvent(QPaintEvent *event)
// large pixmap: 2 x 2 tiles
// 2x pixmap : 4 x 4 tiles
//
- // On a 2x display the 2x pimxap tiles
+ // On a 2x display the 2x pixmap tiles
// will be drawn in high resolution.
p.drawTiledPixmap(QRect(xoff, yoff, tileAreaEdge, tileAreaEdge), pixmap1X);
yoff += tiles * pixmapEdge + 10;
diff --git a/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp b/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp
index 27dd8097ad..bb3722bec5 100644
--- a/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp
+++ b/tests/manual/rhi/compressedtexture_bc1/compressedtexture_bc1.cpp
@@ -182,7 +182,7 @@ void Window::customRender()
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
diff --git a/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp b/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp
index 87d1e7646a..4931c8eaa1 100644
--- a/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp
+++ b/tests/manual/rhi/compressedtexture_bc1_subupload/compressedtexture_bc1_subupload.cpp
@@ -197,7 +197,7 @@ void Window::customRender()
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
diff --git a/tests/manual/rhi/computebuffer/computebuffer.cpp b/tests/manual/rhi/computebuffer/computebuffer.cpp
index 2a3e0b92b5..c991a11438 100644
--- a/tests/manual/rhi/computebuffer/computebuffer.cpp
+++ b/tests/manual/rhi/computebuffer/computebuffer.cpp
@@ -195,7 +195,7 @@ void Window::customRender()
cb->endComputePass();
// graphics pass
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
cb->setGraphicsPipeline(d.graphicsPipeline);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
QRhiCommandBuffer::VertexInput vbufBinding(d.sbuf, 0);
diff --git a/tests/manual/rhi/computeimage/computeimage.cpp b/tests/manual/rhi/computeimage/computeimage.cpp
index 51bf216c5a..a6c860f8ee 100644
--- a/tests/manual/rhi/computeimage/computeimage.cpp
+++ b/tests/manual/rhi/computeimage/computeimage.cpp
@@ -217,7 +217,7 @@ void Window::customRender()
cb->dispatch(d.imageSize.width() / 16, d.imageSize.height() / 16, 1);
cb->endComputePass();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
diff --git a/tests/manual/rhi/cubemap/cubemap.cpp b/tests/manual/rhi/cubemap/cubemap.cpp
index df302736a2..fe6ac9762e 100644
--- a/tests/manual/rhi/cubemap/cubemap.cpp
+++ b/tests/manual/rhi/cubemap/cubemap.cpp
@@ -168,7 +168,7 @@ void Window::customRender()
// no translation
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
cb->setShaderResources();
diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp
new file mode 100644
index 0000000000..25a7c64c8a
--- /dev/null
+++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.cpp
@@ -0,0 +1,241 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// This is a test for scissoring. Based on the cubemap test (because there the
+// rendering covers the entire viewport which is what we need here). The
+// scissor rectangle moves first up, then down, then from the center to the
+// left and then to right. The important part is to ensure that the behavior
+// identical between all backends, especially when the rectangle is partly or
+// fully off window.
+
+#include "../shared/examplefw.h"
+#include "../shared/cube.h"
+
+struct {
+ QVector<QRhiResource *> releasePool;
+ QRhiBuffer *vbuf = nullptr;
+ QRhiBuffer *ubuf = nullptr;
+ QRhiTexture *tex = nullptr;
+ QRhiSampler *sampler = nullptr;
+ QRhiShaderResourceBindings *srb = nullptr;
+ QRhiGraphicsPipeline *ps = nullptr;
+ QRhiResourceUpdateBatch *initialUpdates = nullptr;
+
+ QPoint scissorBottomLeft;
+ QSize scissorSize;
+ int scissorAnimState = 0;
+ QSize outputSize;
+} d;
+
+void Window::customInit()
+{
+ d.vbuf = m_r->newBuffer(QRhiBuffer::Immutable, QRhiBuffer::VertexBuffer, sizeof(cube));
+ d.vbuf->build();
+ d.releasePool << d.vbuf;
+
+ d.ubuf = m_r->newBuffer(QRhiBuffer::Dynamic, QRhiBuffer::UniformBuffer, 64);
+ d.ubuf->build();
+ d.releasePool << d.ubuf;
+
+ const QSize cubeMapSize(512, 512);
+ d.tex = m_r->newTexture(QRhiTexture::RGBA8, cubeMapSize, 1, QRhiTexture::CubeMap);
+ d.releasePool << d.tex;
+ d.tex->build();
+
+ d.initialUpdates = m_r->nextResourceUpdateBatch();
+ d.initialUpdates->uploadStaticBuffer(d.vbuf, cube);
+
+ QImage img = QImage(":/c.png").mirrored().convertToFormat(QImage::Format_RGBA8888);
+ // just use the same image for all faces for now
+ QRhiTextureSubresourceUploadDescription subresDesc(img);
+ QRhiTextureUploadDescription desc({
+ { 0, 0, subresDesc }, // +X
+ { 1, 0, subresDesc }, // -X
+ { 2, 0, subresDesc }, // +Y
+ { 3, 0, subresDesc }, // -Y
+ { 4, 0, subresDesc }, // +Z
+ { 5, 0, subresDesc } // -Z
+ });
+ d.initialUpdates->uploadTexture(d.tex, desc);
+
+ d.sampler = m_r->newSampler(QRhiSampler::Linear, QRhiSampler::Linear, QRhiSampler::None,
+ QRhiSampler::Repeat, QRhiSampler::Repeat);
+ d.releasePool << d.sampler;
+ d.sampler->build();
+
+ d.srb = m_r->newShaderResourceBindings();
+ d.releasePool << d.srb;
+ d.srb->setBindings({
+ QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf),
+ QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler)
+ });
+ d.srb->build();
+
+ d.ps = m_r->newGraphicsPipeline();
+ d.releasePool << d.ps;
+
+ d.ps->setFlags(QRhiGraphicsPipeline::UsesScissor);
+
+ d.ps->setDepthTest(true);
+ d.ps->setDepthWrite(true);
+ d.ps->setDepthOp(QRhiGraphicsPipeline::LessOrEqual);
+
+ d.ps->setCullMode(QRhiGraphicsPipeline::Front); // we are inside the cube so cull front, not back
+ d.ps->setFrontFace(QRhiGraphicsPipeline::CCW); // front is ccw in the cube data
+
+ QShader vs = getShader(QLatin1String(":/cubemap.vert.qsb"));
+ Q_ASSERT(vs.isValid());
+ QShader fs = getShader(QLatin1String(":/cubemap.frag.qsb"));
+ Q_ASSERT(fs.isValid());
+ d.ps->setShaderStages({
+ { QRhiShaderStage::Vertex, vs },
+ { QRhiShaderStage::Fragment, fs }
+ });
+
+ QRhiVertexInputLayout inputLayout;
+ inputLayout.setBindings({
+ { 3 * sizeof(float) }
+ });
+ inputLayout.setAttributes({
+ { 0, 0, QRhiVertexInputAttribute::Float3, 0 }
+ });
+
+ d.ps->setVertexInputLayout(inputLayout);
+ d.ps->setShaderResourceBindings(d.srb);
+ d.ps->setRenderPassDescriptor(m_rp);
+
+ d.ps->build();
+
+ d.scissorAnimState = 0;
+}
+
+void Window::customRelease()
+{
+ qDeleteAll(d.releasePool);
+ d.releasePool.clear();
+}
+
+static void advanceScissor()
+{
+ switch (d.scissorAnimState) {
+ case 1: // up
+ d.scissorBottomLeft.setX(d.outputSize.width() / 4);
+ d.scissorBottomLeft.ry() += 1;
+ if (d.scissorBottomLeft.y() > d.outputSize.height() + 100)
+ d.scissorAnimState = 2;
+ break;
+ case 2: // down
+ d.scissorBottomLeft.ry() -= 1;
+ if (d.scissorBottomLeft.y() < -d.scissorSize.height() - 100)
+ d.scissorAnimState = 3;
+ break;
+ case 3: // left
+ d.scissorBottomLeft.setY(d.outputSize.height() / 4);
+ d.scissorBottomLeft.rx() += 1;
+ if (d.scissorBottomLeft.x() > d.outputSize.width() + 100)
+ d.scissorAnimState = 4;
+ break;
+ case 4: // right
+ d.scissorBottomLeft.rx() -= 1;
+ if (d.scissorBottomLeft.x() < -d.scissorSize.width() - 100)
+ d.scissorAnimState = 1;
+ break;
+ }
+
+ qDebug() << "scissor bottom-left" << d.scissorBottomLeft << "size" << d.scissorSize;
+}
+
+void Window::customRender()
+{
+ const QSize outputSizeInPixels = m_sc->currentPixelSize();
+ QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
+ QRhiResourceUpdateBatch *u = m_r->nextResourceUpdateBatch();
+
+ if (d.initialUpdates) {
+ u->merge(d.initialUpdates);
+ d.initialUpdates->release();
+ d.initialUpdates = nullptr;
+ }
+
+ d.outputSize = outputSizeInPixels;
+ if (d.scissorAnimState == 0) {
+ d.scissorBottomLeft = QPoint(outputSizeInPixels.width() / 4, 0);
+ d.scissorSize = QSize(outputSizeInPixels.width() / 2, outputSizeInPixels.height() / 2);
+ d.scissorAnimState = 1;
+ }
+
+ QMatrix4x4 mvp = m_r->clipSpaceCorrMatrix();
+ mvp.perspective(90.0f, outputSizeInPixels.width() / (float) outputSizeInPixels.height(), 0.01f, 1000.0f);
+ // cube vertices go from -1..1
+ mvp.scale(10);
+ static float rx = 0;
+ mvp.rotate(rx, 1, 0, 0);
+ rx += 0.5f;
+ // no translation
+ u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
+
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
+ cb->setGraphicsPipeline(d.ps);
+ cb->setViewport(QRhiViewport(0, 0, outputSizeInPixels.width(), outputSizeInPixels.height()));
+
+ // Apply a scissor rectangle that moves around on the screen, also
+ // exercising the out of screen (negative x or y) case.
+ cb->setScissor(QRhiScissor(d.scissorBottomLeft.x(), d.scissorBottomLeft.y(),
+ d.scissorSize.width(), d.scissorSize.height()));
+
+ cb->setShaderResources();
+
+ const QRhiCommandBuffer::VertexInput vbufBinding(d.vbuf, 0);
+ cb->setVertexInput(0, 1, &vbufBinding);
+ cb->draw(36);
+ cb->endPass();
+
+ advanceScissor();
+}
diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro
new file mode 100644
index 0000000000..1f02bda87a
--- /dev/null
+++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.pro
@@ -0,0 +1,8 @@
+TEMPLATE = app
+
+QT += gui-private
+
+SOURCES = \
+ cubemap_scissor.cpp
+
+RESOURCES = cubemap_scissor.qrc
diff --git a/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc
new file mode 100644
index 0000000000..8a0ae17dc8
--- /dev/null
+++ b/tests/manual/rhi/cubemap_scissor/cubemap_scissor.qrc
@@ -0,0 +1,7 @@
+<!DOCTYPE RCC><RCC version="1.0">
+<qresource>
+ <file alias="cubemap.vert.qsb">../cubemap/cubemap.vert.qsb</file>
+ <file alias="cubemap.frag.qsb">../cubemap/cubemap.frag.qsb</file>
+ <file alias="c.png">../cubemap/c.png</file>
+</qresource>
+</RCC>
diff --git a/tests/manual/rhi/floattexture/floattexture.cpp b/tests/manual/rhi/floattexture/floattexture.cpp
index 16e58ff00f..0d24860c78 100644
--- a/tests/manual/rhi/floattexture/floattexture.cpp
+++ b/tests/manual/rhi/floattexture/floattexture.cpp
@@ -317,7 +317,7 @@ void Window::customRender()
}
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
diff --git a/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp b/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
index 3c39ff1719..ea1fefc308 100644
--- a/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
+++ b/tests/manual/rhi/hellominimalcrossgfxtriangle/hellominimalcrossgfxtriangle.cpp
@@ -298,7 +298,7 @@ void Window::init()
m_sc = m_r->newSwapChain();
// allow depth-stencil, although we do not actually enable depth test/write for the triangle
m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
- QSize(), // no need to set the size yet
+ QSize(), // no need to set the size here, due to UsedWithSwapChainOnly
1,
QRhiRenderBuffer::UsedWithSwapChainOnly);
releasePool << m_ds;
@@ -376,16 +376,12 @@ void Window::releaseResources()
void Window::resizeSwapChain()
{
- const QSize outputSize = m_sc->surfacePixelSize();
-
- m_ds->setPixelSize(outputSize);
- m_ds->build(); // == m_ds->release(); m_ds->build();
-
- m_hasSwapChain = m_sc->buildOrResize();
+ m_hasSwapChain = m_sc->buildOrResize(); // also handles m_ds
m_elapsedMs = 0;
m_elapsedCount = 0;
+ const QSize outputSize = m_sc->currentPixelSize();
m_proj = m_r->clipSpaceCorrMatrix();
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 100.0f);
m_proj.translate(0, 0, -4);
diff --git a/tests/manual/rhi/instancing/instancing.cpp b/tests/manual/rhi/instancing/instancing.cpp
index 87029e541c..bdafbd81bc 100644
--- a/tests/manual/rhi/instancing/instancing.cpp
+++ b/tests/manual/rhi/instancing/instancing.cpp
@@ -161,7 +161,7 @@ void Window::customRender()
u->updateDynamicBuffer(d.ubuf, 0, 64, mvp.constData());
}
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
diff --git a/tests/manual/rhi/mrt/mrt.cpp b/tests/manual/rhi/mrt/mrt.cpp
index b80af7ac87..dc72c7d194 100644
--- a/tests/manual/rhi/mrt/mrt.cpp
+++ b/tests/manual/rhi/mrt/mrt.cpp
@@ -200,12 +200,10 @@ void Window::customInit()
{ QRhiShaderStage::Vertex, getShader(QLatin1String(":/mrt.vert.qsb")) },
{ QRhiShaderStage::Fragment, getShader(QLatin1String(":/mrt.frag.qsb")) }
});
- QVector<QRhiGraphicsPipeline::TargetBlend> blends;
- for (int i = 0; i < ATTCOUNT; ++i) {
- QRhiGraphicsPipeline::TargetBlend blend;
- blends.append(blend);
- }
- d.triPs->setTargetBlends(blends);
+
+ QRhiGraphicsPipeline::TargetBlend blends[ATTCOUNT]; // defaults to blending == false
+ d.triPs->setTargetBlends(blends, blends + ATTCOUNT);
+
inputLayout.setBindings({
{ 5 * sizeof(float) }
});
@@ -283,7 +281,7 @@ void Window::customRender()
}
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
vbufBinding.second = 0;
diff --git a/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp b/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp
index b77a27b1b5..27dabb2276 100644
--- a/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp
+++ b/tests/manual/rhi/msaarenderbuffer/msaarenderbuffer.cpp
@@ -248,7 +248,7 @@ void Window::customRender()
// onscreen (quad)
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
diff --git a/tests/manual/rhi/msaatexture/msaatexture.cpp b/tests/manual/rhi/msaatexture/msaatexture.cpp
index 46a9b2830c..2fb466c8d6 100644
--- a/tests/manual/rhi/msaatexture/msaatexture.cpp
+++ b/tests/manual/rhi/msaatexture/msaatexture.cpp
@@ -240,7 +240,7 @@ void Window::customInit()
#else
d.msaaTriPs->setSampleCount(1);
#endif
- d.msaaTriPs->setShaderStages(d.triPs->shaderStages());
+ d.msaaTriPs->setShaderStages(d.triPs->cbeginShaderStages(), d.triPs->cendShaderStages());
d.msaaTriPs->setVertexInputLayout(d.triPs->vertexInputLayout());
d.msaaTriPs->setShaderResourceBindings(d.triSrb);
d.msaaTriPs->setRenderPassDescriptor(d.msaaRtRp);
@@ -315,7 +315,7 @@ void Window::customRender()
// onscreen
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
cb->setGraphicsPipeline(d.psLeft); // showing the non-msaa version
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
cb->setShaderResources();
diff --git a/tests/manual/rhi/multiwindow/multiwindow.cpp b/tests/manual/rhi/multiwindow/multiwindow.cpp
index 4c5d5c345a..4d5de16a58 100644
--- a/tests/manual/rhi/multiwindow/multiwindow.cpp
+++ b/tests/manual/rhi/multiwindow/multiwindow.cpp
@@ -400,7 +400,7 @@ void Window::init()
{
m_sc = r.r->newSwapChain();
m_ds = r.r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
- QSize(), // no need to set the size yet
+ QSize(),
1,
QRhiRenderBuffer::UsedWithSwapChainOnly);
m_releasePool << m_ds;
@@ -427,13 +427,9 @@ void Window::releaseResources()
void Window::resizeSwapChain()
{
- const QSize outputSize = m_sc->surfacePixelSize();
-
- m_ds->setPixelSize(outputSize);
- m_ds->build();
-
m_hasSwapChain = m_sc->buildOrResize();
+ const QSize outputSize = m_sc->currentPixelSize();
m_proj = r.r->clipSpaceCorrMatrix();
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
m_proj.translate(0, 0, -4);
diff --git a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
index 53185bddb2..37c6cd04c3 100644
--- a/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
+++ b/tests/manual/rhi/multiwindow_threaded/multiwindow_threaded.cpp
@@ -441,7 +441,7 @@ void Renderer::init()
{
m_sc = r->newSwapChain();
m_ds = r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
- QSize(), // no need to set the size yet
+ QSize(),
1,
QRhiRenderBuffer::UsedWithSwapChainOnly);
m_releasePool << m_ds;
@@ -543,11 +543,9 @@ void Renderer::render(bool newlyExposed, bool wakeBeforePresent)
auto buildOrResizeSwapChain = [this] {
qDebug() << "renderer" << this << "build or resize swapchain for window" << window;
- const QSize outputSize = m_sc->surfacePixelSize();
- qDebug() << " size is" << outputSize;
- m_ds->setPixelSize(outputSize);
- m_ds->build();
m_hasSwapChain = m_sc->buildOrResize();
+ const QSize outputSize = m_sc->currentPixelSize();
+ qDebug() << " size is" << outputSize;
m_proj = r->clipSpaceCorrMatrix();
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 100.0f);
m_proj.translate(0, 0, -4);
diff --git a/tests/manual/rhi/rhi.pro b/tests/manual/rhi/rhi.pro
index d3661ff169..4768ee1c6d 100644
--- a/tests/manual/rhi/rhi.pro
+++ b/tests/manual/rhi/rhi.pro
@@ -8,6 +8,7 @@ SUBDIRS += \
msaatexture \
msaarenderbuffer \
cubemap \
+ cubemap_scissor \
multiwindow \
multiwindow_threaded \
triquadcube \
diff --git a/tests/manual/rhi/shadowmap/shadowmap.cpp b/tests/manual/rhi/shadowmap/shadowmap.cpp
index 9146be5cc9..424a8b3783 100644
--- a/tests/manual/rhi/shadowmap/shadowmap.cpp
+++ b/tests/manual/rhi/shadowmap/shadowmap.cpp
@@ -296,7 +296,7 @@ void Window::customRender()
cb->endPass();
// main pass
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 });
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 });
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
enqueueScene(cb, d.srb, oneRoundedUniformBlockSize, 0);
diff --git a/tests/manual/rhi/shared/examplefw.h b/tests/manual/rhi/shared/examplefw.h
index 4bd087473b..d28bbea0a8 100644
--- a/tests/manual/rhi/shared/examplefw.h
+++ b/tests/manual/rhi/shared/examplefw.h
@@ -58,6 +58,7 @@
#include <QPlatformSurfaceEvent>
#include <QElapsedTimer>
#include <QTimer>
+#include <QLoggingCategory>
#include <QtGui/private/qshader_p.h>
#include <QFile>
@@ -70,7 +71,6 @@
#endif
#if QT_CONFIG(vulkan)
-#include <QLoggingCategory>
#include <QtGui/private/qrhivulkan_p.h>
#endif
@@ -127,6 +127,7 @@ QRhiSwapChain::Flags scFlags = 0;
QRhi::BeginFrameFlags beginFrameFlags = 0;
QRhi::EndFrameFlags endFrameFlags = 0;
int framesUntilTdr = -1;
+bool transparentBackground = false;
class Window : public QWindow
{
@@ -167,6 +168,8 @@ protected:
QOffscreenSurface *m_fallbackSurface = nullptr;
#endif
+ QColor m_clearColor;
+
friend int main(int, char**);
};
@@ -194,6 +197,8 @@ Window::Window()
default:
break;
}
+
+ m_clearColor = transparentBackground ? Qt::transparent : QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f);
}
Window::~Window()
@@ -302,7 +307,7 @@ void Window::init()
m_sc = m_r->newSwapChain();
// allow depth-stencil, although we do not actually enable depth test/write for the triangle
m_ds = m_r->newRenderBuffer(QRhiRenderBuffer::DepthStencil,
- QSize(), // no need to set the size yet
+ QSize(), // no need to set the size here, due to UsedWithSwapChainOnly
sampleCount,
QRhiRenderBuffer::UsedWithSwapChainOnly);
m_sc->setWindow(this);
@@ -339,16 +344,12 @@ void Window::releaseResources()
void Window::resizeSwapChain()
{
- const QSize outputSize = m_sc->surfacePixelSize();
-
- m_ds->setPixelSize(outputSize);
- m_ds->build(); // == m_ds->release(); m_ds->build();
-
- m_hasSwapChain = m_sc->buildOrResize();
+ m_hasSwapChain = m_sc->buildOrResize(); // also handles m_ds
m_frameCount = 0;
m_timer.restart();
+ const QSize outputSize = m_sc->currentPixelSize();
m_proj = m_r->clipSpaceCorrMatrix();
m_proj.perspective(45.0f, outputSize.width() / (float) outputSize.height(), 0.01f, 1000.0f);
m_proj.translate(0, 0, -4);
@@ -439,6 +440,8 @@ int main(int argc, char **argv)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
+ QLoggingCategory::setFilterRules(QLatin1String("qt.rhi.*=true"));
+
// Defaults.
#if defined(Q_OS_WIN)
graphicsApi = D3D11;
@@ -477,6 +480,9 @@ int main(int argc, char **argv)
QCommandLineOption swOption(QLatin1String("software"), QLatin1String("Prefer a software renderer when choosing the adapter. "
"Only applicable with some APIs and platforms."));
cmdLineParser.addOption(swOption);
+ // Allow testing having a semi-transparent window.
+ QCommandLineOption transparentOption(QLatin1String("transparent"), QLatin1String("Make background transparent"));
+ cmdLineParser.addOption(transparentOption);
cmdLineParser.process(app);
if (cmdLineParser.isSet(nullOption))
@@ -493,6 +499,11 @@ int main(int argc, char **argv)
qDebug("Selected graphics API is %s", qPrintable(graphicsApiName()));
qDebug("This is a multi-api example, use command line arguments to override:\n%s", qPrintable(cmdLineParser.helpText()));
+ if (cmdLineParser.isSet(transparentOption)) {
+ transparentBackground = true;
+ scFlags |= QRhiSwapChain::SurfaceHasPreMulAlpha;
+ }
+
#ifdef EXAMPLEFW_PREINIT
void preInit();
preInit();
@@ -508,6 +519,9 @@ int main(int argc, char **argv)
fmt.setSwapInterval(0);
if (scFlags.testFlag(QRhiSwapChain::sRGB))
fmt.setColorSpace(QSurfaceFormat::sRGBColorSpace);
+ // Exception: The alpha size is not necessarily OpenGL specific.
+ if (transparentBackground)
+ fmt.setAlphaBufferSize(8);
QSurfaceFormat::setDefaultFormat(fmt);
// Vulkan setup.
diff --git a/tests/manual/rhi/texuploads/texuploads.cpp b/tests/manual/rhi/texuploads/texuploads.cpp
index dc20ffb1fc..4c10a6b965 100644
--- a/tests/manual/rhi/texuploads/texuploads.cpp
+++ b/tests/manual/rhi/texuploads/texuploads.cpp
@@ -68,6 +68,8 @@ struct {
QRhiTexture *newTex = nullptr;
QRhiTexture *importedTex = nullptr;
int testStage = 0;
+
+ QRhiShaderResourceBinding bindings[2];
} d;
void Window::customInit()
@@ -100,10 +102,10 @@ void Window::customInit()
d.srb = m_r->newShaderResourceBindings();
d.releasePool << d.srb;
- d.srb->setBindings({
- QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf),
- QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler)
- });
+
+ d.bindings[0] = QRhiShaderResourceBinding::uniformBuffer(0, QRhiShaderResourceBinding::VertexStage | QRhiShaderResourceBinding::FragmentStage, d.ubuf);
+ d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.tex, d.sampler);
+ d.srb->setBindings(d.bindings, d.bindings + 2);
d.srb->build();
d.ps = m_r->newGraphicsPipeline();
@@ -211,9 +213,8 @@ void Window::customRender()
u->copyTexture(d.newTex, d.tex, desc);
// Now replace d.tex with d.newTex as the shader resource.
- auto bindings = d.srb->bindings();
- bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler);
- d.srb->setBindings(bindings);
+ d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler);
+ d.srb->setBindings(d.bindings, d.bindings + 2);
// "rebuild", whatever that means for a given backend. This srb is
// already live as the ps in the setGraphicsPipeline references it,
// but that's fine. Changes will be picked up automatically.
@@ -259,9 +260,8 @@ void Window::customRender()
// underneath (owned by d.tex)
// switch to showing d.importedTex
- auto bindings = d.srb->bindings();
- bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.importedTex, d.sampler);
- d.srb->setBindings(bindings);
+ d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.importedTex, d.sampler);
+ d.srb->setBindings(d.bindings, d.bindings + 2);
d.srb->build();
} else {
qWarning("Accessing native texture object is not supported");
@@ -270,9 +270,8 @@ void Window::customRender()
// Exercise uploading uncompressed data without a QImage.
if (d.testStage == 7) {
- auto bindings = d.srb->bindings();
- bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler);
- d.srb->setBindings(bindings);
+ d.bindings[1] = QRhiShaderResourceBinding::sampledTexture(1, QRhiShaderResourceBinding::FragmentStage, d.newTex, d.sampler);
+ d.srb->setBindings(d.bindings, d.bindings + 2);
d.srb->build();
const QSize sz(221, 139);
@@ -296,7 +295,7 @@ void Window::customRender()
QRhiCommandBuffer *cb = m_sc->currentFrameCommandBuffer();
const QSize outputSizeInPixels = m_sc->currentPixelSize();
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->setGraphicsPipeline(d.ps);
cb->setViewport({ 0, 0, float(outputSizeInPixels.width()), float(outputSizeInPixels.height()) });
diff --git a/tests/manual/rhi/triquadcube/trianglerenderer.cpp b/tests/manual/rhi/triquadcube/trianglerenderer.cpp
index 0980acca49..5d932aea52 100644
--- a/tests/manual/rhi/triquadcube/trianglerenderer.cpp
+++ b/tests/manual/rhi/triquadcube/trianglerenderer.cpp
@@ -94,11 +94,11 @@ void TriangleRenderer::initResources(QRhiRenderPassDescriptor *rp)
QRhiGraphicsPipeline::TargetBlend premulAlphaBlend; // convenient defaults...
premulAlphaBlend.enable = true;
- QVector<QRhiGraphicsPipeline::TargetBlend> rtblends;
+ QVarLengthArray<QRhiGraphicsPipeline::TargetBlend, 4> rtblends;
for (int i = 0; i < m_colorAttCount; ++i)
rtblends << premulAlphaBlend;
- m_ps->setTargetBlends(rtblends);
+ m_ps->setTargetBlends(rtblends.cbegin(), rtblends.cend());
m_ps->setSampleCount(m_sampleCount);
if (m_depthWrite) { // TriangleOnCube may want to exercise this
diff --git a/tests/manual/rhi/triquadcube/triquadcube.cpp b/tests/manual/rhi/triquadcube/triquadcube.cpp
index 76dbe558ab..252ec63e21 100644
--- a/tests/manual/rhi/triquadcube/triquadcube.cpp
+++ b/tests/manual/rhi/triquadcube/triquadcube.cpp
@@ -230,7 +230,7 @@ void Window::customRender()
if (!d.onScreenOnly)
d.liveTexCubeRenderer.queueResourceUpdates(u);
- cb->beginPass(m_sc->currentFrameRenderTarget(), QColor::fromRgbF(0.4f, 0.7f, 0.0f, 1.0f), { 1.0f, 0 }, u);
+ cb->beginPass(m_sc->currentFrameRenderTarget(), m_clearColor, { 1.0f, 0 }, u);
cb->debugMarkBegin(QByteArrayLiteral("Triangle"));
d.triRenderer.queueDraw(cb, outputSize);
cb->debugMarkEnd();