diff options
Diffstat (limited to 'tests')
367 files changed, 10957 insertions, 3525 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 1dc26bbde9..6fb4b6cb2a 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -68,6 +68,7 @@ if(TARGET Qt::Qml) If(NOT ANDROID) # QML only project cannot run on Android with C++ enty point _qt_internal_test_expect_pass(qmlquery) endif() + _qt_internal_test_expect_fail(test_internal_singleton) endif() if(TARGET Qt::Quick) diff --git a/tests/auto/cmake/test_internal_singleton/CMakeLists.txt b/tests/auto/cmake/test_internal_singleton/CMakeLists.txt new file mode 100644 index 0000000000..f1db46a0f9 --- /dev/null +++ b/tests/auto/cmake/test_internal_singleton/CMakeLists.txt @@ -0,0 +1,23 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + + +cmake_minimum_required(VERSION 3.19) + +project(test_internal_singleton) + +find_package(Qt6 REQUIRED COMPONENTS Qml) + +qt_standard_project_setup() + +set_source_files_properties(Test.qml PROPERTIES + QT_QML_SINGLETON_TYPE TRUE + QT_QML_INTERNAL_TYPE TRUE +) + +qt_add_qml_module(test_internal_singleton + URI Controls + VERSION 1.0 + QML_FILES + Test.qml +) diff --git a/tests/auto/cmake/test_internal_singleton/Test.qml b/tests/auto/cmake/test_internal_singleton/Test.qml new file mode 100644 index 0000000000..a2eb03bd4e --- /dev/null +++ b/tests/auto/cmake/test_internal_singleton/Test.qml @@ -0,0 +1,4 @@ +pragma singleton +import QtQml + +QtObject {} diff --git a/tests/auto/particles/qquickage/tst_qquickage.cpp b/tests/auto/particles/qquickage/tst_qquickage.cpp index b0a41afb45..21b79d8921 100644 --- a/tests/auto/particles/qquickage/tst_qquickage.cpp +++ b/tests/auto/particles/qquickage/tst_qquickage.cpp @@ -35,7 +35,7 @@ void tst_qquickage::test_kill() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -60,7 +60,7 @@ void tst_qquickage::test_jump() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -86,7 +86,7 @@ void tst_qquickage::test_onceOff() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -112,7 +112,7 @@ void tst_qquickage::test_sustained() //TODO: Ensure some particles have lived to 0.4s point despite unified timer //Can't verify size, because particles never die. It will constantly grow. - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp b/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp index 63f77f3b30..8b2cb417cb 100644 --- a/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp +++ b/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp @@ -32,7 +32,7 @@ void tst_qquickangleddirection::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp b/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp index 9e1a95863d..df427600c5 100644 --- a/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp +++ b/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp @@ -31,7 +31,7 @@ void tst_qquickcumulativedirection::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickcustomaffector/tst_qquickcustomaffector.cpp b/tests/auto/particles/qquickcustomaffector/tst_qquickcustomaffector.cpp index c38bc1cdd8..e10885cf84 100644 --- a/tests/auto/particles/qquickcustomaffector/tst_qquickcustomaffector.cpp +++ b/tests/auto/particles/qquickcustomaffector/tst_qquickcustomaffector.cpp @@ -33,7 +33,7 @@ void tst_qquickcustomaffector::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused //in CI the whole simulation often happens at once, so dead particles end up missing out @@ -66,7 +66,7 @@ void tst_qquickcustomaffector::test_move() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused if (!d->stillAlive(system)) diff --git a/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp b/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp index 9912e54eec..98139e8271 100644 --- a/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp +++ b/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp @@ -48,7 +48,7 @@ void tst_qquickellipseextruder::test_basic() //Filled QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -65,7 +65,7 @@ void tst_qquickellipseextruder::test_basic() //Just border QCOMPARE(system->groupData[1]->size(), 500); - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp b/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp index 94e2b67ac2..edc3770f85 100644 --- a/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp +++ b/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp @@ -33,7 +33,7 @@ void tst_qquickfriction::test_basic() //Default is just slowed a little QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -50,7 +50,7 @@ void tst_qquickfriction::test_basic() //Nondefault comes to a complete stop within the first half of its life QCOMPARE(system->groupData[1]->size(), 500); - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused @@ -77,7 +77,7 @@ void tst_qquickfriction::test_threshold() //Velocity capped at 50, but it might take a frame or two to get there QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1.0f) continue; //Particle data unused if (myFuzzyGEQ(d->t, ((qreal)system->timeInt/1000.0) - 0.1)) diff --git a/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp b/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp index 772eabba55..d95bb19827 100644 --- a/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp +++ b/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp @@ -32,7 +32,7 @@ void tst_qquickgravity::test_basic() QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); float mag = 707.10678f; - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1 || !d->stillAlive(system)) continue; //Particle data unused or dead diff --git a/tests/auto/particles/qquickgroupgoal/tst_qquickgroupgoal.cpp b/tests/auto/particles/qquickgroupgoal/tst_qquickgroupgoal.cpp index 6d91ed149c..87a0c9f21e 100644 --- a/tests/auto/particles/qquickgroupgoal/tst_qquickgroupgoal.cpp +++ b/tests/auto/particles/qquickgroupgoal/tst_qquickgroupgoal.cpp @@ -32,7 +32,7 @@ void tst_qquickgroupgoal::test_instantTransition() ensureAnimTime(600, system->m_animation); QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp b/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp index 87335172ce..f4b6794cc2 100644 --- a/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp +++ b/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp @@ -45,7 +45,7 @@ void tst_qquickimageparticle::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -89,7 +89,7 @@ void tst_qquickimageparticle::test_colored() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -133,7 +133,7 @@ void tst_qquickimageparticle::test_colorVariance() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -178,7 +178,7 @@ void tst_qquickimageparticle::test_deformed() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -217,46 +217,50 @@ void tst_qquickimageparticle::test_deformed() void tst_qquickimageparticle::test_tabled() { - QQuickView* view = createView(testFileUrl("tabled.qml"), 600); - QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system"); - ensureAnimTime(600, system->m_animation); + #if defined(Q_OS_LINUX) + QSKIP("Crashing on Ubuntu 22.04: QTBUG-107707"); + #else + QQuickView* view = createView(testFileUrl("tabled.qml"), 600); + QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system"); + ensureAnimTime(600, system->m_animation); - QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { - if (d->t == -1) - continue; //Particle data unused + QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { + if (d->t == -1) + continue; //Particle data unused - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)255); - QCOMPARE(d->color.g, (uchar)255); - QCOMPARE(d->color.b, (uchar)255); - QCOMPARE(d->color.a, (uchar)255); - QCOMPARE(d->xx, 1.0f); - QCOMPARE(d->xy, 0.0f); - QCOMPARE(d->yy, 1.0f); - QCOMPARE(d->yx, 0.0f); - QCOMPARE(d->rotation, 0.0f); - QCOMPARE(d->rotationVelocity, 0.0f); - QCOMPARE(d->autoRotate, (uchar)0); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 1.0f); - QCOMPARE(d->animHeight, 1.0f); - QCOMPARE(d->frameDuration, 1.0f); - QCOMPARE(d->frameCount, 1.0f); - QCOMPARE(d->animT, -1.0f); - //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test - } - delete view; + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)255); + QCOMPARE(d->color.g, (uchar)255); + QCOMPARE(d->color.b, (uchar)255); + QCOMPARE(d->color.a, (uchar)255); + QCOMPARE(d->xx, 1.0f); + QCOMPARE(d->xy, 0.0f); + QCOMPARE(d->yy, 1.0f); + QCOMPARE(d->yx, 0.0f); + QCOMPARE(d->rotation, 0.0f); + QCOMPARE(d->rotationVelocity, 0.0f); + QCOMPARE(d->autoRotate, (uchar)0); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 1.0f); + QCOMPARE(d->animHeight, 1.0f); + QCOMPARE(d->frameDuration, 1.0f); + QCOMPARE(d->frameCount, 1.0f); + QCOMPARE(d->animT, -1.0f); + //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test + } + delete view; + #endif } @@ -267,7 +271,7 @@ void tst_qquickimageparticle::test_sprite() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp b/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp index 24b87bad41..8e82f91a92 100644 --- a/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp +++ b/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp @@ -38,7 +38,7 @@ void tst_qquickitemparticle::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -119,7 +119,7 @@ void tst_qquickitemparticle::test_noLeakWhenDeleted() QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system"); ensureAnimTime(100, system->m_animation); - auto particles = qAsConst(system->groupData[0]->data); + auto particles = std::as_const(system->groupData[0]->data); QVERIFY(!particles.isEmpty()); QQuickParticleData* firstParticleData = particles.first(); diff --git a/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp b/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp index 81c7462f54..98e300d90a 100644 --- a/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp +++ b/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp @@ -31,7 +31,7 @@ void tst_qquicklineextruder::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -47,7 +47,7 @@ void tst_qquicklineextruder::test_basic() } QCOMPARE(system->groupData[1]->size(), 500); - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp b/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp index faa3d0732a..6c4bb44a07 100644 --- a/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp +++ b/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp @@ -31,7 +31,7 @@ void tst_qquickmaskextruder::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp b/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp index 0a6ba45be7..75c2e72c34 100644 --- a/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp +++ b/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp @@ -32,7 +32,7 @@ void tst_qquickparticlegroup::test_instantTransition() //A frame or two worth of particles will be missed, the transition doesn't take effect on the frame it's spawned (QTBUG-21781) QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp index 0a22f86fc3..cadeac66f5 100644 --- a/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp +++ b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp @@ -33,7 +33,7 @@ void tst_qquickparticlesystem::test_basic() QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); int stillAlive = 0; - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp index 04bd52bee0..e5822c1b88 100644 --- a/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp +++ b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp @@ -31,7 +31,7 @@ void tst_qquickpointattractor::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp b/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp index 441e2663b1..8c39bad812 100644 --- a/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp +++ b/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp @@ -31,7 +31,7 @@ void tst_qquickpointdirection::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp b/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp index c40d57704d..99cbeba35a 100644 --- a/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp +++ b/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp @@ -31,7 +31,7 @@ void tst_qquickrectangleextruder::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -50,7 +50,7 @@ void tst_qquickrectangleextruder::test_basic() } QCOMPARE(system->groupData[1]->size(), 500); - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickspritegoal/tst_qquickspritegoal.cpp b/tests/auto/particles/qquickspritegoal/tst_qquickspritegoal.cpp index c349456790..4dd965aff7 100644 --- a/tests/auto/particles/qquickspritegoal/tst_qquickspritegoal.cpp +++ b/tests/auto/particles/qquickspritegoal/tst_qquickspritegoal.cpp @@ -31,7 +31,7 @@ void tst_qquickspritegoal::test_instantTransition() ensureAnimTime(600, system->m_animation); QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp b/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp index 013612d277..6e695440a0 100644 --- a/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp +++ b/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp @@ -31,7 +31,7 @@ void tst_qquicktargetdirection::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp b/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp index ef5a513b2f..230c666c8d 100644 --- a/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp +++ b/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp @@ -31,7 +31,7 @@ void tst_qquicktrailemitter::test_basic() ensureAnimTime(600, system->m_animation); QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -48,7 +48,7 @@ void tst_qquicktrailemitter::test_basic() } QVERIFY(extremelyFuzzyCompare(system->groupData[1]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp b/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp index 246dba20fe..d90dd17199 100644 --- a/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp +++ b/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp @@ -33,7 +33,7 @@ void tst_qquickturbulence::test_basic() //Note that the noise image built-in provides the 'randomness', so this test should be stable so long as it and the size //of the Turbulence item remain the same QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 500, 10)); - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/particles/qquickwander/tst_qquickwander.cpp b/tests/auto/particles/qquickwander/tst_qquickwander.cpp index 6f056f5760..71a8ee1f97 100644 --- a/tests/auto/particles/qquickwander/tst_qquickwander.cpp +++ b/tests/auto/particles/qquickwander/tst_qquickwander.cpp @@ -35,7 +35,7 @@ void tst_qquickwander::test_basic() //the 500 was randomly changed from 0.0 in velocity bool vxChanged = false; bool vyChanged = false; - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/auto/qml/CMakeLists.txt b/tests/auto/qml/CMakeLists.txt index 29a1a2b011..a2a90a413a 100644 --- a/tests/auto/qml/CMakeLists.txt +++ b/tests/auto/qml/CMakeLists.txt @@ -47,7 +47,11 @@ endif() add_subdirectory(qqmlmetatype) if(TARGET Qt::Quick) add_subdirectory(qmltc_manual) - add_subdirectory(qmltc) + # QML Type Compiler tests cannot be run on webOS due to missing support for multiple + # consecutive window creation from a single QtWayland client + if(NOT WEBOS) + add_subdirectory(qmltc) + endif() # This test always creates static plugins. To avoid linker command line # ordering issues, we need at least CMake 3.21 and we cannot include the # test if qmlimportscanner is being built as part of the main project. diff --git a/tests/auto/qml/animation/qanimationgroupjob/tst_qanimationgroupjob.cpp b/tests/auto/qml/animation/qanimationgroupjob/tst_qanimationgroupjob.cpp index 0a17d75387..cac9581803 100644 --- a/tests/auto/qml/animation/qanimationgroupjob/tst_qanimationgroupjob.cpp +++ b/tests/auto/qml/animation/qanimationgroupjob/tst_qanimationgroupjob.cpp @@ -81,7 +81,7 @@ public: int count() { - return states.count(); + return states.size(); } QList<QAbstractAnimationJob::State> states; diff --git a/tests/auto/qml/animation/qparallelanimationgroupjob/tst_qparallelanimationgroupjob.cpp b/tests/auto/qml/animation/qparallelanimationgroupjob/tst_qparallelanimationgroupjob.cpp index f8665eac0a..a11ae75033 100644 --- a/tests/auto/qml/animation/qparallelanimationgroupjob/tst_qparallelanimationgroupjob.cpp +++ b/tests/auto/qml/animation/qparallelanimationgroupjob/tst_qparallelanimationgroupjob.cpp @@ -99,7 +99,7 @@ public: } void clear() { states.clear(); } - int count() { return states.count(); } + int count() { return states.size(); } QList<QAbstractAnimationJob::State> states; }; diff --git a/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp b/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp index 03d207e49b..cc67df420c 100644 --- a/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp +++ b/tests/auto/qml/animation/qsequentialanimationgroupjob/tst_qsequentialanimationgroupjob.cpp @@ -116,7 +116,7 @@ public: } void clear() { states.clear(); } - int count() const { return states.count(); } + int count() const { return states.size(); } QList<QAbstractAnimationJob::State> states; bool beEvil = false; @@ -562,8 +562,8 @@ typedef QList<QAbstractAnimationJob::State> StateList; static bool compareStates(const StateChangeListener& spy, const StateList &expectedStates) { bool equals = true; - for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) { - if (i >= spy.count() || i >= expectedStates.count()) { + for (int i = 0; i < qMax(expectedStates.size(), spy.count()); ++i) { + if (i >= spy.count() || i >= expectedStates.size()) { equals = false; break; } @@ -577,8 +577,8 @@ static bool compareStates(const StateChangeListener& spy, const StateList &expec if (!equals) { const char *stateStrings[] = {"Stopped", "Paused", "Running"}; QString e,a; - for (int i = 0; i < qMax(expectedStates.count(), spy.count()); ++i) { - if (i < expectedStates.count()) { + for (int i = 0; i < qMax(expectedStates.size(), spy.count()); ++i) { + if (i < expectedStates.size()) { int exp = int(expectedStates.at(i)); if (!e.isEmpty()) e += QLatin1String(", "); @@ -596,7 +596,7 @@ static bool compareStates(const StateChangeListener& spy, const StateList &expec } } - qDebug().noquote() << "\nexpected (count == " << expectedStates.count() << "): " << e + qDebug().noquote() << "\nexpected (count == " << expectedStates.size() << "): " << e << "\nactual (count == " << spy.count() << "): " << a << "\n"; } return equals; diff --git a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp index 1efc48e07d..81d8694406 100644 --- a/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp +++ b/tests/auto/qml/debugger/qpacketprotocol/tst_qpacketprotocol.cpp @@ -45,8 +45,8 @@ void tst_QPacketProtocol::init() m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); - QVERIFY(clientSpy.count() > 0 || clientSpy.wait()); - QVERIFY(serverSpy.count() > 0 || serverSpy.wait()); + QVERIFY(clientSpy.size() > 0 || clientSpy.wait()); + QVERIFY(serverSpy.size() > 0 || serverSpy.wait()); m_serverConn = m_server->nextPendingConnection(); } diff --git a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp index 5a8fce6424..ab599e9a23 100644 --- a/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp +++ b/tests/auto/qml/debugger/qqmldebuggingenabler/qqmldebuggingenabler/tst_qqmldebuggingenabler.cpp @@ -150,7 +150,7 @@ void tst_QQmlDebuggingEnabler::custom() m_clients = QQmlDebugTest::createOtherClients(m_connection); m_connection->connectToHost("127.0.0.1", m_process->debugPort()); QVERIFY(m_connection->waitForConnected()); - for (QQmlDebugClient *client : qAsConst(m_clients)) + for (QQmlDebugClient *client : std::as_const(m_clients)) QCOMPARE(client->state(), (services.isEmpty() || services.contains(client->name())) ? QQmlDebugClient::Enabled : QQmlDebugClient::Unavailable); } diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp index 9f51b65c7f..ac607df0a0 100644 --- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp +++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp @@ -853,15 +853,15 @@ void tst_QQmlDebugJS::evaluateInContext() QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); - QVERIFY(engineClient->engines().count()); + QVERIFY(engineClient->engines().size()); engineClient->queryRootContexts(engineClient->engines()[0], &success); QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); auto contexts = engineClient->rootContext().contexts; - QCOMPARE(contexts.count(), 1); + QCOMPARE(contexts.size(), 1); auto objects = contexts[0].objects; - QCOMPARE(objects.count(), 1); + QCOMPARE(objects.size(), 1); engineClient->queryObjectRecursive(objects[0], &success); QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(engineClient.data(), SIGNAL(result()))); @@ -874,7 +874,7 @@ void tst_QQmlDebugJS::evaluateInContext() QTRY_COMPARE(responseBody(m_client).value("value").toInt(), 20); auto childObjects = object.children; - QVERIFY(childObjects.count() > 0); // QQmlComponentAttached is also in there + QVERIFY(childObjects.size() > 0); // QQmlComponentAttached is also in there QCOMPARE(childObjects[0].className, QString::fromLatin1("Item")); // "b" accessible in context of surrounding (child) object @@ -1065,7 +1065,7 @@ void tst_QQmlDebugJS::letConstLocals() for (const auto prop : props) { const auto propObj = prop.toObject(); QString name = propObj.value(QStringLiteral("name")).toString(); - QVERIFY(name.length() == 1); + QVERIFY(name.size() == 1); auto i = expectedMembers.indexOf(name.at(0)); QVERIFY(i != -1); expectedMembers.remove(i, 1); diff --git a/tests/auto/qml/debugger/qqmldebugtranslationservice/tst_qqmldebugtranslationservice.cpp b/tests/auto/qml/debugger/qqmldebugtranslationservice/tst_qqmldebugtranslationservice.cpp index 48396aefea..0e0340b672 100644 --- a/tests/auto/qml/debugger/qqmldebugtranslationservice/tst_qqmldebugtranslationservice.cpp +++ b/tests/auto/qml/debugger/qqmldebugtranslationservice/tst_qqmldebugtranslationservice.cpp @@ -63,7 +63,7 @@ private slots: changeLanguage("ru"); auto translationIssues = getTranslationIssues(); - QCOMPARE(translationIssues.length(), getTranslatableTextOccurrences().count()); + QCOMPARE(translationIssues.size(), getTranslatableTextOccurrences().size()); QCOMPARE(translationIssues.at(0).language, "ru-Cyrl-RU ru-RU ru"); } @@ -73,18 +73,18 @@ private slots: auto translationIssues = getTranslationIssues(); - QCOMPARE(translationIssues.length(), 3); + QCOMPARE(translationIssues.size(), 3); QCOMPARE(translationIssues.at(0).language, "fr-Latn-FR fr-FR fr"); } void verifyCorrectNumberOfTranslatableTextOccurrences() { - QCOMPARE(getTranslatableTextOccurrences().length(), 5); + QCOMPARE(getTranslatableTextOccurrences().size(), 5); } void verifyCorrectNumberOfStates() { - QCOMPARE(getStates().length(), 2); + QCOMPARE(getStates().size(), 2); } void getElideWarnings() @@ -128,9 +128,9 @@ private slots: { QVector<QmlState> stateList = getStates(); - QCOMPARE(stateList.length(), 2); + QCOMPARE(stateList.size(), 2); - for (int i = 0; i < stateList.count(); i++) { + for (int i = 0; i < stateList.size(); i++) { auto stateName = stateList.at(i).name; QVersionedPacket<QQmlDebugConnector> packet; sendMessageToService(createChangeStateRequest(packet, stateName)); diff --git a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp index 78d80405f4..890f4eeef6 100644 --- a/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebuginspectorintegrationtest/tst_qqmlenginedebuginspectorintegration.cpp @@ -55,7 +55,7 @@ QQmlEngineDebugObjectReference tst_QQmlEngineDebugInspectorIntegration::findRoot if (!QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))) return QQmlEngineDebugObjectReference(); - int count = m_engineDebugClient->rootContext().contexts.count(); + int count = m_engineDebugClient->rootContext().contexts.size(); m_engineDebugClient->queryObject( m_engineDebugClient->rootContext().contexts[count - 1].objects[0], &success); if (!QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))) @@ -156,7 +156,7 @@ void tst_QQmlEngineDebugInspectorIntegration::createObject() QQmlEngineDebugObjectReference rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 2); + QCOMPARE(rootObject.children.size(), 2); int requestId = m_inspectorClient->createObject( qml, rootObject.debugId, QStringList() << QLatin1String("import QtQuick 2.0"), @@ -166,7 +166,7 @@ void tst_QQmlEngineDebugInspectorIntegration::createObject() rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 3); + QCOMPARE(rootObject.children.size(), 3); QCOMPARE(rootObject.children[2].idString, QLatin1String("xxxyxxx")); } @@ -177,7 +177,7 @@ void tst_QQmlEngineDebugInspectorIntegration::moveObject() QCOMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled); QQmlEngineDebugObjectReference rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 2); + QCOMPARE(rootObject.children.size(), 2); int childId = rootObject.children[0].debugId; int requestId = m_inspectorClient->moveObject(childId, rootObject.children[1].debugId); @@ -186,12 +186,12 @@ void tst_QQmlEngineDebugInspectorIntegration::moveObject() rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 1); + QCOMPARE(rootObject.children.size(), 1); bool success = false; m_engineDebugClient->queryObject(rootObject.children[0], &success); QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); - QCOMPARE(m_engineDebugClient->object().children.length(), 1); + QCOMPARE(m_engineDebugClient->object().children.size(), 1); QCOMPARE(m_engineDebugClient->object().children[0].debugId, childId); } @@ -202,7 +202,7 @@ void tst_QQmlEngineDebugInspectorIntegration::destroyObject() QCOMPARE(m_inspectorClient->state(), QQmlDebugClient::Enabled); QQmlEngineDebugObjectReference rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 2); + QCOMPARE(rootObject.children.size(), 2); int requestId = m_inspectorClient->destroyObject(rootObject.children[0].debugId); QTRY_COMPARE(m_recipient->lastResponseId, requestId); @@ -210,12 +210,12 @@ void tst_QQmlEngineDebugInspectorIntegration::destroyObject() rootObject = findRootObject(); QVERIFY(rootObject.debugId != -1); - QCOMPARE(rootObject.children.length(), 1); + QCOMPARE(rootObject.children.size(), 1); bool success = false; m_engineDebugClient->queryObject(rootObject.children[0], &success); QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(m_engineDebugClient, SIGNAL(result()))); - QCOMPARE(m_engineDebugClient->object().children.length(), 0); + QCOMPARE(m_engineDebugClient->object().children.size(), 0); } QTEST_MAIN(tst_QQmlEngineDebugInspectorIntegration) diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/data/fetchValueType.qml b/tests/auto/qml/debugger/qqmlenginedebugservice/data/fetchValueType.qml new file mode 100644 index 0000000000..ea0c3ff8c0 --- /dev/null +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/data/fetchValueType.qml @@ -0,0 +1,9 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick +import QtQuick.Controls + +Item { + Button {} +} diff --git a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp index 49fe5948d5..467ebda91b 100644 --- a/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp +++ b/tests/auto/qml/debugger/qqmlenginedebugservice/tst_qqmlenginedebugservice.cpp @@ -21,6 +21,7 @@ #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlproperty.h> #include <QtQml/qqmlincubator.h> +#include <QtQml/qqmlapplicationengine.h> #include <QtQuick/qquickitem.h> #include <QtNetwork/qhostaddress.h> @@ -161,6 +162,7 @@ private slots: void asynchronousCreate(); void invalidContexts(); void createObjectOnDestruction(); + void fetchValueType(); }; QQmlEngineDebugObjectReference tst_QQmlEngineDebugService::findRootObject( @@ -171,14 +173,14 @@ QQmlEngineDebugObjectReference tst_QQmlEngineDebugService::findRootObject( QVERIFYOBJECT(success); QVERIFYOBJECT(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QVERIFYOBJECT(m_dbg->engines().count()); + QVERIFYOBJECT(m_dbg->engines().size()); m_dbg->queryRootContexts(m_dbg->engines()[0], &success); QVERIFYOBJECT(success); QVERIFYOBJECT(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QVERIFYOBJECT(m_dbg->rootContext().contexts.count()); - QVERIFYOBJECT(m_dbg->rootContext().contexts.last().objects.count()); - int count = m_dbg->rootContext().contexts.count(); + QVERIFYOBJECT(m_dbg->rootContext().contexts.size()); + QVERIFYOBJECT(m_dbg->rootContext().contexts.last().objects.size()); + int count = m_dbg->rootContext().contexts.size(); recursive ? m_dbg->queryObjectRecursive(m_dbg->rootContext().contexts[count - context - 1].objects[0], &success) : m_dbg->queryObject(m_dbg->rootContext().contexts[count - context - 1].objects[0], &success); @@ -210,7 +212,7 @@ void tst_QQmlEngineDebugService::recursiveObjectTest( qmlContext(o))); const QObjectList &children = o->children(); - for (int i=0; i<children.count(); i++) { + for (int i=0; i<children.size(); i++) { QObject *child = children[i]; if (!qmlContext(child)) continue; @@ -235,7 +237,7 @@ void tst_QQmlEngineDebugService::recursiveObjectTest( QCOMPARE(p.objectDebugId, QQmlDebugService::idForObject(o)); // signal properties are fake - they are generated from QQmlAbstractBoundSignal children - if (p.name.startsWith("on") && p.name.length() > 2 && p.name[2].isUpper()) { + if (p.name.startsWith("on") && p.name.size() > 2 && p.name[2].isUpper()) { QString signal = p.value.toString(); QQmlBoundSignalExpression *expr = QQmlPropertyPrivate::signalExpression(QQmlProperty(o, p.name)); QVERIFY(expr && expr->expression() == signal); @@ -299,7 +301,7 @@ void tst_QQmlEngineDebugService::getContexts() QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); QList<QQmlEngineDebugEngineReference> engines = m_dbg->engines(); - QCOMPARE(engines.count(), 1); + QCOMPARE(engines.size(), 1); m_dbg->queryRootContexts(engines.first(), &success); QVERIFY(success); @@ -438,7 +440,7 @@ void tst_QQmlEngineDebugService::watch_property() m_rootItem->setProperty("width", origWidth*2); QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); m_dbg->removeWatch(id, &success); QVERIFY(success); @@ -448,7 +450,7 @@ void tst_QQmlEngineDebugService::watch_property() // restore original value and verify spy doesn't get additional signal since watch has been removed m_rootItem->setProperty("width", origWidth); QTest::qWait(100); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).at(0).value<QByteArray>(), prop.name.toUtf8()); QCOMPARE(spy.at(0).at(1).value<QVariant>(), QVariant::fromValue(origWidth*2)); @@ -486,11 +488,11 @@ void tst_QQmlEngineDebugService::watch_object() m_rootItem->setProperty("height", origHeight*2); QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(valueChanged(QByteArray,QVariant)))); - QVERIFY(spy.count() > 0); + QVERIFY(spy.size() > 0); int newWidth = -1; int newHeight = -1; - for (int i=0; i<spy.count(); i++) { + for (int i=0; i<spy.size(); i++) { const QVariantList &values = spy[i]; if (values[0].value<QByteArray>() == "width") newWidth = values[1].value<QVariant>().toInt(); @@ -509,7 +511,7 @@ void tst_QQmlEngineDebugService::watch_object() m_rootItem->setProperty("width", origWidth); m_rootItem->setProperty("height", origHeight); QTest::qWait(100); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QCOMPARE(newWidth, origWidth * 2); QCOMPARE(newHeight, origHeight * 2); @@ -562,10 +564,10 @@ void tst_QQmlEngineDebugService::watch_expression() // restore original value and verify spy doesn't get a signal since watch has been removed m_rootItem->setProperty("width", origWidth); QTest::qWait(100); - QCOMPARE(spy.count(), incrementCount); + QCOMPARE(spy.size(), incrementCount); width = origWidth + increment; - for (int i=0; i<spy.count(); i++) { + for (int i=0; i<spy.size(); i++) { width += increment; QCOMPARE(spy.at(i).at(1).value<QVariant>().toInt(), width); } @@ -614,7 +616,7 @@ void tst_QQmlEngineDebugService::queryAvailableEngines() // TODO test multiple engines QList<QQmlEngineDebugEngineReference> engines = m_dbg->engines(); - QCOMPARE(engines.count(), 1); + QCOMPARE(engines.size(), 1); foreach (const QQmlEngineDebugEngineReference &e, engines) { QCOMPARE(e.debugId, QQmlDebugService::idForObject(m_engine)); @@ -628,7 +630,7 @@ void tst_QQmlEngineDebugService::queryRootContexts() m_dbg->queryAvailableEngines(&success); QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QVERIFY(m_dbg->engines().count()); + QVERIFY(m_dbg->engines().size()); const QQmlEngineDebugEngineReference engine = m_dbg->engines()[0]; QQmlEngineDebugClient *unconnected = new QQmlEngineDebugClient(nullptr); @@ -647,8 +649,8 @@ void tst_QQmlEngineDebugService::queryRootContexts() // root context query sends only root object data - it doesn't fill in // the children or property info - QCOMPARE(context.objects.count(), 0); - QCOMPARE(context.contexts.count(), 8); + QCOMPARE(context.objects.size(), 0); + QCOMPARE(context.contexts.size(), 8); QVERIFY(context.contexts[0].debugId >= 0); QCOMPARE(context.contexts[0].name, QString("tst_QQmlDebug_childContext")); } @@ -686,7 +688,7 @@ void tst_QQmlEngineDebugService::queryObject() if (recursive) { foreach (const QQmlEngineDebugObjectReference &child, obj.children) { QVERIFY(!child.className.isEmpty()); - QVERIFY(child.properties.count() > 0); + QVERIFY(child.properties.size() > 0); } QQmlEngineDebugObjectReference rect; @@ -708,7 +710,7 @@ void tst_QQmlEngineDebugService::queryObject() } else { foreach (const QQmlEngineDebugObjectReference &child, obj.children) { QVERIFY(!child.className.isEmpty()); - QCOMPARE(child.properties.count(), 0); + QCOMPARE(child.properties.size(), 0); } } } @@ -749,7 +751,7 @@ void tst_QQmlEngineDebugService::queryObjectsForLocation() QVERIFY(success); QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); - QCOMPARE(m_dbg->objects().count(), 1); + QCOMPARE(m_dbg->objects().size(), 1); QQmlEngineDebugObjectReference obj = m_dbg->objects().first(); QVERIFY(!obj.className.isEmpty()); @@ -765,7 +767,7 @@ void tst_QQmlEngineDebugService::queryObjectsForLocation() if (recursive) { foreach (const QQmlEngineDebugObjectReference &child, obj.children) { QVERIFY(!child.className.isEmpty()); - QVERIFY(child.properties.count() > 0); + QVERIFY(child.properties.size() > 0); } QQmlEngineDebugObjectReference rect; @@ -789,7 +791,7 @@ void tst_QQmlEngineDebugService::queryObjectsForLocation() } else { foreach (const QQmlEngineDebugObjectReference &child, obj.children) { QVERIFY(!child.className.isEmpty()); - QCOMPARE(child.properties.count(), 0); + QCOMPARE(child.properties.size(), 0); } } } @@ -1134,7 +1136,7 @@ void tst_QQmlEngineDebugService::setBindingInStates() QQmlEngineDebugObjectReference obj = findRootObject(sourceIndex); QVERIFY(!obj.className.isEmpty()); QVERIFY(obj.debugId != -1); - QVERIFY(obj.children.count() >= 2); + QVERIFY(obj.children.size() >= 2); bool success; // We are going to switch state a couple of times, we need to get rid of the transition before m_dbg->queryExpressionResult(obj.debugId,QString("transitions = []"), &success); @@ -1166,7 +1168,7 @@ void tst_QQmlEngineDebugService::setBindingInStates() // change the binding QQmlEngineDebugObjectReference state = obj.children[1]; QCOMPARE(state.className, QString("State")); - QVERIFY(state.children.count() > 0); + QVERIFY(state.children.size() > 0); QQmlEngineDebugObjectReference propertyChange = state.children[0]; QVERIFY(!propertyChange.className.isEmpty()); @@ -1250,12 +1252,12 @@ void tst_QQmlEngineDebugService::queryObjectTree() QQmlEngineDebugObjectReference obj = findRootObject(sourceIndex, true); QVERIFY(!obj.className.isEmpty()); QVERIFY(obj.debugId != -1); - QVERIFY(obj.children.count() >= 2); + QVERIFY(obj.children.size() >= 2); // check state QQmlEngineDebugObjectReference state = obj.children[1]; QCOMPARE(state.className, QString("State")); - QVERIFY(state.children.count() > 0); + QVERIFY(state.children.size() > 0); QQmlEngineDebugObjectReference propertyChange = state.children[0]; QVERIFY(!propertyChange.className.isEmpty()); @@ -1274,7 +1276,7 @@ void tst_QQmlEngineDebugService::queryObjectTree() QCOMPARE(transition.className, QString("Transition")); QCOMPARE(findProperty(transition.properties,"from").value.toString(), QString("*")); QCOMPARE(findProperty(transition.properties,"to").value, findProperty(state.properties,"name").value); - QVERIFY(transition.children.count() > 0); + QVERIFY(transition.children.size() > 0); QQmlEngineDebugObjectReference animation = transition.children[0]; QVERIFY(!animation.className.isEmpty()); @@ -1321,18 +1323,18 @@ void tst_QQmlEngineDebugService::asynchronousCreate() { void tst_QQmlEngineDebugService::invalidContexts() { getContexts(); - const int base = m_dbg->rootContext().contexts.count(); + const int base = m_dbg->rootContext().contexts.size(); QQmlContext context(m_engine); getContexts(); - QCOMPARE(m_dbg->rootContext().contexts.count(), base + 1); + QCOMPARE(m_dbg->rootContext().contexts.size(), base + 1); QQmlRefPointer<QQmlContextData> contextData = QQmlContextData::get(&context); contextData->invalidate(); getContexts(); - QCOMPARE(m_dbg->rootContext().contexts.count(), base); + QCOMPARE(m_dbg->rootContext().contexts.size(), base); QQmlRefPointer<QQmlContextData> rootData = QQmlContextData::get(m_engine->rootContext()); rootData->invalidate(); getContexts(); - QCOMPARE(m_dbg->rootContext().contexts.count(), 0); + QCOMPARE(m_dbg->rootContext().contexts.size(), 0); } void tst_QQmlEngineDebugService::createObjectOnDestruction() @@ -1351,11 +1353,31 @@ void tst_QQmlEngineDebugService::createObjectOnDestruction() "}", QUrl::fromLocalFile("x.qml")); QVERIFY(component.isReady()); QVERIFY(component.create()); - QTRY_COMPARE(spy.count(), 2); + QTRY_COMPARE(spy.size(), 2); } // Doesn't crash and doesn't give us another signal for the object created on destruction. QTest::qWait(500); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); +} + +void tst_QQmlEngineDebugService::fetchValueType() +{ + QQmlApplicationEngine engine; + engine.load(testFileUrl("fetchValueType.qml")); + + + bool success = false; + m_dbg->queryAvailableEngines(&success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + QVERIFY(m_dbg->engines().size() > 1); + + QQmlEngineDebugObjectReference object; + object.debugId = QQmlDebugService::idForObject(&engine); + m_dbg->queryObjectRecursive(object, &success); + QVERIFY(success); + QVERIFY(QQmlDebugTest::waitForSignal(m_dbg, SIGNAL(result()))); + } void tst_QQmlEngineDebugService::debuggerCrashOnAttach() { diff --git a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp index f389fb8f9f..897d8c8688 100644 --- a/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp +++ b/tests/auto/qml/debugger/qqmlinspector/tst_qqmlinspector.cpp @@ -64,7 +64,7 @@ void tst_QQmlInspector::checkAnimationSpeed(int targetMillisPerDegree) for (int i = 0; i < 10; ++i) { QString output = m_process->output(); - int position = output.length(); + int position = output.size(); do { QVERIFY(QQmlDebugTest::waitForSignal(m_process, SIGNAL(readyReadStandardOutput()))); output = m_process->output(); diff --git a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp index 90ababb67e..0c4fd568a9 100644 --- a/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp +++ b/tests/auto/qml/debugger/qqmlpreview/tst_qqmlpreview.cpp @@ -266,14 +266,14 @@ void tst_QQmlPreview::error() QCOMPARE(startQmlProcess("window.qml"), ConnectSuccess); QVERIFY(m_client); m_client->triggerLoad(testFileUrl("broken.qml")); - QTRY_COMPARE_WITH_TIMEOUT(m_serviceErrors.count(), 1, 10000); + QTRY_COMPARE_WITH_TIMEOUT(m_serviceErrors.size(), 1, 10000); QVERIFY(m_serviceErrors.first().contains("broken.qml:7 Expected token `}'")); } static float parseZoomFactor(const QString &output) { const QString prefix("zoom "); - const int start = output.lastIndexOf(prefix) + prefix.length(); + const int start = output.lastIndexOf(prefix) + prefix.size(); if (start < 0) return -1; const int end = output.indexOf('\n', start); diff --git a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp index ce92728ee4..53971d3e8b 100644 --- a/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp +++ b/tests/auto/qml/debugger/qqmlprofilerservice/tst_qqmlprofilerservice.cpp @@ -52,20 +52,20 @@ private: void QQmlProfilerTestClient::startTrace(qint64 timestamp, const QList<int> &engineIds) { types.append(QQmlProfilerEventType(Event, MaximumRangeType, StartTrace)); - asynchronousMessages.append(QQmlProfilerEvent(timestamp, types.length() - 1, + asynchronousMessages.append(QQmlProfilerEvent(timestamp, types.size() - 1, engineIds.toVector())); } void QQmlProfilerTestClient::endTrace(qint64 timestamp, const QList<int> &engineIds) { types.append(QQmlProfilerEventType(Event, MaximumRangeType, EndTrace)); - asynchronousMessages.append(QQmlProfilerEvent(timestamp, types.length() - 1, + asynchronousMessages.append(QQmlProfilerEvent(timestamp, types.size() - 1, engineIds.toVector())); } int QQmlProfilerTestClient::numLoadedEventTypes() const { - return types.length(); + return types.size(); } void QQmlProfilerTestClient::addEventType(const QQmlProfilerEventType &type) @@ -76,7 +76,7 @@ void QQmlProfilerTestClient::addEventType(const QQmlProfilerEventType &type) void QQmlProfilerTestClient::addEvent(const QQmlProfilerEvent &event) { const int typeIndex = event.typeIndex(); - QVERIFY(typeIndex < types.length()); + QVERIFY(typeIndex < types.size()); const QQmlProfilerEventType &type = types[typeIndex]; @@ -272,14 +272,14 @@ void tst_QQmlProfilerService::checkTraceReceived() // must end with "EndTrace" expected = QQmlProfilerEventType(Event, MaximumRangeType, EndTrace); - VERIFY(MessageListAsynchronous, m_client->asynchronousMessages.length() - 1, expected, + VERIFY(MessageListAsynchronous, m_client->asynchronousMessages.size() - 1, expected, CheckMessageType | CheckDetailType, numbers); } void tst_QQmlProfilerService::checkJsHeap() { QVERIFY(m_client); - QVERIFY2(m_client->jsHeapMessages.count() > 0, "no JavaScript heap messages received"); + QVERIFY2(m_client->jsHeapMessages.size() > 0, "no JavaScript heap messages received"); bool seen_alloc = false; bool seen_small = false; @@ -357,9 +357,9 @@ bool tst_QQmlProfilerService::verify(tst_QQmlProfilerService::MessageListType ty return false; } - if (target->length() <= expectedPosition) { + if (target->size() <= expectedPosition) { qWarning() << "Not enough events. expected position:" << expectedPosition - << "length:" << target->length(); + << "length:" << target->size(); return false; } @@ -438,7 +438,7 @@ bool tst_QQmlProfilerService::verify(tst_QQmlProfilerService::MessageListType ty } return true; - } while (++position < target->length() && target->at(position).timestamp() == timestamp); + } while (++position < target->size() && target->at(position).timestamp() == timestamp); foreach (const QString &message, warnings) qWarning() << message.toLocal8Bit().constData(); @@ -467,34 +467,34 @@ void tst_QQmlProfilerService::cleanup() }; if (m_client && QTest::currentTestFailed()) { - qDebug() << "QML Messages:" << m_client->qmlMessages.count(); + qDebug() << "QML Messages:" << m_client->qmlMessages.size(); int i = 0; - for (const QQmlProfilerEvent &data : qAsConst(m_client->qmlMessages)) + for (const QQmlProfilerEvent &data : std::as_const(m_client->qmlMessages)) log(data, i++); qDebug() << " "; - qDebug() << "JavaScript Messages:" << m_client->javascriptMessages.count(); + qDebug() << "JavaScript Messages:" << m_client->javascriptMessages.size(); i = 0; - for (const QQmlProfilerEvent &data : qAsConst(m_client->javascriptMessages)) + for (const QQmlProfilerEvent &data : std::as_const(m_client->javascriptMessages)) log(data, i++); qDebug() << " "; - qDebug() << "Asynchronous Messages:" << m_client->asynchronousMessages.count(); + qDebug() << "Asynchronous Messages:" << m_client->asynchronousMessages.size(); i = 0; - for (const QQmlProfilerEvent &data : qAsConst(m_client->asynchronousMessages)) + for (const QQmlProfilerEvent &data : std::as_const(m_client->asynchronousMessages)) log(data, i++); qDebug() << " "; - qDebug() << "Pixmap Cache Messages:" << m_client->pixmapMessages.count(); + qDebug() << "Pixmap Cache Messages:" << m_client->pixmapMessages.size(); i = 0; - for (const QQmlProfilerEvent &data : qAsConst(m_client->pixmapMessages)) + for (const QQmlProfilerEvent &data : std::as_const(m_client->pixmapMessages)) log(data, i++); qDebug() << " "; - qDebug() << "Javascript Heap Messages:" << m_client->jsHeapMessages.count(); + qDebug() << "Javascript Heap Messages:" << m_client->jsHeapMessages.size(); i = 0; - for (const QQmlProfilerEvent &data : qAsConst(m_client->jsHeapMessages)) + for (const QQmlProfilerEvent &data : std::as_const(m_client->jsHeapMessages)) log(data, i++); qDebug() << " "; @@ -677,9 +677,9 @@ void tst_QQmlProfilerService::flushInterval() QCOMPARE(connectTo(true, "timer.qml", true, 1), ConnectSuccess); // Make sure we get multiple messages - QTRY_VERIFY(m_client->qmlMessages.length() > 0); - QVERIFY(m_client->qmlMessages.length() < 100); - QTRY_VERIFY(m_client->qmlMessages.length() > 100); + QTRY_VERIFY(m_client->qmlMessages.size() > 0); + QVERIFY(m_client->qmlMessages.size() < 100); + QTRY_VERIFY(m_client->qmlMessages.size() > 100); m_client->client->setRecording(false); checkTraceReceived(); @@ -783,7 +783,7 @@ void tst_QQmlProfilerService::multiEngine() QTRY_COMPARE(m_process->state(), QProcess::NotRunning); QCOMPARE(m_process->exitStatus(), QProcess::NormalExit); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QQmlProfilerService::batchOverflow() diff --git a/tests/auto/qml/debugger/qv4debugger/CMakeLists.txt b/tests/auto/qml/debugger/qv4debugger/CMakeLists.txt index ecefcb65bc..92565f55c1 100644 --- a/tests/auto/qml/debugger/qv4debugger/CMakeLists.txt +++ b/tests/auto/qml/debugger/qv4debugger/CMakeLists.txt @@ -10,6 +10,18 @@ file(GLOB_RECURSE test_data_glob data/*) list(APPEND test_data ${test_data_glob}) +qt_add_library(testCppTypes STATIC) +qt_autogen_tools_initial_setup(testCppTypes) +target_link_libraries(testCppTypes PRIVATE Qt::Qml Qt::QmlPrivate Qt::Quick) + +qt6_add_qml_module(testCppTypes + VERSION 1.0 + URI TestTypes + SOURCES + commontypes.h +) +qt_autogen_tools_initial_setup(testCppTypesplugin) + qt_internal_add_test(tst_qv4debugger SOURCES ../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.cpp ../../../../../src/plugins/qmltooling/qmldbg_debugger/qv4datacollector.h @@ -25,6 +37,7 @@ qt_internal_add_test(tst_qv4debugger Qt::Network Qt::QmlPrivate Qt::QuickTestUtilsPrivate + testCppTypesplugin TESTDATA ${test_data} ) diff --git a/tests/auto/qml/debugger/qv4debugger/commontypes.h b/tests/auto/qml/debugger/qv4debugger/commontypes.h new file mode 100644 index 0000000000..01b2125ae3 --- /dev/null +++ b/tests/auto/qml/debugger/qv4debugger/commontypes.h @@ -0,0 +1,20 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef COMMONTYPES_H +#define COMMONTYPES_H + +#include <QtQuick/qquickitem.h> +#include <QtQml/qqmlregistration.h> +#include <QtQml/private/qv4engine_p.h> + +class MyType : public QQuickItem +{ + Q_OBJECT + QML_ELEMENT +public: + MyType(QQuickItem *parent = nullptr) : QQuickItem(parent) {} + Q_INVOKABLE void name(QQmlV4Function*) const {} +}; + +#endif // COMMONTYPES_H diff --git a/tests/auto/qml/debugger/qv4debugger/data/qtbug_107607.qml b/tests/auto/qml/debugger/qv4debugger/data/qtbug_107607.qml new file mode 100644 index 0000000000..a7758de8a8 --- /dev/null +++ b/tests/auto/qml/debugger/qv4debugger/data/qtbug_107607.qml @@ -0,0 +1,10 @@ +import QtQuick +import TestTypes +MyType { + objectName: "patron" + Item { + Component.onCompleted: { + console.log("Hallo Welt"); + } + } +}
\ No newline at end of file diff --git a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp index d7a79f446b..6f147446f0 100644 --- a/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp +++ b/tests/auto/qml/debugger/qv4debugger/tst_qv4debugger.cpp @@ -16,10 +16,13 @@ #include <private/qv4string_p.h> #include <private/qqmlbuiltinfunctions_p.h> #include <private/qqmldebugservice_p.h> +#include <QtQml/qqmlextensionplugin.h> using namespace QV4; using namespace QV4::Debugging; +Q_IMPORT_QML_PLUGIN(TestTypesPlugin); + typedef QV4::ReturnedValue (*InjectedFunction)(const FunctionObject *b, const QV4::Value *, const QV4::Value *, int); Q_DECLARE_METATYPE(InjectedFunction) @@ -176,7 +179,15 @@ public slots: ExpressionEvalJob job(debugger->engine(), request.frameNr, request.context, request.expression, &collector); debugger->runInEngine(&job); - m_expressionResults << job.returnValue(); + const QJsonObject& result = job.returnValue(); + m_expressionResults << result; + + if (request.shouldLookup) { + QJsonArray handles {result.value("handle").toInt()}; + ValueLookupJob job(handles, &collector); + debugger->runInEngine(&job); + m_lookupResults << job.returnValue(); + } } if (m_captureContextInfo) @@ -249,10 +260,14 @@ public: QString expression; int frameNr; int context; + bool shouldLookup = false; }; + + QVector<ExpressionRequest> m_expressionRequests; QV4Debugger::Speed m_resumeSpeed; QList<QJsonObject> m_expressionResults; + QList<QJsonObject> m_lookupResults; QV4Debugger *m_debugger; // Utility methods: @@ -306,7 +321,7 @@ private slots: void readThis(); void signalParameters(); - + void debuggerNoCrash(); private: QV4Debugger *debugger() const { @@ -370,7 +385,7 @@ void tst_qv4debugger::pendingBreakpoint() debugger()->addBreakPoint("testfile", 2); evaluateJavaScript(script, "testfile"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 1); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 1); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(state.fileName, QString("testfile")); QCOMPARE(state.lineNumber, 2); @@ -386,7 +401,7 @@ void tst_qv4debugger::liveBreakPoint() debugger()->pause(); evaluateJavaScript(script, "liveBreakPoint"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 2); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 2); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.at(1); QCOMPARE(state.fileName, QString("liveBreakPoint")); QCOMPARE(state.lineNumber, 3); @@ -414,7 +429,7 @@ void tst_qv4debugger::addBreakPointWhilePaused() m_debuggerAgent->m_breakPointsToAddWhenPaused << TestAgent::TestBreakPoint("addBreakPointWhilePaused", 2); evaluateJavaScript(script, "addBreakPointWhilePaused"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 2); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 2); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.at(0); QCOMPARE(state.fileName, QString("addBreakPointWhilePaused")); @@ -461,7 +476,7 @@ void tst_qv4debugger::conditionalBreakPoint() debugger()->addBreakPoint("conditionalBreakPoint", 3, QStringLiteral("i > 10")); evaluateJavaScript(script, "conditionalBreakPoint"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 4); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 4); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(state.fileName, QString("conditionalBreakPoint")); QCOMPARE(state.lineNumber, 3); @@ -495,7 +510,7 @@ void tst_qv4debugger::conditionalBreakPointInQml() QScopedPointer<QObject> obj(component.create()); QCOMPARE(obj->property("success").toBool(), true); - QCOMPARE(debuggerAgent->m_statesWhenPaused.count(), 1); + QCOMPARE(debuggerAgent->m_statesWhenPaused.size(), 1); QCOMPARE(debuggerAgent->m_statesWhenPaused.at(0).fileName, qmlFileName); QCOMPARE(debuggerAgent->m_statesWhenPaused.at(0).lineNumber, 7); @@ -699,7 +714,7 @@ void tst_qv4debugger::breakInCatch() evaluateJavaScript(script, "breakInCatch"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::BreakPointHit); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 1); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 1); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(state.fileName, QString("breakInCatch")); QCOMPARE(state.lineNumber, 4); @@ -716,7 +731,7 @@ void tst_qv4debugger::breakInWith() evaluateJavaScript(script, "breakInWith"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::BreakPointHit); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 1); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 1); QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(state.fileName, QString("breakInWith")); QCOMPARE(state.lineNumber, 2); @@ -752,7 +767,7 @@ void tst_qv4debugger::evaluateExpression() evaluateJavaScript(script, "evaluateExpression"); - QCOMPARE(m_debuggerAgent->m_expressionResults.count(), 4); + QCOMPARE(m_debuggerAgent->m_expressionResults.size(), 4); QJsonObject result0 = m_debuggerAgent->m_expressionResults[0]; QCOMPARE(result0.value("type").toString(), QStringLiteral("number")); QCOMPARE(result0.value("value").toInt(), 10); @@ -776,7 +791,7 @@ void tst_qv4debugger::stepToEndOfScript() evaluateJavaScript(script, "toEnd"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::Step); - QCOMPARE(m_debuggerAgent->m_statesWhenPaused.count(), 5); + QCOMPARE(m_debuggerAgent->m_statesWhenPaused.size(), 5); for (int i = 0; i < 4; ++i) { QV4Debugger::ExecutionState state = m_debuggerAgent->m_statesWhenPaused.at(i); QCOMPARE(state.fileName, QString("toEnd")); @@ -846,7 +861,7 @@ void tst_qv4debugger::lastLineOfConditional() evaluateJavaScript(script, "trueBranch"); QVERIFY(m_debuggerAgent->m_wasPaused); QCOMPARE(m_debuggerAgent->m_pauseReason, QV4Debugger::Step); - QVERIFY(m_debuggerAgent->m_statesWhenPaused.count() > 1); + QVERIFY(m_debuggerAgent->m_statesWhenPaused.size() > 1); QV4Debugger::ExecutionState firstState = m_debuggerAgent->m_statesWhenPaused.first(); QCOMPARE(firstState.fileName, QString("trueBranch")); QCOMPARE(firstState.lineNumber, breakPoint); @@ -873,7 +888,7 @@ void tst_qv4debugger::readThis() evaluateJavaScript(script, "applyThis"); QVERIFY(m_debuggerAgent->m_wasPaused); - QCOMPARE(m_debuggerAgent->m_expressionResults.count(), 1); + QCOMPARE(m_debuggerAgent->m_expressionResults.size(), 1); QJsonObject result0 = m_debuggerAgent->m_expressionResults[0]; QCOMPARE(result0.value("type").toString(), QStringLiteral("object")); QCOMPARE(result0.value("value").toInt(), 1); @@ -916,6 +931,42 @@ void tst_qv4debugger::signalParameters() QCOMPARE(obj->property("resultCallbackExternal").toString(), QLatin1String("unset")); } +void tst_qv4debugger::debuggerNoCrash() +{ + QQmlEngine engine; + QV4::ExecutionEngine *v4 = engine.handle(); + QPointer<QV4Debugger> v4Debugger = new QV4Debugger(v4); + v4->setDebugger(v4Debugger.data()); + + QScopedPointer<QThread> debugThread(new QThread); + debugThread->start(); + QScopedPointer<TestAgent> debuggerAgent(new TestAgent(v4)); + debuggerAgent->addDebugger(v4Debugger); + debuggerAgent->moveToThread(debugThread.data()); + + const QString qmlFileName("qtbug_107607.qml"); + const QString qmlFilePath(testFile(qmlFileName)); + QQmlComponent component(&engine, qmlFilePath); + + TestAgent::ExpressionRequest request; + request.expression = "this.parent"; + request.frameNr = 0; + request.context = -1; + request.shouldLookup = true; + debuggerAgent->m_expressionRequests << request; + v4Debugger->addBreakPoint(qmlFileName, 7); + + QScopedPointer<QObject> obj(component.create()); + + QVERIFY(debuggerAgent->m_lookupResults.size() > 0); + const QJsonObject result = debuggerAgent->m_lookupResults[0]; + const QJsonArray properties = result["0"].toObject().value("properties").toArray(); + QCOMPARE(properties[0].toObject().value("value").toString(), QStringLiteral("patron")); + + debugThread->quit(); + debugThread->wait(); +} + tst_qv4debugger::tst_qv4debugger() : QQmlDataTest(QT_QMLTEST_DATADIR) { } QTEST_MAIN(tst_qv4debugger) diff --git a/tests/auto/qml/debugger/shared/debugutil.cpp b/tests/auto/qml/debugger/shared/debugutil.cpp index bc15af706d..bce2c28378 100644 --- a/tests/auto/qml/debugger/shared/debugutil.cpp +++ b/tests/auto/qml/debugger/shared/debugutil.cpp @@ -20,7 +20,7 @@ bool QQmlDebugTest::waitForSignal(QObject *sender, const char *member, int timeo QSignalSpy spy(sender, member); // Do not use spy.wait(). We want to avoid nested event loops. - if (QTest::qWaitFor([&]() { return spy.count() > 0; }, timeout)) + if (QTest::qWaitFor([&]() { return spy.size() > 0; }, timeout)) return true; qWarning("waitForSignal %s timed out after %d ms", member, timeout); @@ -132,7 +132,7 @@ QQmlDebugTest::ConnectResult QQmlDebugTest::connectTo( QSignalSpy okSpy(&stateHandler, &ClientStateHandler::allOk); QSignalSpy disconnectSpy(m_connection, &QQmlDebugConnection::disconnected); m_connection->connectToHost(QLatin1String("127.0.0.1"), m_process->debugPort()); - if (!QTest::qWaitFor([&](){ return okSpy.count() > 0 || disconnectSpy.count() > 0; }, 5000)) + if (!QTest::qWaitFor([&](){ return okSpy.size() > 0 || disconnectSpy.size() > 0; }, 5000)) return ConnectionTimeout; if (!stateHandler.allEnabled()) @@ -231,7 +231,7 @@ QString debugJsServerPath(const QString &selfPath) static const char *debugserver = "qqmldebugjsserver"; QString appPath = QCoreApplication::applicationDirPath(); const int position = appPath.lastIndexOf(selfPath); - return (position == -1 ? appPath : appPath.replace(position, selfPath.length(), debugserver)) + return (position == -1 ? appPath : appPath.replace(position, selfPath.size(), debugserver)) + "/" + debugserver; } diff --git a/tests/auto/qml/ecmascripttests/qjstest/test262runner.cpp b/tests/auto/qml/ecmascripttests/qjstest/test262runner.cpp index 3963e9aa48..03706b8e7c 100644 --- a/tests/auto/qml/ecmascripttests/qjstest/test262runner.cpp +++ b/tests/auto/qml/ecmascripttests/qjstest/test262runner.cpp @@ -179,17 +179,17 @@ bool Test262Runner::report() } if (!crashes.isEmpty()) { qDebug() << " Encountered" << crashes.size() << "crashes in the following files:"; - for (const QString &f : qAsConst(crashes)) + for (const QString &f : std::as_const(crashes)) qDebug() << " " << f; } if (!unexpectedFailures.isEmpty()) { qDebug() << " Encountered" << unexpectedFailures.size() << "unexpected failures in the following files:"; - for (const QString &f : qAsConst(unexpectedFailures)) + for (const QString &f : std::as_const(unexpectedFailures)) qDebug() << " " << f; } if (!unexpectedPasses.isEmpty()) { qDebug() << " Encountered" << unexpectedPasses.size() << "unexpected passes in the following files:"; - for (const QString &f : qAsConst(unexpectedPasses)) + for (const QString &f : std::as_const(unexpectedPasses)) qDebug() << " " << f; } return crashes.isEmpty() && unexpectedFailures.isEmpty() && unexpectedPasses.isEmpty(); @@ -207,7 +207,7 @@ bool Test262Runner::loadTests() QString harness = "harness"; QString intl402 = "intl402"; - int pathlen = dir.path().length() + 1; + int pathlen = dir.path().size() + 1; QDirIterator it(dir, QDirIterator::Subdirectories); while (it.hasNext()) { QString file = it.next().mid(pathlen); @@ -373,9 +373,7 @@ void Test262Runner::loadTestExpectations() return; } - int line = 0; while (!file.atEnd()) { - ++line; QByteArray line = file.readLine().trimmed(); if (line.startsWith('#') || line.isEmpty()) continue; @@ -420,9 +418,7 @@ void Test262Runner::updateTestExpectations() QTemporaryFile updatedExpectations; updatedExpectations.open(); - int line = 0; while (!file.atEnd()) { - ++line; QByteArray originalLine = file.readLine(); QByteArray line = originalLine.trimmed(); if (line.startsWith('#') || line.isEmpty()) { @@ -458,7 +454,7 @@ void Test262Runner::writeTestExpectations() QTemporaryFile expectations; expectations.open(); - for (auto c : qAsConst(testCases)) { + for (auto c : std::as_const(testCases)) { TestExpectationLine line = TestExpectationLine::fromTestCase(c); expectations.write(line.toLine()); } @@ -494,7 +490,7 @@ static bool executeTest(const QByteArray &data, bool runAsModule = false, const QFile f(url.toLocalFile()); if (f.open(QIODevice::ReadOnly)) { QByteArray content = harnessForModules + f.readAll(); - module = vm.compileModule(url.toString(), QString::fromUtf8(content.constData(), content.length()), QFileInfo(f).lastModified()); + module = vm.compileModule(url.toString(), QString::fromUtf8(content.constData(), content.size()), QFileInfo(f).lastModified()); if (vm.hasException) break; vm.injectModule(module); @@ -692,7 +688,7 @@ TestData Test262Runner::getTestData(const TestCase &testCase) data.harness += harness("assert.js"); data.harness += harness("sta.js"); - for (QByteArray inc : qAsConst(data.includes)) { + for (QByteArray inc : std::as_const(data.includes)) { inc = inc.trimmed(); data.harness += harness(inc); } @@ -726,7 +722,7 @@ YamlSection::YamlSection(const QByteArray &yaml, const char *sectionName) start += static_cast<int>(strlen(sectionName)); int end = yaml.indexOf('\n', start + 1); if (end < 0) - end = yaml.length(); + end = yaml.size(); int s = yaml.indexOf('[', start); if (s > 0 && s < end) { diff --git a/tests/auto/qml/ecmascripttests/tst_ecmascripttests.cpp b/tests/auto/qml/ecmascripttests/tst_ecmascripttests.cpp index bf8d194bf4..bee391e62c 100644 --- a/tests/auto/qml/ecmascripttests/tst_ecmascripttests.cpp +++ b/tests/auto/qml/ecmascripttests/tst_ecmascripttests.cpp @@ -1,7 +1,6 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - #include <QtTest/QtTest> #include <QProcess> #include <QLibraryInfo> @@ -12,16 +11,62 @@ class tst_EcmaScriptTests : public QObject Q_OBJECT private slots: + void initTestCase(); + void cleanupTestCase(); void runInterpreted(); void runJitted(); + +private: + static QLoggingCategory::CategoryFilter priorFilter; + static void filterCategories(QLoggingCategory *category); }; +QLoggingCategory::CategoryFilter tst_EcmaScriptTests::priorFilter = nullptr; + +static inline bool isNoise(QByteArrayView name) +{ +#ifdef QT_V4_WANT_ES262_WARNINGS + return false; +#else + const QByteArrayView noisy("qt.qml.compiler"); + return name.startsWith(noisy) && (name.size() <= noisy.size() || name[noisy.size()] == '.'); +#endif +} + +void tst_EcmaScriptTests::filterCategories(QLoggingCategory *category) +{ + if (priorFilter) + priorFilter(category); + + if (isNoise(category->categoryName())) { + category->setEnabled(QtDebugMsg, false); + category->setEnabled(QtWarningMsg, false); + } +} + +void tst_EcmaScriptTests::initTestCase() +{ + /* Suppress lcQmlCompiler's "qt.qml.compiler" warnings; we aren't in a + position to fix test262's many warnings and they flood messages so we + didn't get to see actual failures unless we passed -maxwarnings with a + huge value on the command-line (resulting in huge log output). + */ + priorFilter = QLoggingCategory::installFilter(filterCategories); +} + +void tst_EcmaScriptTests::cleanupTestCase() +{ + QLoggingCategory::installFilter(priorFilter); +} void tst_EcmaScriptTests::runInterpreted() { #if defined(Q_PROCESSOR_X86_64) QDir::setCurrent(QLatin1String(SRCDIR)); Test262Runner runner(QString(), "test262"); - runner.setFlags(Test262Runner::ForceBytecode|Test262Runner::WithTestExpectations|Test262Runner::Parallel|Test262Runner::Verbose); + runner.setFlags(Test262Runner::ForceBytecode + | Test262Runner::WithTestExpectations + | Test262Runner::Parallel + | Test262Runner::Verbose); bool result = runner.run(); QVERIFY(result); #endif @@ -32,7 +77,10 @@ void tst_EcmaScriptTests::runJitted() #if defined(Q_PROCESSOR_X86_64) QDir::setCurrent(QLatin1String(SRCDIR)); Test262Runner runner(QString(), "test262"); - runner.setFlags(Test262Runner::ForceJIT|Test262Runner::WithTestExpectations|Test262Runner::Parallel|Test262Runner::Verbose); + runner.setFlags(Test262Runner::ForceJIT + | Test262Runner::WithTestExpectations + | Test262Runner::Parallel + | Test262Runner::Verbose); bool result = runner.run(); QVERIFY(result); #endif diff --git a/tests/auto/qml/parserstress/tst_parserstress.cpp b/tests/auto/qml/parserstress/tst_parserstress.cpp index 7fb2787d31..99af0247a8 100644 --- a/tests/auto/qml/parserstress/tst_parserstress.cpp +++ b/tests/auto/qml/parserstress/tst_parserstress.cpp @@ -126,7 +126,7 @@ void tst_parserstress::ecmascript() if (fileInfo.fileName() == QLatin1String("regress-352044-02-n.js")) { QVERIFY(component.isError()); - QCOMPARE(component.errors().length(), 2); + QCOMPARE(component.errors().size(), 2); QCOMPARE(component.errors().at(0).description(), QString("Expected token `;'")); QCOMPARE(component.errors().at(0).line(), 66); diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index 0c3a8d1703..8c2f9ae645 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -249,6 +249,8 @@ private slots: void sortNonStringArray(); void iterateInvalidProxy(); void applyOnHugeArray(); + void reflectApplyOnHugeArray(); + void jsonStringifyHugeArray(); void tostringRecursionCheck(); void arrayIncludesWithLargeArray(); @@ -260,6 +262,9 @@ private slots: void urlObject(); void thisInConstructor(); void forOfAndGc(); + void staticInNestedClasses(); + + void spreadNoOverflow(); public: Q_INVOKABLE QJSValue throwingCppMethod1(); @@ -5326,6 +5331,36 @@ void tst_QJSEngine::applyOnHugeArray() QCOMPARE(value.toString(), "RangeError: Array too large for apply()."); } + +void tst_QJSEngine::reflectApplyOnHugeArray() +{ + QQmlEngine engine; + const QJSValue value = engine.evaluate(R"( +(function(){ +const v1 = []; +const v3 = []; +v3.length = 3900000000; +Reflect.apply(v1.reverse,v1,v3); +})() + )"); + QVERIFY(value.isError()); + QCOMPARE(value.toString(), QLatin1String("RangeError: Invalid array length.")); +} + +void tst_QJSEngine::jsonStringifyHugeArray() +{ + QQmlEngine engine; + const QJSValue value = engine.evaluate(R"( +(function(){ +const v3 = []; +v3.length = 3900000000; +JSON.stringify([], v3); +})() + )"); + QVERIFY(value.isError()); + QCOMPARE(value.toString(), QLatin1String("RangeError: Invalid array length.")); +} + void tst_QJSEngine::typedArraySet() { QJSEngine engine; @@ -5425,7 +5460,7 @@ void tst_QJSEngine::urlObject() check(QStringLiteral("href"), url.toString()); check(QStringLiteral("origin"), QStringLiteral("http://example.com:777")); - check(QStringLiteral("protocol"), url.scheme()); + check(QStringLiteral("protocol"), url.scheme() + QLatin1Char(':')); check(QStringLiteral("username"), url.userName()); check(QStringLiteral("password"), url.password()); check(QStringLiteral("host"), url.host() + u':' + QString::number(url.port())); @@ -5571,6 +5606,32 @@ void tst_QJSEngine::forOfAndGc() QTRY_VERIFY(o->property("count").toInt() > 32768); } +void tst_QJSEngine::staticInNestedClasses() +{ + QJSEngine engine; + const QString program = uR"( + class Tester { + constructor() { + new (class {})(); + } + static get test() { return "a" } + } + Tester.test + )"_s; + + QCOMPARE(engine.evaluate(program).toString(), u"a"_s); +} + +void tst_QJSEngine::spreadNoOverflow() +{ + QJSEngine engine; + + const QString program = QString::fromLatin1("var a = [] ;a.length = 555840;Math.max(...a)"); + const QJSValue result = engine.evaluate(program); + QVERIFY(result.isError()); + QCOMPARE(result.errorType(), QJSValue::RangeError); +} + QTEST_MAIN(tst_QJSEngine) #include "tst_qjsengine.moc" diff --git a/tests/auto/qml/qjsmanagedvalue/tst_qjsmanagedvalue.cpp b/tests/auto/qml/qjsmanagedvalue/tst_qjsmanagedvalue.cpp index 568b14b5ac..6723926585 100644 --- a/tests/auto/qml/qjsmanagedvalue/tst_qjsmanagedvalue.cpp +++ b/tests/auto/qml/qjsmanagedvalue/tst_qjsmanagedvalue.cpp @@ -1742,7 +1742,7 @@ void tst_QJSManagedValue::stringByIndex() const QString testString = QStringLiteral("foobar"); QJSManagedValue str(testString, &engine); - for (uint i = 0; i < testString.length(); ++i) { + for (uint i = 0; i < testString.size(); ++i) { QVERIFY(str.hasOwnProperty(i)); QVERIFY(str.hasProperty(i)); diff --git a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp index cc301081cf..6235ff376d 100644 --- a/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp +++ b/tests/auto/qml/qjsonbinding/tst_qjsonbinding.cpp @@ -52,6 +52,9 @@ private slots: void writeProperty_javascriptExpression_data(); void writeProperty_javascriptExpression(); + void cyclicStringify(); + void recursiveStringify(); + private: QByteArray readAsUtf8(const QString &fileName); static QJsonValue valueFromJson(const QByteArray &json); @@ -489,6 +492,43 @@ void tst_qjsonbinding::writeProperty_javascriptExpression() QCOMPARE(ret.toString(), expectedJson); } +void tst_qjsonbinding::cyclicStringify() +{ + QJSEngine e; + const QString program = QStringLiteral(R"( + var a = {}; + a.a = a; + JSON.stringify(a); + )"); + + QJSValue result = e.evaluate(program); + QVERIFY(result.isError()); + QCOMPARE(result.errorType(), QJSValue::TypeError); + QVERIFY(result.toString().contains(QLatin1String("Cannot convert circular structure to JSON"))); +} + +void tst_qjsonbinding::recursiveStringify() +{ + QJSEngine e; + const QString program = QStringLiteral(R"( + function create() { + var a = {} + Object.defineProperty(a, "a", { + enumerable: true, + get: function() { return create(); } + }); + return a; + } + + JSON.stringify(create()); + )"); + + QJSValue result = e.evaluate(program); + QVERIFY(result.isError()); + QCOMPARE(result.errorType(), QJSValue::RangeError); + QVERIFY(result.toString().contains(QLatin1String("Maximum call stack size exceeded"))); +} + QTEST_MAIN(tst_qjsonbinding) #include "tst_qjsonbinding.moc" diff --git a/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp b/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp index 339a524604..e329cf948f 100644 --- a/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp +++ b/tests/auto/qml/qjsvalueiterator/tst_qjsvalueiterator.cpp @@ -95,7 +95,7 @@ void tst_QJSValueIterator::iterateForward() QCOMPARE(it.hasNext(), false); it = object; - for (int i = 0; i < lst.count(); ++i) { + for (int i = 0; i < lst.size(); ++i) { QCOMPARE(it.hasNext(), true); it.next(); QCOMPARE(it.name(), lst.at(i)); diff --git a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt index f3e608a6ae..a5a73d7eb1 100644 --- a/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt +++ b/tests/auto/qml/qmlcppcodegen/data/CMakeLists.txt @@ -2,7 +2,11 @@ set(cpp_sources ambiguous.h birthdayparty.cpp birthdayparty.h cppbaseclass.h + dummyobjekt.h dynamicmeta.h + enumProperty.h + enumproblems.h + gadgetwithenum.h invisible.h objectwithmethod.h person.cpp person.h @@ -49,6 +53,7 @@ set(qml_files blockComments.qml boundComponents.qml callContextPropertyLookupResult.qml + callWithSpread.qml childobject.qml colorAsVariant.qml colorString.qml @@ -66,8 +71,11 @@ set(qml_files deadStoreLoop.qml dialog.qml dynamicscene.qml + enumConversion.qml + enumFromBadSingleton.qml enumInvalid.qml enumLookup.qml + enumProblems.qml enumScope.qml enumsInOtherObject.qml enumsUser.qml @@ -116,6 +124,7 @@ set(qml_files notEqualsInt.qml notNotString.qml nullAccess.qml + nullComparison.qml objectInVar.qml outOfBounds.qml overriddenMember.qml @@ -135,7 +144,9 @@ set(qml_files shifts.qml signal.qml signalHandler.qml + signalIndexMismatch.qml specificParent.qml + storeElementSideEffects.qml stringLength.qml stringToByteArray.qml testlogger.js @@ -144,9 +155,11 @@ set(qml_files themergood.qml throwObjectName.qml toString.qml + typePropagationLoop.qml typePropertyClash.qml typedArray.qml undefinedResets.qml + undefinedToDouble.qml unknownAttached.qml unknownParameter.qml unstoredUndefined.qml @@ -155,6 +168,7 @@ set(qml_files valueTypeLists.qml valueTypeProperty.qml variantlist.qml + versionmismatch.qml voidfunction.qml ) @@ -176,7 +190,7 @@ set_target_properties(codegen_test_module PROPERTIES ) qt6_add_qml_module(codegen_test_module - VERSION 1.0 + VERSION 1.5 URI TestTypes IMPORT_PATH "${CMAKE_CURRENT_SOURCE_DIR}/imports/" DEPENDENCIES diff --git a/tests/auto/qml/qmlcppcodegen/data/badSequence.qml b/tests/auto/qml/qmlcppcodegen/data/badSequence.qml index 5b0742ab6a..785765ec74 100644 --- a/tests/auto/qml/qmlcppcodegen/data/badSequence.qml +++ b/tests/auto/qml/qmlcppcodegen/data/badSequence.qml @@ -3,4 +3,5 @@ import TestTypes Person { property Person other: Person { id: oo } barzles: oo.barzles + property int l: oo.barzles.length } diff --git a/tests/auto/qml/qmlcppcodegen/data/birthdayparty.cpp b/tests/auto/qml/qmlcppcodegen/data/birthdayparty.cpp index 4ba76d882d..048459f03a 100644 --- a/tests/auto/qml/qmlcppcodegen/data/birthdayparty.cpp +++ b/tests/auto/qml/qmlcppcodegen/data/birthdayparty.cpp @@ -28,7 +28,7 @@ QQmlListProperty<Person> BirthdayParty::guests() int BirthdayParty::guestCount() const { - return m_guests.count(); + return m_guests.size(); } Person *BirthdayParty::guest(int index) const diff --git a/tests/auto/qml/qmlcppcodegen/data/callWithSpread.qml b/tests/auto/qml/qmlcppcodegen/data/callWithSpread.qml new file mode 100644 index 0000000000..3d7f79d68d --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/callWithSpread.qml @@ -0,0 +1,9 @@ +import QtQml + +QtObject { + Component.onCompleted: { + let f = console.error; + const data = [f, ["That is great!"]] + data[0](...data[1]); + } +} diff --git a/tests/auto/qml/qmlcppcodegen/data/cppbaseclass.h b/tests/auto/qml/qmlcppcodegen/data/cppbaseclass.h index 416a61defc..eecc3d968e 100644 --- a/tests/auto/qml/qmlcppcodegen/data/cppbaseclass.h +++ b/tests/auto/qml/qmlcppcodegen/data/cppbaseclass.h @@ -15,6 +15,8 @@ class CppBaseClass : public QObject Q_PROPERTY(int cppProp2 MEMBER cppProp2 BINDABLE cppProp2Bindable FINAL) Q_PROPERTY(QList<int> boo MEMBER boo FINAL CONSTANT) Q_PROPERTY(QList<qreal> hoo MEMBER hoo FINAL CONSTANT) + Q_PROPERTY(int inaccessible READ inaccessible FINAL CONSTANT REVISION(1, 5)) + QML_ADDED_IN_VERSION(1, 0) QML_ELEMENT public: CppBaseClass(QObject *parent = nullptr) @@ -35,6 +37,7 @@ public: Q_INVOKABLE void doCall(QObject *foo); + int inaccessible() const { return 7; } private: QList<int> boo; QList<qreal> hoo; diff --git a/tests/auto/qml/qmlcppcodegen/data/dummyobjekt.h b/tests/auto/qml/qmlcppcodegen/data/dummyobjekt.h new file mode 100644 index 0000000000..c75501a5b8 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/dummyobjekt.h @@ -0,0 +1,29 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef DUMMYOBJEKT_H +#define DUMMYOBJEKT_H + +#include <QtCore/qobject.h> +#include <QtQml/qqml.h> + +#if QT_DEPRECATED_SINCE(6, 4) +class DummyObjekt : public QObject +{ + Q_OBJECT + QML_ELEMENT + QML_SINGLETON + +public: + enum Test { + TestA = 1, + TestB + }; + Q_ENUM(Test) + + // Deliberately not default constructible + explicit DummyObjekt(QObject *parent) : QObject(parent) {} +}; +#endif + +#endif // DUMMYOBJEKT_H diff --git a/tests/auto/qml/qmlcppcodegen/data/enumConversion.qml b/tests/auto/qml/qmlcppcodegen/data/enumConversion.qml new file mode 100644 index 0000000000..fee2c50e15 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/enumConversion.qml @@ -0,0 +1,7 @@ +import TestTypes + +MyType { + id: root + property int test: myEnumType.type + property bool test_1: myEnumType.type +} diff --git a/tests/auto/qml/qmlcppcodegen/data/enumFromBadSingleton.qml b/tests/auto/qml/qmlcppcodegen/data/enumFromBadSingleton.qml new file mode 100644 index 0000000000..3176fde315 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/enumFromBadSingleton.qml @@ -0,0 +1,6 @@ +import QtQml +import TestTypes + +QtObject { + objectName: "Dummy: " + DummyObjekt.TestA +} diff --git a/tests/auto/qml/qmlcppcodegen/data/enumProblems.qml b/tests/auto/qml/qmlcppcodegen/data/enumProblems.qml new file mode 100644 index 0000000000..230172ce48 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/enumProblems.qml @@ -0,0 +1,13 @@ +import TestTypes +import QtQml + +QtObject { + id: root + + readonly property FooFactory f: FooFactory {} + + property QtObject o: QtObject { + readonly property FooThing fighter: root.f.get(Foo.Fighter) + readonly property FooThing bar: root.f.get(Foo.Component) + } +} diff --git a/tests/auto/qml/qmlcppcodegen/data/enumProperty.h b/tests/auto/qml/qmlcppcodegen/data/enumProperty.h new file mode 100644 index 0000000000..8c13e860a3 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/enumProperty.h @@ -0,0 +1,34 @@ +#ifndef ENUMPROPERTY_H +#define ENUMPROPERTY_H + +#include <QObject> +#include <QtQml> + +class MyEnumType +{ + Q_GADGET + QML_ANONYMOUS +public: + enum MyEnum { + Sin = 0x01, + Saw = 0x02, + Tri = 0x04, + }; + Q_ENUM(MyEnum) + Q_PROPERTY(MyEnum type READ type) + MyEnum type() const { return MyEnum::Tri; } +}; + +class MyType : public QObject +{ + Q_OBJECT + Q_PROPERTY(MyEnumType myEnumType READ myEnumType) + QML_ELEMENT +public: + MyEnumType myEnumType() const { return m_type; } + +private: + MyEnumType m_type; +}; + +#endif // ENUMPROPERTY_H diff --git a/tests/auto/qml/qmlcppcodegen/data/enumproblems.h b/tests/auto/qml/qmlcppcodegen/data/enumproblems.h new file mode 100644 index 0000000000..08a00acf7e --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/enumproblems.h @@ -0,0 +1,53 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef ENUMPROBLEMS_H +#define ENUMPROBLEMS_H + +#include <QObject> +#include <QtQml/qqml.h> +#include <QtQml/qqmlregistration.h> + +class Foo : public QObject { + Q_OBJECT + +public: + enum Type { + Unknown, + Fighter, + Component + }; + Q_ENUM(Type) + + explicit Foo(Foo::Type type, QObject *parent = nullptr) : QObject(parent), m_type(type) {} + + Type type() const { return m_type; } + +private: + Type m_type = Type::Unknown; +}; + +namespace FooWrapper { + Q_NAMESPACE + QML_FOREIGN_NAMESPACE(Foo) + QML_NAMED_ELEMENT(Foo) +}; + + +class FooThingWrapper { + Q_GADGET + QML_FOREIGN(Foo) + QML_NAMED_ELEMENT(FooThing) + QML_UNCREATABLE("nope") +}; + + +class FooFactory : public QObject { + Q_OBJECT + QML_ELEMENT + +public: + Q_INVOKABLE Foo* get(Foo::Type type) const { return new Foo(type); } +}; + +#endif // ENUMPROBLEMS_H diff --git a/tests/auto/qml/qmlcppcodegen/data/failures.qml b/tests/auto/qml/qmlcppcodegen/data/failures.qml index 39268d84ce..16dd0c764a 100644 --- a/tests/auto/qml/qmlcppcodegen/data/failures.qml +++ b/tests/auto/qml/qmlcppcodegen/data/failures.qml @@ -1,5 +1,6 @@ import QtQml import TestTypes +import TestTypes as TT2 import Ambiguous 1.2 QtObject { @@ -35,4 +36,7 @@ QtObject { signal bar() // Cannot assign potential undefined onFoo: objectName = self.bar() + + property int enumFromGadget1: GadgetWithEnum.CONNECTED + 1 + property int enumFromGadget2: TT2.GadgetWithEnum.CONNECTED + 1 } diff --git a/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h b/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h new file mode 100644 index 0000000000..d146b9f654 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/gadgetwithenum.h @@ -0,0 +1,23 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#ifndef GADGETWITHENUM_H +#define GADGETWITHENUM_H + +#include <QtCore/qobject.h> +#include <QtQmlIntegration/qqmlintegration.h> + +class GadgetWithEnum : public QObject { + Q_GADGET + QML_ELEMENT + +public: + enum State { + DISCONNECTED, + CONNECTING, + CONNECTED + }; + Q_ENUM(State) +}; + +#endif // GADGETWITHENUM_H diff --git a/tests/auto/qml/qmlcppcodegen/data/nullComparison.qml b/tests/auto/qml/qmlcppcodegen/data/nullComparison.qml new file mode 100644 index 0000000000..1f9af7169b --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/nullComparison.qml @@ -0,0 +1,26 @@ +pragma Strict +import QtQml + +QtObject { + property int v: 1 + property int w: 1 + property int x: 1 + property int y: 1 + Component.onCompleted: { + var g = null; + if (g !== null) { + v = 2; + } + if (g === null) { + w = 3; + } + + var h = undefined; + if (h !== undefined) { + x = 4; + } + if (h === undefined) { + y = 5; + } + } +} diff --git a/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml b/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml new file mode 100644 index 0000000000..ecc03026ba --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/signalIndexMismatch.qml @@ -0,0 +1,48 @@ +import QtQuick +import QtQml.Models + +Item { + property var visualIndexBeforeMove: [-1, -1, -1] + property var visualIndexAfterMove: [-1, -1, -1] + + DelegateModel { + id: visualModel + model: ListModel { + ListElement { name: "Apple (id 0)" } + ListElement { name: "Orange (id 1)" } + ListElement { name: "Banana (id 2)" } + } + + delegate: DropArea { + id: delegateRoot + + required property string name + // property that was not updated correctly in QTBUG-104047 + readonly property int visualIndex: DelegateModel.itemsIndex + Rectangle { + id: child + + readonly property int visualIndex: delegateRoot.visualIndex + } + } + } + + Repeater { + id: root + model: visualModel + } + + Component.onCompleted: { + visualIndexBeforeMove[0] = root.itemAt(0).visualIndex + visualIndexBeforeMove[1] = root.itemAt(1).visualIndex + visualIndexBeforeMove[2] = root.itemAt(2).visualIndex + visualModel.items.move(2, 0) + // test that bindings on the QQmlDelegateModelAttached are captured properly: + // after the move, the visualIndex property should be updated to the new value, + // which in this case is also the index used in itemAt() + visualIndexAfterMove[0] = root.itemAt(0).visualIndex + visualIndexAfterMove[1] = root.itemAt(1).visualIndex + visualIndexAfterMove[2] = root.itemAt(2).visualIndex + } + +} diff --git a/tests/auto/qml/qmlcppcodegen/data/storeElementSideEffects.qml b/tests/auto/qml/qmlcppcodegen/data/storeElementSideEffects.qml new file mode 100644 index 0000000000..273f08aad5 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/storeElementSideEffects.qml @@ -0,0 +1,6 @@ +import QtQml + +QtObject { + property var myItem: [] + Component.onCompleted: myItem[0] = 10 +} diff --git a/tests/auto/qml/qmlcppcodegen/data/typePropagationLoop.qml b/tests/auto/qml/qmlcppcodegen/data/typePropagationLoop.qml new file mode 100644 index 0000000000..b2fdabfd2d --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/typePropagationLoop.qml @@ -0,0 +1,9 @@ +import QtQml + +QtObject { + property int j: { + var tmp = Qt.PartiallyChecked + for (var i = 0; i < Qt.Checked; i++) {} + return tmp + i; + } +} diff --git a/tests/auto/qml/qmlcppcodegen/data/undefinedToDouble.qml b/tests/auto/qml/qmlcppcodegen/data/undefinedToDouble.qml new file mode 100644 index 0000000000..e76443a2e0 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/undefinedToDouble.qml @@ -0,0 +1,6 @@ +pragma Strict +import QtQml + +QtObject { + property double d: Math.max(undefined, 40) +} diff --git a/tests/auto/qml/qmlcppcodegen/data/versionmismatch.qml b/tests/auto/qml/qmlcppcodegen/data/versionmismatch.qml new file mode 100644 index 0000000000..2fa163c047 --- /dev/null +++ b/tests/auto/qml/qmlcppcodegen/data/versionmismatch.qml @@ -0,0 +1,10 @@ +import QtQml +import TestTypes 1.0 + +QtObject { + property int inaccessible: 4 + property CppBaseClass a: CppBaseClass { + property int b: inaccessible + 1 + } + property int c: a.b +} diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 186758518e..7d302d611f 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -2,6 +2,7 @@ #include <data/birthdayparty.h> #include <data/cppbaseclass.h> +#include <data/enumproblems.h> #include <data/objectwithmethod.h> #include <QtQml/private/qqmlengine_p.h> @@ -132,6 +133,16 @@ private slots: void stringToByteArray(); void listPropertyAsModel(); void notNotString(); + void inaccessibleProperty(); + void typePropagationLoop(); + void nullComparison(); + void signalIndexMismatch(); + void callWithSpread(); + void enumConversion(); + void enumProblems(); + void storeElementSideEffects(); + void undefinedToDouble(); + void enumFromBadSingleton(); }; void tst_QmlCppCodegen::simpleBinding() @@ -1956,8 +1967,19 @@ void tst_QmlCppCodegen::typedArray() QList<int>({1, 2, 3, 4})); QCOMPARE(qvariant_cast<QList<QDateTime>>(o->property("values4")), QList<QDateTime>({date, date, date})); - QCOMPARE(qvariant_cast<QList<double>>(o->property("values5")), - QList<double>({1, 2, 3.4, 30, 0, 0})); + { + const QList<double> actual + = qvariant_cast<QList<double>>(o->property("values5")); + const QList<double> expected + = QList<double>({1, 2, 3.4, 30, std::numeric_limits<double>::quiet_NaN(), 0}); + QCOMPARE(actual.size(), expected.size()); + for (qsizetype i = 0, end = actual.size(); i != end; ++i) { + if (std::isnan(expected[i])) + QVERIFY(std::isnan(actual[i])); + else + QCOMPARE(actual[i], expected[i]); + } + } date = QDateTime::currentDateTime(); o->setProperty("aDate", date); QCOMPARE(qvariant_cast<QList<QDateTime>>(o->property("values4")), @@ -2366,6 +2388,7 @@ void tst_QmlCppCodegen::badSequence() other->setBarzles(barzles); QCOMPARE(self->barzles(), barzles); + QCOMPARE(self->property("l").toInt(), 2); } void tst_QmlCppCodegen::enumLookup() @@ -2438,6 +2461,151 @@ void tst_QmlCppCodegen::runInterpreted() #endif } +void tst_QmlCppCodegen::inaccessibleProperty() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/versionmismatch.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + + QCOMPARE(o->property("c").toInt(), 5); +} + +void tst_QmlCppCodegen::typePropagationLoop() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/typePropagationLoop.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + + QCOMPARE(o->property("j").toInt(), 3); +} + +void tst_QmlCppCodegen::nullComparison() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/nullComparison.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + + QCOMPARE(o->property("v").toInt(), 1); + QCOMPARE(o->property("w").toInt(), 3); + QCOMPARE(o->property("x").toInt(), 1); + QCOMPARE(o->property("y").toInt(), 5); +} + +void tst_QmlCppCodegen::signalIndexMismatch() +{ + QQmlEngine engine; + + QQmlComponent c1(&engine, QUrl(u"qrc:/TestTypes/signalIndexMismatch.qml"_s)); + QVERIFY2(c1.isReady(), qPrintable(c1.errorString())); + + QScopedPointer<QObject> item(c1.create()); + const auto visualIndexBeforeMoveList = item->property("visualIndexBeforeMove").toList(); + const auto visualIndexAfterMoveList = item->property("visualIndexAfterMove").toList(); + + QCOMPARE(visualIndexBeforeMoveList, QList<QVariant>({ 0, 1, 2 })); + QCOMPARE(visualIndexAfterMoveList, QList<QVariant>({ 0, 1, 2 })); +} + +void tst_QmlCppCodegen::callWithSpread() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/callWithSpread.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QTest::ignoreMessage(QtCriticalMsg, "That is great!"); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); +}; + +void tst_QmlCppCodegen::enumConversion() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/enumConversion.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + QCOMPARE(o->property("test").toInt(), 0x04); + QCOMPARE(o->property("test_1").toBool(), true); +}; + +void tst_QmlCppCodegen::enumProblems() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/enumProblems.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> outer(c.create()); + QVERIFY(!outer.isNull()); + QObject *inner = outer->property("o").value<QObject *>(); + QVERIFY(inner); + + Foo *bar = inner->property("bar").value<Foo *>(); + QVERIFY(bar); + QCOMPARE(bar->type(), Foo::Component); + + Foo *fighter = inner->property("fighter").value<Foo *>(); + QVERIFY(fighter); + QCOMPARE(fighter->type(), Foo::Fighter); +} + +void tst_QmlCppCodegen::storeElementSideEffects() +{ + QQmlEngine engine; + + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/storeElementSideEffects.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + + const QJSValue prop = o->property("myItem").value<QJSValue>(); + QVERIFY(prop.isArray()); + QCOMPARE(prop.property(0).toInt(), 10); +}; + +void tst_QmlCppCodegen::undefinedToDouble() +{ + QQmlEngine engine; + QQmlComponent c(&engine, QUrl(u"qrc:/TestTypes/undefinedToDouble.qml"_s)); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + const QVariant d = o->property("d"); + QCOMPARE(d.metaType(), QMetaType::fromType<double>()); + QVERIFY(std::isnan(d.toDouble())); +} + +void tst_QmlCppCodegen::enumFromBadSingleton() +{ + QQmlEngine e; + const QUrl url(u"qrc:/TestTypes/enumFromBadSingleton.qml"_s); + QQmlComponent c(&e, url); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + +#if QT_DEPRECATED_SINCE(6,4) + QTest::ignoreMessage( + QtWarningMsg, qPrintable( + url.toString() + + u":5:5: TypeError: Cannot read property 'TestA' of undefined"_s)); +#else + QTest::ignoreMessage( + QtWarningMsg, qPrintable( + url.toString() + + u":5:5: ReferenceError: DummyObjekt is not defined"_s)); +#endif + + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + QVERIFY(o->objectName().isEmpty()); +} + QTEST_MAIN(tst_QmlCppCodegen) #include "tst_qmlcppcodegen.moc" diff --git a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp index dc4b66e8f9..7aeb23a398 100644 --- a/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp +++ b/tests/auto/qml/qmldiskcache/tst_qmldiskcache.cpp @@ -40,6 +40,7 @@ private slots: void cppRegisteredSingletonDependency(); void cacheModuleScripts(); void reuseStaticMappings(); + void invalidateSaveLoadCache(); private: QDir m_qmlCacheDirectory; @@ -527,6 +528,7 @@ void tst_qmldiskcache::recompileAfterChange() CleanlyLoadingComponent component(&engine, testCompiler.testFilePath); QScopedPointer<TypeVersion2> obj(qobject_cast<TypeVersion2*>(component.create())); QVERIFY(!obj.isNull()); + qDebug() << obj->property("x"); QVERIFY(QFileInfo(testCompiler.cacheFilePath).lastModified() > initialCacheTimeStamp); } } @@ -697,7 +699,7 @@ void tst_qmldiskcache::cacheResources() } const QSet<QString> entries = entrySet(m_qmlCacheDirectory).subtract(existingFiles); - QCOMPARE(entries.count(), 1); + QCOMPARE(entries.size(), 1); QDateTime cacheFileTimeStamp; @@ -726,7 +728,7 @@ void tst_qmldiskcache::cacheResources() { const QSet<QString> entries = entrySet(m_qmlCacheDirectory).subtract(existingFiles); - QCOMPARE(entries.count(), 1); + QCOMPARE(entries.size(), 1); QCOMPARE(QFileInfo(m_qmlCacheDirectory.absoluteFilePath(*entries.cbegin())).lastModified().toMSecsSinceEpoch(), cacheFileTimeStamp.toMSecsSinceEpoch()); @@ -972,7 +974,7 @@ void tst_qmldiskcache::cacheModuleScripts() const QSet<QString> entries = entrySet(m_qmlCacheDirectory, QStringList("*.mjsc")); - QCOMPARE(entries.count(), 1); + QCOMPARE(entries.size(), 1); QDateTime cacheFileTimeStamp; @@ -1007,6 +1009,112 @@ void tst_qmldiskcache::reuseStaticMappings() QCOMPARE(testCompiler.unitData(), data1); } +class AParent : public QObject +{ + Q_OBJECT + Q_PROPERTY(int x MEMBER x) +public: + AParent(QObject *parent = nullptr) : QObject(parent) {} + int x = 25; +}; + +class BParent : public QObject +{ + Q_OBJECT + + // Insert y before x, to change the property index of x + Q_PROPERTY(int y MEMBER y) + + Q_PROPERTY(int x MEMBER x) +public: + BParent(QObject *parent = nullptr) : QObject(parent) {} + int y = 13; + int x = 25; +}; + +static QString writeTempFile( + const QTemporaryDir &tempDir, const QString &fileName, const char *contents) { + QFile f(tempDir.path() + '/' + fileName); + const bool ok = f.open(QIODevice::WriteOnly | QIODevice::Truncate); + Q_ASSERT(ok); + f.write(contents); + return f.fileName(); +}; + +void tst_qmldiskcache::invalidateSaveLoadCache() +{ + qmlRegisterType<AParent>("Base", 1, 0, "Parent"); + QQmlEngine e; + + // If you store a CU to a .qmlc file at run time, the .qmlc file will contain + // alias entries with the encodedMetaPropertyIndex pre-resolved. That's in + // contrast to .qmlc files generated ahead of time. Exploit that to cause + // a need to recompile the file. + + QTemporaryDir tempDir; + const QString fileName = writeTempFile( + tempDir, QLatin1String("a.qml"), + "import Base\nParent { id: self; property alias z: self.x }"); + const QUrl url = QUrl::fromLocalFile(fileName); + waitForFileSystem(); + + { + QQmlComponent a(&e, url); + QVERIFY2(a.isReady(), qPrintable(a.errorString())); + QScopedPointer<QObject> ao(a.create()); + QVERIFY(!ao.isNull()); + AParent *ap = qobject_cast<AParent *>(ao.data()); + QCOMPARE(ap->property("z").toInt(), ap->x); + } + + QString errorString; + QQmlRefPointer<QV4::ExecutableCompilationUnit> oldUnit + = QV4::ExecutableCompilationUnit::create(); + QVERIFY2(oldUnit->loadFromDisk(url, QFileInfo(fileName).lastModified(), &errorString), qPrintable(errorString)); + + // Produce a checksum mismatch. + e.clearComponentCache(); + qmlClearTypeRegistrations(); + qmlRegisterType<BParent>("Base", 1, 0, "Parent"); + + { + QQmlComponent b(&e, url); + QVERIFY2(b.isReady(), qPrintable(b.errorString())); + QScopedPointer<QObject> bo(b.create()); + QVERIFY(!bo.isNull()); + BParent *bp = qobject_cast<BParent *>(bo.data()); + QCOMPARE(bp->property("z").toInt(), bp->x); + } + + // Make it recompile again. + e.clearComponentCache(); + { + QFile file(fileName); + file.open(QIODevice::WriteOnly | QIODevice::Append); + file.write(" "); + } + waitForFileSystem(); + + { + QQmlComponent b(&e, url); + QVERIFY2(b.isReady(), qPrintable(b.errorString())); + QScopedPointer<QObject> bo(b.create()); + QVERIFY(!bo.isNull()); + BParent *bp = qobject_cast<BParent *>(bo.data()); + QCOMPARE(bp->property("z").toInt(), bp->x); + } + + // Verify that the mapped unit data is actually different now. + // The cache should have been invalidated after all. + // So, now we should be able to load a freshly written CU. + + QQmlRefPointer<QV4::ExecutableCompilationUnit> unit + = QV4::ExecutableCompilationUnit::create(); + QVERIFY2(unit->loadFromDisk(url, QFileInfo(fileName).lastModified(), &errorString), qPrintable(errorString)); + + QVERIFY(unit->unitData() != oldUnit->unitData()); +} + QTEST_MAIN(tst_qmldiskcache) #include "tst_qmldiskcache.moc" diff --git a/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml b/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml new file mode 100644 index 0000000000..0c7a2829c9 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/dontRemoveComments.formatted.qml @@ -0,0 +1,13 @@ +Item { + property var test: [{ + // Testing + "foo": "bar" + }] + + onTestChanged: { + fooBar(test, { + // Testing + "foo": "bar" + }); + } +} diff --git a/tests/auto/qml/qmlformat/data/dontRemoveComments.qml b/tests/auto/qml/qmlformat/data/dontRemoveComments.qml new file mode 100644 index 0000000000..1797834879 --- /dev/null +++ b/tests/auto/qml/qmlformat/data/dontRemoveComments.qml @@ -0,0 +1,13 @@ +Item { + property var test: [{ +// Testing + "foo": "bar" + }] + + onTestChanged: { + fooBar(test, { + // Testing + "foo": "bar" + }); + } +} diff --git a/tests/auto/qml/qmlformat/tst_qmlformat.cpp b/tests/auto/qml/qmlformat/tst_qmlformat.cpp index 9d7beb23a7..bc59b8dce1 100644 --- a/tests/auto/qml/qmlformat/tst_qmlformat.cpp +++ b/tests/auto/qml/qmlformat/tst_qmlformat.cpp @@ -147,7 +147,7 @@ void TestQmlformat::initTestCase() QStringList TestQmlformat::findFiles(const QDir &d) { - for (int ii = 0; ii < m_excludedDirs.count(); ++ii) { + for (int ii = 0; ii < m_excludedDirs.size(); ++ii) { QString s = m_excludedDirs.at(ii); if (d.absolutePath().endsWith(s)) return QStringList(); @@ -276,6 +276,9 @@ void TestQmlformat::testFormat_data() QTest::newRow("forWithLet") << "forWithLet.qml" << "forWithLet.formatted.qml" << QStringList {} << RunOption::OnCopy; + QTest::newRow("dontRemoveComments") + << "dontRemoveComments.qml" + << "dontRemoveComments.formatted.qml" << QStringList {} << RunOption::OnCopy; } void TestQmlformat::testFormat() diff --git a/tests/auto/qml/qmllint/data/Foo.qml b/tests/auto/qml/qmllint/data/Foo.qml new file mode 100644 index 0000000000..6e47488e95 --- /dev/null +++ b/tests/auto/qml/qmllint/data/Foo.qml @@ -0,0 +1,5 @@ +import QtQml + +QtObject { + function whatSUp() : string { return "I'm crashing"; } +} diff --git a/tests/auto/qml/qmllint/data/callBase.qml b/tests/auto/qml/qmllint/data/callBase.qml new file mode 100644 index 0000000000..435a5f04dd --- /dev/null +++ b/tests/auto/qml/qmllint/data/callBase.qml @@ -0,0 +1,7 @@ +import QtQml + +QtObject { + function bar(foo : Foo) { + var state = foo.whatSUp() + } +} diff --git a/tests/auto/qml/qmllint/data/enumsOfScrollBar.qml b/tests/auto/qml/qmllint/data/enumsOfScrollBar.qml new file mode 100644 index 0000000000..d0cd5591b9 --- /dev/null +++ b/tests/auto/qml/qmllint/data/enumsOfScrollBar.qml @@ -0,0 +1,7 @@ +import QtQuick +import QtQuick.Controls + +Item { + Component.onCompleted: console.log(ScrollBar.AlwaysOn) +} + diff --git a/tests/auto/qml/qmllint/data/inlineComponentNoComponent.qml b/tests/auto/qml/qmllint/data/inlineComponentNoComponent.qml new file mode 100644 index 0000000000..f72b0a27c5 --- /dev/null +++ b/tests/auto/qml/qmllint/data/inlineComponentNoComponent.qml @@ -0,0 +1,5 @@ +import QtQuick 2.0 +Item { + component Base : eItm { } +} + diff --git a/tests/auto/qml/qmllint/data/invalidAliasTarget.qml b/tests/auto/qml/qmllint/data/invalidAliasTarget.qml new file mode 100644 index 0000000000..e6ad63b518 --- /dev/null +++ b/tests/auto/qml/qmllint/data/invalidAliasTarget.qml @@ -0,0 +1,11 @@ +import QtQuick + +Item { + Item { + + property alias innerinner + property alias name: function f() {} + + property alias innerObj: 1+1 + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index e0e690ed99..d28390b719 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -89,6 +89,8 @@ private Q_SLOTS: void importMultipartUri(); + void testLineEndings(); + #if QT_CONFIG(library) void testPlugin(); void quickPlugin(); @@ -449,6 +451,18 @@ void TestQmllint::dirtyQmlCode_data() << Result { { Message { QStringLiteral("Alias \"a\" is part of an alias cycle"), 3, 1 } } }; + QTest::newRow("invalidAliasTarget1") << QStringLiteral("invalidAliasTarget.qml") + << Result { { Message { + QStringLiteral("Invalid alias expression – an initalizer is needed."), + 6, 18 } } }; + QTest::newRow("invalidAliasTarget2") << QStringLiteral("invalidAliasTarget.qml") + << Result { { Message { + QStringLiteral("Invalid alias expression. Only IDs and field member expressions can be aliased"), + 7, 30 } } }; + QTest::newRow("invalidAliasTarget3") << QStringLiteral("invalidAliasTarget.qml") + << Result { { Message { + QStringLiteral("Invalid alias expression. Only IDs and field member expressions can be aliased"), + 9, 34 } } }; QTest::newRow("badParent") << QStringLiteral("badParent.qml") << Result { { Message { QStringLiteral("Property \"rrr\" not found on type \"Item\""), @@ -782,6 +796,11 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", << QStringLiteral("nestedInlineComponents.qml") << Result { { Message { QStringLiteral("Nested inline components are not supported") } } }; + QTest::newRow("inlineComponentNoComponent") + << QStringLiteral("inlineComponentNoComponent.qml") + << Result { { Message { + QStringLiteral("Inline component declaration must be followed by a typename"), + 3, 2 } } }; QTest::newRow("WithStatement") << QStringLiteral("WithStatement.qml") << Result { { Message { QStringLiteral( "with statements are strongly discouraged") } } }; @@ -1145,6 +1164,8 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("BindingTypeMismatchFunction") << QStringLiteral("bindingTypeMismatchFunction.qml"); QTest::newRow("BindingTypeMismatch") << QStringLiteral("bindingTypeMismatch.qml"); QTest::newRow("template literal (substitution)") << QStringLiteral("templateStringSubstitution.qml"); + QTest::newRow("enumsOfScrollBar") << QStringLiteral("enumsOfScrollBar.qml"); + QTest::newRow("callBase") << QStringLiteral("callBase.qml"); } void TestQmllint::cleanQmlCode() @@ -1618,6 +1639,36 @@ void TestQmllint::importMultipartUri() runTest("here.qml", Result::clean(), {}, { testFile("Elsewhere/qmldir") }); } +void TestQmllint::testLineEndings() +{ + { + const auto textWithLF = QString::fromUtf16(u"import QtQuick 2.0\nimport QtTest 2.0 // qmllint disable unused-imports\n" + "import QtTest 2.0 // qmllint disable\n\nItem {\n @Deprecated {}\n property string deprecated\n\n " + "property string a: root.a // qmllint disable unqualifi77777777777777777777777777777777777777777777777777777" + "777777777777777777777777777777777777ed\n property string b: root.a // qmllint di000000000000000000000000" + "000000000000000000inyyyyyyyyg c: root.a\n property string d: root.a\n // qmllint enable unqualified\n\n " + "//qmllint d 4isable\n property string e: root.a\n Component.onCompleted: {\n console.log" + "(deprecated);\n }\n // qmllint enable\n\n}\n"); + + const auto lintResult = m_linter.lintFile( {}, &textWithLF, true, nullptr, {}, {}, {}, {}); + + QCOMPARE(lintResult, QQmlJSLinter::LintResult::HasWarnings); + } + { + const auto textWithCRLF = QString::fromUtf16(u"import QtQuick 2.0\nimport QtTest 2.0 // qmllint disable unused-imports\n" + "import QtTest 2.0 // qmllint disable\n\nItem {\n @Deprecated {}\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r" + "\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\r\n property string deprecated\n\n property string a: root.a " + "// qmllint disable unqualifi77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777ed\n " + "property string b: root.a // qmllint di000000000000000000000000000000000000000000inyyyyyyyyg c: root.a\n property string d: " + "root.a\n // qmllint enable unqualified\n\n //qmllint d 4isable\n property string e: root.a\n Component.onCompleted: " + "{\n console.log(deprecated);\n }\n // qmllint enable\n\n}\n"); + + const auto lintResult = m_linter.lintFile( {}, &textWithCRLF, true, nullptr, {}, {}, {}, {}); + + QCOMPARE(lintResult, QQmlJSLinter::LintResult::HasWarnings); + } +} + #if QT_CONFIG(library) void TestQmllint::testPlugin() { diff --git a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt index 45fc2492dd..cf3cd41fa4 100644 --- a/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt +++ b/tests/auto/qml/qmltc/QmltcTests/CMakeLists.txt @@ -90,6 +90,8 @@ set(qml_sources deferredProperties_group.qml deferredProperties_attached.qml deferredProperties_complex.qml + repeaterCrash.qml + aliases.qml # support types: DefaultPropertySingleChild.qml @@ -98,6 +100,9 @@ set(qml_sources LocalWithOnCompleted.qml LocallyImported_context.qml # SingletonThing.qml + ComponentWithAlias1.qml + ComponentWithAlias2.qml + ComponentWithAlias3.qml badFile.qml ) diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml new file mode 100644 index 0000000000..210cf1e159 --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias1.qml @@ -0,0 +1,8 @@ +import QtQuick + +Item { + property alias setMe: firstComponent.setMe + ComponentWithAlias2 { + id: firstComponent + } +} diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml new file mode 100644 index 0000000000..818f3a464e --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias2.qml @@ -0,0 +1,8 @@ +import QtQuick + +Item { + property alias setMe: firstComponent.setMe + ComponentWithAlias3 { + id: firstComponent + } +} diff --git a/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml new file mode 100644 index 0000000000..87b917ad19 --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/ComponentWithAlias3.qml @@ -0,0 +1,5 @@ +import QtQuick + +Item { + property string setMe: "Set me!" +} diff --git a/tests/auto/qml/qmltc/QmltcTests/aliases.qml b/tests/auto/qml/qmltc/QmltcTests/aliases.qml new file mode 100644 index 0000000000..9f13f7b17a --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/aliases.qml @@ -0,0 +1,29 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Item { + property alias aliasToAlias: subItem.aliasToAlias + Item { + id: subItem + property alias aliasToAlias: subsubItem.aliasToAlias + + Item { + id: subsubItem + property alias aliasToAlias: subsubsubItem.value + + Item { + id: subsubsubItem + property string value: "Hello World!" + } + } + } + + property alias aliasToOtherFile: inOtherFile.setMe + + ComponentWithAlias1 { + id: inOtherFile + } +} + diff --git a/tests/auto/qml/qmltc/QmltcTests/repeaterCrash.qml b/tests/auto/qml/qmltc/QmltcTests/repeaterCrash.qml new file mode 100644 index 0000000000..7c4dad5a4e --- /dev/null +++ b/tests/auto/qml/qmltc/QmltcTests/repeaterCrash.qml @@ -0,0 +1,22 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Item { + Item { + property string objName: "Child1" + } + + Repeater { + model: 4 + + Item { + property string objName: "Child" + (index + 1) + } + } + + Item { + property string objName: "Child6" + } +} diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp index 5a0d7eea9d..f958b1880b 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.cpp +++ b/tests/auto/qml/qmltc/tst_qmltc.cpp @@ -69,7 +69,8 @@ #include "privatepropertysubclass.h" #include "calqlatrbits.h" #include "propertychangeandsignalhandlers.h" - +#include "repeatercrash.h" +#include "aliases.h" #include "testprivateproperty.h" // Qt: @@ -1052,8 +1053,8 @@ void tst_qmltc::propertyAlias_external() QSignalSpy heightAliasChangedSpy(&created, &PREPEND_NAMESPACE(propertyAlias_external)::heightAliasChanged); created.setHeight(10); QCOMPARE(created.heightAlias(), 10); - QCOMPARE(heightChangedSpy.count(), 1); - QCOMPARE(heightAliasChangedSpy.count(), 1); + QCOMPARE(heightChangedSpy.size(), 1); + QCOMPARE(heightAliasChangedSpy.size(), 1); } // TODO: we need to support RESET in aliases as well? (does it make sense?) @@ -1138,15 +1139,15 @@ void tst_qmltc::complexAliases() created.setAFont(newFont); QCOMPARE(created.aFont(), newFont); QCOMPARE(created.aFont(), theText->property("font").value<QFont>()); - QCOMPARE(aFontSpy.count(), 1); + QCOMPARE(aFontSpy.size(), 1); newFont.setStyle(QFont::StyleOblique); theText->setProperty("font", newFont); QCOMPARE(theText->property("font").value<QFont>(), newFont); QCOMPARE(created.aFont(), theText->property("font").value<QFont>()); - QCOMPARE(aFontSpy.count(), 2); + QCOMPARE(aFontSpy.size(), 2); created.setAWordSpacing(1); - QCOMPARE(aFontSpy.count(), 3); + QCOMPARE(aFontSpy.size(), 3); // aliasToObjectAlias: QCOMPARE(created.aliasToObjectAlias(), created.aRectObject()); @@ -1181,12 +1182,12 @@ void tst_qmltc::complexAliases() QCOMPARE(created.aliasToValueTypeAlias(), newFont); QCOMPARE(created.aliasToValueTypeAlias(), created.aFont()); QCOMPARE(created.aliasToValueTypeAlias(), theText->property("font").value<QFont>()); - QCOMPARE(aFontSpy.count(), 4); - QCOMPARE(aliasToValueTypeAliasSpy.count(), 1); + QCOMPARE(aFontSpy.size(), 4); + QCOMPARE(aliasToValueTypeAliasSpy.size(), 1); newFont.setPixelSize(12); created.setAFont(newFont); - QCOMPARE(aFontSpy.count(), 5); - QCOMPARE(aliasToValueTypeAliasSpy.count(), 2); + QCOMPARE(aFontSpy.size(), 5); + QCOMPARE(aliasToValueTypeAliasSpy.size(), 2); QCOMPARE(created.aliasToValueTypeAlias(), created.aFont()); QCOMPARE(created.aliasToValueTypeAlias(), theText->property("font").value<QFont>()); @@ -1195,8 +1196,8 @@ void tst_qmltc::complexAliases() created.setAliasToPropertyOfValueTypeAlias(3); QCOMPARE(created.aliasToPropertyOfValueTypeAlias(), created.aFont().pixelSize()); QCOMPARE(created.aFont(), theText->property("font").value<QFont>()); - QCOMPARE(aFontSpy.count(), 6); - QCOMPARE(aliasToValueTypeAliasSpy.count(), 3); + QCOMPARE(aFontSpy.size(), 6); + QCOMPARE(aliasToValueTypeAliasSpy.size(), 3); // aliasToImportedMessage: QCOMPARE(created.aliasToImportedMessage(), localImport->property("message").toString()); @@ -1234,7 +1235,7 @@ void tst_qmltc::complexAliases() newPalette->fromQPalette(QPalette(QColor(u"cyan"_s))); QCOMPARE(newPalette->button(), QColor(u"cyan"_s)); created.setAliasToPrivatePalette(newPalette); - QCOMPARE(paletteChangedSpy.count(), 1); + QCOMPARE(paletteChangedSpy.size(), 1); QCOMPARE(QQuickItemPrivate::get(theRect)->palette()->button(), QColor(u"cyan"_s)); QCOMPARE(created.aliasToPrivatePalette(), QQuickItemPrivate::get(theRect)->palette()); @@ -1316,9 +1317,9 @@ void tst_qmltc::componentHelloWorld() QCOMPARE(created->hello(), QStringLiteral("Hello, World!")); QSignalSpy onDestroySpy(created.get(), &PREPEND_NAMESPACE(ComponentHelloWorld)::sDestroying); - QCOMPARE(onDestroySpy.count(), 0); + QCOMPARE(onDestroySpy.size(), 0); created.reset(); - QCOMPARE(onDestroySpy.count(), 1); + QCOMPARE(onDestroySpy.size(), 1); } void tst_qmltc::propertyReturningFunction() @@ -2091,7 +2092,7 @@ void tst_qmltc::calqlatrBits() QSignalSpy scaleChangedSpy(textItem, &QQuickItem::scaleChanged); controller->completeToBeginning(); - QTRY_VERIFY(scaleChangedSpy.count() > 0); + QTRY_VERIFY(scaleChangedSpy.size() > 0); } void tst_qmltc::trickyPropertyChangeAndSignalHandlers() @@ -2161,4 +2162,66 @@ void tst_qmltc::trickyPropertyChangeAndSignalHandlers() QCOMPARE(created.cChangedCount3(), 22); } +void tst_qmltc::repeaterCrash() +{ + QQmlEngine e; + PREPEND_NAMESPACE(repeaterCrash) fromQmltc(&e); + + QQmlComponent component(&e, "qrc:/QmltcTests/repeaterCrash.qml"); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QQuickItem> fromEngine(qobject_cast<QQuickItem *>(component.create())); + QVERIFY(fromEngine); + + const int size = 7; + + const auto listFromEngine = fromEngine->childItems(); + const auto listFromQmltc = fromQmltc.childItems(); + + QCOMPARE(listFromEngine.size(), size); + QCOMPARE(listFromQmltc.size(), size); + + for (int i = 0; i < size; i++) { + // the repeater itself has no objName property + if (i == 5) + continue; + + const QVariant nameFromEngine = listFromEngine.at(i)->property("objName"); + const QVariant nameFromQmltc = listFromQmltc.at(i)->property("objName"); + + QVERIFY(nameFromEngine.isValid()); + QVERIFY(nameFromQmltc.isValid()); + QCOMPARE(nameFromQmltc.toString(), nameFromEngine.toString()); + } +} + +void tst_qmltc::aliases() +{ + QQmlEngine e; + PREPEND_NAMESPACE(aliases) fromQmltc(&e); + + QQmlComponent component(&e); + component.loadUrl(QUrl("qrc:/QmltcTests/aliases.qml")); + QVERIFY2(!component.isError(), qPrintable(component.errorString())); + QScopedPointer<QObject> fromComponent(component.create()); + const QString testString = u"myTestString"_s; + + QCOMPARE(fromQmltc.aliasToAlias(), u"Hello World!"_s); + QCOMPARE(fromComponent->property("aliasToAlias"), u"Hello World!"_s); + + fromQmltc.setAliasToAlias(testString); + QVERIFY(fromComponent->setProperty("aliasToAlias", testString)); + + QCOMPARE(fromQmltc.aliasToAlias(), testString); + QCOMPARE(fromComponent->property("aliasToAlias"), testString); + + QCOMPARE(fromQmltc.aliasToOtherFile(), u"Set me!"_s); + QCOMPARE(fromComponent->property("aliasToOtherFile"), u"Set me!"_s); + + fromQmltc.setAliasToOtherFile(testString); + QVERIFY(fromComponent->setProperty("aliasToOtherFile", testString)); + + QCOMPARE(fromQmltc.aliasToOtherFile(), testString); + QCOMPARE(fromComponent->property("aliasToOtherFile"), testString); +} + QTEST_MAIN(tst_qmltc) diff --git a/tests/auto/qml/qmltc/tst_qmltc.h b/tests/auto/qml/qmltc/tst_qmltc.h index 19f225a548..bbc3be73a7 100644 --- a/tests/auto/qml/qmltc/tst_qmltc.h +++ b/tests/auto/qml/qmltc/tst_qmltc.h @@ -82,4 +82,6 @@ private slots: void privateProperties(); void calqlatrBits(); // corner cases from calqlatr demo void trickyPropertyChangeAndSignalHandlers(); + void repeaterCrash(); + void aliases(); }; diff --git a/tests/auto/qml/qmltc_qprocess/data/kebab-case.qml b/tests/auto/qml/qmltc_qprocess/data/kebab-case.qml new file mode 100644 index 0000000000..68c21087cb --- /dev/null +++ b/tests/auto/qml/qmltc_qprocess/data/kebab-case.qml @@ -0,0 +1,5 @@ +import QtQuick 2.15 + +Item { + +} diff --git a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp index b3079334b6..911906f44d 100644 --- a/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp +++ b/tests/auto/qml/qmltc_qprocess/tst_qmltc_qprocess.cpp @@ -47,6 +47,7 @@ private slots: void inlineComponent(); void singleton(); void warningsAsErrors(); + void dashesInFilename(); }; #ifndef TST_QMLTC_QPROCESS_RESOURCES @@ -192,5 +193,14 @@ void tst_qmltc_qprocess::warningsAsErrors() QVERIFY2(errors.contains(u"Error:"_s), qPrintable(errors)); // Note: not a warning! } +void tst_qmltc_qprocess::dashesInFilename() +{ + { + const auto errors = runQmltc(u"kebab-case.qml"_s, false); + QVERIFY(errors.contains( + u"The given QML filename is unsuited for type compilation: the name must consist of letters, digits and underscores, starting with a letter or an underscore and ending in '.qml'!"_s)); + } +} + QTEST_MAIN(tst_qmltc_qprocess) #include "tst_qmltc_qprocess.moc" diff --git a/tests/auto/qml/qqmlapplicationengine/androidassets/tst_androidassets.cpp b/tests/auto/qml/qqmlapplicationengine/androidassets/tst_androidassets.cpp index 4ba7deb98e..7a6774c268 100644 --- a/tests/auto/qml/qqmlapplicationengine/androidassets/tst_androidassets.cpp +++ b/tests/auto/qml/qqmlapplicationengine/androidassets/tst_androidassets.cpp @@ -41,7 +41,7 @@ void tst_AndroidAssets::loadsFromAssetsPath() // load QML file from assets, by path: engine.load(pathPrefix() + QStringLiteral("/qml/main.qml")); - QTRY_VERIFY(engine.rootObjects().length() == 1); + QTRY_VERIFY(engine.rootObjects().size() == 1); QVERIFY(failureSpy.isEmpty()); } @@ -52,7 +52,7 @@ void tst_AndroidAssets::loadsFromAssetsUrl() // load QML file from assets, by URL: engine.load(QUrl(urlPrefix() + QStringLiteral("/qml/main.qml"))); - QTRY_VERIFY(engine.rootObjects().length() == 1); + QTRY_VERIFY(engine.rootObjects().size() == 1); QVERIFY(failureSpy.isEmpty()); } diff --git a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp index 43f7296d4f..d0f580cf5f 100644 --- a/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp +++ b/tests/auto/qml/qqmlapplicationengine/tst_qqmlapplicationengine.cpp @@ -57,14 +57,14 @@ void tst_qqmlapplicationengine::basicLoading() QSignalSpy objectCreated(test, SIGNAL(objectCreated(QObject*,QUrl))); test->load(testFileUrl("basicTest.qml")); - QCOMPARE(objectCreated.count(), size);//one less than rootObjects().size() because we missed the first one + QCOMPARE(objectCreated.size(), size);//one less than rootObjects().size() because we missed the first one QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); QByteArray testQml("import QtQml 2.0; QtObject{property bool success: true; property TestItem t: TestItem{}}"); test->loadData(testQml, testFileUrl("dynamicTest.qml")); - QCOMPARE(objectCreated.count(), size); + QCOMPARE(objectCreated.size(), size); QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); @@ -215,10 +215,10 @@ void tst_qqmlapplicationengine::applicationProperties() QCoreApplication::setOrganizationName(originalOrganization); QCoreApplication::setOrganizationDomain(originalDomain); - QCOMPARE(nameChanged.count(), 1); - QCOMPARE(versionChanged.count(), 1); - QCOMPARE(organizationChanged.count(), 1); - QCOMPARE(domainChanged.count(), 1); + QCOMPARE(nameChanged.size(), 1); + QCOMPARE(versionChanged.size(), 1); + QCOMPARE(organizationChanged.size(), 1); + QCOMPARE(domainChanged.size(), 1); delete test; } @@ -230,12 +230,12 @@ void tst_qqmlapplicationengine::removeObjectsWhenDestroyed() QSignalSpy objectCreated(test.data(), SIGNAL(objectCreated(QObject*,QUrl))); test->load(testFileUrl("basicTest.qml")); - QCOMPARE(objectCreated.count(), 1); + QCOMPARE(objectCreated.size(), 1); QSignalSpy objectDestroyed(test->rootObjects().first(), SIGNAL(destroyed())); test->rootObjects().first()->deleteLater(); objectDestroyed.wait(); - QCOMPARE(objectDestroyed.count(), 1); + QCOMPARE(objectDestroyed.size(), 1); QCOMPARE(test->rootObjects().size(), 0); } @@ -315,7 +315,7 @@ void tst_qqmlapplicationengine::failureToLoadTriggersWarningSignal() QQmlApplicationEngine test; QSignalSpy warningObserver(&test, &QQmlApplicationEngine::warnings); test.load(url); - QTRY_COMPARE(warningObserver.count(), 1); + QTRY_COMPARE(warningObserver.size(), 1); } void tst_qqmlapplicationengine::errorWhileCreating() @@ -330,8 +330,8 @@ void tst_qqmlapplicationengine::errorWhileCreating() test.load(url); - QTRY_COMPARE(observer.count(), 1); - QCOMPARE(failureObserver.count(), 1); + QTRY_COMPARE(observer.size(), 1); + QCOMPARE(failureObserver.size(), 1); QCOMPARE(failureObserver.first().first(), url); QList<QVariant> args = observer.takeFirst(); QVERIFY(args.at(0).isNull()); diff --git a/tests/auto/qml/qqmlbinding/data/bindingWithHandler.qml b/tests/auto/qml/qqmlbinding/data/bindingWithHandler.qml new file mode 100644 index 0000000000..bd819167d8 --- /dev/null +++ b/tests/auto/qml/qqmlbinding/data/bindingWithHandler.qml @@ -0,0 +1,7 @@ +import QtQml + +Binding { + property string input + property string output + onInputChanged: output = input +} diff --git a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp index 53a8c49e94..9c0caf1aee 100644 --- a/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp +++ b/tests/auto/qml/qqmlbinding/tst_qqmlbinding.cpp @@ -37,6 +37,7 @@ private slots: void bindNaNToInt(); void intOverflow(); void generalizedGroupedProperties(); + void localSignalHandler(); private: QQmlEngine engine; @@ -309,7 +310,7 @@ void tst_qqmlbinding::warningOnUnknownProperty() QScopedPointer<QQuickItem> item { qobject_cast<QQuickItem *>(c.create()) }; QVERIFY(item); - QCOMPARE(messageHandler.messages().count(), 1); + QCOMPARE(messageHandler.messages().size(), 1); const QString expectedMessage = c.url().toString() + QLatin1String(":6:5: QML Binding: Property 'unknown' does not exist on Item."); QCOMPARE(messageHandler.messages().first(), expectedMessage); @@ -324,7 +325,7 @@ void tst_qqmlbinding::warningOnReadOnlyProperty() QScopedPointer<QQuickItem> item { qobject_cast<QQuickItem *>(c.create()) }; QVERIFY(item); - QCOMPARE(messageHandler.messages().count(), 1); + QCOMPARE(messageHandler.messages().size(), 1); const QString expectedMessage = c.url().toString() + QLatin1String(":8:5: QML Binding: Property 'name' on Item is read-only."); QCOMPARE(messageHandler.messages().first(), expectedMessage); @@ -339,7 +340,7 @@ void tst_qqmlbinding::disabledOnUnknownProperty() QScopedPointer<QQuickItem> item { qobject_cast<QQuickItem *>(c.create()) }; QVERIFY(item); - QCOMPARE(messageHandler.messages().count(), 0); + QCOMPARE(messageHandler.messages().size(), 0); } void tst_qqmlbinding::disabledOnReadonlyProperty() @@ -350,7 +351,7 @@ void tst_qqmlbinding::disabledOnReadonlyProperty() QQmlComponent c(&engine, testFileUrl("disabledReadonly.qml")); QScopedPointer<QQuickItem> item { qobject_cast<QQuickItem *>(c.create()) }; QVERIFY(item); - QCOMPARE(messageHandler.messages().count(), 0); + QCOMPARE(messageHandler.messages().size(), 0); } void tst_qqmlbinding::delayed() @@ -447,7 +448,7 @@ void tst_qqmlbinding::bindingOverwriting() QVERIFY(item); QLoggingCategory::setFilterRules(QString()); - QCOMPARE(messageHandler.messages().count(), 2); + QCOMPARE(messageHandler.messages().size(), 2); } void tst_qqmlbinding::bindToQmlComponent() @@ -572,6 +573,17 @@ void tst_qqmlbinding::generalizedGroupedProperties() QCOMPARE(rootAttached->objectName(), QString()); } +void tst_qqmlbinding::localSignalHandler() +{ + QQmlEngine e; + QQmlComponent c(&e, testFileUrl("bindingWithHandler.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + o->setProperty("input", QStringLiteral("abc")); + QCOMPARE(o->property("output").toString(), QStringLiteral("abc")); +} + QTEST_MAIN(tst_qqmlbinding) #include "tst_qqmlbinding.moc" diff --git a/tests/auto/qml/qqmlchangeset/CMakeLists.txt b/tests/auto/qml/qqmlchangeset/CMakeLists.txt index da06b85fad..510e304717 100644 --- a/tests/auto/qml/qqmlchangeset/CMakeLists.txt +++ b/tests/auto/qml/qqmlchangeset/CMakeLists.txt @@ -1,10 +1,10 @@ # Generated from qqmlchangeset.pro. ##################################################################### -## tst_qqmlhangeset Test: +## tst_qqmlchangeset Test: ##################################################################### -qt_internal_add_test(tst_qqmlhangeset +qt_internal_add_test(tst_qqmlchangeset SOURCES tst_qqmlchangeset.cpp PUBLIC_LIBRARIES diff --git a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp index c15fdf0323..cf3894ccbb 100644 --- a/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp +++ b/tests/auto/qml/qqmlcomponent/tst_qqmlcomponent.cpp @@ -162,7 +162,7 @@ void tst_qqmlcomponent::loadEmptyUrl() c.loadUrl(QUrl()); QVERIFY(c.isError()); - QCOMPARE(c.errors().count(), 1); + QCOMPARE(c.errors().size(), 1); QQmlError error = c.errors().first(); QCOMPARE(error.url(), QUrl()); QCOMPARE(error.line(), -1); @@ -338,7 +338,7 @@ void tst_qqmlcomponent::qmlCreateObjectDirty() QQmlEngine engine; engine.setOutputWarningsToStandardError(false); QObject::connect(&engine, &QQmlEngine::warnings, [](const QList<QQmlError> &warnings) { - QCOMPARE(warnings.count(), 1); + QCOMPARE(warnings.size(), 1); QCOMPARE(warnings[0].description(), "QML Component: Unsuitable arguments passed to createObject(). The first argument " "should be a QObject* or null, and the second argument should be a JavaScript " @@ -556,7 +556,7 @@ void tst_qqmlcomponent::onDestructionCount() engine.setOutputWarningsToStandardError(false); QCOMPARE(engine.outputWarningsToStandardError(), false); - QCOMPARE(warnings.count(), 0); + QCOMPARE(warnings.size(), 0); } void tst_qqmlcomponent::recursion() @@ -1095,7 +1095,7 @@ void tst_qqmlcomponent::qmlPropertySignalExists() QSignalSpy changeSignalSpy(o.get(), SIGNAL(pChanged())); QVERIFY(QMetaObject::invokeMethod(o.get(), "doStuff")); - QCOMPARE(changeSignalSpy.count(), 1); + QCOMPARE(changeSignalSpy.size(), 1); QCOMPARE(o->property("p").toInt(), 42); } diff --git a/tests/auto/qml/qqmlconnections/data/invalidTarget.qml b/tests/auto/qml/qqmlconnections/data/invalidTarget.qml new file mode 100644 index 0000000000..23599649ec --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/invalidTarget.qml @@ -0,0 +1,31 @@ +import QtQml + +QtObject { + id: root + objectName: button.objectName + + property QtObject b: QtObject { + objectName: "button" + id: button + signal clicked + } + + property Connections c: Connections { + id: connections + target: null + function onClicked() { button.destroy(); } + } + + property Timer t: Timer { + interval: 10 + running: true + onTriggered: { + root.objectName = connections.target.objectName + } + } + + Component.onCompleted: { + connections.target = button; + button.clicked() + } +} diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp index f203bd1800..f23c474907 100644 --- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp +++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp @@ -53,6 +53,7 @@ private slots: void noAcceleratedGlobalLookup(); void bindToPropertyWithUnderscoreChangeHandler(); + void invalidTarget(); private: QQmlEngine engine; @@ -227,7 +228,7 @@ void tst_qqmlconnections::errors() QQmlComponent c(&engine, url); QVERIFY(c.isError()); QList<QQmlError> errors = c.errors(); - QCOMPARE(errors.count(), 1); + QCOMPARE(errors.size(), 1); QCOMPARE(errors.at(0).description(), error); } @@ -465,6 +466,25 @@ void tst_qqmlconnections::bindToPropertyWithUnderscoreChangeHandler() QVERIFY(root->property("success").toBool()); } +void tst_qqmlconnections::invalidTarget() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("invalidTarget.qml"); + QQmlComponent component(&engine, url); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + + QScopedPointer<QObject> root {component.create()}; + QVERIFY(root); + QCOMPARE(root->objectName(), QStringLiteral("button")); + + QTest::ignoreMessage( + QtWarningMsg, + qPrintable( + url.toString() + + QLatin1String(":5:5: TypeError: Cannot read property 'objectName' of null"))); + QTRY_VERIFY(root->objectName().isEmpty()); +} + QTEST_MAIN(tst_qqmlconnections) #include "tst_qqmlconnections.moc" diff --git a/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp b/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp index 1737d1eaeb..11d79707d0 100644 --- a/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp +++ b/tests/auto/qml/qqmlcpputils/tst_qqmlcpputils.cpp @@ -58,7 +58,7 @@ void tst_qqmlcpputils::fastConnect() qmlobject_connect(obj, MyObject, SIGNAL(signal1()), obj, MyObject, SIGNAL(signal2())); obj->signal1(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); delete obj; } diff --git a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp index 491324fa57..ca66ddb618 100644 --- a/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp +++ b/tests/auto/qml/qqmldelegatemodel/tst_qqmldelegatemodel.cpp @@ -56,7 +56,7 @@ public: if (parent.isValid()) return 0; - return mValues.count(); + return mValues.size(); } int columnCount(const QModelIndex &parent) const override @@ -187,15 +187,15 @@ void tst_QQmlDelegateModel::nestedDelegates() QScopedPointer<QObject> o(c.create()); QQuickItem *item = qobject_cast<QQuickItem *>(o.data()); - QCOMPARE(item->childItems().length(), 2); + QCOMPARE(item->childItems().size(), 2); for (QQuickItem *child : item->childItems()) { if (child->objectName() != QLatin1String("loader")) continue; - QCOMPARE(child->childItems().length(), 1); + QCOMPARE(child->childItems().size(), 1); QQuickItem *timeMarks = child->childItems().at(0); const QList<QQuickItem *> children = timeMarks->childItems(); - QCOMPARE(children.length(), 2); + QCOMPARE(children.size(), 2); // One of them is the repeater, the other one is the rectangle QVERIFY(children.at(0)->objectName() == QLatin1String("zap") diff --git a/tests/auto/qml/qqmlecmascript/BLACKLIST b/tests/auto/qml/qqmlecmascript/BLACKLIST deleted file mode 100644 index bd25566eef..0000000000 --- a/tests/auto/qml/qqmlecmascript/BLACKLIST +++ /dev/null @@ -1,2 +0,0 @@ -[gcCrashRegressionTest] -macos arm diff --git a/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml b/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml new file mode 100644 index 0000000000..17116bb091 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/aliasPropertyToIC.qml @@ -0,0 +1,11 @@ +import QtQml + + +QtObject { + id: root + + component Test : QtObject {} + + property alias myalias: other + property var direct: Test { id: other } +} diff --git a/tests/auto/qml/qqmlecmascript/data/frozenQObject2.qml b/tests/auto/qml/qqmlecmascript/data/frozenQObject2.qml new file mode 100644 index 0000000000..ebff0cde8b --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/frozenQObject2.qml @@ -0,0 +1,19 @@ +import QtQml +import test + +FrozenObjects { + id: app; + + property bool caughtSignal: false + onFooMember2Emitted: caughtSignal = true + + Component.onCompleted: { + app.fooMember.name = "John"; + app.fooMemberConst; + app.fooMember.name = "Jane"; + + app.fooMember2.name = "John"; + app.triggerSignal(); + app.fooMember2.name = "Jane"; + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/methodTypeMismatch.qml b/tests/auto/qml/qqmlecmascript/data/methodTypeMismatch.qml new file mode 100644 index 0000000000..fdf5f4ea11 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/methodTypeMismatch.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item { + id: self + property font myFont + property int notMyFont + + property var object + + function callWithFont() { + object.method_gadget(myFont) // should be fine + } + function callWithInt() { + object.method_gadget(123) + } + function callWithInt2() { + object.method_gadget(notMyFont) + } + function callWithNull() { + object.method_gadget(null) + } + function callWithAllowedNull() { + object.method_qobject(null) + } +} diff --git a/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs.qml b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs.qml new file mode 100644 index 0000000000..7f1b5b0317 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs.qml @@ -0,0 +1,8 @@ +import QtQml + +QtObject { + id: root + required property QtObject invokableObject + + Component.onCompleted: root.invokableObject.method_QObject(Component) +} diff --git a/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs2.qml b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs2.qml new file mode 100644 index 0000000000..1904740b26 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs2.qml @@ -0,0 +1,9 @@ +import QtQml +import QtQml as NS + +QtObject { + id: root + required property QtObject invokableObject + + Component.onCompleted: root.invokableObject.method_QObject(NS) +} diff --git a/tests/auto/qml/qqmlecmascript/data/qpropertyBindingNoQPropertyCapture.qml b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingNoQPropertyCapture.qml new file mode 100644 index 0000000000..d3a151efe3 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qpropertyBindingNoQPropertyCapture.qml @@ -0,0 +1,19 @@ +import QtQuick + +Item { + objectName: "redRectangle" + id: redRectangle + + property bool b: false + function toggle() { b = !b } + width: b ? 600 : 500 + + Item { + id: blueRectangle + objectName: "blueRectangle" + // width: b ? (100 + redRectangle.width / 2) : 25 + width: b ? redRectangle.width : 25 + } + + property int blueRectangleWidth: blueRectangle.width +} diff --git a/tests/auto/qml/qqmlecmascript/data/readOnlyBindable.qml b/tests/auto/qml/qqmlecmascript/data/readOnlyBindable.qml new file mode 100644 index 0000000000..116036c9ff --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/readOnlyBindable.qml @@ -0,0 +1,7 @@ +import Qt.test +import QtQuick + +ReadOnlyBindable { + property int v: 12 + x: v +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.cpp b/tests/auto/qml/qqmlecmascript/testtypes.cpp index cb2dd9373a..40f5e5cf5c 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.cpp +++ b/tests/auto/qml/qqmlecmascript/testtypes.cpp @@ -401,7 +401,7 @@ void QObjectContainer::children_append(QQmlListProperty<QObject> *prop, QObject qsizetype QObjectContainer::children_count(QQmlListProperty<QObject> *prop) { - return static_cast<QObjectContainer*>(prop->object)->dataChildren.count(); + return static_cast<QObjectContainer*>(prop->object)->dataChildren.size(); } QObject *QObjectContainer::children_at(QQmlListProperty<QObject> *prop, qsizetype index) @@ -541,6 +541,7 @@ void registerTypes() qmlRegisterType<Receiver>("Qt.test", 1,0, "Receiver"); qmlRegisterType<Sender>("Qt.test", 1,0, "Sender"); + qmlRegisterTypesAndRevisions<ReadOnlyBindable>("Qt.test", 1); } #include "testtypes.moc" diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 9a0ef2cd68..76c1a31e43 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -938,12 +938,38 @@ public: Q_INVOKABLE void method_overload2(QString a) { invoke(36); m_actuals << a; } Q_INVOKABLE void method_overload2() { invoke(37); } + Q_PROPERTY(QFont someFont READ someFont WRITE setSomeFont NOTIFY someFontChanged); + QFont someFont() { return m_someFont; } + void setSomeFont(const QFont &f) + { + if (f == m_someFont) + return; + m_someFont = f; + emit someFontChanged(); + } + Q_INVOKABLE void method_gadget(QFont f) + { + invoke(40); + m_actuals << f; + } + Q_INVOKABLE void method_qobject(QObject *o) + { + invoke(41); + m_actuals << QVariant::fromValue(o); + } + private: friend class MyInvokableBaseObject; void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} int m_invoked; bool m_invokedError; QVariantList m_actuals; + + QFont m_someFont; + +public: +Q_SIGNALS: + void someFontChanged(); }; MyInvokableBaseObject::~MyInvokableBaseObject() {} @@ -1952,6 +1978,25 @@ public slots: int slot1(int i, int j, int k) {return i+j+k;} }; +class ReadOnlyBindable : public QObject +{ + Q_OBJECT + QML_ELEMENT + Q_PROPERTY(int x READ x WRITE setX BINDABLE bindableX) + Q_OBJECT_BINDABLE_PROPERTY(ReadOnlyBindable, int, _xProp) + +public: + ReadOnlyBindable(QObject *parent = nullptr) + : QObject(parent) + { + setX(7); + } + + int x() const { return _xProp.value(); } + void setX(int x) { _xProp.setValue(x); } + QBindable<int> bindableX() const { return &_xProp; } +}; + void registerTypes(); #endif // TESTTYPES_H diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 87995b0aca..7f48c244d8 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -96,6 +96,7 @@ private slots: void outerBindingOverridesInnerBinding(); void aliasPropertyAndBinding(); void aliasPropertyReset(); + void aliasPropertyToIC(); void nonExistentAttachedObject(); void scope(); void importScope(); @@ -292,6 +293,7 @@ private slots: void bindingBoundFunctions(); void qpropertyAndQtBinding(); void qpropertyBindingReplacement(); + void qpropertyBindingNoQPropertyCapture(); void deleteRootObjectInCreation(); void onDestruction(); void onDestructionViaGC(); @@ -386,6 +388,7 @@ private slots: void urlConstruction(); void urlPropertyInvalid(); void urlPropertySet(); + void colonAfterProtocol(); void urlSearchParamsConstruction(); void urlSearchParamsMethods(); void variantConversionMethod(); @@ -408,6 +411,9 @@ private slots: void functionAsDefaultArgument(); void internalClassParentGc(); + void methodTypeMismatch(); + + void doNotCrashOnReadOnlyBindable(); private: // static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter); @@ -1911,6 +1917,24 @@ void tst_qqmlecmascript::aliasPropertyReset() QCOMPARE(object->property("aliasedIntIsUndefined"), QVariant(false)); } +void tst_qqmlecmascript::aliasPropertyToIC() +{ + QQmlEngine engine; + std::unique_ptr<QObject> root; + + // test that a manual write (of undefined) to a resettable aliased property succeeds + QQmlComponent c(&engine, testFileUrl("aliasPropertyToIC.qml")); + root.reset(c.create()); + QVERIFY(root); + auto mo = root->metaObject(); + int aliasIndex = mo->indexOfProperty("myalias"); + auto prop = mo->property(aliasIndex); + QVERIFY(prop.isAlias()); + auto fromAlias = prop.read(root.get()).value<QObject *>(); + auto direct = root->property("direct").value<QObject *>(); + QCOMPARE(fromAlias, direct); +} + void tst_qqmlecmascript::componentCreation_data() { QTest::addColumn<QString>("method"); @@ -2269,9 +2293,9 @@ void tst_qqmlecmascript::scriptErrors() QQmlComponent component(&engine, testFileUrl("scriptErrors.qml")); QString url = component.url().toString(); - QString warning1 = url.left(url.length() - 3) + "js:2: Error: Invalid write to global property \"a\""; + QString warning1 = url.left(url.size() - 3) + "js:2: Error: Invalid write to global property \"a\""; QString warning2 = url + ":5: ReferenceError: a is not defined"; - QString warning3 = url.left(url.length() - 3) + "js:4: Error: Invalid write to global property \"a\""; + QString warning3 = url.left(url.size() - 3) + "js:4: Error: Invalid write to global property \"a\""; QString warning4 = url + ":13: ReferenceError: a is not defined"; QString warning5 = url + ":11: ReferenceError: a is not defined"; QString warning6 = url + ":10:5: Unable to assign [undefined] to int"; @@ -2833,26 +2857,26 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_ERROR("object.method_nonexistent()")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_nonexistent(10, 11)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); // Insufficient arguments o->reset(); QVERIFY(EVALUATE_ERROR("object.method_int()")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_intint(10)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); // Excessive arguments QTest::ignoreMessage(QtWarningMsg, qPrintable("Too many arguments, ignoring 1")); @@ -2861,7 +2885,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_int(10, 11)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(10)); QTest::ignoreMessage(QtWarningMsg, qPrintable("Too many arguments, ignoring 1")); @@ -2870,7 +2894,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_intint(10, 11, 12)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 9); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(10)); QCOMPARE(o->actuals().at(1), QVariant(11)); @@ -2879,19 +2903,19 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_NoArgs()", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 0); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_NoArgs_int()", QV4::Primitive::fromInt32(6))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_NoArgs_real()", QV4::Primitive::fromDouble(19.75))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 2); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); { @@ -2900,7 +2924,7 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(scope.engine->toVariant(ret, QMetaType {}), QVariant(QPointF(123, 4.5))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 3); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); } o->reset(); @@ -2910,14 +2934,14 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(qobjectWrapper->object(), (QObject *)o); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 4); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); } o->reset(); QVERIFY(EVALUATE_ERROR("object.method_NoArgs_unknown()")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); { @@ -2926,63 +2950,63 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(ret->toQStringNoThrow(), QString("Hello world")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 6); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); } o->reset(); QVERIFY(EVALUATE_VALUE("object.method_NoArgs_QVariant()", QV4::ScopedValue(scope, scope.engine->newString("QML rocks")))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 7); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); // Test arg types o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(94)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(94)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(\"94\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(94)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(\"not a number\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(0)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(0)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(0)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_int(object)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 8); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(0)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_intint(122, 9)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 9); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(122)); QCOMPARE(o->actuals().at(1), QVariant(9)); @@ -2990,56 +3014,56 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_real(94.3)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(94.3)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_real(\"94.3\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(94.3)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_real(\"not a number\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qIsNaN(o->actuals().at(0).toDouble())); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_real(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(0)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_real(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qIsNaN(o->actuals().at(0).toDouble())); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_real(object)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 10); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qIsNaN(o->actuals().at(0).toDouble())); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QString(\"Hello world\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 11); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant("Hello world")); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QString(19)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 11); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant("19")); o->reset(); @@ -3048,7 +3072,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_QString(object)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 11); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(expected)); } @@ -3056,120 +3080,140 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_QString(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 11); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(QString())); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QString(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 11); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(QString())); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QPointF(0)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QPointF(null)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QPointF(undefined)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QPointF(object)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPointF())", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 12); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(QPointF(99.3, -10.2))); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QPointF(object.method_get_QPoint())", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 12); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(QPointF(9, 12))); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QObject(0)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_QObject(\"Hello world\")")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QObject(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 13); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant::fromValue((QObject *)nullptr)); + { + o->reset(); + QQmlComponent comp(&qmlengine, testFileUrl("qmlTypeWrapperArgs.qml")); + QScopedPointer<QObject> root {comp.createWithInitialProperties({{"invokableObject", QVariant::fromValue(o)}}) }; + QVERIFY(root); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 13); + QCOMPARE(o->actuals().size(), 1); + QCOMPARE(o->actuals().at(0).value<QObject *>()->metaObject()->className(), "QQmlComponentAttached"); + } + + { + o->reset(); + QQmlComponent comp(&qmlengine, testFileUrl("qmlTypeWrapperArgs2.qml")); + QScopedPointer<QObject> root {comp.createWithInitialProperties({{"invokableObject", QVariant::fromValue(o)}}) }; + QVERIFY(root); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), -1); // no function got called due to incompatible arguments + } + o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QObject(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 13); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant::fromValue((QObject *)nullptr)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QObject(object)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 13); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant::fromValue((QObject *)o)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 14); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(0)).isNull()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 14); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(0)).isUndefined()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QScriptValue(19)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 14); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(0)).strictlyEquals(QJSValue(19))); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QScriptValue([19, 20])", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 14); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(0)).isArray()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(4, null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 15); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(4)); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(1)).isNull()); @@ -3177,7 +3221,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(8, undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 15); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(8)); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(1)).isUndefined()); @@ -3185,7 +3229,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(3, 19)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 15); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(3)); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(1)).strictlyEquals(QJSValue(19))); @@ -3193,7 +3237,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_intQScriptValue(44, [19, 20])", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 15); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(44)); QVERIFY(qvariant_cast<QJSValue>(o->actuals().at(1)).isArray()); @@ -3201,20 +3245,20 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_ERROR("object.method_overload()")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload(10)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 16); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(10)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload(10, 11)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 17); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(10)); QCOMPARE(o->actuals().at(1), QVariant(11)); @@ -3222,21 +3266,21 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_overload(\"Hello\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 18); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(QString("Hello"))); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_with_enum(9)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 19); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(9)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_default(10)", QV4::Primitive::fromInt32(19))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 20); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(10)); QCOMPARE(o->actuals().at(1), QVariant(19)); @@ -3244,7 +3288,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_default(10, 13)", QV4::Primitive::fromInt32(13))); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 20); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(10)); QCOMPARE(o->actuals().at(1), QVariant(13)); @@ -3252,14 +3296,14 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_inherited(9)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -3); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(o->actuals().at(0), QVariant(9)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QVariant(9)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 21); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(9)); QCOMPARE(o->actuals().at(1), QVariant()); @@ -3267,7 +3311,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_QVariant(\"Hello\", \"World\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 21); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(QString("Hello"))); QCOMPARE(o->actuals().at(1), QVariant(QString("World"))); @@ -3275,104 +3319,104 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_QJsonObject({foo:123})", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 22); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonObject>(o->actuals().at(0)), QJsonDocument::fromJson("{\"foo\":123}").object()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonArray([123])", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 23); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonArray>(o->actuals().at(0)), QJsonDocument::fromJson("[123]").array()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(123)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(123)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(42.35)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(42.35)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue('ciao')", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(QStringLiteral("ciao"))); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(true)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(true)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(false)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(false)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(QJsonValue::Null)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QJsonValue(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 24); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(QJsonValue::Undefined)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload({foo:123})", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 25); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonObject>(o->actuals().at(0)), QJsonDocument::fromJson("{\"foo\":123}").object()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload([123])", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 26); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonArray>(o->actuals().at(0)), QJsonDocument::fromJson("[123]").array()); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload(null)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 27); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(QJsonValue::Null)); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_overload(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 27); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QJsonValue>(o->actuals().at(0)), QJsonValue(QJsonValue::Undefined)); o->reset(); QVERIFY(EVALUATE_ERROR("object.method_unknown(null)")); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); - QCOMPARE(o->actuals().count(), 0); + QCOMPARE(o->actuals().size(), 0); o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QByteArray(\"Hello\")", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 29); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QByteArray>(o->actuals().at(0)), QByteArray("Hello")); o->reset(); @@ -3381,7 +3425,7 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->invoked(), 30); QVERIFY(ret->isString()); QCOMPARE(ret->toQStringNoThrow(), QString("Hello world!")); - QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().size(), 2); QCOMPARE(o->actuals().at(0), QVariant(123)); QJSValue callback = qvariant_cast<QJSValue>(o->actuals().at(1)); QVERIFY(!callback.isNull()); @@ -3391,7 +3435,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_overload2('foo', 12, [1, 2, 3])", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 31); - QCOMPARE(o->actuals().count(), 3); + QCOMPARE(o->actuals().size(), 3); QCOMPARE(qvariant_cast<QString>(o->actuals().at(0)), QStringLiteral("foo")); QCOMPARE(qvariant_cast<int>(o->actuals().at(1)), 12); QCOMPARE(qvariant_cast<QVariantList>(o->actuals().at(2)), (QVariantList {1.0, 2.0, 3.0})); @@ -3400,7 +3444,7 @@ void tst_qqmlecmascript::callQtInvokables() QVERIFY(EVALUATE_VALUE("object.method_overload2(11, 12, {a: 1, b: 2})", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 31); - QCOMPARE(o->actuals().count(), 3); + QCOMPARE(o->actuals().size(), 3); QCOMPARE(qvariant_cast<int>(o->actuals().at(0)), 11); QCOMPARE(qvariant_cast<int>(o->actuals().at(1)), 12); QCOMPARE(qvariant_cast<QVariantMap>(o->actuals().at(2)), @@ -3411,7 +3455,7 @@ void tst_qqmlecmascript::callQtInvokables() QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 32); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QVariantList>(o->actuals().at(0)), (QVariantList {1.0, QStringLiteral("bar"), 0.2})); @@ -3420,13 +3464,26 @@ void tst_qqmlecmascript::callQtInvokables() QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), 33); - QCOMPARE(o->actuals().count(), 1); + QCOMPARE(o->actuals().size(), 1); QCOMPARE(qvariant_cast<QVariantMap>(o->actuals().at(0)), (QVariantMap { {QStringLiteral("one"), 1.0}, {QStringLiteral("two"), QStringLiteral("bar")}, {QStringLiteral("three"), 0.2} })); + + o->reset(); + QVERIFY(EVALUATE_VALUE("object.method_gadget(object.someFont)", + QV4::Primitive::undefinedValue())); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 40); + QCOMPARE(o->actuals(), QVariantList() << QVariant(o->someFont())); + + o->reset(); + QVERIFY(EVALUATE_ERROR("object.method_gadget(123)")); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), -1); + QCOMPARE(o->actuals(), QVariantList()); } void tst_qqmlecmascript::resolveClashingProperties() @@ -4428,7 +4485,7 @@ void tst_qqmlecmascript::singletonType() if (!errorMessage.isEmpty()) QTest::ignoreMessage(QtWarningMsg, errorMessage.toLatin1().constData()); - for (const QString &warning : qAsConst(warningMessages)) + for (const QString &warning : std::as_const(warningMessages)) QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); QScopedPointer<QObject> object(component.create()); @@ -4785,7 +4842,7 @@ void tst_qqmlecmascript::importScripts() QTest::ignoreMessage(QtWarningMsg, errorMessage.toLatin1().constData()); if (compilationShouldSucceed) { - for (const QString &warning : qAsConst(warningMessages)) + for (const QString &warning : std::as_const(warningMessages)) QTest::ignoreMessage(QtWarningMsg, warning.toLatin1().constData()); } @@ -4794,7 +4851,7 @@ void tst_qqmlecmascript::importScripts() else { QVERIFY(component.isError()); QCOMPARE(warningMessages.size(), 1); - QCOMPARE(component.errors().count(), 2); + QCOMPARE(component.errors().size(), 2); QCOMPARE(component.errors().at(1).toString(), warningMessages.first()); return; } @@ -5809,22 +5866,22 @@ void tst_qqmlecmascript::sequenceConversionRead() QMetaObject::invokeMethod(object.data(), "readSequences"); QList<int> intList; intList << 1 << 2 << 3 << 4; - QCOMPARE(object->property("intListLength").toInt(), intList.length()); + QCOMPARE(object->property("intListLength").toInt(), intList.size()); QCOMPARE(object->property("intList").value<QList<int> >(), intList); QList<qreal> qrealList; qrealList << 1.1 << 2.2 << 3.3 << 4.4; - QCOMPARE(object->property("qrealListLength").toInt(), qrealList.length()); + QCOMPARE(object->property("qrealListLength").toInt(), qrealList.size()); QCOMPARE(object->property("qrealList").value<QList<qreal> >(), qrealList); QList<bool> boolList; boolList << true << false << true << false; - QCOMPARE(object->property("boolListLength").toInt(), boolList.length()); + QCOMPARE(object->property("boolListLength").toInt(), boolList.size()); QCOMPARE(object->property("boolList").value<QList<bool> >(), boolList); QList<QString> stringList; stringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth"); - QCOMPARE(object->property("stringListLength").toInt(), stringList.length()); + QCOMPARE(object->property("stringListLength").toInt(), stringList.size()); QCOMPARE(object->property("stringList").value<QList<QString> >(), stringList); QList<QUrl> urlList; urlList << QUrl("http://www.example1.com") << QUrl("http://www.example2.com") << QUrl("http://www.example3.com"); - QCOMPARE(object->property("urlListLength").toInt(), urlList.length()); + QCOMPARE(object->property("urlListLength").toInt(), urlList.size()); QCOMPARE(object->property("urlList").value<QList<QUrl> >(), urlList); QStringList qstringList; qstringList << QLatin1String("first") << QLatin1String("second") << QLatin1String("third") << QLatin1String("fourth"); - QCOMPARE(object->property("qstringListLength").toInt(), qstringList.length()); + QCOMPARE(object->property("qstringListLength").toInt(), qstringList.size()); QCOMPARE(object->property("qstringList").value<QStringList>(), qstringList); QMetaObject::invokeMethod(object.data(), "readSequenceElements"); @@ -7300,7 +7357,7 @@ void tst_qqmlecmascript::nonNotifyable() QLatin1String(object->metaObject()->className()) + QLatin1String("::value"); - QCOMPARE(messageHandler.messages().length(), 2); + QCOMPARE(messageHandler.messages().size(), 2); QCOMPARE(messageHandler.messages().at(0), expected1); QCOMPARE(messageHandler.messages().at(1), expected2); } @@ -7358,7 +7415,7 @@ void tst_qqmlecmascript::qtbug_22679() QScopedPointer<QObject> o(component.create()); QVERIFY2(o, qPrintable(component.errorString())); - QCOMPARE(warningsSpy.count(), 0); + QCOMPARE(warningsSpy.size(), 0); } void tst_qqmlecmascript::qtbug_22843_data() @@ -7382,7 +7439,7 @@ void tst_qqmlecmascript::qtbug_22843() QQmlComponent component(&engine, testFileUrl(fileName)); QString url = component.url().toString(); - QString expectedError = url.left(url.length()-3) + QLatin1String("js:4:16: Expected token `;'"); + QString expectedError = url.left(url.size()-3) + QLatin1String("js:4:16: Expected token `;'"); QVERIFY(component.isError()); QCOMPARE(component.errors().value(1).toString(), expectedError); @@ -7722,6 +7779,28 @@ void tst_qqmlecmascript::qpropertyBindingReplacement() QCOMPARE(root->objectName(), u"overwritten"_s); } +void tst_qqmlecmascript::qpropertyBindingNoQPropertyCapture() +{ + + QQmlEngine engine; + QQmlComponent comp(&engine, testFileUrl("qpropertyBindingNoQPropertyCapture.qml")); + std::unique_ptr<QObject> root(comp.create()); + QVERIFY2(root, qPrintable(comp.errorString())); + auto redRectangle = root.get(); + + QQmlProperty blueRectangleWidth(redRectangle, "blueRectangleWidth", &engine); + + auto toggle = [&](){ + QMetaObject::invokeMethod(root.get(), "toggle"); + }; + + QCOMPARE(blueRectangleWidth.read().toInt(), 25); + toggle(); + QCOMPARE(blueRectangleWidth.read().toInt(), 600); + toggle(); + QCOMPARE(blueRectangleWidth.read().toInt(), 25); +} + void tst_qqmlecmascript::deleteRootObjectInCreation() { QQmlEngine engine; @@ -8190,8 +8269,8 @@ void tst_qqmlecmascript::jsOwnedObjectsDeletedOnEngineDestroy() QSignalSpy spy1(object1, SIGNAL(destroyed())); QSignalSpy spy2(object2, SIGNAL(destroyed())); myEngine.reset(); - QCOMPARE(spy1.count(), 1); - QCOMPARE(spy2.count(), 1); + QCOMPARE(spy1.size(), 1); + QCOMPARE(spy2.size(), 1); deleteObject.deleteNestedObject(); } @@ -8506,14 +8585,14 @@ void tst_qqmlecmascript::garbageCollectionDuringCreation() QVERIFY2(object, qPrintable(component.errorString())); QObjectContainer *container = qobject_cast<QObjectContainer*>(object.data()); - QCOMPARE(container->dataChildren.count(), 1); + QCOMPARE(container->dataChildren.size(), 1); QObject *child = container->dataChildren.first(); QQmlData *ddata = QQmlData::get(child); QVERIFY(!ddata->jsWrapper.isNullOrUndefined()); gc(engine); - QCOMPARE(container->dataChildren.count(), 0); + QCOMPARE(container->dataChildren.size(), 0); } void tst_qqmlecmascript::qtbug_39520() @@ -9546,7 +9625,7 @@ void tst_qqmlecmascript::urlConstruction() QV4::UrlObject *validUrl = ret->as<QV4::UrlObject>(); QVERIFY(validUrl != nullptr); - QCOMPARE(validUrl->protocol(), "https"); + QCOMPARE(validUrl->protocol(), "https:"); QCOMPARE(validUrl->hostname(), "example.com"); QCOMPARE(validUrl->username(), "username"); QCOMPARE(validUrl->password(), "password"); @@ -9566,7 +9645,7 @@ void tst_qqmlecmascript::urlConstruction() QV4::UrlObject *validRelativeUrl = retRel->as<QV4::UrlObject>(); QVERIFY(validRelativeUrl != nullptr); - QCOMPARE(validRelativeUrl->protocol(), "https"); + QCOMPARE(validRelativeUrl->protocol(), "https:"); QCOMPARE(validRelativeUrl->hostname(), "example.com"); QCOMPARE(validRelativeUrl->username(), "username"); QCOMPARE(validRelativeUrl->password(), "password"); @@ -9626,7 +9705,7 @@ void tst_qqmlecmascript::urlPropertySet() // protocol QVERIFY(EVALUATE("this.url.protocol = 'https';")); - QCOMPARE(url->protocol(), "https"); + QCOMPARE(url->protocol(), "https:"); QCOMPARE(url->href(), "https://localhost/a/b/c"); QCOMPARE(url->origin(), "https://localhost"); @@ -9689,7 +9768,7 @@ void tst_qqmlecmascript::urlPropertySet() "this.url.href = " "'https://username:password@example.com:1234/path/to/something?search=value#hash';")); - QCOMPARE(url->protocol(), "https"); + QCOMPARE(url->protocol(), "https:"); QCOMPARE(url->hostname(), "example.com"); QCOMPARE(url->username(), "username"); QCOMPARE(url->password(), "password"); @@ -9703,6 +9782,57 @@ void tst_qqmlecmascript::urlPropertySet() QCOMPARE(url->hash(), "#hash"); } +void tst_qqmlecmascript::colonAfterProtocol() +{ + QQmlEngine qmlengine; + + QObject *o = new QObject(&qmlengine); + + QV4::ExecutionEngine *engine = qmlengine.handle(); + QV4::Scope scope(engine); + + QV4::ScopedValue object(scope, QV4::QObjectWrapper::wrap(engine, o)); + + QV4::ScopedValue ret(scope, EVALUATE("this.url = new URL('http://localhost/a/b/c');")); + QV4::UrlObject *url = ret->as<QV4::UrlObject>(); + QVERIFY(url != nullptr); + + // https without colon + QVERIFY(EVALUATE("this.url.protocol = 'https';")); + QCOMPARE(url->protocol(), "https:"); + QCOMPARE(url->href(), "https://localhost/a/b/c"); + QCOMPARE(url->origin(), "https://localhost"); + + QV4::ScopedValue retHttps(scope, EVALUATE("this.url = new URL('https://localhost/a/b/c');")); + QV4::UrlObject *urlHttps = retHttps->as<QV4::UrlObject>(); + QVERIFY(urlHttps != nullptr); + + // ftp with a colon + QVERIFY(EVALUATE("this.url.protocol = 'ftp:';")); + QCOMPARE(urlHttps->protocol(), "ftp:"); + QCOMPARE(urlHttps->href(), "ftp://localhost/a/b/c"); + QCOMPARE(urlHttps->origin(), "ftp://localhost"); + + QV4::ScopedValue retHttp(scope, EVALUATE("this.url = new URL('http://localhost/a/b/c');")); + QV4::UrlObject *ftpHttps = retHttp->as<QV4::UrlObject>(); + QVERIFY(ftpHttps != nullptr); + + // ftp with three colons + QVERIFY(EVALUATE("this.url.protocol = 'ftp:::';")); + QCOMPARE(ftpHttps->protocol(), "ftp:"); + QCOMPARE(ftpHttps->href(), "ftp://localhost/a/b/c"); + QCOMPARE(ftpHttps->origin(), "ftp://localhost"); + + QV4::ScopedValue retWss(scope, EVALUATE("this.url = new URL('wss://localhost/a/b/c');")); + QV4::UrlObject *urlFtpHttp = retWss->as<QV4::UrlObject>(); + QVERIFY(urlFtpHttp != nullptr); + + // ftp and http with a colon inbetween + QVERIFY(EVALUATE("this.url.protocol = 'ftp:http:';")); + QCOMPARE(urlFtpHttp->protocol(), "ftp:"); + QCOMPARE(urlFtpHttp->href(), "ftp://localhost/a/b/c"); + QCOMPARE(urlFtpHttp->origin(), "ftp://localhost"); +} void tst_qqmlecmascript::urlSearchParamsConstruction() { @@ -9836,14 +9966,65 @@ void tst_qqmlecmascript::cmpInThrows() QCOMPARE(stacktrace.at(0), QStringLiteral("%entry:14:-1:file:foo.js")); } +class FrozenFoo : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString name MEMBER m_name NOTIFY nameChanged) + +public: + FrozenFoo(QObject *parent = nullptr) : QObject(parent) {} + QString name() const { return m_name; } + +signals: + void nameChanged(); + +private: + QString m_name{ "Foo" }; +}; + +class FrozenObjects : public QObject +{ + Q_OBJECT + Q_PROPERTY(FrozenFoo *fooMember READ fooMember CONSTANT); + Q_PROPERTY(const FrozenFoo *fooMemberConst READ fooMemberConst CONSTANT); + Q_PROPERTY(FrozenFoo *fooMember2 READ fooMember2 CONSTANT); + +public: + FrozenObjects(QObject *parent = nullptr) : QObject(parent) {} + + Q_INVOKABLE void triggerSignal() { emit fooMember2Emitted(&m_fooMember2); } + + FrozenFoo *fooMember() { return &m_fooMember; } + FrozenFoo *fooMember2() { return &m_fooMember2; } + +signals: + void fooMember2Emitted(const FrozenFoo *fooMember2); + +private: + const FrozenFoo *fooMemberConst() const { return &m_fooMember; } + + FrozenFoo m_fooMember; + FrozenFoo m_fooMember2; +}; + void tst_qqmlecmascript::frozenQObject() { + qmlRegisterType<FrozenObjects>("test", 1, 0, "FrozenObjects"); + QQmlEngine engine; - QQmlComponent component(&engine, testFileUrl("frozenQObject.qml")); - QScopedPointer<QObject> root(component.create()); - QVERIFY2(root, qPrintable(component.errorString())); - QVERIFY(root->property("caughtException").toBool()); - QVERIFY(root->property("nameCorrect").toBool()); + QQmlComponent component1(&engine, testFileUrl("frozenQObject.qml")); + QScopedPointer<QObject> root1(component1.create()); + QVERIFY2(root1, qPrintable(component1.errorString())); + QVERIFY(root1->property("caughtException").toBool()); + QVERIFY(root1->property("nameCorrect").toBool()); + + QQmlComponent component2(&engine, testFileUrl("frozenQObject2.qml")); + QScopedPointer<QObject> root2(component2.create()); + FrozenObjects *frozenObjects = qobject_cast<FrozenObjects *>(root2.data()); + QVERIFY2(frozenObjects, qPrintable(component2.errorString())); + QVERIFY(frozenObjects->property("caughtSignal").toBool()); + QCOMPARE(frozenObjects->fooMember()->name(), QStringLiteral("Jane")); + QCOMPARE(frozenObjects->fooMember2()->name(), QStringLiteral("Jane")); } struct ConstPointer : QObject @@ -10080,6 +10261,85 @@ void tst_qqmlecmascript::internalClassParentGc() QCOMPARE(root->objectName(), "3"); } +void tst_qqmlecmascript::methodTypeMismatch() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("methodTypeMismatch.qml")); + + QScopedPointer<MyInvokableObject> object(new MyInvokableObject()); + + QScopedPointer<QObject> o(component.create()); + QVERIFY2(o, qPrintable(component.errorString())); + o->setProperty("object", QVariant::fromValue(object.get())); + + auto mo = o->metaObject(); + QVERIFY(mo); + + auto method = mo->method(mo->indexOfMethod("callWithFont()")); + QVERIFY(method.isValid()); + QVERIFY(method.invoke(o.get())); + QCOMPARE(object->actuals(), QVariantList() << QVariant(object->someFont())); + + QRegularExpression argumentConversionErrorMatcher("Could not convert argument 0"); + QRegularExpression argumentConversionErrorMatcher2(".*/methodTypeMismatch.qml"); + QRegularExpression typeErrorMatcher( + ".*/methodTypeMismatch\\.qml:..: TypeError: Passing incompatible arguments to C\\+\\+ " + "functions from JavaScript is not allowed."); + + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher); + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher2); + QTest::ignoreMessage(QtWarningMsg, typeErrorMatcher); + object->reset(); + method = mo->method(mo->indexOfMethod("callWithInt()")); + QVERIFY(method.isValid()); + QVERIFY(method.invoke(o.get())); + QCOMPARE(object->actuals().size(), + 0); // actuals() should not contain reinterpret_cast<QFont>(123) !!! + + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher); + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher2); + QTest::ignoreMessage(QtWarningMsg, typeErrorMatcher); + object->reset(); + method = mo->method(mo->indexOfMethod("callWithInt2()")); + QVERIFY(method.isValid()); + QVERIFY(method.invoke(o.get())); + QCOMPARE(object->actuals().size(), + 0); // actuals() should not contain reinterpret_cast<QFont>(0) !!! + + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher); + QTest::ignoreMessage(QtWarningMsg, argumentConversionErrorMatcher2); + QTest::ignoreMessage(QtWarningMsg, typeErrorMatcher); + object->reset(); + method = mo->method(mo->indexOfMethod("callWithNull()")); + QVERIFY(method.isValid()); + QVERIFY(method.invoke(o.get())); + QCOMPARE(object->actuals().size(), + 0); // actuals() should not contain reinterpret_cast<QFont>(nullptr) !!! + + // make sure that null is still accepted by functions accepting, e.g., a QObject*! + object->reset(); + method = mo->method(mo->indexOfMethod("callWithAllowedNull()")); + QVERIFY(method.isValid()); + QVERIFY(method.invoke(o.get())); + QCOMPARE(object->actuals(), QVariantList() << QVariant::fromValue((QObject *)nullptr)); +} + +void tst_qqmlecmascript::doNotCrashOnReadOnlyBindable() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("readOnlyBindable.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); +#ifndef QT_NO_DEBUG + QTest::ignoreMessage( + QtWarningMsg, + "setBinding: Could not set binding via bindable interface. " + "The QBindable is read-only."); +#endif + QScopedPointer<QObject> o(c.create()); + QVERIFY(o); + QCOMPARE(o->property("x").toInt(), 7); +} + QTEST_MAIN(tst_qqmlecmascript) #include "tst_qqmlecmascript.moc" diff --git a/tests/auto/qml/qqmlfile/tst_qqmlfile.cpp b/tests/auto/qml/qqmlfile/tst_qqmlfile.cpp index e9de34f657..3f75a14bf6 100644 --- a/tests/auto/qml/qqmlfile/tst_qqmlfile.cpp +++ b/tests/auto/qml/qqmlfile/tst_qqmlfile.cpp @@ -118,6 +118,27 @@ void tst_qqmlfile::urlData() QTest::addRow("file:content 1 slash") << QStringLiteral("file:content:/foo/bar") << true << QStringLiteral("content:/foo/bar"); QTest::addRow("file:content 2 slashes") << QStringLiteral("file:content://foo/bar") << true << QStringLiteral("content://foo/bar"); QTest::addRow("file:content 3 slashes") << QStringLiteral("file:content:///foo/bar") << true << QStringLiteral("content:///foo/bar"); + + const QString contentExternalstoragePath = hasAssetsAndContent ? + QStringLiteral("content://com.android.externalstorage.documents/foo") : invalid; + const QString contentDownloadsPath = hasAssetsAndContent ? + QStringLiteral("content://com.android.providers.downloads.documents/foo") : invalid; + const QString contentMediaPath = hasAssetsAndContent ? + QStringLiteral("content://com.android.providers.media.documents") : invalid; + + QTest::addRow("content externalstorage") << QStringLiteral("content://com.android.externalstorage.documents/foo") + << hasAssetsAndContent << contentExternalstoragePath; + QTest::addRow("content downloads documents") << QStringLiteral("content://com.android.providers.downloads.documents/foo") + << hasAssetsAndContent << contentDownloadsPath; + QTest::addRow("content media documents") << QStringLiteral("content://com.android.providers.media.documents") + << hasAssetsAndContent << contentMediaPath; + + QTest::addRow("assets externalstorage") << QStringLiteral("assets://com.android.externalstorage.documents/foo") + << false << invalid; + QTest::addRow("assets downloads documents") << QStringLiteral("assets://com.android.providers.downloads.documents/foo") + << false << invalid; + QTest::addRow("assets media documents") << QStringLiteral("assets://com.android.providers.media.documents") + << false << invalid; } void tst_qqmlfile::isLocalFile_data() diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml new file mode 100644 index 0000000000..d6dd2c9b90 --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/main.qml @@ -0,0 +1,13 @@ +import QtQuick +import qmldirtest + +Window { + width: 640 + height: 480 + visible: true + property color color: mybutton.color + + MyButton { + id: mybutton + } +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml new file mode 100644 index 0000000000..cc6eb967da --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+linux/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "blue" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml new file mode 100644 index 0000000000..5bf632c48d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/+macos/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "yellow" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml new file mode 100644 index 0000000000..32db428c4f --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qml/MyButton.qml @@ -0,0 +1,7 @@ +import QtQuick + +Rectangle { + width: 300 + height: 50 + color: "green" +} diff --git a/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir new file mode 100644 index 0000000000..ac68d9097d --- /dev/null +++ b/tests/auto/qml/qqmlfileselector/data/qmldirtest/qmldir @@ -0,0 +1,5 @@ +module qmldirtest +MyButton 1.0 qml/MyButton.qml +MyButton 1.0 qml/+linux/MyButton.qml +MyButton 1.0 qml/+macos/MyButton.qml + diff --git a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp index 7dd7a68107..46df20378c 100644 --- a/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp +++ b/tests/auto/qml/qqmlfileselector/tst_qqmlfileselector.cpp @@ -22,7 +22,7 @@ private slots: void basicTest(); void basicTestCached(); void applicationEngineTest(); - + void qmldirCompatibility(); }; void tst_qqmlfileselector::basicTest() @@ -70,6 +70,23 @@ void tst_qqmlfileselector::applicationEngineTest() QCOMPARE(object->property("value").toString(), QString("selected")); } +void tst_qqmlfileselector::qmldirCompatibility() +{ + QQmlApplicationEngine engine; + engine.addImportPath(dataDirectory()); + engine.load(testFileUrl("qmldirtest/main.qml")); + QVERIFY(!engine.rootObjects().isEmpty()); + QObject *object = engine.rootObjects().at(0); + auto color = object->property("color").value<QColor>(); +#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) + QCOMPARE(color, QColorConstants::Svg::blue); +#elif defined(Q_OS_DARWIN) + QCOMPARE(color, QColorConstants::Svg::yellow); +#else + QCOMPARE(color, QColorConstants::Svg::green); +#endif +} + QTEST_MAIN(tst_qqmlfileselector) #include "tst_qqmlfileselector.moc" diff --git a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp index 4460dd7de5..fdf3fffeb6 100644 --- a/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp +++ b/tests/auto/qml/qqmlimport/tst_qqmlimport.cpp @@ -170,26 +170,26 @@ void tst_QQmlImport::uiFormatLoading() QSignalSpy objectCreated(test, SIGNAL(objectCreated(QObject*,QUrl))); test->load(testFileUrl("TestForm.ui.qml")); - QCOMPARE(objectCreated.count(), size);//one less than rootObjects().size() because we missed the first one + QCOMPARE(objectCreated.size(), size);//one less than rootObjects().size() because we missed the first one QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); QByteArray testQml("import QtQml 2.0; QtObject{property bool success: true; property TestForm t: TestForm{}}"); test->loadData(testQml, testFileUrl("dynamicTestForm.ui.qml")); - QCOMPARE(objectCreated.count(), size); + QCOMPARE(objectCreated.size(), size); QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); test->load(testFileUrl("openTestFormFromDir.qml")); - QCOMPARE(objectCreated.count(), size); + QCOMPARE(objectCreated.size(), size); QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); test->load(testFileUrl("openTestFormFromQmlDir.qml")); - QCOMPARE(objectCreated.count(), size); + QCOMPARE(objectCreated.size(), size); QCOMPARE(test->rootObjects().size(), ++size); QVERIFY(test->rootObjects()[size -1]); QVERIFY(test->rootObjects()[size -1]->property("success").toBool()); diff --git a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp index e6c8ad721e..1baf61574e 100644 --- a/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp +++ b/tests/auto/qml/qqmlincubator/tst_qqmlincubator.cpp @@ -517,7 +517,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Synchronous); component.create(incubator); QVERIFY(incubator.isReady()); - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); @@ -531,7 +531,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Asynchronous); component.create(incubator); QVERIFY(incubator.isLoading()); - QCOMPARE(incubator.statuses.count(), 1); + QCOMPARE(incubator.statuses.size(), 1); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); { @@ -539,7 +539,7 @@ void tst_qqmlincubator::statusChanged() controller.incubateWhile(&b); } - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); @@ -553,7 +553,7 @@ void tst_qqmlincubator::statusChanged() MyIncubator incubator(QQmlIncubator::Asynchronous); component2.create(incubator); QVERIFY(incubator.isLoading()); - QCOMPARE(incubator.statuses.count(), 1); + QCOMPARE(incubator.statuses.size(), 1); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); { @@ -562,7 +562,7 @@ void tst_qqmlincubator::statusChanged() } QVERIFY(incubator.isReady()); - QCOMPARE(incubator.statuses.count(), 3); + QCOMPARE(incubator.statuses.size(), 3); QCOMPARE(incubator.statuses.at(0), int(QQmlIncubator::Loading)); QCOMPARE(incubator.statuses.at(1), -1); QCOMPARE(incubator.statuses.at(2), int(QQmlIncubator::Ready)); diff --git a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp index 03add4b309..4908ca210b 100644 --- a/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp +++ b/tests/auto/qml/qqmlinfo/tst_qqmlinfo.cpp @@ -226,7 +226,7 @@ void tst_qqmlinfo::attachedObject() QScopedPointer<QObject> object(component.create()); QVERIFY2(object != nullptr, qPrintable(component.errorString())); - QCOMPARE(warningSpy.count(), 2); + QCOMPARE(warningSpy.size(), 2); // The Attached C++ type has no QML engine since it was created in C++, so we should see its parent instead. const auto cppWarnings = warningSpy.at(0).first().value<QList<QQmlError>>(); diff --git a/tests/auto/qml/qqmlinstantiator/stringmodel.h b/tests/auto/qml/qqmlinstantiator/stringmodel.h index 69d617a07f..d9676b9460 100644 --- a/tests/auto/qml/qqmlinstantiator/stringmodel.h +++ b/tests/auto/qml/qqmlinstantiator/stringmodel.h @@ -37,7 +37,7 @@ public: int rowCount(const QModelIndex &) const override { - return items.count(); + return items.size(); } QHash<int, QByteArray> roleNames() const override @@ -72,7 +72,7 @@ public: QVariant data (const QModelIndex & index, int role) const override { int row = index.row(); - if ((row<0) || (row>=items.count())) + if ((row<0) || (row>=items.size())) return QVariant(QMetaType(QMetaType::UnknownType)); switch (role) { diff --git a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp index aeca3f4046..1097c65f02 100644 --- a/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp +++ b/tests/auto/qml/qqmlinstantiator/tst_qqmlinstantiator.cpp @@ -124,19 +124,19 @@ void tst_qqmlinstantiator::activeProperty() QCOMPARE(instantiator->count(), 0); QVERIFY(instantiator->delegate()->isReady()); - QCOMPARE(activeSpy.count(), 0); - QCOMPARE(countSpy.count(), 0); - QCOMPARE(objectSpy.count(), 0); - QCOMPARE(modelSpy.count(), 0); + QCOMPARE(activeSpy.size(), 0); + QCOMPARE(countSpy.size(), 0); + QCOMPARE(objectSpy.size(), 0); + QCOMPARE(modelSpy.size(), 0); instantiator->setActive(true); QCOMPARE(instantiator->isActive(), true); QCOMPARE(instantiator->count(), 1); - QCOMPARE(activeSpy.count(), 1); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(objectSpy.count(), 1); - QCOMPARE(modelSpy.count(), 0); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(objectSpy.size(), 1); + QCOMPARE(modelSpy.size(), 0); QObject *object = instantiator->object(); QVERIFY(object); @@ -178,18 +178,18 @@ void tst_qqmlinstantiator::intModelChange() QSignalSpy modelSpy(instantiator, SIGNAL(modelChanged())); QCOMPARE(instantiator->count(), 10); - QCOMPARE(activeSpy.count(), 0); - QCOMPARE(countSpy.count(), 0); - QCOMPARE(objectSpy.count(), 0); - QCOMPARE(modelSpy.count(), 0); + QCOMPARE(activeSpy.size(), 0); + QCOMPARE(countSpy.size(), 0); + QCOMPARE(objectSpy.size(), 0); + QCOMPARE(modelSpy.size(), 0); instantiator->setModel(QVariant(2)); QCOMPARE(instantiator->count(), 2); - QCOMPARE(activeSpy.count(), 0); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(objectSpy.count(), 2); - QCOMPARE(modelSpy.count(), 1); + QCOMPARE(activeSpy.size(), 0); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(objectSpy.size(), 2); + QCOMPARE(modelSpy.size(), 1); for (int i=0; i<2; i++) { QObject *object = instantiator->objectAt(i); @@ -267,7 +267,7 @@ void tst_qqmlinstantiator::handlerWithParent() QScopedPointer<QObject> rootObject(component.create()); QVERIFY(rootObject != nullptr); const auto handlers = rootObject->findChildren<QObject *>("pointHandler"); - QCOMPARE(handlers.count(), 2); + QCOMPARE(handlers.size(), 2); for (const auto *h : handlers) { QCOMPARE(h->parent(), rootObject.data()); } diff --git a/tests/auto/qml/qqmlitemmodels/qtestmodel.h b/tests/auto/qml/qqmlitemmodels/qtestmodel.h index 9839e4c7f9..6cbec533b1 100644 --- a/tests/auto/qml/qqmlitemmodels/qtestmodel.h +++ b/tests/auto/qml/qqmlitemmodels/qtestmodel.h @@ -74,7 +74,7 @@ public: Node *n = (Node*)parent.internalPointer(); if (!n) n = tree; - return n->children.count(); + return n->children.size(); } int columnCount(const QModelIndex& parent = QModelIndex()) const override { @@ -97,7 +97,7 @@ public: Node *pn = (Node*)parent.internalPointer(); if (!pn) pn = tree; - if (row >= pn->children.count()) + if (row >= pn->children.size()) return QModelIndex(); Node *n = pn->children.at(row); @@ -130,7 +130,7 @@ public: if (pn != tree) pn = pn->parent; if (idx.row() < 0 || idx.column() < 0 || idx.column() >= cols - || idx.row() >= pn->children.count()) { + || idx.row() >= pn->children.size()) { wrongIndex = true; qWarning("Invalid modelIndex [%d,%d,%p]", idx.row(), idx.column(), idx.internalPointer()); @@ -268,15 +268,15 @@ public: void addRows(int row, int count) { if (count > 0) { - children.reserve(children.count() + count); + children.reserve(children.size() + count); children.insert(row, count, (Node *)0); } } void removeRows(int row, int count, bool keepAlive = false) { - int newCount = qMax(children.count() - count, 0); - int effectiveCountDiff = children.count() - newCount; + int newCount = qMax(children.size() - count, 0); + int effectiveCountDiff = children.size() - newCount; if (effectiveCountDiff > 0) { if (!keepAlive) for (int i = 0; i < effectiveCountDiff; i++) diff --git a/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp b/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp index f046fcd35d..339a61f996 100644 --- a/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp +++ b/tests/auto/qml/qqmlitemmodels/tst_qqmlitemmodels.cpp @@ -163,7 +163,7 @@ void tst_qqmlitemmodels::itemSelection() QCOMPARE(isVariant.userType(), qMetaTypeId<QItemSelection>()); const QItemSelection &sel = isVariant.value<QItemSelection>(); - QCOMPARE(sel.count(), object->itemSelection().count()); + QCOMPARE(sel.size(), object->itemSelection().size()); QCOMPARE(sel, object->itemSelection()); } } @@ -181,7 +181,7 @@ void tst_qqmlitemmodels::modelIndexList() QCOMPARE(object->property("count").toInt(), 10); const QModelIndexList &mil = object->modelIndexList(); - QCOMPARE(mil.count(), 4); + QCOMPARE(mil.size(), 4); for (int i = 0; i < 3; i++) QCOMPARE(mil.at(i), model.index(2 + i, 2 + i)); QCOMPARE(mil.at(3), QModelIndex()); // The string inserted at the end should result in an invalid index @@ -198,7 +198,7 @@ void tst_qqmlitemmodels::modelIndexList() QCOMPARE(milVariant.userType(), qMetaTypeId<QModelIndexList>()); const QModelIndexList &milProp = milVariant.value<QModelIndexList>(); - QCOMPARE(milProp.count(), mil.count()); + QCOMPARE(milProp.size(), mil.size()); QCOMPARE(milProp, mil); } } diff --git a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp index a5efd3147e..9646e8004a 100644 --- a/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp +++ b/tests/auto/qml/qqmljsscope/tst_qqmljsscope.cpp @@ -571,7 +571,7 @@ void tst_qqmljsscope::scriptIndices() queue.push_back(c); } - for (const QmlIR::Object *irObject : qAsConst(document.objects)) { + for (const QmlIR::Object *irObject : std::as_const(document.objects)) { const QString objectName = document.stringAt(irObject->inheritedTypeNameIndex); for (auto it = irObject->functionsBegin(); it != irObject->functionsEnd(); ++it) { QString name = document.stringAt(it->nameIndex); diff --git a/tests/auto/qml/qqmllanguage/data/ComponentType.qml b/tests/auto/qml/qqmllanguage/data/ComponentType.qml new file mode 100644 index 0000000000..e8addde1c4 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/ComponentType.qml @@ -0,0 +1,8 @@ +import QtQml + +Component { + id: componentRoot + QtObject { + objectName: "enclosed" + } +} diff --git a/tests/auto/qml/qqmllanguage/data/SignalInlineComponentArg.qml b/tests/auto/qml/qqmllanguage/data/SignalInlineComponentArg.qml new file mode 100644 index 0000000000..0424ac1534 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/SignalInlineComponentArg.qml @@ -0,0 +1,21 @@ +import QtQuick + +Item { + component Abc: Item { + property string success + } + + signal canYouFeelIt(arg1: Abc) + property Abc someAbc: Abc { + success: "Signal was called" + } + property string success: "Signal not called yet" + + Component.onCompleted: { + canYouFeelIt(someAbc); + } + + onCanYouFeelIt: (arg) => { + success = arg.success + } +} diff --git a/tests/auto/qml/qqmllanguage/data/alias.15.qml b/tests/auto/qml/qqmllanguage/data/alias.15.qml index 5f3de9c83e..7e362d8823 100644 --- a/tests/auto/qml/qqmllanguage/data/alias.15.qml +++ b/tests/auto/qml/qqmllanguage/data/alias.15.qml @@ -9,4 +9,25 @@ Item { Item { id: symbol } + + Rectangle { + id: txtElevationValue + + property Rectangle background: Rectangle { } + + state: "ValidatorInvalid" + + states: [ + State { + name: "ValidatorInvalid" + PropertyChanges { + target: txtElevationValue + background.border.color: "red" // this line caused the segfault in qtbug107795 + } + }, + State { + name: "ValidatorAcceptable" + } + ] + } } diff --git a/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml b/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml new file mode 100644 index 0000000000..1b8ba61725 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/badGroupedProperty.qml @@ -0,0 +1,10 @@ +import QtQml + +QtObject { + id: testItem + property rect rect + onComplete { + rect.x: 2 + rect.width: 22 + } +} diff --git a/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl.qml b/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl.qml new file mode 100644 index 0000000000..44fbd03354 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl.qml @@ -0,0 +1,10 @@ +import QtQuick +Item { + id: root + Component { + id: accessibleNormal + Item {} + } + property alias accessibleNormalUrl: accessibleNormal.url + property url urlClone: root.accessibleNormalUrl // crashes qml utility +} diff --git a/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl2.qml b/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl2.qml new file mode 100644 index 0000000000..cfdec5e39b --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/bindingAliasToComponentUrl2.qml @@ -0,0 +1,11 @@ +import QtQuick +Item { + id: root + Component { + id: accessibleNormal + ComponentType { + id: inaccessibleNormal + } + } + property alias accessibleNormalProgress: accessibleNormal.progress +} diff --git a/tests/auto/qml/qqmllanguage/data/nullIsNull.qml b/tests/auto/qml/qqmllanguage/data/nullIsNull.qml new file mode 100644 index 0000000000..a6cbbee0bf --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/nullIsNull.qml @@ -0,0 +1,28 @@ +import QtQml + +QtObject { + id: root + property alias someProperty: internal.someProperty + + property Timer t: Timer { + interval: 1 + running: true + onTriggered: root.someProperty = null + } + + property QtObject a: QtObject { + id: someObjectInstance + } + + property QtObject b: QtObject { + id: internal + property QtObject someProperty: someObjectInstance ? someObjectInstance : null + } + + property Connections c: Connections { + target: internal + function onSomePropertyChanged() { + internal.someProperty = null + } + } +} diff --git a/tests/auto/qml/qqmllanguage/data/signalInlineComponentArg1.qml b/tests/auto/qml/qqmllanguage/data/signalInlineComponentArg1.qml new file mode 100644 index 0000000000..e20710edd9 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/signalInlineComponentArg1.qml @@ -0,0 +1,30 @@ +import QtQuick + +// this file performs two tests: first, using a signal with a inline component from another file +// and second, calling the signal from another file using an inline component from another file + +Item { + signal canYouFeelIt(arg1:SignalInlineComponentArg.Abc) + + property SignalInlineComponentArg.Abc someAbc: SignalInlineComponentArg.Abc { + success: "Own signal was called with component from another file" + } + + property SignalInlineComponentArg fromAnotherFile: SignalInlineComponentArg {} + + // success of own signal call with parameter from another file + property string successFromOwnSignal: "Signal not called yet" + // makes it easier to test + property string successFromSignalFromFile: fromAnotherFile.success + + Component.onCompleted: { + canYouFeelIt(someAbc); + fromAnotherFile.someAbc.success = "Signal was called from another file" + fromAnotherFile.canYouFeelIt(fromAnotherFile.someAbc) + } + + onCanYouFeelIt: (arg) => { + successFromOwnSignal = arg.success + } +} + diff --git a/tests/auto/qml/qqmllanguage/testtypes.cpp b/tests/auto/qml/qqmllanguage/testtypes.cpp index 2b6f8e867e..f4b6acc848 100644 --- a/tests/auto/qml/qqmllanguage/testtypes.cpp +++ b/tests/auto/qml/qqmllanguage/testtypes.cpp @@ -189,7 +189,7 @@ void CustomBinding::componentComplete() void EnumSupportingCustomParser::verifyBindings(const QQmlRefPointer<QV4::ExecutableCompilationUnit> &compilationUnit, const QList<const QV4::CompiledData::Binding *> &bindings) { - if (bindings.count() != 1) { + if (bindings.size() != 1) { error(bindings.first(), QStringLiteral("Custom parser invoked incorrectly for unit test")); return; } @@ -221,7 +221,7 @@ void SimpleObjectCustomParser::applyBindings(QObject *object, const QQmlRefPoint { SimpleObjectWithCustomParser *o = qobject_cast<SimpleObjectWithCustomParser*>(object); Q_ASSERT(o); - o->setCustomBindingsCount(bindings.count()); + o->setCustomBindingsCount(bindings.size()); } diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index 59ba9594f9..409c56d504 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -387,8 +387,11 @@ private slots: void v4SequenceMethodsWithParams_data(); void v4SequenceMethodsWithParams(); void jsFunctionOverridesImport(); - + void bindingAliasToComponentUrl(); + void badGroupedProperty(); void bindableOnly(); + void signalInlineComponentArg(); + void nullIsNull(); private: QQmlEngine engine; @@ -6143,7 +6146,7 @@ void tst_qqmllanguage::qualifiedScopeInCustomParser() "ListModel {\n" " ListElement { text: \"a\"; type: BACKEND.EnumTester.FIRST }\n" "}\n", QUrl()); - QVERIFY(component.isReady()); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); QScopedPointer<QObject> obj(component.create()); QVERIFY(!obj.isNull()); } @@ -7367,6 +7370,69 @@ void tst_qqmllanguage::jsFunctionOverridesImport() QCOMPARE(object->objectName(), u"foo"_s); } +void tst_qqmllanguage::bindingAliasToComponentUrl() +{ + QQmlEngine engine; + { + QQmlComponent component(&engine, testFileUrl("bindingAliasToComponentUrl.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + QVERIFY(object); + QCOMPARE(object->property("accessibleNormalUrl"), object->property("urlClone")); + } + { + QQmlComponent component(&engine, testFileUrl("bindingAliasToComponentUrl2.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + QVERIFY(object); + QCOMPARE(object->property("accessibleNormalProgress"), QVariant(1.0)); + } +} + +void tst_qqmllanguage::badGroupedProperty() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("badGroupedProperty.qml"); + QQmlComponent c(&engine, url); + QVERIFY(c.isError()); + QCOMPARE(c.errorString(), + QStringLiteral("%1:6 Cannot assign to non-existent property \"onComplete\"\n") + .arg(url.toString())); +} + +void tst_qqmllanguage::signalInlineComponentArg() +{ + QQmlEngine engine; + { + QQmlComponent component(&engine, testFileUrl("SignalInlineComponentArg.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + + QCOMPARE(object->property("success"), u"Signal was called"_s); + } + { + QQmlComponent component(&engine, testFileUrl("signalInlineComponentArg1.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> object(component.create()); + + QCOMPARE(object->property("successFromOwnSignal"), + u"Own signal was called with component from another file"_s); + QCOMPARE(object->property("successFromSignalFromFile"), + u"Signal was called from another file"_s); + } +} + +void tst_qqmllanguage::nullIsNull() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("nullIsNull.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> o(c.create()); + QVERIFY(!o.isNull()); + QVERIFY(o->property("someProperty").value<QObject*>() != nullptr); + QTRY_COMPARE(o->property("someProperty").value<QObject*>(), nullptr); +} + QTEST_MAIN(tst_qqmllanguage) #include "tst_qqmllanguage.moc" diff --git a/tests/auto/qml/qqmllistcompositor/tst_qqmllistcompositor.cpp b/tests/auto/qml/qqmllistcompositor/tst_qqmllistcompositor.cpp index dd9df84867..2d02cac9f8 100644 --- a/tests/auto/qml/qqmllistcompositor/tst_qqmllistcompositor.cpp +++ b/tests/auto/qml/qqmllistcompositor/tst_qqmllistcompositor.cpp @@ -1022,7 +1022,7 @@ void tst_qqmllistcompositor::moveFromEnd() QVector<C::Insert> inserts; compositor.listItemsInserted(a, 0, 1, &inserts); - QCOMPARE(inserts.count(), 1); + QCOMPARE(inserts.size(), 1); QCOMPARE(inserts.at(0).index[1], 1); QCOMPARE(inserts.at(0).count, 1); diff --git a/tests/auto/qml/qqmllistmodel/data/Model.qml b/tests/auto/qml/qqmllistmodel/data/Model.qml new file mode 100644 index 0000000000..f6aeed5bdd --- /dev/null +++ b/tests/auto/qml/qqmllistmodel/data/Model.qml @@ -0,0 +1,9 @@ +import QtQml.Models + +ListModel { + enum Choose { Foo, Bar, Baz } + + ListElement { choose: Model.Choose.Foo } + ListElement { choose: Model.Choose.Bar } + ListElement { choose: Model.Choose.Baz } +} diff --git a/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml b/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml new file mode 100644 index 0000000000..e8d594dfd8 --- /dev/null +++ b/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml @@ -0,0 +1,8 @@ +import QtQuick + +ListView { + width: 180 + height: 200 + model: Model {} + delegate: Text { text: choose } +} diff --git a/tests/auto/qml/qqmllistmodel/data/protectQObjectFromGC.qml b/tests/auto/qml/qqmllistmodel/data/protectQObjectFromGC.qml new file mode 100644 index 0000000000..43b375b681 --- /dev/null +++ b/tests/auto/qml/qqmllistmodel/data/protectQObjectFromGC.qml @@ -0,0 +1,21 @@ +import QtQml +import QtQml.Models + +ListModel { + id: filesModel + property Component testComponent: Component { + id: testComponent + QtObject { + required property string name + } + } + Component.onCompleted: { + filesModel.clear() + for(let i = 0; i < 10; i++) { + filesModel.append({ + path: testComponent.createObject(null, { name: "" + i }) + }) + } + gc() + } +} diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp index c92956bd49..e522f280a3 100644 --- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp +++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp @@ -4,6 +4,7 @@ #include <QtQuick/private/qquickitem_p.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQuick/private/qquickanimation_p.h> +#include <QtQuick/private/qquicklistview_p.h> #include <QtQml/private/qqmlengine_p.h> #include <QtQmlModels/private/qqmllistmodel_p.h> #include <QtQml/private/qqmlexpression_p.h> @@ -116,6 +117,8 @@ private slots: void listElementWithTemplateString(); void destroyComponentObject(); void objectOwnershipFlip(); + void enumsInListElement(); + void protectQObjectFromGC(); }; bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object) @@ -126,10 +129,10 @@ bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVarian if (model == nullptr) return false; - if (model->count() != testList.count()) + if (model->count() != testList.size()) return false; - for (int i=0 ; i < testList.count() ; ++i) { + for (int i=0 ; i < testList.size() ; ++i) { const QVariant &testVariant = testList.at(i); if (testVariant.typeId() != QMetaType::QVariantMap) return false; @@ -595,7 +598,7 @@ void tst_qqmllistmodel::dynamic() QCOMPARE(actual,result); if (model.count() > 0) - QVERIFY(spyCount.count() > 0); + QVERIFY(spyCount.size() > 0); } void tst_qqmllistmodel::enumerate() @@ -703,7 +706,7 @@ void tst_qqmllistmodel::error() } else { QVERIFY(component.isError()); QList<QQmlError> errors = component.errors(); - QCOMPARE(errors.count(),1); + QCOMPARE(errors.size(),1); QCOMPARE(errors.at(0).description(),error); } } @@ -801,7 +804,7 @@ void tst_qqmllistmodel::get() QCOMPARE(model->data(index, role), roleValue); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> spyResult = spy.takeFirst(); QCOMPARE(spyResult.at(0).value<QModelIndex>(), model->index(index, 0, QModelIndex())); @@ -902,7 +905,7 @@ void tst_qqmllistmodel::get_nested() testData << qMakePair(1, QString("listRoleB")); testData << qMakePair(1, QString("listRoleC")); - for (int i=0; i<testData.count(); i++) { + for (int i=0; i<testData.size(); i++) { int outerListIndex = testData[i].first; QString outerListRoleName = testData[i].second; int outerListRole = roleFromName(model, outerListRoleName); @@ -925,7 +928,7 @@ void tst_qqmllistmodel::get_nested() } else { QCOMPARE(childModel->data(index, role), roleValue); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> spyResult = spy.takeFirst(); QCOMPARE(spyResult.at(0).value<QModelIndex>(), childModel->index(index, 0, QModelIndex())); @@ -1095,7 +1098,7 @@ void tst_qqmllistmodel::property_changes() expr.evaluate(); QVERIFY2(!expr.hasError(), qPrintable(expr.error().toString())); - QString signalHandler = "on" + QString(roleName[0].toUpper()) + roleName.mid(1, roleName.length()) + "Changed:"; + QString signalHandler = "on" + QString(roleName[0].toUpper()) + roleName.mid(1, roleName.size()) + "Changed:"; QString qml = "import QtQuick 2.0\n" "Connections {\n" "property bool gotSignal: false\n" @@ -1120,11 +1123,11 @@ void tst_qqmllistmodel::property_changes() // test itemsChanged() is emitted correctly if (itemsChanged) { - QCOMPARE(spyItemsChanged.count(), 1); + QCOMPARE(spyItemsChanged.size(), 1); QCOMPARE(spyItemsChanged.at(0).at(0).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex())); QCOMPARE(spyItemsChanged.at(0).at(1).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex())); } else { - QCOMPARE(spyItemsChanged.count(), 0); + QCOMPARE(spyItemsChanged.size(), 0); } expr.setExpression(testExpression); @@ -1641,7 +1644,7 @@ void tst_qqmllistmodel::crash_append_empty_array() QQmlExpression expr(engine.rootContext(), model, "append(new Array())"); expr.evaluate(); QVERIFY2(!expr.hasError(), qPrintable(expr.error().toString())); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } void tst_qqmllistmodel::dynamic_roles_crash_QTBUG_38907() @@ -1853,7 +1856,7 @@ void tst_qqmllistmodel::destroyComponentObject() Q_RETURN_ARG(QVariant, retVal)); QVERIFY(retVal.toBool()); QTRY_VERIFY(created.isNull()); - QTRY_VERIFY(list->get(0).property("obj").isUndefined()); + QTRY_VERIFY(list->get(0).property("obj").isNull()); QCOMPARE(list->count(), 1); } @@ -1891,6 +1894,41 @@ void tst_qqmllistmodel::objectOwnershipFlip() QCOMPARE(QJSEngine::objectOwnership(item.data()), QJSEngine::CppOwnership); } +void tst_qqmllistmodel::enumsInListElement() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("enumsInListElement.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> root(component.create()); + QVERIFY(!root.isNull()); + + QQuickListView *listView = qobject_cast<QQuickListView *>(root.data()); + QVERIFY(listView); + QCOMPARE(listView->count(), 3); + for (int i = 0; i < 3; ++i) { + QCOMPARE(listView->itemAtIndex(i)->property("text"), QVariant(QString::number(i))); + } +} + +void tst_qqmllistmodel::protectQObjectFromGC() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("protectQObjectFromGC.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> root(component.create()); + QVERIFY(!root.isNull()); + + QQmlListModel *listModel = qobject_cast<QQmlListModel *>(root.data()); + QVERIFY(listModel); + QCOMPARE(listModel->count(), 10); + + for (int i = 0; i < 10; ++i) { + QObject *element = qjsvalue_cast<QObject *>(listModel->get(i).property("path")); + QVERIFY(element); + QCOMPARE(element->property("name").toString(), QString::number(i)); + } +} + QTEST_MAIN(tst_qqmllistmodel) #include "tst_qqmllistmodel.moc" diff --git a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp index 6a9cc93abd..4875602314 100644 --- a/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp +++ b/tests/auto/qml/qqmllistmodelworkerscript/tst_qqmllistmodelworkerscript.cpp @@ -91,10 +91,10 @@ bool tst_qqmllistmodelworkerscript::compareVariantList(const QVariantList &testL if (model == nullptr) return false; - if (model->count() != testList.count()) + if (model->count() != testList.size()) return false; - for (int i=0 ; i < testList.count() ; ++i) { + for (int i=0 ; i < testList.size() ; ++i) { const QVariant &testVariant = testList.at(i); if (testVariant.typeId() != QMetaType::QVariantMap) return false; @@ -331,8 +331,8 @@ void tst_qqmllistmodelworkerscript::dynamic_worker() QSignalSpy spyCount(&model, SIGNAL(countChanged())); - if (script[0] == QLatin1Char('{') && script[script.length()-1] == QLatin1Char('}')) - script = script.mid(1, script.length() - 2); + if (script[0] == QLatin1Char('{') && script[script.size()-1] == QLatin1Char('}')) + script = script.mid(1, script.size() - 2); QVariantList operations; foreach (const QString &s, script.split(';')) { if (!s.isEmpty()) @@ -348,7 +348,7 @@ void tst_qqmllistmodelworkerscript::dynamic_worker() QCOMPARE(QQmlProperty(item, "result").read().toInt(), result); if (model.count() > 0) - QVERIFY(spyCount.count() > 0); + QVERIFY(spyCount.size() > 0); delete item; qApp->processEvents(); @@ -380,8 +380,8 @@ void tst_qqmllistmodelworkerscript::dynamic_worker_sync() QQuickItem *item = createWorkerTest(&eng, &component, &model); QVERIFY(item != nullptr); - if (script[0] == QLatin1Char('{') && script[script.length()-1] == QLatin1Char('}')) - script = script.mid(1, script.length() - 2); + if (script[0] == QLatin1Char('{') && script[script.size()-1] == QLatin1Char('}')) + script = script.mid(1, script.size() - 2); QVariantList operations; foreach (const QString &s, script.split(';')) { if (!s.isEmpty()) @@ -394,7 +394,7 @@ void tst_qqmllistmodelworkerscript::dynamic_worker_sync() // execute a set of commands on the worker list model, then check the // changes are reflected in the list model in the main thread QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", - Q_ARG(QVariant, operations.mid(0, operations.length()-1)))); + Q_ARG(QVariant, operations.mid(0, operations.size()-1)))); waitForWorker(item); QQmlExpression e(eng.rootContext(), &model, operations.last().toString()); @@ -468,7 +468,7 @@ void tst_qqmllistmodelworkerscript::get_worker() QCOMPARE(model.data(index, role), roleValue); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> spyResult = spy.takeFirst(); QCOMPARE(spyResult.at(0).value<QModelIndex>(), model.index(index, 0, QModelIndex())); @@ -585,11 +585,11 @@ void tst_qqmllistmodelworkerscript::property_changes_worker() // test itemsChanged() is emitted correctly if (itemsChanged) { - QCOMPARE(spyItemsChanged.count(), 1); + QCOMPARE(spyItemsChanged.size(), 1); QCOMPARE(spyItemsChanged.at(0).at(0).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex())); QCOMPARE(spyItemsChanged.at(0).at(1).value<QModelIndex>(), model.index(listIndex, 0, QModelIndex())); } else { - QCOMPARE(spyItemsChanged.count(), 0); + QCOMPARE(spyItemsChanged.size(), 0); } delete item; @@ -638,32 +638,32 @@ void tst_qqmllistmodelworkerscript::worker_sync() QCOMPARE(model.count(), 2); QCOMPARE(childModel->count(), 1); - QCOMPARE(spyModelInserted.count(), 0); - QCOMPARE(spyChildInserted.count(), 0); + QCOMPARE(spyModelInserted.size(), 0); + QCOMPARE(spyChildInserted.size(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); QCOMPARE(model.count(), 2); QCOMPARE(childModel->count(), 2); - QCOMPARE(spyModelInserted.count(), 0); - QCOMPARE(spyChildInserted.count(), 1); + QCOMPARE(spyModelInserted.size(), 0); + QCOMPARE(spyChildInserted.size(), 1); QVERIFY(QMetaObject::invokeMethod(item, "addItemViaWorker")); waitForWorker(item); QCOMPARE(model.count(), 2); QCOMPARE(childModel->count(), 2); - QCOMPARE(spyModelInserted.count(), 0); - QCOMPARE(spyChildInserted.count(), 1); + QCOMPARE(spyModelInserted.size(), 0); + QCOMPARE(spyChildInserted.size(), 1); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); QCOMPARE(model.count(), 2); QCOMPARE(childModel->count(), 3); - QCOMPARE(spyModelInserted.count(), 0); - QCOMPARE(spyChildInserted.count(), 2); + QCOMPARE(spyModelInserted.size(), 0); + QCOMPARE(spyChildInserted.size(), 2); delete item; qApp->processEvents(); @@ -688,7 +688,7 @@ void tst_qqmllistmodelworkerscript::worker_remove_element() QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QCOMPARE(model.count(), 0); - QCOMPARE(spyModelRemoved.count(), 0); + QCOMPARE(spyModelRemoved.size(), 0); QVERIFY(QMetaObject::invokeMethod(item, "addItem")); @@ -698,13 +698,13 @@ void tst_qqmllistmodelworkerscript::worker_remove_element() waitForWorker(item); QCOMPARE(model.count(), 1); - QCOMPARE(spyModelRemoved.count(), 0); + QCOMPARE(spyModelRemoved.size(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); QCOMPARE(model.count(), 0); - QCOMPARE(spyModelRemoved.count(), 1); + QCOMPARE(spyModelRemoved.size(), 1); delete item; qApp->processEvents(); @@ -751,7 +751,7 @@ void tst_qqmllistmodelworkerscript::worker_remove_list() QSignalSpy spyModelRemoved(&model, SIGNAL(rowsRemoved(QModelIndex,int,int))); QCOMPARE(model.count(), 0); - QCOMPARE(spyModelRemoved.count(), 0); + QCOMPARE(spyModelRemoved.size(), 0); QVERIFY(QMetaObject::invokeMethod(item, "addList")); @@ -761,13 +761,13 @@ void tst_qqmllistmodelworkerscript::worker_remove_list() waitForWorker(item); QCOMPARE(model.count(), 1); - QCOMPARE(spyModelRemoved.count(), 0); + QCOMPARE(spyModelRemoved.size(), 0); QVERIFY(QMetaObject::invokeMethod(item, "doSync")); waitForWorker(item); QCOMPARE(model.count(), 0); - QCOMPARE(spyModelRemoved.count(), 1); + QCOMPARE(spyModelRemoved.size(), 1); delete item; qApp->processEvents(); @@ -798,8 +798,8 @@ void tst_qqmllistmodelworkerscript::dynamic_role() QQmlExpression preExp(engine.rootContext(), &model, preamble); QCOMPARE(preExp.evaluate().toInt(), 0); - if (script[0] == QLatin1Char('{') && script[script.length()-1] == QLatin1Char('}')) - script = script.mid(1, script.length() - 2); + if (script[0] == QLatin1Char('{') && script[script.size()-1] == QLatin1Char('}')) + script = script.mid(1, script.size() - 2); QVariantList operations; foreach (const QString &s, script.split(';')) { if (!s.isEmpty()) @@ -809,7 +809,7 @@ void tst_qqmllistmodelworkerscript::dynamic_role() // execute a set of commands on the worker list model, then check the // changes are reflected in the list model in the main thread QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker", - Q_ARG(QVariant, operations.mid(0, operations.length()-1)))); + Q_ARG(QVariant, operations.mid(0, operations.size()-1)))); waitForWorker(item); QQmlExpression e(engine.rootContext(), &model, operations.last().toString()); diff --git a/tests/auto/qml/qqmllocale/data/functions.qml b/tests/auto/qml/qqmllocale/data/functions.qml index 9fee78a836..42e26a508c 100644 --- a/tests/auto/qml/qqmllocale/data/functions.qml +++ b/tests/auto/qml/qqmllocale/data/functions.qml @@ -3,9 +3,6 @@ import QtQuick QtObject { property var locale: Qt.locale() - // TODO: Workaround for not being able to use "Locale" in QQmlExpression (QTBUG-91747). - property var localeType: Locale - function setLocale(l) { locale = Qt.locale(l) } diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index 90420b7630..b678fbd1e2 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -498,9 +498,9 @@ void tst_qqmllocale::weekDays() QList<QVariant> qmlDays = val.toList(); QList<Qt::DayOfWeek> days = QLocale(locale).weekdays(); - QCOMPARE(days.count(), qmlDays.count()); + QCOMPARE(days.size(), qmlDays.size()); - for (int i = 0; i < days.count(); ++i) { + for (int i = 0; i < days.size(); ++i) { int day = int(days.at(i)); if (day == 7) // JS Date days in range 0(Sunday) to 6(Saturday) day = 0; @@ -540,9 +540,9 @@ void tst_qqmllocale::uiLanguages() QList<QVariant> qmlLangs = val.toList(); QStringList langs = QLocale(locale).uiLanguages(); - QCOMPARE(langs.count(), qmlLangs.count()); + QCOMPARE(langs.size(), qmlLangs.size()); - for (int i = 0; i < langs.count(); ++i) { + for (int i = 0; i < langs.size(); ++i) { QCOMPARE(langs.at(i), qmlLangs.at(i).toString()); } @@ -663,15 +663,15 @@ void tst_qqmllocale::addFormattedDataSizeDataForLocale(const QString &localeStr) expectedResult = locale.formattedDataSize(1000000, 3); QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage; - functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeIecFormat)"); + functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeIecFormat)"); expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeIecFormat); QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage; - functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeTraditionalFormat)"); + functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeTraditionalFormat)"); expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeTraditionalFormat); QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage; - functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, localeType.DataSizeSIFormat)"); + functionCallScript = QLatin1String("locale.formattedDataSize(1000000, 3, Locale.DataSizeSIFormat)"); expectedResult = locale.formattedDataSize(1000000, 3, QLocale::DataSizeSIFormat); QTest::newRow(qPrintable(makeTag())) << localeStr << functionCallScript << expectedResult << expectedErrorMessage; } @@ -695,7 +695,7 @@ void tst_qqmllocale::formattedDataSize_data() QString errorMessage = ".*Locale: formattedDataSize\\(\\): Expected 1-3 arguments, but received 0"; QTest::newRow("too few args") << "en_AU" << functionCallScript << QString() << errorMessage; - functionCallScript = "locale.formattedDataSize(10, 1, localeType.DataSizeIecFormat, \"foo\")"; + functionCallScript = "locale.formattedDataSize(10, 1, Locale.DataSizeIecFormat, \"foo\")"; errorMessage = ".*Locale: formattedDataSize\\(\\): Expected 1-3 arguments, but received 4"; QTest::newRow("too many args") << "en_AU" << functionCallScript << QString() << errorMessage; @@ -727,7 +727,9 @@ void tst_qqmllocale::formattedDataSize() QVERIFY(QMetaObject::invokeMethod(object.data(), "setLocale", Qt::DirectConnection, Q_ARG(QVariant, QVariant(localeStr)))); - QQmlExpression qmlExpression(engine.rootContext(), object.data(), functionCallScript); + // Make sure that we use the object's context rather than the root context, + // so that e.g. enums from the Locale type are available (QTBUG-91747). + QQmlExpression qmlExpression(qmlContext(object.data()), object.data(), functionCallScript); const QVariant evaluationResult = qmlExpression.evaluate(); if (expectedErrorMessagePattern.isEmpty()) { QVERIFY2(!qmlExpression.hasError(), qPrintable(qmlExpression.error().toString())); diff --git a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp index ed6f24aaf3..d945f460eb 100644 --- a/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp +++ b/tests/auto/qml/qqmlmetaobject/tst_qqmlmetaobject.cpp @@ -227,18 +227,18 @@ void tst_QQmlMetaObject::property() QCOMPARE(value, expectedValue); else QVERIFY(value.isValid()); - QCOMPARE(changedSpy.count(), 0); + QCOMPARE(changedSpy.size(), 0); if (isWritable) { QVERIFY(prop.write(object, newValue)); - QCOMPARE(changedSpy.count(), 1); + QCOMPARE(changedSpy.size(), 1); QVariant value = prop.read(object); if (value.userType() == qMetaTypeId<QJSValue>()) value = value.value<QJSValue>().toVariant(); QCOMPARE(value, newValue); } else { QVERIFY(!prop.write(object, prop.read(object))); - QCOMPARE(changedSpy.count(), 0); + QCOMPARE(changedSpy.size(), 0); } } diff --git a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp index 6f4221539d..1304930583 100644 --- a/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp +++ b/tests/auto/qml/qqmlmetatype/tst_qqmlmetatype.cpp @@ -49,6 +49,8 @@ private slots: void enumsInRecursiveImport_data(); void enumsInRecursiveImport(); + + void clearPropertyCaches(); }; class TestType : public QObject @@ -711,6 +713,18 @@ void tst_qqmlmetatype::enumsInRecursiveImport() QTRY_COMPARE(obj->property("color").toString(), QString("green")); } +void tst_qqmlmetatype::clearPropertyCaches() +{ + qmlClearTypeRegistrations(); + qmlRegisterType<TestType>("ClearPropertyCaches", 1, 0, "A"); + QQmlPropertyCache::ConstPtr oldCache = QQmlMetaType::propertyCache(&TestType::staticMetaObject); + QVERIFY(oldCache); + qmlClearTypeRegistrations(); + qmlRegisterType<TestType>("ClearPropertyCaches", 1, 0, "B"); + QQmlPropertyCache::ConstPtr newCache = QQmlMetaType::propertyCache(&TestType::staticMetaObject); + QVERIFY(oldCache.data() != newCache.data()); +} + QTEST_MAIN(tst_qqmlmetatype) #include "tst_qqmlmetatype.moc" diff --git a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp index b36a43243d..a4901aebad 100644 --- a/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp +++ b/tests/auto/qml/qqmlmoduleplugin/tst_qqmlmoduleplugin.cpp @@ -133,7 +133,7 @@ void registerStaticPlugin(const char *uri) PluginType::metaData.append(QCborValue(QCborMap::fromJsonObject(md)).toCbor()); auto rawMetaDataFunctor = []() -> QPluginMetaData { - return {reinterpret_cast<const uchar *>(PluginType::metaData.constData()), size_t(PluginType::metaData.length())}; + return {reinterpret_cast<const uchar *>(PluginType::metaData.constData()), size_t(PluginType::metaData.size())}; }; QStaticPlugin plugin(instanceFunctor, rawMetaDataFunctor); qRegisterStaticPluginFunction(plugin); @@ -235,7 +235,7 @@ void tst_qqmlmoduleplugin::incorrectPluginCase() QQmlComponent component(&engine, testFileUrl(QStringLiteral("incorrectCase.qml"))); QList<QQmlError> errors = component.errors(); - QCOMPARE(errors.count(), 1); + QCOMPARE(errors.size(), 1); QString expectedError = QLatin1String("module \"org.qtproject.WrongCase\" plugin \"PluGin\" not found"); @@ -566,7 +566,7 @@ void tst_qqmlmoduleplugin::importStrictModule() QVERIFY(object != nullptr); } else { QVERIFY(!component.isReady()); - QCOMPARE(component.errors().count(), 1); + QCOMPARE(component.errors().size(), 1); QCOMPARE(component.errors().first().toString(), url.toString() + error); } } diff --git a/tests/auto/qml/qqmlnotifier/BLACKLIST b/tests/auto/qml/qqmlnotifier/BLACKLIST new file mode 100644 index 0000000000..fc23287720 --- /dev/null +++ b/tests/auto/qml/qqmlnotifier/BLACKLIST @@ -0,0 +1,3 @@ +# e64548973d33295268881ac3bed49d1bbedd8a10 +[deleteFromHandler] +macos ci diff --git a/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp index 438dc3d3c2..d007f4d024 100644 --- a/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp +++ b/tests/auto/qml/qqmlobjectmodel/tst_qqmlobjectmodel.cpp @@ -15,7 +15,7 @@ private slots: static bool compareItems(QQmlObjectModel *model, const QObjectList &items) { - for (int i = 0; i < items.count(); ++i) { + for (int i = 0; i < items.size(); ++i) { if (model->get(i) != items.at(i)) return false; } @@ -65,81 +65,81 @@ void tst_QQmlObjectModel::changes() model.append(&item0); items.append(&item0); QCOMPARE(model.count(), ++count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 0, false)); // insert(0, item1) -> [item1, item0] model.insert(0, &item1); items.insert(0, &item1); QCOMPARE(model.count(), ++count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 0, false)); // append(item2) -> [item1, item0, item2] model.append(&item2); items.append(&item2); QCOMPARE(model.count(), ++count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 0, false)); // insert(2, item3) -> [item1, item0, item3, item2] model.insert(2, &item3); items.insert(2, &item3); QCOMPARE(model.count(), ++count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 0, false)); // move(0, 1) -> [item0, item1, item3, item2] model.move(0, 1); items.move(0, 1); QCOMPARE(model.count(), count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 1, true, 1)); // move(3, 2) -> [item0, item1, item2, item3] model.move(3, 2); items.move(3, 2); QCOMPARE(model.count(), count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 1, 1, true, 2)); // remove(0) -> [item1, item2, item3] model.remove(0); items.removeAt(0); QCOMPARE(model.count(), --count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 0, 1, false)); // remove(2) -> [item1, item2] model.remove(2); items.removeAt(2); QCOMPARE(model.count(), --count); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 0, 1, false)); // clear() -> [] model.clear(); items.clear(); QCOMPARE(model.count(), 0); QVERIFY(compareItems(&model, items)); - QCOMPARE(countSpy.count(), ++countSignals); - QCOMPARE(childrenSpy.count(), ++childrenSignals); - QCOMPARE(modelUpdateSpy.count(), ++modelUpdateSignals); + QCOMPARE(countSpy.size(), ++countSignals); + QCOMPARE(childrenSpy.size(), ++childrenSignals); + QCOMPARE(modelUpdateSpy.size(), ++modelUpdateSignals); QVERIFY(verifyChangeSet(modelUpdateSpy.last().first().value<QQmlChangeSet>(), 0, 2, false)); } diff --git a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp index f0a3c19d16..14a1fa13f8 100644 --- a/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp +++ b/tests/auto/qml/qqmlparser/tst_qqmlparser.cpp @@ -550,7 +550,7 @@ void tst_qqmlparser::typeAnnotations_data() QStringList files; files << findFiles(QDir(tests)); - for (const QString &file: qAsConst(files)) + for (const QString &file: std::as_const(files)) QTest::newRow(qPrintable(file)) << file; } @@ -590,7 +590,7 @@ void tst_qqmlparser::disallowedTypeAnnotations_data() QStringList files; files << findFiles(QDir(tests)); - for (const QString &file: qAsConst(files)) + for (const QString &file: std::as_const(files)) QTest::newRow(qPrintable(file)) << file; } @@ -679,7 +679,7 @@ void tst_qqmlparser::annotations_data() QStringList refFiles; refFiles << findFiles(QDir(compare)); - for (const QString &file: qAsConst(files)) { + for (const QString &file: std::as_const(files)) { auto fileNameStart = file.lastIndexOf(QDir::separator()); auto fileName = QStringView(file).mid(fileNameStart, file.length()-fileNameStart); auto ref=std::find_if(refFiles.constBegin(),refFiles.constEnd(), [fileName](const QString &s){ return s.endsWith(fileName); }); diff --git a/tests/auto/qml/qqmlproperty/data/assignVariantList.qml b/tests/auto/qml/qqmlproperty/data/assignVariantList.qml new file mode 100644 index 0000000000..78565b64b9 --- /dev/null +++ b/tests/auto/qml/qqmlproperty/data/assignVariantList.qml @@ -0,0 +1,6 @@ +import Test +import QtQml + +ListHolder { + doubleList: varList +} diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 7d2dc302ea..e432c548d3 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -116,6 +116,35 @@ public: QML_DECLARE_TYPE(MyAlwaysReplaceBehaviorContainer); +class ListHolder : public QObject +{ + Q_OBJECT + Q_PROPERTY(QVariantList varList READ varList NOTIFY varListChanged) + Q_PROPERTY(QList<double> doubleList READ doubleList WRITE setDoubleList NOTIFY doubleListChanged) +public: + explicit ListHolder(QObject *parent = nullptr) : QObject(parent) {} + + QVariantList varList() const { return {1.1, 2.2, 3.3, 11, 5.25f, QStringLiteral("11")}; } + + QList<double> doubleList() const { return m_doubleList; } + + void setDoubleList(const QList<double> &newDoubleList) + { + if (m_doubleList == newDoubleList) + return; + m_doubleList = newDoubleList; + emit doubleListChanged(); + } + +signals: + void varListChanged(); + void doubleListChanged(); + +private: + QList<double> m_doubleList; +}; + + class tst_qqmlproperty : public QQmlDataTest { Q_OBJECT @@ -187,6 +216,7 @@ private slots: void constructFromPlainMetaObject(); void bindToNonQObjectTarget(); + void assignVariantList(); private: QQmlEngine engine; }; @@ -2103,7 +2133,7 @@ void tst_qqmlproperty::assignEmptyVariantMap() QVariantMap map; map.insert("key", "value"); o.setVariantMap(map); - QCOMPARE(o.variantMap().count(), 1); + QCOMPARE(o.variantMap().size(), 1); QCOMPARE(o.variantMap().isEmpty(), false); @@ -2111,7 +2141,7 @@ void tst_qqmlproperty::assignEmptyVariantMap() QObject *obj = component.createWithInitialProperties({{"o", QVariant::fromValue(&o)}}); QVERIFY(obj); - QCOMPARE(o.variantMap().count(), 0); + QCOMPARE(o.variantMap().size(), 0); QCOMPARE(o.variantMap().isEmpty(), true); delete obj; @@ -2267,6 +2297,7 @@ void tst_qqmlproperty::initTestCase() qmlRegisterType<MyContainer>("Test",1,0,"MyContainer"); qmlRegisterType<MyReplaceIfNotDefaultBehaviorContainer>("Test",1,0,"MyReplaceIfNotDefaultBehaviorContainer"); qmlRegisterType<MyAlwaysReplaceBehaviorContainer>("Test",1,0,"MyAlwaysReplaceBehaviorContainer"); + qmlRegisterType<ListHolder>("Test", 1, 0, "ListHolder"); } // QTBUG-60908 @@ -2513,6 +2544,18 @@ void tst_qqmlproperty::bindToNonQObjectTarget() QVERIFY(!o.isNull()); } +void tst_qqmlproperty::assignVariantList() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("assignVariantList.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> o(component.create()); + QVERIFY(!o.isNull()); + ListHolder *holder = qobject_cast<ListHolder *>(o.data()); + const QList<double> doubleList = {1.1, 2.2, 3.3, 11, 5.25, 11}; + QCOMPARE(holder->doubleList(), doubleList); +} + QTEST_MAIN(tst_qqmlproperty) #include "tst_qqmlproperty.moc" diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp index aac9c5229f..3c3e0ba1e9 100644 --- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp +++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp @@ -90,7 +90,7 @@ void tst_QQmlPropertyMap::insert() QQmlPropertyMap map; map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); @@ -103,33 +103,33 @@ void tst_QQmlPropertyMap::insert() //QQmlPropertyMap has an invokable keys() method QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("keys"), 1); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(!map.contains(QLatin1String("keys"))); QVERIFY(map.value(QLatin1String("keys")).isNull()); //QQmlPropertyMap has a deleteLater() slot QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("deleteLater"), 1); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(!map.contains(QLatin1String("deleteLater"))); QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); //QQmlPropertyMap has an valueChanged() signal QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols."); map.insert(QLatin1String("valueChanged"), 1); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(!map.contains(QLatin1String("valueChanged"))); QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); //but 'valueChange' should be ok map.insert(QLatin1String("valueChange"), 1); - QCOMPARE(map.keys().count(), 3); + QCOMPARE(map.keys().size(), 3); QVERIFY(map.contains(QLatin1String("valueChange"))); QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1)); //'valueCHANGED' should be ok, too map.insert(QLatin1String("valueCHANGED"), 1); - QCOMPARE(map.keys().count(), 4); + QCOMPARE(map.keys().size(), 4); QVERIFY(map.contains(QLatin1String("valueCHANGED"))); QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1)); } @@ -144,7 +144,7 @@ void tst_QQmlPropertyMap::insertMany() QQmlPropertyMap map; map.insert(values); - QCOMPARE(map.keys().count(), 4); + QCOMPARE(map.keys().size(), 4); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); @@ -162,7 +162,7 @@ void tst_QQmlPropertyMap::insertMany() //QQmlPropertyMap has an invokable keys() method QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols."); map.insert(values); - QCOMPARE(map.keys().count(), 4); + QCOMPARE(map.keys().size(), 4); QVERIFY(!map.contains(QLatin1String("keys"))); QVERIFY(map.value(QLatin1String("keys")).isNull()); @@ -171,7 +171,7 @@ void tst_QQmlPropertyMap::insertMany() //QQmlPropertyMap has a deleteLater() slot QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols."); map.insert(values); - QCOMPARE(map.keys().count(), 4); + QCOMPARE(map.keys().size(), 4); QVERIFY(!map.contains(QLatin1String("deleteLater"))); QVERIFY(map.value(QLatin1String("deleteLater")).isNull()); @@ -180,13 +180,13 @@ void tst_QQmlPropertyMap::insertMany() //QQmlPropertyMap has an valueChanged() signal QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols."); map.insert(values); - QCOMPARE(map.keys().count(), 4); + QCOMPARE(map.keys().size(), 4); QVERIFY(!map.contains(QLatin1String("valueChanged"))); QVERIFY(map.value(QLatin1String("valueChanged")).isNull()); values.remove(QStringLiteral("valueChanged")); map.insert(values); // Adds "foobar" and changes "key1" - QCOMPARE(map.keys().count(), 5); + QCOMPARE(map.keys().size(), 5); QCOMPARE(map.value(QStringLiteral("foobar")).toInt(), 12); QCOMPARE(map.value(QStringLiteral("key1")).toInt(), 100); } @@ -196,7 +196,7 @@ void tst_QQmlPropertyMap::operatorInsert() QQmlPropertyMap map; map[QLatin1String("key1")] = 100; map[QLatin1String("key2")] = 200; - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); @@ -225,12 +225,12 @@ void tst_QQmlPropertyMap::clear() { QQmlPropertyMap map; map.insert(QLatin1String("key1"),100); - QCOMPARE(map.keys().count(), 1); + QCOMPARE(map.keys().size(), 1); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); map.clear(QLatin1String("key1")); - QCOMPARE(map.keys().count(), 1); + QCOMPARE(map.keys().size(), 1); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant()); } @@ -241,10 +241,10 @@ void tst_QQmlPropertyMap::changed() QSignalSpy spy(&map, SIGNAL(valueChanged(QString,QVariant))); map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); map.clear(QLatin1String("key1")); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); //make changes in QML QQmlEngine engine; @@ -257,9 +257,9 @@ void tst_QQmlPropertyMap::changed() QScopedPointer<QQuickText> txt(qobject_cast<QQuickText*>(component.create())); QVERIFY(txt); QCOMPARE(txt->text(), QString('X')); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> arguments = spy.takeFirst(); - QCOMPARE(arguments.count(), 2); + QCOMPARE(arguments.size(), 2); QCOMPARE(arguments.at(0).toString(),QLatin1String("key1")); QCOMPARE(arguments.at(1).value<QVariant>(),QVariant("Hello World")); QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World")); @@ -485,7 +485,7 @@ void tst_QQmlPropertyMap::disallowExtending() "}\n", QUrl()); obj.reset(component.create()); QVERIFY(obj.isNull()); - QCOMPARE(component.errors().count(), 1); + QCOMPARE(component.errors().size(), 1); QCOMPARE(component.errors().at(0).toString(), QStringLiteral("<Unknown File>:3:1: Fully dynamic types cannot declare new properties.")); } @@ -524,24 +524,24 @@ void tst_QQmlPropertyMap::QTBUG_48136() QSignalSpy notifySpy(&map, QByteArray::number(QSIGNAL_CODE) + prop.notifySignal().methodSignature()); map.insert(key, 42); - QCOMPARE(notifySpy.count(), 1); + QCOMPARE(notifySpy.size(), 1); map.insert(key, 43); - QCOMPARE(notifySpy.count(), 2); + QCOMPARE(notifySpy.size(), 2); map.insert(key, 43); - QCOMPARE(notifySpy.count(), 2); + QCOMPARE(notifySpy.size(), 2); map.insert(key, 44); - QCOMPARE(notifySpy.count(), 3); + QCOMPARE(notifySpy.size(), 3); // // Test that the valueChanged signal is emitted correctly // QSignalSpy valueChangedSpy(&map, &QQmlPropertyMap::valueChanged); map.setProperty(key, 44); - QCOMPARE(valueChangedSpy.count(), 0); + QCOMPARE(valueChangedSpy.size(), 0); map.setProperty(key, 45); - QCOMPARE(valueChangedSpy.count(), 1); + QCOMPARE(valueChangedSpy.size(), 1); map.setProperty(key, 45); - QCOMPARE(valueChangedSpy.count(), 1); + QCOMPARE(valueChangedSpy.size(), 1); } void tst_QQmlPropertyMap::lookupsInSubTypes() @@ -560,14 +560,14 @@ void tst_QQmlPropertyMap::freeze() map.insert(QLatin1String("key1"),100); map.insert(QLatin1String("key2"),200); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(map.contains(QLatin1String("key1"))); QCOMPARE(map.value(QLatin1String("key1")), QVariant(100)); QCOMPARE(map.value(QLatin1String("key2")), QVariant(200)); map.freeze(); map.insert(QLatin1String("key3"), 32); - QCOMPARE(map.keys().count(), 2); + QCOMPARE(map.keys().size(), 2); QVERIFY(!map.contains("key3")); map.insert(QLatin1String("key1"), QStringLiteral("Hello World")); @@ -652,7 +652,7 @@ void tst_QQmlPropertyMap::signalIndices() QSignalSpy spy(&map, method); map.insert(QLatin1String("key1"), 200); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } QTEST_MAIN(tst_QQmlPropertyMap) diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp index 595adf5f67..220f449dfc 100644 --- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp +++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp @@ -733,7 +733,7 @@ void tst_qqmlqt::createQmlObject() QQuickItem *item = qobject_cast<QQuickItem *>(object.data()); QVERIFY(item != nullptr); - QCOMPARE(item->childItems().count(), 1); + QCOMPARE(item->childItems().size(), 1); } @@ -825,7 +825,7 @@ void tst_qqmlqt::dateTimeFormatting() QVERIFY2(component.errorString().isEmpty(), qPrintable(component.errorString())); QVERIFY(object != nullptr); - QVERIFY(inputProperties.count() > 0); + QVERIFY(inputProperties.size() > 0); QVariant result; foreach(const QString &prop, inputProperties) { QVERIFY(QMetaObject::invokeMethod(object.data(), method.toUtf8().constData(), @@ -833,7 +833,7 @@ void tst_qqmlqt::dateTimeFormatting() Q_ARG(QVariant, prop))); QStringList output = result.toStringList(); QCOMPARE(output.size(), expectedResults.size()); - for (int i=0; i<output.count(); i++) + for (int i=0; i<output.size(); i++) QCOMPARE(output[i], expectedResults[i]); } } @@ -885,7 +885,7 @@ void tst_qqmlqt::dateTimeFormattingVariants() << component.url().toString() + ":40: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed." << component.url().toString() + ":43: TypeError: Passing incompatible arguments to C++ functions from JavaScript is not allowed."; - for (const QString &warning : qAsConst(warnings)) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, qPrintable(warning)); warnings.clear(); @@ -899,7 +899,7 @@ void tst_qqmlqt::dateTimeFormattingVariants() << "Could not convert argument 1 at" << "expression for err_dateTime2@"; - for (const QString &warning : qAsConst(warnings)) + for (const QString &warning : std::as_const(warnings)) QTest::ignoreMessage(QtWarningMsg, QRegularExpression(warning)); warnings.clear(); @@ -1136,7 +1136,7 @@ void tst_qqmlqt::quit() QSignalSpy spy(&engine, SIGNAL(quit())); QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_qqmlqt::exit() @@ -1146,7 +1146,7 @@ void tst_qqmlqt::exit() QSignalSpy spy(&engine, &QQmlEngine::exit); QScopedPointer<QObject> object(component.create()); QVERIFY(object != nullptr); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QList<QVariant> arguments = spy.takeFirst(); QVERIFY(arguments.at(0).toInt() == object->property("returnCode").toInt()); } diff --git a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp index 296b5ef0ff..67c44684a4 100644 --- a/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp +++ b/tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp @@ -52,7 +52,7 @@ void removeRecursive(const QString& dirname) { QDir dir(dirname); QFileInfoList entries(dir.entryInfoList(QDir::Dirs|QDir::Files|QDir::NoDotAndDotDot)); - for (int i = 0; i < entries.count(); ++i) + for (int i = 0; i < entries.size(); ++i) if (entries[i].isDir()) removeRecursive(entries[i].filePath()); else @@ -174,7 +174,7 @@ void tst_qqmlsqldatabase::totalDatabases() if (engine->offlineStoragePath().isEmpty()) QSKIP("offlineStoragePath is empty, skip this test."); - QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), total_databases_created_by_tests*2); + QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).size(), total_databases_created_by_tests*2); } void tst_qqmlsqldatabase::upgradeDatabase() diff --git a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp index a8be2d0f99..a01a72c167 100644 --- a/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp +++ b/tests/auto/qml/qqmltablemodel/tst_qqmltablemodel.cpp @@ -69,8 +69,8 @@ void tst_QQmlTableModel::appendRemoveRow() QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, -1))); QCOMPARE(model->rowCount(), 2); QCOMPARE(model->columnCount(), 2); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call remove() with an rowIndex that is too large. QTest::ignoreMessage(QtWarningMsg, QRegularExpression( @@ -78,16 +78,16 @@ void tst_QQmlTableModel::appendRemoveRow() QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, 2))); QCOMPARE(model->rowCount(), 2); QCOMPARE(model->columnCount(), 2); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call remove() with a valid rowIndex but negative rows. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*removeRow\\(\\): \"rows\" is less than or equal to zero")); QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, 0), Q_ARG(int, -1))); QCOMPARE(model->rowCount(), 2); QCOMPARE(model->columnCount(), 2); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call remove() with a valid rowIndex but excessive rows. QTest::ignoreMessage(QtWarningMsg, QRegularExpression( @@ -95,8 +95,8 @@ void tst_QQmlTableModel::appendRemoveRow() QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, 0), Q_ARG(int, 3))); QCOMPARE(model->rowCount(), 2); QCOMPARE(model->columnCount(), 2); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call remove() without specifying the number of rows to remove; it should remove one row. QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, 0))); @@ -104,8 +104,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->columnCount(), 2); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); // Call append() with a row that has an unexpected role; the row should be added and the extra data ignored. QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendRowExtraData")); @@ -116,8 +116,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Foo")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); // Call append() with a row that is an int. QTest::ignoreMessage(QtWarningMsg, QRegularExpression( @@ -130,8 +130,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Foo")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call append() with a row with a role of the wrong type. QTest::ignoreMessage(QtWarningMsg, QRegularExpression( @@ -144,8 +144,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Foo")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call append() with a row that is an array instead of a simple object. QTest::ignoreMessage(QtWarningMsg, QRegularExpression( @@ -156,8 +156,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->columnCount(), 2); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Call append() to insert one row. QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "appendRow", Q_ARG(QVariant, QLatin1String("Max")), Q_ARG(QVariant, 40))); @@ -169,8 +169,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Max")); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 40); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); // Call remove() and specify rowIndex and rows, removing all remaining rows. QVERIFY(QMetaObject::invokeMethod(model, "removeRow", Q_ARG(int, 0), Q_ARG(int, 3))); @@ -178,8 +178,8 @@ void tst_QQmlTableModel::appendRemoveRow() QCOMPARE(model->columnCount(), 2); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")), QVariant()); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")), QVariant()); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); } void tst_QQmlTableModel::appendRowToEmptyModel() @@ -211,8 +211,8 @@ void tst_QQmlTableModel::appendRowToEmptyModel() const QHash<int, QByteArray> roleNames = model->roleNames(); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("John")); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QTRY_COMPARE(tableView->rows(), 1); QCOMPARE(tableView->columns(), 2); } @@ -249,8 +249,8 @@ void tst_QQmlTableModel::clear() QCOMPARE(model->columnCount(), 2); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")), QVariant()); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")), QVariant()); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); // Wait until updatePolish() gets called, which is where the size is recalculated. QTRY_COMPARE(tableView->rows(), 0); QCOMPARE(tableView->columns(), 2); @@ -323,8 +323,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -339,8 +339,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -354,8 +354,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -369,8 +369,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -384,8 +384,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -399,8 +399,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); QTRY_COMPARE(tableView->rows(), 3); QCOMPARE(tableView->columns(), 2); @@ -417,8 +417,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); QCOMPARE(model->data(model->index(3, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Max")); QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleNames.key("display")).toInt(), 40); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); QTRY_COMPARE(tableView->rows(), 4); QCOMPARE(tableView->columns(), 2); @@ -437,8 +437,8 @@ void tst_QQmlTableModel::insertRow() QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Max")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 40); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); QTRY_COMPARE(tableView->rows(), 5); QCOMPARE(tableView->columns(), 2); } @@ -481,8 +481,8 @@ void tst_QQmlTableModel::moveRow() QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); rowCountSignalEmissions = 3; - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Try to move with a fromRowIndex that is negative. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*moveRow\\(\\): \"fromRowIndex\" cannot be negative")); @@ -490,16 +490,16 @@ void tst_QQmlTableModel::moveRow() // Shouldn't have changed. QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Try to move with a fromRowIndex that is too large. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*moveRow\\(\\): \"fromRowIndex\" 5 is greater than or equal to rowCount\\(\\)")); QVERIFY(QMetaObject::invokeMethod(model, "moveRow", Q_ARG(int, 5), Q_ARG(int, 1))); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Try to move with a toRowIndex that is negative. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*moveRow\\(\\): \"toRowIndex\" cannot be negative")); @@ -507,16 +507,16 @@ void tst_QQmlTableModel::moveRow() // Shouldn't have changed. QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Try to move with a toRowIndex that is too large. QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*moveRow\\(\\): \"toRowIndex\" 5 is greater than or equal to rowCount\\(\\)")); QVERIFY(QMetaObject::invokeMethod(model, "moveRow", Q_ARG(int, 0), Q_ARG(int, 5))); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Move the first row to the end. QVERIFY(QMetaObject::invokeMethod(model, "moveRow", Q_ARG(int, 0), Q_ARG(int, 4))); @@ -533,8 +533,8 @@ void tst_QQmlTableModel::moveRow() QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("John")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Move it back again. QVERIFY(QMetaObject::invokeMethod(model, "moveRow", Q_ARG(int, 4), Q_ARG(int, 0))); @@ -550,8 +550,8 @@ void tst_QQmlTableModel::moveRow() QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleNames.key("display")).toInt(), 30); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); // Move the first row down one by one row. QVERIFY(QMetaObject::invokeMethod(model, "moveRow", Q_ARG(int, 0), Q_ARG(int, 1))); @@ -567,8 +567,8 @@ void tst_QQmlTableModel::moveRow() QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleNames.key("display")).toInt(), 30); QCOMPARE(model->data(model->index(4, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Trev")); QCOMPARE(model->data(model->index(4, 1, QModelIndex()), roleNames.key("display")).toInt(), 48); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); } void tst_QQmlTableModel::setRow() @@ -607,8 +607,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -623,8 +623,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -636,8 +636,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -651,8 +651,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -666,8 +666,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -681,8 +681,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -695,8 +695,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 40); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -709,8 +709,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 40); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Daisy")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 30); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), rowCountSignalEmissions); QCOMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); @@ -725,8 +725,8 @@ void tst_QQmlTableModel::setRow() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 30); QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Wot")); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 99); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), ++rowCountSignalEmissions); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), ++rowCountSignalEmissions); QTRY_COMPARE(tableView->rows(), 3); QCOMPARE(tableView->columns(), 2); } @@ -756,16 +756,16 @@ void tst_QQmlTableModel::setDataThroughDelegate() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 0); QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "modify")); QCOMPARE(model->data(model->index(0, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("John")); QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 0); // Test setting a role that doesn't exist for a certain column. QVERIFY(QMetaObject::invokeMethod(view.rootObject(), "modifyInvalidRole")); @@ -774,8 +774,8 @@ void tst_QQmlTableModel::setDataThroughDelegate() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 0); // Test setting a role with a value of the wrong type. // There are two rows, so two delegates respond to the signal, which means we need to ignore two warnings. @@ -789,8 +789,8 @@ void tst_QQmlTableModel::setDataThroughDelegate() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 18); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 0); } // Start off with empty rows and then set them to test rowCountChanged(). @@ -825,8 +825,8 @@ void tst_QQmlTableModel::setRowsImperatively() QCOMPARE(model->data(model->index(0, 1, QModelIndex()), roleNames.key("display")).toInt(), 22); QCOMPARE(model->data(model->index(1, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Oliver")); QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 33); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QTRY_COMPARE(tableView->rows(), 2); QCOMPARE(tableView->columns(), 2); } @@ -865,8 +865,8 @@ void tst_QQmlTableModel::setRowsMultipleTimes() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 41); QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Power")); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 89); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QTRY_COMPARE(tableView->rows(), 3); QCOMPARE(tableView->columns(), 2); @@ -882,8 +882,8 @@ void tst_QQmlTableModel::setRowsMultipleTimes() QCOMPARE(model->data(model->index(1, 1, QModelIndex()), roleNames.key("display")).toInt(), 41); QCOMPARE(model->data(model->index(2, 0, QModelIndex()), roleNames.key("display")).toString(), QLatin1String("Power")); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleNames.key("display")).toInt(), 89); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QCOMPARE(tableView->rows(), 3); QCOMPARE(tableView->columns(), 2); } @@ -986,8 +986,8 @@ void tst_QQmlTableModel::appendRowWithDouble() QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toDouble(), 3.5); QCOMPARE(model->data(model->index(2, 1, QModelIndex()), roleKey).toString(), QLatin1String("3.5")); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QTRY_COMPARE(tableView->rows(), 3); QCOMPARE(tableView->columns(), 2); @@ -1001,8 +1001,8 @@ void tst_QQmlTableModel::appendRowWithDouble() QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toDouble(), 5); QCOMPARE(model->data(model->index(3, 1, QModelIndex()), roleKey).toString(), QLatin1String("5")); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 1); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 1); QTRY_COMPARE(tableView->rows(), 4); QCOMPARE(tableView->columns(), 2); @@ -1015,8 +1015,8 @@ void tst_QQmlTableModel::appendRowWithDouble() // Nothing should change QCOMPARE(model->rowCount(), 4); QCOMPARE(model->columnCount(), 2); - QCOMPARE(columnCountSpy.count(), 0); - QCOMPARE(rowCountSpy.count(), 0); + QCOMPARE(columnCountSpy.size(), 0); + QCOMPARE(rowCountSpy.size(), 0); QCOMPARE(tableView->rows(), 4); QCOMPARE(tableView->columns(), 2); } diff --git a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp index f572016142..736907d5f0 100644 --- a/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp +++ b/tests/auto/qml/qqmltimer/tst_qqmltimer.cpp @@ -142,13 +142,13 @@ void tst_qqmltimer::repeat() timer->setRepeating(false); QVERIFY(!timer->isRepeating()); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setRepeating(false); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setRepeating(true); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete timer; } @@ -176,13 +176,13 @@ void tst_qqmltimer::triggeredOnStart() timer->setTriggeredOnStart(false); QVERIFY(!timer->triggeredOnStart()); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setTriggeredOnStart(false); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setTriggeredOnStart(true); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete timer; } @@ -254,13 +254,13 @@ void tst_qqmltimer::changeDuration() timer->setInterval(200); QCOMPARE(timer->interval(), 200); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setInterval(200); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); timer->setInterval(300); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete timer; } diff --git a/tests/auto/qml/qqmltranslation/CMakeLists.txt b/tests/auto/qml/qqmltranslation/CMakeLists.txt index 396eed518e..67047ff604 100644 --- a/tests/auto/qml/qqmltranslation/CMakeLists.txt +++ b/tests/auto/qml/qqmltranslation/CMakeLists.txt @@ -18,6 +18,7 @@ qt_internal_add_test(tst_qqmltranslation Qt::Gui Qt::GuiPrivate Qt::QmlPrivate + Qt::QmlModelsPrivate Qt::Quick Qt::QuickTestUtilsPrivate TESTDATA ${test_data} diff --git a/tests/auto/qml/qqmltranslation/data/translatedElements.qml b/tests/auto/qml/qqmltranslation/data/translatedElements.qml new file mode 100644 index 0000000000..c2edfe8c78 --- /dev/null +++ b/tests/auto/qml/qqmltranslation/data/translatedElements.qml @@ -0,0 +1,15 @@ +import QtQml +import QtQml.Models + +DelegateModel { + model: ListModel { + ListElement { dish: qsTr("soup"); price: 60 } + ListElement { dish: qsTr("fish"); price: 100 } + ListElement { dish: qsTr("meat"); price: 230 } + ListElement { dish: qsTr("bread"); price: 10 } + } + + delegate: QtObject { + required property string dish + } +} diff --git a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp index 20d81b352d..e6719e7303 100644 --- a/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp +++ b/tests/auto/qml/qqmltranslation/tst_qqmltranslation.cpp @@ -9,6 +9,7 @@ #include <QQuickItem> #include <private/qqmlengine_p.h> #include <private/qqmltypedata_p.h> +#include <private/qqmldelegatemodel_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> class tst_qqmltranslation : public QQmlDataTest @@ -23,6 +24,7 @@ private slots: void idTranslation(); void translationChange(); void preferJSContext(); + void listModel(); }; void tst_qqmltranslation::translation_data() @@ -170,6 +172,14 @@ class DummyTranslator : public QTranslator return QString::fromUtf8("Deutsch in mylibrary"); if (!qstrcmp(sourceText, "English in translation") && !qstrcmp(context, "nested_js_translation")) return QString::fromUtf8("Deutsch in Setzung"); + if (!qstrcmp(sourceText, "soup")) + return QString::fromUtf8("Suppe"); + if (!qstrcmp(sourceText, "fish")) + return QString::fromUtf8("Fisch"); + if (!qstrcmp(sourceText, "meat")) + return QString::fromUtf8("Fleisch"); + if (!qstrcmp(sourceText, "bread")) + return QString::fromUtf8("Brot"); return QString(); } @@ -231,6 +241,35 @@ void tst_qqmltranslation::preferJSContext() QCoreApplication::removeTranslator(&translator); } +void tst_qqmltranslation::listModel() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("translatedElements.qml")); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + QScopedPointer<QObject> o(component.create()); + QVERIFY(o); + + QQmlDelegateModel *model = qobject_cast<QQmlDelegateModel *>(o.data()); + QVERIFY(model); + + QCOMPARE(model->count(), 4); + + QCOMPARE(model->object(0)->property("dish").toString(), QStringLiteral("soup")); + QCOMPARE(model->object(1)->property("dish").toString(), QStringLiteral("fish")); + QCOMPARE(model->object(2)->property("dish").toString(), QStringLiteral("meat")); + QCOMPARE(model->object(3)->property("dish").toString(), QStringLiteral("bread")); + + DummyTranslator translator; + QCoreApplication::installTranslator(&translator); + engine.setUiLanguage(QStringLiteral("xxx")); + engine.retranslate(); + + QCOMPARE(model->object(0)->property("dish").toString(), QStringLiteral("Suppe")); + QCOMPARE(model->object(1)->property("dish").toString(), QStringLiteral("Fisch")); + QCOMPARE(model->object(2)->property("dish").toString(), QStringLiteral("Fleisch")); + QCOMPARE(model->object(3)->property("dish").toString(), QStringLiteral("Brot")); +} + QTEST_MAIN(tst_qqmltranslation) #include "tst_qqmltranslation.moc" diff --git a/tests/auto/qml/qqmltreemodeltotablemodel/testmodel.cpp b/tests/auto/qml/qqmltreemodeltotablemodel/testmodel.cpp index 8bf9561316..58587da79c 100644 --- a/tests/auto/qml/qqmltreemodeltotablemodel/testmodel.cpp +++ b/tests/auto/qml/qqmltreemodeltotablemodel/testmodel.cpp @@ -52,7 +52,7 @@ int TestModel::rowCount(const QModelIndex &parent) const if (!parent.isValid()) return 1; // root of the tree if (parent.column() == 0) - return treeItem(parent)->m_childItems.count(); + return treeItem(parent)->m_childItems.size(); return 0; } diff --git a/tests/auto/qml/qqmltreemodeltotablemodel/tst_qqmltreemodeltotablemodel.cpp b/tests/auto/qml/qqmltreemodeltotablemodel/tst_qqmltreemodeltotablemodel.cpp index 3efc369b57..cd9aed4b30 100644 --- a/tests/auto/qml/qqmltreemodeltotablemodel/tst_qqmltreemodeltotablemodel.cpp +++ b/tests/auto/qml/qqmltreemodeltotablemodel/tst_qqmltreemodeltotablemodel.cpp @@ -8,6 +8,10 @@ #include "testmodel.h" +/* + * Note: Out of practical reasons, QQmlTreeModelToTableModel is by and large + * tested from tst_qquicktreeview.cpp, where TreeView is available. + */ class tst_QQmlTreeModelToTableModel : public QObject { Q_OBJECT diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp index d28035b266..89e208f441 100644 --- a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -129,10 +129,10 @@ void tst_QQMLTypeLoader::trimCache() // The cache is free to keep the others. } - for (auto *data : qAsConst(releaseCompilationUnitLater)) + for (auto *data : std::as_const(releaseCompilationUnitLater)) data->release(); - for (auto *data : qAsConst(releaseLater)) + for (auto *data : std::as_const(releaseLater)) data->release(); } @@ -275,8 +275,8 @@ public: qint64 readData(char *data, qint64 maxlen) override { - if (m_buffer.length() < maxlen) - maxlen = m_buffer.length(); + if (m_buffer.size() < maxlen) + maxlen = m_buffer.size(); std::memcpy(data, m_buffer.data(), maxlen); m_buffer.remove(0, maxlen); return maxlen; @@ -351,9 +351,9 @@ public: segments.removeFirst(); } if (segments.startsWith("plugin")) { - if (segments.length() == 2) { + if (segments.size() == 2) { segments.append(path); - } else if (segments.length() == 3) { + } else if (segments.size() == 3) { if (!segments[2].startsWith('/')) segments[2] = path + segments[2]; } else { @@ -446,7 +446,7 @@ void tst_QQMLTypeLoader::intercept() QTRY_COMPARE(o->property("created").toInt(), 2); QTRY_COMPARE(o->property("loaded").toInt(), 2); - QVERIFY(factory.loadedFiles.length() >= 6); + QVERIFY(factory.loadedFiles.size() >= 6); QVERIFY(factory.loadedFiles.contains(dataDirectory() + "/test_intercept.qml")); QVERIFY(factory.loadedFiles.contains(dataDirectory() + "/Intercept.qml")); QVERIFY(factory.loadedFiles.contains(dataDirectory() + "/Fast/qmldir")); diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index f3f9d29b5c..8701fe5696 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1160,7 +1160,7 @@ static void checkNoErrors(QQmlComponent& component) QList<QQmlError> errors = component.errors(); if (errors.isEmpty()) return; - for (int ii = 0; ii < errors.count(); ++ii) { + for (int ii = 0; ii < errors.size(); ++ii) { const QQmlError &error = errors.at(ii); qWarning("%d:%d:%s",error.line(),error.column(),error.description().toUtf8().constData()); } @@ -1690,8 +1690,8 @@ void tst_qqmlvaluetypes::sequences() { QList<BaseGadget> gadgetList{1, 4, 7, 8, 15}; QJSValue value = engine.toScriptValue(gadgetList); - QCOMPARE(value.property("length").toInt(), gadgetList.length()); - for (int i = 0; i < gadgetList.length(); ++i) + QCOMPARE(value.property("length").toInt(), gadgetList.size()); + for (int i = 0; i < gadgetList.size(); ++i) QCOMPARE(value.property(i).property("baseProperty").toInt(), gadgetList.at(i).baseProperty()); } { @@ -1704,8 +1704,8 @@ void tst_qqmlvaluetypes::sequences() { QVector<QChar> qcharVector{QChar(1), QChar(4), QChar(42), QChar(8), QChar(15)}; QJSValue value = engine.toScriptValue(qcharVector); - QCOMPARE(value.property("length").toInt(), qcharVector.length()); - for (int i = 0; i < qcharVector.length(); ++i) + QCOMPARE(value.property("length").toInt(), qcharVector.size()); + for (int i = 0; i < qcharVector.size(); ++i) QCOMPARE(value.property(i).toString(), qcharVector.at(i)); } { @@ -1767,7 +1767,7 @@ void tst_qqmlvaluetypes::enumerableProperties() names.insert(name); } - QCOMPARE(names.count(), 2); + QCOMPARE(names.size(), 2); QVERIFY(names.contains(QStringLiteral("baseProperty"))); QVERIFY(names.contains(QStringLiteral("derivedProperty"))); } diff --git a/tests/auto/qml/qqmlxmllistmodel/tst_qqmlxmllistmodel.cpp b/tests/auto/qml/qqmlxmllistmodel/tst_qqmlxmllistmodel.cpp index ae4dcbef02..05b8ce605d 100644 --- a/tests/auto/qml/qqmlxmllistmodel/tst_qqmlxmllistmodel.cpp +++ b/tests/auto/qml/qqmlxmllistmodel/tst_qqmlxmllistmodel.cpp @@ -79,7 +79,7 @@ private: const QStringList fields = item.split(QLatin1Char(',')); for (const QString &field : fields) { QStringList values = field.split(QLatin1Char('=')); - if (values.count() != 2) { + if (values.size() != 2) { qWarning() << "makeItemXmlAndData: invalid field:" << field; continue; } @@ -235,7 +235,7 @@ void tst_QQmlXmlListModel::roles() QTRY_COMPARE(model->rowCount(), 9); QHash<int, QByteArray> roleNames = model->roleNames(); - QCOMPARE(roleNames.count(), 4); + QCOMPARE(roleNames.size(), 4); QVERIFY(roleNames.key("name", -1) >= 0); QVERIFY(roleNames.key("type", -1) >= 0); QVERIFY(roleNames.key("age", -1) >= 0); @@ -246,7 +246,7 @@ void tst_QQmlXmlListModel::roles() roles.insert(roleNames.key("type")); roles.insert(roleNames.key("age")); roles.insert(roleNames.key("size")); - QCOMPARE(roles.count(), 4); + QCOMPARE(roles.size(), 4); } void tst_QQmlXmlListModel::elementErrors() @@ -294,7 +294,7 @@ void tst_QQmlXmlListModel::uniqueRoleNames() QTRY_COMPARE(model->rowCount(), 9); QHash<int, QByteArray> roleNames = model->roleNames(); - QCOMPARE(roleNames.count(), 1); + QCOMPARE(roleNames.size(), 1); } void tst_QQmlXmlListModel::headers() @@ -313,7 +313,7 @@ void tst_QQmlXmlListModel::headers() QQmlXmlListModel::Ready); // It doesn't do a network request for a local file - QCOMPARE(factory.lastSentHeaders.count(), 0); + QCOMPARE(factory.lastSentHeaders.size(), 0); model->setProperty("source", QUrl("http://localhost/filethatdoesnotexist.xml")); QTRY_COMPARE_WITH_TIMEOUT(qvariant_cast<QQmlXmlListModel::Status>(model->property("status")), @@ -322,7 +322,7 @@ void tst_QQmlXmlListModel::headers() QVariantMap expectedHeaders; expectedHeaders["Accept"] = "application/xml,*/*"; - QCOMPARE(factory.lastSentHeaders.count(), expectedHeaders.count()); + QCOMPARE(factory.lastSentHeaders.size(), expectedHeaders.size()); for (auto it = expectedHeaders.cbegin(), end = expectedHeaders.cend(); it != end; ++it) { QVERIFY(factory.lastSentHeaders.contains(it.key())); QCOMPARE(factory.lastSentHeaders[it.key()].toString(), it.value().toString()); @@ -345,7 +345,7 @@ void tst_QQmlXmlListModel::source() QCOMPARE(model->property("progress").toDouble(), qreal(1.0)); QCOMPARE(qvariant_cast<QQmlXmlListModel::Status>(model->property("status")), QQmlXmlListModel::Loading); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); spy.clear(); QCOMPARE(qvariant_cast<QQmlXmlListModel::Status>(model->property("status")), QQmlXmlListModel::Ready); @@ -359,7 +359,7 @@ void tst_QQmlXmlListModel::source() QQmlXmlListModel::Null); qreal expectedProgress = (source.isLocalFile() || (source.scheme() == "qrc"_L1)) ? 1.0 : 0.0; QCOMPARE(model->property("progress").toDouble(), expectedProgress); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); spy.clear(); QCOMPARE(qvariant_cast<QQmlXmlListModel::Status>(model->property("status")), QQmlXmlListModel::Loading); @@ -373,10 +373,10 @@ void tst_QQmlXmlListModel::source() timer.start(20000); loop.exec(); - if (spy.count() == 0 && status != QQmlXmlListModel::Ready) { + if (spy.size() == 0 && status != QQmlXmlListModel::Ready) { qWarning("QQmlXmlListModel invalid source test timed out"); } else { - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); } @@ -415,7 +415,7 @@ void tst_QQmlXmlListModel::data() for (int i = 0; i < 9; i++) { QModelIndex index = model->index(i, 0); - for (int j = 0; j < model->roleNames().count(); j++) { + for (int j = 0; j < model->roleNames().size(); j++) { QCOMPARE(model->data(index, j), QVariant()); } } @@ -442,9 +442,9 @@ void tst_QQmlXmlListModel::reload() QCoreApplication::processEvents(); QMetaObject::invokeMethod(model.get(), "reload"); QMetaObject::invokeMethod(model.get(), "reload"); - QTRY_COMPARE(spyCount.count(), 0); - QTRY_COMPARE(spyInsert.count(), 1); - QTRY_COMPARE(spyRemove.count(), 1); + QTRY_COMPARE(spyCount.size(), 0); + QTRY_COMPARE(spyInsert.size(), 1); + QTRY_COMPARE(spyRemove.size(), 1); QCOMPARE(spyInsert[0][1].toInt(), 0); QCOMPARE(spyInsert[0][2].toInt(), 8); @@ -557,14 +557,14 @@ void tst_QQmlXmlListModel::propertyChanges() QCOMPARE(role->property("name").toString(), QString("size")); QCOMPARE(role->property("elementName").toString(), QString("size")); - QCOMPARE(nameSpy.count(), 1); - QCOMPARE(elementSpy.count(), 1); + QCOMPARE(nameSpy.size(), 1); + QCOMPARE(elementSpy.size(), 1); role->setProperty("name", "size"); role->setProperty("elementName", "size"); - QCOMPARE(nameSpy.count(), 1); - QCOMPARE(elementSpy.count(), 1); + QCOMPARE(nameSpy.size(), 1); + QCOMPARE(elementSpy.size(), 1); QSignalSpy sourceSpy(model.get(), SIGNAL(sourceChanged())); QSignalSpy modelQuerySpy(model.get(), SIGNAL(queryChanged())); @@ -577,14 +577,14 @@ void tst_QQmlXmlListModel::propertyChanges() QTRY_COMPARE(model->rowCount(), 1); - QCOMPARE(sourceSpy.count(), 1); - QCOMPARE(modelQuerySpy.count(), 1); + QCOMPARE(sourceSpy.size(), 1); + QCOMPARE(modelQuerySpy.size(), 1); model->setProperty("source", QUrl("model2.xml")); model->setProperty("query", "/Pets"); - QCOMPARE(sourceSpy.count(), 1); - QCOMPARE(modelQuerySpy.count(), 1); + QCOMPARE(sourceSpy.size(), 1); + QCOMPARE(modelQuerySpy.size(), 1); QTRY_COMPARE(model->rowCount(), 1); } diff --git a/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp index b98e1e9da3..7e9e070fa6 100644 --- a/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp +++ b/tests/auto/qml/qv4assembler/tst_qv4assembler.cpp @@ -76,7 +76,7 @@ void tst_QV4Assembler::perfMapFile() const QByteArray contents = file.readLine(); QVERIFY(contents.endsWith('\n')); QList<QByteArray> fields = contents.split(' '); - QCOMPARE(fields.length(), 3); + QCOMPARE(fields.size(), 3); bool ok = false; const qulonglong address = fields[0].toULongLong(&ok, 16); QVERIFY(ok); diff --git a/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp b/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp index d994783e1f..a3f5c4bb70 100644 --- a/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp +++ b/tests/auto/qml/qv4identifiertable/tst_qv4identifiertable.cpp @@ -341,7 +341,7 @@ void tst_qv4identifiertable::insertNumericStringPopulatesIdentifier() QV4::ExecutionEngine engine; const QString numeric = QStringLiteral("1"); uint subtype; - const uint hash = QV4::String::createHashValue(numeric.constData(), numeric.length(), &subtype); + const uint hash = QV4::String::createHashValue(numeric.constData(), numeric.size(), &subtype); QCOMPARE(subtype, QV4::Heap::String::StringType_ArrayIndex); QCOMPARE(engine.identifierTable->insertString(numeric)->identifier, QV4::PropertyKey::fromArrayIndex(hash)); diff --git a/tests/auto/qmldom/domdata/domitem/test1.qml b/tests/auto/qmldom/domdata/domitem/test1.qml index 36c1284978..4a28129ee9 100644 --- a/tests/auto/qmldom/domdata/domitem/test1.qml +++ b/tests/auto/qmldom/domdata/domitem/test1.qml @@ -1,4 +1,5 @@ -import QtQuick 2.15 +import QtQuick +import QtQuick as QQ Window { visible: true diff --git a/tests/auto/qmldom/domdata/reformatter/typeAnnotations.qml b/tests/auto/qmldom/domdata/reformatter/typeAnnotations.qml new file mode 100644 index 0000000000..63c4f5471c --- /dev/null +++ b/tests/auto/qmldom/domdata/reformatter/typeAnnotations.qml @@ -0,0 +1,12 @@ +import QtQuick + +Item { +function calculateWidth(object: Item<a>): list<Item> { +var w = object.width / 3 +// ... +// more javascript code +// ... +console.debug(w) +return w +} +} diff --git a/tests/auto/qmldom/domdata/reformatter/typeAnnotationsReformatted.qml b/tests/auto/qmldom/domdata/reformatter/typeAnnotationsReformatted.qml new file mode 100644 index 0000000000..3b304176fb --- /dev/null +++ b/tests/auto/qmldom/domdata/reformatter/typeAnnotationsReformatted.qml @@ -0,0 +1,12 @@ +import QtQuick + +Item { + function calculateWidth(object: Item<a>): list<Item> { + var w = object.width / 3; + // ... + // more javascript code + // ... + console.debug(w); + return w; + } +} diff --git a/tests/auto/qmldom/domitem/tst_qmldomitem.h b/tests/auto/qmldom/domitem/tst_qmldomitem.h index fab95c4e1e..433a92a2b2 100644 --- a/tests/auto/qmldom/domitem/tst_qmldomitem.h +++ b/tests/auto/qmldom/domitem/tst_qmldomitem.h @@ -292,7 +292,7 @@ private slots: QVERIFY(didAdd2); RefCacheEntry e2 = RefCacheEntry::forPath(env, refPath); QCOMPARE(e2.cached, RefCacheEntry::Cached::First); - QCOMPARE(e2.canonicalPaths.length(), 1); + QCOMPARE(e2.canonicalPaths.size(), 1); QCOMPARE(e2.canonicalPaths.first().toString(), env.canonicalPath().toString()); bool didAdd3 = RefCacheEntry::addForPath( env, refPath, @@ -302,7 +302,7 @@ private slots: QVERIFY(didAdd3); RefCacheEntry e3 = RefCacheEntry::forPath(env, refPath); QCOMPARE(e3.cached, RefCacheEntry::Cached::All); - QCOMPARE(e3.canonicalPaths.length(), 2); + QCOMPARE(e3.canonicalPaths.size(), 2); QCOMPARE(e3.canonicalPaths.first().toString(), env.canonicalPath().toString()); QCOMPARE(e3.canonicalPaths.last().toString(), tOwner.canonicalPath().toString()); } @@ -457,18 +457,18 @@ private slots: const PropertyInfo *p1 = reinterpret_cast<const PropertyInfo *>(wrappedPInfoPtr->m_value.data()); PropertyInfo p2 = wrappedPInfoPtr->m_value.value<PropertyInfo>(); - QCOMPARE(mPInfo.bindings.length(), 1); - QCOMPARE(mPInfo.propertyDefs.length(), 1); + QCOMPARE(mPInfo.bindings.size(), 1); + QCOMPARE(mPInfo.propertyDefs.size(), 1); QCOMPARE(mPInfo.bindings.first().toString(), mPInfo.bindings.first().toString()); QCOMPARE(mPInfo.propertyDefs.first().toString(), mPInfo.propertyDefs.first().toString()); - QCOMPARE(p2.bindings.length(), 1); - QCOMPARE(p2.propertyDefs.length(), 1); + QCOMPARE(p2.bindings.size(), 1); + QCOMPARE(p2.propertyDefs.size(), 1); QCOMPARE(p2.bindings.first().toString(), mPInfo.bindings.first().toString()); QCOMPARE(p2.propertyDefs.first().toString(), mPInfo.propertyDefs.first().toString()); - QCOMPARE(p1->bindings.length(), 1); - QCOMPARE(p1->propertyDefs.length(), 1); + QCOMPARE(p1->bindings.size(), 1); + QCOMPARE(p1->propertyDefs.size(), 1); QCOMPARE(p1->bindings.first().toString(), mPInfo.bindings.first().toString()); QCOMPARE(p1->propertyDefs.first().toString(), mPInfo.propertyDefs.first().toString()); } @@ -517,10 +517,15 @@ private slots: obj1.lookup(u"Rectangle"_s, LookupType::Type, LookupOption::Normal); QList<DomItem> rect2 = obj1.lookup(u"Rectangle"_s, LookupType::Symbol, LookupOption::Normal); - QVERIFY(rect.length() == 1); - QVERIFY(rect2.length() == 1); + QList<DomItem> rectAs = + obj1.lookup(u"QQ.Rectangle"_s, LookupType::Symbol, LookupOption::Normal); + + QVERIFY(rect.size() == 1); + QVERIFY(rect2.size() == 1); + QVERIFY(rectAs.size() == 1); QCOMPARE(rect.first().internalKind(), DomType::Export); QCOMPARE(rect.first(), rect2.first()); + QCOMPARE(rect.first(), rectAs.first()); DomItem rect3 = rect.first().proceedToScope(); QCOMPARE(rect3.internalKind(), DomType::QmlObject); QList<DomItem> rects; @@ -531,7 +536,7 @@ private slots: return true; }, {}); - QVERIFY(rects.length() == 1); + QVERIFY(rects.size() == 1); for (DomItem &el : rects) { QCOMPARE(rect.first(), el); } diff --git a/tests/auto/qmldom/path/tst_qmldompath.h b/tests/auto/qmldom/path/tst_qmldompath.h index 565bab713e..24d8c30bcf 100644 --- a/tests/auto/qmldom/path/tst_qmldompath.h +++ b/tests/auto/qmldom/path/tst_qmldompath.h @@ -28,9 +28,9 @@ public: QCOMPARE(p11, p2); QCOMPARE(p11, p3); QVERIFY(p11.m_data->strData.isEmpty()); - QCOMPARE(p2.m_data->strData.length(), 1); + QCOMPARE(p2.m_data->strData.size(), 1); QCOMPARE(p2.m_data->strData.first(), s); - QCOMPARE(p3.m_data->strData.length(), 1); + QCOMPARE(p3.m_data->strData.size(), 1); QCOMPARE(p3.m_data->strData.first(), s); } diff --git a/tests/auto/qmldom/reformatter/tst_reformatter.h b/tests/auto/qmldom/reformatter/tst_reformatter.h index 1fc18e0452..0b43d24763 100644 --- a/tests/auto/qmldom/reformatter/tst_reformatter.h +++ b/tests/auto/qmldom/reformatter/tst_reformatter.h @@ -57,6 +57,10 @@ private slots: QTest::newRow("template") << QStringLiteral(u"template.qml") << QStringLiteral(u"templateReformatted.qml") << defaultOptions; + QTest::newRow("typeAnnotations") + << QStringLiteral(u"typeAnnotations.qml") + << QStringLiteral(u"typeAnnotationsReformatted.qml") << defaultOptions; + QTest::newRow("arrowFunctions") << QStringLiteral(u"arrowFunctions.qml") << QStringLiteral(u"arrowFunctionsReformatted.qml") << defaultOptions; diff --git a/tests/auto/qmlls/completions/data/completions/Yyy.qml b/tests/auto/qmlls/completions/data/completions/Yyy.qml index b07fb9822e..dc1125c6ad 100644 --- a/tests/auto/qmlls/completions/data/completions/Yyy.qml +++ b/tests/auto/qmlls/completions/data/completions/Yyy.qml @@ -1,4 +1,5 @@ import QtQuick 2.0 +import QtQuick as QQ Zzz { id: root @@ -13,4 +14,8 @@ Zzz { function lala() {} property Rectangle foo: Rectangle{ height: 200 } + + QQ.Rectangle { + color:"red" + } } diff --git a/tests/auto/qmlls/completions/tst_qmllscompletions.cpp b/tests/auto/qmlls/completions/tst_qmllscompletions.cpp index e10b400887..03746589dc 100644 --- a/tests/auto/qmlls/completions/tst_qmllscompletions.cpp +++ b/tests/auto/qmlls/completions/tst_qmllscompletions.cpp @@ -128,7 +128,7 @@ void tst_QmllsCompletions::completions_data() QByteArray uri = testFileUrl("completions/Yyy.qml").toString().toUtf8(); - QTest::newRow("objEmptyLine") << uri << 7 << 0 + QTest::newRow("objEmptyLine") << uri << 8 << 0 << ExpectedCompletions({ { u"Rectangle"_s, CompletionItemKind::Class }, { u"property"_s, CompletionItemKind::Keyword }, @@ -137,7 +137,7 @@ void tst_QmllsCompletions::completions_data() }) << QStringList({ u"QtQuick"_s, u"vector4d"_s }); - QTest::newRow("inBindingLabel") << uri << 4 << 9 + QTest::newRow("inBindingLabel") << uri << 5 << 9 << ExpectedCompletions({ { u"Rectangle"_s, CompletionItemKind::Class }, { u"property"_s, CompletionItemKind::Keyword }, @@ -145,7 +145,7 @@ void tst_QmllsCompletions::completions_data() }) << QStringList({ u"QtQuick"_s, u"vector4d"_s }); - QTest::newRow("afterBinding") << uri << 4 << 10 + QTest::newRow("afterBinding") << uri << 5 << 10 << ExpectedCompletions({ { u"Rectangle"_s, CompletionItemKind::Field }, { u"width"_s, CompletionItemKind::Field }, @@ -154,7 +154,7 @@ void tst_QmllsCompletions::completions_data() << QStringList({ u"QtQuick"_s, u"property"_s }); // suppress? - QTest::newRow("afterId") << uri << 3 << 7 + QTest::newRow("afterId") << uri << 4 << 7 << ExpectedCompletions({ { u"import"_s, CompletionItemKind::Keyword }, }) @@ -197,7 +197,7 @@ void tst_QmllsCompletions::completions_data() // }) // << QStringList({ u"as"_s, u"Rectangle"_s, u"import"_s, u"vector4d"_s, u"width"_s }); - QTest::newRow("inScript") << uri << 5 << 14 + QTest::newRow("inScript") << uri << 6 << 14 << ExpectedCompletions({ { u"Rectangle"_s, CompletionItemKind::Field }, { u"vector4d"_s, CompletionItemKind::Field }, @@ -206,19 +206,26 @@ void tst_QmllsCompletions::completions_data() }) << QStringList({ u"import"_s }); - QTest::newRow("expandBase1") << uri << 8 << 23 + QTest::newRow("expandBase1") << uri << 9 << 23 << ExpectedCompletions({ { u"width"_s, CompletionItemKind::Field }, { u"foo"_s, CompletionItemKind::Field }, }) << QStringList({ u"import"_s, u"Rectangle"_s }); - QTest::newRow("expandBase2") << uri << 9 << 29 + QTest::newRow("expandBase2") << uri << 10 << 29 << ExpectedCompletions({ { u"width"_s, CompletionItemKind::Field }, { u"color"_s, CompletionItemKind::Field }, }) << QStringList({ u"foo"_s, u"import"_s, u"Rectangle"_s }); + + QTest::newRow("asCompletions") + << uri << 17 << 8 + << ExpectedCompletions({ + { u"Rectangle"_s, CompletionItemKind::Field }, + }) + << QStringList({ u"foo"_s, u"import"_s, u"lala()"_s, u"width"_s }); } void tst_QmllsCompletions::checkCompletions(QByteArray uri, int lineNr, int character, diff --git a/tests/auto/qmlls/lifecycle/qiopipe.cpp b/tests/auto/qmlls/lifecycle/qiopipe.cpp index a3ca36ae24..416fe8257d 100644 --- a/tests/auto/qmlls/lifecycle/qiopipe.cpp +++ b/tests/auto/qmlls/lifecycle/qiopipe.cpp @@ -87,7 +87,7 @@ bool QPipeEndPoint::isSequential() const qint64 QPipeEndPoint::bytesAvailable() const { - return m_buffer.length() + QIODevice::bytesAvailable(); + return m_buffer.size() + QIODevice::bytesAvailable(); } void QPipeEndPoint::setRemoteEndPoint(QPipeEndPoint *other) @@ -97,7 +97,7 @@ void QPipeEndPoint::setRemoteEndPoint(QPipeEndPoint *other) qint64 QPipeEndPoint::readData(char *data, qint64 maxlen) { - maxlen = qMin(maxlen, static_cast<qint64>(m_buffer.length())); + maxlen = qMin(maxlen, static_cast<qint64>(m_buffer.size())); if (maxlen <= 0) return 0; @@ -116,7 +116,7 @@ qint64 QPipeEndPoint::writeData(const char *data, qint64 len) return 0; QByteArray &buffer = m_remoteEndPoint->m_buffer; - const qint64 prevLen = buffer.length(); + const qint64 prevLen = buffer.size(); Q_ASSERT(prevLen >= 0); len = qMin(len, std::numeric_limits<int>::max() - prevLen); diff --git a/tests/auto/qmlls/qmlls/tst_qmlls.cpp b/tests/auto/qmlls/qmlls/tst_qmlls.cpp index 1cfa734018..2c7a76626d 100644 --- a/tests/auto/qmlls/qmlls/tst_qmlls.cpp +++ b/tests/auto/qmlls/qmlls/tst_qmlls.cpp @@ -43,7 +43,7 @@ public: int num = 0; for (const auto ¶ms : m_received) { if (params.uri == uri) - num += params.diagnostics.length(); + num += params.diagnostics.size(); } return num; } diff --git a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml index ec3387a38b..a54e5f1e7b 100644 --- a/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml +++ b/tests/auto/qmltest/selftests/tst_createTemporaryObject.qml @@ -25,6 +25,8 @@ TestCase { } function init() { + failOnWarning(/.?/) + // The items are destroyed after cleanup(), so we check here after every test, // and once for the last test in cleanupTestCase(). verifyNoChildren(); @@ -125,7 +127,8 @@ TestCase { { tag: "omit", expectedParent: null }, { tag: "undefined", parent: undefined, expectedParent: null }, { tag: "null", parent: null, expectedParent: null }, - { tag: "1", parent: 1, expectedParent: null }, + { tag: "1", parent: 1, expectedParent: null, + ignoreWarning: /.*Unsuitable arguments passed to createObject.*/ }, { tag: "testCase", parent: testCase, expectedParent: testCase } ]; } @@ -133,6 +136,10 @@ TestCase { // Tests that an invalid or missing parent argument results in a parentless object. // This is the same behavior as displayed by component.createObject(). function test_fromComponentParent(data) { + // ignoreWarning takes precedence over failOnWarning (which we call in init()). + if (data.hasOwnProperty("ignoreWarning")) + ignoreWarning(data.ignoreWarning) + var object = data.hasOwnProperty("parent") ? createTemporaryObject(itemComponent, data.parent) : createTemporaryObject(itemComponent); diff --git a/tests/auto/quick/examples/tst_examples.cpp b/tests/auto/quick/examples/tst_examples.cpp index c56cad7d90..3127784f6a 100644 --- a/tests/auto/quick/examples/tst_examples.cpp +++ b/tests/auto/quick/examples/tst_examples.cpp @@ -62,6 +62,7 @@ tst_examples::tst_examples() excludedDirs << "snippets/qml/imports"; excludedDirs << "examples/quickcontrols2/imagine"; excludedDirs << "examples/quickcontrols2/texteditor"; + excludedDirs << "examples/quickcontrols2/ios/todolist"; // Must be run via executable. excludedFiles << "snippets/qml/image-ext.qml"; excludedFiles << "examples/quick/shapes/content/main.qml"; // relies on resources excludedFiles << "examples/quick/shapes/content/interactive.qml"; // relies on resources @@ -102,7 +103,7 @@ to have them tested by the examples() test. */ void tst_examples::namingConvention(const QDir &d) { - for (int ii = 0; ii < excludedDirs.count(); ++ii) { + for (int ii = 0; ii < excludedDirs.size(); ++ii) { QString s = excludedDirs.at(ii); if (d.absolutePath().endsWith(s)) return; @@ -156,7 +157,7 @@ void tst_examples::namingConvention() QStringList tst_examples::findQmlFiles(const QDir &d) { - for (int ii = 0; ii < excludedDirs.count(); ++ii) { + for (int ii = 0; ii < excludedDirs.size(); ++ii) { QString s = excludedDirs.at(ii); if (d.absolutePath().endsWith(s)) return QStringList(); @@ -171,7 +172,7 @@ QStringList tst_examples::findQmlFiles(const QDir &d) foreach (const QString &file, files) { if (file.at(0).isLower()) { bool superContinue = false; - for (int ii = 0; ii < excludedFiles.count(); ++ii) { + for (int ii = 0; ii < excludedFiles.size(); ++ii) { QString e = excludedFiles.at(ii); if (d.absoluteFilePath(file).endsWith(e)) { superContinue = true; @@ -222,7 +223,7 @@ void tst_examples::sgexamples_data() QStringList files; files << findQmlFiles(examplesDir); - for (const QString &file : qAsConst(files)) + for (const QString &file : std::as_const(files)) QTest::newRow(qPrintable(repoSourceDir.relativeFilePath(file))) << file; } @@ -272,7 +273,7 @@ void tst_examples::sgsnippets_data() QStringList files; files << findQmlFiles(snippetsDir); - for (const QString &file : qAsConst(files)) + for (const QString &file : std::as_const(files)) QTest::newRow(qPrintable(repoSourceDir.relativeFilePath(file))) << file; // Add Quick snippets. @@ -282,7 +283,7 @@ void tst_examples::sgsnippets_data() files.clear(); files << findQmlFiles(snippetsDir); - for (const QString &file : qAsConst(files)) + for (const QString &file : std::as_const(files)) QTest::newRow(qPrintable(repoSourceDir.relativeFilePath(file))) << file; } diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/BLACKLIST b/tests/auto/quick/pointerhandlers/flickableinterop/BLACKLIST index 5c5f2c9ed9..4e54331470 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/BLACKLIST +++ b/tests/auto/quick/pointerhandlers/flickableinterop/BLACKLIST @@ -26,3 +26,6 @@ android android [touchAndDragHandlerOnFlickable] android +# QTBUG-113226 +[pinchHandlerOnFlickable] +* diff --git a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp index 84cfe0e7fd..7a0206c04f 100644 --- a/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp +++ b/tests/auto/quick/pointerhandlers/flickableinterop/tst_flickableinterop.cpp @@ -103,7 +103,7 @@ void tst_FlickableInterop::touchTapButton() QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); QTRY_VERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 1); + QCOMPARE(tappedSpy.size(), 1); // We can drag <= dragThreshold and the button still acts normal, Flickable doesn't grab p1 = button->mapToScene(QPointF(20, 20)).toPoint(); @@ -117,7 +117,7 @@ void tst_FlickableInterop::touchTapButton() QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); QTRY_VERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 2); + QCOMPARE(tappedSpy.size(), 2); } void tst_FlickableInterop::touchDragFlickableBehindButton_data() @@ -167,7 +167,7 @@ void tst_FlickableInterop::touchDragFlickableBehindButton() QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); QVERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 0); + QCOMPARE(tappedSpy.size(), 0); } void tst_FlickableInterop::mouseClickButton_data() @@ -197,7 +197,7 @@ void tst_FlickableInterop::mouseClickButton() QTRY_VERIFY(button->property("pressed").toBool()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); QTRY_VERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 1); + QCOMPARE(tappedSpy.size(), 1); // We can drag <= dragThreshold and the button still acts normal, Flickable doesn't grab p1 = button->mapToScene(QPointF(20, 20)).toPoint(); @@ -208,7 +208,7 @@ void tst_FlickableInterop::mouseClickButton() QVERIFY(button->property("pressed").toBool()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); QTRY_VERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 2); + QCOMPARE(tappedSpy.size(), 2); } void tst_FlickableInterop::mouseDragFlickableBehindButton_data() @@ -254,7 +254,7 @@ void tst_FlickableInterop::mouseDragFlickableBehindButton() QVERIFY(!button->property("pressed").toBool()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); QVERIFY(!button->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 0); + QCOMPARE(tappedSpy.size(), 0); } void tst_FlickableInterop::touchDragSlider() @@ -306,8 +306,8 @@ void tst_FlickableInterop::touchDragSlider() // Release, and do not expect the tapped signal QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); - QCOMPARE(tappedSpy.count(), 0); - QCOMPARE(translationChangedSpy.count(), 1); + QCOMPARE(tappedSpy.size(), 0); + QCOMPARE(translationChangedSpy.size(), 1); } void tst_FlickableInterop::mouseDragSlider_data() @@ -391,8 +391,8 @@ void tst_FlickableInterop::mouseDragSlider() // Release, and do not expect the tapped signal QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); - QCOMPARE(tappedSpy.count(), 0); - QCOMPARE(translationChangedSpy.count(), expectedDragHandlerActive ? 1 : 0); + QCOMPARE(tappedSpy.size(), 0); + QCOMPARE(translationChangedSpy.size(), expectedDragHandlerActive ? 1 : 0); } void tst_FlickableInterop::touchDragFlickableBehindSlider() @@ -437,8 +437,8 @@ void tst_FlickableInterop::touchDragFlickableBehindSlider() QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); QVERIFY(!slider->property("pressed").toBool()); - QCOMPARE(tappedSpy.count(), 0); - QCOMPARE(translationChangedSpy.count(), 0); + QCOMPARE(tappedSpy.size(), 0); + QCOMPARE(translationChangedSpy.size(), 0); } void tst_FlickableInterop::mouseDragFlickableBehindSlider() @@ -479,8 +479,8 @@ void tst_FlickableInterop::mouseDragFlickableBehindSlider() QCOMPARE(i, 2); QVERIFY(!slider->property("pressed").toBool()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); - QCOMPARE(tappedSpy.count(), 0); - QCOMPARE(translationChangedSpy.count(), 0); + QCOMPARE(tappedSpy.size(), 0); + QCOMPARE(translationChangedSpy.size(), 0); } void tst_FlickableInterop::touchDragFlickableBehindItemWithHandlers_data() diff --git a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp index c4059a1fbd..723ad0b63e 100644 --- a/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp +++ b/tests/auto/quick/pointerhandlers/mousearea_interop/tst_mousearea_interop.cpp @@ -178,11 +178,11 @@ void tst_MouseAreaInterop::hoverHandlerDoesntHoverOnPress() // QTBUG-72843 QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p); QTRY_COMPARE(ma->pressed(), true); QCOMPARE(handler->isHovered(), true); - QCOMPARE(hoveredChangedSpy.count(), 0); + QCOMPARE(hoveredChangedSpy.size(), 0); QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p); QTRY_COMPARE(ma->pressed(), false); QCOMPARE(handler->isHovered(), true); - QCOMPARE(hoveredChangedSpy.count(), 0); + QCOMPARE(hoveredChangedSpy.size(), 0); } void tst_MouseAreaInterop::doubleClickInMouseAreaWithDragHandlerInGrandparent() @@ -199,8 +199,8 @@ void tst_MouseAreaInterop::doubleClickInMouseAreaWithDragHandlerInGrandparent() QPoint p = ma->mapToScene(ma->boundingRect().center()).toPoint(); QTest::mouseDClick(&window, Qt::LeftButton, Qt::NoModifier, p); - QCOMPARE(dClickSpy.count(), 1); - QCOMPARE(dragActiveSpy.count(), 0); + QCOMPARE(dClickSpy.size(), 1); + QCOMPARE(dragActiveSpy.size(), 0); } QTEST_MAIN(tst_MouseAreaInterop) diff --git a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp index f2c6ce5ee6..0aa96b6c59 100644 --- a/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp +++ b/tests/auto/quick/pointerhandlers/multipointtoucharea_interop/tst_multipointtoucharea_interop.cpp @@ -145,7 +145,7 @@ void tst_MptaInterop::touchesThenPinch() QQuickTouchUtils::flush(window); QVERIFY(tp.at(0)->property("pressed").toBool()); QTRY_VERIFY(tp.at(1)->property("pressed").toBool()); - QCOMPARE(mptaPressedSpy.count(), 2); + QCOMPARE(mptaPressedSpy.size(), 2); // Press a third touchpoint: MPTA grabs it too QPoint p3 = mpta->mapToScene(QPointF(110, 200)).toPoint(); @@ -154,8 +154,8 @@ void tst_MptaInterop::touchesThenPinch() QCOMPARE(tp.at(0)->property("pressed").toBool(), true); QCOMPARE(tp.at(1)->property("pressed").toBool(), true); QCOMPARE(tp.at(2)->property("pressed").toBool(), true); - QCOMPARE(mptaPressedSpy.count(), 3); - QCOMPARE(mptaCanceledSpy.count(), 0); + QCOMPARE(mptaPressedSpy.size(), 3); + QCOMPARE(mptaCanceledSpy.size(), 0); QCOMPARE(devPriv->pointById(1)->exclusiveGrabber, mpta); QCOMPARE(devPriv->pointById(2)->exclusiveGrabber, mpta); QCOMPARE(devPriv->pointById(3)->exclusiveGrabber, mpta); @@ -254,7 +254,7 @@ void tst_MptaInterop::touchesThenPinch() touch.release(2, p2).commit(); QQuickTouchUtils::flush(window); - QTRY_COMPARE(mptaReleasedSpy.count(), 1); + QTRY_COMPARE(mptaReleasedSpy.size(), 1); } void tst_MptaInterop::unloadHandlerWithPassiveGrab() diff --git a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp index 1f8b73a919..b6e4cec3af 100644 --- a/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickdraghandler/tst_qquickdraghandler.cpp @@ -153,21 +153,21 @@ void tst_DragHandler::touchDrag() QCOMPARE(dragHandler->centroid().scenePosition(), scenePressPos); QCOMPARE(dragHandler->centroid().scenePressPosition(), scenePressPos); QCOMPARE(dragHandler->centroid().velocity(), QVector2D()); - QCOMPARE(centroidChangedSpy.count(), 1); + QCOMPARE(centroidChangedSpy.size(), 1); p1 += QPoint(dragThreshold, 0); QTest::touchEvent(window, touchDevice).move(1, p1, window); QQuickTouchUtils::flush(window); qCDebug(lcPointerTests) << "velocity after drag" << dragHandler->centroid().velocity(); if (dragThreshold > 0) QTRY_VERIFY(!qFuzzyIsNull(dragHandler->centroid().velocity().x())); - QCOMPARE(centroidChangedSpy.count(), 2); + QCOMPARE(centroidChangedSpy.size(), 2); QVERIFY(!dragHandler->active()); p1 += QPoint(1, 0); QTest::touchEvent(window, touchDevice).move(1, p1, window); QQuickTouchUtils::flush(window); QTRY_VERIFY(dragHandler->active()); - QCOMPARE(translationChangedSpy.count(), 0); - QCOMPARE(centroidChangedSpy.count(), 3); + QCOMPARE(translationChangedSpy.size(), 0); + QCOMPARE(centroidChangedSpy.size(), 3); QCOMPARE(dragHandler->persistentTranslation().x(), 0); QCOMPARE(dragHandler->activeTranslation().x(), 0); QPointF sceneGrabPos = p1; @@ -186,15 +186,15 @@ void tst_DragHandler::touchDrag() QCOMPARE(dragHandler->persistentTranslation().y(), 0); QCOMPARE(dragHandler->activeTranslation().y(), 0); QVERIFY(dragHandler->centroid().velocity().x() > 0); - QCOMPARE(centroidChangedSpy.count(), 4); + QCOMPARE(centroidChangedSpy.size(), 4); QTest::touchEvent(window, touchDevice).release(1, p1, window); QQuickTouchUtils::flush(window); QTRY_VERIFY(!dragHandler->active()); QCOMPARE(dragHandler->centroid().pressedButtons(), Qt::NoButton); QCOMPARE(dragHandler->centroid().velocity(), QVector2D()); QCOMPARE(ball->mapToScene(ballCenter).toPoint(), p1); - QCOMPARE(translationChangedSpy.count(), 1); - QCOMPARE(centroidChangedSpy.count(), 5); + QCOMPARE(translationChangedSpy.size(), 1); + QCOMPARE(centroidChangedSpy.size(), 5); QCOMPARE(dragHandler->persistentTranslation().x(), dragThreshold + 20); // Drag again: activeTranslation starts over, while persistentTranslation accumulates @@ -290,13 +290,13 @@ void tst_DragHandler::mouseDrag() QCOMPARE(dragHandler->centroid().scenePosition(), scenePressPos); QCOMPARE(dragHandler->centroid().scenePressPosition(), scenePressPos); QCOMPARE(dragHandler->centroid().velocity(), QVector2D()); - QCOMPARE(centroidChangedSpy.count(), 1); + QCOMPARE(centroidChangedSpy.size(), 1); } p1 += QPoint(dragThreshold, 0); QTest::mouseMove(window, p1); if (shouldDrag) { -// QTRY_VERIFY(dragHandler->centroid().velocity().x() > 0); // TODO QTBUG-33891 - QCOMPARE(centroidChangedSpy.count(), 2); + QVERIFY(dragHandler->centroid().velocity().x() > 0); + QCOMPARE(centroidChangedSpy.size(), 2); QVERIFY(!dragHandler->active()); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); @@ -308,9 +308,9 @@ void tst_DragHandler::mouseDrag() QTRY_VERIFY(dragHandler->active()); else QVERIFY(!dragHandler->active()); - QCOMPARE(translationChangedSpy.count(), 0); + QCOMPARE(translationChangedSpy.size(), 0); if (shouldDrag) - QCOMPARE(centroidChangedSpy.count(), 3); + QCOMPARE(centroidChangedSpy.size(), 3); QCOMPARE(dragHandler->persistentTranslation().x(), 0.0); QCOMPARE(dragHandler->activeTranslation().x(), 0.0); QPointF sceneGrabPos = p1; @@ -329,8 +329,8 @@ void tst_DragHandler::mouseDrag() QCOMPARE(dragHandler->activeTranslation().x(), dragThreshold + 20.0); QCOMPARE(dragHandler->persistentTranslation().y(), 0.0); QCOMPARE(dragHandler->activeTranslation().y(), 0.0); -// QVERIFY(dragHandler->centroid().velocity().x() > 0); // TODO QTBUG-33891 - QCOMPARE(centroidChangedSpy.count(), 4); + QVERIFY(dragHandler->centroid().velocity().x() > 0); + QCOMPARE(centroidChangedSpy.size(), 4); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ClosedHandCursor); #endif @@ -340,8 +340,8 @@ void tst_DragHandler::mouseDrag() QCOMPARE(dragHandler->centroid().pressedButtons(), Qt::NoButton); if (shouldDrag) QCOMPARE(ball->mapToScene(ballCenter).toPoint(), p1); - QCOMPARE(translationChangedSpy.count(), shouldDrag ? 1 : 0); - QCOMPARE(centroidChangedSpy.count(), shouldDrag ? 5 : 0); + QCOMPARE(translationChangedSpy.size(), shouldDrag ? 1 : 0); + QCOMPARE(centroidChangedSpy.size(), shouldDrag ? 5 : 0); #if QT_CONFIG(cursor) QTest::mouseMove(window, p1 + QPoint(1, 0)); // TODO after fixing QTBUG-53987, don't send mouseMove QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); @@ -388,19 +388,19 @@ void tst_DragHandler::mouseDragThreshold() QCOMPARE(dragHandler->centroid().scenePosition(), scenePressPos); QCOMPARE(dragHandler->centroid().scenePressPosition(), scenePressPos); QCOMPARE(dragHandler->centroid().velocity(), QVector2D()); - QCOMPARE(centroidChangedSpy.count(), 1); + QCOMPARE(centroidChangedSpy.size(), 1); p1 += QPoint(qMax(1, dragThreshold), 0); // QTBUG-85431: zero-distance mouse moves are not delivered QTest::mouseMove(window, p1); if (dragThreshold > 0) QTRY_VERIFY(dragHandler->centroid().velocity().x() > 0); - QCOMPARE(centroidChangedSpy.count(), 2); + QCOMPARE(centroidChangedSpy.size(), 2); // the handler is not yet active, unless the drag threshold was already exceeded QCOMPARE(dragHandler->active(), dragThreshold == 0); p1 += QPoint(1, 0); QTest::mouseMove(window, p1); QTRY_VERIFY(dragHandler->active()); - QCOMPARE(translationChangedSpy.count(), dragThreshold ? 0 : 1); - QCOMPARE(centroidChangedSpy.count(), 3); + QCOMPARE(translationChangedSpy.size(), dragThreshold ? 0 : 1); + QCOMPARE(centroidChangedSpy.size(), 3); QCOMPARE(dragHandler->translation().x(), dragThreshold ? 0 : 2); QPointF sceneGrabPos = dragThreshold ? p1 : p1 - QPoint(1, 0); QCOMPARE(dragHandler->centroid().sceneGrabPosition(), sceneGrabPos); @@ -415,13 +415,13 @@ void tst_DragHandler::mouseDragThreshold() QCOMPARE(dragHandler->translation().x(), dragThreshold + (dragThreshold ? 20 : 21)); QCOMPARE(dragHandler->translation().y(), 0.0); QVERIFY(dragHandler->centroid().velocity().x() > 0); - QCOMPARE(centroidChangedSpy.count(), 4); + QCOMPARE(centroidChangedSpy.size(), 4); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, p1); QTRY_VERIFY(!dragHandler->active()); QCOMPARE(dragHandler->centroid().pressedButtons(), Qt::NoButton); QCOMPARE(ball->mapToScene(ballCenter).toPoint(), p1); - QCOMPARE(translationChangedSpy.count(), dragThreshold ? 1 : 2); - QCOMPARE(centroidChangedSpy.count(), 5); + QCOMPARE(translationChangedSpy.size(), dragThreshold ? 1 : 2); + QCOMPARE(centroidChangedSpy.size(), 5); } void tst_DragHandler::dragFromMargin() // QTBUG-74966 @@ -574,13 +574,13 @@ void tst_DragHandler::touchDragMulti() touchSeq.stationary(1).press(2, p2, window).commit(); QQuickTouchUtils::flush(window); QVERIFY(!dragHandler1->active()); - QCOMPARE(centroidChangedSpy1.count(), 2); + QCOMPARE(centroidChangedSpy1.size(), 2); QCOMPARE(dragHandler1->centroid().position(), ball1Center); QCOMPARE(dragHandler1->centroid().pressPosition(), ball1Center); QCOMPARE(dragHandler1->centroid().scenePosition(), scenePressPos1); QCOMPARE(dragHandler1->centroid().scenePressPosition(), scenePressPos1); QVERIFY(!dragHandler2->active()); - QCOMPARE(centroidChangedSpy2.count(), 2); + QCOMPARE(centroidChangedSpy2.size(), 2); QCOMPARE(dragHandler2->centroid().position(), ball2Center); QCOMPARE(dragHandler2->centroid().pressPosition(), ball2Center); QCOMPARE(dragHandler2->centroid().scenePosition(), scenePressPos2); @@ -590,13 +590,13 @@ void tst_DragHandler::touchDragMulti() touchSeq.move(1, p1, window).move(2, p2, window).commit(); QQuickTouchUtils::flush(window); QVERIFY(!dragHandler1->active()); - QCOMPARE(centroidChangedSpy1.count(), 3); + QCOMPARE(centroidChangedSpy1.size(), 3); QCOMPARE(dragHandler1->centroid().position(), ball1Center + QPointF(dragThreshold, 0)); QCOMPARE(dragHandler1->centroid().pressPosition(), ball1Center); QCOMPARE(dragHandler1->centroid().scenePosition().toPoint(), p1); QCOMPARE(dragHandler1->centroid().scenePressPosition(), scenePressPos1); QVERIFY(!dragHandler2->active()); - QCOMPARE(centroidChangedSpy2.count(), 3); + QCOMPARE(centroidChangedSpy2.size(), 3); QCOMPARE(dragHandler2->centroid().position(), ball2Center + QPointF(0, dragThreshold)); QCOMPARE(dragHandler2->centroid().pressPosition(), ball2Center); QCOMPARE(dragHandler2->centroid().scenePosition().toPoint(), p2); @@ -607,7 +607,7 @@ void tst_DragHandler::touchDragMulti() QQuickTouchUtils::flush(window); QTRY_VERIFY(dragHandler1->active()); QVERIFY(dragHandler2->active()); - QCOMPARE(translationChangedSpy1.count(), 0); + QCOMPARE(translationChangedSpy1.size(), 0); QCOMPARE(dragHandler1->translation().x(), 0.0); QPointF sceneGrabPos1 = p1; QPointF sceneGrabPos2 = p2; @@ -616,7 +616,7 @@ void tst_DragHandler::touchDragMulti() p1 += QPoint(19, 0); p2 += QPoint(0, 19); QVERIFY(dragHandler2->active()); - QCOMPARE(translationChangedSpy2.count(), 0); + QCOMPARE(translationChangedSpy2.size(), 0); QCOMPARE(dragHandler2->translation().x(), 0.0); QCOMPARE(dragHandler2->centroid().sceneGrabPosition(), sceneGrabPos2); touchSeq.move(1, p1, window).move(2, p2, window).commit(); @@ -643,12 +643,12 @@ void tst_DragHandler::touchDragMulti() QVERIFY(dragHandler2->active()); QCOMPARE(dragHandler1->centroid().pressedButtons(), Qt::NoButton); QCOMPARE(ball1->mapToScene(ball1Center).toPoint(), p1); - QCOMPARE(translationChangedSpy1.count(), 1); + QCOMPARE(translationChangedSpy1.size(), 1); touchSeq.release(2, p2, window).commit(); QQuickTouchUtils::flush(window); QTRY_VERIFY(!dragHandler2->active()); QCOMPARE(ball2->mapToScene(ball2Center).toPoint(), p2); - QCOMPARE(translationChangedSpy2.count(), 1); + QCOMPARE(translationChangedSpy2.size(), 1); } void tst_DragHandler::touchDragMultiSliders_data() @@ -854,7 +854,7 @@ void tst_DragHandler::touchPinchAndMouseMove() for (int i = 0; i < 10; ++i) { p1 += delta; QTest::mouseMove(window, p1); - QCOMPARE(rectMovedSpy.count(), 0); + QCOMPARE(rectMovedSpy.size(), 0); } } diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/BLACKLIST b/tests/auto/quick/pointerhandlers/qquickhoverhandler/BLACKLIST index 51e1876a88..1c4499753a 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/BLACKLIST +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/BLACKLIST @@ -3,6 +3,3 @@ macos # Can't move cursor (QTBUG-76312) # QTBUG-103065 [movingItemWithHoverHandler] android - -[hoverHandlerAndUnderlyingHoverHandler] -macos ci # QTBUG-89933 diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverDeviceCursors.qml b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverDeviceCursors.qml new file mode 100644 index 0000000000..edb56ffdc6 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/hoverDeviceCursors.qml @@ -0,0 +1,49 @@ +import QtQuick + +Item { + width: 200; height: 200 + + HoverHandler { + objectName: "stylus" + acceptedDevices: PointerDevice.Stylus + acceptedPointerTypes: PointerDevice.Pen + cursorShape: Qt.CrossCursor + } + + HoverHandler { + objectName: "stylus eraser" + acceptedDevices: PointerDevice.Stylus + acceptedPointerTypes: PointerDevice.Eraser + cursorShape: Qt.PointingHandCursor + } + + HoverHandler { + objectName: "airbrush" + acceptedDevices: PointerDevice.Airbrush + acceptedPointerTypes: PointerDevice.Pen + cursorShape: Qt.BusyCursor + } + + HoverHandler { + objectName: "airbrush eraser" + acceptedDevices: PointerDevice.Airbrush + acceptedPointerTypes: PointerDevice.Eraser + cursorShape: Qt.OpenHandCursor + } + + HoverHandler { + objectName: "mouse" + acceptedDevices: PointerDevice.Mouse + // acceptedPointerTypes can be omitted because Mouse is not ambiguous. + // When a genuine mouse move is sent, there's a conflict, and this one should win. + cursorShape: Qt.IBeamCursor + } + + HoverHandler { + objectName: "conflictingMouse" + acceptedDevices: PointerDevice.Mouse + // acceptedPointerTypes can be omitted because Mouse is not ambiguous. + // When a genuine mouse move is sent, there's a conflict, and this one should lose. + cursorShape: Qt.ClosedHandCursor + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/nohandler.qml b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/nohandler.qml new file mode 100644 index 0000000000..ed3728e278 --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/data/nohandler.qml @@ -0,0 +1,15 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 + +Window { + width: 320 + height: 240 + visible: true + + Rectangle { + objectName: "childItem" + width: 100 + height: 100 + color: "lightblue" + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index fcd2c5c49b..e488c0486f 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -6,6 +6,7 @@ #include <QtQuick/qquickview.h> #include <QtQuick/qquickitem.h> #include <QtQuick/private/qquickhoverhandler_p.h> +#include <QtQuick/private/qquickpointerhandler_p_p.h> #include <QtQuick/private/qquickmousearea_p.h> #include <qpa/qwindowsysteminterface.h> @@ -38,9 +39,15 @@ private slots: void hoverHandlerAndUnderlyingHoverHandler(); void mouseAreaAndUnderlyingHoverHandler(); void hoverHandlerAndUnderlyingMouseArea(); + void disabledHoverHandlerAndUnderlyingMouseArea(); + void hoverHandlerOnDisabledItem(); void movingItemWithHoverHandler(); void margin(); void window(); + void deviceCursor_data(); + void deviceCursor(); + void addHandlerFromCpp(); + void ensureHoverHandlerWorksWhenItemHasHoverDisabled(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); @@ -94,45 +101,45 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingHoverHandler() QTest::mouseMove(window, outOfSidebar); QCOMPARE(topSidebarHH->isHovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 0); + QCOMPARE(sidebarHoveredSpy.size(), 0); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.size(), 1); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif QTest::mouseMove(window, buttonCenter); QCOMPARE(topSidebarHH->isHovered(), !blocking); - QCOMPARE(sidebarHoveredSpy.count(), blocking ? 2 : 1); + QCOMPARE(sidebarHoveredSpy.size(), blocking ? 2 : 1); QCOMPARE(buttonHH->isHovered(), true); - QCOMPARE(buttonHoveredSpy.count(), 1); + QCOMPARE(buttonHoveredSpy.size(), 1); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::PointingHandCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), blocking ? 3 : 1); + QCOMPARE(sidebarHoveredSpy.size(), blocking ? 3 : 1); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif QTest::mouseMove(window, outOfSidebar); QCOMPARE(topSidebarHH->isHovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), blocking ? 4 : 2); + QCOMPARE(sidebarHoveredSpy.size(), blocking ? 4 : 2); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif @@ -165,45 +172,45 @@ void tst_HoverHandler::mouseAreaAndUnderlyingHoverHandler() QTest::mouseMove(window, outOfSidebar); QCOMPARE(topSidebarHH->isHovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 0); + QCOMPARE(sidebarHoveredSpy.size(), 0); QCOMPARE(buttonMA->hovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.size(), 1); QCOMPARE(buttonMA->hovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif QTest::mouseMove(window, buttonCenter); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.size(), 1); QCOMPARE(buttonMA->hovered(), true); - QCOMPARE(buttonHoveredSpy.count(), 1); + QCOMPARE(buttonHoveredSpy.size(), 1); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::UpArrowCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(topSidebarHH->isHovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.size(), 1); QCOMPARE(buttonMA->hovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif QTest::mouseMove(window, outOfSidebar); QCOMPARE(topSidebarHH->isHovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 2); + QCOMPARE(sidebarHoveredSpy.size(), 2); QCOMPARE(buttonMA->hovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif @@ -231,50 +238,131 @@ void tst_HoverHandler::hoverHandlerAndUnderlyingMouseArea() QTest::mouseMove(window, outOfSidebar); QCOMPARE(bottomSidebarMA->hovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 0); + QCOMPARE(sidebarHoveredSpy.size(), 0); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(bottomSidebarMA->hovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 1); + QCOMPARE(sidebarHoveredSpy.size(), 1); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 0); + QCOMPARE(buttonHoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ClosedHandCursor); #endif QTest::mouseMove(window, buttonCenter); QCOMPARE(bottomSidebarMA->hovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 2); + QCOMPARE(sidebarHoveredSpy.size(), 2); QCOMPARE(buttonHH->isHovered(), true); - QCOMPARE(buttonHoveredSpy.count(), 1); + QCOMPARE(buttonHoveredSpy.size(), 1); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::PointingHandCursor); #endif QTest::mouseMove(window, rightOfButton); QCOMPARE(bottomSidebarMA->hovered(), true); - QCOMPARE(sidebarHoveredSpy.count(), 3); + QCOMPARE(sidebarHoveredSpy.size(), 3); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ClosedHandCursor); #endif QTest::mouseMove(window, outOfSidebar); QCOMPARE(bottomSidebarMA->hovered(), false); - QCOMPARE(sidebarHoveredSpy.count(), 4); + QCOMPARE(sidebarHoveredSpy.size(), 4); QCOMPARE(buttonHH->isHovered(), false); - QCOMPARE(buttonHoveredSpy.count(), 2); + QCOMPARE(buttonHoveredSpy.size(), 2); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif } +void tst_HoverHandler::disabledHoverHandlerAndUnderlyingMouseArea() +{ + // Check that if a disabled HoverHandler is installed on an item, it + // will not participate in hover event delivery, and as such, also + // not block propagation to siblings. + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "lesHoverables.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem * bottomSidebar = window->rootObject()->findChild<QQuickItem *>("bottomSidebar"); + QVERIFY(bottomSidebar); + QQuickMouseArea *bottomSidebarMA = bottomSidebar->findChild<QQuickMouseArea *>("bottomSidebarMA"); + QVERIFY(bottomSidebarMA); + QQuickItem * button = bottomSidebar->findChild<QQuickItem *>("buttonWithHH"); + QVERIFY(button); + QQuickHoverHandler *buttonHH = button->findChild<QQuickHoverHandler *>("buttonHH"); + QVERIFY(buttonHH); + + // By disabling the HoverHandler, it should no longer + // block the sibling MouseArea underneath from receiving hover events. + buttonHH->setEnabled(false); + + QPoint buttonCenter(button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); + QPoint rightOfButton(button->mapToScene(QPointF(button->width() + 2, button->height() / 2)).toPoint()); + QPoint outOfSidebar(bottomSidebar->mapToScene(QPointF(bottomSidebar->width() + 2, bottomSidebar->height() / 2)).toPoint()); + QSignalSpy sidebarHoveredSpy(bottomSidebarMA, SIGNAL(hoveredChanged())); + QSignalSpy buttonHoveredSpy(buttonHH, SIGNAL(hoveredChanged())); + + QTest::mouseMove(window, outOfSidebar); + QCOMPARE(bottomSidebarMA->hovered(), false); + QCOMPARE(sidebarHoveredSpy.size(), 0); + QCOMPARE(buttonHH->isHovered(), false); + QCOMPARE(buttonHoveredSpy.size(), 0); + + QTest::mouseMove(window, buttonCenter); + QCOMPARE(bottomSidebarMA->hovered(), true); + QCOMPARE(sidebarHoveredSpy.size(), 1); + QCOMPARE(buttonHH->isHovered(), false); + QCOMPARE(buttonHoveredSpy.size(), 0); + + QTest::mouseMove(window, rightOfButton); + QCOMPARE(bottomSidebarMA->hovered(), true); + QCOMPARE(sidebarHoveredSpy.size(), 1); + QCOMPARE(buttonHH->isHovered(), false); + QCOMPARE(buttonHoveredSpy.size(), 0); +} + +void tst_HoverHandler::hoverHandlerOnDisabledItem() +{ + // Check that if HoverHandler on a disabled item will + // continue to receive hover events (QTBUG-30801) + QScopedPointer<QQuickView> windowPtr; + createView(windowPtr, "lesHoverables.qml"); + QQuickView * window = windowPtr.data(); + QQuickItem * bottomSidebar = window->rootObject()->findChild<QQuickItem *>("bottomSidebar"); + QVERIFY(bottomSidebar); + QQuickItem * button = bottomSidebar->findChild<QQuickItem *>("buttonWithHH"); + QVERIFY(button); + QQuickHoverHandler *buttonHH = button->findChild<QQuickHoverHandler *>("buttonHH"); + QVERIFY(buttonHH); + + // Disable the button/rectangle item. This should not + // block its HoverHandler from being hovered + button->setEnabled(false); + + QPoint buttonCenter(button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); + QPoint rightOfButton(button->mapToScene(QPointF(button->width() + 2, button->height() / 2)).toPoint()); + QSignalSpy buttonHoveredSpy(buttonHH, SIGNAL(hoveredChanged())); + + QTest::mouseMove(window, rightOfButton); + QCOMPARE(buttonHH->isHovered(), false); + QCOMPARE(buttonHoveredSpy.size(), 0); + + QTest::mouseMove(window, buttonCenter); + QCOMPARE(buttonHH->isHovered(), true); + QCOMPARE(buttonHoveredSpy.size(), 1); + + QTest::mouseMove(window, rightOfButton); + QCOMPARE(buttonHH->isHovered(), false); + QCOMPARE(buttonHoveredSpy.size(), 2); +} + void tst_HoverHandler::movingItemWithHoverHandler() { if (isPlatformWayland()) @@ -328,21 +416,21 @@ void tst_HoverHandler::margin() // QTBUG-85303 QTest::mouseMove(window, {10, 10}); QCOMPARE(hh->isHovered(), false); - QCOMPARE(hoveredSpy.count(), 0); + QCOMPARE(hoveredSpy.size(), 0); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::ArrowCursor); #endif QTest::mouseMove(window, leftMargin); QCOMPARE(hh->isHovered(), true); - QCOMPARE(hoveredSpy.count(), 1); + QCOMPARE(hoveredSpy.size(), 1); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif QTest::mouseMove(window, itemCenter); QCOMPARE(hh->isHovered(), true); - QCOMPARE(hoveredSpy.count(), 1); + QCOMPARE(hoveredSpy.size(), 1); #if QT_CONFIG(cursor) QCOMPARE(window->cursor().shape(), Qt::OpenHandCursor); #endif @@ -383,6 +471,206 @@ void tst_HoverHandler::window() // QTBUG-98717 #endif } +void tst_HoverHandler::deviceCursor_data() +{ + QTest::addColumn<bool>("synthMouseForTabletEvents"); + QTest::addColumn<bool>("earlierTabletBeforeMouse"); + + QTest::newRow("nosynth, tablet wins") << false << false; + QTest::newRow("synth, tablet wins") << true << false; + QTest::newRow("synth, mouse wins") << true << true; +} + +void tst_HoverHandler::deviceCursor() +{ +#if !QT_CONFIG(tabletevent) + QSKIP("This test depends on QTabletEvent delivery."); +#endif + QFETCH(bool, synthMouseForTabletEvents); + QFETCH(bool, earlierTabletBeforeMouse); + qApp->setAttribute(Qt::AA_SynthesizeMouseForUnhandledTabletEvents, synthMouseForTabletEvents); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("hoverDeviceCursors.qml"))); + // Ensure that we don't get extra hover events delivered on the side + QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->frameSynchronousHoverEnabled = false; + // And flush out any mouse events that might be queued up in QPA, since QTest::mouseMove() calls processEvents. + qGuiApp->processEvents(); + const QQuickItem *root = window.rootObject(); + QQuickHoverHandler *stylusHandler = root->findChild<QQuickHoverHandler *>("stylus"); + QVERIFY(stylusHandler); + QQuickHoverHandler *eraserHandler = root->findChild<QQuickHoverHandler *>("stylus eraser"); + QVERIFY(eraserHandler); + QQuickHoverHandler *aibrushHandler = root->findChild<QQuickHoverHandler *>("airbrush"); + QVERIFY(aibrushHandler); + QQuickHoverHandler *airbrushEraserHandler = root->findChild<QQuickHoverHandler *>("airbrush eraser"); + QVERIFY(airbrushEraserHandler); + QQuickHoverHandler *mouseHandler = root->findChild<QQuickHoverHandler *>("mouse"); + QVERIFY(mouseHandler); + + QPoint point(100, 100); + + const qint64 stylusId = 1234567890; + QElapsedTimer timer; + timer.start(); + auto testStylusDevice = [&](QInputDevice::DeviceType dt, QPointingDevice::PointerType pt, + Qt::CursorShape expectedCursor, QQuickHoverHandler* expectedActiveHandler) { + // We will follow up with a mouse event afterwards, and we want to simulate that the tablet events occur + // either slightly before (earlierTabletBeforeMouse == true) or some time before. + // It turns out that the first mouse move happens at timestamp 501 (simulated). + const ulong timestamp = (earlierTabletBeforeMouse ? 0 : 400) + timer.elapsed(); + qCDebug(lcPointerTests) << "@" << timestamp << "sending" << dt << pt << "expecting" << expectedCursor << expectedActiveHandler->objectName(); + QWindowSystemInterface::handleTabletEvent(&window, timestamp, point, window.mapToGlobal(point), + int(dt), int(pt), Qt::NoButton, 0, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); + point += QPoint(1, 0); +#if QT_CONFIG(cursor) + // QQuickItem::setCursor() doesn't get called: we only have HoverHandlers in this test + QCOMPARE(root->cursor().shape(), Qt::ArrowCursor); + QTRY_COMPARE(window.cursor().shape(), expectedCursor); +#endif + QCOMPARE(stylusHandler->isHovered(), stylusHandler == expectedActiveHandler); + QCOMPARE(eraserHandler->isHovered(), eraserHandler == expectedActiveHandler); + QCOMPARE(aibrushHandler->isHovered(), aibrushHandler == expectedActiveHandler); + QCOMPARE(airbrushEraserHandler->isHovered(), airbrushEraserHandler == expectedActiveHandler); + }; + + // simulate move events from various tablet stylus types + testStylusDevice(QInputDevice::DeviceType::Stylus, QPointingDevice::PointerType::Pen, + Qt::CrossCursor, stylusHandler); + testStylusDevice(QInputDevice::DeviceType::Stylus, QPointingDevice::PointerType::Eraser, + Qt::PointingHandCursor, eraserHandler); + testStylusDevice(QInputDevice::DeviceType::Airbrush, QPointingDevice::PointerType::Pen, + Qt::BusyCursor, aibrushHandler); + testStylusDevice(QInputDevice::DeviceType::Airbrush, QPointingDevice::PointerType::Eraser, + Qt::OpenHandCursor, airbrushEraserHandler); + + qCDebug(lcPointerTests) << "---- no more tablet events, now we send a mouse move"; + + // move the mouse: the mouse-specific HoverHandler gets to set the cursor only if + // more than kCursorOverrideTimeout ms have elapsed (100ms) + QTest::mouseMove(&window, point, 100); + QTRY_IMPL(mouseHandler->isHovered() == true, 500); + const bool afterTimeout = + QQuickPointerHandlerPrivate::get(airbrushEraserHandler)->lastEventTime + 100 < + QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime; + qCDebug(lcPointerTests) << "airbrush handler reacted last time:" << QQuickPointerHandlerPrivate::get(airbrushEraserHandler)->lastEventTime + << "and the mouse handler reacted at time:" << QQuickPointerHandlerPrivate::get(mouseHandler)->lastEventTime + << "so > 100 ms have elapsed?" << afterTimeout; + if (afterTimeout) + QCOMPARE(mouseHandler->isHovered(), true); + else + QSKIP("Failed to delay mouse move 100ms after the previous tablet event"); + +#if QT_CONFIG(cursor) + QCOMPARE(window.cursor().shape(), afterTimeout ? Qt::IBeamCursor : Qt::OpenHandCursor); +#endif + QCOMPARE(stylusHandler->isHovered(), false); + QCOMPARE(eraserHandler->isHovered(), false); + QCOMPARE(aibrushHandler->isHovered(), false); + QCOMPARE(airbrushEraserHandler->isHovered(), true); // there was no fresh QTabletEvent to tell it not to be hovered +} + +void tst_HoverHandler::addHandlerFromCpp() +{ + // Check that you can create a hover handler from c++, and add it + // as a child of an existing item. Continue to check that you can + // also change the parent item at runtime. + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("nohandler.qml")); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickItem *childItem = window->findChild<QQuickItem *>("childItem"); + QVERIFY(childItem); + + // Move mouse outside child + const QPoint outside(200, 200); + const QPoint inside(50, 50); + QTest::mouseMove(window.data(), outside); + + QQuickHoverHandler *handler = new QQuickHoverHandler(childItem); + QSignalSpy spy(handler, &QQuickHoverHandler::hoveredChanged); + + // Move mouse inside child + QTest::mouseMove(window.data(), inside); + QVERIFY(handler->isHovered()); + QCOMPARE(spy.size(), 1); + + // Move mouse outside child + QTest::mouseMove(window.data(), outside); + QVERIFY(!handler->isHovered()); + QCOMPARE(spy.size(), 2); + + // Remove the parent item from the handler + spy.clear(); + handler->setParentItem(nullptr); + + // Move mouse inside child + QTest::mouseMove(window.data(), inside); + QVERIFY(!handler->isHovered()); + QCOMPARE(spy.size(), 0); + + // Move mouse outside child + QTest::mouseMove(window.data(), outside); + QVERIFY(!handler->isHovered()); + QCOMPARE(spy.size(), 0); + + // Reparent back the item to the handler + spy.clear(); + handler->setParentItem(childItem); + + // Move mouse inside child + QTest::mouseMove(window.data(), inside); + QVERIFY(handler->isHovered()); + QCOMPARE(spy.size(), 1); + + // Move mouse outside child + QTest::mouseMove(window.data(), outside); + QVERIFY(!handler->isHovered()); + QCOMPARE(spy.size(), 2); +} + +void tst_HoverHandler::ensureHoverHandlerWorksWhenItemHasHoverDisabled() +{ + // Check that a hover handler with a leaf item as parent, continues to + // receive hover, even if the item itself stops listening for hover. + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("nohandler.qml")); + QScopedPointer<QQuickWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(!window.isNull()); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickItem *childItem = window->findChild<QQuickItem *>("childItem"); + QVERIFY(childItem); + + // Move mouse outside child + const QPoint outside(200, 200); + const QPoint inside(50, 50); + QTest::mouseMove(window.data(), outside); + + QQuickHoverHandler *handler = new QQuickHoverHandler(childItem); + + // Toggle hover on the item. This should not clear subtreeHoverEnabled + // on the item as a whole, since it still has a hover handler. + childItem->setAcceptHoverEvents(true); + childItem->setAcceptHoverEvents(false); + QSignalSpy spy(handler, &QQuickHoverHandler::hoveredChanged); + + // Move mouse inside child + QTest::mouseMove(window.data(), inside); + QVERIFY(handler->isHovered()); + QCOMPARE(spy.size(), 1); + + // Move mouse outside child + QTest::mouseMove(window.data(), outside); + QVERIFY(!handler->isHovered()); + QCOMPARE(spy.size(), 2); +} + QTEST_MAIN(tst_HoverHandler) #include "tst_qquickhoverhandler.moc" diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/nullTarget.qml b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/nullTarget.qml new file mode 100644 index 0000000000..a348938aca --- /dev/null +++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/nullTarget.qml @@ -0,0 +1,33 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick 2.15 + +Item { + width: 320; height: 320 + property alias pinchScale: pinch.scale + + Rectangle { + objectName: "blackrect" + width: 200; height: 200 + color: "black" + antialiasing: true + scale: pinch.scale + rotation: pinch.rotation + x: pinch.translation.x + y: pinch.translation.y + + PinchHandler { + id: pinch + target: null + minimumScale: 0.5 + maximumScale: 4 + } + + Text { + color: "cyan" + anchors.centerIn: parent + text: "scale " + pinch.scale.toFixed(2) + " activeScale " + pinch.activeScale.toFixed(2) + } + } +} diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml index 0e0c949c91..3f1a2556cd 100644 --- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml +++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/data/pinchproperties.qml @@ -5,11 +5,38 @@ import QtQuick 2.12 Rectangle { id: whiteRect - property real scale: -1.0 + property real pinchScale: -1.0 property int activeCount : 0 property int deactiveCount : 0 width: 320; height: 320 color: "white" + + PointHandler { + id: ph1 + acceptedDevices: PointerDevice.TouchScreen + target: Rectangle { + parent: whiteRect + color: "cyan" + x: ph1.point.position.x - 3 + y: ph1.point.position.y - 3 + width: 6; height: 6; radius: 3 + } + } + + PointHandler { + id: ph2 + acceptedDevices: PointerDevice.TouchScreen + target: Rectangle { + parent: whiteRect + color: "lightgreen" + x: ph2.point.position.x - 3 + y: ph2.point.position.y - 3 + width: 6; height: 6; radius: 3 + } + } + + Text { color: "magenta"; z: 1; text: "scale: " + blackRect.scale} + Rectangle { id: blackRect objectName: "blackrect" @@ -18,8 +45,7 @@ Rectangle { x: 50 width: 100 height: 100 - opacity: (whiteRect.width-blackRect.x+whiteRect.height-blackRect.y-199)/200 - Text { color: "white"; text: "opacity: " + blackRect.opacity + "\nscale: " + blackRect.scale} + Rectangle { color: "red" width: 6; height: 6; radius: 3 @@ -31,20 +57,20 @@ Rectangle { PinchHandler { id: pincharea objectName: "pinchHandler" - minimumScale: 1.0 + minimumScale: 0.5 maximumScale: 4.0 minimumRotation: 0.0 maximumRotation: 90.0 xAxis.maximum: 140 yAxis.maximum: 170 onActiveChanged: { - whiteRect.scale = pincharea.scale + whiteRect.pinchScale = pincharea.scale if (active) ++activeCount else ++deactiveCount; } onUpdated: { - whiteRect.scale = pincharea.scale + whiteRect.pinchScale = pincharea.scale //whiteRect.pointCount = pincharea.pointCount } } diff --git a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp index 32f5b4a365..526d1c6941 100644 --- a/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpinchhandler/tst_qquickpinchhandler.cpp @@ -29,6 +29,7 @@ public: private slots: void cleanupTestCase(); void pinchProperties(); + void scale_data(); void scale(); void scaleThreeFingers(); void scaleNativeGesture_data(); @@ -42,8 +43,8 @@ private slots: void transformedpinchHandler(); private: - QPointingDevice *touchscreen = QTest::createTouchDevice(); - QPointingDevice *touchpad = QTest::createTouchDevice(QInputDevice::DeviceType::TouchPad); + QScopedPointer<QPointingDevice> touchscreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); + QScopedPointer<QPointingDevice> touchpad = QScopedPointer<QPointingDevice>(QTest::createTouchDevice(QInputDevice::DeviceType::TouchPad)); }; void tst_QQuickPinchHandler::cleanupTestCase() @@ -74,9 +75,9 @@ void tst_QQuickPinchHandler::pinchProperties() QVERIFY(rootItem != nullptr); QSignalSpy targetSpy(pinchHandler, SIGNAL(targetChanged())); pinchHandler->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); pinchHandler->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); // axis /* @@ -129,23 +130,23 @@ void tst_QQuickPinchHandler::pinchProperties() QSignalSpy scaleMinSpy(pinchHandler, SIGNAL(minimumScaleChanged())); QSignalSpy scaleMaxSpy(pinchHandler, SIGNAL(maximumScaleChanged())); - QCOMPARE(pinchHandler->minimumScale(), 1.0); + QCOMPARE(pinchHandler->minimumScale(), 0.5); QCOMPARE(pinchHandler->maximumScale(), 4.0); - pinchHandler->setMinimumScale(0.5); + pinchHandler->setMinimumScale(0.25); pinchHandler->setMaximumScale(1.5); - QCOMPARE(pinchHandler->minimumScale(), 0.5); + QCOMPARE(pinchHandler->minimumScale(), 0.25); QCOMPARE(pinchHandler->maximumScale(), 1.5); - QCOMPARE(scaleMinSpy.count(),1); - QCOMPARE(scaleMaxSpy.count(),1); + QCOMPARE(scaleMinSpy.size(),1); + QCOMPARE(scaleMaxSpy.size(),1); - pinchHandler->setMinimumScale(0.5); + pinchHandler->setMinimumScale(0.25); pinchHandler->setMaximumScale(1.5); - QCOMPARE(scaleMinSpy.count(),1); - QCOMPARE(scaleMaxSpy.count(),1); + QCOMPARE(scaleMinSpy.size(),1); + QCOMPARE(scaleMaxSpy.size(),1); // minimum and maximum rotation properties QSignalSpy rotMinSpy(pinchHandler, SIGNAL(minimumRotationChanged())); @@ -160,14 +161,14 @@ void tst_QQuickPinchHandler::pinchProperties() QCOMPARE(pinchHandler->minimumRotation(), -90.0); QCOMPARE(pinchHandler->maximumRotation(), 45.0); - QCOMPARE(rotMinSpy.count(),1); - QCOMPARE(rotMaxSpy.count(),1); + QCOMPARE(rotMinSpy.size(),1); + QCOMPARE(rotMaxSpy.size(),1); pinchHandler->setMinimumRotation(-90.0); pinchHandler->setMaximumRotation(45.0); - QCOMPARE(rotMinSpy.count(),1); - QCOMPARE(rotMaxSpy.count(),1); + QCOMPARE(rotMinSpy.size(),1); + QCOMPARE(rotMaxSpy.size(),1); } QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) @@ -179,91 +180,120 @@ QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) return touchPoint; } -void tst_QQuickPinchHandler::scale() +void tst_QQuickPinchHandler::scale_data() { - QQuickView *window = QQuickViewTestUtils::createView(); - QScopedPointer<QQuickView> scope(window); - window->setSource(testFileUrl("pinchproperties.qml")); - window->show(); - QVERIFY(QTest::qWaitForWindowExposed(window)); - QVERIFY(window->rootObject() != nullptr); - qApp->processEvents(); + QTest::addColumn<QUrl>("qmlfile"); + QTest::addColumn<bool>("hasTarget"); + QTest::newRow("targetModifying") << testFileUrl("pinchproperties.qml") << true; + QTest::newRow("nullTarget") << testFileUrl("nullTarget.qml") << false; +} - auto *pinchHandler = static_cast<PinchHandler *>(window->rootObject()->findChild<QQuickPinchHandler*>("pinchHandler")); - QVERIFY(pinchHandler != nullptr); - QSignalSpy grabChangedSpy(pinchHandler, SIGNAL(grabChanged(QPointingDevice::GrabTransition, QEventPoint))); +void tst_QQuickPinchHandler::scale() +{ + QFETCH(QUrl, qmlfile); + QFETCH(bool, hasTarget); - QQuickItem *root = qobject_cast<QQuickItem*>(window->rootObject()); + QQuickView window; + QVERIFY(QQuickTest::showView(window, qmlfile)); + QQuickItem *root = qobject_cast<QQuickItem*>(window.rootObject()); QVERIFY(root != nullptr); - - // target - QQuickItem *blackRect = window->rootObject()->findChild<QQuickItem*>("blackrect"); + auto *pinchHandler = static_cast<PinchHandler *>(root->findChild<QQuickPinchHandler*>()); + QVERIFY(pinchHandler != nullptr); + QQuickItem *blackRect = (hasTarget ? pinchHandler->target() : pinchHandler->parentItem()); QVERIFY(blackRect != nullptr); + QSignalSpy grabChangedSpy(pinchHandler, SIGNAL(grabChanged(QPointingDevice::GrabTransition, QEventPoint))); QPoint p0(80, 80); QPoint p1(100, 100); - { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); - pinchSequence.press(0, p0, window).commit(); - QQuickTouchUtils::flush(window); - // In order for the stationary point to remember its previous position, - // we have to reuse the same pinchSequence object. Otherwise if we let it - // be destroyed and then start a new sequence, point 0 will default to being - // stationary at 0, 0, and pinchHandler will filter out that touchpoint because - // it is outside its bounds. - pinchSequence.stationary(0).press(1, p1, window).commit(); - QQuickTouchUtils::flush(window); - QTRY_COMPARE(grabChangedSpy.count(), 1); // passive grab - - QPoint pd(10, 10); - // move one point until PinchHandler activates - for (int pi = 0; pi < 10 && !pinchHandler->active(); ++pi) { - p1 += pd; - pinchSequence.stationary(0).move(1, p1, window).commit(); - QQuickTouchUtils::flush(window); - } - QCOMPARE(pinchHandler->active(), true); - // grabs occur when the handler becomes active; at that time, QQuickHandlerPoint.sceneGrabPosition should be correct - QVERIFY(pinchHandler->firstPoint().sceneGrabPosition() != QPointF()); - QVERIFY(pinchHandler->lastPoint().sceneGrabPosition() != QPointF()); - QCOMPARE(pinchHandler->firstPoint().sceneGrabPosition(), pinchHandler->firstPoint().scenePosition()); - QCOMPARE(pinchHandler->lastPoint().sceneGrabPosition(), pinchHandler->lastPoint().scenePosition()); - // first point got a passive grab; both points got exclusive grabs - QCOMPARE(grabChangedSpy.count(), 3); - QLineF line(p0, p1); - const qreal startLength = line.length(); - - p1+=pd; - pinchSequence.stationary(0).move(1, p1, window).commit(); - QQuickTouchUtils::flush(window); - line.setP2(p1); - qreal scale = line.length() / startLength; - QVERIFY(qFloatDistance(root->property("scale").toReal(), scale) < 10); - QVERIFY(qFloatDistance(blackRect->scale(), scale) < 10); - - p1+=pd; - pinchSequence.stationary(0).move(1, p1, window).commit(); - QQuickTouchUtils::flush(window); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&window, touchscreen.get()); + pinchSequence.press(0, p0, &window).commit(); + QQuickTouchUtils::flush(&window); + // In order for the stationary point to remember its previous position, + // we have to reuse the same pinchSequence object. Otherwise if we let it + // be destroyed and then start a new sequence, point 0 will default to being + // stationary at 0, 0, and pinchHandler will filter out that touchpoint because + // it is outside its bounds. + pinchSequence.stationary(0).press(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + QCOMPARE(grabChangedSpy.size(), 1); // passive grab + + QPoint pd(10, 10); + // move one point until PinchHandler activates + for (int pi = 0; pi < 10 && !pinchHandler->active(); ++pi) { + p1 += pd; + pinchSequence.stationary(0).move(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + } + QCOMPARE(pinchHandler->active(), true); + // grabs occur when the handler becomes active; at that time, QQuickHandlerPoint.sceneGrabPosition should be correct + QVERIFY(pinchHandler->firstPoint().sceneGrabPosition() != QPointF()); + QVERIFY(pinchHandler->lastPoint().sceneGrabPosition() != QPointF()); + QCOMPARE(pinchHandler->firstPoint().sceneGrabPosition(), pinchHandler->firstPoint().scenePosition()); + QCOMPARE(pinchHandler->lastPoint().sceneGrabPosition(), pinchHandler->lastPoint().scenePosition()); + // first point got a passive grab; both points got exclusive grabs + QCOMPARE(grabChangedSpy.size(), 3); + QLineF line(p0, p1); + const qreal startLength = line.length(); + + // move the same point even further and observe the change in scale + for (int i = 0; i < 2; ++i) { + p1 += pd; + pinchSequence.stationary(0).move(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); line.setP2(p1); - scale = line.length() / startLength; - - QVERIFY(qFloatDistance(root->property("scale").toReal(), scale) < 10); - QVERIFY(qFloatDistance(blackRect->scale(), scale) < 10); - - QPointF expectedCentroid = p0 + (p1 - p0)/2; + qreal expectedScale = line.length() / startLength; + QVERIFY(qFloatDistance(root->property("pinchScale").toReal(), expectedScale) < 10); + QVERIFY(qFloatDistance(blackRect->scale(), expectedScale) < 10); + QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal()); + QCOMPARE(pinchHandler->scale(), pinchHandler->activeScale()); // in sync for the first gesture + QPointF expectedCentroid = p0 + (p1 - p0) / 2; QCOMPARE(pinchHandler->centroid().scenePosition(), expectedCentroid); } - // scale beyond bound - p1 += QPoint(20, 20); - { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); - pinchSequence.stationary(0).move(1, p1, window).commit(); - QQuickTouchUtils::flush(window); - QCOMPARE(blackRect->scale(), qreal(4)); // qquickpinchhandler does not manipulate scale property - pinchSequence.release(0, p0, window).release(1, p1, window).commit(); - QQuickTouchUtils::flush(window); + qreal lastScale = pinchHandler->scale(); + pinchSequence.release(0, p0, &window).release(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); + // scale property is persistent after release + QCOMPARE(pinchHandler->scale(), lastScale); + + // pinch a second time: scale picks up where we left off + p0 = QPoint(80, 80); + p1 = QPoint(100, 100); + pinchSequence.press(0, p0, &window).press(1, p1, &window).commit(); + // move one point until PinchHandler activates + for (int pi = 0; pi < 10 && !pinchHandler->active(); ++pi) { + p1 += pd; + pinchSequence.stationary(0).move(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + } + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); + QCOMPARE(pinchHandler->active(), true); + QCOMPARE(pinchHandler->scale(), lastScale); // just activated, not scaling further yet + for (int i = 0; i < 2; ++i) { + lastScale = pinchHandler->scale(); + p1 += pd; + pinchSequence.stationary(0).move(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); + QCOMPARE_GT(pinchHandler->scale(), lastScale); + line.setP2(p1); + qreal expectedActiveScale = line.length() / startLength; + QVERIFY(qFloatDistance(pinchHandler->activeScale(), expectedActiveScale) < 10); + QCOMPARE(pinchHandler->scale(), root->property("pinchScale").toReal()); + QCOMPARE_NE(pinchHandler->scale(), pinchHandler->activeScale()); // not in sync anymore } + + // scale beyond maximumScale + p1 = QPoint(310, 310); + pinchSequence.stationary(0).move(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); + QCOMPARE(blackRect->scale(), qreal(4)); + QCOMPARE(pinchHandler->scale(), qreal(4)); // limited by maximumScale + pinchSequence.release(0, p0, &window).release(1, p1, &window).commit(); + QQuickTouchUtils::flush(&window); QCOMPARE(pinchHandler->active(), false); } @@ -292,7 +322,7 @@ void tst_QQuickPinchHandler::scaleThreeFingers() QPoint p1(220, 80); QPoint p2(150, 220); { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen.get()); pinchSequence.press(0, p0, window).commit(); QQuickTouchUtils::flush(window); // In order for the stationary point to remember its previous position, @@ -348,14 +378,18 @@ void tst_QQuickPinchHandler::scaleThreeFingers() void tst_QQuickPinchHandler::scaleNativeGesture_data() { QTest::addColumn<QString>("qmlfile"); + QTest::addColumn<qreal>("scale"); - QTest::newRow("just pinch") << "pinchproperties.qml"; - QTest::newRow("pinch & drag") << "pinchAndDrag.qml"; + QTest::newRow("just pinch") << "pinchproperties.qml" << 1.1; + QTest::newRow("pinch & drag") << "pinchAndDrag.qml" << 1.1; + QTest::newRow("bigger than limit") << "pinchproperties.qml" << 5.0; + QTest::newRow("smaller than limit") << "pinchproperties.qml" << 0.25; } void tst_QQuickPinchHandler::scaleNativeGesture() { QFETCH(QString, qmlfile); + QFETCH(qreal, scale); QQuickView *window = QQuickViewTestUtils::createView(); QScopedPointer<QQuickView> scope(window); @@ -375,29 +409,30 @@ void tst_QQuickPinchHandler::scaleNativeGesture() QPointF targetPos = target->position(); ulong ts = 1; - // first pinch: scale it up - const qreal expectedScale = 1.1; + // first pinch: scale it + const qreal expectedScale = qBound(qreal(0.5), scale, qreal(4)); QPointF pinchPos(75, 75); QPointF pinchLocalPos = target->mapFromScene(pinchPos); // target position is adjusted in QQuickItemPrivate::adjustedPosForTransform() // so as to compensate for the change in size, to hold the centroid in place const QPointF expectedPos = targetPos + QPointF( (pinchPos.x() - target->x()) * (expectedScale - 1), (pinchPos.y() - target->y()) * (expectedScale - 1) ); - QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, + QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad.get(), Qt::BeginNativeGesture, pinchPos, pinchPos); - QWindowSystemInterface::handleGestureEventWithRealValue(window, ts++, touchpad, - Qt::ZoomNativeGesture, expectedScale - 1, pinchPos, pinchPos); + if (lcPointerTests().isDebugEnabled()) QTest::qWait(500); + QWindowSystemInterface::handleGestureEventWithRealValue(window, ts++, touchpad.get(), + Qt::ZoomNativeGesture, scale - 1, pinchPos, pinchPos); QTRY_COMPARE(target->scale(), expectedScale); QCOMPARE(pinchHandler->active(), true); - QCOMPARE(pinchHandler->centroid().position(), pinchLocalPos); - QCOMPARE(pinchHandler->centroid().scenePosition(), pinchPos); + QCOMPARE(pinchHandler->centroid().position().toPoint(), pinchLocalPos.toPoint()); + QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), pinchPos.toPoint()); QVERIFY(qAbs(target->position().x() - expectedPos.x()) < 0.001); QVERIFY(qAbs(target->position().y() - expectedPos.y()) < 0.001); QCOMPARE(pinchHandler->scale(), expectedScale); QCOMPARE(pinchHandler->activeScale(), expectedScale); QCOMPARE(pinchHandler->translation(), QVector2D()); QCOMPARE(pinchHandler->rotation(), 0); - QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, + QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad.get(), Qt::EndNativeGesture, pinchPos, pinchPos); QTRY_COMPARE(pinchHandler->active(), false); QCOMPARE(target->scale(), expectedScale); @@ -406,21 +441,24 @@ void tst_QQuickPinchHandler::scaleNativeGesture() QCOMPARE(pinchHandler->translation(), QVector2D()); QCOMPARE(pinchHandler->rotation(), 0); - // second pinch at a different position: scale it down to original size again + // second pinch at a different position: scale it back to original size again + // but remove the limits first, so that we can scale arbitrarily + pinchHandler->setMaximumScale(qInf()); + pinchHandler->setMinimumScale(-qInf()); const qreal reverseScale = (1 / expectedScale); - pinchPos = QPointF(125, 125); + pinchPos = QPointF(110, 110); pinchLocalPos = target->mapFromScene(pinchPos); - QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, + QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad.get(), Qt::BeginNativeGesture, pinchPos, pinchPos); - QWindowSystemInterface::handleGestureEventWithRealValue(window, ts++, touchpad, + QWindowSystemInterface::handleGestureEventWithRealValue(window, ts++, touchpad.get(), Qt::ZoomNativeGesture, reverseScale - 1, pinchPos, pinchPos); QTRY_COMPARE(target->scale(), 1); QCOMPARE(pinchHandler->active(), true); - QCOMPARE(pinchHandler->centroid().position(), pinchLocalPos); - QCOMPARE(pinchHandler->centroid().scenePosition(), pinchPos); + QCOMPARE(pinchHandler->centroid().position().toPoint(), pinchLocalPos.toPoint()); + QCOMPARE(pinchHandler->centroid().scenePosition().toPoint(), pinchPos.toPoint()); QCOMPARE(pinchHandler->scale(), 1); QCOMPARE(pinchHandler->activeScale(), reverseScale); - QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad, + QWindowSystemInterface::handleGestureEvent(window, ts++, touchpad.get(), Qt::EndNativeGesture, pinchPos, pinchPos); QTRY_COMPARE(pinchHandler->active(), false); QCOMPARE(target->scale(), 1); @@ -452,7 +490,7 @@ void tst_QQuickPinchHandler::pan() QPoint p1(100, 100); { const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen.get()); pinchSequence.press(0, p0, window).commit(); QQuickTouchUtils::flush(window); // In order for the stationary point to remember its previous position, @@ -460,7 +498,7 @@ void tst_QQuickPinchHandler::pan() pinchSequence.stationary(0).press(1, p1, window).commit(); QQuickTouchUtils::flush(window); QVERIFY(!root->property("pinchActive").toBool()); - QCOMPARE(root->property("scale").toReal(), -1.0); + QCOMPARE(root->property("pinchScale").toReal(), -1.0); p0 += QPoint(dragThreshold, 0); p1 += QPoint(dragThreshold, 0); @@ -468,7 +506,7 @@ void tst_QQuickPinchHandler::pan() QQuickTouchUtils::flush(window); // movement < dragThreshold: pinchHandler not yet active QVERIFY(!root->property("pinchActive").toBool()); - QCOMPARE(root->property("scale").toReal(), -1.0); + QCOMPARE(root->property("pinchScale").toReal(), -1.0); // just above the dragThreshold: pinchHandler starts p0 += QPoint(1, 0); @@ -476,7 +514,7 @@ void tst_QQuickPinchHandler::pan() pinchSequence.move(0, p0, window).move(1, p1, window).commit(); QQuickTouchUtils::flush(window); QCOMPARE(pinchHandler->active(), true); - QCOMPARE(root->property("scale").toReal(), 1.0); + QCOMPARE(root->property("pinchScale").toReal(), 1.0); // Calculation of the center point is tricky at first: // center point of the two touch points in item coordinates: @@ -518,13 +556,13 @@ void tst_QQuickPinchHandler::pan() // pan x beyond bound p0 += QPoint(100,100); p1 += QPoint(100,100); - QTest::touchEvent(window, touchscreen).move(0, p0, window).move(1, p1, window); + QTest::touchEvent(window, touchscreen.get()).move(0, p0, window).move(1, p1, window); QQuickTouchUtils::flush(window); QCOMPARE(blackRect->x(), 140.0); QCOMPARE(blackRect->y(), 170.0); - QTest::touchEvent(window, touchscreen).release(0, p0, window).release(1, p1, window); + QTest::touchEvent(window, touchscreen.get()).release(0, p0, window).release(1, p1, window); QQuickTouchUtils::flush(window); QVERIFY(!root->property("pinchActive").toBool()); } @@ -564,7 +602,7 @@ void tst_QQuickPinchHandler::dragAxesEnabled() QPoint blackRectPos = blackRect->position().toPoint(); // press two points, one above the rectangle's center and one below - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen.get()); pinchSequence.press(0, p0, window).press(1, p1, window).commit(); QQuickTouchUtils::flush(window); @@ -601,7 +639,7 @@ void tst_QQuickPinchHandler::dragAxesEnabled() QCOMPARE(blackRect->position().toPoint().x(), xEnabled ? 140 : blackRectPos.x()); // because of xAxis.maximum QCOMPARE(blackRect->position().toPoint().y(), yEnabled ? 170 : blackRectPos.y()); // because of yAxis.maximum - QTest::touchEvent(window, touchscreen).release(0, p0, window).release(1, p1, window); + QTest::touchEvent(window, touchscreen.get()).release(0, p0, window).release(1, p1, window); QQuickTouchUtils::flush(window); } @@ -630,7 +668,7 @@ void tst_QQuickPinchHandler::retouch() QPoint p0(80, 80); QPoint p1(100, 100); { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen.get()); pinchSequence.press(0, p0, window).commit(); QQuickTouchUtils::flush(window); // In order for the stationary point to remember its previous position, @@ -643,7 +681,7 @@ void tst_QQuickPinchHandler::retouch() pinchSequence.move(0, p0,window).move(1, p1,window).commit(); QQuickTouchUtils::flush(window); - QCOMPARE(root->property("scale").toReal(), 1.0); + QCOMPARE(root->property("pinchScale").toReal(), 1.0); QCOMPARE(pinchHandler->active(), true); p0 -= delta; @@ -654,8 +692,8 @@ void tst_QQuickPinchHandler::retouch() QCOMPARE(pinchHandler->active(), true); // accept some slack - QVERIFY(withinBounds(1.4, root->property("scale").toReal(), 1.6)); - QCOMPARE(pinchHandler->centroid().position(), QPointF(40, 40)); // blackrect is at 50,50 + QVERIFY(withinBounds(1.4, root->property("pinchScale").toReal(), 1.6)); + QCOMPARE(pinchHandler->centroid().position().toPoint(), QPoint(40, 40)); // blackrect is at 50,50 QVERIFY(withinBounds(1.4, blackRect->scale(), 1.6)); QCOMPARE(root->property("activeCount").toInt(), 1); @@ -713,7 +751,7 @@ void tst_QQuickPinchHandler::cancel() QPoint p0(80, 80); QPoint p1(100, 100); { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(window, touchscreen.get()); pinchSequence.press(0, p0, window).commit(); QQuickTouchUtils::flush(window); // In order for the stationary point to remember its previous position, @@ -729,7 +767,7 @@ void tst_QQuickPinchHandler::cancel() pinchSequence.move(0, p0,window).move(1, p1,window).commit(); QQuickTouchUtils::flush(window); - QCOMPARE(root->property("scale").toReal(), 1.0); + QCOMPARE(root->property("pinchScale").toReal(), 1.0); QCOMPARE(pinchHandler->active(), true); p0 -= delta; @@ -737,18 +775,18 @@ void tst_QQuickPinchHandler::cancel() pinchSequence.move(0, p0,window).move(1, p1,window).commit(); QQuickTouchUtils::flush(window); - QVERIFY(withinBounds(1.4, root->property("scale").toReal(), 1.6)); - QCOMPARE(pinchHandler->centroid().position(), QPointF(40, 40)); // blackrect is at 50,50 + QVERIFY(withinBounds(1.4, root->property("pinchScale").toReal(), 1.6)); + QCOMPARE(pinchHandler->centroid().position().toPoint(), QPoint(40, 40)); // blackrect is at 50,50 QVERIFY(withinBounds(1.4, blackRect->scale(), 1.6)); QSKIP("cancel is not supported atm"); - QTouchEvent cancelEvent(QEvent::TouchCancel, touchscreen); + QTouchEvent cancelEvent(QEvent::TouchCancel, touchscreen.get()); QCoreApplication::sendEvent(window, &cancelEvent); QQuickTouchUtils::flush(window); - QCOMPARE(root->property("scale").toReal(), 1.0); - QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50 + QCOMPARE(root->property("pinchScale").toReal(), 1.0); + QCOMPARE(root->property("center").toPoint(), QPoint(40, 40)); // blackrect is at 50,50 QCOMPARE(blackRect->scale(), 1.0); QVERIFY(!root->property("pinchActive").toBool()); } @@ -799,7 +837,7 @@ void tst_QQuickPinchHandler::transformedpinchHandler() const int threshold = qApp->styleHints()->startDragDistance(); { - QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(view, touchscreen); + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(view, touchscreen.get()); // start pinchHandler pinchSequence.press(0, p0, view).commit(); QQuickTouchUtils::flush(view); diff --git a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp index eea1946316..1a32a25bd8 100644 --- a/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickpointhandler/tst_qquickpointhandler.cpp @@ -37,6 +37,7 @@ private slots: void simultaneousMultiTouch(); void pressedMultipleButtons_data(); void pressedMultipleButtons(); + void ignoreSystemSynthMouse(); private: void createView(QScopedPointer<QQuickView> &window, const char *fileName); @@ -82,20 +83,20 @@ void tst_PointHandler::singleTouch() QTest::touchEvent(window, touchDevice).press(1, point, window); QQuickTouchUtils::flush(window); QTRY_COMPARE(handler->active(), true); - QCOMPARE(activeSpy.count(), 1); - QCOMPARE(pointSpy.count(), 1); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 1); QCOMPARE(handler->point().position().toPoint(), point); QCOMPARE(handler->point().scenePosition().toPoint(), point); QCOMPARE(handler->point().pressedButtons(), Qt::NoButton); QCOMPARE(handler->translation(), QVector2D()); - QCOMPARE(translationSpy.count(), 1); + QCOMPARE(translationSpy.size(), 1); point += QPoint(10, 10); QTest::touchEvent(window, touchDevice).move(1, point, window); QQuickTouchUtils::flush(window); QCOMPARE(handler->active(), true); - QCOMPARE(activeSpy.count(), 1); - QCOMPARE(pointSpy.count(), 2); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 2); QCOMPARE(handler->point().position().toPoint(), point); QCOMPARE(handler->point().scenePosition().toPoint(), point); QCOMPARE(handler->point().pressPosition().toPoint(), QPoint(100, 100)); @@ -104,15 +105,15 @@ void tst_PointHandler::singleTouch() QVERIFY(handler->point().velocity().x() > 0); QVERIFY(handler->point().velocity().y() > 0); QCOMPARE(handler->translation(), QVector2D(10, 10)); - QCOMPARE(translationSpy.count(), 2); + QCOMPARE(translationSpy.size(), 2); QTest::touchEvent(window, touchDevice).release(1, point, window); QQuickTouchUtils::flush(window); QTRY_COMPARE(handler->active(), false); - QCOMPARE(activeSpy.count(), 2); - QCOMPARE(pointSpy.count(), 3); + QCOMPARE(activeSpy.size(), 2); + QCOMPARE(pointSpy.size(), 3); QCOMPARE(handler->translation(), QVector2D()); - QCOMPARE(translationSpy.count(), 3); + QCOMPARE(translationSpy.size(), 3); } void tst_PointHandler::tabletStylus() @@ -138,8 +139,8 @@ void tst_PointHandler::tabletStylus() QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point), int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0.5, 25, 35, 0.6, 12.3, 3, stylusId, Qt::NoModifier); QTRY_COMPARE(handler->active(), true); - QCOMPARE(activeSpy.count(), 1); - QCOMPARE(pointSpy.count(), 1); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 1); QCOMPARE(handler->point().position().toPoint(), pointLocalDPI); QCOMPARE(handler->point().scenePosition().toPoint(), pointLocalDPI); QCOMPARE(handler->point().pressedButtons(), Qt::LeftButton); @@ -147,16 +148,16 @@ void tst_PointHandler::tabletStylus() QCOMPARE(handler->point().rotation(), 12.3); QCOMPARE(handler->point().uniqueId().numericId(), stylusId); QCOMPARE(handler->translation(), QVector2D()); - QCOMPARE(translationSpy.count(), 1); + QCOMPARE(translationSpy.size(), 1); QPoint delta(10, 10); QPoint deltaLocalDPI = QHighDpi::fromNativeLocalPosition(delta, window); point += delta; QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point), int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::LeftButton, 0.45, 23, 33, 0.57, 15.6, 3, stylusId, Qt::NoModifier); - QTRY_COMPARE(pointSpy.count(), 2); + QTRY_COMPARE(pointSpy.size(), 2); QCOMPARE(handler->active(), true); - QCOMPARE(activeSpy.count(), 1); + QCOMPARE(activeSpy.size(), 1); QCOMPARE(handler->point().position().toPoint(), pointLocalDPI + deltaLocalDPI); QCOMPARE(handler->point().scenePosition().toPoint(), pointLocalDPI + deltaLocalDPI); QCOMPARE(handler->point().pressPosition().toPoint(), pointLocalDPI); @@ -168,15 +169,15 @@ void tst_PointHandler::tabletStylus() QVERIFY(handler->point().velocity().x() > 0); QVERIFY(handler->point().velocity().y() > 0); QCOMPARE(handler->translation(), QVector2D(deltaLocalDPI)); - QCOMPARE(translationSpy.count(), 2); + QCOMPARE(translationSpy.size(), 2); QWindowSystemInterface::handleTabletEvent(window, point, window->mapToGlobal(point), int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); QTRY_COMPARE(handler->active(), false); - QCOMPARE(activeSpy.count(), 2); - QCOMPARE(pointSpy.count(), 3); + QCOMPARE(activeSpy.size(), 2); + QCOMPARE(pointSpy.size(), 3); QCOMPARE(handler->translation(), QVector2D()); - QCOMPARE(translationSpy.count(), 3); + QCOMPARE(translationSpy.size(), 3); } void tst_PointHandler::simultaneousMultiTouch() @@ -185,7 +186,7 @@ void tst_PointHandler::simultaneousMultiTouch() createView(windowPtr, "multiPointTracker.qml"); QQuickView * window = windowPtr.data(); QList<QQuickPointHandler *> handlers = window->rootObject()->findChildren<QQuickPointHandler *>(); - QCOMPARE(handlers.count(), 3); + QCOMPARE(handlers.size(), 3); QVector<QSignalSpy*> activeSpies; QVector<QSignalSpy*> pointSpies; @@ -204,8 +205,8 @@ void tst_PointHandler::simultaneousMultiTouch() int i = 0; for (auto h : handlers) { QTRY_COMPARE(h->active(), true); - QCOMPARE(activeSpies[i]->count(), 1); - QCOMPARE(pointSpies[i]->count(), 1); + QCOMPARE(activeSpies[i]->size(), 1); + QCOMPARE(pointSpies[i]->size(), 1); int chosenPointIndex = points.indexOf(h->point().position().toPoint()); QVERIFY(chosenPointIndex != -1); // Verify that each handler chose a unique point @@ -215,7 +216,7 @@ void tst_PointHandler::simultaneousMultiTouch() QCOMPARE(h->point().scenePosition().toPoint(), point); QCOMPARE(h->point().pressedButtons(), Qt::NoButton); QCOMPARE(h->translation(), QVector2D()); - QCOMPARE(translationSpies[i]->count(), 1); + QCOMPARE(translationSpies[i]->size(), 1); ++i; } @@ -226,8 +227,8 @@ void tst_PointHandler::simultaneousMultiTouch() i = 0; for (auto h : handlers) { QCOMPARE(h->active(), true); - QCOMPARE(activeSpies[i]->count(), 1); - QCOMPARE(pointSpies[i]->count(), 2); + QCOMPARE(activeSpies[i]->size(), 1); + QCOMPARE(pointSpies[i]->size(), 2); QCOMPARE(h->point().position().toPoint(), points[pointIndexPerHandler[i]]); QCOMPARE(h->point().scenePosition().toPoint(), points[pointIndexPerHandler[i]]); QCOMPARE(h->point().pressPosition().toPoint(), pressPoints[pointIndexPerHandler[i]]); @@ -236,7 +237,7 @@ void tst_PointHandler::simultaneousMultiTouch() QVERIFY(h->point().velocity().x() > 0); QVERIFY(h->point().velocity().y() > 0); QCOMPARE(h->translation(), QVector2D(10 + 10 * pointIndexPerHandler[i], 10 + 10 * pointIndexPerHandler[i] % 2)); - QCOMPARE(translationSpies[i]->count(), 2); + QCOMPARE(translationSpies[i]->size(), 2); ++i; } @@ -245,10 +246,10 @@ void tst_PointHandler::simultaneousMultiTouch() i = 0; for (auto h : handlers) { QTRY_COMPARE(h->active(), false); - QCOMPARE(activeSpies[i]->count(), 2); - QCOMPARE(pointSpies[i]->count(), 3); + QCOMPARE(activeSpies[i]->size(), 2); + QCOMPARE(pointSpies[i]->size(), 3); QCOMPARE(h->translation(), QVector2D()); - QCOMPARE(translationSpies[i]->count(), 3); + QCOMPARE(translationSpies[i]->size(), 3); ++i; } @@ -362,7 +363,7 @@ void tst_PointHandler::pressedMultipleButtons() QPoint point(100,100); - for (int i = 0; i < buttons.count(); ++i) { + for (int i = 0; i < buttons.size(); ++i) { int btns = int(buttons.at(i)); int release = 0; if (i > 0) { @@ -382,8 +383,91 @@ void tst_PointHandler::pressedMultipleButtons() QTest::mousePress(windowPtr.data(), Qt::NoButton, Qt::NoModifier, point); QCOMPARE(handler->active(), false); - QCOMPARE(activeSpy.count(), activeChangeCount); - QCOMPARE(pointSpy.count(), changeCount); + QCOMPARE(activeSpy.size(), activeChangeCount); + QCOMPARE(pointSpy.size(), changeCount); +} + +void tst_PointHandler::ignoreSystemSynthMouse() // QTBUG-104890 +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("pointTracker.qml"))); + QQuickPointHandler *handler = window.rootObject()->findChild<QQuickPointHandler *>(); + QVERIFY(handler); + auto devPriv = QPointingDevicePrivate::get(touchDevice); + QSignalSpy activeSpy(handler, SIGNAL(activeChanged())); + QSignalSpy pointSpy(handler, SIGNAL(pointChanged())); + + // touch press + QPoint point(100,100); + QTest::touchEvent(&window, touchDevice).press(0, point, &window); + QQuickTouchUtils::flush(&window); + + // touch move + point += QPoint(10, 10); + QTest::touchEvent(&window, touchDevice).move(0, point, &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 2); + QVERIFY(devPriv->queryPointById(0)->passiveGrabbers.contains(handler)); + + // Windows begins to synthesize mouse events in parallel with the touch event stream: move to touchpoint position, then press + { + QMouseEvent move(QEvent::MouseMove, point, point, window.mapToGlobal(point), + Qt::NoButton, Qt::NoButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem, touchDevice); + move.setTimestamp(235); // slightly after the last touch event + QGuiApplication::sendEvent(&window, &move); + } + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 2); + QVERIFY(devPriv->queryPointById(0)->passiveGrabbers.contains(handler)); + { + QMouseEvent press(QEvent::MouseButtonPress, point, point, window.mapToGlobal(point), + Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem, touchDevice); + press.setTimestamp(235); + QGuiApplication::sendEvent(&window, &press); + } + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 2); + QVERIFY(devPriv->queryPointById(0)->passiveGrabbers.contains(handler)); + + // another touch move + point += QPoint(10, 10); + QTest::touchEvent(&window, touchDevice).move(0, point, &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 3); + QCOMPARE(handler->point().position().toPoint(), point); + QCOMPARE(handler->point().scenePosition().toPoint(), point); + QCOMPARE(handler->point().pressPosition().toPoint(), QPoint(100, 100)); + QCOMPARE(handler->point().scenePressPosition().toPoint(), QPoint(100, 100)); + QVERIFY(devPriv->queryPointById(0)->passiveGrabbers.contains(handler)); + + // another fake mouse move + { + QMouseEvent move(QEvent::MouseMove, point, point, window.mapToGlobal(point), + Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem, touchDevice); + move.setTimestamp(240); + QGuiApplication::sendEvent(&window, &move); + } + QCOMPARE(handler->active(), true); + QCOMPARE(activeSpy.size(), 1); + QCOMPARE(pointSpy.size(), 3); + QCOMPARE(handler->point().position().toPoint(), point); + QCOMPARE(handler->point().scenePosition().toPoint(), point); + QCOMPARE(handler->point().pressPosition().toPoint(), QPoint(100, 100)); + QCOMPARE(handler->point().scenePressPosition().toPoint(), QPoint(100, 100)); + QVERIFY(devPriv->queryPointById(0)->passiveGrabbers.contains(handler)); + + // end with released state + QTest::touchEvent(&window, touchDevice).release(0, point, &window); + QMouseEvent release(QEvent::MouseButtonRelease, point, point, window.mapToGlobal(point), + Qt::LeftButton, Qt::LeftButton, Qt::NoModifier, Qt::MouseEventSynthesizedBySystem); + release.setTimestamp(280); + QGuiApplication::sendEvent(&window, &release); } QTEST_MAIN(tst_PointHandler) diff --git a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp index 3c016967ea..33d94a63e2 100644 --- a/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquicktaphandler/tst_qquicktaphandler.cpp @@ -412,22 +412,22 @@ void tst_TapHandler::mouseGesturePolicyReleaseWithinBounds() void tst_TapHandler::gesturePolicyDragWithinBounds_data() { - QTest::addColumn<QPointingDevice::DeviceType>("deviceType"); + QTest::addColumn<const QPointingDevice *>("device"); QTest::addColumn<QPoint>("dragStart"); QTest::addColumn<QPoint>("dragDistance"); QTest::addColumn<QString>("expectedFeedback"); - QTest::newRow("mouse: click") << QPointingDevice::DeviceType::Mouse << QPoint(200, 200) << QPoint(0, 0) << "middle"; - QTest::newRow("touch: tap") << QPointingDevice::DeviceType::TouchScreen << QPoint(200, 200) << QPoint(0, 0) << "middle"; - QTest::newRow("mouse: drag up") << QPointingDevice::DeviceType::Mouse << QPoint(200, 200) << QPoint(0, -20) << "top"; - QTest::newRow("touch: drag up") << QPointingDevice::DeviceType::TouchScreen << QPoint(200, 200) << QPoint(0, -20) << "top"; - QTest::newRow("mouse: drag out to cancel") << QPointingDevice::DeviceType::Mouse << QPoint(435, 200) << QPoint(10, 0) << "canceled"; - QTest::newRow("touch: drag out to cancel") << QPointingDevice::DeviceType::TouchScreen << QPoint(435, 200) << QPoint(10, 0) << "canceled"; + QTest::newRow("mouse: click") << QPointingDevice::primaryPointingDevice() << QPoint(200, 200) << QPoint(0, 0) << "middle"; + QTest::newRow("touch: tap") << touchDevice << QPoint(200, 200) << QPoint(0, 0) << "middle"; + QTest::newRow("mouse: drag up") << QPointingDevice::primaryPointingDevice() << QPoint(200, 200) << QPoint(0, -20) << "top"; + QTest::newRow("touch: drag up") << touchDevice << QPoint(200, 200) << QPoint(0, -20) << "top"; + QTest::newRow("mouse: drag out to cancel") << QPointingDevice::primaryPointingDevice() << QPoint(435, 200) << QPoint(10, 0) << "canceled"; + QTest::newRow("touch: drag out to cancel") << touchDevice << QPoint(435, 200) << QPoint(10, 0) << "canceled"; } void tst_TapHandler::gesturePolicyDragWithinBounds() { - QFETCH(QPointingDevice::DeviceType, deviceType); + QFETCH(const QPointingDevice *, device); QFETCH(QPoint, dragStart); QFETCH(QPoint, dragDistance); QFETCH(QString, expectedFeedback); @@ -439,33 +439,14 @@ void tst_TapHandler::gesturePolicyDragWithinBounds() QVERIFY(tapHandler); QSignalSpy canceledSpy(tapHandler, &QQuickTapHandler::canceled); - switch (static_cast<QPointingDevice::DeviceType>(deviceType)) { - case QPointingDevice::DeviceType::Mouse: - QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, dragStart); - QTRY_VERIFY(tapHandler->isPressed()); - QTest::mouseMove(&window, dragStart + dragDistance); - if (expectedCanceled) - QTRY_COMPARE(tapHandler->timeHeld(), -1); - else - QTRY_VERIFY(tapHandler->timeHeld() > 0.1); - QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, dragStart + dragDistance); - break; - case QPointingDevice::DeviceType::TouchScreen: - QTest::touchEvent(&window, touchDevice).press(0, dragStart, &window); - QQuickTouchUtils::flush(&window); - QTRY_VERIFY(tapHandler->isPressed()); - QTest::touchEvent(&window, touchDevice).move(0, dragStart + dragDistance, &window); - QQuickTouchUtils::flush(&window); - if (expectedCanceled) - QTRY_COMPARE(tapHandler->timeHeld(), -1); - else - QTRY_VERIFY(tapHandler->timeHeld() > 0.1); - QTest::touchEvent(&window, touchDevice).release(0, dragStart + dragDistance, &window); - QQuickTouchUtils::flush(&window); - break; - default: - break; - } + QQuickTest::pointerPress(device, &window, 0, dragStart); + QTRY_VERIFY(tapHandler->isPressed()); + QQuickTest::pointerMove(device, &window, 0, dragStart + dragDistance); + if (expectedCanceled) + QTRY_COMPARE(tapHandler->timeHeld(), -1); + else + QTRY_VERIFY(tapHandler->timeHeld() > 0.1); + QQuickTest::pointerRelease(device, &window, 0, dragStart + dragDistance); QCOMPARE(window.rootObject()->property("feedbackText"), expectedFeedback); if (expectedCanceled) diff --git a/tests/auto/quick/pointerhandlers/qquickwheelhandler/tst_qquickwheelhandler.cpp b/tests/auto/quick/pointerhandlers/qquickwheelhandler/tst_qquickwheelhandler.cpp index 3b9599e435..d87acc3200 100644 --- a/tests/auto/quick/pointerhandlers/qquickwheelhandler/tst_qquickwheelhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickwheelhandler/tst_qquickwheelhandler.cpp @@ -165,13 +165,13 @@ void tst_QQuickWheelHandler::singleHandler() sendWheelEvent(window, eventPos, eventAngleDelta, eventPixelDelta, eventModifiers, Qt::NoScrollPhase, eventInverted); } QCOMPARE(rect->position().toPoint(), expectedPosition); - QCOMPARE(activeChangedSpy.count(), 1); + QCOMPARE(activeChangedSpy.size(), 1); QCOMPARE(handler->active(), true); QCOMPARE(rect->scale(), expectedScale); QCOMPARE(rect->rotation(), expectedRotation); if (!eventPhases) { QTRY_COMPARE(handler->active(), false); - QCOMPARE(activeChangedSpy.count(), 2); + QCOMPARE(activeChangedSpy.size(), 2); } // restore by rotating backwards @@ -181,7 +181,7 @@ void tst_QQuickWheelHandler::singleHandler() } else { sendWheelEvent(window, eventPos, eventAngleDelta * -1, eventPixelDelta * -1, eventModifiers, Qt::NoScrollPhase, eventInverted); } - QCOMPARE(activeChangedSpy.count(), eventPhases ? 2 : 3); + QCOMPARE(activeChangedSpy.size(), eventPhases ? 2 : 3); QCOMPARE(handler->active(), !eventPhases); QCOMPARE(rect->position().toPoint(), QPoint(0, 0)); QCOMPARE(rect->scale(), 1); @@ -306,13 +306,13 @@ void tst_QQuickWheelHandler::nestedHandler() QCOMPARE(innerRect->scale(), innerScale); QCOMPARE(innerRect->rotation(), innerRotation); QCOMPARE(outerRect->position().toPoint(), outerPosition); - QCOMPARE(outerActiveChangedSpy.count(), 1); + QCOMPARE(outerActiveChangedSpy.size(), 1); QCOMPARE(outerHandler->active(), true); QCOMPARE(outerRect->scale(), outerScale); QCOMPARE(outerRect->rotation(), outerRotation); if (!eventPhases) { QTRY_COMPARE(outerHandler->active(), false); - QCOMPARE(outerActiveChangedSpy.count(), 2); + QCOMPARE(outerActiveChangedSpy.size(), 2); } } @@ -355,9 +355,9 @@ void tst_QQuickWheelHandler::blocking() qreal outerPosWas = outerRect->position().x(); sendWheelEvent(window, eventPos, {0, 120}, {0, 0}, Qt::NoModifier, Qt::NoScrollPhase, false); - QTRY_COMPARE(innerActiveChangedSpy.count(), 2); + QTRY_COMPARE(innerActiveChangedSpy.size(), 2); QCOMPARE(innerRect->position().x(), innerPosWas + 15); - QCOMPARE(outerActiveChangedSpy.count(), blocking ? 0 : 2); + QCOMPARE(outerActiveChangedSpy.size(), blocking ? 0 : 2); QCOMPARE(outerRect->position().x(), outerPosWas + (blocking ? 0 : 15)); } diff --git a/tests/auto/quick/propertyrequirements/tst_propertyrequirements.cpp b/tests/auto/quick/propertyrequirements/tst_propertyrequirements.cpp index 4734382fc8..b8de922777 100644 --- a/tests/auto/quick/propertyrequirements/tst_propertyrequirements.cpp +++ b/tests/auto/quick/propertyrequirements/tst_propertyrequirements.cpp @@ -160,7 +160,7 @@ void tst_PropertyRequirements::testQmlType(TestDepth testDepth, const QQmlType & inheritanceHierarchy.append(qmlType.metaObject()); } - for (const QMetaObject *metaClass : qAsConst(inheritanceHierarchy)) { + for (const QMetaObject *metaClass : std::as_const(inheritanceHierarchy)) { for (int idx = metaClass->propertyOffset(); idx < metaClass->propertyCount(); ++idx) { const QMetaProperty property = metaClass->property(idx); diff --git a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp index fa41dfd3d6..e7da38a5ce 100644 --- a/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp +++ b/tests/auto/quick/qquickaccessible/tst_qquickaccessible.cpp @@ -98,10 +98,10 @@ void tst_QQuickAccessible::cleanup() { const EventList list = QTestAccessibility::events(); if (!list.isEmpty()) { - qWarning().noquote() << list.count() + qWarning().noquote() << list.size() << "accessibility event(s) were not handled in testfunction '" << QTest::currentTestFunction() << "':"; - for (int i = 0; i < list.count(); ++i) { + for (int i = 0; i < list.size(); ++i) { auto object = list.at(i)->object(); QString objectInfo = object ? QDebug::toString(object) : u"[deleted object]"_s; diff --git a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp index 8be86cdec4..1a01a8aca5 100644 --- a/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp +++ b/tests/auto/quick/qquickanimatedimage/tst_qquickanimatedimage.cpp @@ -132,10 +132,10 @@ void tst_qquickanimatedimage::frameCount() const QUrl origSource = anim->source(); anim->setSource(QUrl()); QCOMPARE(anim->frameCount(), 0); - QCOMPARE(frameCountChangedSpy.count(), 1); + QCOMPARE(frameCountChangedSpy.size(), 1); anim->setSource(origSource); QCOMPARE(anim->frameCount(), 3); - QCOMPARE(frameCountChangedSpy.count(), 2); + QCOMPARE(frameCountChangedSpy.size(), 2); delete anim; } @@ -169,13 +169,13 @@ void tst_qquickanimatedimage::mirror_running() QVERIFY(spy.isValid()); anim->setPlaying(true); - QTRY_VERIFY(spy.count() == 1); spy.clear(); + QTRY_VERIFY(spy.size() == 1); spy.clear(); anim->setMirror(true); QCOMPARE(anim->currentFrame(), 1); QImage frame1_flipped = window.grabWindow(); - QTRY_VERIFY(spy.count() == 1); spy.clear(); + QTRY_VERIFY(spy.size() == 1); spy.clear(); QCOMPARE(anim->currentFrame(), 0); // animation only has 2 frames, should cycle back to first QImage frame0_flipped = window.grabWindow(); @@ -336,48 +336,48 @@ void tst_qquickanimatedimage::sourceSizeChanges() // Local ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 0); + QTRY_COMPARE(sourceSizeSpy.size(), 0); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 2); + QTRY_COMPARE(sourceSizeSpy.size(), 2); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 3); + QTRY_COMPARE(sourceSizeSpy.size(), 3); // Remote ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/hearts_copy.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/colors.gif")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 5); + QTRY_COMPARE(sourceSizeSpy.size(), 5); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(anim->status(), QQuickAnimatedImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 6); + QTRY_COMPARE(sourceSizeSpy.size(), 6); delete anim; } @@ -453,17 +453,17 @@ void tst_qquickanimatedimage::progressAndStatusChanges() ctxt->setContextProperty("srcImage", testFileUrl("stickman.gif")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 0); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 0); + QTRY_COMPARE(sourceSpy.size(), 0); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.gif")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 1); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 1); + QTRY_COMPARE(sourceSpy.size(), 1); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/stickman.gif")); @@ -471,16 +471,16 @@ void tst_qquickanimatedimage::progressAndStatusChanges() QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_VERIFY(progressSpy.count() > 1); - QTRY_COMPARE(statusSpy.count(), 3); + QTRY_COMPARE(sourceSpy.size(), 2); + QTRY_VERIFY(progressSpy.size() > 1); + QTRY_COMPARE(statusSpy.size(), 3); ctxt->setContextProperty("srcImage", ""); QTRY_COMPARE(obj->status(), QQuickImage::Null); QTRY_COMPARE(obj->progress(), 0.0); - QTRY_COMPARE(sourceSpy.count(), 3); - QTRY_VERIFY(progressSpy.count() > 2); - QTRY_COMPARE(statusSpy.count(), 4); + QTRY_COMPARE(sourceSpy.size(), 3); + QTRY_VERIFY(progressSpy.size() > 2); + QTRY_COMPARE(statusSpy.size(), 4); delete obj; } @@ -506,40 +506,40 @@ void tst_qquickanimatedimage::playingAndPausedChanges() obj->setProperty("paused", false); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 0); - QTRY_COMPARE(pausedSpy.count(), 0); + QTRY_COMPARE(playingSpy.size(), 0); + QTRY_COMPARE(pausedSpy.size(), 0); obj->setProperty("playing", false); obj->setProperty("paused", true); QTRY_VERIFY(!obj->isPlaying()); QTRY_VERIFY(obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 1); - QTRY_COMPARE(pausedSpy.count(), 1); + QTRY_COMPARE(playingSpy.size(), 1); + QTRY_COMPARE(pausedSpy.size(), 1); obj->setProperty("playing", true); obj->setProperty("paused", false); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 2); - QTRY_COMPARE(pausedSpy.count(), 2); + QTRY_COMPARE(playingSpy.size(), 2); + QTRY_COMPARE(pausedSpy.size(), 2); ctxt->setContextProperty("srcImage", testFileUrl("stickman.gif")); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 2); - QTRY_COMPARE(pausedSpy.count(), 2); + QTRY_COMPARE(playingSpy.size(), 2); + QTRY_COMPARE(pausedSpy.size(), 2); obj->setProperty("paused", true); QTRY_VERIFY(obj->isPlaying()); QTRY_VERIFY(obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 2); - QTRY_COMPARE(pausedSpy.count(), 3); + QTRY_COMPARE(playingSpy.size(), 2); + QTRY_COMPARE(pausedSpy.size(), 3); obj->setProperty("playing", false); QTRY_VERIFY(!obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 3); - QTRY_COMPARE(pausedSpy.count(), 4); + QTRY_COMPARE(playingSpy.size(), 3); + QTRY_COMPARE(pausedSpy.size(), 4); obj->setProperty("playing", true); @@ -547,8 +547,8 @@ void tst_qquickanimatedimage::playingAndPausedChanges() ctxt->setContextProperty("srcImage", testFileUrl("green.png")); QTRY_VERIFY(!obj->isPlaying()); QTRY_VERIFY(!obj->isPaused()); - QTRY_COMPARE(playingSpy.count(), 5); - QTRY_COMPARE(pausedSpy.count(), 4); + QTRY_COMPARE(playingSpy.size(), 5); + QTRY_COMPARE(pausedSpy.size(), 4); delete obj; } @@ -626,15 +626,15 @@ void tst_qquickanimatedimage::currentFrame() anim->setCurrentFrame(1); QCOMPARE(anim->currentFrame(), 1); - QCOMPARE(frameChangedSpy.count(), 1); - QCOMPARE(currentFrameChangedSpy.count(), 1); + QCOMPARE(frameChangedSpy.size(), 1); + QCOMPARE(currentFrameChangedSpy.size(), 1); QCOMPARE(anim->property("currentFrameChangeCount"), 1); QCOMPARE(anim->property("frameChangeCount"), 1); evaluate<void>(anim, "scriptedSetCurrentFrame(2)"); QCOMPARE(anim->currentFrame(), 2); - QCOMPARE(frameChangedSpy.count(), 2); - QCOMPARE(currentFrameChangedSpy.count(), 2); + QCOMPARE(frameChangedSpy.size(), 2); + QCOMPARE(currentFrameChangedSpy.size(), 2); QCOMPARE(anim->property("currentFrameChangeCount"), 2); QCOMPARE(anim->property("frameChangeCount"), 2); } diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index c9f16af86a..72c807bdf8 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -63,7 +63,7 @@ void tst_qquickanimatedsprite::test_properties() sprite->setRunning(false); QVERIFY(!sprite->running()); // The finished() signal shouldn't be emitted when running is manually set to false. - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(finishedSpy.size(), 0); sprite->setInterpolate(false); QVERIFY(!sprite->interpolate()); } @@ -87,11 +87,11 @@ void tst_qquickanimatedsprite::test_runningChangedSignal() QVERIFY(finishedSpy.isValid()); sprite->setRunning(true); - QTRY_COMPARE(runningChangedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 0); + QTRY_COMPARE(runningChangedSpy.size(), 1); + QCOMPARE(finishedSpy.size(), 0); QTRY_VERIFY(!sprite->running()); - QTRY_COMPARE(runningChangedSpy.count(), 2); - QCOMPARE(finishedSpy.count(), 1); + QTRY_COMPARE(runningChangedSpy.size(), 2); + QCOMPARE(finishedSpy.size(), 1); } void tst_qquickanimatedsprite::test_startStop() @@ -114,12 +114,12 @@ void tst_qquickanimatedsprite::test_startStop() sprite->start(); QVERIFY(sprite->running()); - QTRY_COMPARE(runningChangedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 0); + QTRY_COMPARE(runningChangedSpy.size(), 1); + QCOMPARE(finishedSpy.size(), 0); sprite->stop(); QVERIFY(!sprite->running()); - QTRY_COMPARE(runningChangedSpy.count(), 2); - QCOMPARE(finishedSpy.count(), 0); + QTRY_COMPARE(runningChangedSpy.size(), 2); + QCOMPARE(finishedSpy.size(), 0); sprite->setCurrentFrame(2); sprite->start(); @@ -154,12 +154,12 @@ void tst_qquickanimatedsprite::test_frameChangedSignal() QVERIFY(!sprite->paused()); QCOMPARE(sprite->loops(), 3); QCOMPARE(sprite->frameCount(), 6); - QCOMPARE(frameChangedSpy.count(), 0); + QCOMPARE(frameChangedSpy.size(), 0); frameChangedSpy.clear(); sprite->setRunning(true); QTRY_VERIFY(!sprite->running()); - QCOMPARE(frameChangedSpy.count(), 3*6 + 1); + QCOMPARE(frameChangedSpy.size(), 3*6 + 1); int prevFrame = -1; int loopCounter = 0; @@ -257,7 +257,7 @@ void tst_qquickanimatedsprite::test_largeAnimation() sprite->setRunning(true); QTRY_VERIFY_WITH_TIMEOUT(!sprite->running(), 100000 /* make sure we wait until its done*/ ); if (frameSync) - QVERIFY(isWithinRange(3*40, int(frameChangedSpy.count()), 3*40 + 1)); + QVERIFY(isWithinRange(3*40, int(frameChangedSpy.size()), 3*40 + 1)); int prevFrame = -1; int loopCounter = 0; int maxFrame = 0; @@ -375,8 +375,8 @@ void tst_qquickanimatedsprite::test_implicitSize() QVERIFY(frameImplicitWidthChangedSpy.isValid()); sprite->setFrameWidth(20); - QCOMPARE(frameWidthChangedSpy.count(), 1); - QCOMPARE(frameImplicitWidthChangedSpy.count(), 1); + QCOMPARE(frameWidthChangedSpy.size(), 1); + QCOMPARE(frameImplicitWidthChangedSpy.size(), 1); // Ensure that implicitHeight matches frameHeight. QSignalSpy frameHeightChangedSpy(sprite, SIGNAL(frameHeightChanged(int))); @@ -386,8 +386,8 @@ void tst_qquickanimatedsprite::test_implicitSize() QVERIFY(frameImplicitHeightChangedSpy.isValid()); sprite->setFrameHeight(20); - QCOMPARE(frameHeightChangedSpy.count(), 1); - QCOMPARE(frameImplicitHeightChangedSpy.count(), 1); + QCOMPARE(frameHeightChangedSpy.size(), 1); + QCOMPARE(frameImplicitHeightChangedSpy.size(), 1); } void tst_qquickanimatedsprite::test_infiniteLoops() @@ -409,7 +409,7 @@ void tst_qquickanimatedsprite::test_infiniteLoops() // The finished() signal shouldn't be emitted for infinite animations. const int previousFrame = sprite->currentFrame(); QTRY_VERIFY(sprite->currentFrame() != previousFrame); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(finishedSpy.size(), 0); } void tst_qquickanimatedsprite::test_finishBehavior() diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 4b0e38ba65..f7a84ca979 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -121,8 +121,8 @@ void tst_qquickanimations::simpleProperty() QCOMPARE(animation.target(), &rect); QCOMPARE(animation.property(), QLatin1String("x")); QCOMPARE(animation.to().toReal(), 200.0); - QCOMPARE(fromChangedSpy.count(), 0); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 0); + QCOMPARE(toChangedSpy.size(), 1); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -137,8 +137,8 @@ void tst_qquickanimations::simpleProperty() QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(),100.0); animation.setFrom(100); - QCOMPARE(fromChangedSpy.count(), 1); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 1); + QCOMPARE(toChangedSpy.size(), 1); } void tst_qquickanimations::simpleNumber() @@ -153,8 +153,8 @@ void tst_qquickanimations::simpleNumber() QCOMPARE(animation.target(), &rect); QCOMPARE(animation.property(), QLatin1String("x")); QCOMPARE(animation.to(), qreal(200)); - QCOMPARE(fromChangedSpy.count(), 0); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 0); + QCOMPARE(toChangedSpy.size(), 1); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -169,8 +169,8 @@ void tst_qquickanimations::simpleNumber() QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.x(), qreal(100)); animation.setFrom(100); - QCOMPARE(fromChangedSpy.count(), 1); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 1); + QCOMPARE(toChangedSpy.size(), 1); } void tst_qquickanimations::simpleColor() @@ -185,8 +185,8 @@ void tst_qquickanimations::simpleColor() QCOMPARE(animation.target(), &rect); QCOMPARE(animation.property(), QLatin1String("color")); QCOMPARE(animation.to(), QColor("red")); - QCOMPARE(fromChangedSpy.count(), 0); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 0); + QCOMPARE(toChangedSpy.size(), 1); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -204,8 +204,8 @@ void tst_qquickanimations::simpleColor() rect.setColor(QColor("green")); animation.setFrom(QColor("blue")); QCOMPARE(animation.from(), QColor("blue")); - QCOMPARE(fromChangedSpy.count(), 1); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 1); + QCOMPARE(toChangedSpy.size(), 1); animation.restart(); QCOMPARE(rect.color(), QColor("blue")); QVERIFY(animation.isRunning()); @@ -226,8 +226,8 @@ void tst_qquickanimations::simpleRotation() QCOMPARE(animation.property(), QLatin1String("rotation")); QCOMPARE(animation.to(), qreal(270)); QCOMPARE(animation.direction(), QQuickRotationAnimation::Numerical); - QCOMPARE(fromChangedSpy.count(), 0); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 0); + QCOMPARE(toChangedSpy.size(), 1); animation.start(); QVERIFY(animation.isRunning()); QTest::qWait(animation.duration()); @@ -242,8 +242,8 @@ void tst_qquickanimations::simpleRotation() QCOMPARE(animation.currentTime(), 125); QCOMPARE(rect.rotation(), qreal(135)); animation.setFrom(90); - QCOMPARE(fromChangedSpy.count(), 1); - QCOMPARE(toChangedSpy.count(), 1); + QCOMPARE(fromChangedSpy.size(), 1); + QCOMPARE(toChangedSpy.size(), 1); } void tst_qquickanimations::simplePath() @@ -667,11 +667,11 @@ void tst_qquickanimations::resume() QSignalSpy spy(&animation, SIGNAL(pausedChanged(bool))); animation.pause(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QVERIFY(animation.isPaused()); animation.stop(); QVERIFY(!animation.isPaused()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); // Load QtQuick to ensure that QQuickPropertyAnimation is registered as PropertyAnimation { @@ -683,12 +683,12 @@ void tst_qquickanimations::resume() QByteArray message = "<Unknown File>: QML PropertyAnimation: setPaused() cannot be used when animation isn't running."; QTest::ignoreMessage(QtWarningMsg, message); animation.pause(); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QVERIFY(!animation.isPaused()); animation.resume(); QVERIFY(!animation.isPaused()); QVERIFY(!animation.isRunning()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquickanimations::dotProperty() @@ -727,7 +727,7 @@ void tst_qquickanimations::badTypes() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj.isNull()); - QCOMPARE(c.errors().count(), 1); + QCOMPARE(c.errors().size(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: number expected")); } @@ -739,7 +739,7 @@ void tst_qquickanimations::badTypes() QScopedPointer<QObject> obj(c.create()); QVERIFY(obj.isNull()); - QCOMPARE(c.errors().count(), 1); + QCOMPARE(c.errors().size(), 1); QCOMPARE(c.errors().at(0).description(), QLatin1String("Invalid property assignment: color expected")); } @@ -1047,12 +1047,12 @@ void tst_qquickanimations::disabledTransition() QSignalSpy runningSpy(trans, SIGNAL(runningChanged())); QQuickItemPrivate::get(rect)->setState(""); QCOMPARE(myRect->x(),qreal(200)); - QCOMPARE(runningSpy.count(), 1); //stopped -> running + QCOMPARE(runningSpy.size(), 1); //stopped -> running QVERIFY(trans->running()); QTest::qWait(300); QTIMED_COMPARE(myRect->x(),qreal(100)); QVERIFY(!trans->running()); - QCOMPARE(runningSpy.count(), 2); //running -> stopped + QCOMPARE(runningSpy.size(), 2); //running -> stopped } void tst_qquickanimations::invalidDuration() @@ -1226,7 +1226,7 @@ void tst_qquickanimations::easingProperties() QVERIFY(animObject != nullptr); QCOMPARE(animObject->easing().type(), QEasingCurve::BezierSpline); QVector<QPointF> points = animObject->easing().toCubicSpline(); - QCOMPARE(points.count(), 3); + QCOMPARE(points.size(), 3); QCOMPARE(points.at(0), QPointF(0.5, 0.2)); QCOMPARE(points.at(1), QPointF(0.13, 0.65)); QCOMPARE(points.at(2), QPointF(1.0, 1.0)); @@ -1355,7 +1355,7 @@ void tst_qquickanimations::signalOrder() colorAnimation->setDuration(duration); animation->start(); - QTRY_VERIFY(finishedSpy.count()); + QTRY_VERIFY(finishedSpy.size()); QCOMPARE(actualSignalOrder, expectedSignalOrder); } @@ -1678,7 +1678,7 @@ void tst_qquickanimations::unsetAnimatorProxyJobWindow() item.setParentItem(&dummy); QSignalSpy spy(&window, SIGNAL(sceneGraphInitialized())); window.show(); - if (spy.count() < 1) + if (spy.size() < 1) spy.wait(); QCOMPARE(proxy.job().data(), job); } @@ -1705,8 +1705,8 @@ void tst_qquickanimations::finished() QVERIFY(finishedSpy.isValid()); QVERIFY(simpleTopLevelAnimation->setProperty("running", QVariant(true))); - QTRY_COMPARE(stoppedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 1); + QTRY_COMPARE(stoppedSpy.size(), 1); + QCOMPARE(finishedSpy.size(), 1); // Test that the signal is properly revisioned and hence accessible from QML. QCOMPARE(root->property("finishedUsableInQml").toBool(), true); @@ -1733,9 +1733,9 @@ void tst_qquickanimations::finished() QObject *transitionRect = root->property("transitionRect").value<QObject*>(); QVERIFY(transitionRect); QVERIFY(transitionRect->setProperty("state", QVariant(QLatin1String("go")))); - QTRY_COMPARE(runningChangedSpy.count(), 1); - QCOMPARE(stoppedSpy.count(), 0); - QCOMPARE(finishedSpy.count(), 0); + QTRY_COMPARE(runningChangedSpy.size(), 1); + QCOMPARE(stoppedSpy.size(), 0); + QCOMPARE(finishedSpy.size(), 0); } // Test that finished() is not emitted for animations within a Behavior. @@ -1752,8 +1752,8 @@ void tst_qquickanimations::finished() QVERIFY(root->setProperty("bar", QVariant(1.0))); QTRY_COMPARE(root->property("bar").toReal(), 1.0); - QCOMPARE(stoppedSpy.count(), 0); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(stoppedSpy.size(), 0); + QCOMPARE(finishedSpy.size(), 0); } } @@ -2095,8 +2095,8 @@ void tst_qquickanimations::changePropertiesDuringAnimation() // mid-animation. if (loops != QQuickAbstractAnimation::Infinite) QVERIFY(numberAnimation->qtAnimation()->currentLoop() < numberAnimation->loops()); - QCOMPARE(startedSpy.count(), 0); - QCOMPARE(stoppedSpy.count(), 0); + QCOMPARE(startedSpy.size(), 0); + QCOMPARE(stoppedSpy.size(), 0); } void tst_qquickanimations::infiniteLoopsWithoutFrom() diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index e65a67c045..5ea11729d8 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -341,7 +341,7 @@ void tst_qquickbehaviors::runningTrue() QSignalSpy runningSpy(animation, SIGNAL(runningChanged(bool))); rect->setProperty("myValue", 180); - QTRY_VERIFY(runningSpy.count() > 0); + QTRY_VERIFY(runningSpy.size() > 0); } //QTBUG-12295 @@ -579,7 +579,7 @@ void tst_qquickbehaviors::aliasedProperty() QSignalSpy targetValueSpy(behavior, SIGNAL(targetValueChanged())); QQuickItemPrivate::get(rect.data())->setState("moved"); QCOMPARE(behavior->targetValue(), 400); - QCOMPARE(targetValueSpy.count(), 1); + QCOMPARE(targetValueSpy.size(), 1); QScopedPointer<QQuickRectangle> acc(qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("acc"))); QScopedPointer<QQuickRectangle> range(qobject_cast<QQuickRectangle*>(acc->findChild<QQuickRectangle*>("range"))); QTRY_VERIFY(acc->property("value").toDouble() > 0); @@ -615,7 +615,7 @@ void tst_qquickbehaviors::oneWay() QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRectOneWay")); myRect->setProperty("x", 100); QCOMPARE(behavior->targetValue(), 100); - QCOMPARE(targetValueSpy.count(), 1); + QCOMPARE(targetValueSpy.size(), 1); QCOMPARE(behavior->enabled(), false); qreal x = myRect->x(); QCOMPARE(x, qreal(100)); //should change immediately @@ -625,7 +625,7 @@ void tst_qquickbehaviors::oneWay() myRect->setProperty("x", 0); QCOMPARE(behavior->targetValue(), 0); - QCOMPARE(targetValueSpy.count(), 2); + QCOMPARE(targetValueSpy.size(), 2); QCOMPARE(behavior->enabled(), true); QCOMPARE(myAnimation->isRunning(), true); QVERIFY(myRect->x() > 0.0); diff --git a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp index 793ab8d8c9..a217c4ea1b 100644 --- a/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp +++ b/tests/auto/quick/qquickborderimage/tst_qquickborderimage.cpp @@ -435,7 +435,7 @@ void tst_qquickborderimage::statusChanges() if (remote) server.sendDelayedItem(); QTRY_COMPARE(obj->status(), finalStatus); - QCOMPARE(spy.count(), emissions); + QCOMPARE(spy.size(), emissions); delete obj; } @@ -460,48 +460,48 @@ void tst_qquickborderimage::sourceSizeChanges() // Local ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 0); + QTRY_COMPARE(sourceSizeSpy.size(), 0); ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("heart200_copy.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 2); + QTRY_COMPARE(sourceSizeSpy.size(), 2); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 3); + QTRY_COMPARE(sourceSizeSpy.size(), 3); // Remote ctxt->setContextProperty("srcImage", server.url("/heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/heart200_copy.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/colors.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 5); + QTRY_COMPARE(sourceSizeSpy.size(), 5); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 6); + QTRY_COMPARE(sourceSizeSpy.size(), 6); delete obj; } @@ -532,17 +532,17 @@ void tst_qquickborderimage::progressAndStatusChanges() ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 0); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 0); + QTRY_COMPARE(sourceSpy.size(), 0); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 1); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 1); + QTRY_COMPARE(sourceSpy.size(), 1); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart200.png")); @@ -550,16 +550,16 @@ void tst_qquickborderimage::progressAndStatusChanges() QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(obj->status(), QQuickBorderImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_VERIFY(progressSpy.count() > 1); - QTRY_COMPARE(statusSpy.count(), 3); + QTRY_COMPARE(sourceSpy.size(), 2); + QTRY_VERIFY(progressSpy.size() > 1); + QTRY_COMPARE(statusSpy.size(), 3); ctxt->setContextProperty("srcImage", ""); QTRY_COMPARE(obj->status(), QQuickBorderImage::Null); QTRY_COMPARE(obj->progress(), 0.0); - QTRY_COMPARE(sourceSpy.count(), 3); - QTRY_VERIFY(progressSpy.count() > 2); - QTRY_COMPARE(statusSpy.count(), 4); + QTRY_COMPARE(sourceSpy.size(), 3); + QTRY_VERIFY(progressSpy.size() > 2); + QTRY_COMPARE(statusSpy.size(), 4); delete obj; } @@ -614,7 +614,7 @@ void tst_qquickborderimage::multiFrame() if (asynchronous) { QCOMPARE(image->frameCount(), 0); QTRY_COMPARE(image->frameCount(), 4); - QCOMPARE(countSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); } else { QCOMPARE(image->frameCount(), 4); } @@ -636,7 +636,7 @@ void tst_qquickborderimage::multiFrame() image->setCurrentFrame(1); QTRY_COMPARE(image->status(), QQuickImageBase::Ready); - QCOMPARE(currentSpy.count(), 1); + QCOMPARE(currentSpy.size(), 1); QCOMPARE(image->currentFrame(), 1); contents = view.grabWindow(); // The middle of the second frame looks green, approximately qRgba(0x3a, 0xd2, 0x31, 0xff) diff --git a/tests/auto/quick/qquickboundaryrule/tst_qquickboundaryrule.cpp b/tests/auto/quick/qquickboundaryrule/tst_qquickboundaryrule.cpp index dab29e21cc..1aa926ab19 100644 --- a/tests/auto/quick/qquickboundaryrule/tst_qquickboundaryrule.cpp +++ b/tests/auto/quick/qquickboundaryrule/tst_qquickboundaryrule.cpp @@ -54,25 +54,25 @@ void tst_qquickboundaryrule::dragHandler() QVERIFY(ok); QCOMPARE(boundaryRule->property("peakOvershoot").toReal(&ok), 0); QVERIFY(ok); - QCOMPARE(overshootChangedSpy.count(), 0); + QCOMPARE(overshootChangedSpy.size(), 0); // restricted drag: halfway into overshoot p1 += QPoint(20, 0); QTest::mouseMove(&window, p1); QCOMPARE(target->position().x(), 117.5); QCOMPARE(boundaryRule->property("currentOvershoot").toReal(), 20); QCOMPARE(boundaryRule->property("peakOvershoot").toReal(), 20); - QCOMPARE(overshootChangedSpy.count(), 1); + QCOMPARE(overshootChangedSpy.size(), 1); // restricted drag: maximum overshoot p1 += QPoint(80, 0); QTest::mouseMove(&window, p1); QCOMPARE(target->position().x(), 140); QCOMPARE(boundaryRule->property("currentOvershoot").toReal(), 100); QCOMPARE(boundaryRule->property("peakOvershoot").toReal(), 100); - QCOMPARE(overshootChangedSpy.count(), 2); + QCOMPARE(overshootChangedSpy.size(), 2); // release and let it return to bounds QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p1); QTRY_COMPARE(dragHandler->active(), false); - QTRY_COMPARE(overshootChangedSpy.count(), 3); + QTRY_COMPARE(overshootChangedSpy.size(), 3); QCOMPARE(boundaryRule->property("currentOvershoot").toReal(&ok), 0); QVERIFY(ok); QCOMPARE(boundaryRule->property("peakOvershoot").toReal(&ok), 0); diff --git a/tests/auto/quick/qquickcolorgroup/tst_qquickcolorgroup.cpp b/tests/auto/quick/qquickcolorgroup/tst_qquickcolorgroup.cpp index f1bc591bd3..046cd5a14c 100644 --- a/tests/auto/quick/qquickcolorgroup/tst_qquickcolorgroup.cpp +++ b/tests/auto/quick/qquickcolorgroup/tst_qquickcolorgroup.cpp @@ -46,7 +46,7 @@ void tst_QQuickColorGroup::checkColorProperty() qvariant_cast<QColor>(property.read(&defaultGroup))); constexpr int expectedNotificationsCount = 2; // One from write + one from reset - QCOMPARE(sp.count(), expectedNotificationsCount); + QCOMPARE(sp.size(), expectedNotificationsCount); } void tst_QQuickColorGroup::checkColorProperty_data() @@ -73,7 +73,7 @@ void tst_QQuickColorGroup::colorGroupChangedWhenColorChanged() group.setMid(Qt::blue); - QCOMPARE(sp.count(), 1); + QCOMPARE(sp.size(), 1); } QTEST_MAIN(tst_QQuickColorGroup) diff --git a/tests/auto/quick/qquickdeliveryagent/data/listViewDelegate.qml b/tests/auto/quick/qquickdeliveryagent/data/listViewDelegate.qml new file mode 100644 index 0000000000..bdb7246450 --- /dev/null +++ b/tests/auto/quick/qquickdeliveryagent/data/listViewDelegate.qml @@ -0,0 +1,21 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Item { + id: root + width: 320 + height: 240 + + ListView { + id: listView + width: 320 + height: 240 + delegate: Rectangle { + width: ListView.view.width + height: ListView.view.height / ListView.view.count + color: "tomato" + } + } +} diff --git a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp index 075dd77b3f..7e6416b8e2 100644 --- a/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp +++ b/tests/auto/quick/qquickdeliveryagent/tst_qquickdeliveryagent.cpp @@ -11,6 +11,7 @@ #include <QtQuick/QQuickWindow> #include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/private/qquicklistview_p.h> #include <QtQuick/private/qquickpointhandler_p.h> #include <QtQuick/private/qquickshadereffectsource_p.h> #include <QtQuick/private/qquicktaphandler_p.h> @@ -130,7 +131,9 @@ public: private slots: void passiveGrabberOrder(); void passiveGrabberItems(); + void tapHandlerDoesntOverrideSubsceneGrabber_data(); void tapHandlerDoesntOverrideSubsceneGrabber(); + void undoDelegationWhenSubsceneFocusCleared(); void touchCompression(); void hoverPropagation_nested_data(); void hoverPropagation_nested(); @@ -176,7 +179,7 @@ void tst_qquickdeliveryagent::passiveGrabberOrder() auto devPriv = QPointingDevicePrivate::get(QPointingDevice::primaryPointingDevice()); const auto &persistentPoint = devPriv->activePoints.values().first(); qCDebug(lcTests) << "passive grabbers" << persistentPoint.passiveGrabbers << "contexts" << persistentPoint.passiveGrabbersContext; - QCOMPARE(persistentPoint.passiveGrabbers.count(), 2); + QCOMPARE(persistentPoint.passiveGrabbers.size(), 2); QCOMPARE(persistentPoint.passiveGrabbers.first(), subsceneTap); QCOMPARE(persistentPoint.passiveGrabbersContext.first(), subscene.deliveryAgent); QCOMPARE(persistentPoint.passiveGrabbers.last(), rootTap); @@ -184,10 +187,10 @@ void tst_qquickdeliveryagent::passiveGrabberOrder() QTest::mouseRelease(&view, Qt::LeftButton); QTest::qWait(100); // QQuickWindow::event() has failsafe: clear all grabbers after release - QCOMPARE(persistentPoint.passiveGrabbers.count(), 0); + QCOMPARE(persistentPoint.passiveGrabbers.size(), 0); qCDebug(lcTests) << "TapHandlers emitted tapped in this order:" << spy.senders; - QCOMPARE(spy.senders.count(), 2); + QCOMPARE(spy.senders.size(), 2); // passive grabbers are visited in order, and emit tapped() at that time QCOMPARE(spy.senders.first(), subsceneTap); QCOMPARE(spy.senders.last(), rootTap); @@ -276,7 +279,7 @@ void tst_qquickdeliveryagent::passiveGrabberItems() QTest::mousePress(&view, Qt::LeftButton, Qt::NoModifier, QPoint(exclusiveGrabber->x() + 1, exclusiveGrabber->y() + 1)); auto devPriv = QPointingDevicePrivate::get(QPointingDevice::primaryPointingDevice()); const auto &persistentPoint = devPriv->activePoints.values().first(); - QTRY_COMPARE(persistentPoint.passiveGrabbers.count(), 1); + QTRY_COMPARE(persistentPoint.passiveGrabbers.size(), 1); QCOMPARE(persistentPoint.passiveGrabbers.first(), passiveGrabber); QCOMPARE(persistentPoint.exclusiveGrabber, exclusiveGrabber); QVERIFY(exclusiveGrabber->lastPressed); @@ -292,7 +295,7 @@ void tst_qquickdeliveryagent::passiveGrabberItems() // since it became the exclusive grabber on mouseMove QTRY_VERIFY(!passiveGrabber->lastPressed); QVERIFY(exclusiveGrabber->lastPressed); - QCOMPARE(persistentPoint.passiveGrabbers.count(), 0); + QCOMPARE(persistentPoint.passiveGrabbers.size(), 0); QCOMPARE(persistentPoint.exclusiveGrabber, nullptr); exclusiveGrabber->lastPressed = false; @@ -301,7 +304,7 @@ void tst_qquickdeliveryagent::passiveGrabberItems() QTest::mousePress(&view, Qt::LeftButton, Qt::NoModifier, QPoint(exclusiveGrabber->x() + 1, exclusiveGrabber->y() + 1)); const auto &pressedPoint = devPriv->activePoints.values().first(); - QTRY_COMPARE(pressedPoint.passiveGrabbers.count(), 1); + QTRY_COMPARE(pressedPoint.passiveGrabbers.size(), 1); QCOMPARE(pressedPoint.passiveGrabbers.first(), passiveGrabber); QCOMPARE(pressedPoint.exclusiveGrabber, exclusiveGrabber); QVERIFY(exclusiveGrabber->lastPressed); @@ -316,12 +319,29 @@ void tst_qquickdeliveryagent::passiveGrabberItems() // Both the passive and the exclusive grabber get the mouseRelease event QTRY_VERIFY(!passiveGrabber->lastPressed); QVERIFY(!exclusiveGrabber->lastPressed); - QCOMPARE(pressedPoint.passiveGrabbers.count(), 0); + QCOMPARE(pressedPoint.passiveGrabbers.size(), 0); QCOMPARE(pressedPoint.exclusiveGrabber, nullptr); } +void tst_qquickdeliveryagent::tapHandlerDoesntOverrideSubsceneGrabber_data() +{ + QTest::addColumn<QQuickTapHandler::GesturePolicy>("gesturePolicy"); + QTest::addColumn<int>("expectedTaps"); + QTest::addColumn<int>("expectedCancels"); + // TapHandler gets passive grab => "stealth" tap, regardless of other Items + QTest::newRow("DragThreshold") << QQuickTapHandler::DragThreshold << 1 << 0; + // TapHandler gets exclusive grab => it's cancelled when the TextEdit takes the grab + QTest::newRow("WithinBounds") << QQuickTapHandler::WithinBounds << 0 << 2; // 2 because of QTBUG-105865 + QTest::newRow("ReleaseWithinBounds") << QQuickTapHandler::ReleaseWithinBounds << 0 << 2; + QTest::newRow("DragWithinBounds") << QQuickTapHandler::DragWithinBounds << 0 << 2; +} + void tst_qquickdeliveryagent::tapHandlerDoesntOverrideSubsceneGrabber() // QTBUG-94012 { + QFETCH(QQuickTapHandler::GesturePolicy, gesturePolicy); + QFETCH(int, expectedTaps); + QFETCH(int, expectedCancels); + QQuickView window; #ifdef DISABLE_HOVER_IN_IRRELEVANT_TESTS QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->frameSynchronousHoverEnabled = false; @@ -338,19 +358,47 @@ void tst_qquickdeliveryagent::tapHandlerDoesntOverrideSubsceneGrabber() // QTBUG // add a TapHandler to it QQuickTapHandler tapHandler(&subscene); + tapHandler.setGesturePolicy(gesturePolicy); QSignalSpy clickSpy(&tapHandler, &QQuickTapHandler::tapped); + QSignalSpy cancelSpy(&tapHandler, &QQuickTapHandler::canceled); window.show(); QVERIFY(QTest::qWaitForWindowExposed(&window)); int cursorPos = textEdit->property("cursorPosition").toInt(); // Click on the middle of the subscene to the right (texture cloned from the left). - // TapHandler takes a passive grab on press; TextEdit takes the exclusive grab; - // and TapHandler does not emit tapped, because of the non-filtering exclusive grabber. + // TapHandler takes whichever type of grab on press; TextEdit takes the exclusive grab; + // TapHandler either gets tapped if it has passive grab, or gets its exclusive grab cancelled. QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, clickPos); qCDebug(lcTests) << "clicking subscene TextEdit set cursorPos to" << cursorPos; - QVERIFY(textEdit->property("cursorPosition").toInt() > cursorPos); - QCOMPARE(clickSpy.count(), 0); // doesn't tap + QVERIFY(textEdit->property("cursorPosition").toInt() > cursorPos); // TextEdit reacts regardless + QCOMPARE(clickSpy.size(), expectedTaps); + QCOMPARE(cancelSpy.size(), expectedCancels); +} + +void tst_qquickdeliveryagent::undoDelegationWhenSubsceneFocusCleared() // QTBUG-105192 +{ + QQuickView window; +#ifdef DISABLE_HOVER_IN_IRRELEVANT_TESTS + QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->frameSynchronousHoverEnabled = false; +#endif + QVERIFY(QQuickTest::initView(window, testFileUrl("listViewDelegate.qml"))); + QQuickListView *listView = window.rootObject()->findChild<QQuickListView*>(); + QVERIFY(listView); + + // put the ListView into a SubsceneRootItem + SubsceneRootItem subscene(listView, listView->boundingRect(), window.rootObject()); + + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + // populate a delegate in ListView + listView->setModel(1); + QQuickItem *delegate = nullptr; + QTRY_VERIFY(QQuickVisualTestUtils::findViewDelegateItem(listView, 0, delegate)); + QCOMPARE(QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->activeFocusItem, delegate); + delete listView; + QCOMPARE_NE(QQuickWindowPrivate::get(&window)->deliveryAgentPrivate()->activeFocusItem, delegate); } void tst_qquickdeliveryagent::touchCompression() diff --git a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp index 04d2784f20..c35f31b8f2 100644 --- a/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp +++ b/tests/auto/quick/qquickdesignersupport/tst_qquickdesignersupport.cpp @@ -344,7 +344,7 @@ void tst_qquickdesignersupport::basicStates() QVERIFY(stateGroup); - QCOMPARE(stateGroup->states().count(), 2 ); + QCOMPARE(stateGroup->states().size(), 2 ); QQuickState *state01 = stateGroup->states().first(); QQuickState *state02 = stateGroup->states().last(); @@ -390,7 +390,7 @@ void tst_qquickdesignersupport::statesPropertyChanges() QVERIFY(stateGroup); - QCOMPARE(stateGroup->states().count(), 2 ); + QCOMPARE(stateGroup->states().size(), 2 ); QQuickState *state01 = stateGroup->states().first(); QQuickState *state02 = stateGroup->states().last(); @@ -409,7 +409,7 @@ void tst_qquickdesignersupport::statesPropertyChanges() QCOMPARE(state01->operationCount(), 1); - QCOMPARE(statePrivate01->operations.count(), 1); + QCOMPARE(statePrivate01->operations.size(), 1); QQuickStateOperation *propertyChange = statePrivate01->operations.at(0).data(); @@ -444,7 +444,7 @@ void tst_qquickdesignersupport::statesPropertyChanges() QCOMPARE(rootItem, QQuickDesignerSupportPropertyChanges::targetObject(newPropertyChange)); QCOMPARE(state01->operationCount(), 2); - QCOMPARE(statePrivate01->operations.count(), 2); + QCOMPARE(statePrivate01->operations.size(), 2); QCOMPARE(QQuickDesignerSupportPropertyChanges::stateObject(newPropertyChange), state01); diff --git a/tests/auto/quick/qquickdroparea/data/ignoreRetriggerEvent.qml b/tests/auto/quick/qquickdroparea/data/ignoreRetriggerEvent.qml new file mode 100644 index 0000000000..af25a04ee7 --- /dev/null +++ b/tests/auto/quick/qquickdroparea/data/ignoreRetriggerEvent.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +DropArea { + property int enterEvents: 0 + property int exitEvents: 0 + width: 100; height: 100 + objectName: "dropArea" + onEntered: function (drag) { ++enterEvents; drag.accepted = false } + onExited: {++exitEvents} + Item { + objectName: "dragItem" + x: 50; y: 50 + width: 10; height: 10 + } +} diff --git a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp index 7d01207e58..fb036b6fad 100644 --- a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp +++ b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp @@ -45,6 +45,9 @@ public: private slots: void containsDrag_internal(); void containsDrag_external(); + + void ignoreRetriggerEvent(); + void keys_internal(); void keys_external(); void source_internal(); @@ -807,6 +810,32 @@ void tst_QQuickDropArea::competingDrags() QCOMPARE(evaluate<QString>(dropArea1, "statuslol"), QStringLiteral("parent")); } +void tst_QQuickDropArea::ignoreRetriggerEvent() +{ + QQuickView window; + QByteArray errorMessage; + QVERIFY2(QQuickTest::initView(window, testFileUrl("ignoreRetriggerEvent.qml"), true, &errorMessage), errorMessage.constData()); + + QQuickItem *dropArea = window.rootObject(); + QVERIFY(dropArea); + QQuickItem *dragItem = dropArea->findChild<QQuickItem *>("dragItem"); + QVERIFY(dragItem); + + evaluate<void>(dragItem, "Drag.active = true"); + // Drag the item within the drop area + dragItem->setPosition(QPointF(25, 25)); + QCoreApplication::processEvents(); + dragItem->setPosition(QPointF(50, 50)); + QCoreApplication::processEvents(); + dragItem->setPosition(QPointF(75, 75)); + QCoreApplication::processEvents(); + + QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); + QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); + QCOMPARE(evaluate<int>(dropArea, "exitEvents"), 0); +} + + void tst_QQuickDropArea::simultaneousDrags() { QQuickWindow window; diff --git a/tests/auto/quick/qquickflickable/data/contentPosWhileDragging.qml b/tests/auto/quick/qquickflickable/data/contentPosWhileDragging.qml new file mode 100644 index 0000000000..b42fbc1adb --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/contentPosWhileDragging.qml @@ -0,0 +1,24 @@ +import QtQuick +import QtQuick.Shapes +import QtQuick.Controls + +Item { + id: root + width: 500 + height: 500 + Flickable { + anchors.centerIn: parent + width: 100 + height: 100 + clip: true + contentWidth: content.width + contentHeight: content.height + Rectangle { + id: content + width: 320 + height: width + color: "#41cd52" + radius: width/2 + } + } +} diff --git a/tests/auto/quick/qquickflickable/data/flickableWithTapHandler.qml b/tests/auto/quick/qquickflickable/data/flickableWithTapHandler.qml new file mode 100644 index 0000000000..91b81059ab --- /dev/null +++ b/tests/auto/quick/qquickflickable/data/flickableWithTapHandler.qml @@ -0,0 +1,24 @@ +import QtQuick + +Item { + width: 300 + height: 300 + + Flickable { + anchors.fill: parent + anchors.topMargin: 100 + contentWidth: 1000 + contentHeight: 1000 + + Rectangle { + objectName: "childItem" + x: 20 + y: 50 + width: 20 + height: 20 + color: "red" + TapHandler { + } + } + } +} diff --git a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp index 1e8d162d03..7d5c113e87 100644 --- a/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp +++ b/tests/auto/quick/qquickflickable/tst_qquickflickable.cpp @@ -1,11 +1,13 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include <qtest.h> + +#include <QtTest/QtTest> #include <QtTest/QSignalSpy> +#include <QtQuick/qquickview.h> +#include <QtQuickTest/QtQuickTest> #include <QtGui/QStyleHints> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> -#include <QtQuick/qquickview.h> #include <private/qquickflickable_p.h> #include <private/qquickflickable_p_p.h> #include <private/qquickmousearea_p.h> @@ -71,7 +73,7 @@ public: protected: void touchEvent(QTouchEvent *ev) override { - QCOMPARE(ev->points().count(), 1); + QCOMPARE(ev->points().size(), 1); auto touchpoint = ev->points().first(); switch (touchpoint.state()) { case QEventPoint::State::Pressed: @@ -180,6 +182,7 @@ private slots: void movingAndDragging_data(); void flickOnRelease(); void pressWhileFlicking(); + void dragWhileFlicking(); void disabled(); void flickVelocity(); void margins(); @@ -214,8 +217,13 @@ private slots: void receiveTapOutsideContentItem(); void flickWhenRotated_data(); void flickWhenRotated(); + void flickAndReleaseOutsideBounds(); void scrollingWithFractionalExtentSize_data(); void scrollingWithFractionalExtentSize(); + void setContentPositionWhileDragging_data(); + void setContentPositionWhileDragging(); + void coalescedMove(); + void onlyOneMove(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -346,27 +354,27 @@ void tst_qquickflickable::boundsBehavior() flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragAndOvershootBounds); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setBoundsBehavior(QQuickFlickable::DragAndOvershootBounds); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::DragOverBounds); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); flickable->setBoundsBehavior(QQuickFlickable::DragOverBounds); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::StopAtBounds); - QCOMPARE(spy.count(),3); + QCOMPARE(spy.size(),3); flickable->setBoundsBehavior(QQuickFlickable::StopAtBounds); - QCOMPARE(spy.count(),3); + QCOMPARE(spy.size(),3); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); QCOMPARE(flickable->boundsBehavior(), QQuickFlickable::OvershootBounds); - QCOMPARE(spy.count(),4); + QCOMPARE(spy.size(),4); flickable->setBoundsBehavior(QQuickFlickable::OvershootBounds); - QCOMPARE(spy.count(),4); + QCOMPARE(spy.size(),4); delete flickable; } @@ -399,23 +407,23 @@ void tst_qquickflickable::rebound() flick(window.data(), QPoint(20,20), QPoint(120,120), 200); QTRY_COMPARE(window->rootObject()->property("transitionsStarted").toInt(), 2); - QCOMPARE(hMoveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), 1); - QCOMPARE(movementStartedSpy.count(), 1); - QCOMPARE(movementEndedSpy.count(), 0); + QCOMPARE(hMoveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), 1); + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 0); QVERIFY(rebound->running()); QTRY_VERIFY(!flickable->isMoving()); QCOMPARE(flickable->contentX(), 0.0); QCOMPARE(flickable->contentY(), 0.0); - QCOMPARE(hMoveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), 2); - QCOMPARE(movementStartedSpy.count(), 1); - QCOMPARE(movementEndedSpy.count(), 1); + QCOMPARE(hMoveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), 2); + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 1); QCOMPARE(window->rootObject()->property("transitionsStarted").toInt(), 2); QVERIFY(!rebound->running()); - QCOMPARE(reboundSpy.count(), 2); + QCOMPARE(reboundSpy.size(), 2); hMoveSpy.clear(); vMoveSpy.clear(); @@ -431,19 +439,19 @@ void tst_qquickflickable::rebound() QVERIFY(flickable->isMoving()); QTRY_VERIFY(window->rootObject()->property("transitionsStarted").toInt() >= 1); - QCOMPARE(hMoveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), 1); - QCOMPARE(movementStartedSpy.count(), 1); + QCOMPARE(hMoveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), 1); + QCOMPARE(movementStartedSpy.size(), 1); QTRY_VERIFY(!flickable->isMoving()); QCOMPARE(flickable->contentX(), 0.0); // moving started/stopped signals should only have been emitted once, // and when they are, all transitions should have finished - QCOMPARE(hMoveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), 2); - QCOMPARE(movementStartedSpy.count(), 1); - QCOMPARE(movementEndedSpy.count(), 1); + QCOMPARE(hMoveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), 2); + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 1); hMoveSpy.clear(); vMoveSpy.clear(); @@ -458,16 +466,16 @@ void tst_qquickflickable::rebound() flick(window.data(), QPoint(20,20), QPoint(120,120), 200); QCOMPARE(window->rootObject()->property("transitionsStarted").toInt(), 0); - QCOMPARE(hMoveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), 1); - QCOMPARE(movementStartedSpy.count(), 1); - QCOMPARE(movementEndedSpy.count(), 0); + QCOMPARE(hMoveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), 1); + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 0); QTRY_VERIFY(!flickable->isMoving()); - QCOMPARE(hMoveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), 2); - QCOMPARE(movementStartedSpy.count(), 1); - QCOMPARE(movementEndedSpy.count(), 1); + QCOMPARE(hMoveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), 2); + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 1); QCOMPARE(window->rootObject()->property("transitionsStarted").toInt(), 0); } @@ -484,9 +492,9 @@ void tst_qquickflickable::maximumFlickVelocity() flickable->setMaximumFlickVelocity(2.0); QCOMPARE(flickable->maximumFlickVelocity(), 2.0); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setMaximumFlickVelocity(2.0); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); delete flickable; } @@ -504,9 +512,9 @@ void tst_qquickflickable::flickDeceleration() flickable->setFlickDeceleration(2.0); QCOMPARE(flickable->flickDeceleration(), 2.0); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setFlickDeceleration(2.0); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); delete flickable; } @@ -530,9 +538,9 @@ void tst_qquickflickable::pressDelay() flickable->setPressDelay(200); QCOMPARE(flickable->pressDelay(), 200); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setPressDelay(200); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); QQuickItem *mouseArea = window->rootObject()->findChild<QQuickItem*>("mouseArea"); QSignalSpy clickedSpy(mouseArea, SIGNAL(clicked(QQuickMouseEvent*))); @@ -545,11 +553,11 @@ void tst_qquickflickable::pressDelay() // But, it should occur eventually QTRY_VERIFY(mouseArea->property("pressed").toBool()); - QCOMPARE(clickedSpy.count(),0); + QCOMPARE(clickedSpy.size(),0); // On release the clicked signal should be emitted QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(150, 150)); - QCOMPARE(clickedSpy.count(),1); + QCOMPARE(clickedSpy.size(),1); // Press and release position should match QCOMPARE(flickable->property("pressX").toReal(), flickable->property("releaseX").toReal()); @@ -563,11 +571,11 @@ void tst_qquickflickable::pressDelay() // The press should not occur immediately QVERIFY(!mouseArea->property("pressed").toBool()); - QCOMPARE(clickedSpy.count(),0); + QCOMPARE(clickedSpy.size(),0); // On release the press, release and clicked signal should be emitted QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(180, 180)); - QCOMPARE(clickedSpy.count(),1); + QCOMPARE(clickedSpy.size(),1); // Press and release position should match QCOMPARE(flickable->property("pressX").toReal(), flickable->property("releaseX").toReal()); @@ -588,7 +596,7 @@ void tst_qquickflickable::pressDelay() // On release the clicked signal should *not* be emitted QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(150, 190)); - QCOMPARE(clickedSpy.count(),1); + QCOMPARE(clickedSpy.size(),1); } // QTBUG-17361 @@ -772,19 +780,19 @@ void tst_qquickflickable::flickableDirection() flickable->setFlickableDirection(QQuickFlickable::HorizontalAndVerticalFlick); QCOMPARE(flickable->flickableDirection(), QQuickFlickable::HorizontalAndVerticalFlick); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); flickable->setFlickableDirection(QQuickFlickable::AutoFlickDirection); QCOMPARE(flickable->flickableDirection(), QQuickFlickable::AutoFlickDirection); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); flickable->setFlickableDirection(QQuickFlickable::HorizontalFlick); QCOMPARE(flickable->flickableDirection(), QQuickFlickable::HorizontalFlick); - QCOMPARE(spy.count(),3); + QCOMPARE(spy.size(),3); flickable->setFlickableDirection(QQuickFlickable::HorizontalFlick); QCOMPARE(flickable->flickableDirection(), QQuickFlickable::HorizontalFlick); - QCOMPARE(spy.count(),3); + QCOMPARE(spy.size(),3); delete flickable; } @@ -857,7 +865,7 @@ void tst_qquickflickable::returnToBounds() QTRY_COMPARE(obj->contentY(), 0.); QVERIFY(!rebound->running()); - QCOMPARE(reboundSpy.count(), setRebound ? 2 : 0); + QCOMPARE(reboundSpy.size(), setRebound ? 2 : 0); } void tst_qquickflickable::returnToBounds_data() @@ -895,7 +903,7 @@ void tst_qquickflickable::wheel() QTRY_VERIFY(flick->contentY() > 0); QCOMPARE(flick->contentX(), qreal(0)); - QTRY_COMPARE(moveEndSpy.count(), 1); + QTRY_COMPARE(moveEndSpy.size(), 1); QCOMPARE(fp->velocityTimeline.isActive(), false); QCOMPARE(fp->timeline.isActive(), false); QTest::qWait(50); // make sure that onContentYChanged won't sneak in again @@ -920,7 +928,7 @@ void tst_qquickflickable::wheel() QTRY_VERIFY(flick->contentX() > 0); QCOMPARE(flick->contentY(), qreal(0)); - QTRY_COMPARE(moveEndSpy.count(), 2); + QTRY_COMPARE(moveEndSpy.size(), 2); QCOMPARE(fp->velocityTimeline.isActive(), false); QCOMPARE(fp->timeline.isActive(), false); QTest::qWait(50); // make sure that onContentXChanged won't sneak in again @@ -974,7 +982,7 @@ void tst_qquickflickable::trackpad() QGuiApplication::sendEvent(window.data(), &event); } - QTRY_COMPARE(moveEndSpy.count(), 1); // QTBUG-55871 + QTRY_COMPARE(moveEndSpy.size(), 1); // QTBUG-55871 QCOMPARE(flick->property("movementsAfterEnd").value<int>(), 0); // QTBUG-55886 } @@ -1011,7 +1019,7 @@ void tst_qquickflickable::nestedTrackpad() event.setTimestamp(timestamp++); QGuiApplication::sendEvent(&window, &event); } - QTRY_COMPARE(innerMoveEndSpy.count(), 1); + QTRY_COMPARE(innerMoveEndSpy.size(), 1); innerFlickable->setContentX(0); QCOMPARE(innerFlickable->contentX(), qreal(0)); @@ -1035,7 +1043,7 @@ void tst_qquickflickable::nestedTrackpad() event.setTimestamp(timestamp++); QGuiApplication::sendEvent(&window, &event); } - QTRY_COMPARE(outerMoveEndSpy.count(), 1); + QTRY_COMPARE(outerMoveEndSpy.size(), 1); } void tst_qquickflickable::movingAndFlicking_data() @@ -1107,15 +1115,15 @@ void tst_qquickflickable::movingAndFlicking() QCOMPARE(flickable->property("movingInContentX").value<bool>(), true); QCOMPARE(flickable->property("movingInContentY").value<bool>(), true); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 1 : 0); - QCOMPARE(flickSpy.count(), 1); - QCOMPARE(vFlickSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hFlickSpy.count(), horizontalEnabled ? 1 : 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 1 : 0); + QCOMPARE(flickSpy.size(), 1); + QCOMPARE(vFlickSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hFlickSpy.size(), horizontalEnabled ? 1 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(flickStartSpy.count(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(flickStartSpy.size(), 1); // wait for any motion to end QTRY_VERIFY(!flickable->isMoving()); @@ -1126,17 +1134,17 @@ void tst_qquickflickable::movingAndFlicking() QVERIFY(!flickable->isFlickingHorizontally()); QVERIFY(!flickable->isFlickingVertically()); - QCOMPARE(moveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 2 : 0); - QCOMPARE(flickSpy.count(), 2); - QCOMPARE(vFlickSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hFlickSpy.count(), horizontalEnabled ? 2 : 0); + QCOMPARE(moveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 2 : 0); + QCOMPARE(flickSpy.size(), 2); + QCOMPARE(vFlickSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hFlickSpy.size(), horizontalEnabled ? 2 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 1); - QCOMPARE(flickStartSpy.count(), 1); - QCOMPARE(flickEndSpy.count(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 1); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 1); // Stop on a full pixel after user interaction if (verticalEnabled) @@ -1163,17 +1171,17 @@ void tst_qquickflickable::movingAndFlicking() QCOMPARE(flickable->isFlickingHorizontally(), horizontalEnabled); QCOMPARE(flickable->isFlickingVertically(), verticalEnabled); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 1 : 0); - QCOMPARE(flickSpy.count(), 1); - QCOMPARE(vFlickSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hFlickSpy.count(), horizontalEnabled ? 1 : 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 1 : 0); + QCOMPARE(flickSpy.size(), 1); + QCOMPARE(vFlickSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hFlickSpy.size(), horizontalEnabled ? 1 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 0); - QCOMPARE(flickStartSpy.count(), 1); - QCOMPARE(flickEndSpy.count(), 0); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 0); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 0); // wait for any motion to end QTRY_VERIFY(!flickable->isMoving()); @@ -1184,17 +1192,17 @@ void tst_qquickflickable::movingAndFlicking() QVERIFY(!flickable->isFlickingHorizontally()); QVERIFY(!flickable->isFlickingVertically()); - QCOMPARE(moveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 2 : 0); - QCOMPARE(flickSpy.count(), 2); - QCOMPARE(vFlickSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hFlickSpy.count(), horizontalEnabled ? 2 : 0); + QCOMPARE(moveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 2 : 0); + QCOMPARE(flickSpy.size(), 2); + QCOMPARE(vFlickSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hFlickSpy.size(), horizontalEnabled ? 2 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 1); - QCOMPARE(flickStartSpy.count(), 1); - QCOMPARE(flickEndSpy.count(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 1); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 1); QCOMPARE(flickable->contentX(), 0.0); QCOMPARE(flickable->contentY(), 0.0); @@ -1275,26 +1283,26 @@ void tst_qquickflickable::movingAndDragging() QCOMPARE(flickable->property("draggingInContentX").value<bool>(), true); QCOMPARE(flickable->property("draggingInContentY").value<bool>(), true); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 1 : 0); - QCOMPARE(dragSpy.count(), 1); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 1 : 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 1 : 0); + QCOMPARE(dragSpy.size(), 1); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 1 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(dragStartSpy.count(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(dragStartSpy.size(), 1); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, moveFrom + moveByWithoutSnapBack*3); QVERIFY(!flickable->isDragging()); QVERIFY(!flickable->isDraggingHorizontally()); QVERIFY(!flickable->isDraggingVertically()); - QCOMPARE(dragSpy.count(), 2); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 2 : 0); - QCOMPARE(dragStartSpy.count(), 1); - QCOMPARE(dragEndSpy.count(), 1); + QCOMPARE(dragSpy.size(), 2); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 2 : 0); + QCOMPARE(dragStartSpy.size(), 1); + QCOMPARE(dragEndSpy.size(), 1); // Don't test whether moving finished because a flick could occur // wait for any motion to end @@ -1306,17 +1314,17 @@ void tst_qquickflickable::movingAndDragging() QVERIFY(!flickable->isDraggingHorizontally()); QVERIFY(!flickable->isDraggingVertically()); - QCOMPARE(dragSpy.count(), 2); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 2 : 0); - QCOMPARE(moveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 2 : 0); + QCOMPARE(dragSpy.size(), 2); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 2 : 0); + QCOMPARE(moveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 2 : 0); - QCOMPARE(dragStartSpy.count(), 1); - QCOMPARE(dragEndSpy.count(), 1); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 1); + QCOMPARE(dragStartSpy.size(), 1); + QCOMPARE(dragEndSpy.size(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 1); // Stop on a full pixel after user interaction if (verticalEnabled) @@ -1346,17 +1354,17 @@ void tst_qquickflickable::movingAndDragging() QCOMPARE(flickable->isDraggingHorizontally(), horizontalEnabled); QCOMPARE(flickable->isDraggingVertically(), verticalEnabled); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 1 : 0); - QCOMPARE(dragSpy.count(), 1); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 1 : 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 1 : 0); + QCOMPARE(dragSpy.size(), 1); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 1 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 0); - QCOMPARE(dragStartSpy.count(), 1); - QCOMPARE(dragEndSpy.count(), 0); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 0); + QCOMPARE(dragStartSpy.size(), 1); + QCOMPARE(dragEndSpy.size(), 0); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, moveFrom + moveByWithSnapBack*3); @@ -1368,15 +1376,15 @@ void tst_qquickflickable::movingAndDragging() QVERIFY(!flickable->isDraggingHorizontally()); QVERIFY(!flickable->isDraggingVertically()); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 1 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 1 : 0); - QCOMPARE(dragSpy.count(), 2); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 2 : 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 1 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 1 : 0); + QCOMPARE(dragSpy.size(), 2); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 2 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 0); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 0); // wait for any motion to end QTRY_VERIFY(!flickable->isMoving()); @@ -1387,17 +1395,17 @@ void tst_qquickflickable::movingAndDragging() QVERIFY(!flickable->isDraggingHorizontally()); QVERIFY(!flickable->isDraggingVertically()); - QCOMPARE(moveSpy.count(), 2); - QCOMPARE(vMoveSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hMoveSpy.count(), horizontalEnabled ? 2 : 0); - QCOMPARE(dragSpy.count(), 2); - QCOMPARE(vDragSpy.count(), verticalEnabled ? 2 : 0); - QCOMPARE(hDragSpy.count(), horizontalEnabled ? 2 : 0); + QCOMPARE(moveSpy.size(), 2); + QCOMPARE(vMoveSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hMoveSpy.size(), horizontalEnabled ? 2 : 0); + QCOMPARE(dragSpy.size(), 2); + QCOMPARE(vDragSpy.size(), verticalEnabled ? 2 : 0); + QCOMPARE(hDragSpy.size(), horizontalEnabled ? 2 : 0); - QCOMPARE(moveStartSpy.count(), 1); - QCOMPARE(moveEndSpy.count(), 1); - QCOMPARE(dragStartSpy.count(), 1); - QCOMPARE(dragEndSpy.count(), 1); + QCOMPARE(moveStartSpy.size(), 1); + QCOMPARE(moveEndSpy.size(), 1); + QCOMPARE(dragStartSpy.size(), 1); + QCOMPARE(dragEndSpy.size(), 1); QCOMPARE(flickable->contentX(), 0.0); QCOMPARE(flickable->contentY(), 0.0); @@ -1425,7 +1433,7 @@ void tst_qquickflickable::flickOnRelease() QTest::mouseMove(window.data(), QPoint(50, 10), 10); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(50, 10), 10); - QCOMPARE(vFlickSpy.count(), 1); + QCOMPARE(vFlickSpy.size(), 1); // wait for any motion to end QTRY_VERIFY(!flickable->isMoving()); @@ -1454,6 +1462,8 @@ void tst_qquickflickable::pressWhileFlicking() QSignalSpy hFlickSpy(flickable, SIGNAL(flickingHorizontallyChanged())); QSignalSpy vFlickSpy(flickable, SIGNAL(flickingVerticallyChanged())); QSignalSpy flickSpy(flickable, SIGNAL(flickingChanged())); + QSignalSpy flickStartSpy(flickable, &QQuickFlickable::flickStarted); + QSignalSpy flickEndSpy(flickable, &QQuickFlickable::flickEnded); // flick then press while it is still moving // flicking == false, moving == true; @@ -1465,12 +1475,14 @@ void tst_qquickflickable::pressWhileFlicking() QVERIFY(flickable->isMoving()); QVERIFY(flickable->isMovingVertically()); QVERIFY(!flickable->isMovingHorizontally()); - QCOMPARE(vMoveSpy.count(), 1); - QCOMPARE(hMoveSpy.count(), 0); - QCOMPARE(moveSpy.count(), 1); - QCOMPARE(vFlickSpy.count(), 1); - QCOMPARE(hFlickSpy.count(), 0); - QCOMPARE(flickSpy.count(), 1); + QCOMPARE(vMoveSpy.size(), 1); + QCOMPARE(hMoveSpy.size(), 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vFlickSpy.size(), 1); + QCOMPARE(hFlickSpy.size(), 0); + QCOMPARE(flickSpy.size(), 1); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 0); QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(20, 50)); QTRY_VERIFY(!flickable->isFlicking()); @@ -1483,6 +1495,76 @@ void tst_qquickflickable::pressWhileFlicking() QVERIFY(!flickable->isFlickingVertically()); QTRY_VERIFY(!flickable->isMoving()); QVERIFY(!flickable->isMovingVertically()); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 1); + // Stop on a full pixel after user interaction + QCOMPARE(flickable->contentX(), (qreal)qRound(flickable->contentX())); +} + +void tst_qquickflickable::dragWhileFlicking() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("flickable03.qml"))); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window.rootObject()); + QVERIFY(flickable != nullptr); + + QSignalSpy vMoveSpy(flickable, &QQuickFlickable::movingVerticallyChanged); + QSignalSpy hMoveSpy(flickable, &QQuickFlickable::movingHorizontallyChanged); + QSignalSpy moveSpy(flickable, &QQuickFlickable::movingChanged); + QSignalSpy hFlickSpy(flickable, &QQuickFlickable::flickingHorizontallyChanged); + QSignalSpy vFlickSpy(flickable, &QQuickFlickable::flickingVerticallyChanged); + QSignalSpy flickSpy(flickable, &QQuickFlickable::flickingChanged); + QSignalSpy flickStartSpy(flickable, &QQuickFlickable::flickStarted); + QSignalSpy flickEndSpy(flickable, &QQuickFlickable::flickEnded); + + // flick first, let it keep moving + flick(&window, QPoint(20,190), QPoint(20, 50), 200); + QVERIFY(flickable->verticalVelocity() > 0.0); + QTRY_VERIFY(flickable->isFlicking()); + QVERIFY(flickable->isFlickingVertically()); + QCOMPARE(flickable->isFlickingHorizontally(), false); + QVERIFY(flickable->isMoving()); + QVERIFY(flickable->isMovingVertically()); + QCOMPARE(flickable->isMovingHorizontally(), false); + QCOMPARE(vMoveSpy.size(), 1); + QCOMPARE(hMoveSpy.size(), 0); + QCOMPARE(moveSpy.size(), 1); + QCOMPARE(vFlickSpy.size(), 1); + QCOMPARE(hFlickSpy.size(), 0); + QCOMPARE(flickSpy.size(), 1); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 0); + + // then drag slowly while it's still flicking and moving + const int dragStepDelay = 100; + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(20, 70)); + QTRY_COMPARE(flickable->isFlicking(), false); + QCOMPARE(flickable->isFlickingVertically(), false); + QVERIFY(flickable->isMoving()); + QVERIFY(flickable->isMovingVertically()); + + for (int y = 70; y > 50; y -= 5) { + QTest::mouseMove(&window, QPoint(20, y), dragStepDelay); + QVERIFY(flickable->isMoving()); + QVERIFY(flickable->isMovingVertically()); + // Flickable's timeline is real-time, so spoofing timestamps isn't enough + QTest::qWait(dragStepDelay); + } + + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(20, 50), dragStepDelay); + + QCOMPARE(flickable->isFlicking(), false); + QCOMPARE(flickable->isFlickingVertically(), false); + QTRY_COMPARE(flickable->isMoving(), false); + QCOMPARE(flickable->isMovingVertically(), false); + QCOMPARE(flickStartSpy.size(), 1); + QCOMPARE(flickEndSpy.size(), 1); + QCOMPARE(vMoveSpy.size(), 2); + QCOMPARE(hMoveSpy.size(), 0); + QCOMPARE(moveSpy.size(), 2); + QCOMPARE(vFlickSpy.size(), 2); + QCOMPARE(hFlickSpy.size(), 0); // Stop on a full pixel after user interaction QCOMPARE(flickable->contentX(), (qreal)qRound(flickable->contentX())); } @@ -2026,10 +2108,10 @@ void tst_qquickflickable::stopAtBounds() else QCOMPARE(transpose ? flickable->isAtYBeginning() : flickable->isAtXBeginning(), false); - QCOMPARE(atXBeginningChangedSpy.count(), (!transpose && !invert) ? 1 : 0); - QCOMPARE(atYBeginningChangedSpy.count(), ( transpose && !invert) ? 1 : 0); - QCOMPARE(atXEndChangedSpy.count(), (!transpose && invert) ? 1 : 0); - QCOMPARE(atYEndChangedSpy.count(), ( transpose && invert) ? 1 : 0); + QCOMPARE(atXBeginningChangedSpy.size(), (!transpose && !invert) ? 1 : 0); + QCOMPARE(atYBeginningChangedSpy.size(), ( transpose && !invert) ? 1 : 0); + QCOMPARE(atXEndChangedSpy.size(), (!transpose && invert) ? 1 : 0); + QCOMPARE(atYEndChangedSpy.size(), ( transpose && invert) ? 1 : 0); // Drag away from the aligned boundary again. // None of the mouse movements will position the view at the boundary exactly, @@ -2063,7 +2145,7 @@ void tst_qquickflickable::stopAtBounds() else flick(&view, QPoint(120,120), QPoint(20,20), 100); - QVERIFY(flickSignal.count() > 0); + QVERIFY(flickSignal.size() > 0); if (transpose) { if (invert) QTRY_COMPARE(flickable->isAtYBeginning(), true); @@ -2234,22 +2316,22 @@ void tst_qquickflickable::contentSize() flickable.setWidth(100); QCOMPARE(flickable.width(), qreal(100)); QCOMPARE(flickable.contentWidth(), qreal(-1.0)); - QCOMPARE(cwspy.count(), 0); + QCOMPARE(cwspy.size(), 0); flickable.setContentWidth(10); QCOMPARE(flickable.width(), qreal(100)); QCOMPARE(flickable.contentWidth(), qreal(10)); - QCOMPARE(cwspy.count(), 1); + QCOMPARE(cwspy.size(), 1); flickable.setHeight(100); QCOMPARE(flickable.height(), qreal(100)); QCOMPARE(flickable.contentHeight(), qreal(-1.0)); - QCOMPARE(chspy.count(), 0); + QCOMPARE(chspy.size(), 0); flickable.setContentHeight(10); QCOMPARE(flickable.height(), qreal(100)); QCOMPARE(flickable.contentHeight(), qreal(10)); - QCOMPARE(chspy.count(), 1); + QCOMPARE(chspy.size(), 1); } // QTBUG-53726 @@ -2743,13 +2825,13 @@ void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909 QTest::mouseMove(&view, p1, 50); } QVERIFY(flickable->isDragging()); - QCOMPARE(dragSpy.count(), 1); + QCOMPARE(dragSpy.size(), 1); // Press other button too, then release left button: dragging changes to false QTest::mousePress(&view, otherButton); QTest::mouseRelease(&view, Qt::LeftButton); QTRY_COMPARE(flickable->isDragging(), false); - QCOMPARE(dragSpy.count(), 2); + QCOMPARE(dragSpy.size(), 2); // Drag further with the other button held: Flickable ignores it for (int i = 0; i < 8; ++i) { @@ -2757,11 +2839,11 @@ void tst_qquickflickable::ignoreNonLeftMouseButtons() // QTBUG-96909 QTest::mouseMove(&view, p1, 50); } QCOMPARE(flickable->isDragging(), false); - QCOMPARE(dragSpy.count(), 2); + QCOMPARE(dragSpy.size(), 2); // Release other button: nothing happens QTest::mouseRelease(&view, otherButton); - QCOMPARE(dragSpy.count(), 2); + QCOMPARE(dragSpy.size(), 2); } void tst_qquickflickable::ignoreNonLeftMouseButtons_data() @@ -2794,12 +2876,12 @@ void tst_qquickflickable::receiveTapOutsideContentItem() // Tap outside the content item in the top-left corner QTest::mouseClick(&window, Qt::LeftButton, {}, QPoint(5, 5)); - QCOMPARE(clickedSpy.count(), 1); + QCOMPARE(clickedSpy.size(), 1); // Tap outside the content item in the bottom-right corner const QPoint bottomRight(flickable.contentItem()->width() + 5, flickable.contentItem()->height() + 5); QTest::mouseClick(&window, Qt::LeftButton, {}, bottomRight); - QCOMPARE(clickedSpy.count(), 2); + QCOMPARE(clickedSpy.size(), 2); } void tst_qquickflickable::flickWhenRotated_data() @@ -2853,6 +2935,42 @@ void tst_qquickflickable::flickWhenRotated() // QTBUG-99639 QVERIFY(!flickable->isAtYBeginning()); } +void tst_qquickflickable::flickAndReleaseOutsideBounds() // QTBUG-104987 +{ + // Check that flicking works when the mouse release happens + // outside the bounds of the flickable (and the flick started on top + // of a TapHandler that has a passive grab). + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("flickableWithTapHandler.qml"))); + QQuickItem *rootItem = window.rootObject(); + QVERIFY(rootItem); + QQuickFlickable *flickable = rootItem->findChild<QQuickFlickable*>(); + QVERIFY(flickable); + QQuickItem *childItem = flickable->findChild<QQuickItem*>("childItem"); + QVERIFY(childItem); + + QVERIFY(flickable->isAtYBeginning()); + + // Startpoint is on top of the tapHandler, while the endpoint is outside the flickable + const QPointF startPos = childItem->mapToGlobal(QPoint(10, 10)); + const QPointF endPos = flickable->mapToGlobal(QPoint(10, -10)); + const QPoint globalStartPos = window.mapFromGlobal(startPos).toPoint(); + const QPoint globalEndPos = window.mapFromGlobal(endPos).toPoint(); + const qreal dragDistance = 20; + + // Note: here we need to initiate a flick using raw events, rather than + // flickable.flick(), since we're testing if the mouse events takes the + // correct path to starts a flick (among passive and exclusive grabbers, combined + // with childMouseEventFilter()). + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, globalStartPos); + QTest::mouseMove(&window, globalStartPos - QPoint(0, dragDistance / 2)); + QTest::mouseMove(&window, globalStartPos - QPoint(0, dragDistance)); + QTest::mouseMove(&window, globalEndPos); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, globalEndPos); + + // Ensure that the content item ends up being moved more than what we dragged + QTRY_VERIFY(flickable->contentY() > dragDistance * 2); +} void tst_qquickflickable::scrollingWithFractionalExtentSize_data() { @@ -2938,6 +3056,183 @@ void tst_qquickflickable::scrollingWithFractionalExtentSize() // QTBUG-101268 } } +void tst_qquickflickable::setContentPositionWhileDragging_data() +{ + QTest::addColumn<bool>("isHorizontal"); + QTest::addColumn<int>("newPos"); + QTest::addColumn<int>("newExtent"); + QTest::newRow("horizontal, setContentX") << true << 0 << -1; + QTest::newRow("vertical, setContentY") << false << 0 << -1; + QTest::newRow("horizontal, setContentWidth") << true << -1 << 200; + QTest::newRow("vertical, setContentHeight") << false << -1 << 200; +} + +void tst_qquickflickable::setContentPositionWhileDragging() // QTBUG-104966 +{ + QFETCH(bool, isHorizontal); + QFETCH(int, newPos); + QFETCH(int, newExtent); + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("contentPosWhileDragging.qml"))); + QQuickViewTestUtils::centerOnScreen(&window); + QVERIFY(window.isVisible()); + QQuickItem *rootItem = window.rootObject(); + QVERIFY(rootItem); + QQuickFlickable *flickable = rootItem->findChild<QQuickFlickable *>(); + QVERIFY(flickable); + + const auto contentPos = [flickable]() -> QPoint { + return QPoint(flickable->contentX(), flickable->contentY()); + }; + const qreal threshold = + qApp->styleHints()->startDragDistance() * flickable->parentItem()->scale(); + const QPoint thresholdPnt(qRound(threshold), qRound(threshold)); + const auto flickableCenterPos = flickable->mapToScene({flickable->width() / 2, flickable->height() / 2}).toPoint(); + + // Drag the mouse until we have surpassed the mouse drag threshold and a drag is initiated + // by checking for flickable->isDragging() + QPoint pos = flickableCenterPos; + QQuickViewTestUtils::moveAndPress(&window, pos); + int j = 1; + QVERIFY(!flickable->isDragging()); + while (!flickable->isDragging()) { + pos = flickableCenterPos - QPoint(j, j); + QTest::mouseMove(&window, pos); + j++; + } + + // Now we have entered the drag state + QVERIFY(flickable->isDragging()); + QCOMPARE(flickable->contentX(), 0); + QCOMPARE(flickable->contentY(), 0); + QVERIFY(flickable->width() > 0); + QVERIFY(flickable->height() > 0); + + + const int moveLength = 50; + const QPoint unitDelta(isHorizontal ? 1 : 0, isHorizontal ? 0 : 1); + const QPoint moveDelta = unitDelta * moveLength; + + pos -= 3*moveDelta; + QTest::mouseMove(&window, pos); + // Should be positive because we drag in the opposite direction + QCOMPARE(contentPos(), 3 * moveDelta); + QPoint expectedContentPos; + + // Set the content item position back to zero *while dragging* (!!) + if (newPos >= 0) { + if (isHorizontal) { + flickable->setContentX(newPos); + } else { + flickable->setContentY(newPos); + } + // Continue dragging + pos -= moveDelta; + expectedContentPos = moveDelta; + } else if (newExtent >= 0) { + // ...or reduce the content size be be less than current (contentX, contentY) position + // This forces the content item to move. + // contentY: 150 + // 320 - 150 = 170 pixels down to bottom + // Now reduce contentHeight to 200 + // since we are at the bottom, and the flickable is 100 pixels tall, contentY must land + // at newExtent - 100. + + if (isHorizontal) { + flickable->setContentWidth(newExtent); + } else { + flickable->setContentHeight(newExtent); + } + // Assumption is that the contentItem is aligned to the bottom of the flickable + // We therefore cannot scroll/flick it further down. Drag it up towards the top instead + // (by moving mouse down). + pos += moveDelta; + expectedContentPos = unitDelta * (newExtent - (isHorizontal ? flickable->width() : flickable->height())); + } + + QTest::mouseMove(&window, pos); + + // Make sure that the contentItem was only dragged the delta in mouse movement since the last + // setContentX/Y() call. + QCOMPARE(contentPos(), expectedContentPos); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, pos); + QVERIFY(!flickable->isDragging()); +} + +void tst_qquickflickable::coalescedMove() +{ + QQuickView *window = new QQuickView; + QScopedPointer<QQuickView> windowPtr(window); + windowPtr->setSource(testFileUrl("flickable03.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickVisualTestUtils::centerOnScreen(window); + QQuickVisualTestUtils::moveMouseAway(window); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(window->rootObject() != nullptr); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != nullptr); + + QSignalSpy movementStartedSpy(flickable, SIGNAL(movementStarted())); + QSignalSpy movementEndedSpy(flickable, SIGNAL(movementEnded())); + QSignalSpy flickStartedSpy(flickable, SIGNAL(flickStarted())); + QSignalSpy flickEndedSpy(flickable, SIGNAL(flickEnded())); + + QTest::touchEvent(window, touchDevice).press(0, {10, 10}).commit(); + + QTest::touchEvent(window, touchDevice).move(0, {10, 40}).commit(); + + QTest::touchEvent(window, touchDevice).move(0, {10, 100}).commit(); + + QTest::touchEvent(window, touchDevice).release(0, {10, 150}).commit(); + QQuickTouchUtils::flush(window); + + QTRY_VERIFY(!flickable->isMoving()); + + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 1); +} + +void tst_qquickflickable::onlyOneMove() +{ + QQuickView *window = new QQuickView; + QScopedPointer<QQuickView> windowPtr(window); + windowPtr->setSource(testFileUrl("flickable03.qml")); + QTRY_COMPARE(window->status(), QQuickView::Ready); + QQuickVisualTestUtils::centerOnScreen(window); + QQuickVisualTestUtils::moveMouseAway(window); + window->show(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(window->rootObject() != nullptr); + + QQuickFlickable *flickable = qobject_cast<QQuickFlickable*>(window->rootObject()); + QVERIFY(flickable != nullptr); + + QSignalSpy movementStartedSpy(flickable, SIGNAL(movementStarted())); + QSignalSpy movementEndedSpy(flickable, SIGNAL(movementEnded())); + QSignalSpy flickStartedSpy(flickable, SIGNAL(flickStarted())); + QSignalSpy flickEndedSpy(flickable, SIGNAL(flickEnded())); + + QTest::touchEvent(window, touchDevice).press(0, {10, 10}).commit(); + QQuickTouchUtils::flush(window); + + QTest::touchEvent(window, touchDevice).move(0, {10, 100}).commit(); + QQuickTouchUtils::flush(window); + + QTest::touchEvent(window, touchDevice).release(0, {10, 200}).commit(); + QQuickTouchUtils::flush(window); + + QTRY_VERIFY(!flickable->isMoving()); + + QCOMPARE(movementStartedSpy.size(), 1); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(movementEndedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 1); +} + QTEST_MAIN(tst_qquickflickable) #include "tst_qquickflickable.moc" diff --git a/tests/auto/quick/qquickflipable/data/flip-y-axis-flipable.qml b/tests/auto/quick/qquickflipable/data/flip-y-axis-flipable.qml new file mode 100644 index 0000000000..1b6a3f5018 --- /dev/null +++ b/tests/auto/quick/qquickflipable/data/flip-y-axis-flipable.qml @@ -0,0 +1,32 @@ +// Copyright (C) 2023 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Flipable { + id: flipable + + property real angle: 0 + width: 3840 // wider than 1024 * 2: part of it goes behind the camera while flipping + height: 2160 + + front: Rectangle { + width: parent.width + height: parent.height + color: "red" + anchors.centerIn: parent + } + back: Rectangle { + color: "yellow" + anchors.centerIn: parent + width: parent.width + height: parent.height + } + transform: Rotation { + id: rotation + origin.x: flipable.width / 2 + origin.y: flipable.height / 2 + axis.x: 0; axis.y: 1; axis.z: 0 + angle: flipable.angle + } +} diff --git a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp index c1eab29759..17b5bba9d5 100644 --- a/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp +++ b/tests/auto/quick/qquickflipable/tst_qquickflipable.cpp @@ -27,6 +27,9 @@ private slots: void QTBUG_9161_crash(); void QTBUG_8474_qgv_abort(); + void flipRotationAngle_data(); + void flipRotationAngle(); + private: QQmlEngine engine; }; @@ -112,6 +115,31 @@ void tst_qquickflipable::QTBUG_8474_qgv_abort() delete window; } +void tst_qquickflipable::flipRotationAngle_data() +{ + QTest::addColumn<int>("angle"); + QTest::addColumn<QQuickFlipable::Side>("side"); + + QTest::newRow("89") << 89 << QQuickFlipable::Front; + QTest::newRow("91") << 91 << QQuickFlipable::Back; + QTest::newRow("-89") << -89 << QQuickFlipable::Front; + QTest::newRow("-91") << -91 << QQuickFlipable::Back; +} + +void tst_qquickflipable::flipRotationAngle() // QTBUG-75954 +{ + QFETCH(int, angle); + QFETCH(QQuickFlipable::Side, side); + + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("flip-y-axis-flipable.qml")); + QQuickFlipable *obj = qobject_cast<QQuickFlipable*>(c.create()); + QVERIFY(obj != nullptr); + obj->setProperty("angle", angle); + QCOMPARE(obj->side(), side); + delete obj; +} + QTEST_MAIN(tst_qquickflipable) #include "tst_qquickflipable.moc" diff --git a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp index 3c9417fb1d..4dcbcc4884 100644 --- a/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp +++ b/tests/auto/quick/qquickfocusscope/tst_qquickfocusscope.cpp @@ -379,78 +379,78 @@ void tst_qquickfocusscope::forceActiveFocus() itemA1->forceActiveFocus(); QVERIFY(itemA1->hasActiveFocus()); QVERIFY(!rootObject->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); scopeA->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); itemA2->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); scopeA->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(itemA2->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 1); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); itemA1->forceActiveFocus(); QVERIFY(itemA1->hasActiveFocus()); QVERIFY(!scopeA->hasActiveFocus()); QVERIFY(!itemA2->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 2); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 2); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); // Then jump back and forth between branch 'a' and 'b' itemB1->forceActiveFocus(); QVERIFY(itemB1->hasActiveFocus()); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); scopeA->forceActiveFocus(); QVERIFY(!itemA1->hasActiveFocus()); QVERIFY(!itemB1->hasActiveFocus()); QVERIFY(scopeA->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 3); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 3); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); scopeB->forceActiveFocus(); QVERIFY(!scopeA->hasActiveFocus()); QVERIFY(!itemB1->hasActiveFocus()); QVERIFY(scopeB->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 4); - QCOMPARE(scopeBSpy.count(), 1); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 4); + QCOMPARE(scopeBSpy.size(), 1); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); itemA2->forceActiveFocus(); QVERIFY(!scopeB->hasActiveFocus()); QVERIFY(itemA2->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 5); - QCOMPARE(scopeBSpy.count(), 2); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 5); + QCOMPARE(scopeBSpy.size(), 2); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); itemB2->forceActiveFocus(); QVERIFY(!itemA2->hasActiveFocus()); QVERIFY(itemB2->hasActiveFocus()); - QCOMPARE(scopeASpy.count(), 6); - QCOMPARE(scopeBSpy.count(), 3); - QCOMPARE(rootSpy.count(), 0); - QCOMPARE(scopeSpy.count(), 1); + QCOMPARE(scopeASpy.size(), 6); + QCOMPARE(scopeBSpy.size(), 3); + QCOMPARE(rootSpy.size(), 0); + QCOMPARE(scopeSpy.size(), 1); delete view; } @@ -516,12 +516,12 @@ void tst_qquickfocusscope::canvasFocus() QCOMPARE(item2->hasFocus(), false); QCOMPARE(item2->hasActiveFocus(), false); - QCOMPARE(rootFocusSpy.count(), 1); - QCOMPARE(rootActiveFocusSpy.count(), 1); - QCOMPARE(scope1FocusSpy.count(), 0); - QCOMPARE(scope1ActiveFocusSpy.count(), 1); - QCOMPARE(item1FocusSpy.count(), 0); - QCOMPARE(item1ActiveFocusSpy.count(), 1); + QCOMPARE(rootFocusSpy.size(), 1); + QCOMPARE(rootActiveFocusSpy.size(), 1); + QCOMPARE(scope1FocusSpy.size(), 0); + QCOMPARE(scope1ActiveFocusSpy.size(), 1); + QCOMPARE(item1FocusSpy.size(), 0); + QCOMPARE(item1ActiveFocusSpy.size(), 1); // view->hide(); // seemingly doesn't remove focus, so have an another view steal it. @@ -537,12 +537,12 @@ void tst_qquickfocusscope::canvasFocus() QCOMPARE(item1->hasFocus(), true); QCOMPARE(item1->hasActiveFocus(), false); - QCOMPARE(rootFocusSpy.count(), 2); - QCOMPARE(rootActiveFocusSpy.count(), 2); - QCOMPARE(scope1FocusSpy.count(), 0); - QCOMPARE(scope1ActiveFocusSpy.count(), 2); - QCOMPARE(item1FocusSpy.count(), 0); - QCOMPARE(item1ActiveFocusSpy.count(), 2); + QCOMPARE(rootFocusSpy.size(), 2); + QCOMPARE(rootActiveFocusSpy.size(), 2); + QCOMPARE(scope1FocusSpy.size(), 0); + QCOMPARE(scope1ActiveFocusSpy.size(), 2); + QCOMPARE(item1FocusSpy.size(), 0); + QCOMPARE(item1ActiveFocusSpy.size(), 2); // window does not have focus, so item2 will not get active focus @@ -559,16 +559,16 @@ void tst_qquickfocusscope::canvasFocus() QCOMPARE(item2->hasFocus(), true); QCOMPARE(item2->hasActiveFocus(), false); - QCOMPARE(rootFocusSpy.count(), 2); - QCOMPARE(rootActiveFocusSpy.count(), 2); - QCOMPARE(scope1FocusSpy.count(), 1); - QCOMPARE(scope1ActiveFocusSpy.count(), 2); - QCOMPARE(item1FocusSpy.count(), 0); - QCOMPARE(item1ActiveFocusSpy.count(), 2); - QCOMPARE(scope2FocusSpy.count(), 1); - QCOMPARE(scope2ActiveFocusSpy.count(), 0); - QCOMPARE(item2FocusSpy.count(), 1); - QCOMPARE(item2ActiveFocusSpy.count(), 0); + QCOMPARE(rootFocusSpy.size(), 2); + QCOMPARE(rootActiveFocusSpy.size(), 2); + QCOMPARE(scope1FocusSpy.size(), 1); + QCOMPARE(scope1ActiveFocusSpy.size(), 2); + QCOMPARE(item1FocusSpy.size(), 0); + QCOMPARE(item1ActiveFocusSpy.size(), 2); + QCOMPARE(scope2FocusSpy.size(), 1); + QCOMPARE(scope2ActiveFocusSpy.size(), 0); + QCOMPARE(item2FocusSpy.size(), 1); + QCOMPARE(item2ActiveFocusSpy.size(), 0); // give the window focus, and item2 will get active focus view->show(); @@ -582,12 +582,12 @@ void tst_qquickfocusscope::canvasFocus() QCOMPARE(scope2->hasActiveFocus(), true); QCOMPARE(item2->hasFocus(), true); QCOMPARE(item2->hasActiveFocus(), true); - QCOMPARE(rootFocusSpy.count(), 3); - QCOMPARE(rootActiveFocusSpy.count(), 3); - QCOMPARE(scope2FocusSpy.count(), 1); - QCOMPARE(scope2ActiveFocusSpy.count(), 1); - QCOMPARE(item2FocusSpy.count(), 1); - QCOMPARE(item2ActiveFocusSpy.count(), 1); + QCOMPARE(rootFocusSpy.size(), 3); + QCOMPARE(rootActiveFocusSpy.size(), 3); + QCOMPARE(scope2FocusSpy.size(), 1); + QCOMPARE(scope2ActiveFocusSpy.size(), 1); + QCOMPARE(item2FocusSpy.size(), 1); + QCOMPARE(item2ActiveFocusSpy.size(), 1); delete view; } diff --git a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp index 0efe3a2c24..c34edbcdde 100644 --- a/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp +++ b/tests/auto/quick/qquickfontloader/tst_qquickfontloader.cpp @@ -147,27 +147,27 @@ void tst_qquickfontloader::changeFont() QSignalSpy statusSpy(fontObject, SIGNAL(statusChanged())); QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); - QCOMPARE(nameSpy.count(), 0); - QCOMPARE(statusSpy.count(), 0); + QCOMPARE(nameSpy.size(), 0); + QCOMPARE(statusSpy.size(), 0); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("fnt", server.urlString("/daniel.ttf")); QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Loading); QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); - QCOMPARE(nameSpy.count(), 1); - QCOMPARE(statusSpy.count(), 2); + QCOMPARE(nameSpy.size(), 1); + QCOMPARE(statusSpy.size(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); ctxt->setContextProperty("fnt", testFileUrl("tarzeau_ocr_a.ttf")); QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); - QCOMPARE(nameSpy.count(), 2); - QCOMPARE(statusSpy.count(), 2); + QCOMPARE(nameSpy.size(), 2); + QCOMPARE(statusSpy.size(), 2); QTRY_COMPARE(fontObject->name(), QString("OCRA")); ctxt->setContextProperty("fnt", server.urlString("/daniel.ttf")); QTRY_COMPARE(fontObject->status(), QQuickFontLoader::Ready); - QCOMPARE(nameSpy.count(), 3); - QCOMPARE(statusSpy.count(), 2); + QCOMPARE(nameSpy.size(), 3); + QCOMPARE(statusSpy.size(), 2); QTRY_COMPARE(fontObject->name(), QString("Daniel")); } diff --git a/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp b/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp index 6d98b62696..f34bdc2059 100644 --- a/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp +++ b/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp @@ -39,7 +39,7 @@ void tst_QuickFontMetrics::properties() QSignalSpy spy(&metrics, SIGNAL(fontChanged(QFont))); metrics.setFont(font); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(metrics.ascent(), expected.ascent()); QCOMPARE(metrics.descent(), expected.descent()); diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index 182458bb10..9e42e0f4e4 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -350,7 +350,7 @@ void tst_QQuickGridView::items() QTRY_COMPARE(gridview->count(), model.count()); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item for (int i = 0; i < model.count(); ++i) { QQuickText *name = findItem<QQuickText>(contentItem, "textName", i); @@ -365,7 +365,7 @@ void tst_QQuickGridView::items() QaimModel model2; ctxt->setContextProperty("testModel", &model2); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QTRY_COMPARE(itemCount, 0); delete window; @@ -430,7 +430,7 @@ void tst_QQuickGridView::inserted_basic() model.insertItem(1, "Will", "9876"); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item QQuickText *name = findItem<QQuickText>(contentItem, "textName", 1); QTRY_VERIFY(name != nullptr); @@ -452,7 +452,7 @@ void tst_QQuickGridView::inserted_basic() model.insertItem(0, "Foo", "1111"); // zero index, and current item - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item name = findItem<QQuickText>(contentItem, "textName", 0); QTRY_VERIFY(name != nullptr); @@ -539,7 +539,7 @@ void tst_QQuickGridView::inserted_defaultLayout(QQuickGridView::Flow flow, QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item && delegateVisible(item)) { firstVisibleIndex = i; @@ -549,7 +549,7 @@ void tst_QQuickGridView::inserted_defaultLayout(QQuickGridView::Flow flow, QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex)); // Confirm items positioned correctly and indexes correct - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->position(), expectedItemPos(gridview, i, rowOffsetAfterMove)); @@ -732,7 +732,7 @@ void tst_QQuickGridView::insertBeforeVisible() QTRY_COMPARE(gridview->contentY(), 0.0 + itemsOffsetAfterMove); // Confirm items positioned correctly and indexes correct - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -804,7 +804,7 @@ void tst_QQuickGridView::removed_basic() QTRY_COMPARE(removed, QString("Item1")); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -825,7 +825,7 @@ void tst_QQuickGridView::removed_basic() // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -838,7 +838,7 @@ void tst_QQuickGridView::removed_basic() QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -876,7 +876,7 @@ void tst_QQuickGridView::removed_basic() QVERIFY(QQuickTest::qWaitForPolish(gridview)); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QTRY_COMPARE(item->x(), qreal((i%3)*80)); @@ -959,7 +959,7 @@ void tst_QQuickGridView::removed_defaultLayout(QQuickGridView::Flow flow, int firstVisibleIndex = -1; QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); QRectF viewRect(gridview->contentX(), gridview->contentY(), gridview->width(), gridview->height()); - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item) { QRectF itemRect(item->x(), item->y(), item->width(), item->height()); @@ -975,7 +975,7 @@ void tst_QQuickGridView::removed_defaultLayout(QQuickGridView::Flow flow, QCOMPARE(firstName, firstVisible); // Confirm items positioned correctly and indexes correct - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->position(), expectedItemPos(gridview, i, rowOffsetAfterMove)); @@ -1200,7 +1200,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() QCOMPARE(name->text(), QString("Item1")); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QTRY_VERIFY(findItem<QQuickItem>(contentItem, "wrapper", i)); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -1309,7 +1309,7 @@ void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow, // Confirm items positioned correctly and indexes correct QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item && delegateVisible(item)) { firstVisibleIndex = i; @@ -1318,7 +1318,7 @@ void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow, } QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex)); - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item && ( (flow == QQuickGridView::FlowLeftToRight && i >= firstVisibleIndex + (3*6)) @@ -1545,7 +1545,7 @@ void tst_QQuickGridView::multipleChanges(bool condensed) QTRY_VERIFY(gridview != nullptr); QVERIFY(QQuickTest::qWaitForPolish(gridview)); - for (int i=0; i<changes.count(); i++) { + for (int i=0; i<changes.size(); i++) { switch (changes[i].type) { case ListChange::Inserted: { @@ -1584,7 +1584,7 @@ void tst_QQuickGridView::multipleChanges(bool condensed) QQuickText *number; QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -2172,7 +2172,7 @@ void tst_QQuickGridView::changeFlow() QTRY_VERIFY(contentItem != nullptr); // Confirm items positioned correctly and indexes correct - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2190,7 +2190,7 @@ void tst_QQuickGridView::changeFlow() ctxt->setContextProperty("testTopToBottom", QVariant(true)); // Confirm items positioned correctly and indexes correct - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2208,7 +2208,7 @@ void tst_QQuickGridView::changeFlow() ctxt->setContextProperty("testRightToLeft", QVariant(true)); // Confirm items positioned correctly and indexes correct - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2228,7 +2228,7 @@ void tst_QQuickGridView::changeFlow() QTRY_COMPARE(gridview->contentX(), 0.); // Confirm items positioned correctly and indexes correct - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2322,17 +2322,17 @@ void tst_QQuickGridView::propertyChanges() QTRY_COMPARE(gridView->cacheBuffer(), 3); QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); - QTRY_COMPARE(cacheBufferSpy.count(),1); - QTRY_COMPARE(flowSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),1); + QTRY_COMPARE(cacheBufferSpy.size(),1); + QTRY_COMPARE(flowSpy.size(),1); gridView->setWrapEnabled(false); gridView->setCacheBuffer(3); gridView->setFlow(QQuickGridView::FlowTopToBottom); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); - QTRY_COMPARE(cacheBufferSpy.count(),1); - QTRY_COMPARE(flowSpy.count(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),1); + QTRY_COMPARE(cacheBufferSpy.size(),1); + QTRY_COMPARE(flowSpy.size(),1); gridView->setFlow(QQuickGridView::FlowLeftToRight); QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowLeftToRight); @@ -2345,26 +2345,26 @@ void tst_QQuickGridView::propertyChanges() QTRY_COMPARE(gridView->cacheBuffer(), 5); QTRY_COMPARE(gridView->layoutDirection(), Qt::RightToLeft); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),2); - QTRY_COMPARE(cacheBufferSpy.count(),2); - QTRY_COMPARE(layoutSpy.count(),1); - QTRY_COMPARE(flowSpy.count(),2); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),2); + QTRY_COMPARE(cacheBufferSpy.size(),2); + QTRY_COMPARE(layoutSpy.size(),1); + QTRY_COMPARE(flowSpy.size(),2); gridView->setWrapEnabled(true); gridView->setCacheBuffer(5); gridView->setLayoutDirection(Qt::RightToLeft); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),2); - QTRY_COMPARE(cacheBufferSpy.count(),2); - QTRY_COMPARE(layoutSpy.count(),1); - QTRY_COMPARE(flowSpy.count(),2); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),2); + QTRY_COMPARE(cacheBufferSpy.size(),2); + QTRY_COMPARE(layoutSpy.size(),1); + QTRY_COMPARE(flowSpy.size(),2); gridView->setFlow(QQuickGridView::FlowTopToBottom); QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom); - QTRY_COMPARE(flowSpy.count(),3); + QTRY_COMPARE(flowSpy.size(),3); gridView->setFlow(QQuickGridView::FlowTopToBottom); - QTRY_COMPARE(flowSpy.count(),3); + QTRY_COMPARE(flowSpy.size(),3); delete window; } @@ -2404,24 +2404,24 @@ void tst_QQuickGridView::componentChanges() QVERIFY(gridView->headerItem()); QVERIFY(gridView->footerItem()); - QTRY_COMPARE(highlightSpy.count(),1); - QTRY_COMPARE(delegateSpy.count(),1); - QTRY_COMPARE(headerSpy.count(),1); - QTRY_COMPARE(footerSpy.count(),1); - QTRY_COMPARE(headerItemSpy.count(),1); - QTRY_COMPARE(footerItemSpy.count(),1); + QTRY_COMPARE(highlightSpy.size(),1); + QTRY_COMPARE(delegateSpy.size(),1); + QTRY_COMPARE(headerSpy.size(),1); + QTRY_COMPARE(footerSpy.size(),1); + QTRY_COMPARE(headerItemSpy.size(),1); + QTRY_COMPARE(footerItemSpy.size(),1); gridView->setHighlight(&component); gridView->setDelegate(&delegateComponent); gridView->setHeader(&component); gridView->setFooter(&component); - QTRY_COMPARE(highlightSpy.count(),1); - QTRY_COMPARE(delegateSpy.count(),1); - QTRY_COMPARE(headerSpy.count(),1); - QTRY_COMPARE(footerSpy.count(),1); - QTRY_COMPARE(headerItemSpy.count(),1); - QTRY_COMPARE(footerItemSpy.count(),1); + QTRY_COMPARE(highlightSpy.size(),1); + QTRY_COMPARE(delegateSpy.size(),1); + QTRY_COMPARE(headerSpy.size(),1); + QTRY_COMPARE(footerSpy.size(),1); + QTRY_COMPARE(headerItemSpy.size(),1); + QTRY_COMPARE(footerItemSpy.size(),1); delete window; } @@ -2442,13 +2442,13 @@ void tst_QQuickGridView::modelChanges() gridView->setModel(modelVariant); QTRY_COMPARE(gridView->model(), modelVariant); - QTRY_COMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.size(),1); gridView->setModel(modelVariant); - QTRY_COMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.size(),1); gridView->setModel(QVariant()); - QTRY_COMPARE(modelSpy.count(),2); + QTRY_COMPARE(modelSpy.size(),2); delete window; } @@ -2578,7 +2578,7 @@ void tst_QQuickGridView::positionViewAtIndex() QTRY_COMPARE(gridview->contentY(), contentPos); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = index; i < model.count() && i < itemCount-index-1; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3073,7 +3073,7 @@ void tst_QQuickGridView::footer() QSignalSpy footerItemSpy(gridview, SIGNAL(footerItemChanged())); QMetaObject::invokeMethod(window->rootObject(), "changeFooter"); - QCOMPARE(footerItemSpy.count(), 1); + QCOMPARE(footerItemSpy.size(), 1); footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(!footer); @@ -3292,7 +3292,7 @@ void tst_QQuickGridView::header() QSignalSpy headerItemSpy(gridview, SIGNAL(headerItemChanged())); QMetaObject::invokeMethod(window->rootObject(), "changeHeader"); - QCOMPARE(headerItemSpy.count(), 1); + QCOMPARE(headerItemSpy.size(), 1); header = findItem<QQuickText>(contentItem, "header"); QVERIFY(!header); @@ -3525,51 +3525,46 @@ void tst_QQuickGridView::extents_data() QTest::newRow("LeftToRight, LtR, TtB") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom - << QPointF(0, -20) << QPointF(0, 0) - << QPointF(0, 20) << QPointF(240, 20) + << QPointF(0, -20) << QPointF(0, 0) << QPointF(0, 20) << QPointF(0, 20) << QPointF(0, -20) << QPointF(0, -20); QTest::newRow("LeftToRight, RtL, TtB") << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom - << QPointF(0, -20) << QPointF(0, 0) - << QPointF(0, 20) << QPointF(240, 20) + << QPointF(0, -20) << QPointF(0, 0) << QPointF(0, 20) << QPointF(0, 20) << QPointF(0, -20) << QPointF(0, -20); QTest::newRow("LeftToRight, LtR, BtT") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop - << QPointF(0, 0) << QPointF(0, -30) - << QPointF(0, 320 - 20) << QPointF(240, 320 - 20) // content flow is reversed + << QPointF(0, 0) << QPointF(0, -30) << QPointF(0, 320 - 20) + << QPointF(0, 320 - 20) // content flow is reversed << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30); QTest::newRow("LeftToRight, RtL, BtT") << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop - << QPointF(0, 0) << QPointF(0, -30) - << QPointF(0, 320 - 20) << QPointF(240, 320 - 20) // content flow is reversed + << QPointF(0, 0) << QPointF(0, -30) << QPointF(0, 320 - 20) + << QPointF(0, 320 - 20) // content flow is reversed << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30); - QTest::newRow("TopToBottom, LtR, TtB") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom - << QPointF(-20, 0) << QPointF(0, 0) - << QPointF(20, 0) << QPointF(20, 320) + << QPointF(-20, 0) << QPointF(0, 0) << QPointF(20, 0) << QPointF(20, 0) << QPointF(-20, 0) << QPointF(-20, 0); QTest::newRow("TopToBottom, RtL, TtB") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom - << QPointF(0, 0) << QPointF(-30, 0) - << QPointF(240 - 20, 0) << QPointF(240 - 20, 320) // content flow is reversed + << QPointF(0, 0) << QPointF(-30, 0) << QPointF(240 - 20, 0) + << QPointF(240 - 20, 0) // content flow is reversed << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0); QTest::newRow("TopToBottom, LtR, BtT") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop - << QPointF(-20, -320) << QPointF(0, -320) - << QPointF(20, 0) << QPointF(20, 320) + << QPointF(-20, -320) << QPointF(0, -320) << QPointF(20, 0) << QPointF(20, 0) << QPointF(-20, 0) << QPointF(-20, 0); QTest::newRow("TopToBottom, RtL, BtT") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop - << QPointF(0, -320) << QPointF(-30, -320) - << QPointF(240 - 20, 0) << QPointF(240 - 20, 320) // content flow is reversed + << QPointF(0, -320) << QPointF(-30, -320) << QPointF(240 - 20, 0) + << QPointF(240 - 20, 0) // content flow is reversed << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0); } @@ -3651,16 +3646,16 @@ void tst_QQuickGridView::resizeViewAndRepaint() // Ensure we handle -ve sizes gridview->setHeight(-100); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 3); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 3); gridview->setCacheBuffer(120); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 9); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 9); // ensure items in cache become visible gridview->setHeight(120); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 15); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 15); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3672,9 +3667,9 @@ void tst_QQuickGridView::resizeViewAndRepaint() // ensure items outside view become invisible gridview->setHeight(60); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 12); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 12); - itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3730,8 +3725,8 @@ void tst_QQuickGridView::resizeGrid() // Confirm items positioned correctly and indexes correct QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - QVERIFY(items.count() >= 18 && items.count() <= 21); - for (int i = 0; i < model.count() && i < items.count(); ++i) { + QVERIFY(items.size() >= 18 && items.size() <= 21); + for (int i = 0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->position(), expectedItemPos(gridview, i, 0)); @@ -3762,8 +3757,8 @@ void tst_QQuickGridView::resizeGrid() // Confirm items positioned correctly and indexes correct items = findItems<QQuickItem>(contentItem, "wrapper"); - QVERIFY(items.count() >= 28); - for (int i = 0; i < model.count() && i < items.count(); ++i) { + QVERIFY(items.size() >= 28); + for (int i = 0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->position(), expectedItemPos(gridview, i, 0)); @@ -3851,7 +3846,7 @@ void tst_QQuickGridView::changeColumnCount() QVERIFY(QQuickTest::qWaitForPolish(gridview)); // a single column of 6 items are visible - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QCOMPARE(itemCount, 6); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -3863,7 +3858,7 @@ void tst_QQuickGridView::changeColumnCount() // now 6x3 grid is visible, plus 1 extra below for refill gridview->setWidth(240); QVERIFY(QQuickTest::qWaitForPolish(gridview)); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QCOMPARE(itemCount, 6*3 + 1); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -3875,7 +3870,7 @@ void tst_QQuickGridView::changeColumnCount() // back to single column gridview->setWidth(100); QVERIFY(QQuickTest::qWaitForPolish(gridview)); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QCOMPARE(itemCount, 6); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -3976,8 +3971,8 @@ void tst_QQuickGridView::onAdd() qApp->processEvents(); QVariantList result = gridview->property("addedDelegates").toList(); - QTRY_COMPARE(result.count(), items.count()); - for (int i=0; i<items.count(); i++) + QTRY_COMPARE(result.size(), items.size()); + for (int i=0; i<items.size(); i++) QCOMPARE(result[i].toString(), items[i].first); releaseView(window); @@ -4461,7 +4456,7 @@ void tst_QQuickGridView::snapOneRow() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(gridview->currentIndex(), 2); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); } // flick to end @@ -4474,7 +4469,7 @@ void tst_QQuickGridView::snapOneRow() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(gridview->currentIndex(), 6); - QCOMPARE(currentIndexSpy.count(), 3); + QCOMPARE(currentIndexSpy.size(), 3); } if (flow == QQuickGridView::FlowLeftToRight) @@ -4497,7 +4492,7 @@ void tst_QQuickGridView::snapOneRow() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(gridview->currentIndex(), 0); - QCOMPARE(currentIndexSpy.count(), 6); + QCOMPARE(currentIndexSpy.size(), 6); } releaseView(window); @@ -4611,7 +4606,7 @@ void tst_QQuickGridView::populateTransitions() QCOMPARE(gridview->property("countAddTransitions").toInt(), 0); } - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -4633,7 +4628,7 @@ void tst_QQuickGridView::populateTransitions() // clear the model window->rootContext()->setContextProperty("testModel", QVariant()); QTRY_COMPARE(gridview->count(), 0); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").size(), 0); gridview->setProperty("countPopulateTransitions", 0); gridview->setProperty("countAddTransitions", 0); @@ -4647,7 +4642,7 @@ void tst_QQuickGridView::populateTransitions() QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 18 : 0); QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -4665,7 +4660,7 @@ void tst_QQuickGridView::populateTransitions() QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 18 : 0); QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -4753,7 +4748,7 @@ void tst_QQuickGridView::addTransitions() targetIndexes << i; } } - QVERIFY(expectedTargetData.count() > 0); + QVERIFY(expectedTargetData.size() > 0); } // start animation @@ -4766,7 +4761,7 @@ void tst_QQuickGridView::addTransitions() QList<QQuickItem *> targetItems = findItems<QQuickItem>(contentItem, "wrapper", targetIndexes); if (shouldAnimateTargets) { - QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(gridview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -4792,7 +4787,7 @@ void tst_QQuickGridView::addTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { if (items[i]->y() >= gridview->contentY()) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); firstVisibleIndex = e.evaluate().toInt(); @@ -4802,7 +4797,7 @@ void tst_QQuickGridView::addTransitions() QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex)); // verify all items moved to the correct final positions - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->x(), (i%3)*80.0); @@ -4965,7 +4960,7 @@ void tst_QQuickGridView::moveTransitions() model.moveItems(moveFrom, moveTo, moveCount); gridview->forceLayout(); - QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(gridview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -4989,7 +4984,7 @@ void tst_QQuickGridView::moveTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { if (items[i]->y() >= gridview->contentY()) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); firstVisibleIndex = e.evaluate().toInt(); @@ -5000,7 +4995,7 @@ void tst_QQuickGridView::moveTransitions() // verify all items moved to the correct final positions qreal pixelOffset = 60 * rowOffsetAfterMove; - for (int i=firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i=firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->x(), (i%3)*80.0); @@ -5201,13 +5196,13 @@ void tst_QQuickGridView::removeTransitions() targetIndexes << i; } } - QVERIFY(expectedTargetData.count() > 0); + QVERIFY(expectedTargetData.size() > 0); } // calculate targetItems and expectedTargets before model changes QList<QQuickItem *> targetItems = findItems<QQuickItem>(contentItem, "wrapper", targetIndexes); QVariantMap expectedTargets; - for (int i=0; i<targetIndexes.count(); i++) + for (int i=0; i<targetIndexes.size(); i++) expectedTargets[model.name(targetIndexes[i])] = targetIndexes[i]; // start animation @@ -5216,7 +5211,7 @@ void tst_QQuickGridView::removeTransitions() QTRY_COMPARE(model.count(), gridview->count()); if (shouldAnimateTargets || expectedDisplacedIndexes.isValid()) { - QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(gridview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(gridview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -5241,9 +5236,9 @@ void tst_QQuickGridView::removeTransitions() } QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - int itemCount = items.count(); + int itemCount = items.size(); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); int index = e.evaluate().toInt(); if (firstVisibleIndex < 0 && items[i]->y() >= gridview->contentY()) @@ -5438,15 +5433,15 @@ void tst_QQuickGridView::displacedTransitions() QTRY_VERIFY(gridview->property("displaceTransitionsDone").toBool()); // check the correct number of target items and indexes were received - QCOMPARE(resultTargetIndexes.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetIndexes.count(); i++) - QCOMPARE(resultTargetIndexes[i].value<QList<int> >().count(), change.count); - QCOMPARE(resultTargetItems.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetItems.count(); i++) - QCOMPARE(resultTargetItems[i].toList().count(), change.count); + QCOMPARE(resultTargetIndexes.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetIndexes.size(); i++) + QCOMPARE(resultTargetIndexes[i].value<QList<int> >().size(), change.count); + QCOMPARE(resultTargetItems.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetItems.size(); i++) + QCOMPARE(resultTargetItems[i].toList().size(), change.count); } else { - QCOMPARE(resultTargetIndexes.count(), 0); - QCOMPARE(resultTargetItems.count(), 0); + QCOMPARE(resultTargetIndexes.size(), 0); + QCOMPARE(resultTargetItems.size(), 0); } if (change.type == ListChange::Inserted && useAddDisplaced && addDisplacedEnabled) @@ -5473,7 +5468,7 @@ void tst_QQuickGridView::displacedTransitions() // verify all items moved to the correct final positions QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - for (int i=0; i < model.count() && i < items.count(); ++i) { + for (int i=0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QCOMPARE(item->x(), (i%3)*80.0); @@ -5626,7 +5621,7 @@ void tst_QQuickGridView::multipleTransitions() int timeBetweenActions = window->rootObject()->property("timeBetweenActions").toInt(); - for (int i=0; i<changes.count(); i++) { + for (int i=0; i<changes.size(); i++) { switch (changes[i].type) { case ListChange::Inserted: { @@ -5636,7 +5631,7 @@ void tst_QQuickGridView::multipleTransitions() model.insertItems(changes[i].index, targetItems); gridview->forceLayout(); QTRY_COMPARE(model.count(), gridview->count()); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!gridview->property("runningAddTargets").toBool()); QTRY_VERIFY(!gridview->property("runningAddDisplaced").toBool()); } else { @@ -5648,7 +5643,7 @@ void tst_QQuickGridView::multipleTransitions() model.removeItems(changes[i].index, changes[i].count); gridview->forceLayout(); QTRY_COMPARE(model.count(), gridview->count()); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!gridview->property("runningRemoveTargets").toBool()); QTRY_VERIFY(!gridview->property("runningRemoveDisplaced").toBool()); } else { @@ -5659,7 +5654,7 @@ void tst_QQuickGridView::multipleTransitions() model.moveItems(changes[i].index, changes[i].to, changes[i].count); gridview->forceLayout(); QVERIFY(QQuickTest::qWaitForPolish(gridview)); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!gridview->property("runningMoveTargets").toBool()); QTRY_VERIFY(!gridview->property("runningMoveDisplaced").toBool()); } else { @@ -5683,7 +5678,7 @@ void tst_QQuickGridView::multipleTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { if (items[i]->y() >= contentY) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); firstVisibleIndex = e.evaluate().toInt(); @@ -5694,7 +5689,7 @@ void tst_QQuickGridView::multipleTransitions() QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex)); // verify all items moved to the correct final positions - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=firstVisibleIndex; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); @@ -5802,7 +5797,7 @@ void tst_QQuickGridView::multipleDisplaced() // verify all items moved to the correct final positions QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - for (int i=0; i < model.count() && i < items.count(); ++i) { + for (int i=0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i))); QTRY_COMPARE(item->x(), (i%3)*80.0); @@ -5896,7 +5891,7 @@ void tst_QQuickGridView::cacheBuffer() QVERIFY(gridview->model() != 0); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QTRY_COMPARE(item->x(), (i%3)*80.0); @@ -5926,7 +5921,7 @@ void tst_QQuickGridView::cacheBuffer() } int newItemCount = 0; - newItemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + newItemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { @@ -6404,7 +6399,7 @@ QList<int> tst_QQuickGridView::toIntList(const QVariantList &list) { QList<int> ret; bool ok = true; - for (int i=0; i<list.count(); i++) { + for (int i=0; i<list.size(); i++) { ret << list[i].toInt(&ok); if (!ok) qWarning() << "tst_QQuickGridView::toIntList(): not a number:" << list[i]; @@ -6416,7 +6411,7 @@ QList<int> tst_QQuickGridView::toIntList(const QVariantList &list) void tst_QQuickGridView::matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes) { const QSet<int> expectedIndexSet(expectedIndexes.cbegin(), expectedIndexes.cend()); - for (int i=0; i<indexLists.count(); i++) { + for (int i=0; i<indexLists.size(); i++) { const auto ¤tList = indexLists[i].value<QList<int> >(); const QSet<int> current(currentList.cbegin(), currentList.cend()); if (current != expectedIndexSet) @@ -6436,19 +6431,19 @@ void tst_QQuickGridView::matchItemsAndIndexes(const QVariantMap &items, const Qa qDebug() << itemIndex; QCOMPARE(model.name(itemIndex), name); } - QCOMPARE(items.count(), expectedIndexes.count()); + QCOMPARE(items.size(), expectedIndexes.size()); } void tst_QQuickGridView::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { - for (int i=0; i<itemLists.count(); i++) { + for (int i=0; i<itemLists.size(); i++) { QVariantList current = itemLists[i].toList(); - for (int j=0; j<current.count(); j++) { + for (int j=0; j<current.size(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); QVERIFY2(o, QTest::toString(QString("Invalid actual item at %1").arg(j))); QVERIFY2(expectedItems.contains(o), QTest::toString(QString("Cannot match item %1").arg(j))); } - QCOMPARE(current.count(), expectedItems.count()); + QCOMPARE(current.size(), expectedItems.size()); } } @@ -6552,11 +6547,11 @@ void tst_QQuickGridView::jsArrayChange() } view->setModel(QVariant::fromValue(array1)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // no change view->setModel(QVariant::fromValue(array2)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QQuickGridView::contentHeightWithDelayRemove_data() @@ -6725,7 +6720,7 @@ void tst_QQuickGridView::keyNavigationEnabled() // of disabling both mouse and keyboard interaction. QSignalSpy enabledSpy(gridView, SIGNAL(keyNavigationEnabledChanged())); gridView->setInteractive(false); - QCOMPARE(enabledSpy.count(), 1); + QCOMPARE(enabledSpy.size(), 1); QCOMPARE(gridView->isKeyNavigationEnabled(), false); flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100); @@ -6738,17 +6733,17 @@ void tst_QQuickGridView::keyNavigationEnabled() // Check that isKeyNavigationEnabled implicitly follows the value of interactive. gridView->setInteractive(true); - QCOMPARE(enabledSpy.count(), 2); + QCOMPARE(enabledSpy.size(), 2); QCOMPARE(gridView->isKeyNavigationEnabled(), true); // Change it back again for the next check. gridView->setInteractive(false); - QCOMPARE(enabledSpy.count(), 3); + QCOMPARE(enabledSpy.size(), 3); QCOMPARE(gridView->isKeyNavigationEnabled(), false); // Setting keyNavigationEnabled to true shouldn't enable mouse interaction. gridView->setKeyNavigationEnabled(true); - QCOMPARE(enabledSpy.count(), 4); + QCOMPARE(enabledSpy.size(), 4); flick(window.data(), QPoint(200, 175), QPoint(200, 50), 100); QVERIFY(!gridView->isMoving()); QCOMPARE(gridView->contentY(), 0.0); @@ -6761,7 +6756,7 @@ void tst_QQuickGridView::keyNavigationEnabled() // Changing interactive now shouldn't result in keyNavigationEnabled changing, // since we broke the "binding". gridView->setInteractive(true); - QCOMPARE(enabledSpy.count(), 4); + QCOMPARE(enabledSpy.size(), 4); // Keyboard interaction shouldn't work now. gridView->setKeyNavigationEnabled(false); diff --git a/tests/auto/quick/qquickimage/tst_qquickimage.cpp b/tests/auto/quick/qquickimage/tst_qquickimage.cpp index 73b575f818..560fad64eb 100644 --- a/tests/auto/quick/qquickimage/tst_qquickimage.cpp +++ b/tests/auto/quick/qquickimage/tst_qquickimage.cpp @@ -582,9 +582,9 @@ void tst_qquickimage::noLoading() ctxt->setContextProperty("srcImage", testFileUrl("green.png")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 1); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 1); + QTRY_COMPARE(sourceSpy.size(), 1); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/rect.png")); @@ -592,9 +592,9 @@ void tst_qquickimage::noLoading() QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_VERIFY(progressSpy.count() >= 2); - QTRY_COMPARE(statusSpy.count(), 3); + QTRY_COMPARE(sourceSpy.size(), 2); + QTRY_VERIFY(progressSpy.size() >= 2); + QTRY_COMPARE(statusSpy.size(), 3); // Loading remote file again - should not go through 'Loading' state. progressSpy.clear(); @@ -602,9 +602,9 @@ void tst_qquickimage::noLoading() ctxt->setContextProperty("srcImage", server.url("/rect.png")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 4); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 5); + QTRY_COMPARE(sourceSpy.size(), 4); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 5); delete obj; } @@ -659,17 +659,17 @@ void tst_qquickimage::sourceSize_QTBUG_14303() QTRY_COMPARE(obj->sourceSize().width(), 200); QTRY_COMPARE(obj->sourceSize().height(), 200); - QTRY_COMPARE(sourceSizeSpy.count(), 0); + QTRY_COMPARE(sourceSizeSpy.size(), 0); ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); QTRY_COMPARE(obj->sourceSize().width(), 120); QTRY_COMPARE(obj->sourceSize().height(), 120); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("heart200.png")); QTRY_COMPARE(obj->sourceSize().width(), 200); QTRY_COMPARE(obj->sourceSize().height(), 200); - QTRY_COMPARE(sourceSizeSpy.count(), 2); + QTRY_COMPARE(sourceSizeSpy.size(), 2); delete obj; } @@ -811,48 +811,48 @@ void tst_qquickimage::sourceSizeChanges() // Local ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(img->status(), QQuickImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 0); + QTRY_COMPARE(sourceSizeSpy.size(), 0); ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("heart_copy.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 1); + QTRY_COMPARE(sourceSizeSpy.size(), 1); ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 2); + QTRY_COMPARE(sourceSizeSpy.size(), 2); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(img->status(), QQuickImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 3); + QTRY_COMPARE(sourceSizeSpy.size(), 3); // Remote ctxt->setContextProperty("srcImage", server.url("/heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/heart.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/heart_copy.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 4); + QTRY_COMPARE(sourceSizeSpy.size(), 4); ctxt->setContextProperty("srcImage", server.url("/colors.png")); QTRY_COMPARE(img->status(), QQuickImage::Ready); - QTRY_COMPARE(sourceSizeSpy.count(), 5); + QTRY_COMPARE(sourceSizeSpy.size(), 5); ctxt->setContextProperty("srcImage", QUrl("")); QTRY_COMPARE(img->status(), QQuickImage::Null); - QTRY_COMPARE(sourceSizeSpy.count(), 6); + QTRY_COMPARE(sourceSizeSpy.size(), 6); delete img; } @@ -954,17 +954,17 @@ void tst_qquickimage::progressAndStatusChanges() ctxt->setContextProperty("srcImage", testFileUrl("heart.png")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 0); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 0); + QTRY_COMPARE(sourceSpy.size(), 0); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 0); // Loading local file ctxt->setContextProperty("srcImage", testFileUrl("colors.png")); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 1); - QTRY_COMPARE(progressSpy.count(), 0); - QTRY_COMPARE(statusSpy.count(), 1); + QTRY_COMPARE(sourceSpy.size(), 1); + QTRY_COMPARE(progressSpy.size(), 0); + QTRY_COMPARE(statusSpy.size(), 1); // Loading remote file ctxt->setContextProperty("srcImage", server.url("/heart.png")); @@ -972,16 +972,16 @@ void tst_qquickimage::progressAndStatusChanges() QTRY_COMPARE(obj->progress(), 0.0); QTRY_COMPARE(obj->status(), QQuickImage::Ready); QTRY_COMPARE(obj->progress(), 1.0); - QTRY_COMPARE(sourceSpy.count(), 2); - QTRY_VERIFY(progressSpy.count() > 1); - QTRY_COMPARE(statusSpy.count(), 3); + QTRY_COMPARE(sourceSpy.size(), 2); + QTRY_VERIFY(progressSpy.size() > 1); + QTRY_COMPARE(statusSpy.size(), 3); ctxt->setContextProperty("srcImage", ""); QTRY_COMPARE(obj->status(), QQuickImage::Null); QTRY_COMPARE(obj->progress(), 0.0); - QTRY_COMPARE(sourceSpy.count(), 3); - QTRY_VERIFY(progressSpy.count() > 2); - QTRY_COMPARE(statusSpy.count(), 4); + QTRY_COMPARE(sourceSpy.size(), 3); + QTRY_VERIFY(progressSpy.size() > 2); + QTRY_COMPARE(statusSpy.size(), 4); delete obj; } @@ -1209,7 +1209,7 @@ void tst_qquickimage::multiFrame() if (asynchronous) { QCOMPARE(image->frameCount(), 0); QTRY_COMPARE(image->frameCount(), 4); - QCOMPARE(countSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); } else { QCOMPARE(image->frameCount(), 4); } @@ -1228,7 +1228,7 @@ void tst_qquickimage::multiFrame() image->setCurrentFrame(1); QTRY_COMPARE(image->status(), QQuickImageBase::Ready); - QCOMPARE(currentSpy.count(), 1); + QCOMPARE(currentSpy.size(), 1); QCOMPARE(image->currentFrame(), 1); contents = toUnscaledImage(view.grabWindow()); // The second frame is a green ball, approximately qRgba(0x27, 0xc8, 0x22, 0xff) diff --git a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp index aa44e9ad61..78727d32a0 100644 --- a/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp +++ b/tests/auto/quick/qquickimageprovider/tst_qquickimageprovider.cpp @@ -423,7 +423,7 @@ void tst_qquickimageprovider::threadTest() //MUST not deadlock QVERIFY(obj != nullptr); QList<QQuickImage *> images = obj->findChildren<QQuickImage *>(); - QCOMPARE(images.count(), 4); + QCOMPARE(images.size(), 4); QTest::qWait(100); foreach (QQuickImage *img, images) { QCOMPARE(img->status(), QQuickImage::Loading); @@ -542,7 +542,7 @@ void tst_qquickimageprovider::asyncTextureTest() //MUST not deadlock QVERIFY(obj != nullptr); QList<QQuickImage *> images = obj->findChildren<QQuickImage *>(); - QCOMPARE(images.count(), 4); + QCOMPARE(images.size(), 4); QTRY_COMPARE(provider->pool.activeThreadCount(), 4); foreach (QQuickImage *img, images) { @@ -615,7 +615,7 @@ void tst_qquickimageprovider::instantAsyncTextureTest() QVERIFY(!obj.isNull()); const QList<QQuickImage *> images = obj->findChildren<QQuickImage *>(); - QCOMPARE(images.count(), 4); + QCOMPARE(images.size(), 4); for (QQuickImage *img: images) { QTRY_COMPARE(img->status(), QQuickImage::Ready); diff --git a/tests/auto/quick/qquickitem/tst_qquickitem.cpp b/tests/auto/quick/qquickitem/tst_qquickitem.cpp index c74134c113..2736d6d9bb 100644 --- a/tests/auto/quick/qquickitem/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem/tst_qquickitem.cpp @@ -1035,13 +1035,13 @@ void tst_qquickitem::constructor() QQuickItem *child1 = new QQuickItem(root.data()); QCOMPARE(child1->parent(), root.data()); QCOMPARE(child1->parentItem(), root.data()); - QCOMPARE(root->childItems().count(), 1); + QCOMPARE(root->childItems().size(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem(root.data()); QCOMPARE(child2->parent(), root.data()); QCOMPARE(child2->parentItem(), root.data()); - QCOMPARE(root->childItems().count(), 2); + QCOMPARE(root->childItems().size(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); } @@ -1059,7 +1059,7 @@ void tst_qquickitem::setParentItem() child1->setParentItem(root); QVERIFY(!child1->parent()); QCOMPARE(child1->parentItem(), root); - QCOMPARE(root->childItems().count(), 1); + QCOMPARE(root->childItems().size(), 1); QCOMPARE(root->childItems().at(0), child1); QQuickItem *child2 = new QQuickItem; @@ -1068,14 +1068,14 @@ void tst_qquickitem::setParentItem() child2->setParentItem(root); QVERIFY(!child2->parent()); QCOMPARE(child2->parentItem(), root); - QCOMPARE(root->childItems().count(), 2); + QCOMPARE(root->childItems().size(), 2); QCOMPARE(root->childItems().at(0), child1); QCOMPARE(root->childItems().at(1), child2); child1->setParentItem(nullptr); QVERIFY(!child1->parent()); QVERIFY(!child1->parentItem()); - QCOMPARE(root->childItems().count(), 1); + QCOMPARE(root->childItems().size(), 1); QCOMPARE(root->childItems().at(0), child2); delete root; @@ -1565,7 +1565,7 @@ void tst_qquickitem::polishLoopDetection() } QList<QQuickItem*> items = window.contentItem()->childItems(); - for (int i = 0; i < items.count(); ++i) { + for (int i = 0; i < items.size(); ++i) { static_cast<TestPolishItem*>(items.at(i))->doPolish(); } item = static_cast<TestPolishItem*>(items.first()); @@ -1921,7 +1921,7 @@ void tst_qquickitem::paintOrder() QList<QQuickItem*> list = QQuickItemPrivate::get(root)->paintOrderChildItems(); QStringList items; - for (int i = 0; i < list.count(); ++i) + for (int i = 0; i < list.size(); ++i) items << list.at(i)->objectName(); QCOMPARE(items, expected); diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 161397640e..2c4b2dd6ec 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -2548,19 +2548,19 @@ void tst_QQuickItem::smooth() item->setSmooth(true); QVERIFY(item->smooth()); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); QList<QVariant> arguments = spy.first(); - QCOMPARE(arguments.count(), 1); + QCOMPARE(arguments.size(), 1); QVERIFY(arguments.at(0).toBool()); item->setSmooth(true); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); item->setSmooth(false); QVERIFY(!item->smooth()); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); item->setSmooth(false); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete item; } @@ -2577,19 +2577,19 @@ void tst_QQuickItem::antialiasing() item->setAntialiasing(true); QVERIFY(item->antialiasing()); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); QList<QVariant> arguments = spy.first(); - QCOMPARE(arguments.count(), 1); + QCOMPARE(arguments.size(), 1); QVERIFY(arguments.at(0).toBool()); item->setAntialiasing(true); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); item->setAntialiasing(false); QVERIFY(!item->antialiasing()); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); item->setAntialiasing(false); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete item; } @@ -2608,18 +2608,18 @@ void tst_QQuickItem::clip() QVERIFY(item->clip()); QList<QVariant> arguments = spy.first(); - QCOMPARE(arguments.count(), 1); + QCOMPARE(arguments.size(), 1); QVERIFY(arguments.at(0).toBool()); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); item->setClip(true); - QCOMPARE(spy.count(),1); + QCOMPARE(spy.size(),1); item->setClip(false); QVERIFY(!item->clip()); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); item->setClip(false); - QCOMPARE(spy.count(),2); + QCOMPARE(spy.size(),2); delete item; } @@ -2927,50 +2927,50 @@ void tst_QQuickItem::propertyChanges() item->setBaselineOffset(10.0); QCOMPARE(item->parentItem(), parentItem); - QCOMPARE(parentSpy.count(),1); + QCOMPARE(parentSpy.size(),1); QList<QVariant> parentArguments = parentSpy.first(); - QCOMPARE(parentArguments.count(), 1); + QCOMPARE(parentArguments.size(), 1); QCOMPARE(item->parentItem(), qvariant_cast<QQuickItem *>(parentArguments.at(0))); - QCOMPARE(childrenChangedSpy.count(),1); + QCOMPARE(childrenChangedSpy.size(),1); item->setParentItem(parentItem); - QCOMPARE(childrenChangedSpy.count(),1); + QCOMPARE(childrenChangedSpy.size(),1); QCOMPARE(item->width(), 100.0); - QCOMPARE(widthSpy.count(),1); + QCOMPARE(widthSpy.size(),1); QCOMPARE(item->height(), 200.0); - QCOMPARE(heightSpy.count(),1); + QCOMPARE(heightSpy.size(),1); QCOMPARE(item->baselineOffset(), 10.0); - QCOMPARE(baselineOffsetSpy.count(),1); + QCOMPARE(baselineOffsetSpy.size(),1); QList<QVariant> baselineOffsetArguments = baselineOffsetSpy.first(); - QCOMPARE(baselineOffsetArguments.count(), 1); + QCOMPARE(baselineOffsetArguments.size(), 1); QCOMPARE(item->baselineOffset(), baselineOffsetArguments.at(0).toReal()); QCOMPARE(parentItem->childrenRect(), QRectF(0.0,0.0,100.0,200.0)); - QCOMPARE(childrenRectSpy.count(),1); + QCOMPARE(childrenRectSpy.size(),1); QList<QVariant> childrenRectArguments = childrenRectSpy.at(0); - QCOMPARE(childrenRectArguments.count(), 1); + QCOMPARE(childrenRectArguments.size(), 1); QCOMPARE(parentItem->childrenRect(), childrenRectArguments.at(0).toRectF()); QCOMPARE(item->hasActiveFocus(), true); - QCOMPARE(focusSpy.count(),1); + QCOMPARE(focusSpy.size(),1); QList<QVariant> focusArguments = focusSpy.first(); - QCOMPARE(focusArguments.count(), 1); + QCOMPARE(focusArguments.size(), 1); QCOMPARE(focusArguments.at(0).toBool(), true); QCOMPARE(parentItem->hasActiveFocus(), false); QCOMPARE(parentItem->hasFocus(), false); - QCOMPARE(wantsFocusSpy.count(),0); + QCOMPARE(wantsFocusSpy.size(),0); item->setX(10.0); QCOMPARE(item->x(), 10.0); - QCOMPARE(xSpy.count(), 1); + QCOMPARE(xSpy.size(), 1); item->setY(10.0); QCOMPARE(item->y(), 10.0); - QCOMPARE(ySpy.count(), 1); + QCOMPARE(ySpy.size(), 1); delete window; } @@ -3255,7 +3255,7 @@ void tst_QQuickItem::changeListener() QCOMPARE(child2Listener.count(QQuickItemPrivate::Destroyed), 1); QQuickItemPrivate::get(parent)->removeItemChangeListener(&parentListener, QQuickItemPrivate::Children); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // QTBUG-54732: all listeners should get invoked even if they remove themselves while iterating the listeners QList<TestListener *> listeners; @@ -3265,89 +3265,89 @@ void tst_QQuickItem::changeListener() // itemVisibilityChanged x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Visibility); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setVisible(false); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Visibility), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemRotationChanged x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Rotation); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setRotation(90); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Rotation), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemOpacityChanged x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Opacity); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setOpacity(0.5); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Opacity), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemChildAdded() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Children); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); child1 = new QQuickItem(parent); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Children), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemParentChanged() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(child1)->addItemChangeListener(listener, QQuickItemPrivate::Parent); - QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.size(), listeners.size()); child1->setParentItem(nullptr); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Parent), 1); - QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(child1)->changeListeners.size(), 0); // itemImplicitWidthChanged() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::ImplicitWidth); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setImplicitWidth(parent->implicitWidth() + 1); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::ImplicitWidth), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemImplicitHeightChanged() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::ImplicitHeight); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setImplicitHeight(parent->implicitHeight() + 1); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::ImplicitHeight), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemGeometryChanged() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Geometry); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); parent->setWidth(parent->width() + 1); foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Geometry), 1); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemChildRemoved() x 5 child1->setParentItem(parent); foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Children); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); delete child1; foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Children), 2); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), 0); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), 0); // itemDestroyed() x 5 foreach (TestListener *listener, listeners) QQuickItemPrivate::get(parent)->addItemChangeListener(listener, QQuickItemPrivate::Destroyed); - QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.count(), listeners.count()); + QCOMPARE(QQuickItemPrivate::get(parent)->changeListeners.size(), listeners.size()); delete parent; foreach (TestListener *listener, listeners) QCOMPARE(listener->count(QQuickItemPrivate::Destroyed), 1); diff --git a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml index 9ecad57ffc..261b8a9a8e 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_gridlayout.qml @@ -539,6 +539,56 @@ Item { tryCompare(layout.children[4], "y", 60); } + Component { + id: layout_alignBaseline_Component + GridLayout { + columns: 2 + columnSpacing: 0 + rowSpacing: 0 + TextInput { + property var itemRect: [x, y, width, height] + text: "red" + baselineOffset: 7 + color: "red" + verticalAlignment: TextInput.AlignVCenter + Layout.preferredWidth: 50 + Layout.preferredHeight: 10 + Layout.fillHeight: true + } + TextInput { + property var itemRect: [x, y, width, height] + text: "green" + baselineOffset: 7 + color: "green" + verticalAlignment: TextInput.AlignVCenter + Layout.preferredWidth: 50 + Layout.preferredHeight: 10 + Layout.fillHeight: true + } + + } + } + + function test_alignBaseline_dont_always_invalidate() + { + var layout = createTemporaryObject(layout_alignBaseline_Component, container); + waitForItemPolished(layout) + layout.height = 20 + // Adjusting height on an item that uses Qt.AlignBaseline might adjust the baseline + // Test if we don't get excessive number of polish() events because of baseline changes + // (In this case, we don't want to align by the baseline) + compare(isPolishScheduled(layout), false) + waitForItemPolished(layout) + var c0 = layout.children[0] + c0.Layout.alignment = Qt.AlignBaseline + var c1 = layout.children[1] + c1.Layout.alignment = Qt.AlignBaseline + + // We want to align by baseline => expect a polish event + compare(isPolishScheduled(layout), true) + waitForItemPolished(layout) + } + Component { id: layout_rightToLeft_Component diff --git a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml index e14b7a2d89..4fd288cfc1 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_rowlayout.qml @@ -32,6 +32,18 @@ Item { } Component { + id: layout_rowLayout_Component + RowLayout { + } + } + + Component { + id: layout_columnLayout_Component + ColumnLayout { + } + } + + Component { id: itemsWithAnchorsLayout_Component RowLayout { spacing: 2 @@ -495,6 +507,102 @@ Item { layout.destroy(); } + + function buildLayout(layout, arrLayoutData) { + for (let i = 0; i < arrLayoutData.length; i++) { + let layoutItemDesc = arrLayoutData[i] + let rect = layoutItem_Component.createObject(layout) + for (let keyName in layoutItemDesc) { + rect.Layout[keyName] = layoutItemDesc[keyName] + } + } + } + + function test_dynamicAlignment_data() + { + return [ + { + tag: "simple", + + layout: { + type: "RowLayout", + items: [ + {preferredWidth: 30, preferredHeight: 20, fillHeight: true}, + {preferredWidth: 30, preferredHeight: 20}, + ] + }, + expectedGeometries: [ + [ 0, 0, 30, 60], + [30, 20, 30, 20] + ] + },{ + tag: "valign", + layout: { + type: "RowLayout", + items: [ + {preferredWidth: 12, preferredHeight: 20, fillHeight: true}, + {preferredWidth: 12, preferredHeight: 20}, + {preferredWidth: 12, preferredHeight: 20, alignment: Qt.AlignTop}, + {preferredWidth: 12, preferredHeight: 20, alignment: Qt.AlignVCenter}, + {preferredWidth: 12, preferredHeight: 20, alignment: Qt.AlignBottom} + ] + }, + expectedGeometries: [ + [ 0, 0, 12, 60], + [12, 20, 12, 20], + [24, 0, 12, 20], + [36, 20, 12, 20], + [48, 40, 12, 20] + ] + },{ + tag: "halign", + layout: { + type: "ColumnLayout", + items: [ + {preferredWidth: 20, preferredHeight: 12, fillWidth: true}, + {preferredWidth: 20, preferredHeight: 12}, + {preferredWidth: 20, preferredHeight: 12, alignment: Qt.AlignLeft}, + {preferredWidth: 20, preferredHeight: 12, alignment: Qt.AlignHCenter}, + {preferredWidth: 20, preferredHeight: 12, alignment: Qt.AlignRight} + ] + }, + expectedGeometries: [ + [ 0, 0, 60, 12], + [ 0, 12, 20, 12], + [ 0, 24, 20, 12], + [20, 36, 20, 12], + [40, 48, 20, 12] + ] + } + ] + } + + function test_dynamicAlignment(data) + { + let layout + switch (data.layout.type) { + case "RowLayout": + layout = createTemporaryObject(layout_rowLayout_Component, container) + break + case "ColumnLayout": + layout = createTemporaryObject(layout_columnLayout_Component, container) + break + default: + console.log("data.layout.type not recognized(" + data.layout.type + ")") + } + layout.spacing = 0 + buildLayout(layout, data.layout.items) + layout.width = 60 + layout.height = 60 // divides in 1/2/3/4/5/6 + waitForItemPolished(layout) + + for (let i = 0; i < layout.children.length; ++i) { + let itm = layout.children[i] + compare(itemRect(itm), data.expectedGeometries[i]) + } + } + + Component { id: layout_sizeHintNormalization_Component GridLayout { @@ -751,13 +859,6 @@ Item { layout.destroy(); } - - Component { - id: layout_rowLayout_Component - RowLayout { - } - } - function test_stretchItem_data() { return [ diff --git a/tests/auto/quick/qquicklayouts/data/tst_stacklayout.qml b/tests/auto/quick/qquicklayouts/data/tst_stacklayout.qml index a04e7a9dd7..85a5bbc88f 100644 --- a/tests/auto/quick/qquicklayouts/data/tst_stacklayout.qml +++ b/tests/auto/quick/qquicklayouts/data/tst_stacklayout.qml @@ -263,5 +263,499 @@ Item { compare(layout.implicitWidth, 20) compare(layout.implicitHeight, 20) } + + Component { + id: layout_setCurrentIndex_Component + + StackLayout { + width: 200 + height: 200 + + property alias firstItem : rect + property alias secondItem: rowLayout + + Rectangle { + id: rect + color: "red" + implicitWidth: 10 + implicitHeight: 10 + } + RowLayout { + id: rowLayout + spacing: 0 + Rectangle { + color: "green" + implicitWidth: 10 + implicitHeight: 10 + Layout.fillWidth: true + Layout.fillHeight: true + } + Rectangle { + color: "blue" + implicitWidth: 10 + implicitHeight: 10 + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } + } + + function test_setCurrentIndex() + { + var layout = layout_setCurrentIndex_Component.createObject(container) + compare(layout.firstItem.width, 200) + + // Invalidate the StackLayout (and its cached size hints) + layout.firstItem.implicitWidth = 42 + + layout.currentIndex = 1 + compare(layout.secondItem.width, 200) // width should not be -1 + layout.destroy() + } + + function geometry(item) { + return [item.x, item.y, item.width, item.height] + } + + Component { + id: countGeometryChanges_Component + StackLayout { + id: stack + property alias col: _col + property alias row: _row + width: 100 + ColumnLayout { + id: _col + property alias r1: _r1 + property alias r2: _r2 + property alias r3: _r3 + spacing: 0 + property int counter : 0 + onWidthChanged: { ++counter; } + Rectangle { + id: _r1 + implicitWidth: 20 + implicitHeight: 20 + Layout.fillWidth: true + property int counter : 0 + onWidthChanged: { ++counter; } + } + Rectangle { + id: _r2 + implicitWidth: 50 + implicitHeight: 50 + Layout.fillWidth: true + property int counter : 0 + onWidthChanged: { ++counter; } + } + Rectangle { + id: _r3 + implicitWidth: 40 + implicitHeight: 40 + Layout.fillWidth: true + property int counter : 0 + onWidthChanged: { ++counter; } + } + } + RowLayout { + id: _row + property alias r5: _r5 + spacing: 0 + property int counter : 0 + onWidthChanged: { ++counter; } + Rectangle { + id: _r5 + implicitWidth: 100 + implicitHeight: 100 + Layout.fillWidth: true + property int counter : 0 + onWidthChanged: { ++counter; } + } + } + } + } + + function test_countGeometryChanges() { + + var stack = countGeometryChanges_Component.createObject(container) + compare(stack.currentIndex, 0) + compare(stack.col.width, 100) + compare(stack.col.height, 110) + compare(stack.row.width, 100) + compare(stack.row.height, 100) + verify(stack.col.r1.counter <= 2) + compare(stack.col.r2.counter, 1) + verify(stack.col.r3.counter <= 2) + verify(stack.col.counter <= 2) + compare(stack.row.counter, 1) // not visible, will only receive the initial geometry change + compare(stack.row.r5.counter, 0) + stack.destroy() + } + + + Component { + id: layoutItem_Component + Rectangle { + implicitWidth: 20 + implicitHeight: 20 + } + } + + Component { + id: emtpy_StackLayout_Component + StackLayout { + property int num_onCountChanged: 0 + property int num_onCurrentIndexChanged: 0 + onCountChanged: { ++num_onCountChanged; } + onCurrentIndexChanged: { ++num_onCurrentIndexChanged; } + } + } + + function test_addAndRemoveItems() + { + var stack = emtpy_StackLayout_Component.createObject(container) + stack.currentIndex = 2 + compare(stack.implicitWidth, 0) + compare(stack.implicitHeight, 0) + + var rect0 = layoutItem_Component.createObject(stack) + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 20) + compare(stack.implicitHeight, 20) + compare(rect0.visible, false) + + var rect1 = layoutItem_Component.createObject(stack) + rect1.Layout.preferredWidth = 30 + rect1.Layout.preferredHeight = 10 + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 30) + compare(stack.implicitHeight, 20) + compare(rect0.visible, false) + compare(rect1.visible, false) + + var rect2 = layoutItem_Component.createObject(stack) + rect2.x = 42 // ### items in a stacklayout will have their x and y positions discarded. + rect2.y = 42 + rect2.Layout.preferredWidth = 80 + rect2.Layout.preferredHeight = 30 + rect2.Layout.fillWidth = true + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 80) + compare(stack.implicitHeight, 30) + compare(rect0.visible, false) + compare(rect1.visible, false) + compare(rect2.visible, true) + compare(geometry(rect2), geometry(stack)) + + rect2.destroy() + wait(0) + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 30) + compare(stack.implicitHeight, 20) + + rect0.destroy() + wait(0) + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 30) + compare(stack.implicitHeight, 10) + + rect1.destroy() + wait(0) + verify(waitForItemPolished(stack)) + compare(stack.implicitWidth, 0) + compare(stack.implicitHeight, 0) + + stack.destroy() + } + + function test_sizeHint_data() { + return [ + { tag: "propagateNone", layoutHints: [10, 20, 30], childHints: [11, 21, 31], expected:[10, 20, Number.POSITIVE_INFINITY]}, + { tag: "propagateMinimumWidth", layoutHints: [-1, 20, 30], childHints: [10, 21, 31], expected:[10, 20, Number.POSITIVE_INFINITY]}, + { tag: "propagatePreferredWidth", layoutHints: [10, -1, 30], childHints: [11, 20, 31], expected:[10, 20, Number.POSITIVE_INFINITY]}, + { tag: "propagateMaximumWidth", layoutHints: [10, 20, -1], childHints: [11, 21, 30], expected:[10, 20, Number.POSITIVE_INFINITY]}, + { tag: "propagateAll", layoutHints: [-1, -1, -1], childHints: [10, 20, 30], expected:[10, 20, Number.POSITIVE_INFINITY]}, + { tag: "propagateCrazy", layoutHints: [-1, -1, -1], childHints: [40, 21, 30], expected:[30, 30, Number.POSITIVE_INFINITY]}, + { tag: "expandMinToExplicitPref", layoutHints: [-1, 1, -1], childHints: [11, 21, 31], expected:[ 1, 1, Number.POSITIVE_INFINITY]}, + { tag: "expandMaxToExplicitPref", layoutHints: [-1, 99, -1], childHints: [11, 21, 31], expected:[11, 99, Number.POSITIVE_INFINITY]}, + { tag: "expandAllToExplicitMin", layoutHints: [99, -1, -1], childHints: [11, 21, 31], expected:[99, 99, Number.POSITIVE_INFINITY]}, + { tag: "expandPrefToExplicitMin", layoutHints: [24, -1, -1], childHints: [11, 21, 31], expected:[24, 24, Number.POSITIVE_INFINITY]}, + { tag: "boundPrefToExplicitMax", layoutHints: [-1, -1, 19], childHints: [11, 21, 31], expected:[11, 19, Number.POSITIVE_INFINITY]}, + { tag: "boundAllToExplicitMax", layoutHints: [-1, -1, 9], childHints: [11, 21, 31], expected:[ 9, 9, Number.POSITIVE_INFINITY]}, + ]; + } + + function itemSizeHints(item) { + return [item.Layout.minimumWidth, item.implicitWidth, item.Layout.maximumWidth] + } + Component { + id: stacklayout_sizeHint_Component + StackLayout { + property int implicitWidthChangedCount : 0 + onImplicitWidthChanged: { ++implicitWidthChangedCount } + ColumnLayout { + Rectangle { + id: r1 + color: "red" + Layout.minimumWidth: 1 + Layout.preferredWidth: 2 + Layout.maximumWidth: 3 + + Layout.minimumHeight: 20 + Layout.preferredHeight: 20 + Layout.maximumHeight: 20 + Layout.fillWidth: true + } + } + } + } + + function test_sizeHint(data) { + var layout = stacklayout_sizeHint_Component.createObject(container) + + var col = layout.children[0] + col.Layout.minimumWidth = data.layoutHints[0] + col.Layout.preferredWidth = data.layoutHints[1] + col.Layout.maximumWidth = data.layoutHints[2] + + var child = col.children[0] + if (data.implicitWidth !== undefined) { + child.implicitWidth = data.implicitWidth + } + child.Layout.minimumWidth = data.childHints[0] + child.Layout.preferredWidth = data.childHints[1] + child.Layout.maximumWidth = data.childHints[2] + + verify(waitForItemPolished(layout)) + var effectiveSizeHintResult = [layout.Layout.minimumWidth, layout.implicitWidth, layout.Layout.maximumWidth] + compare(effectiveSizeHintResult, data.expected) + layout.destroy() + } + + Component { + id: stacklayout_addIgnoredItem_Component + StackLayout { + Repeater { + id: rep + model: 1 + Rectangle { + id: r + } + } + } + } + + // Items with no size information is ignored. + function test_addIgnoredItem() + { + var stack = stacklayout_addIgnoredItem_Component.createObject(container) + compare(stack.count, 1) + compare(stack.implicitWidth, 0) + compare(stack.implicitHeight, 0) + var r = stack.children[0] + r.Layout.preferredWidth = 20 + r.Layout.preferredHeight = 30 + verify(waitForItemPolished(stack)) + compare(stack.count, 1) + compare(stack.implicitWidth, 20) + compare(stack.implicitHeight, 30) + stack.destroy(); + } + + function test_dontCrashWhenAnchoredToAWindow() { + var test_layoutStr = + 'import QtQuick; \ + import QtQuick.Window; \ + import QtQuick.Layouts; \ + Window { \ + visible: true; \ + width: stack.implicitWidth; \ + height: stack.implicitHeight; \ + StackLayout { \ + id: stack; \ + currentIndex: 0; \ + anchors.fill: parent; \ + Rectangle { \ + color: "red"; \ + implicitWidth: 300; \ + implicitHeight: 200; \ + } \ + } \ + } ' + + var win = Qt.createQmlObject(test_layoutStr, container, ''); + if (win.visibility === Window.Windowed) { + // on single-window systems (such as Android), the window geometry will be + // fullscreen, and most likely it will be set to screen size. Avoid this test for + // those systems, as the size of the window will not be determined by the layout + tryCompare(win, 'width', 300); + } + win.destroy() + } + + Component { + id: test_dontCrashWhenChildIsResizedToNull_Component + StackLayout { + property alias rect : _rect + Rectangle { + id: _rect; + color: "red" + implicitWidth: 200 + implicitHeight: 200 + } + } + } + + function test_dontCrashWhenChildIsResizedToNull() { + var layout = test_dontCrashWhenChildIsResizedToNull_Component.createObject(container) + layout.rect.width = 0 + layout.width = 222 // trigger a rearrange with a valid size + layout.height = 222 + } + + Component { + id: test_currentIndex_Component + StackLayout { + currentIndex: 1 + Text { + text: "0" + } + Text { + text: "1" + } + } + } + + function test_currentIndex() { + var layout = test_currentIndex_Component.createObject(container) + var c0 = layout.children[0] + var c1 = layout.children[1] + compare(layout.currentIndex, 1) + tryCompare(layout, 'visible', true) + compare(c0.visible, false) + compare(c1.visible, true) + layout.currentIndex = 0 + compare(c0.visible, true) + compare(c1.visible, false) + var c2 = layoutItem_Component.createObject(layout) + compare(c2.visible, false) + + /* + * destroy the current item and check if visibility advances to next + */ + c0.destroy() + tryCompare(c1, 'visible', true) + compare(c2.visible, false) + c1.destroy() + tryCompare(c2, 'visible', true) + c2.destroy() + tryCompare(layout, 'currentIndex', 0) + + layout.destroy() + + /* + * Test the default/implicit value of currentIndex, either -1 (if empty) or 0: + */ + layout = emtpy_StackLayout_Component.createObject(container) + tryCompare(layout, 'visible', true) + compare(layout.currentIndex, -1) + compare(layout.num_onCurrentIndexChanged, 0) + // make it non-empty + c0 = layoutItem_Component.createObject(layout) + compare(layout.currentIndex, 0) + compare(layout.num_onCurrentIndexChanged, 1) + compare(c0.visible, true) + // make it empty again + c0.destroy() + wait(0) + compare(layout.currentIndex, -1) + //tryCompare(layout, 'currentIndex', -1) + compare(layout.num_onCurrentIndexChanged, 2) + + /* + * Check that explicit value doesn't change, + * and that no items are visible if the index is invalid/out of range + */ + layout.currentIndex = 2 + compare(layout.currentIndex, 2) + compare(layout.num_onCurrentIndexChanged, 3) + c0 = layoutItem_Component.createObject(layout) + compare(layout.currentIndex, 2) + compare(c0.visible, false) + + c1 = layoutItem_Component.createObject(layout) + compare(layout.currentIndex, 2) + compare(c0.visible, false) + compare(c1.visible, false) + + c2 = layoutItem_Component.createObject(layout) + compare(layout.currentIndex, 2) + compare(c0.visible, false) + compare(c1.visible, false) + compare(c2.visible, true) + + c2.destroy() + wait(0) + compare(layout.currentIndex, 2) + compare(c0.visible, false) + compare(c1.visible, false) + c1.destroy() + wait(0) + compare(layout.currentIndex, 2) + compare(c0.visible, false) + c0.destroy() + wait(0) + compare(layout.currentIndex, 2) + compare(layout.num_onCurrentIndexChanged, 3) + } + + function test_count() { + var layout = emtpy_StackLayout_Component.createObject(container) + tryCompare(layout, 'visible', true) + compare(layout.count, 0) + compare(layout.currentIndex, -1) + compare(layout.num_onCountChanged, 0) + compare(layout.num_onCurrentIndexChanged, 0) + var c0 = layoutItem_Component.createObject(layout) + compare(layout.count, 1) + compare(layout.currentIndex, 0) + compare(layout.num_onCurrentIndexChanged, 1) + compare(layout.num_onCountChanged, 1) + } + + // QTBUG-111902 + Component { + id: stackComponent + Loader { + id: loader + asynchronous: true + sourceComponent: StackLayout { + id: stackLayout + Repeater { + model: 3 + Item { + required property int index + } + } + } + } + } + + function test_loadStackLayoutAsynchronously() { + var loaderObj = stackComponent.createObject(container) + // Check for loader status to be ready + tryCompare(loaderObj, 'status', 1) + // Get stack layout object + var stackLayoutObj = loaderObj.item + // Check repeater index of child object + compare(stackLayoutObj.children[0].index, 0) + compare(stackLayoutObj.children[1].index, 1) + compare(stackLayoutObj.children[2].index, 2) + // Check stack layout attached property index + compare(stackLayoutObj.children[0].StackLayout.index, 0) + compare(stackLayoutObj.children[1].StackLayout.index, 1) + compare(stackLayoutObj.children[2].StackLayout.index, 2) + } } } diff --git a/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml b/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml index af35c29143..6ba6480297 100644 --- a/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml +++ b/tests/auto/quick/qquicklistview/data/appendDuringScrollDown.qml @@ -1,10 +1,11 @@ import QtQuick 2.6 ListView { + id: listView width: 320; height: 240 focus: true delegate: Text { - height: 40; width: parent.width + height: 40; width: listView.width text: model.text verticalAlignment: Text.AlignVCenter horizontalAlignment: Text.AlignHCenter diff --git a/tests/auto/quick/qquicklistview/data/displayMargin.qml b/tests/auto/quick/qquicklistview/data/displayMargin.qml index 4fa034922d..20ba124a97 100644 --- a/tests/auto/quick/qquicklistview/data/displayMargin.qml +++ b/tests/auto/quick/qquicklistview/data/displayMargin.qml @@ -19,7 +19,7 @@ Item { model: 100 delegate: Rectangle { objectName: "delegate" - width: parent.width + width: view.width height: 25 color: index % 2 ? "steelblue" : "lightsteelblue" Text { diff --git a/tests/auto/quick/qquicklistview/data/listview-itematindex.qml b/tests/auto/quick/qquicklistview/data/listview-itematindex.qml index fba8b11933..2194f1edff 100644 --- a/tests/auto/quick/qquicklistview/data/listview-itematindex.qml +++ b/tests/auto/quick/qquicklistview/data/listview-itematindex.qml @@ -1,13 +1,14 @@ import QtQuick 2.0 ListView { + id: listView width: 400 height: 400 focus: true model: 3 delegate: Text { - width: parent.width + width: listView.width height: 10 property int idx: index text: index diff --git a/tests/auto/quick/qquicklistview/data/resizeAfterComponentComplete.qml b/tests/auto/quick/qquicklistview/data/resizeAfterComponentComplete.qml index 875199901a..c169d92826 100644 --- a/tests/auto/quick/qquicklistview/data/resizeAfterComponentComplete.qml +++ b/tests/auto/quick/qquicklistview/data/resizeAfterComponentComplete.qml @@ -9,7 +9,7 @@ ListView { anchors.fill: parent model: 10 delegate: Rectangle { - width: parent.width + width: listView.width height: 40 border.color: "lightsteelblue" Text { diff --git a/tests/auto/quick/qquicklistview/data/sectionSnapping.qml b/tests/auto/quick/qquicklistview/data/sectionSnapping.qml index 2583cc0377..48a893f88c 100644 --- a/tests/auto/quick/qquicklistview/data/sectionSnapping.qml +++ b/tests/auto/quick/qquicklistview/data/sectionSnapping.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 ListView { + id: listView width: 400 height: 400 preferredHighlightBegin: 100 @@ -17,7 +18,7 @@ ListView { } delegate: Rectangle { - width: parent.width + width: listView.width height: 50 color: index % 2 ? "lightsteelblue" : "steelblue" Text { diff --git a/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml b/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml index f5b7b35d0c..1dfbfe0feb 100644 --- a/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml +++ b/tests/auto/quick/qquicklistview/data/snapOneItemWrongDirection.qml @@ -1,13 +1,14 @@ import QtQuick 2.0 ListView { + id: listView width: 400 height: 400 focus: true model: 10 delegate: Rectangle { - width: parent.width + width: listView.width height: 50 color: index % 2 ? "blue" : "green" } diff --git a/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml b/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml index 338af38475..16b9c72b16 100644 --- a/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml +++ b/tests/auto/quick/qquicklistview/data/strictlyenforcerange-resize.qml @@ -1,6 +1,7 @@ import QtQuick 2.0 ListView { + id: listView width: 400 height: 400 focus: true @@ -15,7 +16,7 @@ ListView { model: 10 delegate: Item { - width: parent.width + width: listView.width height: ListView.isCurrentItem ? 100 : 50 Text { diff --git a/tests/auto/quick/qquicklistview/proxytestinnermodel.cpp b/tests/auto/quick/qquicklistview/proxytestinnermodel.cpp index c0dbb641fb..d00b417429 100644 --- a/tests/auto/quick/qquicklistview/proxytestinnermodel.cpp +++ b/tests/auto/quick/qquicklistview/proxytestinnermodel.cpp @@ -28,7 +28,7 @@ int ProxyTestInnerModel::rowCount(const QModelIndex &parent) const if (parent.isValid()) return 0; - return m_values.count(); + return m_values.size(); } int ProxyTestInnerModel::columnCount(const QModelIndex &parent) const @@ -49,7 +49,7 @@ QVariant ProxyTestInnerModel::data(const QModelIndex &index, int role) const void ProxyTestInnerModel::append(const QString &s) { - beginInsertRows(QModelIndex(), m_values.count(), m_values.count()); + beginInsertRows(QModelIndex(), m_values.size(), m_values.size()); m_values << s; endInsertRows(); } diff --git a/tests/auto/quick/qquicklistview/randomsortmodel.cpp b/tests/auto/quick/qquicklistview/randomsortmodel.cpp index 764dc81fb7..3e0c45bb1a 100644 --- a/tests/auto/quick/qquicklistview/randomsortmodel.cpp +++ b/tests/auto/quick/qquicklistview/randomsortmodel.cpp @@ -23,7 +23,7 @@ QHash<int, QByteArray> RandomSortModel::roleNames() const int RandomSortModel::rowCount(const QModelIndex& parent) const { if (!parent.isValid()) - return mData.count(); + return mData.size(); return 0; } @@ -34,7 +34,7 @@ QVariant RandomSortModel::data(const QModelIndex& index, int role) const return QVariant(); } - if (index.row() >= mData.count()) { + if (index.row() >= mData.size()) { return QVariant(); } @@ -49,14 +49,14 @@ QVariant RandomSortModel::data(const QModelIndex& index, int role) const void RandomSortModel::randomize() { - const int row = QRandomGenerator::global()->bounded(mData.count()); + const int row = QRandomGenerator::global()->bounded(mData.size()); int random; bool exists = false; // Make sure we won't end up with two items with the same weight, as that // would make unit-testing much harder do { exists = false; - random = QRandomGenerator::global()->bounded(mData.count() * 10); + random = QRandomGenerator::global()->bounded(mData.size() * 10); QList<QPair<QString, int> >::ConstIterator iter, end; for (iter = mData.constBegin(), end = mData.constEnd(); iter != end; ++iter) { if ((*iter).second == random) { diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 9cbae9ad6f..1bafe01768 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -445,7 +445,7 @@ void tst_QQuickListView::items(const QUrl &source) QTRY_COMPARE(listview->count(), model.count()); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); listview->forceLayout(); - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item // current item should be first item QTRY_COMPARE(listview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 0)); @@ -563,7 +563,7 @@ void tst_QQuickListView::inserted(const QUrl &source) model.insertItem(1, "Will", "9876"); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item QQuickText *name = findItem<QQuickText>(contentItem, "textName", 1); QTRY_VERIFY(name != nullptr); @@ -581,7 +581,7 @@ void tst_QQuickListView::inserted(const QUrl &source) model.insertItem(0, "Foo", "1111"); // zero index, and current item QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); - QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item + QTRY_COMPARE(contentItem->childItems().size(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item name = findItem<QQuickText>(contentItem, "textName", 0); QTRY_VERIFY(name != nullptr); @@ -697,7 +697,7 @@ void tst_QQuickListView::inserted_more(QQuickItemView::VerticalLayoutDirection v QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item && !QQuickItemPrivate::get(item)->culled) { firstVisibleIndex = i; @@ -711,7 +711,7 @@ void tst_QQuickListView::inserted_more(QQuickItemView::VerticalLayoutDirection v QQuickText *number; const qreal visibleFromPos = listview->contentY() - listview->displayMarginBeginning() - listview->cacheBuffer(); const qreal visibleToPos = listview->contentY() + listview->height() + listview->displayMarginEnd() + listview->cacheBuffer(); - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); qreal pos = i*20.0 + itemsOffsetAfterMove; @@ -885,7 +885,7 @@ void tst_QQuickListView::insertBeforeVisible() QTRY_COMPARE(listview->contentY(), 0.0 + itemsOffsetAfterMove); // Confirm items positioned correctly and indexes correct - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -976,7 +976,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_COMPARE(number->text(), model.number(1)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -996,7 +996,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_COMPARE(number->text(), model.number(0)); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -1009,7 +1009,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -1045,7 +1045,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -1079,7 +1079,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_COMPARE(listview->count() , model.count()); // Confirm items positioned correctly - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount-1; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i+1); if (!item) qWarning() << "Item" << i+1 << "not found"; @@ -1114,7 +1114,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) listview->positionViewAtEnd(); for (int i = 0; i < 18; ++i) model.removeItems(model.count() - 1, 1); - QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").count() > 16); + QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").size() > 16); } template <class T> @@ -1170,7 +1170,7 @@ void tst_QQuickListView::removed_more(const QUrl &source, QQuickItemView::Vertic QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item && delegateVisible(item)) { firstVisibleIndex = i; @@ -1182,7 +1182,7 @@ void tst_QQuickListView::removed_more(const QUrl &source, QQuickItemView::Vertic // Confirm items positioned correctly and indexes correct QQuickText *name; QQuickText *number; - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); qreal pos = i*20.0 + itemsOffsetAfterMove; @@ -1333,7 +1333,7 @@ void tst_QQuickListView::clear(const QUrl &source, QQuickItemView::VerticalLayou model.clear(); - QTRY_COMPARE(findItems<QQuickListView>(contentItem, "wrapper").count(), 0); + QTRY_COMPARE(findItems<QQuickListView>(contentItem, "wrapper").size(), 0); QTRY_COMPARE(listview->count(), 0); QTRY_VERIFY(!listview->currentItem()); if (verticalLayoutDirection == QQuickItemView::TopToBottom) @@ -1402,7 +1402,7 @@ void tst_QQuickListView::moved(const QUrl &source, QQuickItemView::VerticalLayou QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (item && delegateVisible(item)) { firstVisibleIndex = i; @@ -1412,7 +1412,7 @@ void tst_QQuickListView::moved(const QUrl &source, QQuickItemView::VerticalLayou QVERIFY2(firstVisibleIndex >= 0, QByteArray::number(firstVisibleIndex)); // Confirm items positioned correctly and indexes correct - for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) { + for (int i = firstVisibleIndex; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); qreal pos = i*20.0 + itemsOffsetAfterMove; @@ -1612,7 +1612,7 @@ void tst_QQuickListView::multipleChanges(bool condensed) QTRY_VERIFY(listview != nullptr); QVERIFY(QQuickTest::qWaitForPolish(listview)); - for (int i=0; i<changes.count(); i++) { + for (int i=0; i<changes.size(); i++) { switch (changes[i].type) { case ListChange::Inserted: { @@ -1651,7 +1651,7 @@ void tst_QQuickListView::multipleChanges(bool condensed) QQuickText *number; QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -2048,7 +2048,7 @@ void tst_QQuickListView::spacing() QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2060,7 +2060,7 @@ void tst_QQuickListView::spacing() QTRY_COMPARE(listview->spacing(), qreal(10)); // Confirm items positioned correctly - QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").count() == 11); + QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").size() == 11); for (int i = 0; i < 11; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2071,7 +2071,7 @@ void tst_QQuickListView::spacing() listview->setSpacing(0); // Confirm items positioned correctly - QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").count() >= 16); + QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").size() >= 16); for (int i = 0; i < 16; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -2105,7 +2105,7 @@ void tst_QQuickListView::sections(const QUrl &source) QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY(item); @@ -2159,12 +2159,12 @@ void tst_QQuickListView::sections(const QUrl &source) listview->setContentY(140); QTRY_COMPARE(listview->currentSection(), QString("1")); - QTRY_COMPARE(currentSectionChangedSpy.count(), 1); + QTRY_COMPARE(currentSectionChangedSpy.size(), 1); listview->setContentY(20); QTRY_COMPARE(listview->currentSection(), QString("0")); - QTRY_COMPARE(currentSectionChangedSpy.count(), 2); + QTRY_COMPARE(currentSectionChangedSpy.size(), 2); item = findItem<QQuickItem>(contentItem, "wrapper", 1); QTRY_VERIFY(item); @@ -2214,7 +2214,7 @@ void tst_QQuickListView::sectionsDelegate() QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QTRY_VERIFY(item); @@ -2256,7 +2256,7 @@ void tst_QQuickListView::sectionsDelegate() // QTBUG-17606 QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "sect_1"); - QCOMPARE(items.count(), 1); + QCOMPARE(items.size(), 1); // QTBUG-17759 model.modifyItem(0, "One", "aaa"); @@ -2272,10 +2272,10 @@ void tst_QQuickListView::sectionsDelegate() model.modifyItem(10, "Two", "aaa"); model.modifyItem(11, "Two", "aaa"); QVERIFY(QQuickTest::qWaitForPolish(listview)); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "sect_aaa").count(), 1); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "sect_aaa").size(), 1); window->rootObject()->setProperty("sectionProperty", "name"); // ensure view has settled. - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "sect_Four").count(), 1); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "sect_Four").size(), 1); for (int i = 0; i < 4; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "sect_" + model.name(i*3)); @@ -2631,8 +2631,8 @@ void tst_QQuickListView::sectionDelegateChange() QQuickTest::qWaitForPolish(listview); - QVERIFY(findItems<QQuickItem>(contentItem, "section1").count() > 0); - QCOMPARE(findItems<QQuickItem>(contentItem, "section2").count(), 0); + QVERIFY(findItems<QQuickItem>(contentItem, "section1").size() > 0); + QCOMPARE(findItems<QQuickItem>(contentItem, "section2").size(), 0); for (int i = 0; i < 3; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "item", i); @@ -2643,8 +2643,8 @@ void tst_QQuickListView::sectionDelegateChange() QMetaObject::invokeMethod(window->rootObject(), "switchDelegates"); QQuickTest::qWaitForPolish(listview); - QCOMPARE(findItems<QQuickItem>(contentItem, "section1").count(), 0); - QVERIFY(findItems<QQuickItem>(contentItem, "section2").count() > 0); + QCOMPARE(findItems<QQuickItem>(contentItem, "section1").size(), 0); + QVERIFY(findItems<QQuickItem>(contentItem, "section2").size() > 0); for (int i = 0; i < 3; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "item", i); @@ -2691,7 +2691,7 @@ void tst_QQuickListView::sectionsItemInsertion() QVERIFY(QQuickTest::qWaitForPolish(listview)); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QVERIFY(itemCount > 10); // Verify that the new items are postioned correctly, and have the correct attached section properties @@ -2791,7 +2791,7 @@ void tst_QQuickListView::currentIndex_delayedItemCreation() QSignalSpy spy(listview, SIGNAL(currentItemChanged())); //QCOMPARE(listview->currentIndex(), 0); listview->forceLayout(); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); releaseView(window); } @@ -3193,7 +3193,7 @@ void tst_QQuickListView::cacheBuffer() QTRY_VERIFY(listview->highlight() != nullptr); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3224,7 +3224,7 @@ void tst_QQuickListView::cacheBuffer() } int newItemCount = 0; - newItemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + newItemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); // Confirm items positioned correctly for (int i = 0; i < model.count() && i < newItemCount; ++i) { @@ -3360,7 +3360,7 @@ void tst_QQuickListView::positionViewAtIndex() QTRY_COMPARE(listview->contentY(), contentY); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = index; i < model.count() && i < itemCount-index-1; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3493,13 +3493,13 @@ void tst_QQuickListView::propertyChanges() QTRY_COMPARE(listView->cacheBuffer(), 3); QTRY_COMPARE(listView->snapMode(), QQuickListView::SnapOneItem); - QTRY_COMPARE(highlightFollowsCurrentItemSpy.count(),1); - QTRY_COMPARE(preferredHighlightBeginSpy.count(),1); - QTRY_COMPARE(preferredHighlightEndSpy.count(),1); - QTRY_COMPARE(highlightRangeModeSpy.count(),1); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); - QTRY_COMPARE(cacheBufferSpy.count(),1); - QTRY_COMPARE(snapModeSpy.count(),1); + QTRY_COMPARE(highlightFollowsCurrentItemSpy.size(),1); + QTRY_COMPARE(preferredHighlightBeginSpy.size(),1); + QTRY_COMPARE(preferredHighlightEndSpy.size(),1); + QTRY_COMPARE(highlightRangeModeSpy.size(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),1); + QTRY_COMPARE(cacheBufferSpy.size(),1); + QTRY_COMPARE(snapModeSpy.size(),1); listView->setHighlightFollowsCurrentItem(false); listView->setPreferredHighlightBegin(1.0); @@ -3509,13 +3509,13 @@ void tst_QQuickListView::propertyChanges() listView->setCacheBuffer(3); listView->setSnapMode(QQuickListView::SnapOneItem); - QTRY_COMPARE(highlightFollowsCurrentItemSpy.count(),1); - QTRY_COMPARE(preferredHighlightBeginSpy.count(),1); - QTRY_COMPARE(preferredHighlightEndSpy.count(),1); - QTRY_COMPARE(highlightRangeModeSpy.count(),1); - QTRY_COMPARE(keyNavigationWrapsSpy.count(),1); - QTRY_COMPARE(cacheBufferSpy.count(),1); - QTRY_COMPARE(snapModeSpy.count(),1); + QTRY_COMPARE(highlightFollowsCurrentItemSpy.size(),1); + QTRY_COMPARE(preferredHighlightBeginSpy.size(),1); + QTRY_COMPARE(preferredHighlightEndSpy.size(),1); + QTRY_COMPARE(highlightRangeModeSpy.size(),1); + QTRY_COMPARE(keyNavigationWrapsSpy.size(),1); + QTRY_COMPARE(cacheBufferSpy.size(),1); + QTRY_COMPARE(snapModeSpy.size(),1); } void tst_QQuickListView::componentChanges() @@ -3547,20 +3547,20 @@ void tst_QQuickListView::componentChanges() QTRY_COMPARE(listView->footer(), &component); QTRY_COMPARE(listView->delegate(), &delegateComponent); - QTRY_COMPARE(highlightSpy.count(),1); - QTRY_COMPARE(delegateSpy.count(),1); - QTRY_COMPARE(headerSpy.count(),1); - QTRY_COMPARE(footerSpy.count(),1); + QTRY_COMPARE(highlightSpy.size(),1); + QTRY_COMPARE(delegateSpy.size(),1); + QTRY_COMPARE(headerSpy.size(),1); + QTRY_COMPARE(footerSpy.size(),1); listView->setHighlight(&component); listView->setHeader(&component); listView->setFooter(&component); listView->setDelegate(&delegateComponent); - QTRY_COMPARE(highlightSpy.count(),1); - QTRY_COMPARE(delegateSpy.count(),1); - QTRY_COMPARE(headerSpy.count(),1); - QTRY_COMPARE(footerSpy.count(),1); + QTRY_COMPARE(highlightSpy.size(),1); + QTRY_COMPARE(delegateSpy.size(),1); + QTRY_COMPARE(headerSpy.size(),1); + QTRY_COMPARE(footerSpy.size(),1); } void tst_QQuickListView::modelChanges() @@ -3578,13 +3578,13 @@ void tst_QQuickListView::modelChanges() listView->setModel(modelVariant); QTRY_COMPARE(listView->model(), modelVariant); - QTRY_COMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.size(),1); listView->setModel(modelVariant); - QTRY_COMPARE(modelSpy.count(),1); + QTRY_COMPARE(modelSpy.size(),1); listView->setModel(QVariant()); - QTRY_COMPARE(modelSpy.count(),2); + QTRY_COMPARE(modelSpy.size(),2); } void tst_QQuickListView::QTBUG_9791() @@ -3606,7 +3606,7 @@ void tst_QQuickListView::QTBUG_9791() qApp->processEvents(); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); QCOMPARE(itemCount, 3); for (int i = 0; i < itemCount; ++i) { @@ -3635,12 +3635,12 @@ void tst_QQuickListView::QTBUG_33568() listview->incrementCurrentIndex(); QTRY_COMPARE(listview->contentY(), -100.0); - QVERIFY(spy.count() > 1); + QVERIFY(spy.size() > 1); spy.clear(); listview->incrementCurrentIndex(); QTRY_COMPARE(listview->contentY(), -50.0); - QVERIFY(spy.count() > 1); + QVERIFY(spy.size() > 1); } void tst_QQuickListView::manualHighlight() @@ -3702,7 +3702,7 @@ void tst_QQuickListView::QTBUG_11105() QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -3719,7 +3719,7 @@ void tst_QQuickListView::QTBUG_11105() ctxt->setContextProperty("testModel", &model2); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); QCOMPARE(itemCount, 5); } @@ -3827,7 +3827,7 @@ void tst_QQuickListView::header() QSignalSpy headerItemSpy(listview, SIGNAL(headerItemChanged())); QMetaObject::invokeMethod(window->rootObject(), "changeHeader"); - QCOMPARE(headerItemSpy.count(), 1); + QCOMPARE(headerItemSpy.size(), 1); header = findItem<QQuickText>(contentItem, "header"); QVERIFY(!header); @@ -4086,7 +4086,7 @@ void tst_QQuickListView::footer() QSignalSpy footerItemSpy(listview, SIGNAL(footerItemChanged())); QMetaObject::invokeMethod(window->rootObject(), "changeFooter"); - QCOMPARE(footerItemSpy.count(), 1); + QCOMPARE(footerItemSpy.size(), 1); footer = findItem<QQuickText>(contentItem, "footer"); QVERIFY(!footer); @@ -4285,26 +4285,24 @@ void tst_QQuickListView::extents_data() QTest::newRow("Vertical, TopToBottom") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom - << QPointF(0, -20) << QPointF(0, 0) - << QPointF(0, 20) << QPointF(240, 20) + << QPointF(0, -20) << QPointF(0, 0) << QPointF(0, 20) << QPointF(0, 20) << QPointF(0, -20) << QPointF(0, -20) << QPointF(0, -20); QTest::newRow("Vertical, BottomToTop") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop - << QPointF(0, 0) << QPointF(0, -30) - << QPointF(0, 320 - 20) << QPointF(240, 320 - 20) // content flow is reversed + << QPointF(0, 0) << QPointF(0, -30) << QPointF(0, 320 - 20) + << QPointF(0, 320 - 20) // content flow is reversed << QPointF(0, -30) << QPointF(0, (-30.0 * 3) - 30) << QPointF(0, (-30.0 * 30) - 30); QTest::newRow("Horizontal, LeftToRight") << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom - << QPointF(-20, 0) << QPointF(0, 0) - << QPointF(20, 0) << QPointF(20, 320) + << QPointF(-20, 0) << QPointF(0, 0) << QPointF(20, 0) << QPointF(20, 0) << QPointF(-20, 0) << QPointF(-20, 0) << QPointF(-20, 0); QTest::newRow("Horizontal, RightToLeft") << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom - << QPointF(0, 0) << QPointF(-30, 0) - << QPointF(240 - 20, 0) << QPointF(240 - 20, 320) // content flow is reversed + << QPointF(0, 0) << QPointF(-30, 0) << QPointF(240 - 20, 0) + << QPointF(240 - 20, 0) // content flow is reversed << QPointF(-30, 0) << QPointF((-240.0 * 3) - 30, 0) << QPointF((-240.0 * 30) - 30, 0); } @@ -4373,7 +4371,7 @@ void tst_QQuickListView::resizeView() QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -4393,16 +4391,16 @@ void tst_QQuickListView::resizeView() // Ensure we handle -ve sizes listview->setHeight(-100); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 1); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 1); listview->setCacheBuffer(200); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 11); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 11); // ensure items in cache become visible listview->setHeight(200); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 21); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 21); - itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -4413,9 +4411,9 @@ void tst_QQuickListView::resizeView() // ensure items outside view become invisible listview->setHeight(100); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).count(), 16); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper", false).size(), 16); - itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper", false).size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -4484,7 +4482,7 @@ void tst_QQuickListView::sizeLessThan1() QVERIFY(QQuickTest::qWaitForPolish(listview)); // Confirm items positioned correctly - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i = 0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -4629,7 +4627,7 @@ void tst_QQuickListView::resizeFirstDelegate() QCOMPARE(listview->contentY(), 0.0); QSignalSpy spy(listview, SIGNAL(contentYChanged())); QTest::qWait(100); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); for (int i = 1; i < model.count(); ++i) { item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -4697,13 +4695,13 @@ void tst_QQuickListView::repositionResizedDelegate() listview->setContentX(contentPos_itemFirstHalfVisible.x()); listview->setContentY(contentPos_itemFirstHalfVisible.y()); QVERIFY(QQuickTest::qWaitForPolish(listview)); - prevSpyCount = spy.count(); + prevSpyCount = spy.size(); QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "incrementRepeater")); QTRY_COMPARE(positioner->boundingRect().size(), resizedPositionerRect.size()); QTRY_COMPARE(positioner->position(), resizedPositionerRect.topLeft()); QCOMPARE(listview->contentX(), contentPos_itemFirstHalfVisible.x()); QCOMPARE(listview->contentY(), contentPos_itemFirstHalfVisible.y()); - QCOMPARE(spy.count(), prevSpyCount); + QCOMPARE(spy.size(), prevSpyCount); QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "decrementRepeater")); QTRY_COMPARE(positioner->boundingRect().size(), origPositionerRect.size()); @@ -4714,7 +4712,7 @@ void tst_QQuickListView::repositionResizedDelegate() listview->setContentX(contentPos_itemSecondHalfVisible.x()); listview->setContentY(contentPos_itemSecondHalfVisible.y()); QVERIFY(QQuickTest::qWaitForPolish(listview)); - prevSpyCount = spy.count(); + prevSpyCount = spy.size(); QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "incrementRepeater")); positioner = findItem<QQuickItem>(window->rootObject(), "positioner"); @@ -4723,7 +4721,7 @@ void tst_QQuickListView::repositionResizedDelegate() QCOMPARE(listview->contentX(), contentPos_itemSecondHalfVisible.x()); QCOMPARE(listview->contentY(), contentPos_itemSecondHalfVisible.y()); qApp->processEvents(); - QCOMPARE(spy.count(), prevSpyCount); + QCOMPARE(spy.size(), prevSpyCount); releaseView(window); } @@ -4913,8 +4911,8 @@ void tst_QQuickListView::onAdd() QTRY_COMPARE(listview->property("count").toInt(), model.count()); QVariantList result = listview->property("addedDelegates").toList(); - QCOMPARE(result.count(), items.count()); - for (int i=0; i<items.count(); i++) + QCOMPARE(result.size(), items.size()); + for (int i=0; i<items.size(); i++) QCOMPARE(result[i].toString(), items[i].first); } @@ -6021,7 +6019,7 @@ void tst_QQuickListView::snapOneItemResize_QTBUG_43555() QVERIFY(QQuickTest::qWaitForPolish(listview)); QTRY_COMPARE(listview->currentIndex(), 5); - QCOMPARE(currentIndexSpy.count(), 0); + QCOMPARE(currentIndexSpy.size(), 0); } void tst_QQuickListView::qAbstractItemModel_package_items() @@ -6345,7 +6343,7 @@ void tst_QQuickListView::snapOneItem() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(listview->currentIndex(), 1); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); } // flick to end @@ -6363,7 +6361,7 @@ void tst_QQuickListView::snapOneItem() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(listview->currentIndex(), 3); - QCOMPARE(currentIndexSpy.count(), 3); + QCOMPARE(currentIndexSpy.size(), 3); } // flick to start @@ -6381,7 +6379,7 @@ void tst_QQuickListView::snapOneItem() if (QQuickItemView::HighlightRangeMode(highlightRangeMode) == QQuickItemView::StrictlyEnforceRange) { QCOMPARE(listview->currentIndex(), 0); - QCOMPARE(currentIndexSpy.count(), 6); + QCOMPARE(currentIndexSpy.size(), 6); } releaseView(window); @@ -6407,7 +6405,7 @@ void tst_QQuickListView::snapOneItemCurrentIndexRemoveAnimation() QVERIFY(QQuickTest::qWaitForPolish(listview)); QCOMPARE(listview->currentIndex(), 0); - QCOMPARE(currentIndexSpy.count(), 0); + QCOMPARE(currentIndexSpy.size(), 0); } void tst_QQuickListView::snapOneItemWrongDirection() @@ -6711,7 +6709,7 @@ void tst_QQuickListView::populateTransitions() QCOMPARE(listview->property("countAddTransitions").toInt(), 0); } - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -6734,7 +6732,7 @@ void tst_QQuickListView::populateTransitions() window->rootContext()->setContextProperty("testModel", QVariant()); listview->forceLayout(); QTRY_COMPARE(listview->count(), 0); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").size(), 0); listview->setProperty("countPopulateTransitions", 0); listview->setProperty("countAddTransitions", 0); @@ -6746,7 +6744,7 @@ void tst_QQuickListView::populateTransitions() QTRY_COMPARE(listview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 16 : 0); QTRY_COMPARE(listview->property("countAddTransitions").toInt(), 0); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -6764,7 +6762,7 @@ void tst_QQuickListView::populateTransitions() QTRY_COMPARE(listview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 16 : 0); QTRY_COMPARE(listview->property("countAddTransitions").toInt(), 0); - itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=0; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -6903,7 +6901,7 @@ void tst_QQuickListView::addTransitions() targetIndexes << i; } } - QVERIFY(expectedTargetData.count() > 0); + QVERIFY(expectedTargetData.size() > 0); } // start animation @@ -6916,7 +6914,7 @@ void tst_QQuickListView::addTransitions() QList<QQuickItem *> targetItems = findItems<QQuickItem>(contentItem, "wrapper", targetIndexes); if (shouldAnimateTargets) { - QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(listview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -6943,8 +6941,8 @@ void tst_QQuickListView::addTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - int itemCount = items.count(); - for (int i=0; i<items.count(); i++) { + int itemCount = items.size(); + for (int i=0; i<items.size(); i++) { if (items[i]->y() >= contentY) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); firstVisibleIndex = e.evaluate().toInt(); @@ -7103,7 +7101,7 @@ void tst_QQuickListView::moveTransitions() // start animation model.moveItems(moveFrom, moveTo, moveCount); - QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(listview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -7127,7 +7125,7 @@ void tst_QQuickListView::moveTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { if (items[i]->y() >= contentY) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); firstVisibleIndex = e.evaluate().toInt(); @@ -7137,7 +7135,7 @@ void tst_QQuickListView::moveTransitions() QVERIFY2(firstVisibleIndex >= 0, QByteArray::number(firstVisibleIndex)); // verify all items moved to the correct final positions - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); + int itemCount = findItems<QQuickItem>(contentItem, "wrapper").size(); for (int i=firstVisibleIndex; i < model.count() && i < itemCount; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); @@ -7297,13 +7295,13 @@ void tst_QQuickListView::removeTransitions() targetIndexes << i; } } - QVERIFY(expectedTargetData.count() > 0); + QVERIFY(expectedTargetData.size() > 0); } // calculate targetItems and expectedTargets before model changes QList<QQuickItem *> targetItems = findItems<QQuickItem>(contentItem, "wrapper", targetIndexes); QVariantMap expectedTargets; - for (int i=0; i<targetIndexes.count(); i++) + for (int i=0; i<targetIndexes.size(); i++) expectedTargets[model.name(targetIndexes[i])] = targetIndexes[i]; // start animation @@ -7311,7 +7309,7 @@ void tst_QQuickListView::removeTransitions() QTRY_COMPARE(model.count(), listview->count()); if (shouldAnimateTargets) { - QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.count()); + QTRY_COMPARE(listview->property("targetTransitionsDone").toInt(), expectedTargetData.size()); QTRY_COMPARE(listview->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.isValid() ? expectedDisplacedIndexes.count() : 0); @@ -7337,9 +7335,9 @@ void tst_QQuickListView::removeTransitions() QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; - int itemCount = items.count(); + int itemCount = items.size(); - for (int i=0; i<items.count(); i++) { + for (int i=0; i<items.size(); i++) { QQmlExpression e(qmlContext(items[i]), items[i], "index"); int index = e.evaluate().toInt(); if (firstVisibleIndex < 0 && items[i]->y() >= contentY) @@ -7528,15 +7526,15 @@ void tst_QQuickListView::displacedTransitions() QTRY_VERIFY(listview->property("displaceTransitionsDone").toBool()); // check the correct number of target items and indexes were received - QCOMPARE(resultTargetIndexes.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetIndexes.count(); i++) - QCOMPARE(resultTargetIndexes[i].value<QList<int> >().count(), change.count); - QCOMPARE(resultTargetItems.count(), expectedDisplacedIndexes.count()); - for (int i=0; i<resultTargetItems.count(); i++) - QCOMPARE(resultTargetItems[i].toList().count(), change.count); + QCOMPARE(resultTargetIndexes.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetIndexes.size(); i++) + QCOMPARE(resultTargetIndexes[i].value<QList<int> >().size(), change.count); + QCOMPARE(resultTargetItems.size(), expectedDisplacedIndexes.count()); + for (int i=0; i<resultTargetItems.size(); i++) + QCOMPARE(resultTargetItems[i].toList().size(), change.count); } else { - QCOMPARE(resultTargetIndexes.count(), 0); - QCOMPARE(resultTargetItems.count(), 0); + QCOMPARE(resultTargetIndexes.size(), 0); + QCOMPARE(resultTargetItems.size(), 0); } if (change.type == ListChange::Inserted && useAddDisplaced && addDisplacedEnabled) @@ -7563,7 +7561,7 @@ void tst_QQuickListView::displacedTransitions() // verify all items moved to the correct final positions QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - for (int i=0; i < model.count() && i < items.count(); ++i) { + for (int i=0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); QCOMPARE(item->x(), 0.0); @@ -7717,7 +7715,7 @@ void tst_QQuickListView::multipleTransitions() int timeBetweenActions = window->rootObject()->property("timeBetweenActions").toInt(); - for (int i=0; i<changes.count(); i++) { + for (int i=0; i<changes.size(); i++) { switch (changes[i].type) { case ListChange::Inserted: { @@ -7726,7 +7724,7 @@ void tst_QQuickListView::multipleTransitions() targetItems << qMakePair(QString("new item %1").arg(j), QString::number(j)); model.insertItems(changes[i].index, targetItems); QTRY_COMPARE(model.count(), listview->count()); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!listview->property("runningAddTargets").toBool()); QTRY_VERIFY(!listview->property("runningAddDisplaced").toBool()); } else { @@ -7737,7 +7735,7 @@ void tst_QQuickListView::multipleTransitions() case ListChange::Removed: model.removeItems(changes[i].index, changes[i].count); QTRY_COMPARE(model.count(), listview->count()); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!listview->property("runningRemoveTargets").toBool()); QTRY_VERIFY(!listview->property("runningRemoveDisplaced").toBool()); } else { @@ -7747,7 +7745,7 @@ void tst_QQuickListView::multipleTransitions() case ListChange::Moved: model.moveItems(changes[i].index, changes[i].to, changes[i].count); QVERIFY(QQuickTest::qWaitForPolish(listview)); - if (i == changes.count() - 1) { + if (i == changes.size() - 1) { QTRY_VERIFY(!listview->property("runningMoveTargets").toBool()); QTRY_VERIFY(!listview->property("runningMoveDisplaced").toBool()); } else { @@ -7771,7 +7769,7 @@ void tst_QQuickListView::multipleTransitions() // verify all items moved to the correct final positions QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - for (int i=0; i < model.count() && i < items.count(); ++i) { + for (int i=0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); QTRY_COMPARE(item->x(), 0.0); @@ -7880,7 +7878,7 @@ void tst_QQuickListView::multipleDisplaced() // verify all items moved to the correct final positions QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); - for (int i=0; i < model.count() && i < items.count(); ++i) { + for (int i=0; i < model.count() && i < items.size(); ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); QVERIFY2(item, qPrintable(QString("Item %1 not found").arg(i))); QTRY_COMPARE(item->x(), 0.0); @@ -7897,7 +7895,7 @@ QList<int> tst_QQuickListView::toIntList(const QVariantList &list) { QList<int> ret; bool ok = true; - for (int i=0; i<list.count(); i++) { + for (int i=0; i<list.size(); i++) { ret << list[i].toInt(&ok); if (!ok) qWarning() << "tst_QQuickListView::toIntList(): not a number:" << list[i]; @@ -7909,7 +7907,7 @@ QList<int> tst_QQuickListView::toIntList(const QVariantList &list) void tst_QQuickListView::matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes) { const QSet<int> expectedIndexSet(expectedIndexes.cbegin(), expectedIndexes.cend()); - for (int i=0; i<indexLists.count(); i++) { + for (int i=0; i<indexLists.size(); i++) { const auto ¤tList = indexLists[i].value<QList<int> >(); const QSet<int> current(currentList.cbegin(), currentList.cend()); if (current != expectedIndexSet) @@ -7929,20 +7927,20 @@ void tst_QQuickListView::matchItemsAndIndexes(const QVariantMap &items, const Qa qDebug() << itemIndex; QCOMPARE(model.name(itemIndex), name); } - QCOMPARE(items.count(), expectedIndexes.count()); + QCOMPARE(items.size(), expectedIndexes.size()); } void tst_QQuickListView::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { - for (int i=0; i<itemLists.count(); i++) { + for (int i=0; i<itemLists.size(); i++) { QCOMPARE(itemLists[i].typeId(), QMetaType::QVariantList); QVariantList current = itemLists[i].toList(); - for (int j=0; j<current.count(); j++) { + for (int j=0; j<current.size(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); QVERIFY2(o, qPrintable(QString("Invalid actual item at %1").arg(j))); QVERIFY2(expectedItems.contains(o), qPrintable(QString("Cannot match item %1").arg(j))); } - QCOMPARE(current.count(), expectedItems.count()); + QCOMPARE(current.size(), expectedItems.size()); } } @@ -7972,7 +7970,7 @@ void tst_QQuickListView::flickBeyondBounds() // We're really testing that we don't get stuck in a loop, // but also confirm items positioned correctly. - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 2); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").size(), 2); for (int i = 0; i < 2; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); if (!item) qWarning() << "Item" << i << "not found"; @@ -8079,7 +8077,7 @@ void tst_QQuickListView::destroyItemOnCreation() model.addItem("new item", ""); QTRY_COMPARE(window->rootObject()->property("createdIndex").toInt(), 0); - QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0); + QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").size(), 0); QCOMPARE(model.count(), 0); } @@ -9070,11 +9068,11 @@ void tst_QQuickListView::jsArrayChange() } view->setModel(QVariant::fromValue(array1)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // no change view->setModel(QVariant::fromValue(array2)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } static bool compareObjectModel(QQuickListView *listview, QQmlObjectModel *model) @@ -9259,7 +9257,7 @@ void tst_QQuickListView::keyNavigationEnabled() // of disabling both mouse and keyboard interaction. QSignalSpy enabledSpy(listView, SIGNAL(keyNavigationEnabledChanged())); listView->setInteractive(false); - QCOMPARE(enabledSpy.count(), 1); + QCOMPARE(enabledSpy.size(), 1); QCOMPARE(listView->isKeyNavigationEnabled(), false); flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100); @@ -9272,17 +9270,17 @@ void tst_QQuickListView::keyNavigationEnabled() // Check that isKeyNavigationEnabled implicitly follows the value of interactive. listView->setInteractive(true); - QCOMPARE(enabledSpy.count(), 2); + QCOMPARE(enabledSpy.size(), 2); QCOMPARE(listView->isKeyNavigationEnabled(), true); // Change it back again for the next check. listView->setInteractive(false); - QCOMPARE(enabledSpy.count(), 3); + QCOMPARE(enabledSpy.size(), 3); QCOMPARE(listView->isKeyNavigationEnabled(), false); // Setting keyNavigationEnabled to true shouldn't enable mouse interaction. listView->setKeyNavigationEnabled(true); - QCOMPARE(enabledSpy.count(), 4); + QCOMPARE(enabledSpy.size(), 4); flick(window.data(), QPoint(200, 200), QPoint(200, 50), 100); QVERIFY(!listView->isMoving()); QCOMPARE(listView->contentY(), 0.0); @@ -9296,7 +9294,7 @@ void tst_QQuickListView::keyNavigationEnabled() // Changing interactive now shouldn't result in keyNavigationEnabled changing, // since we broke the "binding". listView->setInteractive(true); - QCOMPARE(enabledSpy.count(), 4); + QCOMPARE(enabledSpy.size(), 4); // Keyboard interaction shouldn't work now. listView->setKeyNavigationEnabled(false); @@ -9473,7 +9471,7 @@ void tst_QQuickListView::QTBUG_66163_setModelViewPortSizeChange() delegate: Rectangle { color: index % 2 ? "green" : "orange" - width: parent.width + width: view.width height: 50 } @@ -9504,7 +9502,7 @@ void tst_QQuickListView::QTBUG_66163_setModelViewPortSizeChange() QTest::qWait(1100); // animation takes 1000ms, + 10% extra delay /* the viewport should not have changed, thus there should not have been any contentYChanged signal*/ - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } void tst_QQuickListView::itemFiltered() @@ -9575,7 +9573,7 @@ void tst_QQuickListView::QTBUG_34576_velocityZero() window->rootObject()->setProperty("horizontalVelocityZeroCount", QVariant(0)); listview->setCurrentIndex(2); QTRY_COMPARE(window->rootObject()->property("current").toInt(), 2); - QCOMPARE(horizontalVelocitySpy.count(), 0); + QCOMPARE(horizontalVelocitySpy.size(), 0); QCOMPARE(window->rootObject()->property("horizontalVelocityZeroCount").toInt(), 0); QSignalSpy currentIndexChangedSpy(listview, SIGNAL(currentIndexChanged())); @@ -9585,11 +9583,11 @@ void tst_QQuickListView::QTBUG_34576_velocityZero() QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(295,215)); // verify that currentIndexChanged is triggered - QTRY_VERIFY(currentIndexChangedSpy.count() > 0); + QTRY_VERIFY(currentIndexChangedSpy.size() > 0); // since we have set currentIndex to an item out of view, the listview will scroll QTRY_COMPARE(window->rootObject()->property("current").toInt(), 3); - QTRY_VERIFY(horizontalVelocitySpy.count() > 0); + QTRY_VERIFY(horizontalVelocitySpy.size() > 0); // velocity should be always > 0.0 QTRY_COMPARE(window->rootObject()->property("horizontalVelocityZeroCount").toInt(), 0); @@ -9618,7 +9616,7 @@ void tst_QQuickListView::QTBUG_61537_modelChangesAsync() // Check that the number of delegates we expect to be visible in // the listview matches the number of items we find if we count. int reportedCount = listView->count(); - int actualCount = findItems<QQuickItem>(listView, "delegate").count(); + int actualCount = findItems<QQuickItem>(listView, "delegate").size(); QCOMPARE(reportedCount, actualCount); } @@ -9749,7 +9747,7 @@ public: m_animals.push_back(Animal {5, QLatin1String("Cherry")}); } - int rowCount(const QModelIndex & = QModelIndex()) const override {return m_animals.count();} + int rowCount(const QModelIndex & = QModelIndex()) const override {return m_animals.size();} QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override { if (!checkIndex(index)) @@ -9865,14 +9863,14 @@ void tst_QQuickListView::reuse_checkThatItemsAreReused() QVERIFY(listView->reuseItems()); auto items = findItems<QQuickItem>(listView, "delegate"); - const int initialItemCount = items.count(); + const int initialItemCount = items.size(); QVERIFY(initialItemCount > 0); // Sanity check that the size of the initial list of items match the count we tracked from QML QCOMPARE(listView->property("delegatesCreatedCount").toInt(), initialItemCount); // Go through all the initial items and check that they have not been reused yet - for (const auto item : qAsConst(items)) + for (const auto item : std::as_const(items)) QCOMPARE(item->property("reusedCount").toInt(), 0); // Flick one page down and count how many items we have created thus @@ -9896,7 +9894,7 @@ void tst_QQuickListView::reuse_checkThatItemsAreReused() // QML model classes, we need to catch it through a binding instead (which is // OK, since then we can also check that bindings are updated when reused). items = findItems<QQuickItem>(listView, "delegate"); - for (const auto item : qAsConst(items)) { + for (const auto item : std::as_const(items)) { const QString display = item->property("displayBinding").toString(); const int modelIndex = item->property("modelIndex").toInt(); QVERIFY(modelIndex >= initialItemCount); @@ -9918,7 +9916,7 @@ void tst_QQuickListView::reuse_checkThatItemsAreReused() // (except for ListView.currentItem, which was never released). const auto listViewCurrentItem = listView->currentItem(); items = findItems<QQuickItem>(listView, "delegate"); - for (const auto item : qAsConst(items)) { + for (const auto item : std::as_const(items)) { const int reusedCount = item->property("reusedCount").toInt(); if (item == listViewCurrentItem) QCOMPARE(reusedCount, 0); @@ -9929,7 +9927,7 @@ void tst_QQuickListView::reuse_checkThatItemsAreReused() // Go through all items again and check that all model data inside the delegate // have correct values now that they have been reused. items = findItems<QQuickItem>(listView, "delegate"); - for (const auto item : qAsConst(items)) { + for (const auto item : std::as_const(items)) { const QString display = item->property("displayBinding").toString(); const int modelIndex = item->property("modelIndex").toInt(); QVERIFY(modelIndex < initialItemCount); @@ -10090,9 +10088,9 @@ void tst_QQuickListView::requiredObjectListModel() const auto *root = qobject_cast<QQuickListView *>(view.rootObject()); QVERIFY(root); - QCOMPARE(root->count(), dataList.count()); + QCOMPARE(root->count(), dataList.size()); - for (int i = 0, end = dataList.count(); i != end; ++i) { + for (int i = 0, end = dataList.size(); i != end; ++i) { const auto *rect = qobject_cast<QQuickRectangle *>(root->itemAtIndex(i)); QVERIFY(rect); const auto *data = qobject_cast<DataObject *>(dataList.at(i)); diff --git a/tests/auto/quick/qquicklistview2/data/maxXExtent.qml b/tests/auto/quick/qquicklistview2/data/maxXExtent.qml new file mode 100644 index 0000000000..b9e88cfc9e --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/maxXExtent.qml @@ -0,0 +1,29 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Item { + property alias view: view + + ListView { + id: view + model: 10 + width: 200 + height: 200 + + Rectangle { + anchors.fill: parent + color: "transparent" + border.color: "darkorange" + } + + delegate: Rectangle { + width: 100 + height: 100 + Text { + text: modelData + } + } + } +} diff --git a/tests/auto/quick/qquicklistview2/data/maxYExtent.qml b/tests/auto/quick/qquicklistview2/data/maxYExtent.qml new file mode 100644 index 0000000000..3be8948691 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/maxYExtent.qml @@ -0,0 +1,30 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +import QtQuick + +Item { + property alias view: view + + ListView { + id: view + model: 10 + width: 200 + height: 200 + orientation: ListView.Horizontal + + Rectangle { + anchors.fill: parent + color: "transparent" + border.color: "darkorange" + } + + delegate: Rectangle { + width: 100 + height: 100 + Text { + text: modelData + } + } + } +} diff --git a/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml b/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml new file mode 100644 index 0000000000..919cf4d2ec --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/qtbug104679_footer.qml @@ -0,0 +1,21 @@ +import QtQuick + +Rectangle { + width: 640 + height: 480 + + ListView { + anchors.fill: parent + spacing: 5 + + footerPositioning: ListView.PullBackFooter + footer: Rectangle { width: ListView.view.width; color: "blue"; implicitHeight: 46 } + + model: 3 // crashed if less items than a full list page + delegate: Rectangle { + width: ListView.view.width + height: 50 + color: index % 2 ? "black" : "gray" + } + } +} diff --git a/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml b/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml new file mode 100644 index 0000000000..40ddf27988 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/qtbug104679_header.qml @@ -0,0 +1,21 @@ +import QtQuick + +Rectangle { + width: 640 + height: 480 + + ListView { + anchors.fill: parent + spacing: 5 + + headerPositioning: ListView.PullBackHeader + header: Rectangle { width: ListView.view.width; color: "red"; implicitHeight: 46 } + + model: 3 // crashed if less items than a full list page + delegate: Rectangle { + width: ListView.view.width + height: 50 + color: index % 2 ? "black" : "gray" + } + } +} diff --git a/tests/auto/quick/qquicklistview2/data/qtbug86744.qml b/tests/auto/quick/qquicklistview2/data/qtbug86744.qml new file mode 100644 index 0000000000..c69a4f7ec6 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/qtbug86744.qml @@ -0,0 +1,25 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQml.Models + +Item { + height: 200 + width: 100 + DelegateModel { + id: dm + model: 2 + delegate: Item { + width: 100 + height: 20 + property bool isCurrent: ListView.isCurrentItem + } + } + ListView { + objectName: "listView" + model: dm + currentIndex: 1 + anchors.fill: parent + } +} diff --git a/tests/auto/quick/qquicklistview2/data/qtbug98315.qml b/tests/auto/quick/qquicklistview2/data/qtbug98315.qml new file mode 100644 index 0000000000..bf2ed857b1 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/qtbug98315.qml @@ -0,0 +1,98 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQml.Models + +Item { + width: 500 + height: 200 + + property list<QtObject> myModel: [ + QtObject { + objectName: "Item 0" + property bool selected: true + }, + QtObject { + objectName: "Item 1" + property bool selected: false + }, + QtObject { + objectName: "Item 2" + property bool selected: false + }, + QtObject { + objectName: "Item 3" + property bool selected: true + }, + QtObject { + objectName: "Item 4" + property bool selected: true + }, + QtObject { + objectName: "Item 5" + property bool selected: true + }, + QtObject { + objectName: "Item 6" + property bool selected: false + } + ] + + ListView { + objectName: "listView" + id: listview + width: 500 + height: 200 + + focus: true + clip: true + spacing: 2 + orientation: ListView.Horizontal + highlightMoveDuration: 300 + highlightMoveVelocity: -1 + preferredHighlightBegin: (500 - 100) / 2 + preferredHighlightEnd: (500 + 100) / 2 + highlightRangeMode: ListView.StrictlyEnforceRange + cacheBuffer: 500 + currentIndex: 1 + + model: DelegateModel { + id: delegateModel + filterOnGroup: "visible" + model: myModel + groups: [ + DelegateModelGroup { + name: "visible" + includeByDefault: true + } + ] + delegate: Rectangle { + id: tile + objectName: model.modelData.objectName + + width: 100 + height: 100 + border.width: 0 + anchors.verticalCenter: parent.verticalCenter + + visible: model.modelData.selected + Component.onCompleted: { + DelegateModel.inPersistedItems = true + DelegateModel.inVisible = Qt.binding(function () { + return model.modelData.selected + }) + } + + property bool isCurrent: ListView.isCurrentItem + color: isCurrent ? "red" : "green" + + Text { + id: valueText + anchors.centerIn: parent + text: model.modelData.objectName + } + } + } + } +} diff --git a/tests/auto/quick/qquicklistview2/data/snapOneItem.qml b/tests/auto/quick/qquicklistview2/data/snapOneItem.qml new file mode 100644 index 0000000000..a27f220865 --- /dev/null +++ b/tests/auto/quick/qquicklistview2/data/snapOneItem.qml @@ -0,0 +1,34 @@ +import QtQuick + +ListView { + id: list + snapMode: ListView.SnapOneItem + model: 4 + width: 200 + height: 200 + highlightRangeMode: ListView.StrictlyEnforceRange + highlight: Rectangle { width: 200; height: 200; color: "yellow" } + delegate: Rectangle { + id: wrapper + width: list.width + height: list.height + Column { + Text { + text: index + } + Text { + text: wrapper.x + ", " + wrapper.y + } + } + color: ListView.isCurrentItem ? "lightsteelblue" : "transparent" + } + // speed up test runs + flickDeceleration: 5000 + rebound: Transition { + NumberAnimation { + properties: "x,y" + duration: 30 + easing.type: Easing.OutBounce + } + } +} diff --git a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp index 8684439d24..98cb3cc20c 100644 --- a/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp +++ b/tests/auto/quick/qquicklistview2/tst_qquicklistview2.cpp @@ -33,6 +33,8 @@ private slots: void footerUpdate(); void singletonModelLifetime(); void delegateModelRefresh(); + void wheelSnap(); + void wheelSnap_data(); void sectionsNoOverlap(); void metaSequenceAsModel(); @@ -43,6 +45,12 @@ private slots: void tapDelegateDuringFlicking(); void flickDuringFlicking_data(); void flickDuringFlicking(); + void maxExtent_data(); + void maxExtent(); + void isCurrentItem_DelegateModel(); + void isCurrentItem_NoRegressionWithDelegateModelGroups(); + + void pullbackSparseList(); private: void flickWithTouch(QQuickWindow *window, const QPoint &from, const QPoint &to); @@ -273,7 +281,7 @@ void tst_QQuickListView2::metaSequenceAsModel() QScopedPointer<QObject> o(c.create()); QVERIFY(!o.isNull()); QStringList strings = qvariant_cast<QStringList>(o->property("texts")); - QCOMPARE(strings.length(), 2); + QCOMPARE(strings.size(), 2); QCOMPARE(strings[0], QStringLiteral("1/2")); QCOMPARE(strings[1], QStringLiteral("5/6")); } @@ -430,7 +438,7 @@ void tst_QQuickListView2::tapDelegateDuringFlicking() // QTBUG-103832 QVERIFY(lastPressed > 5); QCOMPARE(releasedDelegates.last(), lastPressed); QCOMPARE(tappedDelegates.last(), lastPressed); - QCOMPARE(canceledDelegates.count(), 1); // only the first press was canceled, not the second + QCOMPARE(canceledDelegates.size(), 1); // only the first press was canceled, not the second } void tst_QQuickListView2::flickDuringFlicking_data() @@ -539,6 +547,391 @@ void tst_QQuickListView2::delegateModelRefresh() QTRY_VERIFY(engine.rootObjects().first()->property("done").toBool()); } +void tst_QQuickListView2::wheelSnap() +{ + QFETCH(QQuickListView::Orientation, orientation); + QFETCH(Qt::LayoutDirection, layoutDirection); + QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection); + QFETCH(QQuickItemView::HighlightRangeMode, highlightRangeMode); + QFETCH(QPoint, forwardAngleDelta); + QFETCH(qreal, snapAlignment); + QFETCH(qreal, endExtent); + QFETCH(qreal, startExtent); + QFETCH(qreal, preferredHighlightBegin); + QFETCH(qreal, preferredHighlightEnd); + + // Helpers begin + quint64 timestamp = 10; + auto sendWheelEvent = [×tamp](QQuickView *window, const QPoint &angleDelta) { + QPoint pos(100, 100); + QWheelEvent event(pos, window->mapToGlobal(pos), QPoint(), angleDelta, Qt::NoButton, + Qt::NoModifier, Qt::NoScrollPhase, false); + event.setAccepted(false); + event.setTimestamp(timestamp); + QGuiApplication::sendEvent(window, &event); + timestamp += 50; + }; + + auto atEnd = [&layoutDirection, &orientation, + &verticalLayoutDirection](QQuickListView *listview) { + if (orientation == QQuickListView::Horizontal) { + if (layoutDirection == Qt::LeftToRight) + return listview->isAtXEnd(); + + return listview->isAtXBeginning(); + } else { + if (verticalLayoutDirection == QQuickItemView::VerticalLayoutDirection::TopToBottom) + return listview->isAtYEnd(); + + return listview->isAtYBeginning(); + } + }; + + auto atBegin = [&layoutDirection, &orientation, + &verticalLayoutDirection](QQuickListView *listview) { + if (orientation == QQuickListView::Horizontal) { + if (layoutDirection == Qt::LeftToRight) + return listview->isAtXBeginning(); + + return listview->isAtXEnd(); + } else { + if (verticalLayoutDirection == QQuickItemView::VerticalLayoutDirection::TopToBottom) + return listview->isAtYBeginning(); + + return listview->isAtYEnd(); + } + }; + // Helpers end + + QScopedPointer<QQuickView> window(createView()); + QTRY_VERIFY(window); + QQuickViewTestUtils::moveMouseAway(window.data()); + window->setSource(testFileUrl("snapOneItem.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = qobject_cast<QQuickListView *>(window->rootObject()); + QTRY_VERIFY(listview); + + listview->setOrientation(orientation); + listview->setVerticalLayoutDirection(verticalLayoutDirection); + listview->setLayoutDirection(layoutDirection); + listview->setHighlightRangeMode(highlightRangeMode); + listview->setPreferredHighlightBegin(preferredHighlightBegin); + listview->setPreferredHighlightEnd(preferredHighlightEnd); + QVERIFY(QQuickTest::qWaitForPolish(listview)); + + QQuickItem *contentItem = listview->contentItem(); + QTRY_VERIFY(contentItem); + + QSignalSpy currentIndexSpy(listview, &QQuickListView::currentIndexChanged); + + // confirm that a flick hits the next item boundary + int indexCounter = 0; + sendWheelEvent(window.data(), forwardAngleDelta); + QTRY_VERIFY(listview->isMoving() == false); // wait until it stops + + if (orientation == QQuickListView::Vertical) + QCOMPARE(listview->contentY(), snapAlignment); + else + QCOMPARE(listview->contentX(), snapAlignment); + + if (highlightRangeMode == QQuickItemView::StrictlyEnforceRange) { + ++indexCounter; + QTRY_VERIFY(listview->currentIndex() == indexCounter); + } + + // flick to end + do { + sendWheelEvent(window.data(), forwardAngleDelta); + QTRY_VERIFY(listview->isMoving() == false); // wait until it stops + if (highlightRangeMode == QQuickItemView::StrictlyEnforceRange) { + ++indexCounter; + QTRY_VERIFY(listview->currentIndex() == indexCounter); + } + } while (!atEnd(listview)); + + if (orientation == QQuickListView::Vertical) + QCOMPARE(listview->contentY(), endExtent); + else + QCOMPARE(listview->contentX(), endExtent); + + if (highlightRangeMode == QQuickItemView::StrictlyEnforceRange) { + QCOMPARE(listview->currentIndex(), listview->count() - 1); + QCOMPARE(currentIndexSpy.size(), listview->count() - 1); + } + + // flick to start + const QPoint backwardAngleDelta(-forwardAngleDelta.x(), -forwardAngleDelta.y()); + do { + sendWheelEvent(window.data(), backwardAngleDelta); + QTRY_VERIFY(listview->isMoving() == false); // wait until it stops + if (highlightRangeMode == QQuickItemView::StrictlyEnforceRange) { + --indexCounter; + QTRY_VERIFY(listview->currentIndex() == indexCounter); + } + } while (!atBegin(listview)); + + if (orientation == QQuickListView::Vertical) + QCOMPARE(listview->contentY(), startExtent); + else + QCOMPARE(listview->contentX(), startExtent); + + if (highlightRangeMode == QQuickItemView::StrictlyEnforceRange) { + QCOMPARE(listview->currentIndex(), 0); + QCOMPARE(currentIndexSpy.size(), (listview->count() - 1) * 2); + } +} + +void tst_QQuickListView2::wheelSnap_data() +{ + QTest::addColumn<QQuickListView::Orientation>("orientation"); + QTest::addColumn<Qt::LayoutDirection>("layoutDirection"); + QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection"); + QTest::addColumn<QQuickItemView::HighlightRangeMode>("highlightRangeMode"); + QTest::addColumn<QPoint>("forwardAngleDelta"); + QTest::addColumn<qreal>("snapAlignment"); + QTest::addColumn<qreal>("endExtent"); + QTest::addColumn<qreal>("startExtent"); + QTest::addColumn<qreal>("preferredHighlightBegin"); + QTest::addColumn<qreal>("preferredHighlightEnd"); + + QTest::newRow("vertical, top to bottom") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(20, -120) << 200.0 << 600.0 << 0.0 << 0.0 + << 0.0; + + QTest::newRow("vertical, bottom to top") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::NoHighlightRange << QPoint(20, 120) << -400.0 << -800.0 << -200.0 + << 0.0 << 0.0; + + QTest::newRow("horizontal, left to right") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(-120, 20) << 200.0 << 600.0 << 0.0 << 0.0 + << 0.0; + + QTest::newRow("horizontal, right to left") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(120, 20) << -400.0 << -800.0 << -200.0 + << 0.0 << 0.0; + + QTest::newRow("vertical, top to bottom, enforce range") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(20, -120) << 200.0 << 600.0 << 0.0 + << 0.0 << 0.0; + + QTest::newRow("vertical, bottom to top, enforce range") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::StrictlyEnforceRange << QPoint(20, 120) << -400.0 << -800.0 << -200.0 + << 0.0 << 0.0; + + QTest::newRow("horizontal, left to right, enforce range") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(-120, 20) << 200.0 << 600.0 << 0.0 + << 0.0 << 0.0; + + QTest::newRow("horizontal, right to left, enforce range") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(120, 20) << -400.0 << -800.0 << -200.0 + << 0.0 << 0.0; + + QTest::newRow("vertical, top to bottom, apply range") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(20, -120) << 200.0 << 600.0 << 0.0 << 0.0 + << 0.0; + + QTest::newRow("vertical, bottom to top, apply range") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::ApplyRange << QPoint(20, 120) << -400.0 << -800.0 << -200.0 << 0.0 + << 0.0; + + QTest::newRow("horizontal, left to right, apply range") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(-120, 20) << 200.0 << 600.0 << 0.0 << 0.0 + << 0.0; + + QTest::newRow("horizontal, right to left, apply range") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(120, 20) << -400.0 << -800.0 << -200.0 << 0.0 + << 0.0; + + QTest::newRow("vertical, top to bottom with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(20, -120) << 190.0 << 600.0 << 0.0 << 10.0 + << 210.0; + + QTest::newRow("vertical, bottom to top with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::NoHighlightRange << QPoint(20, 120) << -390.0 << -800.0 << -200.0 + << 10.0 << 210.0; + + QTest::newRow("horizontal, left to right with highlightRange") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(-120, 20) << 190.0 << 600.0 << 0.0 << 10.0 + << 210.0; + + QTest::newRow("horizontal, right to left with highlightRange") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::NoHighlightRange << QPoint(120, 20) << -390.0 << -800.0 << -200.0 + << 10.0 << 210.0; + + QTest::newRow("vertical, top to bottom, enforce range with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(20, -120) << 190.0 << 590.0 << -10.0 + << 10.0 << 210.0; + + QTest::newRow("vertical, bottom to top, enforce range with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::StrictlyEnforceRange << QPoint(20, 120) << -390.0 << -790.0 << -190.0 + << 10.0 << 210.0; + + QTest::newRow("horizontal, left to right, enforce range with highlightRange") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(-120, 20) << 190.0 << 590.0 << -10.0 + << 10.0 << 210.0; + + QTest::newRow("horizontal, right to left, enforce range with highlightRange") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::StrictlyEnforceRange << QPoint(120, 20) << -390.0 << -790.0 << -190.0 + << 10.0 << 210.0; + + QTest::newRow("vertical, top to bottom, apply range with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(20, -120) << 190.0 << 600.0 << 0.0 << 10.0 + << 210.0; + + QTest::newRow("vertical, bottom to top, apply range with highlightRange") + << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop + << QQuickItemView::ApplyRange << QPoint(20, 120) << -390.0 << -800.0 << -200.0 << 10.0 + << 210.0; + + QTest::newRow("horizontal, left to right, apply range with highlightRange") + << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(-120, 20) << 190.0 << 600.0 << 0.0 << 10.0 + << 210.0; + + QTest::newRow("horizontal, right to left, apply range with highlightRange") + << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom + << QQuickItemView::ApplyRange << QPoint(120, 20) << -390.0 << -800.0 << -200.0 << 10.0 + << 210.0; +} + +class FriendlyItemView : public QQuickItemView +{ + friend class ItemViewAccessor; +}; + +class ItemViewAccessor +{ +public: + ItemViewAccessor(QQuickItemView *itemView) : + mItemView(reinterpret_cast<FriendlyItemView*>(itemView)) + { + } + + qreal maxXExtent() const + { + return mItemView->maxXExtent(); + } + + qreal maxYExtent() const + { + return mItemView->maxYExtent(); + } + +private: + FriendlyItemView *mItemView = nullptr; +}; + +void tst_QQuickListView2::maxExtent_data() +{ + QTest::addColumn<QString>("qmlFilePath"); + QTest::addRow("maxXExtent") << "maxXExtent.qml"; + QTest::addRow("maxYExtent") << "maxYExtent.qml"; +} + +void tst_QQuickListView2::maxExtent() +{ + QFETCH(QString, qmlFilePath); + + QScopedPointer<QQuickView> window(createView()); + QVERIFY(window); + window->setSource(testFileUrl(qmlFilePath)); + QVERIFY2(window->status() == QQuickView::Ready, qPrintable(QDebug::toString(window->errors()))); + window->resize(640, 480); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *view = window->rootObject()->property("view").value<QQuickListView*>(); + QVERIFY(view); + ItemViewAccessor viewAccessor(view); + if (view->orientation() == QQuickListView::Vertical) + QCOMPARE(viewAccessor.maxXExtent(), 0); + else if (view->orientation() == QQuickListView::Horizontal) + QCOMPARE(viewAccessor.maxYExtent(), 0); +} + +void tst_QQuickListView2::isCurrentItem_DelegateModel() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("qtbug86744.qml")); + window->resize(640, 480); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickListView* listView = window->rootObject()->findChild<QQuickListView*>("listView"); + QVERIFY(listView); + QVariant value = listView->itemAtIndex(1)->property("isCurrent"); + QVERIFY(value.toBool() == true); +} + +void tst_QQuickListView2::isCurrentItem_NoRegressionWithDelegateModelGroups() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("qtbug98315.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + QQuickListView* listView = window->rootObject()->findChild<QQuickListView*>("listView"); + QVERIFY(listView); + + QQuickItem *item3 = listView->itemAtIndex(1); + QVERIFY(item3); + QCOMPARE(item3->property("isCurrent").toBool(), true); + + QObject *item0 = listView->itemAtIndex(0); + QVERIFY(item0); + QCOMPARE(item0->property("isCurrent").toBool(), false); + + // Press left arrow key -> Item 1 should become current, Item 3 should not + // be current anymore. After a previous fix of QTBUG-86744 it was working + // incorrectly - see QTBUG-98315 + QTest::keyPress(window.get(), Qt::Key_Left); + + QTRY_COMPARE(item0->property("isCurrent").toBool(), true); + QCOMPARE(item3->property("isCurrent").toBool(), false); +} + +void tst_QQuickListView2::pullbackSparseList() // QTBUG_104679 +{ + // check if PullbackHeader crashes + QScopedPointer<QQuickView> window(createView()); + QVERIFY(window); + window->setSource(testFileUrl("qtbug104679_header.qml")); + QVERIFY2(window->status() == QQuickView::Ready, qPrintable(QDebug::toString(window->errors()))); + window->resize(640, 480); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + // check if PullbackFooter crashes + window.reset(createView()); + QVERIFY(window); + window->setSource(testFileUrl("qtbug104679_footer.qml")); + QVERIFY2(window->status() == QQuickView::Ready, qPrintable(QDebug::toString(window->errors()))); + window->resize(640, 480); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); +} + QTEST_MAIN(tst_QQuickListView2) #include "tst_qquicklistview2.moc" diff --git a/tests/auto/quick/qquickloader/data/overflow.qml b/tests/auto/quick/qquickloader/data/overflow.qml new file mode 100644 index 0000000000..e5fdfee182 --- /dev/null +++ b/tests/auto/quick/qquickloader/data/overflow.qml @@ -0,0 +1,5 @@ +import QtQuick + +Loader { + source: "overflow.qml" +} diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index b9c6eaab17..94fca41a02 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -108,8 +108,11 @@ private slots: void statusChangeOnlyEmittedOnce(); void setSourceAndCheckStatus(); + void loadComponentWithStates(); void asyncLoaderRace(); void noEngine(); + + void stackOverflow(); }; Q_DECLARE_METATYPE(QList<QQmlError>) @@ -161,7 +164,7 @@ void tst_QQuickLoader::sourceOrComponent() QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), error ? QQuickLoader::Error : QQuickLoader::Ready); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), error ? 0: 1); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), error ? 0: 1); if (!error) { bool sourceComponentIsChildOfLoader = false; @@ -222,12 +225,12 @@ void tst_QQuickLoader::clear() QVERIFY(loader != nullptr); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 1); QTRY_VERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), 0); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 0); } { QQmlComponent component(&engine, testFileUrl("/SetSourceComponent.qml")); @@ -238,14 +241,14 @@ void tst_QQuickLoader::clear() QVERIFY(loader); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); loader->setSourceComponent(nullptr); QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 0); } { QQmlComponent component(&engine, testFileUrl("/SetSourceComponent.qml")); @@ -256,14 +259,14 @@ void tst_QQuickLoader::clear() QVERIFY(loader); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); QMetaObject::invokeMethod(item.data(), "clear"); QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 0); } } @@ -284,7 +287,7 @@ void tst_QQuickLoader::urlToComponent() QTRY_VERIFY(loader != nullptr); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 1); QCOMPARE(loader->width(), 10.0); QCOMPARE(loader->height(), 10.0); } @@ -300,12 +303,12 @@ void tst_QQuickLoader::componentToUrl() QVERIFY(loader); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); loader->setSource(testFileUrl("/Rect120x60.qml")); QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); QCOMPARE(loader->width(), 120.0); QCOMPARE(loader->height(), 60.0); } @@ -435,7 +438,7 @@ void tst_QQuickLoader::networkRequestUrl() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->property("signalCount").toInt(), 1); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 1); } /* XXX Component waits until all dependencies are loaded. Is this actually possible? */ @@ -466,7 +469,7 @@ void tst_QQuickLoader::networkComponent() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QQuickLoader::Ready); - QCOMPARE(static_cast<QQuickItem*>(loader)->children().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->children().size(), 1); } @@ -489,7 +492,7 @@ void tst_QQuickLoader::failNetworkRequest() QVERIFY(!loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->property("did_load").toInt(), 123); - QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().count(), 0); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 0); } void tst_QQuickLoader::active() @@ -789,7 +792,7 @@ void tst_QQuickLoader::deleteComponentCrash() QCOMPARE(loader->status(), QQuickLoader::Ready); QCoreApplication::sendPostedEvents(nullptr, QEvent::DeferredDelete); QCoreApplication::processEvents(); - QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QTRY_COMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); QCOMPARE(loader->source(), QUrl("BlueRect.qml")); } @@ -866,8 +869,8 @@ void tst_QQuickLoader::implicitSize() QCOMPARE(loader->property("implicitWidth").toReal(), 200.); QCOMPARE(loader->property("implicitHeight").toReal(), 300.); - QCOMPARE(implWidthSpy.count(), 1); - QCOMPARE(implHeightSpy.count(), 1); + QCOMPARE(implWidthSpy.size(), 1); + QCOMPARE(implHeightSpy.size(), 1); } void tst_QQuickLoader::QTBUG_17114() @@ -970,7 +973,7 @@ void tst_QQuickLoader::asynchronous_clear() QCOMPARE(loader->progress(), 0.0); QCOMPARE(loader->status(), QQuickLoader::Null); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 0); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 0); // check loading component root->setProperty("comp", "BigComponent.qml"); @@ -983,7 +986,7 @@ void tst_QQuickLoader::asynchronous_clear() QTRY_VERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QQuickLoader::Ready); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); } void tst_QQuickLoader::simultaneousSyncAsync() @@ -1047,7 +1050,7 @@ void tst_QQuickLoader::asyncToSync1() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QQuickLoader::Ready); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); } void tst_QQuickLoader::asyncToSync2() @@ -1079,7 +1082,7 @@ void tst_QQuickLoader::asyncToSync2() QVERIFY(loader->item()); QCOMPARE(loader->progress(), 1.0); QCOMPARE(loader->status(), QQuickLoader::Ready); - QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().size(), 1); } void tst_QQuickLoader::loadedSignal() @@ -1287,7 +1290,7 @@ void tst_QQuickLoader::sourceComponentGarbageCollection() if (spy.isEmpty()) QVERIFY(spy.wait()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } // QTBUG-51995 @@ -1491,6 +1494,26 @@ void tst_QQuickLoader::setSourceAndCheckStatus() QCOMPARE(loader->status(), QQuickLoader::Null); } +void tst_QQuickLoader::loadComponentWithStates() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.setData(QByteArray("import QtQuick\n" + "Loader {\n" + "id: loader\n" + "property int createdObjCount: 0\n" + "states: [ State { when: true; PropertyChanges { target: loader; sourceComponent: myComp } } ]\n" + "Component { id: myComp; Item { Component.onCompleted: { ++createdObjCount } } }\n" + "}" ) + , dataDirectoryUrl()); + QScopedPointer<QQuickLoader> loader(qobject_cast<QQuickLoader*>(component.create())); + QTest::qWait(200); + QTRY_VERIFY(loader != nullptr); + QVERIFY(loader->item()); + QCOMPARE(static_cast<QQuickItem*>(loader.data())->childItems().size(), 1); + QCOMPARE(loader->property("createdObjCount").toInt(), 1); +} + void tst_QQuickLoader::asyncLoaderRace() { QQmlApplicationEngine engine; @@ -1523,6 +1546,17 @@ void tst_QQuickLoader::noEngine() QTRY_COMPARE(o->property("changes").toInt(), 1); } +void tst_QQuickLoader::stackOverflow() +{ + QQmlEngine engine; + const QUrl url = testFileUrl("overflow.qml"); + QQmlComponent component(&engine, url); + QVERIFY2(component.isReady(), qPrintable(component.errorString())); + const QString message = url.toString() + QStringLiteral(": Maximum call stack size exceeded."); + QTest::ignoreMessage(QtCriticalMsg, qPrintable(message)); + QScopedPointer<QObject> o(component.create()); +} + QTEST_MAIN(tst_QQuickLoader) #include "tst_qquickloader.moc" diff --git a/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml new file mode 100644 index 0000000000..d98ef85c55 --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/containsMouseAndHoverDisabled.qml @@ -0,0 +1,15 @@ +import QtQuick + +Rectangle { + width: 200 + height: 200 + visible: true + MouseArea { + id: mouseArea + objectName: "mouseArea" + anchors.fill: parent + hoverEnabled: false + onPressed: function(mouse) { mouse.accepted = false } + } +} + diff --git a/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml b/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml new file mode 100644 index 0000000000..35cfd4b7ef --- /dev/null +++ b/tests/auto/quick/qquickmousearea/data/containsMouseMasked.qml @@ -0,0 +1,24 @@ +import QtQuick + +Rectangle { + width: 200 + height: 200 + visible: true + MouseArea { + id: mouseArea1 + objectName: "mouseArea1" + anchors.fill: parent + hoverEnabled: true + visible: true + } + + MouseArea { + id: mouseArea2 + objectName: "mouseArea2" + anchors.centerIn: mouseArea1 + width: 50 + height: 50 + hoverEnabled: true + visible: true + } +} diff --git a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp index f07a7ba221..44aa28f3f9 100644 --- a/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp +++ b/tests/auto/quick/qquickmousearea/tst_qquickmousearea.cpp @@ -108,6 +108,7 @@ private slots: void hoverVisible(); void hoverAfterPress(); void subtreeHoverEnabled(); + void hoverWhenDisabled(); void disableAfterPress(); void onWheel(); void transformedMouseArea_data(); @@ -135,6 +136,8 @@ private slots: void settingHiddenInPressUngrabs(); void negativeZStackingOrder(); void containsMouseAndVisibility(); + void containsMouseAndVisibilityMasked(); + void containsMouseAndHoverDisabled(); void doubleClickToHide(); void releaseFirstTouchAfterSecond(); #if QT_CONFIG(tabletevent) @@ -195,18 +198,18 @@ void tst_QQuickMouseArea::dragProperties() QVERIFY(rootItem != nullptr); QSignalSpy targetSpy(drag, SIGNAL(targetChanged())); drag->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); drag->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); // axis QCOMPARE(drag->axis(), QQuickDrag::XAndYAxis); QSignalSpy axisSpy(drag, SIGNAL(axisChanged())); drag->setAxis(QQuickDrag::XAxis); QCOMPARE(drag->axis(), QQuickDrag::XAxis); - QCOMPARE(axisSpy.count(),1); + QCOMPARE(axisSpy.size(),1); drag->setAxis(QQuickDrag::XAxis); - QCOMPARE(axisSpy.count(),1); + QCOMPARE(axisSpy.size(),1); // minimum and maximum properties QSignalSpy xminSpy(drag, SIGNAL(minimumXChanged())); @@ -229,20 +232,20 @@ void tst_QQuickMouseArea::dragProperties() QCOMPARE(drag->ymin(), 10.0); QCOMPARE(drag->ymax(), 10.0); - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); + QCOMPARE(xminSpy.size(),1); + QCOMPARE(xmaxSpy.size(),1); + QCOMPARE(yminSpy.size(),1); + QCOMPARE(ymaxSpy.size(),1); drag->setXmin(10); drag->setXmax(10); drag->setYmin(10); drag->setYmax(10); - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); + QCOMPARE(xminSpy.size(),1); + QCOMPARE(xmaxSpy.size(),1); + QCOMPARE(yminSpy.size(),1); + QCOMPARE(ymaxSpy.size(),1); // filterChildren QSignalSpy filterChildrenSpy(drag, SIGNAL(filterChildrenChanged())); @@ -250,24 +253,24 @@ void tst_QQuickMouseArea::dragProperties() drag->setFilterChildren(true); QVERIFY(drag->filterChildren()); - QCOMPARE(filterChildrenSpy.count(), 1); + QCOMPARE(filterChildrenSpy.size(), 1); drag->setFilterChildren(true); - QCOMPARE(filterChildrenSpy.count(), 1); + QCOMPARE(filterChildrenSpy.size(), 1); // threshold QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance()); QSignalSpy thresholdSpy(drag, SIGNAL(thresholdChanged())); drag->setThreshold(0.0); QCOMPARE(drag->threshold(), 0.0); - QCOMPARE(thresholdSpy.count(), 1); + QCOMPARE(thresholdSpy.size(), 1); drag->setThreshold(99); - QCOMPARE(thresholdSpy.count(), 2); + QCOMPARE(thresholdSpy.size(), 2); drag->setThreshold(99); - QCOMPARE(thresholdSpy.count(), 2); + QCOMPARE(thresholdSpy.size(), 2); drag->resetThreshold(); QCOMPARE(int(drag->threshold()), qApp->styleHints()->startDragDistance()); - QCOMPARE(thresholdSpy.count(), 3); + QCOMPARE(thresholdSpy.size(), 3); } void tst_QQuickMouseArea::resetDrag() @@ -292,7 +295,7 @@ void tst_QQuickMouseArea::resetDrag() auto root = window.rootObject(); QQmlProperty haveTarget {root, "haveTarget"}; haveTarget.write(false); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); QVERIFY(!drag->target()); } @@ -1049,7 +1052,7 @@ void tst_QQuickMouseArea::preventStealing() QTest::mouseMove(&window, p); // We should have received all four move events - QTRY_COMPARE(mousePositionSpy.count(), 4); + QTRY_COMPARE(mousePositionSpy.size(), 4); mousePositionSpy.clear(); QVERIFY(mouseArea->pressed()); @@ -1078,7 +1081,7 @@ void tst_QQuickMouseArea::preventStealing() QTest::mouseMove(&window, p); // We should only have received the first move event - QTRY_COMPARE(mousePositionSpy.count(), 1); + QTRY_COMPARE(mousePositionSpy.size(), 1); // Our press should be taken away QVERIFY(!mouseArea->pressed()); @@ -1319,12 +1322,12 @@ void tst_QQuickMouseArea::hoverVisible() QTest::mouseMove(&window,QPoint(11,33)); QCOMPARE(mouseTracker->hovered(), false); - QCOMPARE(enteredSpy.count(), 0); + QCOMPARE(enteredSpy.size(), 0); mouseTracker->setVisible(true); QCOMPARE(mouseTracker->hovered(), true); - QCOMPARE(enteredSpy.count(), 1); + QCOMPARE(enteredSpy.size(), 1); QCOMPARE(QPointF(mouseTracker->mouseX(), mouseTracker->mouseY()), QPointF(11,33)); @@ -1399,6 +1402,37 @@ void tst_QQuickMouseArea::subtreeHoverEnabled() QCOMPARE(mouseArea->hovered(), false); } +void tst_QQuickMouseArea::hoverWhenDisabled() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("hoverVisible.qml"))); + QQuickItem *root = window.rootObject(); + QVERIFY(root); + + QQuickMouseArea *mouseArea = root->findChild<QQuickMouseArea*>(); + QVERIFY(mouseArea); + mouseArea->setVisible(true); + + QTest::mouseMove(&window, QPoint(50, 50)); + QVERIFY(mouseArea->hovered()); + + mouseArea->setEnabled(false); + QTest::mouseMove(&window, QPoint(51, 50)); + QVERIFY(!mouseArea->hovered()); + + mouseArea->setEnabled(true); + QTest::mouseMove(&window, QPoint(50, 50)); + QVERIFY(mouseArea->hovered()); + + mouseArea->setHoverEnabled(false); + QTest::mouseMove(&window, QPoint(51, 50)); + QVERIFY(!mouseArea->hovered()); + + mouseArea->setHoverEnabled(true); + QTest::mouseMove(&window, QPoint(50, 50)); + QVERIFY(mouseArea->hovered()); +} + void tst_QQuickMouseArea::disableAfterPress() { QQuickView window; @@ -1423,7 +1457,7 @@ void tst_QQuickMouseArea::disableAfterPress() QVERIFY(!drag->active()); QPoint p = QPoint(100,100); QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p); - QTRY_COMPARE(mousePressSpy.count(), 1); + QTRY_COMPARE(mousePressSpy.size(), 1); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); @@ -1437,7 +1471,7 @@ void tst_QQuickMouseArea::disableAfterPress() p += QPoint(11, 11); QTest::mouseMove(&window, p); - QTRY_COMPARE(mousePositionSpy.count(), 2); + QTRY_COMPARE(mousePositionSpy.size(), 2); QTRY_VERIFY(drag->active()); QTRY_COMPARE(blackRect->x(), 61.0); @@ -1451,7 +1485,7 @@ void tst_QQuickMouseArea::disableAfterPress() p += QPoint(11, 11); QTest::mouseMove(&window, p); - QTRY_COMPARE(mousePositionSpy.count(), 4); + QTRY_COMPARE(mousePositionSpy.size(), 4); QVERIFY(drag->active()); QCOMPARE(blackRect->x(), 83.0); @@ -1462,7 +1496,7 @@ void tst_QQuickMouseArea::disableAfterPress() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p); - QTRY_COMPARE(mouseReleaseSpy.count(), 1); + QTRY_COMPARE(mouseReleaseSpy.size(), 1); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 83.0); @@ -1481,14 +1515,14 @@ void tst_QQuickMouseArea::disableAfterPress() QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100,100)); QTest::qWait(50); - QCOMPARE(mousePressSpy.count(), 0); + QCOMPARE(mousePressSpy.size(), 0); QTest::mouseMove(&window, QPoint(111,111)); QTest::qWait(50); QTest::mouseMove(&window, QPoint(122,122)); QTest::qWait(50); - QCOMPARE(mousePositionSpy.count(), 0); + QCOMPARE(mousePositionSpy.size(), 0); QVERIFY(!drag->active()); QCOMPARE(blackRect->x(), 50.0); @@ -1497,7 +1531,7 @@ void tst_QQuickMouseArea::disableAfterPress() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(122,122)); QTest::qWait(50); - QCOMPARE(mouseReleaseSpy.count(), 0); + QCOMPARE(mouseReleaseSpy.size(), 0); } void tst_QQuickMouseArea::onWheel() @@ -1660,7 +1694,7 @@ void tst_QQuickMouseArea::pressedMultipleButtons() mouseArea->setAcceptedMouseButtons(accepted); QPoint point(10, 10); - for (int i = 0; i < mouseEvents.count(); ++i) { + for (int i = 0; i < mouseEvents.size(); ++i) { const MouseEvent mouseEvent = mouseEvents.at(i); if (mouseEvent.type == QEvent::MouseButtonPress) QTest::mousePress(&window, mouseEvent.button, Qt::NoModifier, point); @@ -1670,8 +1704,8 @@ void tst_QQuickMouseArea::pressedMultipleButtons() QCOMPARE(mouseArea->pressedButtons(), pressedButtons.at(i)); } - QCOMPARE(pressedSpy.count(), 2); - QCOMPARE(pressedButtonsSpy.count(), changeCount); + QCOMPARE(pressedSpy.size(), 2); + QCOMPARE(pressedButtonsSpy.size(), changeCount); } void tst_QQuickMouseArea::changeAxis() @@ -1751,15 +1785,15 @@ void tst_QQuickMouseArea::cursorShape() mouseArea->setCursorShape(Qt::IBeamCursor); QCOMPARE(mouseArea->cursorShape(), Qt::IBeamCursor); QCOMPARE(mouseArea->cursor().shape(), Qt::IBeamCursor); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); mouseArea->setCursorShape(Qt::IBeamCursor); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); mouseArea->setCursorShape(Qt::WaitCursor); QCOMPARE(mouseArea->cursorShape(), Qt::WaitCursor); QCOMPARE(mouseArea->cursor().shape(), Qt::WaitCursor); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } #endif @@ -1972,25 +2006,25 @@ void tst_QQuickMouseArea::containsPress() QCOMPARE(mouseArea->hovered(), true); QTRY_COMPARE(mouseArea->pressed(), true); QCOMPARE(mouseArea->containsPress(), true); - QCOMPARE(containsPressSpy.count(), 1); + QCOMPARE(containsPressSpy.size(), 1); QTest::mouseMove(&window, QPoint(22,33)); QCOMPARE(mouseArea->hovered(), false); QCOMPARE(mouseArea->pressed(), true); QCOMPARE(mouseArea->containsPress(), false); - QCOMPARE(containsPressSpy.count(), 2); + QCOMPARE(containsPressSpy.size(), 2); QTest::mouseMove(&window, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), true); QCOMPARE(mouseArea->pressed(), true); QCOMPARE(mouseArea->containsPress(), true); - QCOMPARE(containsPressSpy.count(), 3); + QCOMPARE(containsPressSpy.size(), 3); QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(200,200)); QCOMPARE(mouseArea->hovered(), hoverEnabled); QCOMPARE(mouseArea->pressed(), false); QCOMPARE(mouseArea->containsPress(), false); - QCOMPARE(containsPressSpy.count(), 4); + QCOMPARE(containsPressSpy.size(), 4); } void tst_QQuickMouseArea::ignoreBySource() @@ -2312,8 +2346,8 @@ void tst_QQuickMouseArea::negativeZStackingOrder() // QTBUG-83114 QSignalSpy clickSpyChild(childMouseArea, &QQuickMouseArea::clicked); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100)); - QCOMPARE(clickSpyChild.count(), 1); - QCOMPARE(clickSpyParent.count(), 0); + QCOMPARE(clickSpyChild.size(), 1); + QCOMPARE(clickSpyParent.size(), 0); auto order = root->property("clicks").toList(); QVERIFY(order.at(0) == "childMouseArea"); @@ -2321,8 +2355,8 @@ void tst_QQuickMouseArea::negativeZStackingOrder() // QTBUG-83114 childMouseArea->parentItem()->setZ(-1); root->setProperty("clicks", QVariantList()); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, QPoint(150, 100)); - QCOMPARE(clickSpyChild.count(), 1); - QCOMPARE(clickSpyParent.count(), 1); + QCOMPARE(clickSpyChild.size(), 1); + QCOMPARE(clickSpyParent.size(), 1); order = root->property("clicks").toList(); QVERIFY(order.at(0) == "parentMouseArea"); } @@ -2372,6 +2406,68 @@ void tst_QQuickMouseArea::containsMouseAndVisibility() QVERIFY(!mouseArea->hovered()); } +// QTBUG-109567 +void tst_QQuickMouseArea::containsMouseAndVisibilityMasked() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouseMasked.qml"))); + + QQuickMouseArea *mouseArea1 = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea1"); + QVERIFY(mouseArea1 != nullptr); + QVERIFY(mouseArea1->isVisible()); + + QQuickMouseArea *mouseArea2 = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea2"); + QVERIFY(mouseArea2 != nullptr); + QVERIFY(mouseArea2->isVisible()); + + QTest::mouseMove(&window, QPoint(window.width() / 2, window.height() / 2)); + + // Check that mouseArea" (i.e. the masking MouseArea) is the only hovered MouseArea. + QTRY_VERIFY(!mouseArea1->hovered()); + QTRY_VERIFY(mouseArea2->hovered()); + + // Toggle the visibility of the masked MouseArea (mouseArea1). + mouseArea1->setVisible(false); + QVERIFY(!mouseArea1->isVisible()); + + mouseArea1->setVisible(true); + QVERIFY(mouseArea1->isVisible()); + + // Check that the masked MouseArea is not now hovered depite being under the mouse after + // changing the visibility to visible. mouseArea2 should be the only hovered MouseArea still. + QTRY_VERIFY(!mouseArea1->hovered()); + QTRY_VERIFY(mouseArea2->hovered()); + + QTest::mouseMove(&window, QPoint(10, 10)); + + QTRY_VERIFY(mouseArea1->hovered()); + QTRY_VERIFY(!mouseArea2->hovered()); + + // Toggle the visibility of the masked MouseArea (mouseArea1). + mouseArea1->setVisible(false); + QVERIFY(!mouseArea1->isVisible()); + + mouseArea1->setVisible(true); + QVERIFY(mouseArea1->isVisible()); + + QTRY_VERIFY(mouseArea1->hovered()); + QTRY_VERIFY(!mouseArea2->hovered()); +} + +// QTBUG-110594 +void tst_QQuickMouseArea::containsMouseAndHoverDisabled() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("containsMouseAndHoverDisabled.qml"))); + + QQuickMouseArea *mouseArea = window.rootObject()->findChild<QQuickMouseArea *>("mouseArea"); + QVERIFY(mouseArea != nullptr); + QVERIFY(!mouseArea->hoverEnabled()); + + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTRY_VERIFY(!mouseArea->hovered()); +} + // QTBUG-35995 and QTBUG-102158 void tst_QQuickMouseArea::doubleClickToHide() { @@ -2405,13 +2501,13 @@ void tst_QQuickMouseArea::releaseFirstTouchAfterSecond() // QTBUG-103766 QSignalSpy releaseSpy(mouseArea, &QQuickMouseArea::released); QTest::touchEvent(&window, device).press(0, {20, 20}); - QTRY_COMPARE(pressSpy.count(), 1); + QTRY_COMPARE(pressSpy.size(), 1); QTest::touchEvent(&window, device).stationary(0).press(1, {100, 20}); - QCOMPARE(pressSpy.count(), 1); // touchpoint 0 is the touchmouse, touchpoint 1 is ignored + QCOMPARE(pressSpy.size(), 1); // touchpoint 0 is the touchmouse, touchpoint 1 is ignored QTest::touchEvent(&window, device).stationary(0).release(1, {100, 20}); - QCOMPARE(releaseSpy.count(), 0); // touchpoint 0 is the touchmouse, and remains pressed + QCOMPARE(releaseSpy.size(), 0); // touchpoint 0 is the touchmouse, and remains pressed QTest::touchEvent(&window, device).release(0, {20, 20}); - QTRY_COMPARE(releaseSpy.count(), 1); + QTRY_COMPARE(releaseSpy.size(), 1); } #if QT_CONFIG(tabletevent) @@ -2433,15 +2529,15 @@ void tst_QQuickMouseArea::tabletStylusTap() Qt::LeftButton, 0.5, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); if (QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse) QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, point); // simulate what the platform does - QTRY_COMPARE(pressSpy.count(), 1); + QTRY_COMPARE(pressSpy.size(), 1); QWindowSystemInterface::handleTabletEvent(&window, point, window.mapToGlobal(point), int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), Qt::NoButton, 0.5, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); if (QWindowSystemInterfacePrivate::TabletEvent::platformSynthesizesMouse) QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, point); - QTRY_COMPARE(releaseSpy.count(), 1); - QCOMPARE(clickSpy.count(), 1); - QCOMPARE(pressSpy.count(), 1); + QTRY_COMPARE(releaseSpy.size(), 1); + QCOMPARE(clickSpy.size(), 1); + QCOMPARE(pressSpy.size(), 1); } #endif diff --git a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST index abe504d20c..2488eff270 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST +++ b/tests/auto/quick/qquickmultipointtoucharea/BLACKLIST @@ -1,4 +1,6 @@ [nonOverlapping] ubuntu-20.04 +ubuntu-22.04 [nested] ubuntu-20.04 +ubuntu-22.04 diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index 5da20ce9a2..509465b174 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -1243,22 +1243,22 @@ void tst_QQuickMultiPointTouchArea::mouseGestureStarted() // QTBUG-70258 QPoint p1 = QPoint(distanceFromOrigin, distanceFromOrigin); QTest::mousePress(view.data(), Qt::LeftButton, Qt::NoModifier, p1); - QCOMPARE(gestureStartedSpy.count(), 0); + QCOMPARE(gestureStartedSpy.size(), 0); p1 += QPoint(dragThreshold, dragThreshold); QTest::mouseMove(view.data(), p1); - QCOMPARE(gestureStartedSpy.count(), 0); + QCOMPARE(gestureStartedSpy.size(), 0); p1 += QPoint(1, 1); QTest::mouseMove(view.data(), p1); - QTRY_COMPARE(gestureStartedSpy.count(), 1); + QTRY_COMPARE(gestureStartedSpy.size(), 1); QTRY_COMPARE(area->property("gestureStartedX").toInt(), distanceFromOrigin); QCOMPARE(area->property("gestureStartedY").toInt(), distanceFromOrigin); p1 += QPoint(10, 10); QTest::mouseMove(view.data(), p1); // if nobody called gesteure->grab(), gestureStarted will keep happening - QTRY_COMPARE(gestureStartedSpy.count(), grabGesture ? 1 : 2); + QTRY_COMPARE(gestureStartedSpy.size(), grabGesture ? 1 : 2); QCOMPARE(area->property("gestureStartedX").toInt(), distanceFromOrigin); QCOMPARE(area->property("gestureStartedY").toInt(), distanceFromOrigin); @@ -1370,7 +1370,7 @@ void tst_QQuickMultiPointTouchArea::touchFiltering() // QTBUG-74028 QQuickTouchUtils::flush(window.data()); QTRY_COMPARE(mpta->parentItem()->property("mptaPoint").toPoint(), pt); QCOMPARE(mpta->parentItem()->property("maPoint").toPoint(), ma->boundingRect().center().toPoint()); - QCOMPARE(mptaSpy.count(), 1); + QCOMPARE(mptaSpy.size(), 1); } void tst_QQuickMultiPointTouchArea::nestedPinchAreaMouse() // QTBUG-83662 @@ -1391,32 +1391,32 @@ void tst_QQuickMultiPointTouchArea::nestedPinchAreaMouse() // QTBUG-83662 QTest::mousePress(window.data(), Qt::LeftButton, Qt::NoModifier, p1); QCOMPARE(point1->pressed(), true); QCOMPARE(point2->pressed(), false); - QCOMPARE(pressedSpy.count(), 1); + QCOMPARE(pressedSpy.size(), 1); QCOMPARE(mpta->property("pressedCount").toInt(), 1); - QCOMPARE(updatedSpy.count(), 0); + QCOMPARE(updatedSpy.size(), 0); QCOMPARE(mpta->property("updatedCount").toInt(), 0); - QCOMPARE(releasedSpy.count(), 0); + QCOMPARE(releasedSpy.size(), 0); QCOMPARE(mpta->property("releasedCount").toInt(), 0); p1 += QPoint(0, 15); QTest::mouseMove(window.data(), p1); QCOMPARE(point1->pressed(), true); QCOMPARE(point2->pressed(), false); - QCOMPARE(pressedSpy.count(), 1); + QCOMPARE(pressedSpy.size(), 1); QCOMPARE(mpta->property("pressedCount").toInt(), 1); - QCOMPARE(updatedSpy.count(), 1); + QCOMPARE(updatedSpy.size(), 1); QCOMPARE(mpta->property("updatedCount").toInt(), 1); - QCOMPARE(releasedSpy.count(), 0); + QCOMPARE(releasedSpy.size(), 0); QCOMPARE(mpta->property("releasedCount").toInt(), 0); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, p1); QCOMPARE(point1->pressed(), false); QCOMPARE(point2->pressed(), false); - QCOMPARE(pressedSpy.count(), 1); + QCOMPARE(pressedSpy.size(), 1); QCOMPARE(mpta->property("pressedCount").toInt(), 1); - QCOMPARE(updatedSpy.count(), 1); + QCOMPARE(updatedSpy.size(), 1); QCOMPARE(mpta->property("updatedCount").toInt(), 1); - QCOMPARE(releasedSpy.count(), 1); + QCOMPARE(releasedSpy.size(), 1); QCOMPARE(mpta->property("releasedCount").toInt(), 1); } diff --git a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp index f002de0e3d..56ebfdbd48 100644 --- a/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp +++ b/tests/auto/quick/qquickpainteditem/tst_qquickpainteditem.cpp @@ -282,24 +282,24 @@ void tst_QQuickPaintedItem::contentsSize() item.setContentsSize(QSize()); QCOMPARE(item.contentsSize(), QSize()); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); item.setContentsSize(QSize(320, 240)); QCOMPARE(item.contentsSize(), QSize(320, 240)); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); clearDirtyContentFlag(&item); item.setContentsSize(QSize(320, 240)); QCOMPARE(item.contentsSize(), QSize(320, 240)); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.resetContentsSize(); QCOMPARE(item.contentsSize(), QSize()); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_QQuickPaintedItem::contentScale() @@ -315,7 +315,7 @@ void tst_QQuickPaintedItem::contentScale() item.setContentsScale(1.); QCOMPARE(item.contentsScale(), 1.); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); item.update(); QTRY_COMPARE(hasDirtyContentFlag(&item), false); @@ -325,7 +325,7 @@ void tst_QQuickPaintedItem::contentScale() item.setContentsScale(0.4); QCOMPARE(item.contentsScale(), 0.4); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QTRY_COMPARE(hasDirtyContentFlag(&item), false); QVERIFY(item.paintNode); @@ -334,12 +334,12 @@ void tst_QQuickPaintedItem::contentScale() item.setContentsScale(0.4); QCOMPARE(item.contentsScale(), 0.4); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.setContentsScale(2.5); QCOMPARE(item.contentsScale(), 2.5); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QTRY_COMPARE(hasDirtyContentFlag(&item), false); QVERIFY(item.paintNode); @@ -397,7 +397,7 @@ void tst_QQuickPaintedItem::fillColor() item.setFillColor(QColor(Qt::transparent)); QCOMPARE(item.fillColor(), QColor(Qt::transparent)); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); item.update(); QTRY_COMPARE(hasDirtyContentFlag(&item), false); @@ -407,7 +407,7 @@ void tst_QQuickPaintedItem::fillColor() item.setFillColor(QColor(Qt::green)); QCOMPARE(item.fillColor(), QColor(Qt::green)); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QTRY_COMPARE(hasDirtyContentFlag(&item), false); QVERIFY(item.paintNode); @@ -416,12 +416,12 @@ void tst_QQuickPaintedItem::fillColor() item.setFillColor(QColor(Qt::green)); QCOMPARE(item.fillColor(), QColor(Qt::green)); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.setFillColor(QColor(Qt::blue)); QCOMPARE(item.fillColor(), QColor(Qt::blue)); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QTRY_COMPARE(hasDirtyContentFlag(&item), false); QVERIFY(item.paintNode); @@ -440,24 +440,24 @@ void tst_QQuickPaintedItem::renderTarget() item.setRenderTarget(QQuickPaintedItem::Image); QCOMPARE(item.renderTarget(), QQuickPaintedItem::Image); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); item.setRenderTarget(QQuickPaintedItem::FramebufferObject); QCOMPARE(item.renderTarget(), QQuickPaintedItem::FramebufferObject); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); clearDirtyContentFlag(&item); item.setRenderTarget(QQuickPaintedItem::FramebufferObject); QCOMPARE(item.renderTarget(), QQuickPaintedItem::FramebufferObject); QCOMPARE(hasDirtyContentFlag(&item), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.setRenderTarget(QQuickPaintedItem::InvertedYFramebufferObject); QCOMPARE(item.renderTarget(), QQuickPaintedItem::InvertedYFramebufferObject); QCOMPARE(hasDirtyContentFlag(&item), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } QTEST_MAIN(tst_QQuickPaintedItem) diff --git a/tests/auto/quick/qquickpalette/tst_qquickpalette.cpp b/tests/auto/quick/qquickpalette/tst_qquickpalette.cpp index 90d850ce8a..53fa22dba5 100644 --- a/tests/auto/quick/qquickpalette/tst_qquickpalette.cpp +++ b/tests/auto/quick/qquickpalette/tst_qquickpalette.cpp @@ -117,8 +117,8 @@ void tst_QQuickPalette::newColorSubgroup() anotherPalette.fromQPalette(Qt::red); (p.*setter)((anotherPalette.*getter)()); - QCOMPARE(subgroupChanged.count(), 1); - QCOMPARE(paletteChanged.count(), 1); + QCOMPARE(subgroupChanged.size(), 1); + QCOMPARE(paletteChanged.size(), 1); } } @@ -161,7 +161,7 @@ void tst_QQuickPalette::paletteChangedWhenColorGroupChanged() p.inactive()->setMid(Qt::green); p.disabled()->setMid(Qt::blue); - QCOMPARE(sp.count(), 3); + QCOMPARE(sp.size(), 3); } void tst_QQuickPalette::createDefault() @@ -182,7 +182,7 @@ void tst_QQuickPalette::changeCurrentColorGroup() palette.setCurrentGroup(QPalette::Disabled); QCOMPARE(palette.currentColorGroup(), QPalette::Disabled); - QCOMPARE(ss.count(), 1); + QCOMPARE(ss.size(), 1); } void tst_QQuickPalette::inheritColor() @@ -266,10 +266,10 @@ void tst_QQuickPalette::createFromQtPalette() QSignalSpy sp(&palette, &QQuickColorGroup::changed); palette.fromQPalette(QPalette()); - QCOMPARE(sp.count(), 0); + QCOMPARE(sp.size(), 0); palette.fromQPalette(somePalette); - QCOMPARE(sp.count(), 1); + QCOMPARE(sp.size(), 1); } void tst_QQuickPalette::convertToQtPalette() diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 0d894c8581..98085002ea 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -129,6 +129,10 @@ private slots: void objectModelMove(); void requiredPropertiesInDelegate(); void requiredPropertiesInDelegatePreventUnrelated(); + void touchMove(); + +private: + QScopedPointer<QPointingDevice> touchDevice = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); }; class TestObject : public QObject @@ -207,7 +211,7 @@ void tst_QQuickPathView::items() QCOMPARE(pathview->count(), model.count()); QCOMPARE(window->rootObject()->property("count").toInt(), model.count()); - QCOMPARE(pathview->childItems().count(), model.count()+1); // assumes all are visible, including highlight + QCOMPARE(pathview->childItems().size(), model.count()+1); // assumes all are visible, including highlight for (int i = 0; i < model.count(); ++i) { QQuickText *name = findItem<QQuickText>(pathview, "textName", i); @@ -677,7 +681,7 @@ void tst_QQuickPathView::consecutiveModelChanges() else pathview->setOffset(4); - for (int i=0; i<changes.count(); i++) { + for (int i=0; i<changes.size(); i++) { switch (changes[i].type) { case ListChange::Inserted: { @@ -705,7 +709,7 @@ void tst_QQuickPathView::consecutiveModelChanges() } QQuickTest::qWaitForPolish(pathview); - QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), count); + QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), count); QCOMPARE(pathview->count(), count); QTRY_COMPARE(pathview->offset(), offset); @@ -808,7 +812,7 @@ void tst_QQuickPathView::dataModel() QTest::qWait(100); QCOMPARE(window->rootObject()->property("viewCount").toInt(), model.count()); - QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 14); + QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 14); QCOMPARE(pathview->currentIndex(), 0); QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 0)); @@ -828,7 +832,7 @@ void tst_QQuickPathView::dataModel() QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); QVERIFY(!testObject->error()); - QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); + QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 5); QQuickRectangle *testItem = findItem<QQuickRectangle>(pathview, "wrapper", 4); QVERIFY(testItem != nullptr); @@ -841,7 +845,7 @@ void tst_QQuickPathView::dataModel() model.insertItem(2, "pink", "2"); - QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); + QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 5); QCOMPARE(pathview->currentIndex(), 1); QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1)); @@ -849,14 +853,14 @@ void tst_QQuickPathView::dataModel() QCOMPARE(text->text(), model.name(2)); model.removeItem(3); - QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); + QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 5); text = findItem<QQuickText>(pathview, "myText", 3); QVERIFY(text); QCOMPARE(text->text(), model.name(3)); QCOMPARE(pathview->currentItem(), findItem<QQuickItem>(pathview, "wrapper", 1)); model.moveItem(3, 5); - QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); + QTRY_COMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 5); QList<QQuickItem*> items = findItems<QQuickItem>(pathview, "wrapper"); foreach (QQuickItem *item, items) { QVERIFY(item->property("onPath").toBool()); @@ -866,7 +870,7 @@ void tst_QQuickPathView::dataModel() // QTBUG-14199 pathview->setOffset(7); pathview->setOffset(0); - QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), 5); + QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").size(), 5); pathview->setCurrentIndex(model.count()-1); QTRY_COMPARE(pathview->offset(), 1.0); @@ -1117,7 +1121,7 @@ void tst_QQuickPathView::setCurrentIndex() pathview->setSnapMode(QQuickPathView::SnapToItem); pathview->setCurrentIndex(3); QTRY_COMPARE(pathview->currentIndex(), 3); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); } void tst_QQuickPathView::setCurrentIndexWrap() @@ -1138,8 +1142,8 @@ void tst_QQuickPathView::setCurrentIndexWrap() pathview->setCurrentIndex(0); pathview->setCurrentIndex(4); QCOMPARE(pathview->currentIndex(), 4); - QCOMPARE(currentIndexSpy.count(), 2); - QCOMPARE(movementStartedSpy.count(), 0); + QCOMPARE(currentIndexSpy.size(), 2); + QCOMPARE(movementStartedSpy.size(), 0); } void tst_QQuickPathView::resetModel() @@ -1204,21 +1208,21 @@ void tst_QQuickPathView::propertyChanges() QCOMPARE(pathView->preferredHighlightEnd(), 0.4); QCOMPARE(pathView->dragMargin(), 20.0); - QCOMPARE(snapPositionSpy.count(), 1); - QCOMPARE(dragMarginSpy.count(), 1); + QCOMPARE(snapPositionSpy.size(), 1); + QCOMPARE(dragMarginSpy.size(), 1); pathView->setPreferredHighlightBegin(0.4); pathView->setPreferredHighlightEnd(0.4); pathView->setDragMargin(20.0); - QCOMPARE(snapPositionSpy.count(), 1); - QCOMPARE(dragMarginSpy.count(), 1); + QCOMPARE(snapPositionSpy.size(), 1); + QCOMPARE(dragMarginSpy.size(), 1); QSignalSpy maximumFlickVelocitySpy(pathView, SIGNAL(maximumFlickVelocityChanged())); pathView->setMaximumFlickVelocity(1000); - QCOMPARE(maximumFlickVelocitySpy.count(), 1); + QCOMPARE(maximumFlickVelocitySpy.size(), 1); pathView->setMaximumFlickVelocity(1000); - QCOMPARE(maximumFlickVelocitySpy.count(), 1); + QCOMPARE(maximumFlickVelocitySpy.size(), 1); } @@ -1246,14 +1250,14 @@ void tst_QQuickPathView::pathChanges() QCOMPARE(path->startX(), 240.0); QCOMPARE(path->startY(), 220.0); - QCOMPARE(startXSpy.count(),1); - QCOMPARE(startYSpy.count(),1); + QCOMPARE(startXSpy.size(),1); + QCOMPARE(startYSpy.size(),1); path->setStartX(240); path->setStartY(220); - QCOMPARE(startXSpy.count(),1); - QCOMPARE(startYSpy.count(),1); + QCOMPARE(startXSpy.size(),1); + QCOMPARE(startYSpy.size(),1); QQuickPath *alternatePath = window->rootObject()->findChild<QQuickPath*>("alternatePath"); QVERIFY(alternatePath); @@ -1264,10 +1268,10 @@ void tst_QQuickPathView::pathChanges() pathView->setPath(alternatePath); QCOMPARE(pathView->path(), alternatePath); - QCOMPARE(pathSpy.count(),1); + QCOMPARE(pathSpy.size(),1); pathView->setPath(alternatePath); - QCOMPARE(pathSpy.count(),1); + QCOMPARE(pathSpy.size(),1); QQuickPathAttribute *pathAttribute = window->rootObject()->findChild<QQuickPathAttribute*>("pathAttribute"); QVERIFY(pathAttribute); @@ -1277,10 +1281,10 @@ void tst_QQuickPathView::pathChanges() pathAttribute->setName("scale"); QCOMPARE(pathAttribute->name(), QString("scale")); - QCOMPARE(nameSpy.count(),1); + QCOMPARE(nameSpy.size(),1); pathAttribute->setName("scale"); - QCOMPARE(nameSpy.count(),1); + QCOMPARE(nameSpy.size(),1); } void tst_QQuickPathView::componentChanges() @@ -1299,10 +1303,10 @@ void tst_QQuickPathView::componentChanges() pathView->setDelegate(&delegateComponent); QCOMPARE(pathView->delegate(), &delegateComponent); - QCOMPARE(delegateSpy.count(),1); + QCOMPARE(delegateSpy.size(),1); pathView->setDelegate(&delegateComponent); - QCOMPARE(delegateSpy.count(),1); + QCOMPARE(delegateSpy.size(),1); } void tst_QQuickPathView::modelChanges() @@ -1325,17 +1329,17 @@ void tst_QQuickPathView::modelChanges() QCOMPARE(pathView->currentIndex(), 3); pathView->setModel(modelVariant); QCOMPARE(pathView->model(), modelVariant); - QCOMPARE(modelSpy.count(),1); + QCOMPARE(modelSpy.size(),1); QCOMPARE(pathView->currentIndex(), 0); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); pathView->setModel(modelVariant); - QCOMPARE(modelSpy.count(),1); + QCOMPARE(modelSpy.size(),1); pathView->setModel(QVariant()); - QCOMPARE(modelSpy.count(),2); + QCOMPARE(modelSpy.size(),2); QCOMPARE(pathView->currentIndex(), 0); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); } @@ -1519,12 +1523,12 @@ void tst_QQuickPathView::mouseDrag() // first move beyond threshold does not trigger drag QVERIFY(!pathview->isMoving()); QVERIFY(!pathview->isDragging()); - QCOMPARE(movingSpy.count(), 0); - QCOMPARE(moveStartedSpy.count(), 0); - QCOMPARE(moveEndedSpy.count(), 0); - QCOMPARE(draggingSpy.count(), 0); - QCOMPARE(dragStartedSpy.count(), 0); - QCOMPARE(dragEndedSpy.count(), 0); + QCOMPARE(movingSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 0); + QCOMPARE(dragStartedSpy.size(), 0); + QCOMPARE(dragEndedSpy.size(), 0); { QMouseEvent mv(QEvent::MouseMove, QPoint(90,100), window->mapToGlobal(QPoint(90,100)), @@ -1538,23 +1542,23 @@ void tst_QQuickPathView::mouseDrag() #endif // Q_OS_WIN QVERIFY(pathview->isMoving()); QVERIFY(pathview->isDragging()); - QCOMPARE(movingSpy.count(), 1); - QCOMPARE(moveStartedSpy.count(), 1); - QCOMPARE(moveEndedSpy.count(), 0); - QCOMPARE(draggingSpy.count(), 1); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 0); + QCOMPARE(movingSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 1); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 0); QVERIFY(pathview->currentIndex() != current); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(40,100)); QVERIFY(!pathview->isDragging()); - QCOMPARE(draggingSpy.count(), 2); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 1); - QTRY_COMPARE(movingSpy.count(), 2); - QTRY_COMPARE(moveEndedSpy.count(), 1); - QCOMPARE(moveStartedSpy.count(), 1); + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); + QTRY_COMPARE(movingSpy.size(), 2); + QTRY_COMPARE(moveEndedSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); } @@ -1613,30 +1617,30 @@ void tst_QQuickPathView::flickNClick() // QTBUG-77173 // Dragging the child mouse area should animate the PathView (MA has no drag target) flick(window.data(), QPoint(199,199), QPoint(399,199), duration); QVERIFY(pathview->isMoving()); - QCOMPARE(movingChangedSpy.count(), 1); - QCOMPARE(draggingSpy.count(), 2); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 1); - QVERIFY(currentIndexSpy.count() > 0); - QCOMPARE(moveStartedSpy.count(), 1); - QCOMPARE(moveEndedSpy.count(), 0); - QCOMPARE(flickingSpy.count(), 1); - QCOMPARE(flickStartedSpy.count(), 1); - QCOMPARE(flickEndedSpy.count(), 0); + QCOMPARE(movingChangedSpy.size(), 1); + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); + QVERIFY(currentIndexSpy.size() > 0); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(flickingSpy.size(), 1); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 0); // Now while it's still moving, click it. // The PathView should stop at a position such that offset is a whole number. QTest::mouseClick(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(200, 200)); QTRY_VERIFY(!pathview->isMoving()); - QCOMPARE(movingChangedSpy.count(), 2); // QTBUG-78926 - QCOMPARE(draggingSpy.count(), 2); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 1); - QCOMPARE(moveStartedSpy.count(), 1); - QCOMPARE(moveEndedSpy.count(), 1); - QCOMPARE(flickingSpy.count(), 2); - QCOMPARE(flickStartedSpy.count(), 1); - QCOMPARE(flickEndedSpy.count(), 1); + QCOMPARE(movingChangedSpy.size(), 2); // QTBUG-78926 + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 1); + QCOMPARE(flickingSpy.size(), 2); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 1); QVERIFY(qFuzzyIsNull(pathview->offset() - int(pathview->offset()))); } } @@ -1758,7 +1762,7 @@ void tst_QQuickPathView::currentOffsetOnInsertion() model.insertItem(0, "item1", "1"); qApp->processEvents(); - QCOMPARE(currentIndexSpy.count(), 1); + QCOMPARE(currentIndexSpy.size(), 1); // currentIndex is now 1 item = findItem<QQuickRectangle>(pathview, "wrapper", 1); @@ -1771,7 +1775,7 @@ void tst_QQuickPathView::currentOffsetOnInsertion() model.insertItem(0, "item2", "2"); qApp->processEvents(); - QCOMPARE(currentIndexSpy.count(), 2); + QCOMPARE(currentIndexSpy.size(), 2); // currentIndex is now 2 item = findItem<QQuickRectangle>(pathview, "wrapper", 2); @@ -1784,7 +1788,7 @@ void tst_QQuickPathView::currentOffsetOnInsertion() model.removeItem(0); qApp->processEvents(); - QCOMPARE(currentIndexSpy.count(), 3); + QCOMPARE(currentIndexSpy.size(), 3); // currentIndex is now 1 item = findItem<QQuickRectangle>(pathview, "wrapper", 1); @@ -1892,9 +1896,9 @@ void tst_QQuickPathView::cancelDrag() QTRY_VERIFY(hasFraction(pathview->offset())); QTRY_VERIFY(pathview->isMoving()); QVERIFY(pathview->isDragging()); - QCOMPARE(draggingSpy.count(), 1); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 0); + QCOMPARE(draggingSpy.size(), 1); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 0); // steal mouse grab - cancels PathView dragging auto mouse = QPointingDevice::primaryPointingDevice(); @@ -1907,9 +1911,9 @@ void tst_QQuickPathView::cancelDrag() QTRY_COMPARE(pathview->offset(), qreal(qFloor(pathview->offset()))); QTRY_VERIFY(!pathview->isMoving()); QVERIFY(!pathview->isDragging()); - QCOMPARE(draggingSpy.count(), 2); - QCOMPARE(dragStartedSpy.count(), 1); - QCOMPARE(dragEndedSpy.count(), 1); + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(40,100)); } @@ -2017,7 +2021,7 @@ void tst_QQuickPathView::snapOneItem() QSignalSpy snapModeSpy(pathview, SIGNAL(snapModeChanged())); window->rootObject()->setProperty("snapOne", true); - QCOMPARE(snapModeSpy.count(), 1); + QCOMPARE(snapModeSpy.size(), 1); QTRY_VERIFY(!pathview->isMoving()); // ensure stable int currentIndex = pathview->currentIndex(); @@ -2298,22 +2302,22 @@ void tst_QQuickPathView::nestedinFlickable() // first move beyond threshold does not trigger drag QVERIFY(!pathview->isMoving()); QVERIFY(!pathview->isDragging()); - QCOMPARE(movingSpy.count(), 0); - QCOMPARE(moveStartedSpy.count(), 0); - QCOMPARE(moveEndedSpy.count(), 0); - QCOMPARE(fflickingSpy.count(), 0); - QCOMPARE(fflickStartedSpy.count(), 0); - QCOMPARE(fflickEndedSpy.count(), 0); + QCOMPARE(movingSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(fflickingSpy.size(), 0); + QCOMPARE(fflickStartedSpy.size(), 0); + QCOMPARE(fflickEndedSpy.size(), 0); // no further moves after the initial move beyond threshold QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(73,219)); - QTRY_COMPARE(movingSpy.count(), 2); - QTRY_COMPARE(moveEndedSpy.count(), 1); - QCOMPARE(moveStartedSpy.count(), 1); + QTRY_COMPARE(movingSpy.size(), 2); + QTRY_COMPARE(moveEndedSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); // Flickable should not handle this - QCOMPARE(fflickingSpy.count(), 0); - QCOMPARE(fflickStartedSpy.count(), 0); - QCOMPARE(fflickEndedSpy.count(), 0); + QCOMPARE(fflickingSpy.size(), 0); + QCOMPARE(fflickStartedSpy.size(), 0); + QCOMPARE(fflickEndedSpy.size(), 0); // now test that two quick flicks are both handled by the pathview movingSpy.clear(); @@ -2347,25 +2351,25 @@ void tst_QQuickPathView::nestedinFlickable() // we allow the multiple signal count case, rather than simply: // QTRY_COMPARE(moveEndedSpy.count(), 1); // QCOMPARE(moveStartedSpy.count(), 1); - QTRY_VERIFY(moveEndedSpy.count() > 0); + QTRY_VERIFY(moveEndedSpy.size() > 0); qCDebug(lcTests) << "After receiving moveEnded signal:" - << "moveEndedSpy.count():" << moveEndedSpy.count() - << "moveStartedSpy.count():" << moveStartedSpy.count() - << "fflickingSpy.count():" << fflickingSpy.count() - << "fflickStartedSpy.count():" << fflickStartedSpy.count() - << "fflickEndedSpy.count():" << fflickEndedSpy.count(); - QTRY_COMPARE(moveStartedSpy.count(), moveEndedSpy.count()); + << "moveEndedSpy.count():" << moveEndedSpy.size() + << "moveStartedSpy.count():" << moveStartedSpy.size() + << "fflickingSpy.count():" << fflickingSpy.size() + << "fflickStartedSpy.count():" << fflickStartedSpy.size() + << "fflickEndedSpy.count():" << fflickEndedSpy.size(); + QTRY_COMPARE(moveStartedSpy.size(), moveEndedSpy.size()); qCDebug(lcTests) << "After receiving matched moveEnded signal(s):" - << "moveEndedSpy.count():" << moveEndedSpy.count() - << "moveStartedSpy.count():" << moveStartedSpy.count() - << "fflickingSpy.count():" << fflickingSpy.count() - << "fflickStartedSpy.count():" << fflickStartedSpy.count() - << "fflickEndedSpy.count():" << fflickEndedSpy.count(); - QVERIFY(moveStartedSpy.count() <= 2); + << "moveEndedSpy.count():" << moveEndedSpy.size() + << "moveStartedSpy.count():" << moveStartedSpy.size() + << "fflickingSpy.count():" << fflickingSpy.size() + << "fflickStartedSpy.count():" << fflickStartedSpy.size() + << "fflickEndedSpy.count():" << fflickEndedSpy.size(); + QVERIFY(moveStartedSpy.size() <= 2); // Flickable should not handle this - QCOMPARE(fflickingSpy.count(), 0); - QCOMPARE(fflickStartedSpy.count(), 0); - QCOMPARE(fflickEndedSpy.count(), 0); + QCOMPARE(fflickingSpy.size(), 0); + QCOMPARE(fflickStartedSpy.size(), 0); + QCOMPARE(fflickEndedSpy.size(), 0); } @@ -2436,22 +2440,22 @@ void tst_QQuickPathView::flickableDelegate() // first move beyond threshold does not trigger drag QVERIFY(!flickable->isMoving()); QVERIFY(!flickable->isDragging()); - QCOMPARE(movingSpy.count(), 0); - QCOMPARE(moveStartedSpy.count(), 0); - QCOMPARE(moveEndedSpy.count(), 0); - QCOMPARE(fflickingSpy.count(), 0); - QCOMPARE(fflickStartedSpy.count(), 0); - QCOMPARE(fflickEndedSpy.count(), 0); + QCOMPARE(movingSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(fflickingSpy.size(), 0); + QCOMPARE(fflickStartedSpy.size(), 0); + QCOMPARE(fflickEndedSpy.size(), 0); // no further moves after the initial move beyond threshold QTest::mouseRelease(window.data(), Qt::LeftButton, Qt::NoModifier, QPoint(53,100)); - QTRY_COMPARE(fflickingSpy.count(), 2); - QTRY_COMPARE(fflickStartedSpy.count(), 1); - QCOMPARE(fflickEndedSpy.count(), 1); + QTRY_COMPARE(fflickingSpy.size(), 2); + QTRY_COMPARE(fflickStartedSpy.size(), 1); + QCOMPARE(fflickEndedSpy.size(), 1); // PathView should not handle this - QTRY_COMPARE(movingSpy.count(), 0); - QTRY_COMPARE(moveEndedSpy.count(), 0); - QCOMPARE(moveStartedSpy.count(), 0); + QTRY_COMPARE(movingSpy.size(), 0); + QTRY_COMPARE(moveEndedSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); } void tst_QQuickPathView::jsArrayChange() @@ -2474,11 +2478,11 @@ void tst_QQuickPathView::jsArrayChange() } view->setModel(QVariant::fromValue(array1)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // no change view->setModel(QVariant::fromValue(array2)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QQuickPathView::qtbug37815() @@ -2688,7 +2692,7 @@ void tst_QQuickPathView::objectModelMove() QVector<QString> itemObjectNames; itemObjectNames << QLatin1String("red") << QLatin1String("green") << QLatin1String("blue"); QVector<QQuickItem*> childItems; - for (const QString &itemObjectName : qAsConst(itemObjectNames)) { + for (const QString &itemObjectName : std::as_const(itemObjectNames)) { QQuickItem *childItem = findItem<QQuickItem>(pathView, itemObjectName); QVERIFY(childItem); childItems.append(childItem); @@ -2701,7 +2705,7 @@ void tst_QQuickPathView::objectModelMove() QTRY_VERIFY(pathView.isNull()); // By this point, all of its cached items should have been released, // which means none of the items should have any listeners. - for (const auto childItem : qAsConst(childItems)) { + for (const auto childItem : std::as_const(childItems)) { const QQuickItemPrivate *childItemPrivate = QQuickItemPrivate::get(childItem); QCOMPARE(childItemPrivate->changeListeners.size(), 0); } @@ -2741,6 +2745,112 @@ void tst_QQuickPathView::requiredPropertiesInDelegatePreventUnrelated() window->show(); } +void tst_QQuickPathView::touchMove() +{ + QScopedPointer<QQuickView> window(createView()); + QQuickVisualTestUtils::moveMouseAway(window.data()); + window->setSource(testFileUrl("dragpath.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject()); + QVERIFY(pathview != nullptr); + + QSignalSpy movingSpy(pathview, SIGNAL(movingChanged())); + QSignalSpy moveStartedSpy(pathview, SIGNAL(movementStarted())); + QSignalSpy moveEndedSpy(pathview, SIGNAL(movementEnded())); + QSignalSpy draggingSpy(pathview, SIGNAL(draggingChanged())); + QSignalSpy dragStartedSpy(pathview, SIGNAL(dragStarted())); + QSignalSpy dragEndedSpy(pathview, SIGNAL(dragEnded())); + QSignalSpy flickStartedSpy(pathview, SIGNAL(flickStarted())); + QSignalSpy flickEndedSpy(pathview, SIGNAL(flickEnded())); + + int current = pathview->currentIndex(); + + // touch move from left to right + QPoint from(250, 100); + QPoint to(10, 100); + + QTest::touchEvent(window.data(), touchDevice.data()).press(0, from, window.data()); + QQuickTouchUtils::flush(window.data()); + + QVERIFY(!pathview->isMoving()); + QVERIFY(!pathview->isDragging()); + QCOMPARE(movingSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 0); + QCOMPARE(dragStartedSpy.size(), 0); + QCOMPARE(dragEndedSpy.size(), 0); + QCOMPARE(flickStartedSpy.size(), 0); + QCOMPARE(flickEndedSpy.size(), 0); + + from -= QPoint(QGuiApplication::styleHints()->startDragDistance() + 1, 0); + QTest::touchEvent(window.data(), touchDevice.data()).move(0, from, window.data()); + QQuickTouchUtils::flush(window.data()); + + // first move does not trigger move/drag + QVERIFY(!pathview->isMoving()); + QVERIFY(!pathview->isDragging()); + QCOMPARE(movingSpy.size(), 0); + QCOMPARE(moveStartedSpy.size(), 0); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 0); + QCOMPARE(dragStartedSpy.size(), 0); + QCOMPARE(dragEndedSpy.size(), 0); + QCOMPARE(flickStartedSpy.size(), 0); + QCOMPARE(flickEndedSpy.size(), 0); + + QPoint diff = from - to; + int moveCount = 4; + for (int i = 1; i <= moveCount; ++i) { + QTest::touchEvent(window.data(), touchDevice.data()).move(0, from - i * diff / moveCount, window.data()); + QQuickTouchUtils::flush(window.data()); + + QVERIFY(pathview->isMoving()); + QVERIFY(pathview->isDragging()); + QCOMPARE(movingSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 1); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 0); + QCOMPARE(flickStartedSpy.size(), 0); + QCOMPARE(flickEndedSpy.size(), 0); + } + QVERIFY(pathview->currentIndex() != current); + + QTest::touchEvent(window.data(), touchDevice.data()).release(0, to, window.data()); + QQuickTouchUtils::flush(window.data()); + + QVERIFY(pathview->isMoving()); + QVERIFY(!pathview->isDragging()); + QCOMPARE(movingSpy.size(), 1); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 0); + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 0); + + // Wait for the flick to finish + QVERIFY(QTest::qWaitFor([&]() + { return !pathview->isFlicking(); } + )); + QVERIFY(!pathview->isMoving()); + QVERIFY(!pathview->isDragging()); + QCOMPARE(movingSpy.size(), 2); + QCOMPARE(moveStartedSpy.size(), 1); + QCOMPARE(moveEndedSpy.size(), 1); + QCOMPARE(draggingSpy.size(), 2); + QCOMPARE(dragStartedSpy.size(), 1); + QCOMPARE(dragEndedSpy.size(), 1); + QCOMPARE(flickStartedSpy.size(), 1); + QCOMPARE(flickEndedSpy.size(), 1); + +} + QTEST_MAIN(tst_QQuickPathView) #include "tst_qquickpathview.moc" diff --git a/tests/auto/quick/qquickpincharea/data/pinchAreaInPathView.qml b/tests/auto/quick/qquickpincharea/data/pinchAreaInPathView.qml new file mode 100644 index 0000000000..dc909c2c7c --- /dev/null +++ b/tests/auto/quick/qquickpincharea/data/pinchAreaInPathView.qml @@ -0,0 +1,48 @@ +import QtQuick + +PathView { + width: 600 + height: 200 + + model: 3 + delegate: Rectangle { + width: 200 + height: 200 + color: "salmon" + opacity: PathView.isCurrentItem ? 1 : 0.5 + + property alias pinchArea: pinchArea + + Text { + text: "Test" + font.pixelSize: 100 + anchors.fill: parent + fontSizeMode: Text.Fit + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + PinchArea { + id: pinchArea + anchors.fill: parent + pinch.target: parent + pinch.dragAxis: Pinch.XAndYAxis + pinch.minimumScale: 1.0 + pinch.maximumScale: 5.0 + + onPinchFinished: (pinch) => { + parent.scale = 1 + parent.x = 0 + parent.y = 0 + } + } + } + path: Path { + startX: 100 + startY: 100 + PathLine { + x: 700 + y: 100 + } + } +} diff --git a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp index d23f804690..800d7211fb 100644 --- a/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp +++ b/tests/auto/quick/qquickpincharea/tst_qquickpincharea.cpp @@ -1,6 +1,7 @@ // Copyright (C) 2020 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +#include <QtCore/private/qvariantanimation_p.h> #include <QtTest/QtTest> #include <QtTest/QSignalSpy> #include <QtGui/QStyleHints> @@ -8,6 +9,7 @@ #include <QtGui/private/qeventpoint_p.h> #include <qpa/qwindowsysteminterface.h> #include <private/qquickpincharea_p.h> +#include <QtQuick/private/qquickpathview_p.h> #include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/qquickview.h> #include <QtQml/qqmlcontext.h> @@ -30,6 +32,8 @@ private slots: void transformedPinchArea(); void dragTransformedPinchArea_data(); void dragTransformedPinchArea(); + void pinchAreaKeepsDragInView(); + void pinchInPathView(); private: QQuickView *createView(); @@ -60,18 +64,18 @@ void tst_QQuickPinchArea::pinchProperties() QVERIFY(rootItem != nullptr); QSignalSpy targetSpy(pinch, SIGNAL(targetChanged())); pinch->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); pinch->setTarget(rootItem); - QCOMPARE(targetSpy.count(),1); + QCOMPARE(targetSpy.size(),1); // axis QCOMPARE(pinch->axis(), QQuickPinch::XAndYAxis); QSignalSpy axisSpy(pinch, SIGNAL(dragAxisChanged())); pinch->setAxis(QQuickPinch::XAxis); QCOMPARE(pinch->axis(), QQuickPinch::XAxis); - QCOMPARE(axisSpy.count(),1); + QCOMPARE(axisSpy.size(),1); pinch->setAxis(QQuickPinch::XAxis); - QCOMPARE(axisSpy.count(),1); + QCOMPARE(axisSpy.size(),1); // minimum and maximum drag properties QSignalSpy xminSpy(pinch, SIGNAL(minimumXChanged())); @@ -94,20 +98,20 @@ void tst_QQuickPinchArea::pinchProperties() QCOMPARE(pinch->ymin(), 10.0); QCOMPARE(pinch->ymax(), 10.0); - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); + QCOMPARE(xminSpy.size(),1); + QCOMPARE(xmaxSpy.size(),1); + QCOMPARE(yminSpy.size(),1); + QCOMPARE(ymaxSpy.size(),1); pinch->setXmin(10); pinch->setXmax(10); pinch->setYmin(10); pinch->setYmax(10); - QCOMPARE(xminSpy.count(),1); - QCOMPARE(xmaxSpy.count(),1); - QCOMPARE(yminSpy.count(),1); - QCOMPARE(ymaxSpy.count(),1); + QCOMPARE(xminSpy.size(),1); + QCOMPARE(xmaxSpy.size(),1); + QCOMPARE(yminSpy.size(),1); + QCOMPARE(ymaxSpy.size(),1); // minimum and maximum scale properties QSignalSpy scaleMinSpy(pinch, SIGNAL(minimumScaleChanged())); @@ -122,14 +126,14 @@ void tst_QQuickPinchArea::pinchProperties() QCOMPARE(pinch->minimumScale(), 0.5); QCOMPARE(pinch->maximumScale(), 1.5); - QCOMPARE(scaleMinSpy.count(),1); - QCOMPARE(scaleMaxSpy.count(),1); + QCOMPARE(scaleMinSpy.size(),1); + QCOMPARE(scaleMaxSpy.size(),1); pinch->setMinimumScale(0.5); pinch->setMaximumScale(1.5); - QCOMPARE(scaleMinSpy.count(),1); - QCOMPARE(scaleMaxSpy.count(),1); + QCOMPARE(scaleMinSpy.size(),1); + QCOMPARE(scaleMaxSpy.size(),1); // minimum and maximum rotation properties QSignalSpy rotMinSpy(pinch, SIGNAL(minimumRotationChanged())); @@ -144,14 +148,14 @@ void tst_QQuickPinchArea::pinchProperties() QCOMPARE(pinch->minimumRotation(), -90.0); QCOMPARE(pinch->maximumRotation(), 45.0); - QCOMPARE(rotMinSpy.count(),1); - QCOMPARE(rotMaxSpy.count(),1); + QCOMPARE(rotMinSpy.size(),1); + QCOMPARE(rotMaxSpy.size(),1); pinch->setMinimumRotation(-90.0); pinch->setMaximumRotation(45.0); - QCOMPARE(rotMinSpy.count(),1); - QCOMPARE(rotMaxSpy.count(),1); + QCOMPARE(rotMinSpy.size(),1); + QCOMPARE(rotMaxSpy.size(),1); } QEventPoint makeTouchPoint(int id, QPoint p, QQuickView *v, QQuickItem *i) @@ -384,7 +388,7 @@ void tst_QQuickPinchArea::retouch() pinchSequence.move(0, p1,window).move(1, p2,window).commit(); QQuickTouchUtils::flush(window); - QCOMPARE(startedSpy.count(), 1); + QCOMPARE(startedSpy.size(), 1); QCOMPARE(root->property("scale").toReal(), 1.5); QCOMPARE(root->property("center").toPointF(), QPointF(40, 40)); // blackrect is at 50,50 @@ -392,15 +396,15 @@ void tst_QQuickPinchArea::retouch() QCOMPARE(window->rootObject()->property("pointCount").toInt(), 2); - QCOMPARE(startedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(startedSpy.size(), 1); + QCOMPARE(finishedSpy.size(), 0); // Hold down the first finger but release the second one pinchSequence.stationary(0).release(1, p2, window).commit(); QQuickTouchUtils::flush(window); - QCOMPARE(startedSpy.count(), 1); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(startedSpy.size(), 1); + QCOMPARE(finishedSpy.size(), 0); QCOMPARE(window->rootObject()->property("pointCount").toInt(), 1); @@ -413,8 +417,8 @@ void tst_QQuickPinchArea::retouch() QQuickTouchUtils::flush(window); // Lifting and retouching results in onPinchStarted being called again - QCOMPARE(startedSpy.count(), 2); - QCOMPARE(finishedSpy.count(), 0); + QCOMPARE(startedSpy.size(), 2); + QCOMPARE(finishedSpy.size(), 0); QCOMPARE(window->rootObject()->property("pointCount").toInt(), 2); @@ -422,8 +426,8 @@ void tst_QQuickPinchArea::retouch() QQuickTouchUtils::flush(window); QVERIFY(!root->property("pinchActive").toBool()); - QCOMPARE(startedSpy.count(), 2); - QCOMPARE(finishedSpy.count(), 1); + QCOMPARE(startedSpy.size(), 2); + QCOMPARE(finishedSpy.size(), 1); } } @@ -618,6 +622,147 @@ void tst_QQuickPinchArea::dragTransformedPinchArea() // QTBUG-63673 QCOMPARE(pinchArea->pinch()->active(), false); } +template<typename F> +void forEachLerpStep(int steps, F &&func) +{ + for (int i = 0; i < steps; ++i) { + const qreal t = qreal(i) / steps; + func(t); + } +} + +QPoint lerpPoints(const QPoint &point1, const QPoint &point2, qreal t) +{ + return QPoint(_q_interpolate(point1.x(), point2.x(), t), _q_interpolate(point1.y(), point2.y(), t)); +}; + +// QTBUG-105058 +void tst_QQuickPinchArea::pinchAreaKeepsDragInView() +{ + QQuickView view; + view.setSource(testFileUrl("pinchAreaInPathView.qml")); + QVERIFY(view.rootObject()); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickPathView *pathView = qobject_cast<QQuickPathView*>(view.rootObject()); + QVERIFY(pathView); + QCOMPARE(pathView->count(), 3); + + const QQuickItem *pinchDelegateItem = pathView->itemAtIndex(0); + QQuickPinchArea *pinchArea = pinchDelegateItem->property("pinchArea").value<QQuickPinchArea*>(); + QVERIFY(pinchArea); + + // Press. + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&view, device); + QPoint point1Start = { 80, 120 }; + QPoint point2Start = { 120, 80 }; + const int dragThreshold = qApp->styleHints()->startDragDistance(); + pinchSequence.press(1, pinchArea->mapToScene(point1Start).toPoint(), &view) + .press(2, pinchArea->mapToScene(point2Start).toPoint(), &view).commit(); + QQuickTouchUtils::flush(&view); + + // Move past the drag threshold to begin the pinch. + const int steps = 30; + QPoint point1End = point1Start + QPoint(-dragThreshold, dragThreshold); + QPoint point2End = point2Start + QPoint(dragThreshold, -dragThreshold); + forEachLerpStep(steps, [&](qreal t) { + pinchSequence.move(1, lerpPoints(point1Start, point1End, t), &view) + .move(2, lerpPoints(point2Start, point2End, t), &view).commit(); + QQuickTouchUtils::flush(&view); + QTest::qWait(5); + }); + QCOMPARE(pinchArea->pinch()->active(), true); + QVERIFY2(pinchDelegateItem->scale() > 1.0, qPrintable(QString::number(pinchDelegateItem->scale()))); + // The PathView contents shouldn't have moved. + QCOMPARE(pathView->offset(), 0); + + // Release a touch point. + pinchSequence.stationary(1).release(2, point2End, &view).commit(); + QQuickTouchUtils::flush(&view); + + // Press it again. + pinchSequence.stationary(1).press(2, point2End, &view).commit(); + QQuickTouchUtils::flush(&view); + QCOMPARE(pinchArea->pinch()->active(), true); + + // Drag to the right; the PathView still shouldn't move. + point1Start = point1End; + point2Start = point2End; + point1End = point1Start + QPoint(100, 0); + point2End = point2Start + QPoint(100, 0); + forEachLerpStep(steps, [&](qreal t) { + pinchSequence.move(1, lerpPoints(point1Start, point1End, t), &view) + .move(2, lerpPoints(point2Start, point2End, t), &view).commit(); + QQuickTouchUtils::flush(&view); + QTest::qWait(5); + }); + QCOMPARE(pinchArea->pinch()->active(), true); + QVERIFY2(pinchDelegateItem->scale() > 1.0, qPrintable(QString::number(pinchDelegateItem->scale()))); + QCOMPARE(pathView->offset(), 0); + + // Release pinch. + pinchSequence.release(1, point1End, &view).release(2, point2End, &view).commit(); + QQuickTouchUtils::flush(&view); + QCOMPARE(pinchArea->pinch()->active(), false); + QCOMPARE(pathView->offset(), 0); +} + +void tst_QQuickPinchArea::pinchInPathView() +{ + QQuickView view; + view.setSource(testFileUrl("pinchAreaInPathView.qml")); + QVERIFY(view.rootObject()); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + QQuickPathView *pathView = qobject_cast<QQuickPathView*>(view.rootObject()); + QVERIFY(pathView); + QCOMPARE(pathView->count(), 3); + + const QQuickItem *pinchDelegateItem = pathView->itemAtIndex(0); + QQuickPinchArea *pinchArea = pinchDelegateItem->property("pinchArea").value<QQuickPinchArea*>(); + QVERIFY(pinchArea); + + // press + QTest::QTouchEventSequence pinchSequence = QTest::touchEvent(&view, device); + QPoint point1Start = { 10, 10 }; + QPoint point2Start = { 100, 100 }; + const int dragThreshold = qApp->styleHints()->startDragDistance(); + pinchSequence.press(0, point1Start, &view) + .press(1, point2Start, &view) + .commit(); + QQuickTouchUtils::flush(&view); + QTest::qWait(20); + + // move + QPoint moveDistance = QPoint(dragThreshold * 3, dragThreshold * 3); + QPoint point2End = point2Start + moveDistance; + pinchSequence.stationary(0) + .move(1, point2End, &view) + .commit(); + QQuickTouchUtils::flush(&view); + QTest::qWait(20); + + point2End += moveDistance; + pinchSequence.stationary(0) + .move(1, point2End, &view) + .commit(); + QQuickTouchUtils::flush(&view); + QTest::qWait(20); + + QCOMPARE(pinchArea->pinch()->active(), true); + QVERIFY2(pinchDelegateItem->scale() > 1.0, qPrintable(QString::number(pinchDelegateItem->scale()))); + // PathView shouldn't have moved. + QCOMPARE(pathView->offset(), 0); + + // release pinch. + pinchSequence.release(0, point1Start, &view).release(1, point2End, &view).commit(); + QQuickTouchUtils::flush(&view); + QCOMPARE(pinchArea->pinch()->active(), false); + QCOMPARE(pathView->offset(), 0); +} + QQuickView *tst_QQuickPinchArea::createView() { QQuickView *window = new QQuickView(nullptr); diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index dbcb502653..590f022e4e 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -203,7 +203,7 @@ void tst_qquickpixmapcache::parallel() QList<bool> pending; QList<Slotter*> getters; - for (int i=0; i<targets.count(); ++i) { + for (int i=0; i<targets.size(); ++i) { QUrl target = targets.at(i); QQuickPixmap *pixmap = new QQuickPixmap; @@ -223,9 +223,9 @@ void tst_qquickpixmapcache::parallel() } } - if (incache + slotters != targets.count()) + if (incache + slotters != targets.size()) QFAIL(QString::fromLatin1("pixmap counts don't add up: %1 incache, %2 slotters, %3 total") - .arg(incache).arg(slotters).arg(targets.count()).toLatin1().constData()); + .arg(incache).arg(slotters).arg(targets.size()).toLatin1().constData()); if (cancel >= 0) { pixmaps.at(cancel)->clear(getters[cancel]); @@ -237,7 +237,7 @@ void tst_qquickpixmapcache::parallel() QVERIFY(!QTestEventLoop::instance().timeout()); } - for (int i=0; i<targets.count(); ++i) { + for (int i=0; i<targets.size(); ++i) { QQuickPixmap *pixmap = pixmaps[i]; if (i == cancel) { diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index ab8e83b488..317694f06c 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -1149,7 +1149,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) targetItems = findItems<QQuickItem>(positioner, "wrapper", targetIndexes); - QTRY_COMPARE(window->rootObject()->property("addTransitionsDone").toInt(), targetData.count()); + QTRY_COMPARE(window->rootObject()->property("addTransitionsDone").toInt(), targetData.size()); QTRY_COMPARE(window->rootObject()->property("displaceTransitionsDone").toInt(), expectedDisplacedIndexes.count()); // check the target and displaced items were animated @@ -1262,9 +1262,9 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) model_displacedItems_transitionVia.matchAgainst(expectedDisplacedValues, "wasn't animated with displaced anim", "shouldn't have been animated with displaced anim"); // check attached properties - QCOMPARE(window->rootObject()->property("targetTrans_items").toMap().count(), 0); - QCOMPARE(window->rootObject()->property("targetTrans_targetIndexes").toList().count(), 0); - QCOMPARE(window->rootObject()->property("targetTrans_targetItems").toList().count(), 0); + QCOMPARE(window->rootObject()->property("targetTrans_items").toMap().size(), 0); + QCOMPARE(window->rootObject()->property("targetTrans_targetIndexes").toList().size(), 0); + QCOMPARE(window->rootObject()->property("targetTrans_targetItems").toList().size(), 0); if (expectedDisplacedIndexes.isValid()) { // adjust expectedDisplacedIndexes to their final values after the move QList<int> displacedIndexes; @@ -1279,12 +1279,12 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) matchItemsAndIndexes(window->rootObject()->property("displacedTrans_items").toMap(), model, displacedIndexes); QVariantList listOfEmptyIntLists; - for (int i=0; i<displacedIndexes.count(); i++) + for (int i=0; i<displacedIndexes.size(); i++) listOfEmptyIntLists << QVariant::fromValue(QList<int>()); QCOMPARE(window->rootObject()->property("displacedTrans_targetIndexes").toList(), listOfEmptyIntLists); QVariantList listOfEmptyObjectLists; - for (int i=0; i<displacedIndexes.count(); i++) - listOfEmptyObjectLists.insert(listOfEmptyObjectLists.count(), QVariantList()); + for (int i=0; i<displacedIndexes.size(); i++) + listOfEmptyObjectLists.insert(listOfEmptyObjectLists.size(), QVariantList()); QCOMPARE(window->rootObject()->property("displacedTrans_targetItems").toList(), listOfEmptyObjectLists); } @@ -2938,37 +2938,37 @@ void tst_qquickpositioners::test_propertychanges() grid->setMove(rowTransition); QCOMPARE(grid->add(), rowTransition); QCOMPARE(grid->move(), rowTransition); - QCOMPARE(addSpy.count(),1); - QCOMPARE(moveSpy.count(),1); + QCOMPARE(addSpy.size(),1); + QCOMPARE(moveSpy.size(),1); grid->setAdd(rowTransition); grid->setMove(rowTransition); - QCOMPARE(addSpy.count(),1); - QCOMPARE(moveSpy.count(),1); + QCOMPARE(addSpy.size(),1); + QCOMPARE(moveSpy.size(),1); grid->setAdd(nullptr); grid->setMove(nullptr); - QCOMPARE(addSpy.count(),2); - QCOMPARE(moveSpy.count(),2); + QCOMPARE(addSpy.size(),2); + QCOMPARE(moveSpy.size(),2); grid->setColumns(-1); grid->setRows(3); QCOMPARE(grid->columns(), -1); QCOMPARE(grid->rows(), 3); - QCOMPARE(columnsSpy.count(),1); - QCOMPARE(rowsSpy.count(),1); + QCOMPARE(columnsSpy.size(),1); + QCOMPARE(rowsSpy.size(),1); grid->setColumns(-1); grid->setRows(3); - QCOMPARE(columnsSpy.count(),1); - QCOMPARE(rowsSpy.count(),1); + QCOMPARE(columnsSpy.size(),1); + QCOMPARE(rowsSpy.size(),1); QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Grid: Grid contains more visible items \\(20\\) than rows\\*columns \\(6\\)")); grid->setColumns(2); QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*QML Grid: Grid contains more visible items \\(20\\) than rows\\*columns \\(4\\)")); grid->setRows(2); - QCOMPARE(columnsSpy.count(),2); - QCOMPARE(rowsSpy.count(),2); + QCOMPARE(columnsSpy.size(),2); + QCOMPARE(rowsSpy.size(),2); } @@ -4012,7 +4012,7 @@ QQuickView *tst_qquickpositioners::createView(const QString &filename, bool wait void tst_qquickpositioners::matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes) { const QSet<int> expectedIndexSet(expectedIndexes.cbegin(), expectedIndexes.cend()); - for (int i=0; i<indexLists.count(); i++) { + for (int i=0; i<indexLists.size(); i++) { const auto ¤tList = indexLists[i].value<QList<int> >(); const QSet<int> current(currentList.cbegin(), currentList.cend()); if (current != expectedIndexSet) @@ -4032,20 +4032,20 @@ void tst_qquickpositioners::matchItemsAndIndexes(const QVariantMap &items, const qDebug() << itemIndex; QCOMPARE(model.name(itemIndex), name); } - QCOMPARE(items.count(), expectedIndexes.count()); + QCOMPARE(items.size(), expectedIndexes.size()); } void tst_qquickpositioners::matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems) { - for (int i=0; i<itemLists.count(); i++) { + for (int i=0; i<itemLists.size(); i++) { QCOMPARE(itemLists[i].typeId(), QMetaType::QVariantList); QVariantList current = itemLists[i].toList(); - for (int j=0; j<current.count(); j++) { + for (int j=0; j<current.size(); j++) { QQuickItem *o = qobject_cast<QQuickItem*>(current[j].value<QObject*>()); QVERIFY2(o, QTest::toString(QString("Invalid actual item at %1").arg(j))); QVERIFY2(expectedItems.contains(o), QTest::toString(QString("Cannot match item %1").arg(j))); } - QCOMPARE(current.count(), expectedItems.count()); + QCOMPARE(current.size(), expectedItems.size()); } } diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp index 644e698647..d5520de682 100644 --- a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp +++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp @@ -75,7 +75,7 @@ void tst_qquickrectangle::gradient() QCOMPARE(stops.at(&stops, 1)->color(), QColor("white")); QGradientStops gradientStops = grad->gradientStops(); - QCOMPARE(gradientStops.count(), 2); + QCOMPARE(gradientStops.size(), 2); QCOMPARE(gradientStops.at(0).first, 0.0); QCOMPARE(gradientStops.at(0).second, QColor("gray")); QCOMPARE(gradientStops.at(1).first, 1.0); @@ -189,46 +189,46 @@ void tst_qquickrectangle::antialiasing() rect->setAntialiasing(true); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); rect->setAntialiasing(true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); rect->resetAntialiasing(); QCOMPARE(rect->antialiasing(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); rect->setRadius(5); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); rect->resetAntialiasing(); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); rect->setRadius(0); QCOMPARE(rect->antialiasing(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); rect->resetAntialiasing(); QCOMPARE(rect->antialiasing(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); rect->setRadius(5); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); rect->resetAntialiasing(); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); rect->setAntialiasing(false); QCOMPARE(rect->antialiasing(), false); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); rect->resetAntialiasing(); QCOMPARE(rect->antialiasing(), true); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); } QTEST_MAIN(tst_qquickrectangle) diff --git a/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp b/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp index b1cc9563eb..2d56312f9d 100644 --- a/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp +++ b/tests/auto/quick/qquickrendercontrol/tst_qquickrendercontrol.cpp @@ -388,7 +388,7 @@ void tst_RenderControl::renderAndReadBackWithVulkanNative() f->vkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, queueFamilyProps.data()); int gfxQueueFamilyIdx = -1; - for (int i = 0; i < queueFamilyProps.count(); ++i) { + for (int i = 0; i < queueFamilyProps.size(); ++i) { if (queueFamilyProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { gfxQueueFamilyIdx = i; break; diff --git a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp index befa16b632..5a6498a5d7 100644 --- a/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp +++ b/tests/auto/quick/qquickrepeater/tst_qquickrepeater.cpp @@ -106,7 +106,7 @@ void tst_QQuickRepeater::numberModel() QQuickRepeater *repeater = findItem<QQuickRepeater>(window->rootObject(), "repeater"); QVERIFY(repeater != nullptr); - QCOMPARE(repeater->parentItem()->childItems().count(), 5+1); + QCOMPARE(repeater->parentItem()->childItems().size(), 5+1); QVERIFY(!repeater->itemAt(-1)); for (int i=0; i<repeater->count(); i++) @@ -117,10 +117,10 @@ void tst_QQuickRepeater::numberModel() QVERIFY(!testObject->error()); ctxt->setContextProperty("testData", std::numeric_limits<int>::max()); - QCOMPARE(repeater->parentItem()->childItems().count(), 1); + QCOMPARE(repeater->parentItem()->childItems().size(), 1); ctxt->setContextProperty("testData", -1234); - QCOMPARE(repeater->parentItem()->childItems().count(), 1); + QCOMPARE(repeater->parentItem()->childItems().size(), 1); delete testObject; delete window; @@ -166,15 +166,15 @@ void tst_QQuickRepeater::objectList() QCOMPARE(repeater->property("instantiated").toInt(), 100); QVERIFY(!repeater->itemAt(-1)); - for (int i=0; i<data.count(); i++) + for (int i=0; i<data.size(); i++) QCOMPARE(repeater->itemAt(i), repeater->parentItem()->childItems().at(i)); - QVERIFY(!repeater->itemAt(data.count())); + QVERIFY(!repeater->itemAt(data.size())); QSignalSpy addedSpy(repeater, SIGNAL(itemAdded(int,QQuickItem*))); QSignalSpy removedSpy(repeater, SIGNAL(itemRemoved(int,QQuickItem*))); ctxt->setContextProperty("testData", QVariant::fromValue(data)); - QCOMPARE(addedSpy.count(), data.count()); - QCOMPARE(removedSpy.count(), data.count()); + QCOMPARE(addedSpy.size(), data.size()); + QCOMPARE(removedSpy.size(), data.size()); qDeleteAll(data); delete window; @@ -207,22 +207,22 @@ void tst_QQuickRepeater::stringList() QQuickItem *container = findItem<QQuickItem>(window->rootObject(), "container"); QVERIFY(container != nullptr); - QCOMPARE(container->childItems().count(), data.count() + 3); + QCOMPARE(container->childItems().size(), data.size() + 3); bool saw_repeater = false; - for (int i = 0; i < container->childItems().count(); ++i) { + for (int i = 0; i < container->childItems().size(); ++i) { if (i == 0) { QQuickText *name = qobject_cast<QQuickText*>(container->childItems().at(i)); QVERIFY(name != nullptr); QCOMPARE(name->text(), QLatin1String("Zero")); - } else if (i == container->childItems().count() - 2) { + } else if (i == container->childItems().size() - 2) { // The repeater itself QQuickRepeater *rep = qobject_cast<QQuickRepeater*>(container->childItems().at(i)); QCOMPARE(rep, repeater); saw_repeater = true; continue; - } else if (i == container->childItems().count() - 1) { + } else if (i == container->childItems().size() - 1) { QQuickText *name = qobject_cast<QQuickText*>(container->childItems().at(i)); QVERIFY(name != nullptr); QCOMPARE(name->text(), QLatin1String("Last")); @@ -262,8 +262,8 @@ void tst_QQuickRepeater::dataModel_adding() // add to empty model testModel.addItem("two", "2"); QCOMPARE(repeater->itemAt(0), container->childItems().at(0)); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(addedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(addedSpy.size(), 1); QCOMPARE(addedSpy.at(0).at(0).toInt(), 0); QCOMPARE(addedSpy.at(0).at(1).value<QQuickItem*>(), container->childItems().at(0)); addedSpy.clear(); @@ -271,8 +271,8 @@ void tst_QQuickRepeater::dataModel_adding() // insert at start testModel.insertItem(0, "one", "1"); QCOMPARE(repeater->itemAt(0), container->childItems().at(0)); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(addedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(addedSpy.size(), 1); QCOMPARE(addedSpy.at(0).at(0).toInt(), 0); QCOMPARE(addedSpy.at(0).at(1).value<QQuickItem*>(), container->childItems().at(0)); addedSpy.clear(); @@ -280,8 +280,8 @@ void tst_QQuickRepeater::dataModel_adding() // insert at end testModel.insertItem(2, "four", "4"); QCOMPARE(repeater->itemAt(2), container->childItems().at(2)); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(addedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(addedSpy.size(), 1); QCOMPARE(addedSpy.at(0).at(0).toInt(), 2); QCOMPARE(addedSpy.at(0).at(1).value<QQuickItem*>(), container->childItems().at(2)); addedSpy.clear(); @@ -289,8 +289,8 @@ void tst_QQuickRepeater::dataModel_adding() // insert in middle testModel.insertItem(2, "three", "3"); QCOMPARE(repeater->itemAt(2), container->childItems().at(2)); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(addedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(addedSpy.size(), 1); QCOMPARE(addedSpy.at(0).at(0).toInt(), 2); QCOMPARE(addedSpy.at(0).at(1).value<QQuickItem*>(), container->childItems().at(2)); addedSpy.clear(); @@ -300,8 +300,8 @@ void tst_QQuickRepeater::dataModel_adding() QList<QPair<QString, QString> > multiData; multiData << qMakePair(QStringLiteral("five"), QStringLiteral("5")) << qMakePair(QStringLiteral("six"), QStringLiteral("6")) << qMakePair(QStringLiteral("seven"), QStringLiteral("7")); testModel.insertItems(1, multiData); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(addedSpy.count(), 3); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(addedSpy.size(), 3); QCOMPARE(container->childItems().size(), childItemsSize + 3); QCOMPARE(repeater->itemAt(2), container->childItems().at(2)); addedSpy.clear(); @@ -335,7 +335,7 @@ void tst_QQuickRepeater::dataModel_removing() QVERIFY(repeater != nullptr); QQuickItem *container = findItem<QQuickItem>(window->rootObject(), "container"); QVERIFY(container != nullptr); - QCOMPARE(container->childItems().count(), repeater->count()+1); + QCOMPARE(container->childItems().size(), repeater->count()+1); QSignalSpy countSpy(repeater, SIGNAL(countChanged())); QSignalSpy removedSpy(repeater, SIGNAL(itemRemoved(int,QQuickItem*))); @@ -346,8 +346,8 @@ void tst_QQuickRepeater::dataModel_removing() testModel.removeItem(0); QVERIFY(repeater->itemAt(0) != item); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(removedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(removedSpy.size(), 1); QCOMPARE(removedSpy.at(0).at(0).toInt(), 0); QCOMPARE(removedSpy.at(0).at(1).value<QQuickItem*>(), item); removedSpy.clear(); @@ -359,8 +359,8 @@ void tst_QQuickRepeater::dataModel_removing() testModel.removeItem(lastIndex); QVERIFY(repeater->itemAt(lastIndex) != item); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(removedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(removedSpy.size(), 1); QCOMPARE(removedSpy.at(0).at(0).toInt(), lastIndex); QCOMPARE(removedSpy.at(0).at(1).value<QQuickItem*>(), item); removedSpy.clear(); @@ -371,8 +371,8 @@ void tst_QQuickRepeater::dataModel_removing() testModel.removeItem(1); QVERIFY(repeater->itemAt(lastIndex) != item); - QCOMPARE(countSpy.count(), 1); countSpy.clear(); - QCOMPARE(removedSpy.count(), 1); + QCOMPARE(countSpy.size(), 1); countSpy.clear(); + QCOMPARE(removedSpy.size(), 1); QCOMPARE(removedSpy.at(0).at(0).toInt(), 1); QCOMPARE(removedSpy.at(0).at(1).value<QQuickItem*>(), item); removedSpy.clear(); @@ -401,7 +401,7 @@ void tst_QQuickRepeater::dataModel_changes() QVERIFY(repeater != nullptr); QQuickItem *container = findItem<QQuickItem>(window->rootObject(), "container"); QVERIFY(container != nullptr); - QCOMPARE(container->childItems().count(), repeater->count()+1); + QCOMPARE(container->childItems().size(), repeater->count()+1); // Check that model changes are propagated QQuickText *text = findItem<QQuickText>(window->rootObject(), "myName", 1); @@ -437,7 +437,7 @@ void tst_QQuickRepeater::itemModel() QQuickItem *container = findItem<QQuickItem>(window->rootObject(), "container"); QVERIFY(container != nullptr); - QCOMPARE(container->childItems().count(), 1); + QCOMPARE(container->childItems().size(), 1); testObject->setUseModel(true); QMetaObject::invokeMethod(window->rootObject(), "checkProperties"); @@ -450,20 +450,20 @@ void tst_QQuickRepeater::itemModel() window->dumpObjectTree(); } - QCOMPARE(container->childItems().count(), 4); + QCOMPARE(container->childItems().size(), 4); QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item1")); QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item2")); QCOMPARE(qobject_cast<QObject*>(container->childItems().at(2))->objectName(), QLatin1String("item3")); QCOMPARE(container->childItems().at(3), repeater); QMetaObject::invokeMethod(window->rootObject(), "switchModel"); - QCOMPARE(container->childItems().count(), 3); + QCOMPARE(container->childItems().size(), 3); QCOMPARE(qobject_cast<QObject*>(container->childItems().at(0))->objectName(), QLatin1String("item4")); QCOMPARE(qobject_cast<QObject*>(container->childItems().at(1))->objectName(), QLatin1String("item5")); QCOMPARE(container->childItems().at(2), repeater); testObject->setUseModel(false); - QCOMPARE(container->childItems().count(), 1); + QCOMPARE(container->childItems().size(), 1); delete testObject; delete window; @@ -486,7 +486,7 @@ void tst_QQuickRepeater::resetModel() QQuickItem *container = findItem<QQuickItem>(window->rootObject(), "container"); QVERIFY(container != nullptr); - QCOMPARE(repeater->count(), dataA.count()); + QCOMPARE(repeater->count(), dataA.size()); for (int i=0; i<repeater->count(); i++) QCOMPARE(repeater->itemAt(i), container->childItems().at(i+1)); // +1 to skip first Text object @@ -501,13 +501,13 @@ void tst_QQuickRepeater::resetModel() // reset context property ctxt->setContextProperty("testData", dataB); - QCOMPARE(repeater->count(), dataB.count()); + QCOMPARE(repeater->count(), dataB.size()); - QCOMPARE(modelChangedSpy.count(), 1); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(removedSpy.count(), dataA.count()); - QCOMPARE(addedSpy.count(), dataB.count()); - for (int i=0; i<dataB.count(); i++) { + QCOMPARE(modelChangedSpy.size(), 1); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(removedSpy.size(), dataA.size()); + QCOMPARE(addedSpy.size(), dataB.size()); + for (int i=0; i<dataB.size(); i++) { QCOMPARE(addedSpy.at(i).at(0).toInt(), i); QCOMPARE(addedSpy.at(i).at(1).value<QQuickItem*>(), repeater->itemAt(i)); } @@ -518,13 +518,13 @@ void tst_QQuickRepeater::resetModel() // reset via setModel() repeater->setModel(dataA); - QCOMPARE(repeater->count(), dataA.count()); + QCOMPARE(repeater->count(), dataA.size()); - QCOMPARE(modelChangedSpy.count(), 1); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(removedSpy.count(), dataB.count()); - QCOMPARE(addedSpy.count(), dataA.count()); - for (int i=0; i<dataA.count(); i++) { + QCOMPARE(modelChangedSpy.size(), 1); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(removedSpy.size(), dataB.size()); + QCOMPARE(addedSpy.size(), dataA.size()); + for (int i=0; i<dataA.size(); i++) { QCOMPARE(addedSpy.at(i).at(0).toInt(), i); QCOMPARE(addedSpy.at(i).at(1).value<QQuickItem*>(), repeater->itemAt(i)); } @@ -551,12 +551,12 @@ void tst_QQuickRepeater::modelChanged() repeater->setModel(4); QCOMPARE(repeater->count(), 4); QCOMPARE(repeater->property("itemsCount").toInt(), 4); - QCOMPARE(repeater->property("itemsFound").toList().count(), 4); + QCOMPARE(repeater->property("itemsFound").toList().size(), 4); repeater->setModel(10); QCOMPARE(repeater->count(), 10); QCOMPARE(repeater->property("itemsCount").toInt(), 10); - QCOMPARE(repeater->property("itemsFound").toList().count(), 10); + QCOMPARE(repeater->property("itemsFound").toList().size(), 10); delete rootObject; } @@ -593,10 +593,10 @@ void tst_QQuickRepeater::modelReset() model.resetItems(items); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(removedSpy.count(), 0); - QCOMPARE(addedSpy.count(), items.count()); - for (int i = 0; i< items.count(); i++) { + QCOMPARE(countSpy.size(), 1); + QCOMPARE(removedSpy.size(), 0); + QCOMPARE(addedSpy.size(), items.size()); + for (int i = 0; i< items.size(); i++) { QCOMPARE(addedSpy.at(i).at(0).toInt(), i); QCOMPARE(addedSpy.at(i).at(1).value<QQuickItem*>(), repeater->itemAt(i)); } @@ -605,10 +605,10 @@ void tst_QQuickRepeater::modelReset() addedSpy.clear(); model.reset(); - QCOMPARE(countSpy.count(), 0); - QCOMPARE(removedSpy.count(), 3); - QCOMPARE(addedSpy.count(), 3); - for (int i = 0; i< items.count(); i++) { + QCOMPARE(countSpy.size(), 0); + QCOMPARE(removedSpy.size(), 3); + QCOMPARE(addedSpy.size(), 3); + for (int i = 0; i< items.size(); i++) { QCOMPARE(addedSpy.at(i).at(0).toInt(), i); QCOMPARE(addedSpy.at(i).at(1).value<QQuickItem*>(), repeater->itemAt(i)); } @@ -620,10 +620,10 @@ void tst_QQuickRepeater::modelReset() items.append(qMakePair(QString::fromLatin1("five"), QString::fromLatin1("5"))); model.resetItems(items); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(removedSpy.count(), 3); - QCOMPARE(addedSpy.count(), 5); - for (int i = 0; i< items.count(); i++) { + QCOMPARE(countSpy.size(), 1); + QCOMPARE(removedSpy.size(), 3); + QCOMPARE(addedSpy.size(), 5); + for (int i = 0; i< items.size(); i++) { QCOMPARE(addedSpy.at(i).at(0).toInt(), i); QCOMPARE(addedSpy.at(i).at(1).value<QQuickItem*>(), repeater->itemAt(i)); } @@ -634,9 +634,9 @@ void tst_QQuickRepeater::modelReset() items.clear(); model.resetItems(items); - QCOMPARE(countSpy.count(), 1); - QCOMPARE(removedSpy.count(), 5); - QCOMPARE(addedSpy.count(), 0); + QCOMPARE(countSpy.size(), 1); + QCOMPARE(removedSpy.size(), 5); + QCOMPARE(addedSpy.size(), 0); } // QTBUG-46828 @@ -672,9 +672,9 @@ void tst_QQuickRepeater::properties() QSignalSpy modelSpy(repeater, SIGNAL(modelChanged())); repeater->setModel(3); - QCOMPARE(modelSpy.count(),1); + QCOMPARE(modelSpy.size(),1); repeater->setModel(3); - QCOMPARE(modelSpy.count(),1); + QCOMPARE(modelSpy.size(),1); QSignalSpy delegateSpy(repeater, SIGNAL(delegateChanged())); @@ -682,9 +682,9 @@ void tst_QQuickRepeater::properties() rectComponent.setData("import QtQuick 2.0; Rectangle {}", QUrl::fromLocalFile("")); repeater->setDelegate(&rectComponent); - QCOMPARE(delegateSpy.count(),1); + QCOMPARE(delegateSpy.size(),1); repeater->setDelegate(&rectComponent); - QCOMPARE(delegateSpy.count(),1); + QCOMPARE(delegateSpy.size(),1); delete rootObject; } @@ -805,7 +805,7 @@ void tst_QQuickRepeater::invalidContextCrash() engine.rootContext()->setContextProperty("badModel", model); QScopedPointer<QObject> root(component.create()); - QCOMPARE(root->children().count(), 1); + QCOMPARE(root->children().size(), 1); QObject *repeater = root->children().first(); // Make sure the model comes first in the child list, so it will be @@ -815,7 +815,7 @@ void tst_QQuickRepeater::invalidContextCrash() repeater->setParent(nullptr); repeater->setParent(root.data()); - QCOMPARE(root->children().count(), 2); + QCOMPARE(root->children().size(), 2); QCOMPARE(root->children().at(0), model); QCOMPARE(root->children().at(1), repeater); @@ -844,11 +844,11 @@ void tst_QQuickRepeater::jsArrayChange() } repeater->setModel(QVariant::fromValue(array1)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // no change repeater->setModel(QVariant::fromValue(array2)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QQuickRepeater::clearRemovalOrder() @@ -876,7 +876,7 @@ void tst_QQuickRepeater::clearRemovalOrder() // we should have 0 items, and 3 removal signals. QCOMPARE(repeater->count(), 0); - QCOMPARE(removedSpy.count(), 3); + QCOMPARE(removedSpy.size(), 3); // column 1 is for the items, we won't bother verifying these. just look at // the indices and make sure they're sane. diff --git a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp index 64547108b8..ccdf69facf 100644 --- a/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp +++ b/tests/auto/quick/qquickscreen/tst_qquickscreen.cpp @@ -50,7 +50,7 @@ void tst_qquickscreen::basicProperties() QCOMPARE(screen->geometry().x(), root->property("vx").toInt()); QCOMPARE(screen->geometry().y(), root->property("vy").toInt()); - QVERIFY(root->property("screenCount").toInt() == QGuiApplication::screens().count()); + QVERIFY(root->property("screenCount").toInt() == QGuiApplication::screens().size()); } void tst_qquickscreen::screenOnStartup() @@ -89,7 +89,7 @@ void tst_qquickscreen::fullScreenList() QVERIFY(screensArray.isArray()); int length = screensArray.property("length").toInt(); const QList<QScreen *> screenList = QGuiApplication::screens(); - QVERIFY(length == screenList.count()); + QVERIFY(length == screenList.size()); for (int i = 0; i < length; ++i) { QQuickScreenInfo *info = qobject_cast<QQuickScreenInfo *>(screensArray.property(i).toQObject()); diff --git a/tests/auto/quick/qquickshape/tst_qquickshape.cpp b/tests/auto/quick/qquickshape/tst_qquickshape.cpp index 4da77cd35b..a9e15939d3 100644 --- a/tests/auto/quick/qquickshape/tst_qquickshape.cpp +++ b/tests/auto/quick/qquickshape/tst_qquickshape.cpp @@ -204,7 +204,7 @@ void tst_QQuickShape::changeSignals() QSignalSpy asyncPropSpy(obj, SIGNAL(asynchronousChanged())); obj->setAsynchronous(true); obj->setAsynchronous(false); - QCOMPARE(asyncPropSpy.count(), 2); + QCOMPARE(asyncPropSpy.size(), 2); QQmlListReference list(obj, "data"); QQuickShapePath *vp = qobject_cast<QQuickShapePath *>(list.at(0)); @@ -224,29 +224,29 @@ void tst_QQuickShape::changeSignals() vp->setCapStyle(QQuickShapePath::RoundCap); vp->setDashOffset(10); vp->setDashPattern(QVector<qreal>() << 1 << 2 << 3 << 4); - QCOMPARE(strokeColorPropSpy.count(), 1); - QCOMPARE(vpChangeSpy.count(), 10); + QCOMPARE(strokeColorPropSpy.size(), 1); + QCOMPARE(vpChangeSpy.size(), 10); // Verify that property changes from Path and its elements bubble up and result in shapePathChanged(). QQuickPath *path = vp; path->setStartX(30); - QCOMPARE(vpChangeSpy.count(), 11); + QCOMPARE(vpChangeSpy.size(), 11); QQmlListReference pathList(path, "pathElements"); qobject_cast<QQuickPathLine *>(pathList.at(1))->setY(200); - QCOMPARE(vpChangeSpy.count(), 12); + QCOMPARE(vpChangeSpy.size(), 12); // Verify that property changes from the gradient bubble up and result in shapePathChanged(). vp->setFillGradient(g); - QCOMPARE(vpChangeSpy.count(), 13); + QCOMPARE(vpChangeSpy.size(), 13); QQuickShapeLinearGradient *lgrad = qobject_cast<QQuickShapeLinearGradient *>(g); lgrad->setX2(200); - QCOMPARE(vpChangeSpy.count(), 14); + QCOMPARE(vpChangeSpy.size(), 14); QQmlListReference stopList(lgrad, "stops"); QCOMPARE(stopList.count(), 5); qobject_cast<QQuickGradientStop *>(stopList.at(1))->setPosition(0.3); - QCOMPARE(vpChangeSpy.count(), 15); + QCOMPARE(vpChangeSpy.size(), 15); qobject_cast<QQuickGradientStop *>(stopList.at(1))->setColor(Qt::black); - QCOMPARE(vpChangeSpy.count(), 16); + QCOMPARE(vpChangeSpy.size(), 16); } void tst_QQuickShape::render() diff --git a/tests/auto/quick/qquickstates/data/jsValueWhen2.qml b/tests/auto/quick/qquickstates/data/jsValueWhen2.qml new file mode 100644 index 0000000000..e1f173138e --- /dev/null +++ b/tests/auto/quick/qquickstates/data/jsValueWhen2.qml @@ -0,0 +1,20 @@ +import QtQuick 2.15 + +Item { + id: root + property var prop: null + property bool works: false + states: [ + State { + name: "mystate" + when: root.prop + PropertyChanges { + target: root + works: "works" + } + } + ] + Component.onCompleted: root.prop = Qt.createQmlObject( + "import QtQml 2.15\nQtObject {}", + root, "dynamicSnippet") +} diff --git a/tests/auto/quick/qquickstates/data/removeBindingWithTransition.qml b/tests/auto/quick/qquickstates/data/removeBindingWithTransition.qml new file mode 100644 index 0000000000..ed40e18374 --- /dev/null +++ b/tests/auto/quick/qquickstates/data/removeBindingWithTransition.qml @@ -0,0 +1,23 @@ +import QtQuick + +Item { + id: root + property bool toggle: true + property int state1Width: 500 + + states: [ + State { + when: root.toggle + PropertyChanges { root.width: root.state1Width } + }, + State { + when: !root.toggle + PropertyChanges { root.width: 300 } + } + ] + + transitions: Transition { + id: transition + SmoothedAnimation { target: root; property: "width"; velocity: 200 } + } +} diff --git a/tests/auto/quick/qquickstates/tst_qquickstates.cpp b/tests/auto/quick/qquickstates/tst_qquickstates.cpp index a57f186d80..44187d2b65 100644 --- a/tests/auto/quick/qquickstates/tst_qquickstates.cpp +++ b/tests/auto/quick/qquickstates/tst_qquickstates.cpp @@ -175,6 +175,7 @@ private slots: void revertListMemoryLeak(); void duplicateStateName(); void trivialWhen(); + void jsValueWhen_data(); void jsValueWhen(); void noStateOsciallation(); void parentChangeCorrectReversal(); @@ -183,6 +184,7 @@ private slots: void parentChangeInvolvingBindings(); void deferredProperties(); void rewindAnchorChange(); + void bindingProperlyRemovedWithTransition(); }; void tst_qquickstates::initTestCase() @@ -1327,7 +1329,7 @@ void tst_qquickstates::illegalObjectCreation() QQmlComponent component(&engine, testFileUrl("illegalObj.qml")); QList<QQmlError> errors = component.errors(); - QCOMPARE(errors.count(), 1); + QCOMPARE(errors.size(), 1); const QQmlError &error = errors.at(0); QCOMPARE(error.line(), 9); QCOMPARE(error.column(), 23); @@ -1482,7 +1484,7 @@ void tst_qquickstates::editProperties() rectPrivate->setState(""); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); QVERIFY(propertyChangesBlue->containsValue("width")); QVERIFY(!propertyChangesBlue->containsProperty("x")); QCOMPARE(propertyChangesBlue->value("width").toInt(), 50); @@ -1490,20 +1492,20 @@ void tst_qquickstates::editProperties() propertyChangesBlue->changeValue("width", 60); QCOMPARE(propertyChangesBlue->value("width").toInt(), 60); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); propertyChangesBlue->changeExpression("width", "myRectangle.width / 2"); QVERIFY(!propertyChangesBlue->containsValue("width")); QVERIFY(propertyChangesBlue->containsExpression("width")); QCOMPARE(propertyChangesBlue->value("width").toInt(), 0); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); propertyChangesBlue->changeValue("width", 50); QVERIFY(propertyChangesBlue->containsValue("width")); QVERIFY(!propertyChangesBlue->containsExpression("width")); QCOMPARE(propertyChangesBlue->value("width").toInt(), 50); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); QVERIFY(QQmlAnyBinding::ofProperty(QQmlProperty(childRect, "width"))); rectPrivate->setState("blue"); @@ -1512,7 +1514,7 @@ void tst_qquickstates::editProperties() propertyChangesBlue->changeValue("width", 60); QCOMPARE(propertyChangesBlue->value("width").toInt(), 60); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); QCOMPARE(childRect->width(), qreal(60)); QVERIFY(!QQmlAnyBinding::ofProperty(QQmlProperty(childRect, "width"))); @@ -1520,7 +1522,7 @@ void tst_qquickstates::editProperties() QVERIFY(!propertyChangesBlue->containsValue("width")); QVERIFY(propertyChangesBlue->containsExpression("width")); QCOMPARE(propertyChangesBlue->value("width").toInt(), 0); - QCOMPARE(propertyChangesBlue->actions().length(), 2); + QCOMPARE(propertyChangesBlue->actions().size(), 2); QVERIFY(QQmlAnyBinding::ofProperty(QQmlProperty(childRect, "width"))); QCOMPARE(childRect->width(), qreal(200)); @@ -1531,13 +1533,13 @@ void tst_qquickstates::editProperties() QCOMPARE(childRect->width(), qreal(402)); QVERIFY(QQmlAnyBinding::ofProperty(QQmlProperty(childRect, "width"))); - QCOMPARE(propertyChangesGreen->actions().length(), 2); + QCOMPARE(propertyChangesGreen->actions().size(), 2); rectPrivate->setState("green"); QCOMPARE(childRect->width(), qreal(200)); QCOMPARE(childRect->height(), qreal(100)); QVERIFY(QQmlAnyBinding::ofProperty(QQmlProperty(childRect, "width"))); QVERIFY(greenState->bindingInRevertList(childRect, "width")); - QCOMPARE(propertyChangesGreen->actions().length(), 2); + QCOMPARE(propertyChangesGreen->actions().size(), 2); propertyChangesGreen->removeProperty("height"); @@ -1694,11 +1696,20 @@ void tst_qquickstates::trivialWhen() QVERIFY(root); } + +void tst_qquickstates::jsValueWhen_data() +{ + QTest::addColumn<QByteArray>("fileName"); + QTest::addRow("jsObject") << QByteArray("jsValueWhen.qml"); + QTest::addRow("qmlObject") << QByteArray("jsValueWhen2.qml"); +} + void tst_qquickstates::jsValueWhen() { + QFETCH(QByteArray, fileName); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("jsValueWhen.qml")); + QQmlComponent c(&engine, testFileUrl(fileName.constData())); QScopedPointer<QObject> root(c.create()); QVERIFY(root); QVERIFY(root->property("works").toBool()); @@ -1883,10 +1894,10 @@ void tst_qquickstates::parentChangeInvolvingBindings() QCOMPARE(root->property("childRotation").toInt(), 100); // First change to 40 via reverse(), then to 20 via binding. - QCOMPARE(xSpy.count(), 2); + QCOMPARE(xSpy.size(), 2); // First change to 400 via reverse(), then to 200 via binding. - QCOMPARE(widthSpy.count(), 2); + QCOMPARE(widthSpy.size(), 2); QCOMPARE(root->property("childX").toInt(), 20); QCOMPARE(root->property("childWidth").toInt(), 200); @@ -1964,6 +1975,26 @@ void tst_qquickstates::rewindAnchorChange() QTRY_COMPARE(innerRect->height(), 200); } +void tst_qquickstates::bindingProperlyRemovedWithTransition() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("removeBindingWithTransition.qml")); + QVERIFY2(c.isReady(), qPrintable(c.errorString())); + QScopedPointer<QObject> root(c.create()); + QVERIFY(root); + QQuickItem *item = qobject_cast<QQuickItem *>(root.get()); + QVERIFY(item); + + item->setProperty("toggle", false); + QTRY_COMPARE(item->width(), 300); + + item->setProperty("state1Width", 100); + QCOMPARE(item->width(), 300); + + item->setProperty("toggle", true); + QTRY_COMPARE(item->width(), 100); +} + QTEST_MAIN(tst_qquickstates) #include "tst_qquickstates.moc" diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp index 233c467201..aebd9990f7 100644 --- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp +++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp @@ -130,6 +130,10 @@ void tst_qquickstyledtext::textOutput_data() QTest::newRow("tag mix") << "<f6>ds<b></img><pro>gfh</b><w><w>ghj</stron><ql><sl><pl>dfg</j6><img><bol><r><prp>dfg<bkj></b><up><string>ewrq</al><bl>jklhj<zl>" << "dsgfhghjdfgdfgewrqjklhj" << (FormatList() << Format(Format::Bold, 2, 3)) << false; QTest::newRow("named html entities") << "> < & " " << QLatin1String("> < & \" ") + QChar(QChar::Nbsp) << FormatList() << false; QTest::newRow("invalid html entities") << "a &hello & a &goodbye;" << "a &hello & a " << FormatList() << false; + QTest::newRow("upper case tags 1") << "<B><I><S><U>text</U></S></I></B>" << "text" << (FormatList() << Format(Format::Bold|Format::Italic|Format::StrikeOut|Format::Underline, 0, 4)) << false; + QTest::newRow("upper case tags 2") << "<STRONG><DEL>text</DEL></STRONG>" << "text" << (FormatList() << Format(Format::Bold|Format::StrikeOut, 0, 4)) << false; + QTest::newRow("upper case font") << "<FONT COLOR=\"red\" SIZE=\"1\">text</FONT>" << "text" << (FormatList() << Format(0, 0, 4)) << true; + QTest::newRow("upper case entities") << "<b>"this" & that</b>" << "<b>\"this\" & that</b>" << FormatList() << false; } void tst_qquickstyledtext::textOutput() @@ -148,8 +152,8 @@ void tst_qquickstyledtext::textOutput() const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); - QCOMPARE(layoutFormats.count(), formats.count()); - for (int i = 0; i < formats.count(); ++i) { + QCOMPARE(layoutFormats.size(), formats.size()); + for (int i = 0; i < formats.size(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); if (formats.at(i).type & Format::Bold) @@ -178,8 +182,8 @@ void tst_qquickstyledtext::anchors() const QVector<QTextLayout::FormatRange> layoutFormats = layout.formats(); - QCOMPARE(layoutFormats.count(), formats.count()); - for (int i = 0; i < formats.count(); ++i) { + QCOMPARE(layoutFormats.size(), formats.size()); + for (int i = 0; i < formats.size(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); QVERIFY(layoutFormats.at(i).format.isAnchor() == bool(formats.at(i).type & Format::Anchor)); diff --git a/tests/auto/quick/qquicktableview/data/columnwidthboundtoviewwidth.qml b/tests/auto/quick/qquicktableview/data/columnwidthboundtoviewwidth.qml new file mode 100644 index 0000000000..bbbdf74d4e --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/columnwidthboundtoviewwidth.qml @@ -0,0 +1,40 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +import QtQuick 2.12 +import QtQuick.Window 2.3 + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + property Component delegate: tableViewDelegate + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + } + + Component { + id: tableViewDelegate + Rectangle { + implicitWidth: tableView.width + implicitHeight: 50 + objectName: "tableViewDelegate" + color: "lightgray" + border.width: 1 + Text { + anchors.centerIn: parent + text: modelData + } + } + } + +} diff --git a/tests/auto/quick/qquicktableview/data/syncviewsimple.qml b/tests/auto/quick/qquicktableview/data/syncviewsimple.qml index f0534e8440..880554b129 100644 --- a/tests/auto/quick/qquicktableview/data/syncviewsimple.qml +++ b/tests/auto/quick/qquicktableview/data/syncviewsimple.qml @@ -13,6 +13,9 @@ Item { property alias tableViewV: tableViewV property alias tableViewHV: tableViewHV + property real delegateWidth: 30 + property real delegateHeight: 60 + Column { spacing: 10 TableView { @@ -57,7 +60,7 @@ Item { height: 100 anchors.margins: 1 clip: true - delegate: tableViewDelegate + delegate: tableViewDelegateMainView columnSpacing: 1 rowSpacing: 1 @@ -70,10 +73,27 @@ Item { id: tableViewDelegate Rectangle { objectName: "tableViewDelegate" + color: "lightblue" + border.width: 1 + implicitWidth: 100 + implicitHeight: 100 + + Text { + anchors.centerIn: parent + font.pixelSize: 10 + text: parent.TableView.view.objectName + "\n" + column + ", " + row + } + } + } + + Component { + id: tableViewDelegateMainView + Rectangle { + objectName: "tableViewDelegate" color: "lightgray" border.width: 1 - implicitWidth: 30 - implicitHeight: 60 + implicitWidth: delegateWidth + implicitHeight: delegateHeight Text { anchors.centerIn: parent diff --git a/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml new file mode 100644 index 0000000000..526313dc24 --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/tableviewinteractive.qml @@ -0,0 +1,32 @@ +import QtQuick +import QtQuick.Controls + +Item { + id: rootItem + + width: 200 + height: 200 + visible: true + + property int eventCount: 0 + property alias tableView: tableView + + MouseArea { + anchors.fill: parent + onPressed: function(mouse) { + ++eventCount + } + } + + TableView { + id: tableView + objectName: "tableView" + anchors.fill: parent + model: 1 + delegate: Rectangle { + color: "red" + implicitWidth: 200 + implicitHeight: 200 + } + } +} diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index eeaf95068f..176b9cb603 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -90,6 +90,7 @@ private slots: void checkColumnWidthProviderInvalidReturnValues(); void checkColumnWidthProviderNegativeReturnValue(); void checkColumnWidthProviderNotCallable(); + void checkColumnWidthBoundToViewWidth(); void checkRowHeightWithoutProvider(); void checkRowHeightProvider(); void checkRowHeightProviderInvalidReturnValues(); @@ -155,10 +156,12 @@ private slots: void checkSyncView_childViews_data(); void checkSyncView_childViews(); void checkSyncView_differentSizedModels(); + void checkSyncView_differentGeometry(); void checkSyncView_connect_late_data(); void checkSyncView_connect_late(); void checkSyncView_pageFlicking(); void checkSyncView_emptyModel(); + void checkSyncView_topLeftChanged(); void delegateWithRequiredProperties(); void checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable(); void replaceModel(); @@ -215,6 +218,7 @@ private slots: void testDeprecatedApi(); void alternatingRows(); void boundDelegateComponent(); + void tableViewInteractive(); }; tst_QQuickTableView::tst_QQuickTableView() @@ -284,8 +288,9 @@ void tst_QQuickTableView::emptyModel() LOAD_TABLEVIEW("plaintableview.qml"); tableView->setModel(model); - WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedItems.count(), 0); + if (QQuickTest::qIsPolishScheduled(tableView)) + WAIT_UNTIL_POLISHED; + QCOMPARE(tableViewPrivate->loadedItems.size(), 0); } void tst_QQuickTableView::checkPreload_data() @@ -504,6 +509,27 @@ void tst_QQuickTableView::checkColumnWidthProviderNotCallable() QCOMPARE(fxItem->item->width(), kDefaultColumnWidth); } +void tst_QQuickTableView::checkColumnWidthBoundToViewWidth() +{ + // Check that you can bind the width of a delegate to the + // width of TableView, and that it updates when TableView is resized. + LOAD_TABLEVIEW("columnwidthboundtoviewwidth.qml"); + + auto model = TestModelAsVariant(10, 1); + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), tableView->width()); + + tableView->setWidth(200); + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), 200); +} + void tst_QQuickTableView::checkRowHeightWithoutProvider() { // Checks that a function isn't assigned to the rowHeightProvider property @@ -2680,6 +2706,18 @@ void tst_QQuickTableView::checkSyncView_rootView() QCOMPARE(tableViewVPrivate->loadedTableOuterRect.left(), 0); QCOMPARE(tableViewHVPrivate->loadedTableOuterRect, tableViewPrivate->loadedTableOuterRect); + + // Check that the column widths are in sync + for (int column = tableView->leftColumn(); column < tableView->rightColumn(); ++column) { + QCOMPARE(tableViewH->columnWidth(column), tableView->columnWidth(column)); + QCOMPARE(tableViewHV->columnWidth(column), tableView->columnWidth(column)); + } + + // Check that the row heights are in sync + for (int row = tableView->topRow(); row < tableView->bottomRow(); ++row) { + QCOMPARE(tableViewV->rowHeight(row), tableView->rowHeight(row)); + QCOMPARE(tableViewHV->rowHeight(row), tableView->rowHeight(row)); + } } void tst_QQuickTableView::checkSyncView_childViews_data() @@ -2785,6 +2823,18 @@ void tst_QQuickTableView::checkSyncView_childViews() QCOMPARE(tableViewHVPrivate->bottomRow(), tableViewPrivate->bottomRow()); QCOMPARE(tableViewHVPrivate->loadedTableOuterRect, tableViewPrivate->loadedTableOuterRect); } + + // Check that the column widths are in sync + for (int column = tableView->leftColumn(); column < tableView->rightColumn(); ++column) { + QCOMPARE(tableViewH->columnWidth(column), tableView->columnWidth(column)); + QCOMPARE(tableViewHV->columnWidth(column), tableView->columnWidth(column)); + } + + // Check that the row heights are in sync + for (int row = tableView->topRow(); row < tableView->bottomRow(); ++row) { + QCOMPARE(tableViewV->rowHeight(row), tableView->rowHeight(row)); + QCOMPARE(tableViewHV->rowHeight(row), tableView->rowHeight(row)); + } } void tst_QQuickTableView::checkSyncView_differentSizedModels() @@ -2850,6 +2900,61 @@ void tst_QQuickTableView::checkSyncView_differentSizedModels() QVERIFY(tableViewHVPrivate->loadedColumns.isEmpty()); } +void tst_QQuickTableView::checkSyncView_differentGeometry() +{ + // Check that you can have two tables in a syncView relation, where + // the sync "child" is larger than the sync view. This means that the + // child will display more rows and columns than the parent. + // In that case, the sync view will anyway need to load the same rows + // and columns as the child, otherwise the column and row sizes + // cannot be determined for the child. + LOAD_TABLEVIEW("syncviewsimple.qml"); + GET_QML_TABLEVIEW(tableViewH); + GET_QML_TABLEVIEW(tableViewV); + GET_QML_TABLEVIEW(tableViewHV); + + tableView->setWidth(40); + tableView->setHeight(40); + + auto tableViewModel = TestModelAsVariant(100, 100); + + tableView->setModel(tableViewModel); + tableViewH->setModel(tableViewModel); + tableViewV->setModel(tableViewModel); + tableViewHV->setModel(tableViewModel); + + WAIT_UNTIL_POLISHED; + + // Check that the column widths are in sync + for (int column = tableViewH->leftColumn(); column < tableViewH->rightColumn(); ++column) { + QCOMPARE(tableViewH->columnWidth(column), tableView->columnWidth(column)); + QCOMPARE(tableViewHV->columnWidth(column), tableView->columnWidth(column)); + } + + // Check that the row heights are in sync + for (int row = tableViewV->topRow(); row < tableViewV->bottomRow(); ++row) { + QCOMPARE(tableViewV->rowHeight(row), tableView->rowHeight(row)); + QCOMPARE(tableViewHV->rowHeight(row), tableView->rowHeight(row)); + } + + // Flick a bit, and do the same test again + tableView->setContentX(200); + tableView->setContentY(200); + WAIT_UNTIL_POLISHED; + + // Check that the column widths are in sync + for (int column = tableViewH->leftColumn(); column < tableViewH->rightColumn(); ++column) { + QCOMPARE(tableViewH->columnWidth(column), tableView->columnWidth(column)); + QCOMPARE(tableViewHV->columnWidth(column), tableView->columnWidth(column)); + } + + // Check that the row heights are in sync + for (int row = tableViewV->topRow(); row < tableViewV->bottomRow(); ++row) { + QCOMPARE(tableViewV->rowHeight(row), tableView->rowHeight(row)); + QCOMPARE(tableViewHV->rowHeight(row), tableView->rowHeight(row)); + } +} + void tst_QQuickTableView::checkSyncView_connect_late_data() { QTest::addColumn<qreal>("flickToPos"); @@ -3017,6 +3122,42 @@ void tst_QQuickTableView::checkSyncView_emptyModel() QCOMPARE(tableViewVPrivate->loadedTableOuterRect.left(), 0); } +void tst_QQuickTableView::checkSyncView_topLeftChanged() +{ + LOAD_TABLEVIEW("syncviewsimple.qml"); + GET_QML_TABLEVIEW(tableViewH); + GET_QML_TABLEVIEW(tableViewV); + GET_QML_TABLEVIEW(tableViewHV); + QQuickTableView *views[] = {tableViewH, tableViewV, tableViewHV}; + + auto model = TestModelAsVariant(100, 100); + tableView->setModel(model); + + for (auto view : views) + view->setModel(model); + + tableView->setColumnWidthProvider(QJSValue()); + tableView->setRowHeightProvider(QJSValue()); + view->rootObject()->setProperty("delegateWidth", 300); + view->rootObject()->setProperty("delegateHeight", 300); + tableView->forceLayout(); + + tableViewHV->setContentX(350); + tableViewHV->setContentY(350); + + WAIT_UNTIL_POLISHED; + + QCOMPARE(tableViewH->leftColumn(), tableView->leftColumn()); + QCOMPARE(tableViewV->topRow(), tableView->topRow()); + + view->rootObject()->setProperty("delegateWidth", 50); + view->rootObject()->setProperty("delegateHeight", 50); + tableView->forceLayout(); + + QCOMPARE(tableViewH->leftColumn(), tableView->leftColumn()); + QCOMPARE(tableViewV->topRow(), tableView->topRow()); +} + void tst_QQuickTableView::checkThatFetchMoreIsCalledWhenScrolledToTheEndOfTable() { LOAD_TABLEVIEW("plaintableview.qml"); @@ -4918,7 +5059,7 @@ void tst_QQuickTableView::disablePointerNavigation() // Enable navigation, and try again tableView->setPointerNavigationEnabled(true); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(selectionModel.currentIndex(), tableView->modelIndex(0, 0)); + QCOMPARE(selectionModel.currentIndex(), tableView->index(0, 0)); QVERIFY(item0_0->property("current").toBool()); QCOMPARE(tableView->currentColumn(), cell0_0.x()); QCOMPARE(tableView->currentRow(), cell0_0.y()); @@ -5347,6 +5488,42 @@ void tst_QQuickTableView::boundDelegateComponent() QVERIFY(innerTableView->itemAtCell(0, i)->objectName().isEmpty()); } +void tst_QQuickTableView::tableViewInteractive() +{ + LOAD_TABLEVIEW("tableviewinteractive.qml"); + auto *root = view->rootObject(); + QVERIFY(root); + auto *window = root->window(); + QVERIFY(window); + int eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 0); + // Event though we make 'interactive' as false, the TableView has + // pointerNacigationEnabled set as true by default, which allows it to consume + // mouse events and thus, eventCount still be zero + tableView->setInteractive(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 0); + // Making both 'interactive' and 'pointerNavigationEnabled' as false, doesn't + // allow TableView (and its parent Flickable) to consume mouse event and it + // passes to the below visual item + tableView->setInteractive(false); + tableView->setPointerNavigationEnabled(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 1); + // Making 'interactive' as true and 'pointerNavigationEnabled' as false, + // allows parent of TableView (i.e. Flickable) to consume mouse events + tableView->setInteractive(true); + tableView->setPointerNavigationEnabled(false); + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 100)); + eventCount = root->property("eventCount").toInt(); + QCOMPARE(eventCount, 1); +} + QTEST_MAIN(tst_QQuickTableView) #include "tst_qquicktableview.moc" diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index a660814113..f448928875 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -88,6 +88,7 @@ private slots: void implicitSize_data(); void implicitSize(); void implicitSizeChangeRewrap(); + void implicitSizeMaxLineCount(); void dependentImplicitSizes(); void contentSize(); void implicitSizeBinding_data(); @@ -488,14 +489,14 @@ void tst_qquicktext::wrap() textObject->setWrapMode(QQuickText::Wrap); QCOMPARE(textObject->wrapMode(), QQuickText::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->setWrapMode(QQuickText::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->setWrapMode(QQuickText::NoWrap); QCOMPARE(textObject->wrapMode(), QQuickText::NoWrap); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } } @@ -760,14 +761,14 @@ void tst_qquicktext::textFormat() text->setTextFormat(QQuickText::StyledText); QCOMPARE(text->textFormat(), QQuickText::StyledText); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->setTextFormat(QQuickText::StyledText); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->setTextFormat(QQuickText::AutoText); QCOMPARE(text->textFormat(), QQuickText::AutoText); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } { @@ -1244,25 +1245,25 @@ void tst_qquicktext::color() textObject->setColor(QColor("white")); QCOMPARE(textObject->color(), QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textObject->setLinkColor(QColor("black")); QCOMPARE(textObject->linkColor(), QColor("black")); - QCOMPARE(linkColorSpy.count(), 1); + QCOMPARE(linkColorSpy.size(), 1); textObject->setColor(QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textObject->setLinkColor(QColor("black")); - QCOMPARE(linkColorSpy.count(), 1); + QCOMPARE(linkColorSpy.size(), 1); textObject->setColor(QColor("black")); QCOMPARE(textObject->color(), QColor("black")); - QCOMPARE(colorSpy.count(), 2); + QCOMPARE(colorSpy.size(), 2); textObject->setLinkColor(QColor("blue")); QCOMPARE(textObject->linkColor(), QColor("blue")); - QCOMPARE(linkColorSpy.count(), 2); + QCOMPARE(linkColorSpy.size(), 2); delete textObject; } @@ -1329,12 +1330,12 @@ void tst_qquicktext::color() QCOMPARE(textObject->color(), testColor); textObject->setColor(testColor); QCOMPARE(textObject->color(), testColor); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); testColor = QColor("black"); textObject->setColor(testColor); QCOMPARE(textObject->color(), testColor); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } { QString colorStr = "#001234"; QColor testColor(colorStr); @@ -1350,12 +1351,12 @@ void tst_qquicktext::color() QCOMPARE(textObject->styleColor(), testColor); textObject->setStyleColor(testColor); QCOMPARE(textObject->styleColor(), testColor); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); testColor = QColor("black"); textObject->setStyleColor(testColor); QCOMPARE(textObject->styleColor(), testColor); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } { QString colorStr = "#001234"; QColor testColor(colorStr); @@ -1371,12 +1372,12 @@ void tst_qquicktext::color() QCOMPARE(textObject->linkColor(), testColor); textObject->setLinkColor(testColor); QCOMPARE(textObject->linkColor(), testColor); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); testColor = QColor("black"); textObject->setLinkColor(testColor); QCOMPARE(textObject->linkColor(), testColor); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } } @@ -1440,14 +1441,14 @@ void tst_qquicktext::renderType() text->setRenderType(QQuickText::NativeRendering); QCOMPARE(text->renderType(), QQuickText::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->setRenderType(QQuickText::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->setRenderType(QQuickText::QtRendering); QCOMPARE(text->renderType(), QQuickText::QtRendering); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktext::antialiasing() @@ -1464,14 +1465,14 @@ void tst_qquicktext::antialiasing() text->setAntialiasing(false); QCOMPARE(text->antialiasing(), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->setAntialiasing(false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); text->resetAntialiasing(); QCOMPARE(text->antialiasing(), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); // QTBUG-39047 component.setData("import QtQuick 2.0\n Text { antialiasing: true }", QUrl()); @@ -2075,7 +2076,7 @@ void tst_qquicktext::linkInteraction() QObject::connect(textObject, SIGNAL(linkActivated(QString)), &test, SLOT(linkClicked(QString))); QObject::connect(textObject, SIGNAL(linkHovered(QString)), &test, SLOT(linkHovered(QString))); - QVERIFY(mousePositions.count() > 0); + QVERIFY(mousePositions.size() > 0); QPointF mousePosition = mousePositions.first(); auto globalPos = textObject->mapToGlobal(mousePosition); @@ -2091,7 +2092,7 @@ void tst_qquicktext::linkInteraction() QCOMPARE(textObject->hoveredLink(), hoverEnterLink); QCOMPARE(textObject->linkAt(mousePosition.x(), mousePosition.y()), hoverEnterLink); - for (int i = 1; i < mousePositions.count(); ++i) { + for (int i = 1; i < mousePositions.size(); ++i) { mousePosition = mousePositions.at(i); auto globalPos = textObject->mapToGlobal(mousePosition); @@ -2137,15 +2138,15 @@ void tst_qquicktext::baseUrl() textObject->setBaseUrl(localUrl); QCOMPARE(textObject->baseUrl(), localUrl); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); textObject->setBaseUrl(remoteUrl); QCOMPARE(textObject->baseUrl(), remoteUrl); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->resetBaseUrl(); QCOMPARE(textObject->baseUrl(), localUrl); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktext::embeddedImages_data() @@ -2377,6 +2378,20 @@ void tst_qquicktext::implicitSize() delete textObject; } +void tst_qquicktext::implicitSizeMaxLineCount() +{ + QScopedPointer<QQuickText> textObject(new QQuickText); + + textObject->setText("1st line"); + const auto referenceWidth = textObject->implicitWidth(); + + textObject->setText(textObject->text() + "\n2nd long long long long long line"); + QCOMPARE_GT(textObject->implicitWidth(), referenceWidth); + + textObject->setMaximumLineCount(1); + QCOMPARE_EQ(textObject->implicitWidth(), referenceWidth); +} + void tst_qquicktext::dependentImplicitSizes() { QQmlComponent component(&engine, testFile("implicitSizes.qml")); @@ -2449,23 +2464,23 @@ void tst_qquicktext::contentSize() QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() < textObject->height()); - QCOMPARE(spySize.count(), 1); - QCOMPARE(spyWidth.count(), 1); - QCOMPARE(spyHeight.count(), 0); + QCOMPARE(spySize.size(), 1); + QCOMPARE(spyWidth.size(), 1); + QCOMPARE(spyHeight.size(), 0); textObject->setWrapMode(QQuickText::WordWrap); QVERIFY(textObject->contentWidth() <= textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spySize.count(), 2); - QCOMPARE(spyWidth.count(), 2); - QCOMPARE(spyHeight.count(), 1); + QCOMPARE(spySize.size(), 2); + QCOMPARE(spyWidth.size(), 2); + QCOMPARE(spyHeight.size(), 1); textObject->setElideMode(QQuickText::ElideRight); QVERIFY(textObject->contentWidth() <= textObject->width()); QVERIFY(textObject->contentHeight() < textObject->height()); - QCOMPARE(spySize.count(), 3); - QCOMPARE(spyWidth.count(), 3); - QCOMPARE(spyHeight.count(), 2); + QCOMPARE(spySize.size(), 3); + QCOMPARE(spyWidth.size(), 3); + QCOMPARE(spyHeight.size(), 2); int spyCount = 3; qreal elidedWidth = textObject->contentWidth(); @@ -2474,16 +2489,16 @@ void tst_qquicktext::contentSize() QVERIFY(textObject->contentHeight() < textObject->height()); // this text probably won't have the same elided width, but it's not guaranteed. if (textObject->contentWidth() != elidedWidth) - QCOMPARE(spySize.count(), ++spyCount); + QCOMPARE(spySize.size(), ++spyCount); else - QCOMPARE(spySize.count(), spyCount); + QCOMPARE(spySize.size(), spyCount); textObject->setElideMode(QQuickText::ElideNone); QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spySize.count(), ++spyCount); - QCOMPARE(spyWidth.count(), spyCount); - QCOMPARE(spyHeight.count(), 3); + QCOMPARE(spySize.size(), ++spyCount); + QCOMPARE(spyWidth.size(), spyCount); + QCOMPARE(spyHeight.size(), 3); } void tst_qquicktext::geometryChanged() @@ -3297,7 +3312,7 @@ void tst_qquicktext::imgTagsMultipleImages() QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(textObject); QVERIFY(textPrivate != nullptr); - QCOMPARE(textPrivate->extra->visibleImgTags.count(), 2); + QCOMPARE(textPrivate->extra->visibleImgTags.size(), 2); delete textObject; } @@ -3310,9 +3325,9 @@ void tst_qquicktext::imgTagsElide() QQuickTextPrivate *textPrivate = QQuickTextPrivate::get(myText); QVERIFY(textPrivate != nullptr); - QCOMPARE(textPrivate->extra->visibleImgTags.count(), 0); + QCOMPARE(textPrivate->extra->visibleImgTags.size(), 0); myText->setMaximumLineCount(20); - QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.size(), 1); delete myText; } @@ -3329,16 +3344,16 @@ void tst_qquicktext::imgTagsUpdates() QVERIFY(textPrivate != nullptr); myText->setText("This is a heart<img src=\"images/heart200.png\">."); - QCOMPARE(textPrivate->extra->visibleImgTags.count(), 1); - QCOMPARE(spy.count(), 1); + QCOMPARE(textPrivate->extra->visibleImgTags.size(), 1); + QCOMPARE(spy.size(), 1); myText->setMaximumLineCount(2); myText->setText("This is another heart<img src=\"images/heart200.png\">."); - QTRY_COMPARE(textPrivate->extra->visibleImgTags.count(), 1); + QTRY_COMPARE(textPrivate->extra->visibleImgTags.size(), 1); // if maximumLineCount is set and the img tag doesn't have an explicit size // we relayout twice. - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); delete myText; } @@ -3601,6 +3616,46 @@ void tst_qquicktext::fontSizeMode() myText->setElideMode(QQuickText::ElideNone); QVERIFY(QQuickTest::qWaitForPolish(myText)); + + // Growing height needs to update the baselineOffset when AlignBottom is used + // and text is NOT wrapped + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::Fit); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + + int baselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() * 2); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QVERIFY(myText->baselineOffset() > baselineOffset); + + // Growing height needs to update the baselineOffset when AlignBottom is used + // and the text is wrapped + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::Fit); + myText->setWrapMode(QQuickText::NoWrap); + myText->resetMaximumLineCount(); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + + baselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() * 2); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); + QVERIFY(myText->baselineOffset() > baselineOffset); + + // Check baselineOffset for the HorizontalFit case + myText->setVAlign(QQuickText::AlignBottom); + myText->setFontSizeMode(QQuickText::HorizontalFit); + QVERIFY(QQuickTest::qWaitForPolish(myText)); + QSignalSpy baselineOffsetSpy(myText, SIGNAL(baselineOffsetChanged(qreal))); + QVERIFY(QQuickTest::qWaitForPolish(myText)); + const qreal oldBaselineOffset = myText->baselineOffset(); + myText->setHeight(myText->height() + 42); + QVERIFY(QQuickTest::qWaitForPolish(myText)); + QCOMPARE(baselineOffsetSpy.size(), 1); + QCOMPARE(myText->baselineOffset(), oldBaselineOffset + 42); + myText->setHeight(myText->height() - 42); + QVERIFY(QQuickTest::qWaitForPolish(myText)); + QCOMPARE(baselineOffsetSpy.size(), 2); + QCOMPARE(myText->baselineOffset(), oldBaselineOffset); } void tst_qquicktext::fontSizeModeMultiline_data() diff --git a/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml index 24bd434830..b753d844be 100644 --- a/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml +++ b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml @@ -14,7 +14,7 @@ Item { id: txt x: 100 text: "enter text" - Keys.onShortcutOverride: { + Keys.onShortcutOverride: (event) => { who = "TextEdit" event.accepted = (event.key === Qt.Key_Escape) } @@ -26,7 +26,7 @@ Item { height: width focus: true color: focus ? "red" : "gray" - Keys.onShortcutOverride: { + Keys.onShortcutOverride: (event) => { who = "Rectangle" event.accepted = (event.key === Qt.Key_Escape) } diff --git a/tests/auto/quick/qquicktextedit/data/threeLines.qml b/tests/auto/quick/qquicktextedit/data/threeLines.qml new file mode 100644 index 0000000000..cee03bfa15 --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/threeLines.qml @@ -0,0 +1,7 @@ +import QtQuick +import Qt.test 1.0 + +NodeCheckerTextEdit { + width: 200; height: 100 + text: "Line 1\nLine 2\nLine 3\n" +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index b8861f101d..36543357a2 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -57,6 +57,8 @@ public: tst_qquicktextedit(); private slots: + void initTestCase() override; + void cleanup(); void text(); void width(); @@ -138,6 +140,7 @@ private slots: void implicitSizeBinding(); void largeTextObservesViewport_data(); void largeTextObservesViewport(); + void renderingAroundSelection(); void signal_editingfinished(); @@ -241,7 +244,7 @@ Q_DECLARE_METATYPE(QQuickTextEdit::TextFormat) void tst_qquicktextedit::simulateKeys(QWindow *window, const QList<Key> &keys) { - for (int i = 0; i < keys.count(); ++i) { + for (int i = 0; i < keys.size(); ++i) { const int key = keys.at(i).first; const int modifiers = key & Qt::KeyboardModifierMask; const QString text = !keys.at(i).second.isNull() ? QString(keys.at(i).second) : QString(); @@ -336,6 +339,56 @@ tst_qquicktextedit::tst_qquicktextedit() // } +class NodeCheckerTextEdit : public QQuickTextEdit +{ +public: + NodeCheckerTextEdit(QQuickItem *parent = nullptr) : QQuickTextEdit(parent) {} + + void populateLinePositions(QSGNode *node) + { + linePositions.clear(); + lastLinePosition = 0; + QSGNode *ch = node->firstChild(); + while (ch != node->lastChild()) { + QCOMPARE(ch->type(), QSGNode::TransformNodeType); + QSGTransformNode *tn = static_cast<QSGTransformNode *>(ch); + int y = 0; + if (!tn->matrix().isIdentity()) + y = tn->matrix().column(3).y(); + if (tn->childCount() == 0) { + // A TransformNode with no children is a waste of memory. + // So far, QQuickTextEdit still creates a couple of extras. + qCDebug(lcTests) << "ignoring leaf TransformNode" << tn << "@ y" << y; + } else { + qCDebug(lcTests) << "child" << tn << "@ y" << y << "has children" << tn->childCount(); + if (!linePositions.contains(y)) { + linePositions.append(y); + lastLinePosition = qMax(lastLinePosition, y); + } + } + ch = ch->nextSibling(); + } + std::sort(linePositions.begin(), linePositions.end()); + } + + QSGNode *updatePaintNode(QSGNode *node, UpdatePaintNodeData *data) override + { + QSGNode *ret = QQuickTextEdit::updatePaintNode(node, data); + qCDebug(lcTests) << "updated root node" << ret; + populateLinePositions(ret); + return ret; + } + + QList<int> linePositions; + int lastLinePosition; +}; + +void tst_qquicktextedit::initTestCase() +{ + QQmlDataTest::initTestCase(); + qmlRegisterType<NodeCheckerTextEdit>("Qt.test", 1, 0, "NodeCheckerTextEdit"); +} + void tst_qquicktextedit::cleanup() { // ensure not even skipped tests with custom input context leave it dangling @@ -364,7 +417,7 @@ void tst_qquicktextedit::text() QVERIFY(textEditObject != nullptr); QCOMPARE(textEditObject->text(), standard.at(i)); - QCOMPARE(textEditObject->length(), standard.at(i).length()); + QCOMPARE(textEditObject->length(), standard.at(i).size()); } for (int i = 0; i < richText.size(); i++) @@ -380,7 +433,7 @@ void tst_qquicktextedit::text() QString expected = richText.at(i); expected.replace(QRegularExpression("\\\\(.)"),"\\1"); QCOMPARE(textEditObject->text(), expected); - QCOMPARE(textEditObject->length(), expected.length()); + QCOMPARE(textEditObject->length(), expected.size()); } for (int i = 0; i < standard.size(); i++) @@ -399,7 +452,7 @@ void tst_qquicktextedit::text() actual.remove(QRegularExpression("(<[^>]*>)+")); expected.remove("\n"); QCOMPARE(actual.simplified(), expected); - QCOMPARE(textEditObject->length(), expected.length()); + QCOMPARE(textEditObject->length(), expected.size()); } for (int i = 0; i < richText.size(); i++) @@ -419,7 +472,7 @@ void tst_qquicktextedit::text() QCOMPARE(actual.simplified(),expected.simplified()); expected.replace("<>", " "); - QCOMPARE(textEditObject->length(), expected.simplified().length()); + QCOMPARE(textEditObject->length(), expected.simplified().size()); } for (int i = 0; i < standard.size(); i++) @@ -431,7 +484,7 @@ void tst_qquicktextedit::text() QVERIFY(textEditObject != nullptr); QCOMPARE(textEditObject->text(), standard.at(i)); - QCOMPARE(textEditObject->length(), standard.at(i).length()); + QCOMPARE(textEditObject->length(), standard.at(i).size()); } for (int i = 0; i < richText.size(); i++) @@ -451,7 +504,7 @@ void tst_qquicktextedit::text() QCOMPARE(actual.simplified(),expected.simplified()); expected.replace("<>", " "); - QCOMPARE(textEditObject->length(), expected.simplified().length()); + QCOMPARE(textEditObject->length(), expected.simplified().size()); } } @@ -569,14 +622,14 @@ void tst_qquicktextedit::wrap() edit->setWrapMode(QQuickTextEdit::Wrap); QCOMPARE(edit->wrapMode(), QQuickTextEdit::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setWrapMode(QQuickTextEdit::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setWrapMode(QQuickTextEdit::NoWrap); QCOMPARE(edit->wrapMode(), QQuickTextEdit::NoWrap); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } } @@ -625,18 +678,18 @@ void tst_qquicktextedit::textFormat() edit->setTextFormat(QQuickTextEdit::RichText); QCOMPARE(edit->textFormat(), QQuickTextEdit::RichText); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setTextFormat(QQuickTextEdit::RichText); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setTextFormat(QQuickTextEdit::PlainText); QCOMPARE(edit->textFormat(), QQuickTextEdit::PlainText); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); edit->setTextFormat(QQuickTextEdit::MarkdownText); QCOMPARE(edit->textFormat(), QQuickTextEdit::MarkdownText); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); } } @@ -838,7 +891,7 @@ void tst_qquicktextedit::hAlign_RightToLeft() QSignalSpy cursorRectangleSpy(textEdit, SIGNAL(cursorRectangleChanged())); platformInputContext.setInputDirection(Qt::RightToLeft); - QCOMPARE(cursorRectangleSpy.count(), 1); + QCOMPARE(cursorRectangleSpy.size(), 1); QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); QCOMPARE(textEdit->hAlign(), QQuickTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > window.width()/2); @@ -1149,36 +1202,36 @@ void tst_qquicktextedit::color() textEditObject->setColor(QColor("white")); QCOMPARE(textEditObject->color(), QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textEditObject->setSelectionColor(QColor("black")); QCOMPARE(textEditObject->selectionColor(), QColor("black")); - QCOMPARE(selectionColorSpy.count(), 1); + QCOMPARE(selectionColorSpy.size(), 1); textEditObject->setSelectedTextColor(QColor("blue")); QCOMPARE(textEditObject->selectedTextColor(), QColor("blue")); - QCOMPARE(selectedTextColorSpy.count(), 1); + QCOMPARE(selectedTextColorSpy.size(), 1); textEditObject->setColor(QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textEditObject->setSelectionColor(QColor("black")); - QCOMPARE(selectionColorSpy.count(), 1); + QCOMPARE(selectionColorSpy.size(), 1); textEditObject->setSelectedTextColor(QColor("blue")); - QCOMPARE(selectedTextColorSpy.count(), 1); + QCOMPARE(selectedTextColorSpy.size(), 1); textEditObject->setColor(QColor("black")); QCOMPARE(textEditObject->color(), QColor("black")); - QCOMPARE(colorSpy.count(), 2); + QCOMPARE(colorSpy.size(), 2); textEditObject->setSelectionColor(QColor("blue")); QCOMPARE(textEditObject->selectionColor(), QColor("blue")); - QCOMPARE(selectionColorSpy.count(), 2); + QCOMPARE(selectionColorSpy.size(), 2); textEditObject->setSelectedTextColor(QColor("white")); QCOMPARE(textEditObject->selectedTextColor(), QColor("white")); - QCOMPARE(selectedTextColorSpy.count(), 2); + QCOMPARE(selectedTextColorSpy.size(), 2); } //test normal @@ -1259,7 +1312,7 @@ void tst_qquicktextedit::persistentSelection() edit->setPersistentSelection(false); QCOMPARE(edit->persistentSelection(), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); edit->select(1, 4); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); @@ -1272,7 +1325,7 @@ void tst_qquicktextedit::persistentSelection() edit->setPersistentSelection(true); QCOMPARE(edit->persistentSelection(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->select(1, 4); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); @@ -1288,7 +1341,7 @@ void tst_qquicktextedit::persistentSelection() edit->setPersistentSelection(false); QCOMPARE(edit->persistentSelection(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); edit->select(1, 4); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); @@ -1301,7 +1354,7 @@ void tst_qquicktextedit::persistentSelection() edit->setPersistentSelection(true); QCOMPARE(edit->persistentSelection(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); edit->select(1, 4); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); @@ -1379,7 +1432,7 @@ void tst_qquicktextedit::focusOnPress() textEditObject->setFocusOnPress(true); QCOMPARE(textEditObject->focusOnPress(), true); - QCOMPARE(activeFocusOnPressSpy.count(), 0); + QCOMPARE(activeFocusOnPressSpy.size(), 0); QQuickWindow window; window.resize(100, 50); @@ -1397,20 +1450,20 @@ void tst_qquicktextedit::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textEditObject->hasFocus(), true); QCOMPARE(textEditObject->hasActiveFocus(), true); - QCOMPARE(focusSpy.count(), 1); - QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.size(), 1); + QCOMPARE(activeFocusSpy.size(), 1); QCOMPARE(textEditObject->selectedText(), QString()); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); textEditObject->setFocusOnPress(false); QCOMPARE(textEditObject->focusOnPress(), false); - QCOMPARE(activeFocusOnPressSpy.count(), 1); + QCOMPARE(activeFocusOnPressSpy.size(), 1); textEditObject->setFocus(false); QCOMPARE(textEditObject->hasFocus(), false); QCOMPARE(textEditObject->hasActiveFocus(), false); - QCOMPARE(focusSpy.count(), 2); - QCOMPARE(activeFocusSpy.count(), 2); + QCOMPARE(focusSpy.size(), 2); + QCOMPARE(activeFocusSpy.size(), 2); // Wait for double click timeout to expire before clicking again. QTest::qWait(400); @@ -1418,13 +1471,13 @@ void tst_qquicktextedit::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textEditObject->hasFocus(), false); QCOMPARE(textEditObject->hasActiveFocus(), false); - QCOMPARE(focusSpy.count(), 2); - QCOMPARE(activeFocusSpy.count(), 2); + QCOMPARE(focusSpy.size(), 2); + QCOMPARE(activeFocusSpy.size(), 2); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); textEditObject->setFocusOnPress(true); QCOMPARE(textEditObject->focusOnPress(), true); - QCOMPARE(activeFocusOnPressSpy.count(), 2); + QCOMPARE(activeFocusOnPressSpy.size(), 2); // Test a selection made in the on(Active)FocusChanged handler isn't overwritten. textEditObject->setProperty("selectOnFocus", true); @@ -1434,8 +1487,8 @@ void tst_qquicktextedit::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textEditObject->hasFocus(), true); QCOMPARE(textEditObject->hasActiveFocus(), true); - QCOMPARE(focusSpy.count(), 3); - QCOMPARE(activeFocusSpy.count(), 3); + QCOMPARE(focusSpy.size(), 3); + QCOMPARE(activeFocusSpy.size(), 3); QCOMPARE(textEditObject->selectedText(), textEditObject->text()); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers, centerPoint); } @@ -1472,7 +1525,7 @@ void tst_qquicktextedit::selection() QCOMPARE(textEditObject->selectionEnd(), 0); QVERIFY(textEditObject->selectedText().isNull()); - textEditObject->setCursorPosition(textEditObject->text().length()+1); + textEditObject->setCursorPosition(textEditObject->text().size()+1); QCOMPARE(textEditObject->cursorPosition(), 0); QCOMPARE(textEditObject->selectionStart(), 0); QCOMPARE(textEditObject->selectionEnd(), 0); @@ -1543,37 +1596,37 @@ void tst_qquicktextedit::overwriteMode() QVERIFY(textEdit->hasActiveFocus()); textEdit->setOverwriteMode(true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(true, textEdit->overwriteMode()); textEdit->setOverwriteMode(false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(false, textEdit->overwriteMode()); QVERIFY(!textEdit->overwriteMode()); QString insertString = "Some first text"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textEdit->text(), QString("Some first text")); textEdit->setOverwriteMode(true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); textEdit->setCursorPosition(5); insertString = "shiny"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textEdit->text(), QString("Some shiny text")); - textEdit->setCursorPosition(textEdit->text().length()); + textEdit->setCursorPosition(textEdit->text().size()); QTest::keyClick(&window, Qt::Key_Enter); textEdit->setOverwriteMode(false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); insertString = "Second paragraph"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textEdit->lineCount(), 2); @@ -1582,10 +1635,10 @@ void tst_qquicktextedit::overwriteMode() QCOMPARE(textEdit->cursorPosition(), 15); textEdit->setOverwriteMode(true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); insertString = " blah"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textEdit->lineCount(), 2); @@ -1629,24 +1682,24 @@ void tst_qquicktextedit::isRightToLeft() // first test that the right string is delivered to the QString::isRightToLeft() QCOMPARE(textEdit.isRightToLeft(0,0), text.mid(0,0).isRightToLeft()); QCOMPARE(textEdit.isRightToLeft(0,1), text.mid(0,1).isRightToLeft()); - QCOMPARE(textEdit.isRightToLeft(text.length()-2, text.length()-1), text.mid(text.length()-2, text.length()-1).isRightToLeft()); - QCOMPARE(textEdit.isRightToLeft(text.length()/2, text.length()/2 + 1), text.mid(text.length()/2, text.length()/2 + 1).isRightToLeft()); - QCOMPARE(textEdit.isRightToLeft(0,text.length()/4), text.mid(0,text.length()/4).isRightToLeft()); - QCOMPARE(textEdit.isRightToLeft(text.length()/4,3*text.length()/4), text.mid(text.length()/4,3*text.length()/4).isRightToLeft()); + QCOMPARE(textEdit.isRightToLeft(text.size()-2, text.size()-1), text.mid(text.size()-2, text.size()-1).isRightToLeft()); + QCOMPARE(textEdit.isRightToLeft(text.size()/2, text.size()/2 + 1), text.mid(text.size()/2, text.size()/2 + 1).isRightToLeft()); + QCOMPARE(textEdit.isRightToLeft(0,text.size()/4), text.mid(0,text.size()/4).isRightToLeft()); + QCOMPARE(textEdit.isRightToLeft(text.size()/4,3*text.size()/4), text.mid(text.size()/4,3*text.size()/4).isRightToLeft()); if (text.isEmpty()) QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML TextEdit: isRightToLeft(start, end) called with the end property being smaller than the start."); - QCOMPARE(textEdit.isRightToLeft(3*text.length()/4,text.length()-1), text.mid(3*text.length()/4,text.length()-1).isRightToLeft()); + QCOMPARE(textEdit.isRightToLeft(3*text.size()/4,text.size()-1), text.mid(3*text.size()/4,text.size()-1).isRightToLeft()); // then test that the feature actually works QCOMPARE(textEdit.isRightToLeft(0,0), emptyString); QCOMPARE(textEdit.isRightToLeft(0,1), firstCharacter); - QCOMPARE(textEdit.isRightToLeft(text.length()-2, text.length()-1), lastCharacter); - QCOMPARE(textEdit.isRightToLeft(text.length()/2, text.length()/2 + 1), middleCharacter); - QCOMPARE(textEdit.isRightToLeft(0,text.length()/4), startString); - QCOMPARE(textEdit.isRightToLeft(text.length()/4,3*text.length()/4), midString); + QCOMPARE(textEdit.isRightToLeft(text.size()-2, text.size()-1), lastCharacter); + QCOMPARE(textEdit.isRightToLeft(text.size()/2, text.size()/2 + 1), middleCharacter); + QCOMPARE(textEdit.isRightToLeft(0,text.size()/4), startString); + QCOMPARE(textEdit.isRightToLeft(text.size()/4,3*text.size()/4), midString); if (text.isEmpty()) QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML TextEdit: isRightToLeft(start, end) called with the end property being smaller than the start."); - QCOMPARE(textEdit.isRightToLeft(3*text.length()/4,text.length()-1), endString); + QCOMPARE(textEdit.isRightToLeft(3*text.size()/4,text.size()-1), endString); } void tst_qquicktextedit::keySelection() @@ -1668,31 +1721,31 @@ void tst_qquicktextedit::keySelection() simulateKey(&window, Qt::Key_Right, Qt::ShiftModifier); QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); simulateKey(&window, Qt::Key_Right); QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); simulateKey(&window, Qt::Key_Right); QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); simulateKey(&window, Qt::Key_Left); QVERIFY(input->hasActiveFocus()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); simulateKey(&window, Qt::Key_Left, Qt::ShiftModifier); QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString("a")); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); simulateKey(&window, Qt::Key_Left); QVERIFY(input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); simulateKey(&window, Qt::Key_Left); QVERIFY(!input->hasActiveFocus()); QCOMPARE(input->selectedText(), QString()); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); } void tst_qquicktextedit::moveCursorSelection_data() @@ -2174,7 +2227,7 @@ void tst_qquicktextedit::dragMouseSelection() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(x2,y)); QTest::qWait(300); QString str1; - QTRY_VERIFY((str1 = textEditObject->selectedText()).length() > 3); + QTRY_VERIFY((str1 = textEditObject->selectedText()).size() > 3); // press and drag the current selection. x1 = 40; @@ -2184,7 +2237,7 @@ void tst_qquicktextedit::dragMouseSelection() QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(x2,y)); QTest::qWait(300); QString str2; - QTRY_VERIFY((str2 = textEditObject->selectedText()).length() > 3); + QTRY_VERIFY((str2 = textEditObject->selectedText()).size() > 3); QVERIFY(str1 != str2); // Verify the second press and drag is a new selection and not the first moved. @@ -2230,7 +2283,7 @@ void tst_qquicktextedit::mouseSelectionMode() if (selectWords) { QTRY_COMPARE(textEditObject->selectedText(), text); } else { - QTRY_VERIFY(textEditObject->selectedText().length() > 3); + QTRY_VERIFY(textEditObject->selectedText().size() > 3); QVERIFY(str != text); } } @@ -2249,14 +2302,14 @@ void tst_qquicktextedit::mouseSelectionMode_accessors() edit->setMouseSelectionMode(QQuickTextEdit::SelectWords); QCOMPARE(edit->mouseSelectionMode(), QQuickTextEdit::SelectWords); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setMouseSelectionMode(QQuickTextEdit::SelectWords); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setMouseSelectionMode(QQuickTextEdit::SelectCharacters); QCOMPARE(edit->mouseSelectionMode(), QQuickTextEdit::SelectCharacters); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextedit::selectByMouse() @@ -2273,15 +2326,15 @@ void tst_qquicktextedit::selectByMouse() edit->setSelectByMouse(true); QCOMPARE(edit->selectByMouse(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).at(0).toBool(), true); edit->setSelectByMouse(true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setSelectByMouse(false); QCOMPARE(edit->selectByMouse(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(spy.at(1).at(0).toBool(), false); } @@ -2304,21 +2357,21 @@ void tst_qquicktextedit::selectByKeyboard() edit->setReadOnly(true); QCOMPARE(edit->selectByKeyboard(), false); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).at(0).toBool(), false); edit->setSelectByKeyboard(true); QCOMPARE(edit->selectByKeyboard(), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(spy.at(1).at(0).toBool(), true); edit->setReadOnly(false); QCOMPARE(edit->selectByKeyboard(), true); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); edit->setSelectByKeyboard(false); QCOMPARE(edit->selectByKeyboard(), false); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); QCOMPARE(spy.at(2).at(0).toBool(), false); } @@ -2424,14 +2477,14 @@ void tst_qquicktextedit::renderType() edit->setRenderType(QQuickTextEdit::NativeRendering); QCOMPARE(edit->renderType(), QQuickTextEdit::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setRenderType(QQuickTextEdit::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit->setRenderType(QQuickTextEdit::QtRendering); QCOMPARE(edit->renderType(), QQuickTextEdit::QtRendering); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextedit::inputMethodHints() @@ -2447,9 +2500,9 @@ void tst_qquicktextedit::inputMethodHints() QSignalSpy inputMethodHintSpy(textEditObject, SIGNAL(inputMethodHintsChanged())); textEditObject->setInputMethodHints(Qt::ImhUppercaseOnly); QVERIFY(textEditObject->inputMethodHints() & Qt::ImhUppercaseOnly); - QCOMPARE(inputMethodHintSpy.count(), 1); + QCOMPARE(inputMethodHintSpy.size(), 1); textEditObject->setInputMethodHints(Qt::ImhUppercaseOnly); - QCOMPARE(inputMethodHintSpy.count(), 1); + QCOMPARE(inputMethodHintSpy.size(), 1); QQuickTextEdit plainTextEdit; QCOMPARE(plainTextEdit.inputMethodHints(), Qt::ImhNone); @@ -2587,22 +2640,22 @@ void tst_qquicktextedit::linkHover() const QPoint textPos = window.mapToGlobal(texteditObject->positionToRectangle(2).center().toPoint()); QCursor::setPos(linkPos); - QTRY_COMPARE(hover.count(), 1); + QTRY_COMPARE(hover.size(), 1); QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor); QCOMPARE(hover.last()[0].toString(), link); QCursor::setPos(textPos); - QTRY_COMPARE(hover.count(), 2); + QTRY_COMPARE(hover.size(), 2); QCOMPARE(window.cursor().shape(), Qt::IBeamCursor); QCOMPARE(hover.last()[0].toString(), QString()); QCursor::setPos(linkPos); - QTRY_COMPARE(hover.count(), 3); + QTRY_COMPARE(hover.size(), 3); QCOMPARE(window.cursor().shape(), Qt::PointingHandCursor); QCOMPARE(hover.last()[0].toString(), link); QCursor::setPos(textPos); - QTRY_COMPARE(hover.count(), 4); + QTRY_COMPARE(hover.size(), 4); QCOMPARE(window.cursor().shape(), Qt::IBeamCursor); QCOMPARE(hover.last()[0].toString(), QString()); } @@ -2630,16 +2683,16 @@ void tst_qquicktextedit::linkInteraction() const QPointF textPos = texteditObject->positionToRectangle(2).center(); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, linkPos.toPoint()); - QTRY_COMPARE(spy.count(), 1); - QTRY_COMPARE(hover.count(), 1); + QTRY_COMPARE(spy.size(), 1); + QTRY_COMPARE(hover.size(), 1); QCOMPARE(spy.last()[0].toString(), link); QCOMPARE(hover.last()[0].toString(), link); QCOMPARE(texteditObject->hoveredLink(), link); QCOMPARE(texteditObject->linkAt(linkPos.x(), linkPos.y()), link); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, textPos.toPoint()); - QTRY_COMPARE(spy.count(), 1); - QTRY_COMPARE(hover.count(), 2); + QTRY_COMPARE(spy.size(), 1); + QTRY_COMPARE(hover.size(), 2); QCOMPARE(hover.last()[0].toString(), QString()); QCOMPARE(texteditObject->hoveredLink(), QString()); QCOMPARE(texteditObject->linkAt(textPos.x(), textPos.y()), QString()); @@ -2647,16 +2700,16 @@ void tst_qquicktextedit::linkInteraction() texteditObject->setReadOnly(true); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, linkPos.toPoint()); - QTRY_COMPARE(spy.count(), 2); - QTRY_COMPARE(hover.count(), 3); + QTRY_COMPARE(spy.size(), 2); + QTRY_COMPARE(hover.size(), 3); QCOMPARE(spy.last()[0].toString(), link); QCOMPARE(hover.last()[0].toString(), link); QCOMPARE(texteditObject->hoveredLink(), link); QCOMPARE(texteditObject->linkAt(linkPos.x(), linkPos.y()), link); QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, textPos.toPoint()); - QTRY_COMPARE(spy.count(), 2); - QTRY_COMPARE(hover.count(), 4); + QTRY_COMPARE(spy.size(), 2); + QTRY_COMPARE(hover.size(), 4); QCOMPARE(hover.last()[0].toString(), QString()); QCOMPARE(texteditObject->hoveredLink(), QString()); QCOMPARE(texteditObject->linkAt(textPos.x(), textPos.y()), QString()); @@ -2689,7 +2742,7 @@ void tst_qquicktextedit::cursorDelegate() QVERIFY(delegateObject); QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello")); //Test Delegate gets moved - for (int i=0; i<= textEditObject->text().length(); i++) { + for (int i=0; i<= textEditObject->text().size(); i++) { textEditObject->setCursorPosition(i); QCOMPARE(textEditObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textEditObject->cursorRectangle().y(), delegateObject->y()); @@ -2825,27 +2878,27 @@ void tst_qquicktextedit::cursorVisible() edit.setCursorVisible(true); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); edit.setCursorVisible(false); QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); edit.setFocus(true); QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); edit.setParentItem(view.rootObject()); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); edit.setFocus(false); QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); edit.setFocus(true); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); QWindow alternateView; alternateView.show(); @@ -2853,12 +2906,12 @@ void tst_qquicktextedit::cursorVisible() QVERIFY(QTest::qWaitForWindowActive(&alternateView)); QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); { // Cursor attribute with 0 length hides cursor. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -2866,7 +2919,7 @@ void tst_qquicktextedit::cursorVisible() QCoreApplication::sendEvent(&edit, &ev); } QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 8); + QCOMPARE(spy.size(), 8); { // Cursor attribute with non zero length shows cursor. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -2874,7 +2927,7 @@ void tst_qquicktextedit::cursorVisible() QCoreApplication::sendEvent(&edit, &ev); } QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 9); + QCOMPARE(spy.size(), 9); { // If the cursor is hidden by the input method and the text is changed it should be visible again. @@ -2883,11 +2936,11 @@ void tst_qquicktextedit::cursorVisible() QCoreApplication::sendEvent(&edit, &ev); } QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 10); + QCOMPARE(spy.size(), 10); edit.setText("something"); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 11); + QCOMPARE(spy.size(), 11); { // If the cursor is hidden by the input method and the cursor position is changed it should be visible again. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -2895,11 +2948,11 @@ void tst_qquicktextedit::cursorVisible() QCoreApplication::sendEvent(&edit, &ev); } QCOMPARE(edit.isCursorVisible(), false); - QCOMPARE(spy.count(), 12); + QCOMPARE(spy.size(), 12); edit.setCursorPosition(5); QCOMPARE(edit.isCursorVisible(), true); - QCOMPARE(spy.count(), 13); + QCOMPARE(spy.size(), 13); } void tst_qquicktextedit::delegateLoading_data() @@ -3046,16 +3099,16 @@ void tst_qquicktextedit::copyAndPaste() QVERIFY(textEdit != nullptr); // copy and paste - QCOMPARE(textEdit->text().length(), 12); - textEdit->select(0, textEdit->text().length());; + QCOMPARE(textEdit->text().size(), 12); + textEdit->select(0, textEdit->text().size());; textEdit->copy(); QCOMPARE(textEdit->selectedText(), QString("Hello world!")); - QCOMPARE(textEdit->selectedText().length(), 12); + QCOMPARE(textEdit->selectedText().size(), 12); textEdit->setCursorPosition(0); QVERIFY(textEdit->canPaste()); textEdit->paste(); QCOMPARE(textEdit->text(), QString("Hello world!Hello world!")); - QCOMPARE(textEdit->text().length(), 24); + QCOMPARE(textEdit->text().size(), 24); // canPaste QVERIFY(textEdit->canPaste()); @@ -3063,7 +3116,7 @@ void tst_qquicktextedit::copyAndPaste() QVERIFY(!textEdit->canPaste()); textEdit->paste(); QCOMPARE(textEdit->text(), QString("Hello world!Hello world!")); - QCOMPARE(textEdit->text().length(), 24); + QCOMPARE(textEdit->text().size(), 24); textEdit->setReadOnly(false); QVERIFY(textEdit->canPaste()); @@ -3091,10 +3144,10 @@ void tst_qquicktextedit::copyAndPaste() // select all and cut textEdit->selectAll(); textEdit->cut(); - QCOMPARE(textEdit->text().length(), 0); + QCOMPARE(textEdit->text().size(), 0); textEdit->paste(); QCOMPARE(textEdit->text(), QString("Hello world!Hello world!")); - QCOMPARE(textEdit->text().length(), 24); + QCOMPARE(textEdit->text().size(), 24); // Copy first word. textEdit->setCursorPosition(0); @@ -3180,7 +3233,7 @@ void tst_qquicktextedit::middleClickPaste() QTest::mouseClick(&window, Qt::MiddleButton, Qt::NoModifier, p3); if (QGuiApplication::clipboard()->supportsSelection()) - QCOMPARE(textEditObject->text().mid(1, selectedText.length()), selectedText); + QCOMPARE(textEditObject->text().mid(1, selectedText.size()), selectedText); else QCOMPARE(textEditObject->text(), originalText); } @@ -3210,7 +3263,7 @@ void tst_qquicktextedit::readOnly() edit->setCursorPosition(3); edit->setReadOnly(false); QCOMPARE(edit->isReadOnly(), false); - QCOMPARE(edit->cursorPosition(), edit->text().length()); + QCOMPARE(edit->cursorPosition(), edit->text().size()); } void tst_qquicktextedit::inFlickableMouse_data() @@ -3357,7 +3410,7 @@ void tst_qquicktextedit::textInput() event.setCommitString( "Hello world!", 0, 0); QGuiApplication::sendEvent(edit, &event); QCOMPARE(edit->text(), QString("Hello world!")); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // QTBUG-12339 // test that document and internal text attribute are in sync @@ -3527,7 +3580,7 @@ void tst_qquicktextedit::openInputPanel() anotherEdit.setFocus(true); QCOMPARE(qApp->inputMethod()->isVisible(), true); QCOMPARE(qApp->focusObject(), qobject_cast<QObject*>(&anotherEdit)); - QCOMPARE(inputPanelVisibilitySpy.count(), 0); + QCOMPARE(inputPanelVisibilitySpy.size(), 0); anotherEdit.setFocus(false); QVERIFY(qApp->focusObject() != &anotherEdit); @@ -3643,18 +3696,18 @@ void tst_qquicktextedit::contentSize() QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() < textObject->height()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->setWrapMode(QQuickTextEdit::WordWrap); QVERIFY(textObject->contentWidth() <= textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); textObject->setText("The quickredfoxjumpedoverthe lazy brown dog"); QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); } void tst_qquicktextedit::implicitSizeBinding_data() @@ -3823,6 +3876,40 @@ void tst_qquicktextedit::largeTextObservesViewport() QCOMPARE(textPriv->cursorItem->isVisible(), textPriv->renderedRegion.intersects(textItem->cursorRectangle())); } +void tst_qquicktextedit::renderingAroundSelection() +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("threeLines.qml"))); + NodeCheckerTextEdit *textItem = qmlobject_cast<NodeCheckerTextEdit*>(window.rootObject()); + QVERIFY(textItem); + QTRY_VERIFY(textItem->linePositions.size() > 0); + const auto linePositions = textItem->linePositions; + const int lastLinePosition = textItem->lastLinePosition; + QQuickTextEditPrivate *textPriv = QQuickTextEditPrivate::get(textItem); + QSignalSpy renderSpy(&window, &QQuickWindow::afterRendering); + + if (lcTests().isDebugEnabled()) + QTest::qWait(500); // for visual check; not needed in CI + + const int renderCount = renderSpy.size(); + QPoint p1 = textItem->mapToScene(textItem->positionToRectangle(8).center()).toPoint(); + QPoint p2 = textItem->mapToScene(textItem->positionToRectangle(10).center()).toPoint(); + qCDebug(lcTests) << "drag from" << p1 << "to" << p2; + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, p1); + QTest::mouseMove(&window, p2); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, p2); + // ensure that QQuickTextEdit::updatePaintNode() has a chance to run + QTRY_COMPARE_GT(renderSpy.size(), renderCount); + + if (lcTests().isDebugEnabled()) + QTest::qWait(500); // for visual check; not needed in CI + + qCDebug(lcTests) << "TextEdit's nodes" << textPriv->textNodeMap; + qCDebug(lcTests) << "font" << textItem->font() << "line positions" << textItem->linePositions << "should be" << linePositions; + QCOMPARE(textItem->lastLinePosition, lastLinePosition); + QTRY_COMPARE(textItem->linePositions, linePositions); +} + void tst_qquicktextedit::signal_editingfinished() { QQuickView *window = new QQuickView(nullptr); @@ -3851,7 +3938,7 @@ void tst_qquicktextedit::signal_editingfinished() QKeyEvent key(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); - QTRY_COMPARE(editingFinished1Spy.count(), 1); + QTRY_COMPARE(editingFinished1Spy.size(), 1); QTRY_VERIFY(!input1->hasActiveFocus()); QTRY_VERIFY(input2->hasActiveFocus()); @@ -3867,7 +3954,7 @@ void tst_qquicktextedit::signal_editingfinished() QKeyEvent key = QKeyEvent(QEvent::KeyPress, Qt::Key_Tab, Qt::ShiftModifier, "", false, 1); QGuiApplication::sendEvent(window, &key); QVERIFY(key.isAccepted()); - QTRY_COMPARE(editingFinished2Spy.count(), 1); + QTRY_COMPARE(editingFinished2Spy.size(), 1); QTRY_VERIFY(input1->hasActiveFocus()); QTRY_VERIFY(!input2->hasActiveFocus()); @@ -4071,7 +4158,7 @@ void tst_qquicktextedit::preeditCursorRectangle() // Verify that the micro focus rect is positioned the same for position 0 as // it would be if there was no preedit text. QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>() - << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, preeditText.length(), QVariant())); + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, 0, preeditText.size(), QVariant())); QCoreApplication::sendEvent(edit, &imEvent); QCoreApplication::sendEvent(edit, &query); currentRect = query.value(Qt::ImCursorRectangle).toRectF(); @@ -4085,15 +4172,15 @@ void tst_qquicktextedit::preeditCursorRectangle() panelSpy.clear(); for (int i = 1; i <= 5; ++i) { QInputMethodEvent imEvent(preeditText, QList<QInputMethodEvent::Attribute>() - << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.length(), QVariant())); + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, preeditText.size(), QVariant())); QCoreApplication::sendEvent(edit, &imEvent); QCoreApplication::sendEvent(edit, &query); currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(edit->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); QVERIFY(previousRect.left() < currentRect.left()); - QCOMPARE(editSpy.count(), 1); editSpy.clear(); - QCOMPARE(panelSpy.count(), 1); panelSpy.clear(); + QCOMPARE(editSpy.size(), 1); editSpy.clear(); + QCOMPARE(panelSpy.size(), 1); panelSpy.clear(); previousRect = currentRect; } @@ -4108,8 +4195,8 @@ void tst_qquicktextedit::preeditCursorRectangle() currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(edit->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); - QCOMPARE(editSpy.count(), 1); - QCOMPARE(panelSpy.count(), 1); + QCOMPARE(editSpy.size(), 1); + QCOMPARE(panelSpy.size(), 1); // Verify that if there is no preedit cursor then the micro focus rect is the // same as it would be if it were positioned at the end of the preedit text. @@ -4122,8 +4209,8 @@ void tst_qquicktextedit::preeditCursorRectangle() QCOMPARE(edit->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); QCOMPARE(currentRect, previousRect); - QCOMPARE(editSpy.count(), 1); - QCOMPARE(panelSpy.count(), 1); + QCOMPARE(editSpy.size(), 1); + QCOMPARE(panelSpy.size(), 1); } void tst_qquicktextedit::inputMethodComposing() @@ -4150,37 +4237,37 @@ void tst_qquicktextedit::inputMethodComposing() } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); { QInputMethodEvent event(text.mid(12), QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(edit, &event); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); { QInputMethodEvent event; QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); // Changing the text while not composing doesn't alter the composing state. edit->setText(text.mid(0, 16)); QCOMPARE(edit->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); { QInputMethodEvent event(text.mid(16), QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); // Changing the text while composing cancels composition. edit->setText(text.mid(0, 12)); QCOMPARE(edit->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); { // Preedit cursor positioned outside (empty) preedit; composing. QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4188,7 +4275,7 @@ void tst_qquicktextedit::inputMethodComposing() QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Cursor hidden; composing QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4196,7 +4283,7 @@ void tst_qquicktextedit::inputMethodComposing() QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Default cursor attributes; composing. QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4204,7 +4291,7 @@ void tst_qquicktextedit::inputMethodComposing() QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Selections are persisted: not composing QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4212,7 +4299,7 @@ void tst_qquicktextedit::inputMethodComposing() QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); edit->setCursorPosition(0); @@ -4224,14 +4311,14 @@ void tst_qquicktextedit::inputMethodComposing() QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); { QInputMethodEvent event; QGuiApplication::sendEvent(edit, &event); } QCOMPARE(edit->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 8); + QCOMPARE(spy.size(), 8); } void tst_qquicktextedit::cursorRectangleSize_data() @@ -4307,7 +4394,7 @@ void tst_qquicktextedit::getText_data() QTest::newRow("all plain text") << standard.at(0) - << 0 << standard.at(0).length() + << 0 << standard.at(0).size() << standard.at(0); QTest::newRow("plain text sub string") @@ -4327,17 +4414,17 @@ void tst_qquicktextedit::getText_data() QTest::newRow("plain text cropped end") << standard.at(0) - << 23 << standard.at(0).length() + 8 + << 23 << standard.at(0).size() + 8 << standard.at(0).mid(23); QTest::newRow("plain text cropped beginning and end") << standard.at(0) - << -9 << standard.at(0).length() + 4 + << -9 << standard.at(0).size() + 4 << standard.at(0); QTest::newRow("all rich text") << richBoldText - << 0 << plainBoldText.length() + << 0 << plainBoldText.size() << plainBoldText; QTest::newRow("rich text sub string") @@ -4348,7 +4435,7 @@ void tst_qquicktextedit::getText_data() // Line break. QTest::newRow("all plain text (line break)") << standard.at(1) - << 0 << standard.at(1).length() + << 0 << standard.at(1).size() << standard.at(1); QTest::newRow("plain text sub string (line break)") @@ -4368,17 +4455,17 @@ void tst_qquicktextedit::getText_data() QTest::newRow("plain text cropped end (line break)") << standard.at(1) - << 23 << standard.at(1).length() + 8 + << 23 << standard.at(1).size() + 8 << standard.at(1).mid(23); QTest::newRow("plain text cropped beginning and end (line break)") << standard.at(1) - << -9 << standard.at(1).length() + 4 + << -9 << standard.at(1).size() + 4 << standard.at(1); QTest::newRow("all rich text (line break)") << richBoldTextLB - << 0 << plainBoldTextLB.length() + << 0 << plainBoldTextLB.size() << plainBoldTextLB; QTest::newRow("rich text sub string (line break)") @@ -4417,7 +4504,7 @@ void tst_qquicktextedit::getFormattedText_data() QTest::newRow("all plain text") << standard.at(0) << QQuickTextEdit::PlainText - << 0 << standard.at(0).length() + << 0 << standard.at(0).size() << standard.at(0); QTest::newRow("plain text sub string") @@ -4441,31 +4528,31 @@ void tst_qquicktextedit::getFormattedText_data() QTest::newRow("plain text cropped end") << standard.at(0) << QQuickTextEdit::PlainText - << 23 << standard.at(0).length() + 8 + << 23 << standard.at(0).size() + 8 << standard.at(0).mid(23); QTest::newRow("plain text cropped beginning and end") << standard.at(0) << QQuickTextEdit::PlainText - << -9 << standard.at(0).length() + 4 + << -9 << standard.at(0).size() + 4 << standard.at(0); QTest::newRow("all rich (Auto) text") << richBoldText << QQuickTextEdit::AutoText - << 0 << plainBoldText.length() + << 0 << plainBoldText.size() << QString("This is some \\<.*\\>bold\\</.*\\> text"); QTest::newRow("all rich (Rich) text") << richBoldText << QQuickTextEdit::RichText - << 0 << plainBoldText.length() + << 0 << plainBoldText.size() << QString("This is some \\<.*\\>bold\\</.*\\> text"); QTest::newRow("all rich (Plain) text") << richBoldText << QQuickTextEdit::PlainText - << 0 << richBoldText.length() + << 0 << richBoldText.size() << richBoldText; QTest::newRow("rich (Auto) text sub string") @@ -4544,10 +4631,10 @@ void tst_qquicktextedit::append_data() QTest::newRow("cursor follows (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() + << standard.at(0).size() << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("\nHello") - << standard.at(0).length() + 6 << standard.at(0).length() + 6 << standard.at(0).length() + 6 + << standard.at(0).size() + 6 << standard.at(0).size() + 6 << standard.at(0).size() + 6 << false << true; QTest::newRow("selection kept intact (beginning)") @@ -4568,10 +4655,10 @@ void tst_qquicktextedit::append_data() QTest::newRow("selection kept intact, cursor follows (end)") << standard.at(0) << QQuickTextEdit::PlainText - << 18 << standard.at(0).length() + << 18 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("\nHello") - << 18 << standard.at(0).length() + 6 << standard.at(0).length() + 6 + << 18 << standard.at(0).size() + 6 << standard.at(0).size() + 6 << true << true; QTest::newRow("reversed selection kept intact") @@ -4657,12 +4744,12 @@ void tst_qquicktextedit::append() if (textFormat == QQuickTextEdit::RichText || textFormat == QQuickTextEdit::MarkdownText || (textFormat == QQuickTextEdit::AutoText && (Qt::mightBeRichText(text) || Qt::mightBeRichText(appendText)))) { - QCOMPARE(textEdit->getText(0, expectedText.length()), expectedText); + QCOMPARE(textEdit->getText(0, expectedText.size()), expectedText); } else { QCOMPARE(textEdit->text(), expectedText); } - QCOMPARE(textEdit->length(), expectedText.length()); + QCOMPARE(textEdit->length(), expectedText.size()); QCOMPARE(textEdit->selectionStart(), expectedSelectionStart); QCOMPARE(textEdit->selectionEnd(), expectedSelectionEnd); @@ -4671,11 +4758,11 @@ void tst_qquicktextedit::append() if (selectionStart > selectionEnd) qSwap(selectionStart, selectionEnd); - QCOMPARE(selectionSpy.count() > 0, selectionChanged); - QCOMPARE(selectionStartSpy.count() > 0, selectionStart != expectedSelectionStart); - QCOMPARE(selectionEndSpy.count() > 0, selectionEnd != expectedSelectionEnd); - QCOMPARE(textSpy.count() > 0, text != expectedText); - QCOMPARE(cursorPositionSpy.count() > 0, cursorPositionChanged); + QCOMPARE(selectionSpy.size() > 0, selectionChanged); + QCOMPARE(selectionStartSpy.size() > 0, selectionStart != expectedSelectionStart); + QCOMPARE(selectionEndSpy.size() > 0, selectionEnd != expectedSelectionEnd); + QCOMPARE(textSpy.size() > 0, text != expectedText); + QCOMPARE(cursorPositionSpy.size() > 0, cursorPositionChanged); } void tst_qquicktextedit::insert_data() @@ -4703,10 +4790,10 @@ void tst_qquicktextedit::insert_data() QTest::newRow("at cursor position (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() << standard.at(0).length() + << standard.at(0).size() << standard.at(0).size() << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") - << standard.at(0).length() + 5 << standard.at(0).length() + 5 << standard.at(0).length() + 5 + << standard.at(0).size() + 5 << standard.at(0).size() + 5 << standard.at(0).size() + 5 << false << true; QTest::newRow("at cursor position (middle)") @@ -4727,10 +4814,10 @@ void tst_qquicktextedit::insert_data() QTest::newRow("before cursor position (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() << 18 + << standard.at(0).size() << standard.at(0).size() << 18 << QString("Hello") << standard.at(0).mid(0, 18) + QString("Hello") + standard.at(0).mid(18) - << standard.at(0).length() + 5 << standard.at(0).length() + 5 << standard.at(0).length() + 5 + << standard.at(0).size() + 5 << standard.at(0).size() + 5 << standard.at(0).size() + 5 << false << true; QTest::newRow("before cursor position (middle)") @@ -4743,7 +4830,7 @@ void tst_qquicktextedit::insert_data() QTest::newRow("after cursor position (middle)") << standard.at(0) << QQuickTextEdit::PlainText - << 18 << 18 << standard.at(0).length() + << 18 << 18 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 18 << 18 << 18 @@ -4767,7 +4854,7 @@ void tst_qquicktextedit::insert_data() QTest::newRow("after selection") << standard.at(0) << QQuickTextEdit::PlainText - << 14 << 19 << standard.at(0).length() + << 14 << 19 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 14 << 19 << 19 @@ -4775,7 +4862,7 @@ void tst_qquicktextedit::insert_data() QTest::newRow("after reversed selection") << standard.at(0) << QQuickTextEdit::PlainText - << 19 << 14 << standard.at(0).length() + << 19 << 14 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 14 << 19 << 14 @@ -4831,7 +4918,7 @@ void tst_qquicktextedit::insert_data() QTest::newRow("past end") << standard.at(0) << QQuickTextEdit::PlainText - << 0 << 0 << standard.at(0).length() + 3 + << 0 << 0 << standard.at(0).size() + 3 << QString("Hello") << standard.at(0) << 0 << 0 << 0 @@ -4906,12 +4993,12 @@ void tst_qquicktextedit::insert() if (textFormat == QQuickTextEdit::RichText || textFormat == QQuickTextEdit::MarkdownText || (textFormat == QQuickTextEdit::AutoText && (Qt::mightBeRichText(text) || Qt::mightBeRichText(insertText)))) { - QCOMPARE(textEdit->getText(0, expectedText.length()), expectedText); + QCOMPARE(textEdit->getText(0, expectedText.size()), expectedText); qCDebug(lcTests) << "with formatting:" << textEdit->getFormattedText(0, 100); } else { QCOMPARE(textEdit->text(), expectedText); } - QCOMPARE(textEdit->length(), expectedText.length()); + QCOMPARE(textEdit->length(), expectedText.size()); QCOMPARE(textEdit->selectionStart(), expectedSelectionStart); QCOMPARE(textEdit->selectionEnd(), expectedSelectionEnd); @@ -4920,11 +5007,11 @@ void tst_qquicktextedit::insert() if (selectionStart > selectionEnd) qSwap(selectionStart, selectionEnd); - QCOMPARE(selectionSpy.count() > 0, selectionChanged); - QCOMPARE(selectionStartSpy.count() > 0, selectionStart != expectedSelectionStart); - QCOMPARE(selectionEndSpy.count() > 0, selectionEnd != expectedSelectionEnd); - QCOMPARE(textSpy.count() > 0, text != expectedText); - QCOMPARE(cursorPositionSpy.count() > 0, cursorPositionChanged); + QCOMPARE(selectionSpy.size() > 0, selectionChanged); + QCOMPARE(selectionStartSpy.size() > 0, selectionStart != expectedSelectionStart); + QCOMPARE(selectionEndSpy.size() > 0, selectionEnd != expectedSelectionEnd); + QCOMPARE(textSpy.size() > 0, text != expectedText); + QCOMPARE(cursorPositionSpy.size() > 0, cursorPositionChanged); } void tst_qquicktextedit::remove_data() @@ -4963,18 +5050,18 @@ void tst_qquicktextedit::remove_data() QTest::newRow("to cursor position (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() - << standard.at(0).length() << standard.at(0).length() - 5 - << standard.at(0).mid(0, standard.at(0).length() - 5) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() << standard.at(0).size() + << standard.at(0).size() << standard.at(0).size() - 5 + << standard.at(0).mid(0, standard.at(0).size() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("to cursor position (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() << standard.at(0).size() + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("from cursor position (middle)") @@ -5003,10 +5090,10 @@ void tst_qquicktextedit::remove_data() QTest::newRow("before cursor position (end)") << standard.at(0) << QQuickTextEdit::PlainText - << standard.at(0).length() << standard.at(0).length() + << standard.at(0).size() << standard.at(0).size() << 18 << 23 << standard.at(0).mid(0, 18) + standard.at(0).mid(23) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("before cursor position (middle)") @@ -5044,16 +5131,16 @@ void tst_qquicktextedit::remove_data() QTest::newRow("after selection") << standard.at(0) << QQuickTextEdit::PlainText << 14 << 19 - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) << 14 << 19 << 19 << false << false; QTest::newRow("after reversed selection") << standard.at(0) << QQuickTextEdit::PlainText << 19 << 14 - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) << 14 << 19 << 14 << false << false; @@ -5084,7 +5171,7 @@ void tst_qquicktextedit::remove_data() QTest::newRow("plain text cropped end") << standard.at(0) << QQuickTextEdit::PlainText << 0 << 0 - << 23 << standard.at(0).length() + 8 + << 23 << standard.at(0).size() + 8 << standard.at(0).mid(0, 23) << 0 << 0 << 0 << false << false; @@ -5092,7 +5179,7 @@ void tst_qquicktextedit::remove_data() QTest::newRow("plain text cropped beginning and end") << standard.at(0) << QQuickTextEdit::PlainText << 0 << 0 - << -9 << standard.at(0).length() + 4 + << -9 << standard.at(0).size() + 4 << QString() << 0 << 0 << 0 << false << false; @@ -5100,7 +5187,7 @@ void tst_qquicktextedit::remove_data() QTest::newRow("all rich text") << richBoldText << QQuickTextEdit::RichText << 0 << 0 - << 0 << plainBoldText.length() + << 0 << plainBoldText.size() << QString() << 0 << 0 << 0 << false << false; @@ -5148,11 +5235,11 @@ void tst_qquicktextedit::remove() if (textFormat == QQuickTextEdit::RichText || (textFormat == QQuickTextEdit::AutoText && Qt::mightBeRichText(text))) { - QCOMPARE(textEdit->getText(0, expectedText.length()), expectedText); + QCOMPARE(textEdit->getText(0, expectedText.size()), expectedText); } else { QCOMPARE(textEdit->text(), expectedText); } - QCOMPARE(textEdit->length(), expectedText.length()); + QCOMPARE(textEdit->length(), expectedText.size()); if (selectionStart > selectionEnd) // qSwap(selectionStart, selectionEnd); @@ -5161,14 +5248,14 @@ void tst_qquicktextedit::remove() QCOMPARE(textEdit->selectionEnd(), expectedSelectionEnd); QCOMPARE(textEdit->cursorPosition(), expectedCursorPosition); - QCOMPARE(selectionSpy.count() > 0, selectionChanged); - QCOMPARE(selectionStartSpy.count() > 0, selectionStart != expectedSelectionStart); - QCOMPARE(selectionEndSpy.count() > 0, selectionEnd != expectedSelectionEnd); - QCOMPARE(textSpy.count() > 0, text != expectedText); + QCOMPARE(selectionSpy.size() > 0, selectionChanged); + QCOMPARE(selectionStartSpy.size() > 0, selectionStart != expectedSelectionStart); + QCOMPARE(selectionEndSpy.size() > 0, selectionEnd != expectedSelectionEnd); + QCOMPARE(textSpy.size() > 0, text != expectedText); if (cursorPositionChanged) // - QVERIFY(cursorPositionSpy.count() > 0); + QVERIFY(cursorPositionSpy.size() > 0); } #if QT_CONFIG(shortcut) @@ -5507,11 +5594,11 @@ void tst_qquicktextedit::undo() // QTest::keyClick(testWidget, Qt::Key_End, Qt::ShiftModifier); } - for (int j = 0; j < insertString.at(i).length(); j++) + for (int j = 0; j < insertString.at(i).size(); j++) QTest::keyClick(&window, insertString.at(i).at(j).toLatin1()); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // STEP 2: Next call undo several times and see if we can restore to the previous state for (i = 0; i < expectedString.size() - 1; ++i) { @@ -5523,7 +5610,7 @@ void tst_qquicktextedit::undo() // STEP 3: Verify that we have undone everything QVERIFY(textEdit->text().isEmpty()); QVERIFY(!textEdit->canUndo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextedit::redo_data() @@ -5584,13 +5671,13 @@ void tst_qquicktextedit::redo() for (i = 0; i < insertString.size(); ++i) { if (insertIndex[i] > -1) textEdit->setCursorPosition(insertIndex[i]); - for (int j = 0; j < insertString.at(i).length(); j++) + for (int j = 0; j < insertString.at(i).size(); j++) QTest::keyClick(&window, insertString.at(i).at(j).toLatin1()); QVERIFY(textEdit->canUndo()); QVERIFY(!textEdit->canRedo()); } - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // undo everything while (!textEdit->text().isEmpty()) { @@ -5599,7 +5686,7 @@ void tst_qquicktextedit::redo() QVERIFY(textEdit->canRedo()); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); for (i = 0; i < expectedString.size(); ++i) { QVERIFY(textEdit->canRedo()); @@ -5608,7 +5695,7 @@ void tst_qquicktextedit::redo() QVERIFY(textEdit->canUndo()); } QVERIFY(!textEdit->canRedo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } #if QT_CONFIG(shortcut) @@ -5830,12 +5917,12 @@ void tst_qquicktextedit::clear() textEdit->clear(); QVERIFY(textEdit->text().isEmpty()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // checks that clears can be undone textEdit->undo(); QVERIFY(!textEdit->canUndo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(textEdit->text(), QString("I am Legend")); textEdit->setCursorPosition(4); @@ -5847,12 +5934,12 @@ void tst_qquicktextedit::clear() textEdit->clear(); QVERIFY(textEdit->text().isEmpty()); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); // checks that clears can be undone textEdit->undo(); QVERIFY(!textEdit->canUndo()); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); QCOMPARE(textEdit->text(), QString("I am Legend")); textEdit->setText(QString("<i>I am Legend</i>")); @@ -5860,11 +5947,11 @@ void tst_qquicktextedit::clear() textEdit->clear(); QVERIFY(textEdit->text().isEmpty()); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); // checks that clears can be undone textEdit->undo(); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); QCOMPARE(textEdit->text(), QString("<i>I am Legend</i>")); } @@ -5883,15 +5970,15 @@ void tst_qquicktextedit::baseUrl() textObject->setBaseUrl(localUrl); QCOMPARE(textObject->baseUrl(), localUrl); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); textObject->setBaseUrl(remoteUrl); QCOMPARE(textObject->baseUrl(), remoteUrl); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->resetBaseUrl(); QCOMPARE(textObject->baseUrl(), localUrl); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextedit::embeddedImages_data() @@ -5989,7 +6076,7 @@ void tst_qquicktextedit::cursorRectangle_QTBUG_38947() QRectF rect = edit->positionToRectangle(i); QTest::mouseMove(&window, rect.center().toPoint()); QCOMPARE(edit->cursorRectangle(), rect); - QCOMPARE(spy.count(), i); + QCOMPARE(spy.size(), i); } QPoint to = edit->positionToRectangle(edit->length() - 1).center().toPoint(); @@ -6018,13 +6105,13 @@ void tst_qquicktextedit::doubleSelect_QTBUG_38704() QSignalSpy selectionSpy(textEdit, SIGNAL(selectedTextChanged())); textEdit->select(0,1); //Select some text initially - QCOMPARE(selectionSpy.count(), 1); + QCOMPARE(selectionSpy.size(), 1); textEdit->select(0,1); //No change to selection start/end - QCOMPARE(selectionSpy.count(), 1); + QCOMPARE(selectionSpy.size(), 1); textEdit->select(0,2); //Change selection end - QCOMPARE(selectionSpy.count(), 2); + QCOMPARE(selectionSpy.size(), 2); textEdit->select(1,2); //Change selection start - QCOMPARE(selectionSpy.count(), 3); + QCOMPARE(selectionSpy.size(), 3); } void tst_qquicktextedit::padding() @@ -6210,28 +6297,28 @@ void tst_qquicktextedit::keyEventPropagation() QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit *>(); QVERIFY(textEdit->hasActiveFocus()); simulateKey(&view, Qt::Key_Back); - QCOMPARE(downSpy.count(), 1); - QCOMPARE(upSpy.count(), 1); + QCOMPARE(downSpy.size(), 1); + QCOMPARE(upSpy.size(), 1); auto downKey = downSpy.takeFirst(); auto upKey = upSpy.takeFirst(); QCOMPARE(downKey.at(0).toInt(), Qt::Key_Back); QCOMPARE(upKey.at(0).toInt(), Qt::Key_Back); simulateKey(&view, Qt::Key_Shift); - QCOMPARE(downSpy.count(), 1); - QCOMPARE(upSpy.count(), 1); + QCOMPARE(downSpy.size(), 1); + QCOMPARE(upSpy.size(), 1); downKey = downSpy.takeFirst(); upKey = upSpy.takeFirst(); QCOMPARE(downKey.at(0).toInt(), Qt::Key_Shift); QCOMPARE(upKey.at(0).toInt(), Qt::Key_Shift); simulateKey(&view, Qt::Key_A); - QCOMPARE(downSpy.count(), 0); - QCOMPARE(upSpy.count(), 0); + QCOMPARE(downSpy.size(), 0); + QCOMPARE(upSpy.size(), 0); simulateKey(&view, Qt::Key_Right); - QCOMPARE(downSpy.count(), 0); - QCOMPARE(upSpy.count(), 1); + QCOMPARE(downSpy.size(), 0); + QCOMPARE(upSpy.size(), 1); upKey = upSpy.takeFirst(); QCOMPARE(upKey.at(0).toInt(), Qt::Key_Right); } @@ -6366,7 +6453,7 @@ void tst_qquicktextedit::touchscreenSetsFocusAndMovesCursor() QVERIFY(top); QQuickTextEdit *bottom = window.rootObject()->findChild<QQuickTextEdit*>("bottom"); QVERIFY(bottom); - const auto len = bottom->text().length(); + const auto len = bottom->text().size(); // tap the bottom field QPoint p1 = bottom->mapToScene({6, 6}).toPoint(); @@ -6379,7 +6466,7 @@ void tst_qquicktextedit::touchscreenSetsFocusAndMovesCursor() QVERIFY(!bottom->text().startsWith('q')); QTest::keyClick(&window, Qt::Key_Q); QVERIFY(bottom->text().startsWith('q')); - QCOMPARE(bottom->text().length(), len + 1); + QCOMPARE(bottom->text().size(), len + 1); QTest::touchEvent(&window, touchDevice).release(0, p1, &window); QQuickTouchUtils::flush(&window); // the cursor gets moved on release, as long as TextInput's grab wasn't stolen (e.g. by Flickable) diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index 54f650f86e..9475d63930 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -226,7 +226,7 @@ Q_DECLARE_METATYPE(KeyList) void tst_qquicktextinput::simulateKeys(QWindow *window, const QList<Key> &keys) { - for (int i = 0; i < keys.count(); ++i) { + for (int i = 0; i < keys.size(); ++i) { const Qt::KeyboardModifiers modifiers = keys.at(i).keyCombination.keyboardModifiers(); const QChar character = keys.at(i).character; if (!character.isNull()) @@ -318,7 +318,7 @@ void tst_qquicktextinput::text() QVERIFY(textinputObject != nullptr); QCOMPARE(textinputObject->text(), standard.at(i)); - QCOMPARE(textinputObject->length(), standard.at(i).length()); + QCOMPARE(textinputObject->length(), standard.at(i).size()); delete textinputObject; } @@ -470,36 +470,36 @@ void tst_qquicktextinput::color() textInputObject->setColor(QColor("white")); QCOMPARE(textInputObject->color(), QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textInputObject->setSelectionColor(QColor("black")); QCOMPARE(textInputObject->selectionColor(), QColor("black")); - QCOMPARE(selectionColorSpy.count(), 1); + QCOMPARE(selectionColorSpy.size(), 1); textInputObject->setSelectedTextColor(QColor("blue")); QCOMPARE(textInputObject->selectedTextColor(), QColor("blue")); - QCOMPARE(selectedTextColorSpy.count(), 1); + QCOMPARE(selectedTextColorSpy.size(), 1); textInputObject->setColor(QColor("white")); - QCOMPARE(colorSpy.count(), 1); + QCOMPARE(colorSpy.size(), 1); textInputObject->setSelectionColor(QColor("black")); - QCOMPARE(selectionColorSpy.count(), 1); + QCOMPARE(selectionColorSpy.size(), 1); textInputObject->setSelectedTextColor(QColor("blue")); - QCOMPARE(selectedTextColorSpy.count(), 1); + QCOMPARE(selectedTextColorSpy.size(), 1); textInputObject->setColor(QColor("black")); QCOMPARE(textInputObject->color(), QColor("black")); - QCOMPARE(colorSpy.count(), 2); + QCOMPARE(colorSpy.size(), 2); textInputObject->setSelectionColor(QColor("blue")); QCOMPARE(textInputObject->selectionColor(), QColor("blue")); - QCOMPARE(selectionColorSpy.count(), 2); + QCOMPARE(selectionColorSpy.size(), 2); textInputObject->setSelectedTextColor(QColor("white")); QCOMPARE(textInputObject->selectedTextColor(), QColor("white")); - QCOMPARE(selectedTextColorSpy.count(), 2); + QCOMPARE(selectedTextColorSpy.size(), 2); } //test color @@ -575,7 +575,7 @@ void tst_qquicktextinput::wrap() delete textObject; } - for (int i = 0; i < standard.count(); i++) { + for (int i = 0; i < standard.size(); i++) { QString componentStr = "import QtQuick 2.0\nTextInput { wrapMode: Text.WrapAnywhere; width: 30; text: \"" + standard.at(i) + "\" }"; QQmlComponent textComponent(&engine); textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile("")); @@ -605,14 +605,14 @@ void tst_qquicktextinput::wrap() input->setWrapMode(QQuickTextInput::Wrap); QCOMPARE(input->wrapMode(), QQuickTextInput::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setWrapMode(QQuickTextInput::Wrap); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setWrapMode(QQuickTextInput::NoWrap); QCOMPARE(input->wrapMode(), QQuickTextInput::NoWrap); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } } @@ -648,7 +648,7 @@ void tst_qquicktextinput::selection() QCOMPARE(textinputObject->selectionEnd(), 0); QVERIFY(textinputObject->selectedText().isNull()); - textinputObject->setCursorPosition(textinputObject->text().length() + 1); + textinputObject->setCursorPosition(textinputObject->text().size() + 1); QCOMPARE(textinputObject->cursorPosition(), 0); QCOMPARE(textinputObject->selectionStart(), 0); QCOMPARE(textinputObject->selectionEnd(), 0); @@ -708,7 +708,7 @@ void tst_qquicktextinput::selection() QInputMethodEvent event("", attributes); QGuiApplication::sendEvent(textinputObject, &event); } - QCOMPARE(selectionSpy.count(), 1); + QCOMPARE(selectionSpy.size(), 1); QCOMPARE(textinputObject->selectionStart(), 12); QCOMPARE(textinputObject->selectionEnd(), 17); @@ -732,7 +732,7 @@ void tst_qquicktextinput::persistentSelection() input->setPersistentSelection(false); QCOMPARE(input->persistentSelection(), false); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); input->select(1, 4); QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); @@ -745,7 +745,7 @@ void tst_qquicktextinput::persistentSelection() input->setPersistentSelection(true); QCOMPARE(input->persistentSelection(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->select(1, 4); QCOMPARE(input->property("selected").toString(), QLatin1String("ell")); @@ -776,25 +776,25 @@ void tst_qquicktextinput::overwriteMode() QVERIFY(textInput->hasActiveFocus()); textInput->setOverwriteMode(true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(true, textInput->overwriteMode()); textInput->setOverwriteMode(false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(false, textInput->overwriteMode()); QVERIFY(!textInput->overwriteMode()); QString insertString = "Some first text"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textInput->text(), QString("Some first text")); textInput->setOverwriteMode(true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); textInput->setCursorPosition(5); insertString = "shiny"; - for (int j = 0; j < insertString.length(); j++) + for (int j = 0; j < insertString.size(); j++) QTest::keyClick(&window, insertString.at(j).toLatin1()); QCOMPARE(textInput->text(), QString("Some shiny text")); } @@ -836,24 +836,24 @@ void tst_qquicktextinput::isRightToLeft() // first test that the right string is delivered to the QString::isRightToLeft() QCOMPARE(textInput.isRightToLeft(0,0), text.mid(0,0).isRightToLeft()); QCOMPARE(textInput.isRightToLeft(0,1), text.mid(0,1).isRightToLeft()); - QCOMPARE(textInput.isRightToLeft(text.length()-2, text.length()-1), text.mid(text.length()-2, text.length()-1).isRightToLeft()); - QCOMPARE(textInput.isRightToLeft(text.length()/2, text.length()/2 + 1), text.mid(text.length()/2, text.length()/2 + 1).isRightToLeft()); - QCOMPARE(textInput.isRightToLeft(0,text.length()/4), text.mid(0,text.length()/4).isRightToLeft()); - QCOMPARE(textInput.isRightToLeft(text.length()/4,3*text.length()/4), text.mid(text.length()/4,3*text.length()/4).isRightToLeft()); + QCOMPARE(textInput.isRightToLeft(text.size()-2, text.size()-1), text.mid(text.size()-2, text.size()-1).isRightToLeft()); + QCOMPARE(textInput.isRightToLeft(text.size()/2, text.size()/2 + 1), text.mid(text.size()/2, text.size()/2 + 1).isRightToLeft()); + QCOMPARE(textInput.isRightToLeft(0,text.size()/4), text.mid(0,text.size()/4).isRightToLeft()); + QCOMPARE(textInput.isRightToLeft(text.size()/4,3*text.size()/4), text.mid(text.size()/4,3*text.size()/4).isRightToLeft()); if (text.isEmpty()) QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML TextInput: isRightToLeft(start, end) called with the end property being smaller than the start."); - QCOMPARE(textInput.isRightToLeft(3*text.length()/4,text.length()-1), text.mid(3*text.length()/4,text.length()-1).isRightToLeft()); + QCOMPARE(textInput.isRightToLeft(3*text.size()/4,text.size()-1), text.mid(3*text.size()/4,text.size()-1).isRightToLeft()); // then test that the feature actually works QCOMPARE(textInput.isRightToLeft(0,0), emptyString); QCOMPARE(textInput.isRightToLeft(0,1), firstCharacter); - QCOMPARE(textInput.isRightToLeft(text.length()-2, text.length()-1), lastCharacter); - QCOMPARE(textInput.isRightToLeft(text.length()/2, text.length()/2 + 1), middleCharacter); - QCOMPARE(textInput.isRightToLeft(0,text.length()/4), startString); - QCOMPARE(textInput.isRightToLeft(text.length()/4,3*text.length()/4), midString); + QCOMPARE(textInput.isRightToLeft(text.size()-2, text.size()-1), lastCharacter); + QCOMPARE(textInput.isRightToLeft(text.size()/2, text.size()/2 + 1), middleCharacter); + QCOMPARE(textInput.isRightToLeft(0,text.size()/4), startString); + QCOMPARE(textInput.isRightToLeft(text.size()/4,3*text.size()/4), midString); if (text.isEmpty()) QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML TextInput: isRightToLeft(start, end) called with the end property being smaller than the start."); - QCOMPARE(textInput.isRightToLeft(3*text.length()/4,text.length()-1), endString); + QCOMPARE(textInput.isRightToLeft(3*text.size()/4,text.size()-1), endString); } void tst_qquicktextinput::moveCursorSelection_data() @@ -1289,8 +1289,8 @@ void tst_qquicktextinput::dragMouseSelection() QTest::mouseMove(&window, QPoint(x2, y)); QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(x2,y)); QString str1; - QTRY_VERIFY((str1 = textInputObject->selectedText()).length() > 3); - QTRY_VERIFY(str1.length() > 3); + QTRY_VERIFY((str1 = textInputObject->selectedText()).size() > 3); + QTRY_VERIFY(str1.size() > 3); // press and drag the current selection. x1 = 40; @@ -1299,7 +1299,7 @@ void tst_qquicktextinput::dragMouseSelection() QTest::mouseMove(&window, QPoint(x2, y)); QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, QPoint(x2,y)); QString str2 = textInputObject->selectedText(); - QTRY_VERIFY(str2.length() > 3); + QTRY_VERIFY(str2.size() > 3); QTRY_VERIFY(str1 != str2); } @@ -1355,7 +1355,7 @@ void tst_qquicktextinput::mouseSelectionMode() if (selectWords) { QTRY_COMPARE(textInputObject->selectedText(), text); } else { - QTRY_VERIFY(textInputObject->selectedText().length() > 3); + QTRY_VERIFY(textInputObject->selectedText().size() > 3); QVERIFY(textInputObject->selectedText() != text); } } @@ -1374,14 +1374,14 @@ void tst_qquicktextinput::mouseSelectionMode_accessors() input->setMouseSelectionMode(QQuickTextInput::SelectWords); QCOMPARE(input->mouseSelectionMode(), QQuickTextInput::SelectWords); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setMouseSelectionMode(QQuickTextInput::SelectWords); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setMouseSelectionMode(QQuickTextInput::SelectCharacters); QCOMPARE(input->mouseSelectionMode(), QQuickTextInput::SelectCharacters); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextinput::selectByMouse() @@ -1398,15 +1398,15 @@ void tst_qquicktextinput::selectByMouse() input->setSelectByMouse(true); QCOMPARE(input->selectByMouse(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(spy.at(0).at(0).toBool(), true); input->setSelectByMouse(true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setSelectByMouse(false); QCOMPARE(input->selectByMouse(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(spy.at(1).at(0).toBool(), false); } @@ -1424,14 +1424,14 @@ void tst_qquicktextinput::renderType() input->setRenderType(QQuickTextInput::NativeRendering); QCOMPARE(input->renderType(), QQuickTextInput::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setRenderType(QQuickTextInput::NativeRendering); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input->setRenderType(QQuickTextInput::QtRendering); QCOMPARE(input->renderType(), QQuickTextInput::QtRendering); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextinput::horizontalAlignment_RightToLeft() @@ -1541,7 +1541,7 @@ void tst_qquicktextinput::horizontalAlignment_RightToLeft() QSignalSpy cursorRectangleSpy(textInput, SIGNAL(cursorRectangleChanged())); platformInputContext.setInputDirection(Qt::RightToLeft); QCOMPARE(qApp->inputMethod()->inputDirection(), Qt::RightToLeft); - QCOMPARE(cursorRectangleSpy.count(), 1); + QCOMPARE(cursorRectangleSpy.size(), 1); QCOMPARE(textInput->hAlign(), QQuickTextInput::AlignRight); QVERIFY(textInput->boundingRect().right() >= textInput->width() - 1); QVERIFY(textInput->boundingRect().right() <= textInput->width() + 1); @@ -1876,15 +1876,15 @@ void tst_qquicktextinput::maxLength() QVERIFY(textinputObject->text().isEmpty()); QCOMPARE(textinputObject->maxLength(), 10); foreach (const QString &str, standard) { - QVERIFY(textinputObject->text().length() <= 10); + QVERIFY(textinputObject->text().size() <= 10); textinputObject->setText(str); - QVERIFY(textinputObject->text().length() <= 10); + QVERIFY(textinputObject->text().size() <= 10); } textinputObject->setText(""); QTRY_VERIFY(textinputObject->hasActiveFocus()); for (int i=0; i<20; i++) { - QTRY_COMPARE(textinputObject->text().length(), qMin(i,10)); + QTRY_COMPARE(textinputObject->text().size(), qMin(i,10)); QTest::keyClick(&window, Qt::Key_A); } } @@ -1900,11 +1900,11 @@ void tst_qquicktextinput::masks() QQuickTextInput *textinputObject = qobject_cast<QQuickTextInput *>(window.rootObject()); QVERIFY(textinputObject != nullptr); QTRY_VERIFY(textinputObject->hasActiveFocus()); - QCOMPARE(textinputObject->text().length(), 0); + QCOMPARE(textinputObject->text().size(), 0); QCOMPARE(textinputObject->inputMask(), QString("HHHHhhhh; ")); QCOMPARE(textinputObject->length(), 8); for (int i=0; i<10; i++) { - QTRY_COMPARE(qMin(i,8), textinputObject->text().length()); + QTRY_COMPARE(qMin(i,8), textinputObject->text().size()); QCOMPARE(textinputObject->length(), 8); QCOMPARE(textinputObject->getText(0, qMin(i, 8)), QString(qMin(i, 8), 'a')); QCOMPARE(textinputObject->getText(qMin(i, 8), 8), QString(8 - qMin(i, 8), ' ')); @@ -1956,10 +1956,10 @@ void tst_qquicktextinput::validators() QTRY_COMPARE(intInput->text(), QLatin1String("1")); QCOMPARE(intInput->hasAcceptableInput(), false); QCOMPARE(intInput->property("acceptable").toBool(), false); - QCOMPARE(intSpy.count(), 0); + QCOMPARE(intSpy.size(), 0); QCOMPARE(intInput->hasAcceptableInput(), false); QCOMPARE(intInput->property("acceptable").toBool(), false); - QCOMPARE(intSpy.count(), 0); + QCOMPARE(intSpy.size(), 0); QTest::keyPress(&window, Qt::Key_Period); QTest::keyRelease(&window, Qt::Key_Period, Qt::NoModifier); QTRY_COMPARE(intInput->text(), QLatin1String("1")); @@ -1987,13 +1987,13 @@ void tst_qquicktextinput::validators() QCOMPARE(intInput->text(), QLatin1String("11")); QCOMPARE(intInput->hasAcceptableInput(), true); QCOMPARE(intInput->property("acceptable").toBool(), true); - QCOMPARE(intSpy.count(), 1); + QCOMPARE(intSpy.size(), 1); QTest::keyPress(&window, Qt::Key_0); QTest::keyRelease(&window, Qt::Key_0, Qt::NoModifier); QCOMPARE(intInput->text(), QLatin1String("11")); QCOMPARE(intInput->hasAcceptableInput(), true); QCOMPARE(intInput->property("acceptable").toBool(), true); - QCOMPARE(intSpy.count(), 1); + QCOMPARE(intSpy.size(), 1); QQuickTextInput *dblInput = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("dblInput"))); QVERIFY(dblInput); @@ -2019,13 +2019,13 @@ void tst_qquicktextinput::validators() QTRY_COMPARE(dblInput->text(), QLatin1String("1")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 0); + QCOMPARE(dblSpy.size(), 0); QTest::keyPress(&window, Qt::Key_2); QTest::keyRelease(&window, Qt::Key_2, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12")); QCOMPARE(dblInput->hasAcceptableInput(), true); QCOMPARE(dblInput->property("acceptable").toBool(), true); - QCOMPARE(dblSpy.count(), 1); + QCOMPARE(dblSpy.size(), 1); QTest::keyPress(&window, Qt::Key_Comma); QTest::keyRelease(&window, Qt::Key_Comma, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12,")); @@ -2066,84 +2066,84 @@ void tst_qquicktextinput::validators() QTRY_COMPARE(dblInput->text(), QLatin1String("12.")); QCOMPARE(dblInput->hasAcceptableInput(), true); QCOMPARE(dblInput->property("acceptable").toBool(), true); - QCOMPARE(dblSpy.count(), 1 + extraSignals); + QCOMPARE(dblSpy.size(), 1 + extraSignals); QTest::keyPress(&window, Qt::Key_1); QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.1")); QCOMPARE(dblInput->hasAcceptableInput(), true); QCOMPARE(dblInput->property("acceptable").toBool(), true); - QCOMPARE(dblSpy.count(), 1 + extraSignals); + QCOMPARE(dblSpy.size(), 1 + extraSignals); QTest::keyPress(&window, Qt::Key_1); QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.11")); QCOMPARE(dblInput->hasAcceptableInput(), true); QCOMPARE(dblInput->property("acceptable").toBool(), true); - QCOMPARE(dblSpy.count(), 1 + extraSignals); + QCOMPARE(dblSpy.size(), 1 + extraSignals); QTest::keyPress(&window, Qt::Key_1); QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.11")); QCOMPARE(dblInput->hasAcceptableInput(), true); QCOMPARE(dblInput->property("acceptable").toBool(), true); - QCOMPARE(dblSpy.count(), 1 + extraSignals); + QCOMPARE(dblSpy.size(), 1 + extraSignals); // Ensure the validator doesn't prevent characters being removed. dblInput->setValidator(intInput->validator()); QCOMPARE(dblInput->text(), QLatin1String("12.11")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_Backspace); QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.1")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); // Once unacceptable input is in anything goes until it reaches an acceptable state again. QTest::keyPress(&window, Qt::Key_1); QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.11")); QCOMPARE(dblInput->hasAcceptableInput(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_Backspace); QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.1")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_Backspace); QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12.")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_Backspace); QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("12")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_Backspace); QTest::keyRelease(&window, Qt::Key_Backspace, Qt::NoModifier); QTRY_COMPARE(dblInput->text(), QLatin1String("1")); QCOMPARE(dblInput->hasAcceptableInput(), false); QCOMPARE(dblInput->property("acceptable").toBool(), false); - QCOMPARE(dblSpy.count(), 2 + extraSignals); + QCOMPARE(dblSpy.size(), 2 + extraSignals); QTest::keyPress(&window, Qt::Key_1); QTest::keyRelease(&window, Qt::Key_1, Qt::NoModifier); QCOMPARE(dblInput->text(), QLatin1String("11")); QCOMPARE(dblInput->property("acceptable").toBool(), true); QCOMPARE(dblInput->hasAcceptableInput(), true); - QCOMPARE(dblSpy.count(), 3 + extraSignals); + QCOMPARE(dblSpy.size(), 3 + extraSignals); // Changing the validator properties will re-evaluate whether the input is acceptable. intValidator->setTop(10); QCOMPARE(dblInput->property("acceptable").toBool(), false); QCOMPARE(dblInput->hasAcceptableInput(), false); - QCOMPARE(dblSpy.count(), 4 + extraSignals); + QCOMPARE(dblSpy.size(), 4 + extraSignals); intValidator->setTop(12); QCOMPARE(dblInput->property("acceptable").toBool(), true); QCOMPARE(dblInput->hasAcceptableInput(), true); - QCOMPARE(dblSpy.count(), 5 + extraSignals); + QCOMPARE(dblSpy.size(), 5 + extraSignals); QQuickTextInput *strInput = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("strInput"))); QVERIFY(strInput); @@ -2157,37 +2157,37 @@ void tst_qquicktextinput::validators() QTRY_COMPARE(strInput->text(), QLatin1String("")); QCOMPARE(strInput->hasAcceptableInput(), false); QCOMPARE(strInput->property("acceptable").toBool(), false); - QCOMPARE(strSpy.count(), 0); + QCOMPARE(strSpy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(strInput->text(), QLatin1String("a")); QCOMPARE(strInput->hasAcceptableInput(), false); QCOMPARE(strInput->property("acceptable").toBool(), false); - QCOMPARE(strSpy.count(), 0); + QCOMPARE(strSpy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(strInput->text(), QLatin1String("aa")); QCOMPARE(strInput->hasAcceptableInput(), true); QCOMPARE(strInput->property("acceptable").toBool(), true); - QCOMPARE(strSpy.count(), 1); + QCOMPARE(strSpy.size(), 1); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(strInput->text(), QLatin1String("aaa")); QCOMPARE(strInput->hasAcceptableInput(), true); QCOMPARE(strInput->property("acceptable").toBool(), true); - QCOMPARE(strSpy.count(), 1); + QCOMPARE(strSpy.size(), 1); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(strInput->text(), QLatin1String("aaaa")); QCOMPARE(strInput->hasAcceptableInput(), true); QCOMPARE(strInput->property("acceptable").toBool(), true); - QCOMPARE(strSpy.count(), 1); + QCOMPARE(strSpy.size(), 1); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(strInput->text(), QLatin1String("aaaa")); QCOMPARE(strInput->hasAcceptableInput(), true); QCOMPARE(strInput->property("acceptable").toBool(), true); - QCOMPARE(strSpy.count(), 1); + QCOMPARE(strSpy.size(), 1); QQuickTextInput *unvalidatedInput = qobject_cast<QQuickTextInput *>(qvariant_cast<QObject *>(window.rootObject()->property("unvalidatedInput"))); QVERIFY(unvalidatedInput); @@ -2201,13 +2201,13 @@ void tst_qquicktextinput::validators() QTRY_COMPARE(unvalidatedInput->text(), QLatin1String("1")); QCOMPARE(unvalidatedInput->hasAcceptableInput(), true); QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true); - QCOMPARE(unvalidatedSpy.count(), 0); + QCOMPARE(unvalidatedSpy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(unvalidatedInput->text(), QLatin1String("1a")); QCOMPARE(unvalidatedInput->hasAcceptableInput(), true); QCOMPARE(unvalidatedInput->property("acceptable").toBool(), true); - QCOMPARE(unvalidatedSpy.count(), 0); + QCOMPARE(unvalidatedSpy.size(), 0); } void tst_qquicktextinput::inputMethods() @@ -2225,9 +2225,9 @@ void tst_qquicktextinput::inputMethods() QSignalSpy inputMethodHintSpy(input, SIGNAL(inputMethodHintsChanged())); input->setInputMethodHints(Qt::ImhUppercaseOnly); QVERIFY(input->inputMethodHints() & Qt::ImhUppercaseOnly); - QCOMPARE(inputMethodHintSpy.count(), 1); + QCOMPARE(inputMethodHintSpy.size(), 1); input->setInputMethodHints(Qt::ImhUppercaseOnly); - QCOMPARE(inputMethodHintSpy.count(), 1); + QCOMPARE(inputMethodHintSpy.size(), 1); // default value QQuickTextInput plainInput; @@ -2286,8 +2286,8 @@ void tst_qquicktextinput::inputMethods() // input should reset selection even if replacement parameters are out of bounds input->setText("text"); input->setCursorPosition(0); - input->moveCursorSelection(input->text().length()); - event.setCommitString("replacement", -input->text().length(), input->text().length()); + input->moveCursorSelection(input->text().size()); + event.setCommitString("replacement", -input->text().size(), input->text().size()); QGuiApplication::sendEvent(input, &event); QCOMPARE(input->selectionStart(), input->selectionEnd()); QCOMPARE(input->text(), QString("replacement")); @@ -2326,22 +2326,22 @@ void tst_qquicktextinput::signal_accepted() QTRY_COMPARE(input->text(), QLatin1String("a")); QCOMPARE(input->hasAcceptableInput(), false); QCOMPARE(input->property("acceptable").toBool(), false); - QTRY_COMPARE(inputSpy.count(), 0); + QTRY_COMPARE(inputSpy.size(), 0); QTest::keyPress(&window, Qt::Key_Enter); QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier); - QTRY_COMPARE(acceptedSpy.count(), 0); + QTRY_COMPARE(acceptedSpy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(input->text(), QLatin1String("aa")); QCOMPARE(input->hasAcceptableInput(), true); QCOMPARE(input->property("acceptable").toBool(), true); - QTRY_COMPARE(inputSpy.count(), 1); + QTRY_COMPARE(inputSpy.size(), 1); QTest::keyPress(&window, Qt::Key_Enter); QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier); - QTRY_COMPARE(acceptedSpy.count(), 1); + QTRY_COMPARE(acceptedSpy.size(), 1); } void tst_qquicktextinput::signal_editingfinished() @@ -2369,23 +2369,23 @@ void tst_qquicktextinput::signal_editingfinished() QTRY_COMPARE(input1->text(), QLatin1String("a")); QCOMPARE(input1->hasAcceptableInput(), false); QCOMPARE(input1->property("acceptable").toBool(), false); - QTRY_COMPARE(input1Spy.count(), 0); + QTRY_COMPARE(input1Spy.size(), 0); QTest::keyPress(&window, Qt::Key_Enter); QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier); - QTRY_COMPARE(editingFinished1Spy.count(), 0); + QTRY_COMPARE(editingFinished1Spy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(input1->text(), QLatin1String("aa")); QCOMPARE(input1->hasAcceptableInput(), true); QCOMPARE(input1->property("acceptable").toBool(), true); - QTRY_COMPARE(input1Spy.count(), 1); + QTRY_COMPARE(input1Spy.size(), 1); QTest::keyPress(&window, Qt::Key_Enter); QTest::keyRelease(&window, Qt::Key_Enter, Qt::NoModifier); - QTRY_COMPARE(editingFinished1Spy.count(), 1); - QTRY_COMPARE(input1Spy.count(), 1); + QTRY_COMPARE(editingFinished1Spy.size(), 1); + QTRY_COMPARE(input1Spy.size(), 1); QSignalSpy editingFinished2Spy(input2, SIGNAL(editingFinished())); QSignalSpy input2Spy(input2, SIGNAL(acceptableInputChanged())); @@ -2399,19 +2399,19 @@ void tst_qquicktextinput::signal_editingfinished() QTRY_COMPARE(input2->text(), QLatin1String("a")); QCOMPARE(input2->hasAcceptableInput(), false); QCOMPARE(input2->property("acceptable").toBool(), false); - QTRY_COMPARE(input2Spy.count(), 0); + QTRY_COMPARE(input2Spy.size(), 0); QTest::keyPress(&window, Qt::Key_A); QTest::keyRelease(&window, Qt::Key_A, Qt::NoModifier); QTRY_COMPARE(input2->text(), QLatin1String("aa")); QCOMPARE(input2->hasAcceptableInput(), true); QCOMPARE(input2->property("acceptable").toBool(), true); - QTRY_COMPARE(input2Spy.count(), 1); + QTRY_COMPARE(input2Spy.size(), 1); input1->setFocus(true); QTRY_VERIFY(input1->hasActiveFocus()); QTRY_VERIFY(!input2->hasActiveFocus()); - QTRY_COMPARE(editingFinished2Spy.count(), 1); + QTRY_COMPARE(editingFinished2Spy.size(), 1); } void tst_qquicktextinput::signal_textEdited() @@ -2437,32 +2437,32 @@ void tst_qquicktextinput::signal_textEdited() int textEdits = 0; QTest::keyClick(&window, Qt::Key_A); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), ++textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), ++textEdits); QTest::keyClick(&window, Qt::Key_B); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), ++textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), ++textEdits); QTest::keyClick(&window, Qt::Key_C); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), ++textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), ++textEdits); QTest::keyClick(&window, Qt::Key_Space); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), ++textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), ++textEdits); QTest::keyClick(&window, Qt::Key_Backspace); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), ++textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), ++textEdits); input->clear(); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), textEdits); input->setText("TextInput"); - QCOMPARE(textChangedSpy.count(), ++textChanges); - QCOMPARE(textEditedSpy.count(), textEdits); + QCOMPARE(textChangedSpy.size(), ++textChanges); + QCOMPARE(textEditedSpy.size(), textEdits); } /* @@ -2488,12 +2488,12 @@ void tst_qquicktextinput::navigation() QTest::keyClick(&window, Qt::Key_Right); QVERIFY(input->hasActiveFocus()); //QT-2944: If text is selected, ensure we deselect upon cursor motion - input->setCursorPosition(input->text().length()); - input->select(0,input->text().length()); + input->setCursorPosition(input->text().size()); + input->select(0,input->text().size()); QVERIFY(input->selectionStart() != input->selectionEnd()); QTest::keyClick(&window, Qt::Key_Right); QCOMPARE(input->selectionStart(), input->selectionEnd()); - QCOMPARE(input->selectionStart(), input->text().length()); + QCOMPARE(input->selectionStart(), input->text().size()); QVERIFY(input->hasActiveFocus()); QTest::keyClick(&window, Qt::Key_Right); QVERIFY(!input->hasActiveFocus()); @@ -2544,7 +2544,7 @@ void tst_qquicktextinput::navigation_RTL() QTest::keyClick(&window, Qt::Key_Left); QVERIFY(input->hasActiveFocus()); - input->setCursorPosition(input->text().length()); + input->setCursorPosition(input->text().size()); QVERIFY(input->hasActiveFocus()); // move off @@ -2569,16 +2569,16 @@ void tst_qquicktextinput::copyAndPaste() QVERIFY(textInput != nullptr); // copy and paste - QCOMPARE(textInput->text().length(), 12); - textInput->select(0, textInput->text().length()); + QCOMPARE(textInput->text().size(), 12); + textInput->select(0, textInput->text().size()); textInput->copy(); QCOMPARE(textInput->selectedText(), QString("Hello world!")); - QCOMPARE(textInput->selectedText().length(), 12); + QCOMPARE(textInput->selectedText().size(), 12); textInput->setCursorPosition(0); QTRY_VERIFY(textInput->canPaste()); textInput->paste(); QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); - QCOMPARE(textInput->text().length(), 24); + QCOMPARE(textInput->text().size(), 24); // can paste QVERIFY(textInput->canPaste()); @@ -2586,7 +2586,7 @@ void tst_qquicktextinput::copyAndPaste() QVERIFY(!textInput->canPaste()); textInput->paste(); QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); - QCOMPARE(textInput->text().length(), 24); + QCOMPARE(textInput->text().size(), 24); textInput->setReadOnly(false); QVERIFY(textInput->canPaste()); @@ -2608,10 +2608,10 @@ void tst_qquicktextinput::copyAndPaste() // select all and cut textInput->selectAll(); textInput->cut(); - QCOMPARE(textInput->text().length(), 0); + QCOMPARE(textInput->text().size(), 0); textInput->paste(); QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); - QCOMPARE(textInput->text().length(), 24); + QCOMPARE(textInput->text().size(), 24); // Copy first word. textInput->setCursorPosition(0); @@ -2638,7 +2638,7 @@ void tst_qquicktextinput::copyAndPaste() QQuickTextInput::EchoMode echoMode = QQuickTextInput::EchoMode(index); textInput->setEchoMode(echoMode); textInput->setText("My password"); - textInput->select(0, textInput->text().length()); + textInput->select(0, textInput->text().size()); textInput->copy(); if (echoMode == QQuickTextInput::Normal) { QVERIFY(!clipboard->text().isEmpty()); @@ -2674,24 +2674,24 @@ void tst_qquicktextinput::copyAndPasteKeySequence() // copy and paste QVERIFY(textInput->hasActiveFocus()); - QCOMPARE(textInput->text().length(), 12); - textInput->select(0, textInput->text().length()); + QCOMPARE(textInput->text().size(), 12); + textInput->select(0, textInput->text().size()); simulateKeys(&window, QKeySequence::Copy); QCOMPARE(textInput->selectedText(), QString("Hello world!")); - QCOMPARE(textInput->selectedText().length(), 12); + QCOMPARE(textInput->selectedText().size(), 12); textInput->setCursorPosition(0); QVERIFY(textInput->canPaste()); simulateKeys(&window, QKeySequence::Paste); QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); - QCOMPARE(textInput->text().length(), 24); + QCOMPARE(textInput->text().size(), 24); // select all and cut simulateKeys(&window, QKeySequence::SelectAll); simulateKeys(&window, QKeySequence::Cut); - QCOMPARE(textInput->text().length(), 0); + QCOMPARE(textInput->text().size(), 0); simulateKeys(&window, QKeySequence::Paste); QCOMPARE(textInput->text(), QString("Hello world!Hello world!")); - QCOMPARE(textInput->text().length(), 24); + QCOMPARE(textInput->text().size(), 24); // clear copy buffer QClipboard *clipboard = QGuiApplication::clipboard(); @@ -2706,7 +2706,7 @@ void tst_qquicktextinput::copyAndPasteKeySequence() QQuickTextInput::EchoMode echoMode = QQuickTextInput::EchoMode(index); textInput->setEchoMode(echoMode); textInput->setText("My password"); - textInput->select(0, textInput->text().length()); + textInput->select(0, textInput->text().size()); simulateKeys(&window, QKeySequence::Copy); if (echoMode == QQuickTextInput::Normal) { QVERIFY(!clipboard->text().isEmpty()); @@ -2733,7 +2733,7 @@ void tst_qquicktextinput::canPasteEmpty() QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create()); QVERIFY(textInput != nullptr); - bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().length() != 0; + bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0; QCOMPARE(textInput->canPaste(), cp); } #endif @@ -2749,7 +2749,7 @@ void tst_qquicktextinput::canPaste() QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create()); QVERIFY(textInput != nullptr); - bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().length() != 0; + bool cp = !textInput->isReadOnly() && QGuiApplication::clipboard()->text().size() != 0; QCOMPARE(textInput->canPaste(), cp); } #endif @@ -2792,7 +2792,7 @@ void tst_qquicktextinput::middleClickPaste() QTest::qWait(QGuiApplication::styleHints()->mouseDoubleClickInterval() + 10); if (QGuiApplication::clipboard()->supportsSelection()) - QCOMPARE(textInputObject->text().mid(1, selectedText.length()), selectedText); + QCOMPARE(textInputObject->text().mid(1, selectedText.size()), selectedText); else QCOMPARE(textInputObject->text(), originalText); } @@ -2844,7 +2844,7 @@ void tst_qquicktextinput::cursorDelegate() QVERIFY(delegateObject); QCOMPARE(delegateObject->property("localProperty").toString(), QString("Hello")); //Test Delegate gets moved - for (int i=0; i<= textInputObject->text().length(); i++) { + for (int i=0; i<= textInputObject->text().size(); i++) { textInputObject->setCursorPosition(i); QCOMPARE(textInputObject->cursorRectangle().x(), delegateObject->x()); QCOMPARE(textInputObject->cursorRectangle().y(), delegateObject->y()); @@ -2982,27 +2982,27 @@ void tst_qquicktextinput::cursorVisible() input.setCursorVisible(true); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); input.setCursorVisible(false); QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); input.setFocus(true); QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); input.setParentItem(view.rootObject()); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); input.setFocus(false); QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); input.setFocus(true); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); QQuickView alternateView; alternateView.show(); @@ -3010,12 +3010,12 @@ void tst_qquicktextinput::cursorVisible() QVERIFY(QTest::qWaitForWindowActive(&alternateView)); QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); view.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&view)); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); { // Cursor attribute with 0 length hides cursor. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -3023,7 +3023,7 @@ void tst_qquicktextinput::cursorVisible() QCoreApplication::sendEvent(&input, &ev); } QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 8); + QCOMPARE(spy.size(), 8); { // Cursor attribute with non zero length shows cursor. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -3031,7 +3031,7 @@ void tst_qquicktextinput::cursorVisible() QCoreApplication::sendEvent(&input, &ev); } QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 9); + QCOMPARE(spy.size(), 9); { // If the cursor is hidden by the input method and the text is changed it should be visible again. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -3039,11 +3039,11 @@ void tst_qquicktextinput::cursorVisible() QCoreApplication::sendEvent(&input, &ev); } QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 10); + QCOMPARE(spy.size(), 10); input.setText("something"); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 11); + QCOMPARE(spy.size(), 11); { // If the cursor is hidden by the input method and the cursor position is changed it should be visible again. QInputMethodEvent ev(QString(), QList<QInputMethodEvent::Attribute>() @@ -3051,11 +3051,11 @@ void tst_qquicktextinput::cursorVisible() QCoreApplication::sendEvent(&input, &ev); } QCOMPARE(input.isCursorVisible(), false); - QCOMPARE(spy.count(), 12); + QCOMPARE(spy.size(), 12); input.setCursorPosition(5); QCOMPARE(input.isCursorVisible(), true); - QCOMPARE(spy.count(), 13); + QCOMPARE(spy.size(), 13); } void tst_qquicktextinput::cursorRectangle_data() @@ -3132,14 +3132,14 @@ void tst_qquicktextinput::cursorRectangle() // Check the cursor rectangle remains within the input bounding rect when auto scrolling. QCOMPARE(r.left(), leftToRight ? input.width() : 0); - for (int i = positionAtWidth + 1; i < text.length(); ++i) { + for (int i = positionAtWidth + 1; i < text.size(); ++i) { input.setCursorPosition(i); QCOMPARE(r, input.cursorRectangle()); COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(i), r); } - for (int i = text.length() - 2; i >= 0; --i) { + for (int i = text.size() - 2; i >= 0; --i) { input.setCursorPosition(i); r = input.cursorRectangle(); QCOMPARE(r.top(), 0.); @@ -3178,7 +3178,7 @@ void tst_qquicktextinput::cursorRectangle() COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); - for (int i = wrapPosition + 1; i < text.length(); ++i) { + for (int i = wrapPosition + 1; i < text.size(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.top() >= line.height() - 5); @@ -3219,7 +3219,7 @@ void tst_qquicktextinput::cursorRectangle() COMPARE_INPUT_METHOD_QUERY(QRectF, (&input), Qt::ImCursorRectangle, toRectF, r); QCOMPARE(input.positionToRectangle(11), r); - for (int i = wrapPosition + 1; i < text.length(); ++i) { + for (int i = wrapPosition + 1; i < text.size(); ++i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); @@ -3227,7 +3227,7 @@ void tst_qquicktextinput::cursorRectangle() QCOMPARE(input.positionToRectangle(i), r); } - for (int i = text.length() - 2; i >= wrapPosition; --i) { + for (int i = text.size() - 2; i >= wrapPosition; --i) { input.setCursorPosition(i); r = input.cursorRectangle(); QVERIFY(r.bottom() >= input.height()); @@ -3268,7 +3268,7 @@ void tst_qquicktextinput::cursorRectangle() widerText[1] = 'W'; // Assumes shortText is at least two characters long. input.setText(widerText); - QCOMPARE(cursorRectangleSpy.count(), 1); + QCOMPARE(cursorRectangleSpy.size(), 1); } void tst_qquicktextinput::readOnly() @@ -3296,7 +3296,7 @@ void tst_qquicktextinput::readOnly() input->setCursorPosition(3); input->setReadOnly(false); QCOMPARE(input->isReadOnly(), false); - QCOMPARE(input->cursorPosition(), input->text().length()); + QCOMPARE(input->cursorPosition(), input->text().size()); QVERIFY(input->isCursorVisible()); } @@ -3418,7 +3418,7 @@ void tst_qquicktextinput::passwordEchoDelay() QSignalSpy cursorSpy(input, SIGNAL(cursorRectangleChanged())); QTest::qWait(maskDelay); QTRY_COMPARE(input->displayText(), QString(5, fillChar)); - QCOMPARE(cursorSpy.count(), 1); + QCOMPARE(cursorSpy.size(), 1); QCOMPARE(input->cursorRectangle().topLeft(), cursor->position()); QTest::keyPress(&window, '5'); @@ -3469,7 +3469,7 @@ void tst_qquicktextinput::focusOnPress() textInputObject->setFocusOnPress(true); QCOMPARE(textInputObject->focusOnPress(), true); - QCOMPARE(activeFocusOnPressSpy.count(), 0); + QCOMPARE(activeFocusOnPressSpy.size(), 0); QQuickWindow window; window.resize(100, 50); @@ -3486,20 +3486,20 @@ void tst_qquicktextinput::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textInputObject->hasFocus(), true); QCOMPARE(textInputObject->hasActiveFocus(), true); - QCOMPARE(focusSpy.count(), 1); - QCOMPARE(activeFocusSpy.count(), 1); + QCOMPARE(focusSpy.size(), 1); + QCOMPARE(activeFocusSpy.size(), 1); QCOMPARE(textInputObject->selectedText(), QString()); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers); textInputObject->setFocusOnPress(false); QCOMPARE(textInputObject->focusOnPress(), false); - QCOMPARE(activeFocusOnPressSpy.count(), 1); + QCOMPARE(activeFocusOnPressSpy.size(), 1); textInputObject->setFocus(false); QCOMPARE(textInputObject->hasFocus(), false); QCOMPARE(textInputObject->hasActiveFocus(), false); - QCOMPARE(focusSpy.count(), 2); - QCOMPARE(activeFocusSpy.count(), 2); + QCOMPARE(focusSpy.size(), 2); + QCOMPARE(activeFocusSpy.size(), 2); // Wait for double click timeout to expire before clicking again. QTest::qWait(400); @@ -3507,13 +3507,13 @@ void tst_qquicktextinput::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textInputObject->hasFocus(), false); QCOMPARE(textInputObject->hasActiveFocus(), false); - QCOMPARE(focusSpy.count(), 2); - QCOMPARE(activeFocusSpy.count(), 2); + QCOMPARE(focusSpy.size(), 2); + QCOMPARE(activeFocusSpy.size(), 2); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers); textInputObject->setFocusOnPress(true); QCOMPARE(textInputObject->focusOnPress(), true); - QCOMPARE(activeFocusOnPressSpy.count(), 2); + QCOMPARE(activeFocusOnPressSpy.size(), 2); // Test a selection made in the on(Active)FocusChanged handler isn't overwritten. textInputObject->setProperty("selectOnFocus", true); @@ -3523,8 +3523,8 @@ void tst_qquicktextinput::focusOnPress() QGuiApplication::processEvents(); QCOMPARE(textInputObject->hasFocus(), true); QCOMPARE(textInputObject->hasActiveFocus(), true); - QCOMPARE(focusSpy.count(), 3); - QCOMPARE(activeFocusSpy.count(), 3); + QCOMPARE(focusSpy.size(), 3); + QCOMPARE(activeFocusSpy.size(), 3); QCOMPARE(textInputObject->selectedText(), textInputObject->text()); QTest::mouseRelease(&window, Qt::LeftButton, noModifiers); } @@ -3615,7 +3615,7 @@ void tst_qquicktextinput::openInputPanel() anotherInput.setFocus(true); QCOMPARE(qApp->inputMethod()->isVisible(), true); QCOMPARE(qApp->focusObject(), qobject_cast<QObject*>(&anotherInput)); - QCOMPARE(inputPanelVisibilitySpy.count(), 0); + QCOMPARE(inputPanelVisibilitySpy.size(), 0); anotherInput.setFocus(false); QVERIFY(qApp->focusObject() != &anotherInput); @@ -3764,18 +3764,18 @@ void tst_qquicktextinput::contentSize() QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() < textObject->height()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); textObject->setWrapMode(QQuickTextInput::WordWrap); QVERIFY(textObject->contentWidth() <= textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); textObject->setText("The quickredfoxjumpedoverthe lazy brown dog"); QVERIFY(textObject->contentWidth() > textObject->width()); QVERIFY(textObject->contentHeight() > textObject->height()); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); textObject->setText("The quick red fox jumped over the lazy brown dog"); for (int w = 60; w < 120; ++w) { @@ -3788,7 +3788,7 @@ void tst_qquicktextinput::contentSize() static void sendPreeditText(QQuickItem *item, const QString &text, int cursor) { QInputMethodEvent event(text, QList<QInputMethodEvent::Attribute>() - << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, text.length(), QVariant())); + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursor, text.size(), QVariant())); QCoreApplication::sendEvent(item, &event); } @@ -3813,14 +3813,14 @@ void tst_qquicktextinput::preeditAutoScroll() sendPreeditText(input, preeditText.mid(0, 3), 1); QVERIFY(evaluate<int>(input, QString("positionAt(0)")) != 0); QVERIFY(input->cursorRectangle().left() < input->boundingRect().width()); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); // test the text is scrolled back when the preedit is removed. QInputMethodEvent imEvent; QCoreApplication::sendEvent(input, &imEvent); QCOMPARE(evaluate<int>(input, QString("positionAt(%1)").arg(0)), 0); QCOMPARE(evaluate<int>(input, QString("positionAt(%1)").arg(input->width())), 5); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); QTextLayout layout(preeditText); layout.setFont(input->font()); @@ -3841,7 +3841,7 @@ void tst_qquicktextinput::preeditAutoScroll() int width = ceil(line.cursorToX(i, QTextLine::Trailing)) - floor(line.cursorToX(i)); QVERIFY(input->cursorRectangle().right() >= width - 3); QVERIFY(input->positionToRectangle(0).x() < x); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); x = input->positionToRectangle(0).x(); } for (int i = 1; i >= 0; --i) { @@ -3849,24 +3849,24 @@ void tst_qquicktextinput::preeditAutoScroll() int width = ceil(line.cursorToX(i, QTextLine::Trailing)) - floor(line.cursorToX(i)); QVERIFY(input->cursorRectangle().right() >= width - 3); QVERIFY(input->positionToRectangle(0).x() > x); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); x = input->positionToRectangle(0).x(); } // Test incrementing the preedit cursor doesn't cause further // scrolling when right most text is visible. - sendPreeditText(input, preeditText, preeditText.length() - 3); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + sendPreeditText(input, preeditText, preeditText.size() - 3); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); x = input->positionToRectangle(0).x(); for (int i = 2; i >= 0; --i) { - sendPreeditText(input, preeditText, preeditText.length() - i); + sendPreeditText(input, preeditText, preeditText.size() - i); QCOMPARE(input->positionToRectangle(0).x(), x); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); } for (int i = 1; i < 3; ++i) { - sendPreeditText(input, preeditText, preeditText.length() - i); + sendPreeditText(input, preeditText, preeditText.size() - i); QCOMPARE(input->positionToRectangle(0).x(), x); - QCOMPARE(cursorRectangleSpy.count(), ++cursorRectangleChanges); + QCOMPARE(cursorRectangleSpy.size(), ++cursorRectangleChanges); } // Test disabling auto scroll. @@ -3920,8 +3920,8 @@ void tst_qquicktextinput::preeditCursorRectangle() QVERIFY(previousRect.left() < currentRect.left()); QCOMPARE(input->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); - QVERIFY(inputSpy.count() > 0); inputSpy.clear(); - QVERIFY(panelSpy.count() > 0); panelSpy.clear(); + QVERIFY(inputSpy.size() > 0); inputSpy.clear(); + QVERIFY(panelSpy.size() > 0); panelSpy.clear(); previousRect = currentRect; } @@ -3934,8 +3934,8 @@ void tst_qquicktextinput::preeditCursorRectangle() currentRect = query.value(Qt::ImCursorRectangle).toRectF(); QCOMPARE(input->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); - QCOMPARE(inputSpy.count(), 1); - QCOMPARE(panelSpy.count(), 1); + QCOMPARE(inputSpy.size(), 1); + QCOMPARE(panelSpy.size(), 1); // Verify that if there is no preedit cursor then the micro focus rect is the // same as it would be if it were positioned at the end of the preedit text. @@ -3948,8 +3948,8 @@ void tst_qquicktextinput::preeditCursorRectangle() QCOMPARE(currentRect, previousRect); QCOMPARE(input->cursorRectangle(), currentRect); QCOMPARE(cursor->position(), currentRect.topLeft()); - QCOMPARE(inputSpy.count(), 1); - QCOMPARE(panelSpy.count(), 1); + QCOMPARE(inputSpy.size(), 1); + QCOMPARE(panelSpy.size(), 1); } void tst_qquicktextinput::inputContextMouseHandler() @@ -4016,37 +4016,37 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); { QInputMethodEvent event(text.mid(12), QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(input, &event); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); { QInputMethodEvent event; QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); // Changing the text while not composing doesn't alter the composing state. input->setText(text.mid(0, 16)); QCOMPARE(input->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); { QInputMethodEvent event(text.mid(16), QList<QInputMethodEvent::Attribute>()); QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); // Changing the text while composing cancels composition. input->setText(text.mid(0, 12)); QCOMPARE(input->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); { // Preedit cursor positioned outside (empty) preedit; composing. QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4054,7 +4054,7 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Cursor hidden; composing @@ -4063,7 +4063,7 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Default cursor attributes; composing. QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4071,7 +4071,7 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); { // Selections are persisted: not composing QInputMethodEvent event(QString(), QList<QInputMethodEvent::Attribute>() @@ -4079,7 +4079,7 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); input->setCursorPosition(12); @@ -4091,14 +4091,14 @@ void tst_qquicktextinput::inputMethodComposing() QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), true); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); { QInputMethodEvent event; QGuiApplication::sendEvent(input, &event); } QCOMPARE(input->isInputMethodComposing(), false); - QCOMPARE(spy.count(), 8); + QCOMPARE(spy.size(), 8); } void tst_qquicktextinput::inputMethodUpdate() @@ -4285,7 +4285,7 @@ void tst_qquicktextinput::getText_data() QTest::newRow("all plain text") << standard.at(0) << QString() - << 0 << standard.at(0).length() + << 0 << standard.at(0).size() << standard.at(0); QTest::newRow("plain text sub string") @@ -4309,13 +4309,13 @@ void tst_qquicktextinput::getText_data() QTest::newRow("plain text cropped end") << standard.at(0) << QString() - << 23 << standard.at(0).length() + 8 + << 23 << standard.at(0).size() + 8 << standard.at(0).mid(23); QTest::newRow("plain text cropped beginning and end") << standard.at(0) << QString() - << -9 << standard.at(0).length() + 4 + << -9 << standard.at(0).size() + 4 << standard.at(0); } @@ -4363,10 +4363,10 @@ void tst_qquicktextinput::insert_data() QTest::newRow("at cursor position (end)") << standard.at(0) << QString() - << standard.at(0).length() << standard.at(0).length() << standard.at(0).length() + << standard.at(0).size() << standard.at(0).size() << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") - << standard.at(0).length() + 5 << standard.at(0).length() + 5 << standard.at(0).length() + 5 + << standard.at(0).size() + 5 << standard.at(0).size() + 5 << standard.at(0).size() + 5 << false << true; QTest::newRow("at cursor position (middle)") @@ -4390,10 +4390,10 @@ void tst_qquicktextinput::insert_data() QTest::newRow("before cursor position (end)") << standard.at(0) << QString() - << standard.at(0).length() << standard.at(0).length() << 18 + << standard.at(0).size() << standard.at(0).size() << 18 << QString("Hello") << standard.at(0).mid(0, 18) + QString("Hello") + standard.at(0).mid(18) - << standard.at(0).length() + 5 << standard.at(0).length() + 5 << standard.at(0).length() + 5 + << standard.at(0).size() + 5 << standard.at(0).size() + 5 << standard.at(0).size() + 5 << false << true; QTest::newRow("before cursor position (middle)") @@ -4408,7 +4408,7 @@ void tst_qquicktextinput::insert_data() QTest::newRow("after cursor position (middle)") << standard.at(0) << QString() - << 18 << 18 << standard.at(0).length() + << 18 << 18 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 18 << 18 << 18 @@ -4435,7 +4435,7 @@ void tst_qquicktextinput::insert_data() QTest::newRow("after selection") << standard.at(0) << QString() - << 14 << 19 << standard.at(0).length() + << 14 << 19 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 14 << 19 << 19 @@ -4444,7 +4444,7 @@ void tst_qquicktextinput::insert_data() QTest::newRow("after reversed selection") << standard.at(0) << QString() - << 19 << 14 << standard.at(0).length() + << 19 << 14 << standard.at(0).size() << QString("Hello") << standard.at(0) + QString("Hello") << 14 << 19 << 14 @@ -4489,7 +4489,7 @@ void tst_qquicktextinput::insert_data() QTest::newRow("past end") << standard.at(0) << QString() - << 0 << 0 << standard.at(0).length() + 3 + << 0 << 0 << standard.at(0).size() + 3 << QString("Hello") << standard.at(0) << 0 << 0 << 0 @@ -4510,10 +4510,10 @@ void tst_qquicktextinput::insert_data() QTest::newRow("mask: at cursor position (end)") << ip << inputMask - << inputMask.length() << inputMask.length() << inputMask.length() + << inputMask.size() << inputMask.size() << inputMask.size() << QString("8") << ip - << inputMask.length() << inputMask.length() << inputMask.length() + << inputMask.size() << inputMask.size() << inputMask.size() << false << false; QTest::newRow("mask: at cursor position (middle)") @@ -4537,10 +4537,10 @@ void tst_qquicktextinput::insert_data() QTest::newRow("mask: before cursor position (end)") << ip << inputMask - << inputMask.length() << inputMask.length() << 6 + << inputMask.size() << inputMask.size() << 6 << QString("75.2") << QString("192.167.5.24") - << inputMask.length() << inputMask.length() << inputMask.length() + << inputMask.size() << inputMask.size() << inputMask.size() << false << false; QTest::newRow("mask: before cursor position (middle)") @@ -4627,7 +4627,7 @@ void tst_qquicktextinput::insert_data() QTest::newRow("mask: past end") << ip << inputMask - << 0 << 0 << ip.length() + 3 + << 0 << 0 << ip.size() + 3 << QString("4") << ip << 0 << 0 << 0 @@ -4684,7 +4684,7 @@ void tst_qquicktextinput::insert() textInput->insert(insertPosition, insertText); QCOMPARE(textInput->text(), expectedText); - QCOMPARE(textInput->length(), inputMask.isEmpty() ? expectedText.length() : inputMask.length()); + QCOMPARE(textInput->length(), inputMask.isEmpty() ? expectedText.size() : inputMask.size()); QCOMPARE(textInput->selectionStart(), expectedSelectionStart); QCOMPARE(textInput->selectionEnd(), expectedSelectionEnd); @@ -4693,11 +4693,11 @@ void tst_qquicktextinput::insert() if (selectionStart > selectionEnd) qSwap(selectionStart, selectionEnd); - QCOMPARE(selectionSpy.count() > 0, selectionChanged); - QCOMPARE(selectionStartSpy.count() > 0, selectionStart != expectedSelectionStart); - QCOMPARE(selectionEndSpy.count() > 0, selectionEnd != expectedSelectionEnd); - QCOMPARE(textSpy.count() > 0, text != expectedText); - QCOMPARE(cursorPositionSpy.count() > 0, cursorPositionChanged); + QCOMPARE(selectionSpy.size() > 0, selectionChanged); + QCOMPARE(selectionStartSpy.size() > 0, selectionStart != expectedSelectionStart); + QCOMPARE(selectionEndSpy.size() > 0, selectionEnd != expectedSelectionEnd); + QCOMPARE(textSpy.size() > 0, text != expectedText); + QCOMPARE(cursorPositionSpy.size() > 0, cursorPositionChanged); } void tst_qquicktextinput::remove_data() @@ -4736,19 +4736,19 @@ void tst_qquicktextinput::remove_data() QTest::newRow("to cursor position (end)") << standard.at(0) << QString() - << standard.at(0).length() << standard.at(0).length() - << standard.at(0).length() << standard.at(0).length() - 5 - << standard.at(0).mid(0, standard.at(0).length() - 5) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() << standard.at(0).size() + << standard.at(0).size() << standard.at(0).size() - 5 + << standard.at(0).mid(0, standard.at(0).size() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("to cursor position (end)") << standard.at(0) << QString() - << standard.at(0).length() << standard.at(0).length() - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() << standard.at(0).size() + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("from cursor position (middle)") @@ -4781,10 +4781,10 @@ void tst_qquicktextinput::remove_data() QTest::newRow("before cursor position (end)") << standard.at(0) << QString() - << standard.at(0).length() << standard.at(0).length() + << standard.at(0).size() << standard.at(0).size() << 18 << 23 << standard.at(0).mid(0, 18) + standard.at(0).mid(23) - << standard.at(0).length() - 5 << standard.at(0).length() - 5 << standard.at(0).length() - 5 + << standard.at(0).size() - 5 << standard.at(0).size() - 5 << standard.at(0).size() - 5 << false << true; QTest::newRow("before cursor position (middle)") @@ -4827,8 +4827,8 @@ void tst_qquicktextinput::remove_data() << standard.at(0) << QString() << 14 << 19 - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) << 14 << 19 << 19 << false << false; @@ -4836,8 +4836,8 @@ void tst_qquicktextinput::remove_data() << standard.at(0) << QString() << 19 << 14 - << standard.at(0).length() - 5 << standard.at(0).length() - << standard.at(0).mid(0, standard.at(0).length() - 5) + << standard.at(0).size() - 5 << standard.at(0).size() + << standard.at(0).mid(0, standard.at(0).size() - 5) << 14 << 19 << 14 << false << false; @@ -4872,7 +4872,7 @@ void tst_qquicktextinput::remove_data() << standard.at(0) << QString() << 0 << 0 - << 23 << standard.at(0).length() + 8 + << 23 << standard.at(0).size() + 8 << standard.at(0).mid(0, 23) << 0 << 0 << 0 << false << false; @@ -4881,7 +4881,7 @@ void tst_qquicktextinput::remove_data() << standard.at(0) << QString() << 0 << 0 - << -9 << standard.at(0).length() + 4 + << -9 << standard.at(0).size() + 4 << QString() << 0 << 0 << 0 << false << false; @@ -5039,7 +5039,7 @@ void tst_qquicktextinput::remove() textInput->remove(removeStart, removeEnd); QCOMPARE(textInput->text(), expectedText); - QCOMPARE(textInput->length(), inputMask.isEmpty() ? expectedText.length() : inputMask.length()); + QCOMPARE(textInput->length(), inputMask.isEmpty() ? expectedText.size() : inputMask.size()); if (selectionStart > selectionEnd) // qSwap(selectionStart, selectionEnd); @@ -5048,13 +5048,13 @@ void tst_qquicktextinput::remove() QCOMPARE(textInput->selectionEnd(), expectedSelectionEnd); QCOMPARE(textInput->cursorPosition(), expectedCursorPosition); - QCOMPARE(selectionSpy.count() > 0, selectionChanged); - QCOMPARE(selectionStartSpy.count() > 0, selectionStart != expectedSelectionStart); - QCOMPARE(selectionEndSpy.count() > 0, selectionEnd != expectedSelectionEnd); - QCOMPARE(textSpy.count() > 0, text != expectedText); + QCOMPARE(selectionSpy.size() > 0, selectionChanged); + QCOMPARE(selectionStartSpy.size() > 0, selectionStart != expectedSelectionStart); + QCOMPARE(selectionEndSpy.size() > 0, selectionEnd != expectedSelectionEnd); + QCOMPARE(textSpy.size() > 0, text != expectedText); if (cursorPositionChanged) // - QVERIFY(cursorPositionSpy.count() > 0); + QVERIFY(cursorPositionSpy.size() > 0); } #if QT_CONFIG(shortcut) @@ -5414,11 +5414,11 @@ void tst_qquicktextinput::undo() // QTest::keyClick(testWidget, Qt::Key_End, Qt::ShiftModifier); } - for (int j = 0; j < insertString.at(i).length(); j++) + for (int j = 0; j < insertString.at(i).size(); j++) QTest::keyClick(&window, insertString.at(i).at(j).toLatin1()); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // STEP 2: Next call undo several times and see if we can restore to the previous state for (i = 0; i < expectedString.size() - 1; ++i) { @@ -5430,7 +5430,7 @@ void tst_qquicktextinput::undo() // STEP 3: Verify that we have undone everything QVERIFY(textInput->text().isEmpty()); QVERIFY(!textInput->canUndo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_qquicktextinput::redo_data() @@ -5491,13 +5491,13 @@ void tst_qquicktextinput::redo() for (i = 0; i < insertString.size(); ++i) { if (insertIndex[i] > -1) textInput->setCursorPosition(insertIndex[i]); - for (int j = 0; j < insertString.at(i).length(); j++) + for (int j = 0; j < insertString.at(i).size(); j++) QTest::keyClick(&window, insertString.at(i).at(j).toLatin1()); QVERIFY(textInput->canUndo()); QVERIFY(!textInput->canRedo()); } - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // undo everything while (!textInput->text().isEmpty()) { @@ -5506,7 +5506,7 @@ void tst_qquicktextinput::redo() QVERIFY(textInput->canRedo()); } - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); for (i = 0; i < expectedString.size(); ++i) { QVERIFY(textInput->canRedo()); @@ -5515,7 +5515,7 @@ void tst_qquicktextinput::redo() QVERIFY(textInput->canUndo()); } QVERIFY(!textInput->canRedo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } #if QT_CONFIG(shortcut) @@ -5849,12 +5849,12 @@ void tst_qquicktextinput::clear() textInput->clear(); QVERIFY(textInput->text().isEmpty()); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); // checks that clears can be undone textInput->undo(); QVERIFY(!textInput->canUndo()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); QCOMPARE(textInput->text(), QString("I am Legend")); textInput->setCursorPosition(4); @@ -5868,12 +5868,12 @@ void tst_qquicktextinput::clear() QVERIFY(textInput->text().isEmpty()); QVERIFY2(textInput->preeditText().isEmpty(), "Pre-edit text must be empty after clear"); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); // checks that clears can be undone textInput->undo(); QVERIFY(!textInput->canUndo()); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); QCOMPARE(textInput->text(), QString("I am Legend")); QVERIFY2(textInput->preeditText().isEmpty(), "Pre-edit text must be empty after undo"); } @@ -5890,7 +5890,7 @@ void tst_qquicktextinput::backspaceSurrogatePairs() QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(textInputComponent.create()); QVERIFY(textInput != nullptr); textInput->setText(text); - textInput->setCursorPosition(text.length()); + textInput->setCursorPosition(text.size()); QQuickWindow window; textInput->setParentItem(window.contentItem()); @@ -5899,7 +5899,7 @@ void tst_qquicktextinput::backspaceSurrogatePairs() QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(QGuiApplication::focusWindow(), &window); - for (int i = text.length(); i >= 0; i -= 2) { + for (int i = text.size(); i >= 0; i -= 2) { QCOMPARE(textInput->text(), text.mid(0, i)); QTest::keyClick(&window, Qt::Key_Backspace, Qt::NoModifier); } @@ -5908,7 +5908,7 @@ void tst_qquicktextinput::backspaceSurrogatePairs() textInput->setText(text); textInput->setCursorPosition(0); - for (int i = 0; i < text.length(); i += 2) { + for (int i = 0; i < text.size(); i += 2) { QCOMPARE(textInput->text(), text.mid(i)); QTest::keyClick(&window, Qt::Key_Delete, Qt::NoModifier); } @@ -6397,7 +6397,7 @@ void tst_qquicktextinput::setInputMask() unescapedMask.replace(QLatin1String("\\\\"), QLatin1String("\\")); // simple unescape QSignalSpy spy(textInput, SIGNAL(inputMaskChanged(const QString &))); textInput->setInputMask(unescapedMask); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // then either insert using insert() or keyboard if (insert_text) { @@ -6411,7 +6411,7 @@ void tst_qquicktextinput::setInputMask() QVERIFY(textInput->hasActiveFocus()); QTest::keyClick(&window, Qt::Key_Home); - for (int i = 0; i < input.length(); i++) + for (int i = 0; i < input.size(); i++) QTest::keyClick(&window, input.at(i).toLatin1()); } @@ -6891,7 +6891,7 @@ void tst_qquicktextinput::ensureVisible() input->ensureVisible(input->length()); - QCOMPARE(cursorSpy.count(), 1); + QCOMPARE(cursorSpy.size(), 1); QCOMPARE(input->boundingRect().x(), input->width() - line.naturalTextWidth()); QCOMPARE(input->boundingRect().y(), qreal(0)); @@ -7167,13 +7167,13 @@ void tst_qquicktextinput::touchscreenSetsFocusAndMovesCursor() QQuickTouchUtils::flush(&window); QCOMPARE(qApp->focusObject(), bottom); // text cursor is at the end by default, on press - const auto len = bottom->text().length(); + const auto len = bottom->text().size(); QCOMPARE(bottom->cursorPosition(), len); // so typing a character appends it QVERIFY(!bottom->text().endsWith('q')); QTest::keyClick(&window, Qt::Key_Q); QVERIFY(bottom->text().endsWith('q')); - QCOMPARE(bottom->text().length(), len + 1); + QCOMPARE(bottom->text().size(), len + 1); QTest::touchEvent(&window, touchscreen.data()).release(0, QPoint(x1,y), &window); QQuickTouchUtils::flush(&window); // the cursor gets moved on release, as long as TextInput's grab wasn't stolen (e.g. by Flickable) diff --git a/tests/auto/quick/qquicktreeview/testmodel.cpp b/tests/auto/quick/qquicktreeview/testmodel.cpp index 50e326e108..9962234a06 100644 --- a/tests/auto/quick/qquicktreeview/testmodel.cpp +++ b/tests/auto/quick/qquicktreeview/testmodel.cpp @@ -38,8 +38,14 @@ void TestModel::createTreeRecursive(TreeItem *item, int childCount, int currentD for (int col = 0; col < m_columnCount; ++col) childItem->m_entries << QVariant(QString("%1, %2").arg(row).arg(col)); item->m_childItems.append(childItem); - if (row == childCount - 1) + if (row == childCount - 2 && currentDepth != maxDepth()) { + // Add a branch that doesn't recurse + createTreeRecursive(childItem, childCount, maxDepth()); + } + if (row == childCount - 1) { + // Add a branch that recurses createTreeRecursive(childItem, childCount, currentDepth + 1); + } } } @@ -54,7 +60,7 @@ int TestModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) return 1; // root of the tree - return treeItem(parent)->m_childItems.count(); + return treeItem(parent)->m_childItems.size(); } int TestModel::columnCount(const QModelIndex &) const diff --git a/tests/auto/quick/qquicktreeview/testmodel.h b/tests/auto/quick/qquicktreeview/testmodel.h index e35a6e4f6a..4cb80d0eab 100644 --- a/tests/auto/quick/qquicktreeview/testmodel.h +++ b/tests/auto/quick/qquicktreeview/testmodel.h @@ -45,4 +45,6 @@ private: int m_columnCount = 5; }; +#define TestModelAsVariant(...) QVariant::fromValue(QSharedPointer<TestModel>(new TestModel(__VA_ARGS__))) + #endif // TESTMODEL_H diff --git a/tests/auto/quick/qquicktreeview/tst_qquicktreeview.cpp b/tests/auto/quick/qquicktreeview/tst_qquicktreeview.cpp index 1a775ed3c7..71aa10a518 100644 --- a/tests/auto/quick/qquicktreeview/tst_qquicktreeview.cpp +++ b/tests/auto/quick/qquicktreeview/tst_qquicktreeview.cpp @@ -79,6 +79,10 @@ private slots: void selectionBehaviorRows(); void selectionBehaviorColumns(); void selectionBehaviorDisabled(); + void sortTreeModel_data(); + void sortTreeModel(); + void sortTreeModelDynamic_data(); + void sortTreeModelDynamic(); }; tst_qquicktreeview::tst_qquicktreeview() @@ -136,7 +140,7 @@ void tst_qquicktreeview::expandAndCollapseRoot() // Expand the root treeView->expand(0); - QCOMPARE(expandedSpy.count(), 1); + QCOMPARE(expandedSpy.size(), 1); auto signalArgs = expandedSpy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == 0); QVERIFY(signalArgs.at(1).toInt() == 1); @@ -186,7 +190,7 @@ void tst_qquicktreeview::expandAndCollapseChildren() treeView->expand(nodeToExpand); - QCOMPARE(expandedSpy.count(), 1); + QCOMPARE(expandedSpy.size(), 1); auto signalArgs = expandedSpy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == nodeToExpand); QVERIFY(signalArgs.at(1).toInt() == 1); @@ -297,7 +301,7 @@ void tst_qquicktreeview::requiredPropertiesChildren() QCOMPARE(viewProp, treeView); QCOMPARE(isTreeNode, true); QCOMPARE(expanded, row == 4); - QCOMPARE(hasChildren, row == 4 || row == 8); + QCOMPARE(hasChildren, model->hasChildren(treeView->index(row, 0))); QCOMPARE(depth, row <= 4 ? 1 : 2); } } @@ -310,7 +314,7 @@ void tst_qquicktreeview::emptyModel() treeView->setModel(QVariant()); WAIT_UNTIL_POLISHED; - QCOMPARE(treeViewPrivate->loadedItems.count(), 0); + QCOMPARE(treeViewPrivate->loadedItems.size(), 0); QCOMPARE(treeView->rows(), 0); QCOMPARE(treeView->columns(), 0); @@ -320,7 +324,7 @@ void tst_qquicktreeview::emptyModel() QCOMPARE(treeView->depth(0), -1); QCOMPARE(treeView->isExpanded(0), false); - QVERIFY(!treeView->modelIndex(10, 10).isValid()); + QVERIFY(!treeView->index(10, 10).isValid()); QCOMPARE(treeView->rowAtIndex(QModelIndex()), -1); QCOMPARE(treeView->columnAtIndex(QModelIndex()), -1); } @@ -431,10 +435,10 @@ void tst_qquicktreeview::expandRecursivelyRoot() treeView->expandRecursively(rowToExpand, depth); if (depth == 0) { - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } else { - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); const auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == rowToExpand); QVERIFY(signalArgs.at(1).toInt() == depth); @@ -453,7 +457,7 @@ void tst_qquicktreeview::expandRecursivelyRoot() // Check that all rows after rowToExpand, that are also // children of that row, is expanded (down to depth) for (int currentRow = rowToExpand + 1; currentRow < treeView->rows(); ++currentRow) { - const auto modelIndex = treeView->modelIndex(0, currentRow); + const auto modelIndex = treeView->index(currentRow, 0); const int currentDepth = treeView->depth(currentRow); const bool isChild = currentDepth > rowToExpandDepth; const bool isExpandable = model->rowCount(modelIndex) > 0; @@ -487,7 +491,7 @@ void tst_qquicktreeview::expandRecursivelyChild() treeView->expand(0); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == 0); QVERIFY(signalArgs.at(1).toInt() == 1); @@ -495,9 +499,9 @@ void tst_qquicktreeview::expandRecursivelyChild() treeView->expandRecursively(rowToExpand, depth); if (depth == 0) { - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); } else { - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == rowToExpand); QVERIFY(signalArgs.at(1).toInt() == depth); @@ -508,7 +512,7 @@ void tst_qquicktreeview::expandRecursivelyChild() const bool rowToExpandDepth = treeView->depth(rowToExpand); const int effectiveMaxDepth = depth != -1 ? rowToExpandDepth + depth : model->maxDepth(); - // Check that all rows before rowToExpand is not expanded + // Check that none of the rows before rowToExpand are expanded // (except the root node) for (int currentRow = 1; currentRow < rowToExpand; ++currentRow) QVERIFY(!treeView->isExpanded(currentRow)); @@ -519,12 +523,12 @@ void tst_qquicktreeview::expandRecursivelyChild() else QVERIFY(!treeView->isExpanded(rowToExpand)); - // Check that all rows after rowToExpand that is also - // children of that row is expanded (down to depth) + // Check that any row after rowToExpand, that is also + // a child of that row, is expanded (down to depth) for (int currentRow = rowToExpand + 1; currentRow < treeView->rows(); ++currentRow) { const int currentDepth = treeView->depth(currentRow); const bool isChild = currentDepth > rowToExpandDepth; - const auto modelIndex = treeView->modelIndex(0, currentRow); + const auto modelIndex = treeView->index(currentRow, 0); const bool isExpandable = model->rowCount(modelIndex) > 0; const bool shouldBeExpanded = isChild && isExpandable && currentDepth < effectiveMaxDepth; QCOMPARE(treeView->isExpanded(currentRow), shouldBeExpanded); @@ -538,7 +542,7 @@ void tst_qquicktreeview::expandRecursivelyWholeTree() QSignalSpy spy(treeView, SIGNAL(expanded(int, int))); treeView->expandRecursively(-1, -1); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == -1); QVERIFY(signalArgs.at(1).toInt() == -1); @@ -547,7 +551,7 @@ void tst_qquicktreeview::expandRecursivelyWholeTree() // Check that all rows that have children are expanded for (int currentRow = 0; currentRow < treeView->rows(); ++currentRow) { - const auto modelIndex = treeView->modelIndex(0, currentRow); + const auto modelIndex = treeView->index(currentRow, 0); const bool isExpandable = model->rowCount(modelIndex) > 0; QCOMPARE(treeView->isExpanded(currentRow), isExpandable); } @@ -562,7 +566,9 @@ void tst_qquicktreeview::collapseRecursivelyRoot() WAIT_UNTIL_POLISHED; // Verify that the tree is now fully expanded - const int expectedRowCount = 1 + (model->maxDepth() * 4); // root + 4 children per level + // The number of rows should be the root, + 4 children per level. All parents + // (minus the root), will also have a node with 4 non-recursive children. + const int expectedRowCount = 1 + (model->maxDepth() * 8) - 4; QCOMPARE(treeView->rows(), expectedRowCount); QSignalSpy spy(treeView, SIGNAL(collapsed(int, bool))); @@ -570,7 +576,7 @@ void tst_qquicktreeview::collapseRecursivelyRoot() // Collapse the whole tree again. This time, only the root should end up visible treeView->collapseRecursively(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); const auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == -1); QVERIFY(signalArgs.at(1).toBool() == true); @@ -585,7 +591,7 @@ void tst_qquicktreeview::collapseRecursivelyRoot() // We can do that by simply iterate over the rows in the view as we expand. int currentRow = 0; while (currentRow < treeView->rows()) { - const QModelIndex currentIndex = treeView->modelIndex(0, currentRow); + const QModelIndex currentIndex = treeView->index(currentRow, 0); if (model->hasChildren(currentIndex)) { QVERIFY(!treeView->isExpanded(currentRow)); treeView->expand(currentRow); @@ -607,24 +613,28 @@ void tst_qquicktreeview::collapseRecursivelyChild() WAIT_UNTIL_POLISHED; // Verify that the tree is now fully expanded - const int expectedRowCount = 1 + (model->maxDepth() * 4); // root + 4 children per level + // The number of rows should be the root, + 4 children per level. All parents + // (minus the root), will also have a node with 4 non-recursive children. + const int expectedRowCount = 1 + (model->maxDepth() * 8) - 4; QCOMPARE(treeView->rows(), expectedRowCount); QSignalSpy spy(treeView, SIGNAL(collapsed(int, bool))); - // Collapse the 4th child recursive - const int rowToCollapse = 4; - QCOMPARE(model->data(treeView->modelIndex(0, rowToCollapse), Qt::DisplayRole), QStringLiteral("3, 0")); + // Collapse the 8th child recursive + const int rowToCollapse = 8; + const QModelIndex collapseIndex = treeView->index(rowToCollapse, 0); + const auto expectedLabel = model->data(collapseIndex, Qt::DisplayRole); + QCOMPARE(expectedLabel, QStringLiteral("3, 0")); treeView->collapseRecursively(rowToCollapse); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); const auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == rowToCollapse); QVERIFY(signalArgs.at(1).toBool() == true); WAIT_UNTIL_POLISHED; - QCOMPARE(treeView->rows(), 5); // root + 4 children + QCOMPARE(treeView->rows(), 9); // root + 4 children + 4 grand children of the 3rd row // We need to check that all descendants are collapsed as well. But since they're // now no longer visible in the view, we need to expand each parent one by one again to make @@ -632,11 +642,17 @@ void tst_qquicktreeview::collapseRecursivelyChild() // We can do that by simply iterate over the rows in the view as we expand. int currentRow = 1; // start at first child while (currentRow < treeView->rows()) { - const QModelIndex currentIndex = treeView->modelIndex(0, currentRow); + const QModelIndex currentIndex = treeView->index(currentRow, 0); if (model->hasChildren(currentIndex)) { - QVERIFY(!treeView->isExpanded(currentRow)); - treeView->expand(currentRow); - WAIT_UNTIL_POLISHED; + if (treeView->depth(currentRow) == 1 && currentIndex.row() == 2) { + // We did only recursively expand the 4th child, so the + // third should still be expanded + QVERIFY(treeView->isExpanded(currentRow)); + } else { + QVERIFY(!treeView->isExpanded(currentRow)); + treeView->expand(currentRow); + WAIT_UNTIL_POLISHED; + } } currentRow++; } @@ -653,7 +669,7 @@ void tst_qquicktreeview::collapseRecursivelyWholeTree() treeView->expandRecursively(); treeView->collapseRecursively(); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == -1); QVERIFY(signalArgs.at(1).toBool() == true); @@ -689,7 +705,7 @@ void tst_qquicktreeview::expandToIndex() QVERIFY(treeView->isExpanded(treeView->rowAtIndex(child1))); QVERIFY(treeView->isExpanded(treeView->rowAtIndex(child2))); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); auto signalArgs = spy.takeFirst(); QVERIFY(signalArgs.at(0).toInt() == 0); QVERIFY(signalArgs.at(1).toInt() == 3); @@ -711,7 +727,7 @@ void tst_qquicktreeview::toggleExpandedUsingArrowKeys() QQuickWindow *window = treeView->window(); // Start by making cell 0, 0 current - treeView->selectionModel()->setCurrentIndex(treeView->modelIndex(0, 0), QItemSelectionModel::NoUpdate); + treeView->selectionModel()->setCurrentIndex(treeView->index(0, 0), QItemSelectionModel::NoUpdate); // Expand row 0 const int row0 = 0; @@ -727,7 +743,7 @@ void tst_qquicktreeview::toggleExpandedUsingArrowKeys() // Hitting Key_Right again should be a no-op QTest::keyPress(window, Qt::Key_Right); QVERIFY(treeView->isExpanded(row0)); - QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->modelIndex(0, row0)); + QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->index(row0, 0)); // Move down to row 1 and try to expand it. Since Row 1 // doesn't have children, expanding it will be a no-op. @@ -738,7 +754,7 @@ void tst_qquicktreeview::toggleExpandedUsingArrowKeys() QTest::keyPress(window, Qt::Key_Down); QTest::keyPress(window, Qt::Key_Right); QVERIFY(!treeView->isExpanded(row1)); - QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->modelIndex(0, row1)); + QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->index(row1, 0)); // Move down to row 4 and expand it const int row4 = 4; @@ -748,7 +764,7 @@ void tst_qquicktreeview::toggleExpandedUsingArrowKeys() QVERIFY(!treeView->isExpanded(row4)); QTest::keyPress(window, Qt::Key_Right); QVERIFY(treeView->isExpanded(row4)); - QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->modelIndex(0, row4)); + QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->index(row4, 0)); // Move up again to row 0 and collapse it while (treeView->currentRow() != row0) @@ -761,7 +777,7 @@ void tst_qquicktreeview::toggleExpandedUsingArrowKeys() // Hitting Key_Left again should be a no-op QTest::keyPress(window, Qt::Key_Left); QVERIFY(!treeView->isExpanded(row0)); - QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->modelIndex(0, row0)); + QCOMPARE(treeView->selectionModel()->currentIndex(), treeView->index(row0, 0)); } void tst_qquicktreeview::selectionBehaviorCells_data() @@ -837,13 +853,13 @@ void tst_qquicktreeview::selectionBehaviorCells() for (int x = x1; x < x2; ++x) { for (int y = y1; y < y2; ++y) { - const auto index = treeView->modelIndex(x, y); + const auto index = treeView->index(y, x); QVERIFY(selectionModel->isSelected(index)); } } const int expectedCount = (x2 - x1 + 1) * (y2 - y1 + 1); - const int actualCount = selectionModel->selectedIndexes().count(); + const int actualCount = selectionModel->selectedIndexes().size(); QCOMPARE(actualCount, expectedCount); // Wrap the selection @@ -856,7 +872,7 @@ void tst_qquicktreeview::selectionBehaviorCells() } } - const int actualCountAfterWrap = selectionModel->selectedIndexes().count(); + const int actualCountAfterWrap = selectionModel->selectedIndexes().size(); QCOMPARE(actualCountAfterWrap, expectedCount); treeViewPrivate->clearSelection(); @@ -885,12 +901,12 @@ void tst_qquicktreeview::selectionBehaviorRows() QCOMPARE(selectionModel->hasSelection(), true); const int expectedCount = treeView->columns() * 3; // all columns * three rows - int actualCount = selectionModel->selectedIndexes().count(); + int actualCount = selectionModel->selectedIndexes().size(); QCOMPARE(actualCount, expectedCount); for (int x = 0; x < treeView->columns(); ++x) { for (int y = 0; y < 3; ++y) { - const auto index = treeView->modelIndex(x, y); + const auto index = treeView->index(y, x); QVERIFY(selectionModel->isSelected(index)); } } @@ -904,12 +920,12 @@ void tst_qquicktreeview::selectionBehaviorRows() QCOMPARE(selectionModel->hasSelection(), true); - actualCount = selectionModel->selectedIndexes().count(); + actualCount = selectionModel->selectedIndexes().size(); QCOMPARE(actualCount, expectedCount); for (int x = 0; x < treeView->columns(); ++x) { for (int y = 0; y < 3; ++y) { - const auto index = treeView->modelIndex(x, y); + const auto index = treeView->index(y, x); QVERIFY(selectionModel->isSelected(index)); } } @@ -936,12 +952,12 @@ void tst_qquicktreeview::selectionBehaviorColumns() QCOMPARE(selectionModel->hasSelection(), true); const int expectedCount = treeView->rows() * 3; // all rows * three columns - int actualCount = selectionModel->selectedIndexes().count(); + int actualCount = selectionModel->selectedIndexes().size(); QCOMPARE(actualCount, expectedCount); for (int x = 0; x < 3; ++x) { for (int y = 0; y < treeView->rows(); ++y) { - const auto index = treeView->modelIndex(x, y); + const auto index = treeView->index(y, x); QVERIFY(selectionModel->isSelected(index)); } } @@ -955,12 +971,12 @@ void tst_qquicktreeview::selectionBehaviorColumns() QCOMPARE(selectionModel->hasSelection(), true); - actualCount = selectionModel->selectedIndexes().count(); + actualCount = selectionModel->selectedIndexes().size(); QCOMPARE(actualCount, expectedCount); for (int x = 0; x < 3; ++x) { for (int y = 0; y < treeView->rows(); ++y) { - const auto index = treeView->modelIndex(x, y); + const auto index = treeView->index(y, x); QVERIFY(selectionModel->isSelected(index)); } } @@ -986,6 +1002,130 @@ void tst_qquicktreeview::selectionBehaviorDisabled() QCOMPARE(selectionModel->hasSelection(), false); } +void tst_qquicktreeview::sortTreeModel_data() +{ + QTest::addColumn<QSharedPointer<QAbstractItemModel>>("treeModel"); + + const auto stringList = QStringList() << "1" << "2" << "3"; + QTest::newRow("TreeModel") << QSharedPointer<QAbstractItemModel>(new TestModel()); + QTest::newRow("Number model") << QSharedPointer<QAbstractItemModel>(new QStringListModel(stringList)); +} + +void tst_qquicktreeview::sortTreeModel() +{ + // Check that if you assign a QSortFilterProxyModel to to a TreeView, the + // view will end up sorted correctly if the proxy model is sorted. + QFETCH(QSharedPointer<QAbstractItemModel>, treeModel); + LOAD_TREEVIEW("normaltreeview.qml"); + + QSortFilterProxyModel proxyModel; + proxyModel.setSourceModel(treeModel.data()); + treeView->setModel(QVariant::fromValue(&proxyModel)); + + // Expand some nodes + treeView->expand(0); + treeView->expand(4); + treeView->expand(3); + + WAIT_UNTIL_POLISHED; + + // Go through all rows in the view, and check that display in the model + // is the same as in the view. That means that QQmlTreeModelToTableModel + // and QSortFilterProxyModel are in sync. + for (int row = 0; row < treeView->rows(); ++row) { + const auto index = treeView->index(row, 0); + const QString modelDisplay = proxyModel.data(index, Qt::DisplayRole).toString(); + const auto childFxItem = treeViewPrivate->loadedTableItem(QPoint(0, row)); + QVERIFY(childFxItem); + const auto childItem = childFxItem->item; + QVERIFY(childItem); + const auto context = qmlContext(childItem.data()); + const auto itemDisplay = context->contextProperty("display").toString(); + QCOMPARE(itemDisplay, modelDisplay); + } + + // Now sort the model, and do the same test again + proxyModel.sort(0, Qt::DescendingOrder); + WAIT_UNTIL_POLISHED; + + for (int row = 0; row < treeView->rows(); ++row) { + const auto index = treeView->index(row, 0); + const QString modelDisplay = proxyModel.data(index, Qt::DisplayRole).toString(); + const auto childFxItem = treeViewPrivate->loadedTableItem(QPoint(0, row)); + QVERIFY(childFxItem); + const auto childItem = childFxItem->item; + QVERIFY(childItem); + const auto context = qmlContext(childItem.data()); + const auto itemDisplay = context->contextProperty("display").toString(); + QCOMPARE(itemDisplay, modelDisplay); + } +} + +void tst_qquicktreeview::sortTreeModelDynamic_data() +{ + QTest::addColumn<QSharedPointer<QAbstractItemModel>>("treeModel"); + QTest::addColumn<int>("row"); + + const auto stringList = QStringList() << "1" << "2" << "3"; + QTest::newRow("TreeModel 0") << QSharedPointer<QAbstractItemModel>(new TestModel()) << 0; + QTest::newRow("TreeModel 1") << QSharedPointer<QAbstractItemModel>(new TestModel()) << 1; + QTest::newRow("TreeModel 3") << QSharedPointer<QAbstractItemModel>(new TestModel()) << 3; + QTest::newRow("TreeModel 6") << QSharedPointer<QAbstractItemModel>(new TestModel()) << 6; + QTest::newRow("Number model") << QSharedPointer<QAbstractItemModel>(new QStringListModel(stringList)) << 1; +} + +void tst_qquicktreeview::sortTreeModelDynamic() +{ + // Check that if you assign a QSortFilterProxyModel to a TreeView, and + // set DynamicSortFilter to true, the view will end up sorted correctly + // if you change the text for one of the items. + QFETCH(QSharedPointer<QAbstractItemModel>, treeModel); + QFETCH(int, row); + LOAD_TREEVIEW("normaltreeview.qml"); + + QSortFilterProxyModel proxyModel; + proxyModel.setSourceModel(treeModel.data()); + proxyModel.setDynamicSortFilter(true); + proxyModel.sort(Qt::AscendingOrder); + treeView->setModel(QVariant::fromValue(&proxyModel)); + + // Expand some nodes + treeView->expand(0); + treeView->expand(4); + treeView->expand(3); + + // Go through all rows in the view, and check that display in the model + // is the same as in the view. That means that QQmlTreeModelToTableModel + // and QSortFilterProxyModel are in sync. + for (int row = 0; row < treeView->rows(); ++row) { + const auto index = treeView->index(row, 0); + const QString modelDisplay = proxyModel.data(index, Qt::DisplayRole).toString(); + const auto childFxItem = treeViewPrivate->loadedTableItem(QPoint(0, row)); + QVERIFY(childFxItem); + const auto childItem = childFxItem->item; + QVERIFY(childItem); + const auto context = qmlContext(childItem.data()); + const auto itemDisplay = context->contextProperty("display").toString(); + QCOMPARE(itemDisplay, modelDisplay); + } + + // Now change the text in one of the items. This will trigger + // a sort for only one of the parents in the model. + proxyModel.setData(treeView->index(row, 0), u"xxx"_qs, Qt::DisplayRole); + + for (int row = 0; row < treeView->rows(); ++row) { + const auto index = treeView->index(row, 0); + const QString modelDisplay = proxyModel.data(index, Qt::DisplayRole).toString(); + const auto childFxItem = treeViewPrivate->loadedTableItem(QPoint(0, row)); + QVERIFY(childFxItem); + const auto childItem = childFxItem->item; + QVERIFY(childItem); + const auto context = qmlContext(childItem.data()); + const auto itemDisplay = context->contextProperty("display").toString(); + QCOMPARE(itemDisplay, modelDisplay); + } +} + QTEST_MAIN(tst_qquicktreeview) #include "tst_qquicktreeview.moc" diff --git a/tests/auto/quick/qquickview/tst_qquickview.cpp b/tests/auto/quick/qquickview/tst_qquickview.cpp index cb7cdb1c5d..e226cfdca7 100644 --- a/tests/auto/quick/qquickview/tst_qquickview.cpp +++ b/tests/auto/quick/qquickview/tst_qquickview.cpp @@ -123,7 +123,7 @@ void tst_QQuickView::resizemodeitem() view->resize(QSize(200,300)); QTRY_COMPARE(item->width(), 200.0); - for (int i = 0; i < sizeListener.count(); ++i) { + for (int i = 0; i < sizeListener.size(); ++i) { // Check that we have the correct geometry on all signals QCOMPARE(sizeListener.at(i), view->size()); } @@ -171,7 +171,7 @@ void tst_QQuickView::errors() QQmlTestMessageHandler messageHandler; view.setSource(testFileUrl("error1.qml")); QCOMPARE(view.status(), QQuickView::Error); - QCOMPARE(view.errors().count(), 1); + QCOMPARE(view.errors().size(), 1); } { @@ -179,7 +179,7 @@ void tst_QQuickView::errors() QQmlTestMessageHandler messageHandler; view.setSource(testFileUrl("error2.qml")); QCOMPARE(view.status(), QQuickView::Error); - QCOMPARE(view.errors().count(), 1); + QCOMPARE(view.errors().size(), 1); view.show(); } } diff --git a/tests/auto/quick/qquickview_extra/tst_qquickview_extra.cpp b/tests/auto/quick/qquickview_extra/tst_qquickview_extra.cpp index 114b97779a..0cd4b69e00 100644 --- a/tests/auto/quick/qquickview_extra/tst_qquickview_extra.cpp +++ b/tests/auto/quick/qquickview_extra/tst_qquickview_extra.cpp @@ -44,7 +44,7 @@ void tst_QQuickViewExtra::qtbug_87228() // for the sake of this test, any child would be suitable, so pick first deletionSpy.reset(new QSignalSpy(children[0], SIGNAL(destroyed(QObject *)))); } - QCOMPARE(deletionSpy->count(), 1); + QCOMPARE(deletionSpy->size(), 1); } QTEST_APPLESS_MAIN(tst_QQuickViewExtra) diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index 2a567cb307..dd845b37d5 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -61,7 +61,7 @@ public: Branch(Branch *parent = nullptr) : parent(parent) {} ~Branch() { foreach (const Node &child, children) delete child.branch; } int indexOf(Branch *branch) const { - for (int i = 0; i < children.count(); ++i) { + for (int i = 0; i < children.size(); ++i) { if (children.at(i).branch == branch) return i; } @@ -109,7 +109,7 @@ public: if (row < 0 || column != 0) return QModelIndex(); Branch * const branch = branchForIndex(parent); - return branch && row < branch->children.count() + return branch && row < branch->children.size() ? createIndex(row, column, branch) : QModelIndex(); } @@ -123,7 +123,7 @@ public: int rowCount(const QModelIndex &parent) const override { Branch * const branch = branchForIndex(parent); - return branch ? branch->children.count() : 0; + return branch ? branch->children.size() : 0; } int columnCount(const QModelIndex &parent) const override { @@ -138,9 +138,9 @@ public: } void insert(const QModelIndex &parent, int index, const QStringList &data) { - beginInsertRows(parent, index, index + data.count() - 1); + beginInsertRows(parent, index, index + data.size() - 1); Branch * const branch = createBranchForIndex(parent); - for (int i = 0; i < data.count(); ++i) + for (int i = 0; i < data.size(); ++i) branch->children.insert(index + i, Node(data.at(i))); endInsertRows(); } @@ -188,14 +188,14 @@ public: } void setList(const QStringList &l) { - if (trunk.children.count() > 0) { - beginRemoveRows(QModelIndex(), 0, trunk.children.count() - 1); + if (trunk.children.size() > 0) { + beginRemoveRows(QModelIndex(), 0, trunk.children.size() - 1); foreach (const Node &child, trunk.children) delete child.branch; trunk.children.clear(); endRemoveRows(); } - if (l.count() > 0) { - beginInsertRows(QModelIndex(), 0, l.count() -1); + if (l.size() > 0) { + beginInsertRows(QModelIndex(), 0, l.size() -1); foreach (const QString &string, l) trunk.children.append(Node(string)); endInsertRows(); @@ -1040,14 +1040,14 @@ void tst_qquickvisualdatamodel::qaimRowsMoved() QSignalSpy spy(obj, SIGNAL(modelUpdated(QQmlChangeSet,bool))); model.emitMove(sourceFirst, sourceLast, destinationChild); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); - QCOMPARE(spy[0].count(), 2); + QCOMPARE(spy[0].size(), 2); QQmlChangeSet changeSet = spy[0][0].value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 1); + QCOMPARE(changeSet.removes().size(), 1); QCOMPARE(changeSet.removes().at(0).index, expectFrom); QCOMPARE(changeSet.removes().at(0).count, expectCount); - QCOMPARE(changeSet.inserts().count(), 1); + QCOMPARE(changeSet.inserts().size(), 1); QCOMPARE(changeSet.inserts().at(0).index, expectTo); QCOMPARE(changeSet.inserts().at(0).count, expectCount); QCOMPARE(changeSet.removes().at(0).moveId, changeSet.inserts().at(0).moveId); @@ -1109,33 +1109,33 @@ void tst_qquickvisualdatamodel::subtreeRowsMoved() // Move items from the current root index to a sub tree. model.move(QModelIndex(), 1, model.index(0, 0), 3, 2); QCOMPARE(vdm->count(), 2); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); changeSet = spy.last().at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 1); + QCOMPARE(changeSet.removes().size(), 1); QCOMPARE(changeSet.removes().at(0).index, 1); QCOMPARE(changeSet.removes().at(0).count, 2); - QCOMPARE(changeSet.inserts().count(), 0); + QCOMPARE(changeSet.inserts().size(), 0); // Move items from a sub tree to the current root index. model.move(model.index(0, 0), 4, QModelIndex(), 2, 1); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); changeSet = spy.last().at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 0); - QCOMPARE(changeSet.inserts().count(), 1); + QCOMPARE(changeSet.removes().size(), 0); + QCOMPARE(changeSet.inserts().size(), 1); QCOMPARE(changeSet.inserts().at(0).index, 2); QCOMPARE(changeSet.inserts().at(0).count, 1); vdm->setRootIndex(QVariant::fromValue(model.index(2, 0))); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), model.index(2, 0)); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); changeSet = spy.at(2).at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 1); + QCOMPARE(changeSet.removes().size(), 1); QCOMPARE(changeSet.removes().at(0).index, 0); QCOMPARE(changeSet.removes().at(0).count, 3); changeSet = spy.last().at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.inserts().count(), 1); + QCOMPARE(changeSet.inserts().size(), 1); QCOMPARE(changeSet.inserts().at(0).index, 0); QCOMPARE(changeSet.inserts().at(0).count, 3); @@ -1143,41 +1143,41 @@ void tst_qquickvisualdatamodel::subtreeRowsMoved() model.move(QModelIndex(), 2, QModelIndex(), 0, 1); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), model.index(0, 0)); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); // Move the current root index, changing its parent. model.move(QModelIndex(), 0, model.index(1, 0), 0, 1); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), model.index(0, 0, model.index(0, 0))); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); model.insert(model.index(0, 0), 0, QStringList() << "new1" << "new2"); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), model.index(2, 0, model.index(0, 0))); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); model.remove(model.index(0, 0), 1, 1); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), model.index(1, 0, model.index(0, 0))); QCOMPARE(vdm->count(), 3); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); model.remove(model.index(0, 0), 1, 1); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), QModelIndex()); QCOMPARE(vdm->count(), 0); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); changeSet = spy.last().at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 1); + QCOMPARE(changeSet.removes().size(), 1); QCOMPARE(changeSet.removes().at(0).index, 0); QCOMPARE(changeSet.removes().at(0).count, 3); - QCOMPARE(changeSet.inserts().count(), 0); + QCOMPARE(changeSet.inserts().size(), 0); vdm->setRootIndex(QVariant::fromValue(QModelIndex())); QCOMPARE(vdm->rootIndex().value<QModelIndex>(), QModelIndex()); QCOMPARE(vdm->count(), 2); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); changeSet = spy.last().at(0).value<QQmlChangeSet>(); - QCOMPARE(changeSet.removes().count(), 0); - QCOMPARE(changeSet.inserts().count(), 1); + QCOMPARE(changeSet.removes().size(), 0); + QCOMPARE(changeSet.inserts().size(), 1); QCOMPARE(changeSet.inserts().at(0).index, 0); QCOMPARE(changeSet.inserts().at(0).count, 2); } @@ -1209,44 +1209,44 @@ void tst_qquickvisualdatamodel::watchedRoles() QCOMPARE(vdm->count(), 30); emit model.dataChanged(model.index(0), model.index(4)); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); emit model.dataChanged(model.index(0), model.index(4), QVector<int>() << QaimModel::Name); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); emit model.dataChanged(model.index(0), model.index(4), QVector<int>() << QaimModel::Number); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); vdm->setWatchedRoles(QList<QByteArray>() << "name" << "dummy"); emit model.dataChanged(model.index(0), model.index(4)); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 0); QCOMPARE(changeSet.changes().at(0).count, 5); emit model.dataChanged(model.index(1), model.index(6), QVector<int>() << QaimModel::Name); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 1); QCOMPARE(changeSet.changes().at(0).count, 6); emit model.dataChanged(model.index(8), model.index(8), QVector<int>() << QaimModel::Number); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); vdm->setWatchedRoles(QList<QByteArray>() << "number" << "dummy"); emit model.dataChanged(model.index(0), model.index(4)); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 0); QCOMPARE(changeSet.changes().at(0).count, 5); emit model.dataChanged(model.index(1), model.index(6), QVector<int>() << QaimModel::Name); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); emit model.dataChanged(model.index(8), model.index(8), QVector<int>() << QaimModel::Number); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 8); QCOMPARE(changeSet.changes().at(0).count, 1); @@ -1254,19 +1254,19 @@ void tst_qquickvisualdatamodel::watchedRoles() vdm->setWatchedRoles(QList<QByteArray>() << "number" << "name"); emit model.dataChanged(model.index(0), model.index(4)); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 0); QCOMPARE(changeSet.changes().at(0).count, 5); emit model.dataChanged(model.index(1), model.index(6), QVector<int>() << QaimModel::Name); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 1); QCOMPARE(changeSet.changes().at(0).count, 6); emit model.dataChanged(model.index(8), model.index(8), QVector<int>() << QaimModel::Number); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); changeSet = spy.last().at(0).value<QQmlChangeSet>(); QCOMPARE(changeSet.changes().at(0).index, 8); QCOMPARE(changeSet.changes().at(0).count, 1); @@ -2427,24 +2427,24 @@ void tst_qquickvisualdatamodel::incompleteModel() QSignalSpy persistedItemsSpy(model->items(), SIGNAL(countChanged())); evaluate<void>(model, "items.removeGroups(0, items.count, \"items\")"); - QCOMPARE(itemsSpy.count(), 0); - QCOMPARE(persistedItemsSpy.count(), 0); + QCOMPARE(itemsSpy.size(), 0); + QCOMPARE(persistedItemsSpy.size(), 0); evaluate<void>(model, "items.setGroups(0, items.count, \"persistedItems\")"); - QCOMPARE(itemsSpy.count(), 0); - QCOMPARE(persistedItemsSpy.count(), 0); + QCOMPARE(itemsSpy.size(), 0); + QCOMPARE(persistedItemsSpy.size(), 0); evaluate<void>(model, "items.addGroups(0, items.count, \"persistedItems\")"); - QCOMPARE(itemsSpy.count(), 0); - QCOMPARE(persistedItemsSpy.count(), 0); + QCOMPARE(itemsSpy.size(), 0); + QCOMPARE(persistedItemsSpy.size(), 0); evaluate<void>(model, "items.remove(0, items.count)"); - QCOMPARE(itemsSpy.count(), 0); - QCOMPARE(persistedItemsSpy.count(), 0); + QCOMPARE(itemsSpy.size(), 0); + QCOMPARE(persistedItemsSpy.size(), 0); evaluate<void>(model, "items.insert([ \"color\": \"blue\" ])"); - QCOMPARE(itemsSpy.count(), 0); - QCOMPARE(persistedItemsSpy.count(), 0); + QCOMPARE(itemsSpy.size(), 0); + QCOMPARE(persistedItemsSpy.size(), 0); QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*get: index out of range")); QVERIFY(evaluate<bool>(model, "items.get(0) === undefined")); @@ -3070,7 +3070,7 @@ void tst_qquickvisualdatamodel::insert() QCOMPARE(evaluate<int>(visualModel, "visibleItems.count"), visible ? visualCount : modelCount); QCOMPARE(evaluate<int>(visualModel, "selectedItems.count"), selected ? 1 : 0); - QCOMPARE(propertyData.count(), visualCount); + QCOMPARE(propertyData.size(), visualCount); for (int i = 0; i < visualCount; ++i) { int modelIndex = i; if (modelIndex > index) @@ -3538,7 +3538,7 @@ void tst_qquickvisualdatamodel::resolve() QCOMPARE(evaluate<int>(visualModel, "visibleItems.count"), visible ? visualCount : modelCount); QCOMPARE(evaluate<int>(visualModel, "selectedItems.count"), selected ? 1 : 0); - QCOMPARE(propertyData.count(), visualCount); + QCOMPARE(propertyData.size(), visualCount); for (int i = 0; i < visualCount; ++i) { int modelIndex = i; @@ -3939,7 +3939,7 @@ void tst_qquickvisualdatamodel::invalidAttachment() QScopedPointer<QObject> object(component.create()); QVERIFY(object); - QCOMPARE(component.errors().count(), 0); + QCOMPARE(component.errors().size(), 0); QVariant property = object->property("invalidVdm"); QCOMPARE(property.userType(), qMetaTypeId<QQmlDelegateModel *>()); @@ -4268,7 +4268,7 @@ public: static qsizetype listLength(QQmlListProperty<QObject> *property) { auto objectsProvider = qobject_cast<ObjectsProvider*>(property->object); - return objectsProvider ? objectsProvider->m_objects.length() : 0; + return objectsProvider ? objectsProvider->m_objects.size() : 0; } static QObject* listAt(QQmlListProperty<QObject> *property, qsizetype index) diff --git a/tests/auto/quick/qquickwindow/data/shortcutOverride.qml b/tests/auto/quick/qquickwindow/data/shortcutOverride.qml new file mode 100644 index 0000000000..e5d35a984d --- /dev/null +++ b/tests/auto/quick/qquickwindow/data/shortcutOverride.qml @@ -0,0 +1,30 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +import QtQuick +import QtQuick.Window + +Window { + id: root + visible: true + width: 200 + height: 200 + + property bool overridden: false + property bool receivedA: false + property bool receivedB: false + Item { + Keys.onShortcutOverride: (e) => e.accepted = root.overridden = (e.key === Qt.Key_A) + + Item { + focus: true + Shortcut { + sequence: "A" + onActivated: root.receivedA = true + } + Shortcut { + sequence: "B" + onActivated: root.receivedB = true + } + } + } +} diff --git a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp index fca5ebb06d..f7265888cb 100644 --- a/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp +++ b/tests/auto/quick/qquickwindow/tst_qquickwindow.cpp @@ -421,6 +421,9 @@ public: , touchDevice(QTest::createTouchDevice()) , touchDeviceWithVelocity(QTest::createTouchDevice(QInputDevice::DeviceType::TouchScreen, QInputDevice::Capability::Position | QPointingDevice::Capability::Velocity)) + , tabletStylusDevice(QPointingDevicePrivate::tabletDevice(QInputDevice::DeviceType::Stylus, + QPointingDevice::PointerType::Pen, + QPointingDeviceUniqueId::fromNumericId(1234567890))) { QQuickWindow::setDefaultAlphaBuffer(true); } @@ -531,6 +534,8 @@ private slots: #if QT_CONFIG(shortcut) void testShortCut(); + void shortcutOverride_data(); + void shortcutOverride(); #endif void rendererInterface(); @@ -541,6 +546,7 @@ private slots: private: QPointingDevice *touchDevice; QPointingDevice *touchDeviceWithVelocity; + const QPointingDevice *tabletStylusDevice; }; #if QT_CONFIG(opengl) @@ -3610,16 +3616,16 @@ void tst_qquickwindow::cleanupGrabsOnRelease() void tst_qquickwindow::subclassWithPointerEventVirtualOverrides_data() { - QTest::addColumn<QPointingDevice::DeviceType>("deviceType"); + QTest::addColumn<const QPointingDevice *>("device"); - QTest::newRow("mouse click") << QPointingDevice::DeviceType::Mouse; - QTest::newRow("touch tap") << QPointingDevice::DeviceType::TouchScreen; - QTest::newRow("stylus tap") << QPointingDevice::DeviceType::Stylus; + QTest::newRow("mouse click") << QPointingDevice::primaryPointingDevice(); + QTest::newRow("touch tap") << touchDevice; + QTest::newRow("stylus tap") << tabletStylusDevice; } void tst_qquickwindow::subclassWithPointerEventVirtualOverrides() // QTBUG-97859 { - QFETCH(QPointingDevice::DeviceType, deviceType); + QFETCH(const QPointingDevice *, device); PointerRecordingWindow window; window.resize(250, 250); @@ -3627,32 +3633,23 @@ void tst_qquickwindow::subclassWithPointerEventVirtualOverrides() // QTBUG-97859 window.setTitle(QTest::currentTestFunction()); window.show(); QVERIFY(QTest::qWaitForWindowActive(&window)); - const qint64 stylusId = 1234567890; - const QPoint pos(120, 120); - switch (static_cast<QPointingDevice::DeviceType>(deviceType)) { + + QQuickTest::pointerPress(device, &window, 0, pos); + QQuickTest::pointerRelease(device, &window, 0, pos); + + switch (device->type()) { case QPointingDevice::DeviceType::Mouse: - QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, pos); - QTRY_COMPARE(window.m_mouseEvents.count(), 3); // separate move before press - QCOMPARE(window.m_events.count(), 3); + QTRY_COMPARE(window.m_mouseEvents.size(), 3); // separate move before press + QCOMPARE(window.m_events.size(), 3); break; case QPointingDevice::DeviceType::TouchScreen: - QTest::touchEvent(&window, touchDevice).press(0, pos, &window); - QTest::touchEvent(&window, touchDevice).release(0, pos, &window); - QTRY_COMPARE(window.m_touchEvents.count(), 2); - QCOMPARE(window.m_events.count(), 2); + QTRY_COMPARE(window.m_touchEvents.size(), 2); + QCOMPARE(window.m_events.size(), 2); break; case QPointingDevice::DeviceType::Stylus: - // press (pressure is 0.8) - QWindowSystemInterface::handleTabletEvent(&window, pos, window.mapToGlobal(pos), - int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), - Qt::LeftButton, 0.8, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); - // release (pressure is 0) - QWindowSystemInterface::handleTabletEvent(&window, pos, window.mapToGlobal(pos), - int(QInputDevice::DeviceType::Stylus), int(QPointingDevice::PointerType::Pen), - Qt::NoButton, 0, 0, 0, 0, 0, 0, stylusId, Qt::NoModifier); - QTRY_COMPARE(window.m_tabletEvents.count(), 2); - QVERIFY(window.m_events.count() >= window.m_tabletEvents.count()); // tablet + synth-mouse events + QTRY_COMPARE(window.m_tabletEvents.size(), 2); + QVERIFY(window.m_events.size() >= window.m_tabletEvents.size()); // tablet + synth-mouse events break; default: break; @@ -3681,6 +3678,39 @@ void tst_qquickwindow::testShortCut() QVERIFY(eventFilter.events.contains(int(QEvent::ShortcutOverride))); QVERIFY(window->property("received").value<bool>()); } + +void tst_qquickwindow::shortcutOverride_data() +{ + QTest::addColumn<Qt::Key>("key"); + QTest::addColumn<bool>("overridden"); + QTest::addColumn<bool>("receivedA"); + QTest::addColumn<bool>("receivedB"); + + QTest::addRow("Space") << Qt::Key_Space << false << false << false; + QTest::addRow("A") << Qt::Key_A << true << false << false; + QTest::addRow("B") << Qt::Key_B << false << false << true; +} + +void tst_qquickwindow::shortcutOverride() +{ + QFETCH(Qt::Key, key); + QFETCH(bool, overridden); + QFETCH(bool, receivedA); + QFETCH(bool, receivedB); + + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("shortcutOverride.qml")); + + QScopedPointer<QWindow> window(qobject_cast<QQuickWindow *>(component.create())); + QVERIFY(window); + QVERIFY(QTest::qWaitForWindowActive(window.get())); + + QTest::keyPress(window.get(), key); + QCOMPARE(window->property("overridden").value<bool>(), overridden); + QCOMPARE(window->property("receivedA").value<bool>(), receivedA); + QCOMPARE(window->property("receivedB").value<bool>(), receivedB); +} #endif void tst_qquickwindow::rendererInterface() diff --git a/tests/auto/quick/touchmouse/tst_touchmouse.cpp b/tests/auto/quick/touchmouse/tst_touchmouse.cpp index e595175fee..ec98013c8b 100644 --- a/tests/auto/quick/touchmouse/tst_touchmouse.cpp +++ b/tests/auto/quick/touchmouse/tst_touchmouse.cpp @@ -54,7 +54,7 @@ QDebug operator<<(QDebug dbg, const struct Event &event) { if (event.points.isEmpty()) dbg << " @ " << event.mousePos << " global " << event.mousePosGlobal; else - dbg << ", " << event.points.count() << " touchpoints: " << event.points; + dbg << ", " << event.points.size() << " touchpoints: " << event.points; dbg << ')'; return dbg; } @@ -166,12 +166,22 @@ class GrabMonitor : public QObject { public: QObject *exclusiveGrabber = nullptr; + int transitionCount = 0; bool fromMouseEvent = false; bool canceled = false; + void reset() + { + exclusiveGrabber = nullptr; + transitionCount = 0; + fromMouseEvent = false; + canceled = false; + } + void onGrabChanged(QObject *grabber, QPointingDevice::GrabTransition transition, const QPointerEvent *event, const QEventPoint &point) { qCDebug(lcTests) << grabber << transition << event << point << point.device(); + ++transitionCount; switch (transition) { case QPointingDevice::GrabTransition::GrabExclusive: exclusiveGrabber = grabber; @@ -232,6 +242,8 @@ private slots: void oneTouchInsideAndOneOutside(); + void strayTouchDoesntAutograb(); + protected: bool eventFilter(QObject *, QEvent *event) override { @@ -784,7 +796,7 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() qCDebug(lcTests) << "expected filtered events: actual TouchBegin and replayed TouchBegin" << filteredEventList; QTRY_COMPARE(eventItem1->eventList.size(), 1); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress); - QCOMPARE(filteredEventList.count(), 2); // actual touch begin and replayed touch begin + QCOMPARE(filteredEventList.size(), 2); // actual touch begin and replayed touch begin } if (!releaseBeforeDelayIsOver) { @@ -799,7 +811,7 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() if (scrollBeforeDelayIsOver) { QCOMPARE(eventItem1->eventList.size(), 0); qCDebug(lcTests) << "expected filtered events: 1 TouchBegin and 3 TouchUpdate" << filteredEventList; - QCOMPARE(filteredEventList.count(), 4); + QCOMPARE(filteredEventList.size(), 4); } else { qCDebug(lcTests) << "expected delivered events: press(mouse), move(mouse), move(mouse), ungrab(mouse)" << eventItem1->eventList; QCOMPARE(eventItem1->eventList.size(), 4); @@ -807,7 +819,7 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseMove); QCOMPARE(eventItem1->eventList.last().type, QEvent::UngrabMouse); qCDebug(lcTests) << "expected filtered events: 2 TouchBegin and 3 TouchUpdate" << filteredEventList; - QCOMPARE(filteredEventList.count(), 5); + QCOMPARE(filteredEventList.size(), 5); } // flickable should have the touchpoint grab: it no longer relies on synth-mouse @@ -828,17 +840,17 @@ void tst_TouchMouse::buttonOnDelayedPressFlickable() QCOMPARE(eventItem1->eventList.at(1).type, QEvent::MouseButtonRelease); QCOMPARE(eventItem1->eventList.last().type, QEvent::UngrabMouse); // QQuickWindow filters the delayed press and release - QCOMPARE(filteredEventList.count(), 4); - QCOMPARE(filteredEventList.at(filteredEventList.count() - 2).type, QEvent::TouchBegin); + QCOMPARE(filteredEventList.size(), 4); + QCOMPARE(filteredEventList.at(filteredEventList.size() - 2).type, QEvent::TouchBegin); QCOMPARE(filteredEventList.last().type, QEvent::TouchEnd); } else { // QQuickWindow filters the delayed press if there was one if (scrollBeforeDelayIsOver) { qCDebug(lcTests) << "expected filtered events: 1 TouchBegin, 3 TouchUpdate, 1 TouchEnd" << filteredEventList; - QCOMPARE(filteredEventList.count(), 5); + QCOMPARE(filteredEventList.size(), 5); } else { qCDebug(lcTests) << "expected filtered events: 2 TouchBegin, 3 TouchUpdate, 1 TouchEnd" << filteredEventList; - QCOMPARE(filteredEventList.count(), 6); + QCOMPARE(filteredEventList.size(), 6); QCOMPARE(filteredEventList.at(0).type, QEvent::TouchBegin); QCOMPARE(filteredEventList.last().type, QEvent::TouchEnd); } @@ -953,7 +965,7 @@ void tst_TouchMouse::buttonOnTouch() touchSeq.press(0, p1, &window).press(1, p2, &window).commit(); QQuickTouchUtils::flush(&window); QCOMPARE(button1->scale(), 1); - QCOMPARE(eventItem1->eventList.count(), 1); + QCOMPARE(eventItem1->eventList.size(), 1); QCOMPARE(eventItem1->eventList.at(0).type, QEvent::MouseButtonPress); p1 -= QPoint(10, 0); @@ -1265,16 +1277,16 @@ void tst_TouchMouse::tapOnDismissiveTopMouseAreaClicksBottomOne() QTest::touchEvent(&window, device).release(0, p1, &window); QQuickTouchUtils::flush(&window); - QCOMPARE(bottomClickedSpy.count(), 1); - QCOMPARE(bottomDoubleClickedSpy.count(), 0); + QCOMPARE(bottomClickedSpy.size(), 1); + QCOMPARE(bottomDoubleClickedSpy.size(), 0); QTest::touchEvent(&window, device).press(0, p1, &window); QQuickTouchUtils::flush(&window); QTest::touchEvent(&window, device).release(0, p1, &window); QQuickTouchUtils::flush(&window); - QCOMPARE(bottomClickedSpy.count(), 1); - QCOMPARE(bottomDoubleClickedSpy.count(), 1); + QCOMPARE(bottomClickedSpy.size(), 1); + QCOMPARE(bottomDoubleClickedSpy.size(), 1); } /* @@ -1449,21 +1461,21 @@ void tst_TouchMouse::hoverEnabled() // QTBUG-40856 // ------------------------- Mouse move to mouseArea1 QTest::mouseMove(&window, p1); - QVERIFY(enterSpy1.count() == 1); + QVERIFY(enterSpy1.size() == 1); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea2->hovered()); // ------------------------- Touch click on mouseArea1 QTest::touchEvent(&window, device).press(0, p1, &window); - QCOMPARE(enterSpy1.count(), 1); - QCOMPARE(enterSpy2.count(), 0); + QCOMPARE(enterSpy1.size(), 1); + QCOMPARE(enterSpy2.size(), 0); QVERIFY(mouseArea1->pressed()); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea2->hovered()); QTest::touchEvent(&window, device).release(0, p1, &window); - QVERIFY(clickSpy1.count() == 1); + QVERIFY(clickSpy1.size() == 1); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea2->hovered()); @@ -1473,28 +1485,28 @@ void tst_TouchMouse::hoverEnabled() // QTBUG-40856 QVERIFY(mouseArea1->hovered()); QVERIFY(mouseArea2->hovered()); QVERIFY(mouseArea2->pressed()); - QCOMPARE(enterSpy1.count(), 1); - QCOMPARE(enterSpy2.count(), 1); + QCOMPARE(enterSpy1.size(), 1); + QCOMPARE(enterSpy2.size(), 1); QTest::touchEvent(&window, device).release(0, p2, &window); - QVERIFY(clickSpy2.count() == 1); + QVERIFY(clickSpy2.size() == 1); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea2->hovered()); - QCOMPARE(exitSpy1.count(), 0); - QCOMPARE(exitSpy2.count(), 1); + QCOMPARE(exitSpy1.size(), 0); + QCOMPARE(exitSpy2.size(), 1); // ------------------------- Another touch click on mouseArea1 QTest::touchEvent(&window, device).press(0, p1, &window); - QCOMPARE(enterSpy1.count(), 1); - QCOMPARE(enterSpy2.count(), 1); + QCOMPARE(enterSpy1.size(), 1); + QCOMPARE(enterSpy2.size(), 1); QVERIFY(mouseArea1->pressed()); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea2->hovered()); QTest::touchEvent(&window, device).release(0, p1, &window); - QCOMPARE(clickSpy1.count(), 2); + QCOMPARE(clickSpy1.size(), 2); QVERIFY(mouseArea1->hovered()); QVERIFY(!mouseArea1->pressed()); QVERIFY(!mouseArea2->hovered()); @@ -1545,20 +1557,20 @@ void tst_TouchMouse::touchCancelWillCancelMousePress() // Begin a new touch, that gets converted to a mouse press QTest::touchEvent(&window, device).press(0, p1); - QCOMPARE(eventItem->eventList.count(), 1); + QCOMPARE(eventItem->eventList.size(), 1); QCOMPARE(eventItem->eventList.at(0).type, QEvent::MouseButtonPress); // Cancel it... QTouchEvent cancelEvent(QEvent::TouchCancel, device); QCoreApplication::sendEvent(&window, &cancelEvent); - QCOMPARE(eventItem->eventList.count(), 3); + QCOMPARE(eventItem->eventList.size(), 3); QCOMPARE(eventItem->eventList.at(1).type, QEvent::TouchCancel); QCOMPARE(eventItem->eventList.at(2).type, QEvent::UngrabMouse); // Begin a second touch. Since the last one was cancelled, this // should end up as a new mouse press on the target item. QTest::touchEvent(&window, device).press(0, p1); - QVERIFY(eventItem->eventList.count() >= 5); + QVERIFY(eventItem->eventList.size() >= 5); QCOMPARE(eventItem->eventList.at(3).type, QEvent::MouseButtonPress); QTest::touchEvent(&window, device).release(0, p1); // clean up potential state @@ -1600,6 +1612,47 @@ void tst_TouchMouse::oneTouchInsideAndOneOutside() // QTBUG-102996 QQuickTouchUtils::flush(&window); } +void tst_TouchMouse::strayTouchDoesntAutograb() // QTBUG-107867 +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("singleitem.qml"))); + QQuickItem *root = window.rootObject(); + QVERIFY(root); + EventItem *eventItem = root->findChild<EventItem*>(); + QVERIFY(eventItem); + // This item accepts (synth-)mouse events but NOT touch + eventItem->acceptMouse = true; + QCOMPARE(eventItem->acceptTouchEvents(), false); // the default in Qt 6 + QPoint p1(6, 6); + grabMonitor.reset(); + + // Begin a new touch, that gets converted to a mouse press + QTest::touchEvent(&window, device).press(0, p1); + QQuickTouchUtils::flush(&window); + qCDebug(lcTests) << "after touch press:" << eventItem->eventList; + QCOMPARE(eventItem->eventList.size(), 1); + QCOMPARE(eventItem->eventList.at(0).type, QEvent::MouseButtonPress); + QCOMPARE(grabMonitor.exclusiveGrabber, eventItem); + + // Drag + for (int i = 0; i < 3; ++i) { + QTest::touchEvent(&window, device).move(0, p1 + QPoint(i * 5, i * 5), &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(grabMonitor.transitionCount, 1); // no new grab + QCOMPARE(eventItem->eventList.size(), i + 2); + QCOMPARE(eventItem->eventList.last().type, QEvent::MouseMove); + } + + // Press an extra point: EventItem should see nothing + QTest::touchEvent(&window, device).stationary(0).press(1, p1); + QQuickTouchUtils::flush(&window); + qCDebug(lcTests) << "after press of second touchpoint:" << eventItem->eventList; + QCOMPARE(eventItem->eventList.size(), 4); + QCOMPARE(grabMonitor.transitionCount, 1); // no new grab + + QTest::touchEvent(&window, device).release(0, p1).release(1, p1); +} + QTEST_MAIN(tst_TouchMouse) #include "tst_touchmouse.moc" diff --git a/tests/auto/quickcontrols2/CMakeLists.txt b/tests/auto/quickcontrols2/CMakeLists.txt index 5bd05b95ee..e2b37a6202 100644 --- a/tests/auto/quickcontrols2/CMakeLists.txt +++ b/tests/auto/quickcontrols2/CMakeLists.txt @@ -30,6 +30,8 @@ add_subdirectory(qquickmenubar) add_subdirectory(qquickninepatchimage) add_subdirectory(qquickpopup) add_subdirectory(qquickstyle) +add_subdirectory(qquicktextarea) +add_subdirectory(qquicktextfield) add_subdirectory(qquickuniversalstyle) add_subdirectory(qquickuniversalstyleconf) add_subdirectory(revisions) diff --git a/tests/auto/quickcontrols2/controls/data/tst_dialog.qml b/tests/auto/quickcontrols2/controls/data/tst_dialog.qml index 6aa9d39af0..821c7999e0 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_dialog.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_dialog.qml @@ -125,6 +125,8 @@ TestCase { control.closePolicy = Popup.CloseOnPressOutside control.open() verify(control.visible) + // wait for enter transitions to finish + openedSpy.wait() mousePress(testCase, 1, 1) compare(rejectedSpy.count, 3) @@ -143,6 +145,7 @@ TestCase { control.closePolicy = Popup.CloseOnReleaseOutside control.open() verify(control.visible) + openedSpy.wait() mousePress(testCase, 1, 1) compare(rejectedSpy.count, 3) @@ -298,6 +301,7 @@ TestCase { compare(control.implicitHeight, control.contentItem.implicitHeight + control.topPadding + control.bottomPadding + control.header.implicitHeight + control.footer.implicitHeight) + control.footer.implicitWidth = 0 control.header.implicitWidth = 150 compare(control.implicitWidth, control.header.implicitWidth) diff --git a/tests/auto/quickcontrols2/controls/data/tst_popup.qml b/tests/auto/quickcontrols2/controls/data/tst_popup.qml index 58ab662f48..278ee62f06 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_popup.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_popup.qml @@ -6,6 +6,7 @@ import QtTest import QtQuick.Controls import QtQuick.Templates as T import QtQuick.NativeStyle as NativeStyle +import Qt.test.controls TestCase { id: testCase @@ -1405,6 +1406,16 @@ TestCase { property alias popup: popup property alias popupTitle: popupTitle + property alias popupContent: popupContent + property bool gotMouseEvent: false + + MouseArea { + id: windowMouseArea + enabled: true + anchors.fill: parent + onPressed: gotMouseEvent = true + } + Popup { id: popup @@ -1412,6 +1423,7 @@ TestCase { height: 200 background: Rectangle { + id: popupContent color: "#505050" Rectangle { id: popupTitle @@ -1456,6 +1468,11 @@ TestCase { let popup = window.popup popup.open() + + // mouse clicks into the popup must not propagate to the parent + mouseClick(window) + compare(window.gotMouseEvent, false) + let title = window.popupTitle verify(title) @@ -1469,5 +1486,26 @@ TestCase { fuzzyCompare(popup.y, oldPos.y + 5, 1) mouseRelease(title, pressPoint.x, pressPoint.y) compare(title.pressedPosition, Qt.point(0, 0)) + + } + + Component { + id: cppDimmerComponent + + Popup { + dim: true + Overlay.modeless: ComponentCreator.createComponent( + "import QtQuick; Rectangle { objectName: \"rect\"; color: \"tomato\" }") + } + } + + function test_dimmerComponentCreatedInCpp() { + let control = createTemporaryObject(cppDimmerComponent, testCase) + verify(control) + + control.open() + tryCompare(control, "opened", true) + let rect = findChild(control.Overlay.overlay, "rect") + verify(rect) } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml b/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml index 73332e0b4d..1ab2475c45 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_scrollview.qml @@ -578,4 +578,88 @@ TestCase { compare(mouseWheelSpy.count, 1) compare(mouseArea.flickable.contentY, 0) } + + Component { + id: bindingToContentItemAndStandaloneFlickable + + Item { + width: 200 + height: 200 + + property alias scrollView: scrollView + + ScrollView { + id: scrollView + anchors.fill: parent + contentItem: listView + + property Item someBinding: contentItem + } + ListView { + id: listView + model: 10 + delegate: ItemDelegate { + text: modelData + width: listView.width + } + } + } + } + + // Tests that scroll bars show up for a ScrollView where + // - its contentItem is declared as a standalone, separate item + // - there is a binding to contentItem (which causes a default Flickable to be created) + function test_bindingToContentItemAndStandaloneFlickable() { + let root = createTemporaryObject(bindingToContentItemAndStandaloneFlickable, testCase) + verify(root) + + let control = root.scrollView + let verticalScrollBar = control.ScrollBar.vertical + let horizontalScrollBar = control.ScrollBar.horizontal + compare(verticalScrollBar.parent, control) + compare(horizontalScrollBar.parent, control) + verify(verticalScrollBar.visible) + verify(horizontalScrollBar.visible) + + mouseDrag(verticalScrollBar, verticalScrollBar.width / 2, verticalScrollBar.height / 2, 0, 50) + verify(verticalScrollBar.active) + verify(horizontalScrollBar.active) + } + + Component { + id: contentItemAssignedImperatively + + Item { + width: 100 + height: 100 + + property alias scrollView: scrollView + + ListView { + id: listView + model: 20 + delegate: Text { + text: modelData + } + } + + Component.onCompleted: scrollView.contentItem = listView + + ScrollView { + id: scrollView + anchors.fill: parent + + ScrollBar.horizontal.policy: ScrollBar.AlwaysOff + } + } + } + + // Tests that a ListView declared before the ScrollView (as the QObject destruction order + // is relevant for the bug) and assigned imperatively to ScrollView does not cause a crash + // on exit. + function test_contentItemAssignedImperatively() { + let root = createTemporaryObject(contentItemAssignedImperatively, testCase) + verify(root) + // Shouldn't crash. + } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml index add4d7b7ec..c7b5819c3d 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_splitview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_splitview.qml @@ -6,6 +6,7 @@ import QtQuick.Controls import QtQuick.Window import QtTest import Qt.labs.settings +import Qt.test.controls TestCase { id: testCase @@ -2528,4 +2529,65 @@ TestCase { mouseMove(control, control.width - 100, control.height / 2) verify(!targetHandle.SplitHandle.hovered) } + + Component { + id: cppHandleSplitViewComponent + + SplitView { + anchors.fill: parent + handle: ComponentCreator.createComponent(` + import QtQuick + + Rectangle { + objectName: "handle" + implicitWidth: 10 + implicitHeight: 10 + color: "tomato" + }`) + + Rectangle { + objectName: "navajowhite" + color: objectName + implicitWidth: 100 + implicitHeight: 100 + } + Rectangle { + objectName: "steelblue" + color: objectName + implicitWidth: 200 + implicitHeight: 200 + } + } + } + + function test_handleComponentCreatedInCpp() { + let control = createTemporaryObject(cppHandleSplitViewComponent, testCase) + verify(control) + + let handles = findHandles(control) + compare(handles.length, 1) + compare(handles[0].color, Qt.color("tomato")) + } + + function test_touch() { + let control = createTemporaryObject(threeSizedItemsComponent, testCase) + verify(control) + + let touch = touchEvent(control) + + let handles = findHandles(control) + let firstHandle = handles[0] + let handleCenter = control.mapFromItem(firstHandle, firstHandle.width / 2, firstHandle.height / 2) + touch.press(0, control, handleCenter.x, handleCenter.y).commit() + verify(firstHandle.SplitHandle.pressed) + + touch.move(0, control, handleCenter.x + 100, handleCenter.y).commit() + verify(firstHandle.SplitHandle.pressed) + let firstItem = control.itemAt(0) + compare(firstItem.width, 125) + + touch.release(0, control, handleCenter.x + 100, handleCenter.y).commit() + verify(!firstHandle.SplitHandle.pressed) + compare(firstItem.width, 125) + } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_stackview.qml b/tests/auto/quickcontrols2/controls/data/tst_stackview.qml index f2a3781fb1..901c9609a0 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_stackview.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_stackview.qml @@ -4,6 +4,7 @@ import QtQuick import QtTest import QtQuick.Controls +import Qt.test.controls TestCase { id: testCase @@ -1225,7 +1226,12 @@ TestCase { Item { objectName: "clearUponDestructionItem" - Component.onDestruction: container.onDestructionCallback(stackView) + onParentChanged: { + // We don't actually do this on destruction because destruction is delayed. + // Rather, we do it when we get un-parented. + if (parent === null) + container.onDestructionCallback(stackView) + } } } @@ -1544,4 +1550,48 @@ TestCase { tryCompare(control, "busy", true) tryCompare(control, "busy", false) } + + Component { + id: cppComponent + + StackView { + id: stackView + anchors.fill: parent + initialItem: cppComponent + + property Component cppComponent: ComponentCreator.createComponent("import QtQuick; Rectangle { color: \"navajowhite\" }") + } + } + + // Test that a component created in C++ works with StackView. + function test_componentCreatedInCpp() { + let control = createTemporaryObject(cppComponent, testCase) + verify(control) + compare(control.currentItem.color, Qt.color("navajowhite")) + + control.push(control.cppComponent, { color: "tomato" }) + compare(control.currentItem.color, Qt.color("tomato")) + } + + Component { + id: noProperties + Item {} + } + + Component { + id: invalidProperties + + StackView { + anchors.fill: parent + } + } + + function test_invalidProperties() { + let control = createTemporaryObject(invalidProperties, testCase) + verify(control) + verify(control.empty) + ignoreWarning(/Cannot resolve property "unknownProperty.test"/) + control.push(noProperties, { "unknownProperty.test": "crashes" }) + verify(!control.empty) + } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_swipedelegate.qml b/tests/auto/quickcontrols2/controls/data/tst_swipedelegate.qml index 1a544e4c8c..77204015b7 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_swipedelegate.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_swipedelegate.qml @@ -4,7 +4,7 @@ import QtQuick import QtTest import QtQuick.Controls - +import Qt.test.controls TestCase { id: testCase @@ -1726,4 +1726,23 @@ TestCase { compare(control.background.width, 200) compare(control.contentItem.width, 200 - control.leftPadding - control.rightPadding) } + + Component { + id: cppDelegateComponent + + SwipeDelegate { + text: "SwipeDelegate" + width: 150 + swipe.right: ComponentCreator.createComponent( + "import QtQuick; Rectangle { width: 100; height: parent.height; color: \"tomato\" }") + } + } + + function test_delegateComponentCreatedInCpp() { + let control = createTemporaryObject(cppDelegateComponent, testCase) + verify(control) + + swipe(control, 0, -1.0) + compare(control.swipe.rightItem.color, Qt.color("tomato")) + } } diff --git a/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml b/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml index af661def9d..9874988c44 100644 --- a/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml +++ b/tests/auto/quickcontrols2/controls/data/tst_tooltip.qml @@ -249,7 +249,13 @@ TestCase { function test_activateShortcutWhileToolTipVisible() { if ((Qt.platform.pluginName === "offscreen") || (Qt.platform.pluginName === "minimal")) - skip("Mouse hoovering not functional on offscreen/minimal platforms") + skip("Mouse hovering not functional on offscreen/minimal platforms") + + // Window shortcuts (the default context for Shortcut) require the window to have focus. + var window = testCase.Window.window + verify(window) + window.requestActivate() + tryCompare(window, "active", true) var root = createTemporaryObject(buttonAndShortcutComponent, testCase) verify(root) diff --git a/tests/auto/quickcontrols2/cursor/BLACKLIST b/tests/auto/quickcontrols2/cursor/BLACKLIST new file mode 100644 index 0000000000..cebb2c9438 --- /dev/null +++ b/tests/auto/quickcontrols2/cursor/BLACKLIST @@ -0,0 +1,3 @@ +# QTBUG-105611 +[scrollBar] +webos diff --git a/tests/auto/quickcontrols2/customization/tst_customization.cpp b/tests/auto/quickcontrols2/customization/tst_customization.cpp index f22af1d5b8..1ee39ae254 100644 --- a/tests/auto/quickcontrols2/customization/tst_customization.cpp +++ b/tests/auto/quickcontrols2/customization/tst_customization.cpp @@ -293,7 +293,7 @@ void tst_customization::creation() QCOMPARE(control->objectName(), controlName); QVERIFY2(qt_createdQObjects()->removeOne(controlName), qPrintable(controlName + " was not created as expected")); - for (QString delegate : qAsConst(delegates)) { + for (QString delegate : std::as_const(delegates)) { QStringList properties = delegate.split(".", Qt::SkipEmptyParts); // <control>-<delegate>-<style>(-<override>) @@ -390,7 +390,7 @@ void tst_customization::override() QCOMPARE(control->objectName(), controlName); QVERIFY2(qt_createdQObjects()->removeOne(controlName), qPrintable(controlName + " was not created as expected")); - for (QString delegate : qAsConst(delegates)) { + for (QString delegate : std::as_const(delegates)) { QStringList properties = delegate.split(".", Qt::SkipEmptyParts); // <control>-<delegate>-<style>(-override) @@ -420,7 +420,7 @@ void tst_customization::override() if (!nonDeferred.isEmpty()) { // There were items for which deferred execution was not possible. - for (QString delegateName : qAsConst(delegates)) { + for (QString delegateName : std::as_const(delegates)) { if (!delegateName.contains("-")) delegateName.append("-" + nonDeferred); delegateName.prepend(type.toLower() + "-"); diff --git a/tests/auto/quickcontrols2/focus/tst_focus.cpp b/tests/auto/quickcontrols2/focus/tst_focus.cpp index fc38865921..ca70146885 100644 --- a/tests/auto/quickcontrols2/focus/tst_focus.cpp +++ b/tests/auto/quickcontrols2/focus/tst_focus.cpp @@ -93,7 +93,7 @@ void tst_focus::navigation() QVERIFY(QTest::qWaitForWindowActive(&view)); QVERIFY(QGuiApplication::focusWindow() == &view); - for (const QString &name : qAsConst(order)) { + for (const QString &name : std::as_const(order)) { QKeyEvent event(QEvent::KeyPress, key, Qt::NoModifier); QGuiApplication::sendEvent(&view, &event); QVERIFY(event.isAccepted()); @@ -421,7 +421,7 @@ void tst_focus::visualFocus() QQuickItem *column = view.rootObject(); QVERIFY(column); - QCOMPARE(column->childItems().count(), 2); + QCOMPARE(column->childItems().size(), 2); QQuickControl *button = qobject_cast<QQuickControl *>(column->childItems().first()); QVERIFY(button); diff --git a/tests/auto/quickcontrols2/platform/CMakeLists.txt b/tests/auto/quickcontrols2/platform/CMakeLists.txt index 6633de5c02..8e6df7d2b4 100644 --- a/tests/auto/quickcontrols2/platform/CMakeLists.txt +++ b/tests/auto/quickcontrols2/platform/CMakeLists.txt @@ -17,6 +17,7 @@ qt_internal_add_test(tst_platform tst_platform.cpp PUBLIC_LIBRARIES Qt::Gui + Qt::Qml TESTDATA ${test_data} ) diff --git a/tests/auto/quickcontrols2/platform/data/tst_menu.qml b/tests/auto/quickcontrols2/platform/data/tst_menu.qml index 00a75fe110..fb9949c8b7 100644 --- a/tests/auto/quickcontrols2/platform/data/tst_menu.qml +++ b/tests/auto/quickcontrols2/platform/data/tst_menu.qml @@ -4,6 +4,8 @@ import QtQuick import QtTest import Qt.labs.platform +import QtQuick.Controls as Controls +import org.qtproject.Test TestCase { id: testCase @@ -28,6 +30,11 @@ TestCase { signalName: "itemsChanged" } + Component { + id: signalSpyComponent + SignalSpy {} + } + function init() { verify(!itemsSpy.target) compare(itemsSpy.count, 0) @@ -214,4 +221,68 @@ TestCase { compare(subMenu.title, "Title") compare(subMenuItem.text, "Title") } + + Component { + id: disabledMenuItemAndActionComponent + + Item { + property alias action: action + property alias menu: menu + + Controls.Action { + id: action + shortcut: StandardKey.Copy + } + + Menu { + id: menu + + MenuItem { + enabled: !action.enabled + shortcut: StandardKey.Copy + text: "test" + } + } + } + } + + function test_shortcuts() { + if (!TestHelper.shortcutsSupported) + skip("This test requires shortcut support") + + let root = createTemporaryObject(disabledMenuItemAndActionComponent, testCase) + verify(root) + let menu = root.menu + let menuItem = menu.items[0] + verify(menuItem) + let action = root.action + + let actionTriggeredSpy = signalSpyComponent.createObject(root, + { target: action, signalName: "triggered" }) + verify(actionTriggeredSpy.valid) + let menuItemTriggeredSpy = signalSpyComponent.createObject(root, + { target: menuItem, signalName: "triggered" }) + verify(menuItemTriggeredSpy.valid) + + // Perform the shortcut; the Action should be triggered since the MenuItem is disabled. + keySequence(StandardKey.Copy) + compare(actionTriggeredSpy.count, 1) + compare(menuItemTriggeredSpy.count, 0) + + // Disable the Action, enabling the MenuItem in the process. + action.enabled = false + verify(menuItem.enabled) + // Perform the shortcut; the MenuItem should be triggered since the Action is disabled. + keySequence(StandardKey.Copy) + compare(actionTriggeredSpy.count, 1) + compare(menuItemTriggeredSpy.count, 1) + + // Re-enable the Action, disabling the MenuItem in the process. + action.enabled = true + verify(!menuItem.enabled) + // Perform the shortcut; the Action should be triggered since the MenuItem is disabled. + keySequence(StandardKey.Copy) + compare(actionTriggeredSpy.count, 2) + compare(menuItemTriggeredSpy.count, 1) + } } diff --git a/tests/auto/quickcontrols2/platform/tst_platform.cpp b/tests/auto/quickcontrols2/platform/tst_platform.cpp index 335ad9b533..94bf1d6a59 100644 --- a/tests/auto/quickcontrols2/platform/tst_platform.cpp +++ b/tests/auto/quickcontrols2/platform/tst_platform.cpp @@ -1,5 +1,31 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +#include <QtQml/qqmlengine.h> #include <QtQuickTest/quicktest.h> -QUICK_TEST_MAIN(tst_platform) + +class Setup : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool shortcutsSupported READ areShortcutsSupported CONSTANT FINAL) + +public: + bool areShortcutsSupported() const + { +#if QT_CONFIG(shortcut) + return true; +#else + return false; +#endif + } + +public slots: + void qmlEngineAvailable(QQmlEngine *) + { + qmlRegisterSingletonInstance("org.qtproject.Test", 1, 0, "TestHelper", this); + } +}; + +QUICK_TEST_MAIN_WITH_SETUP(tst_platform, Setup) + +#include "tst_platform.moc" diff --git a/tests/auto/quickcontrols2/pointerhandlers/data/draggableButton.qml b/tests/auto/quickcontrols2/pointerhandlers/data/draggableButton.qml new file mode 100644 index 0000000000..ca0c4263b1 --- /dev/null +++ b/tests/auto/quickcontrols2/pointerhandlers/data/draggableButton.qml @@ -0,0 +1,11 @@ +import QtQuick +import QtQuick.Controls + +Rectangle { + width: 150; height: 150 + Button { + text: "Drag me" + width: 150 // workaround for QTBUG-104954 + DragHandler { } + } +} diff --git a/tests/auto/quickcontrols2/pointerhandlers/data/tapHandlerButton.qml b/tests/auto/quickcontrols2/pointerhandlers/data/tapHandlerButton.qml new file mode 100644 index 0000000000..74e0166d0e --- /dev/null +++ b/tests/auto/quickcontrols2/pointerhandlers/data/tapHandlerButton.qml @@ -0,0 +1,12 @@ +import QtQuick +import QtQuick.Controls + +Rectangle { + width: 150; height: 150 + color: th.pressed ? "lightsteelblue" : "beige" + Button { + text: pressed ? "pressed" : "" + width: 150 // workaround for QTBUG-104954 + TapHandler { id: th } + } +} diff --git a/tests/auto/quickcontrols2/pointerhandlers/tst_pointerhandlers.cpp b/tests/auto/quickcontrols2/pointerhandlers/tst_pointerhandlers.cpp index ba1fbd2dd1..aa83175252 100644 --- a/tests/auto/quickcontrols2/pointerhandlers/tst_pointerhandlers.cpp +++ b/tests/auto/quickcontrols2/pointerhandlers/tst_pointerhandlers.cpp @@ -6,16 +6,23 @@ #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickmousearea_p.h> +#include <QtQuick/private/qquickpointerhandler_p.h> +#include <QtQuick/private/qquicktaphandler_p.h> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcontext.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/private/qpointingdevice_p.h> + #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/viewtestutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> +Q_LOGGING_CATEGORY(lcPointerTests, "qt.quick.pointer.tests") + using namespace QQuickViewTestUtils; using namespace QQuickVisualTestUtils; @@ -28,6 +35,13 @@ public: private slots: void hover_controlInsideControl(); void hover_controlAndMouseArea(); + void buttonTapHandler_data(); + void buttonTapHandler(); + void buttonDragHandler_data(); + void buttonDragHandler(); + +private: + QScopedPointer<QPointingDevice> touchscreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); }; tst_pointerhandlers::tst_pointerhandlers() @@ -154,6 +168,127 @@ void tst_pointerhandlers::hover_controlAndMouseArea() QCOMPARE(innerMouseArea->hovered(), false); } +void tst_pointerhandlers::buttonTapHandler_data() +{ + QTest::addColumn<QPointingDevice::DeviceType>("deviceType"); + QTest::addColumn<Qt::MouseButton>("mouseButton"); + + QTest::newRow("left mouse") << QPointingDevice::DeviceType::Mouse << Qt::LeftButton; + QTest::newRow("right mouse") << QPointingDevice::DeviceType::Mouse << Qt::RightButton; + QTest::newRow("touch") << QPointingDevice::DeviceType::TouchScreen << Qt::NoButton; +} + +void tst_pointerhandlers::buttonTapHandler() // QTBUG-105609 +{ + QFETCH(QPointingDevice::DeviceType, deviceType); + QFETCH(Qt::MouseButton, mouseButton); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("tapHandlerButton.qml"))); + + QPointer<QQuickTapHandler> handler = window.rootObject()->findChild<QQuickTapHandler*>(); + QVERIFY(handler); + handler->setAcceptedButtons(mouseButton); + QQuickItem *target = handler->target(); + QVERIFY(target); + QSignalSpy tappedSpy(handler, &QQuickTapHandler::tapped); + QSignalSpy clickedSpy(target, SIGNAL(clicked())); // avoid #include for this signal + + const QPoint pos(10, 10); + switch (static_cast<QPointingDevice::DeviceType>(deviceType)) { + case QPointingDevice::DeviceType::Mouse: + // click it + QTest::mouseClick(&window, mouseButton, Qt::NoModifier, pos); + QTRY_COMPARE(clickedSpy.size(), 1); // perhaps Button should not react to right-click, but it does + QCOMPARE(tappedSpy.size(), 1); + break; + + case QPointingDevice::DeviceType::TouchScreen: { + // tap it + QTest::QTouchEventSequence touch = QTest::touchEvent(&window, touchscreen.data()); + touch.press(0, pos, &window).commit(); + QTRY_COMPARE(target->property("pressed").toBool(), true); + touch.release(0, pos, &window).commit(); + QTRY_COMPARE(clickedSpy.size(), 1); + QCOMPARE(tappedSpy.size(), 1); + break; + } + default: + break; + } + QCOMPARE(handler->isPressed(), false); +} + +void tst_pointerhandlers::buttonDragHandler_data() +{ + QTest::addColumn<QPointingDevice::DeviceType>("deviceType"); + + QTest::newRow("mouse") << QPointingDevice::DeviceType::Mouse; + QTest::newRow("touch") << QPointingDevice::DeviceType::TouchScreen; +} + +void tst_pointerhandlers::buttonDragHandler() // QTBUG-105610 +{ + QFETCH(QPointingDevice::DeviceType, deviceType); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("draggableButton.qml"))); + + const int dragThreshold = QGuiApplication::styleHints()->startDragDistance(); + + QPointer<QQuickPointerHandler> handler = window.rootObject()->findChild<QQuickPointerHandler*>(); + QVERIFY(handler); + QQuickItem *target = handler->target(); + QVERIFY(target); + QSignalSpy clickedSpy(target, SIGNAL(clicked())); + + QPoint dragPos(10, 10); + switch (static_cast<QPointingDevice::DeviceType>(deviceType)) { + case QPointingDevice::DeviceType::Mouse: + // click it + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, dragPos); + QTRY_COMPARE(clickedSpy.size(), 1); + + // drag it + QTest::mousePress(&window, Qt::LeftButton, Qt::NoModifier, dragPos); + dragPos += QPoint(dragThreshold, dragThreshold); + QTest::mouseMove(&window, dragPos); + dragPos += QPoint(1, 1); + QTest::mouseMove(&window, dragPos); + qCDebug(lcPointerTests) << handler << "dragged" << target << "to" << target->position(); + QTRY_VERIFY(handler->active()); + QTest::mouseRelease(&window, Qt::LeftButton, Qt::NoModifier, dragPos); + break; + + case QPointingDevice::DeviceType::TouchScreen: { + QTest::QTouchEventSequence touch = QTest::touchEvent(&window, touchscreen.data()); + + // tap it + touch.press(0, dragPos, &window).commit(); + touch.release(0, dragPos, &window).commit(); + QTRY_COMPARE(clickedSpy.size(), 1); + + // drag it + touch.press(0, dragPos, &window).commit(); + dragPos += QPoint(dragThreshold, dragThreshold); + touch.move(0, dragPos, &window).commit(); + dragPos += QPoint(1, 1); + touch.move(0, dragPos, &window).commit(); + qCDebug(lcPointerTests) << handler << "dragged" << target << "to" << target->position(); + QTRY_VERIFY(handler->active()); + touch.release(0, dragPos, &window).commit(); + break; + } + default: + break; + } + QTRY_COMPARE(handler->active(), false); + + // click it again + QTest::mouseClick(&window, Qt::LeftButton, Qt::NoModifier, dragPos); + QTRY_COMPARE(clickedSpy.size(), 2); +} + QTEST_MAIN(tst_pointerhandlers) #include "tst_pointerhandlers.moc" diff --git a/tests/auto/quickcontrols2/pressandhold/tst_pressandhold.cpp b/tests/auto/quickcontrols2/pressandhold/tst_pressandhold.cpp index 170e61cafa..98013a1d0c 100644 --- a/tests/auto/quickcontrols2/pressandhold/tst_pressandhold.cpp +++ b/tests/auto/quickcontrols2/pressandhold/tst_pressandhold.cpp @@ -79,16 +79,16 @@ void tst_PressAndHold::pressAndHold() // pressAndHold() emitted QGuiApplication::sendEvent(control.data(), &press); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); QGuiApplication::sendEvent(control.data(), &release); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); spy.clear(); // pressAndHold() canceled by release QGuiApplication::sendEvent(control.data(), &press); QGuiApplication::processEvents(); QGuiApplication::sendEvent(control.data(), &release); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); // pressAndHold() canceled by move QGuiApplication::sendEvent(control.data(), &press); @@ -97,12 +97,12 @@ void tst_PressAndHold::pressAndHold() // by the time the second control emits pressAndHold(), we can reliably // assume that the first control would have emitted pressAndHold() if it // wasn't canceled as appropriate by the move event above - QTRY_COMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QTRY_COMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); QGuiApplication::sendEvent(control.data(), &release); QGuiApplication::sendEvent(waitControl.data(), &release); - QCOMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QCOMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); waitSpy.clear(); // pressAndHold() canceled by 2nd press @@ -112,12 +112,12 @@ void tst_PressAndHold::pressAndHold() // by the time the second control emits pressAndHold(), we can reliably // assume that the first control would have emitted pressAndHold() if it // wasn't canceled as appropriate by the 2nd press event above - QTRY_COMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QTRY_COMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); QGuiApplication::sendEvent(control.data(), &release); QGuiApplication::sendEvent(waitControl.data(), &release); - QCOMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QCOMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); waitSpy.clear(); } @@ -158,9 +158,9 @@ void tst_PressAndHold::keepSelection() // pressAndHold() emitted => selection remains QGuiApplication::sendEvent(control.data(), &press); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); QGuiApplication::sendEvent(control.data(), &release); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); QCOMPARE(control->property("selectedText"), control->property("text")); spy.clear(); @@ -168,7 +168,7 @@ void tst_PressAndHold::keepSelection() QGuiApplication::sendEvent(control.data(), &press); QGuiApplication::processEvents(); QGuiApplication::sendEvent(control.data(), &release); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QVERIFY(control->property("selectedText").toString().isEmpty()); QVERIFY(QMetaObject::invokeMethod(control.data(), "selectAll")); @@ -181,12 +181,12 @@ void tst_PressAndHold::keepSelection() // by the time the second control emits pressAndHold(), we can reliably // assume that the first control would have emitted pressAndHold() if it // wasn't canceled as appropriate by the move event above - QTRY_COMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QTRY_COMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); QGuiApplication::sendEvent(control.data(), &release); QGuiApplication::sendEvent(waitControl.data(), &release); - QCOMPARE(waitSpy.count(), 1); - QCOMPARE(spy.count(), 0); + QCOMPARE(waitSpy.size(), 1); + QCOMPARE(spy.size(), 0); QVERIFY(control->property("selectedText").toString().isEmpty()); waitSpy.clear(); } diff --git a/tests/auto/quickcontrols2/qquickapplicationwindow/tst_qquickapplicationwindow.cpp b/tests/auto/quickcontrols2/qquickapplicationwindow/tst_qquickapplicationwindow.cpp index 000b4e22af..e055340dde 100644 --- a/tests/auto/quickcontrols2/qquickapplicationwindow/tst_qquickapplicationwindow.cpp +++ b/tests/auto/quickcontrols2/qquickapplicationwindow/tst_qquickapplicationwindow.cpp @@ -700,7 +700,7 @@ void tst_QQuickApplicationWindow::focusAfterPopupClosed() QSignalSpy focusScopeSpy(window.data(), SIGNAL(focusScopeKeyPressed())); QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusScopeSpy.count(), 1); + QCOMPARE(focusScopeSpy.size(), 1); // Open the menu. QQuickItem* toolButton = window->property("toolButton").value<QQuickItem*>(); @@ -711,14 +711,14 @@ void tst_QQuickApplicationWindow::focusAfterPopupClosed() // The FocusScope shouldn't receive any key events while the menu is open. QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusScopeSpy.count(), 1); + QCOMPARE(focusScopeSpy.size(), 1); // Close the menu. The FocusScope should regain focus. QTest::keyClick(window.data(), Qt::Key_Escape); QVERIFY(focusScope->hasActiveFocus()); QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusScopeSpy.count(), 2); + QCOMPARE(focusScopeSpy.size(), 2); QQuickPopup *focusPopup = window->property("focusPopup").value<QQuickPopup*>(); QVERIFY(focusPopup); @@ -729,7 +729,7 @@ void tst_QQuickApplicationWindow::focusAfterPopupClosed() QSignalSpy focusPopupSpy(window.data(), SIGNAL(focusPopupKeyPressed())); QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusPopupSpy.count(), 1); + QCOMPARE(focusPopupSpy.size(), 1); QQuickMenu *fileMenu = window->property("fileMenu").value<QQuickMenu*>(); QVERIFY(fileMenu); @@ -738,21 +738,21 @@ void tst_QQuickApplicationWindow::focusAfterPopupClosed() // The Popup shouldn't receive any key events while the menu is open. QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusPopupSpy.count(), 1); + QCOMPARE(focusPopupSpy.size(), 1); // Close the menu. The Popup should regain focus. QTest::keyClick(window.data(), Qt::Key_Escape); QVERIFY(focusPopup->hasActiveFocus()); QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusPopupSpy.count(), 2); + QCOMPARE(focusPopupSpy.size(), 2); // Close the popup. The FocusScope should regain focus. QTest::keyClick(window.data(), Qt::Key_Escape); QVERIFY(focusScope->hasActiveFocus()); QTest::keyClick(window.data(), Qt::Key_Space); - QCOMPARE(focusScopeSpy.count(), 3); + QCOMPARE(focusScopeSpy.size(), 3); } void tst_QQuickApplicationWindow::clearFocusOnDestruction() @@ -796,7 +796,7 @@ void tst_QQuickApplicationWindow::clearFocusOnDestruction() Therefore, if you have good reasons to change the behavior (and not emit it) take the test below with a grain of salt. */ - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); } void tst_QQuickApplicationWindow::layout() diff --git a/tests/auto/quickcontrols2/qquickcontrol/tst_qquickcontrol.cpp b/tests/auto/quickcontrols2/qquickcontrol/tst_qquickcontrol.cpp index ca6183e41d..ddb4b7ff8b 100644 --- a/tests/auto/quickcontrols2/qquickcontrol/tst_qquickcontrol.cpp +++ b/tests/auto/quickcontrols2/qquickcontrol/tst_qquickcontrol.cpp @@ -66,12 +66,12 @@ void tst_QQuickControl::flickable() QPoint p(button->width() / 2, button->height() / 2); QTest::touchEvent(window, touchDevice.data()).press(0, p); - QTRY_COMPARE(buttonPressedSpy.count(), 1); + QTRY_COMPARE(buttonPressedSpy.size(), 1); p += QPoint(1, 1); // less than the drag threshold QTest::touchEvent(window, touchDevice.data()).move(0, p); QTest::touchEvent(window, touchDevice.data()).release(0, p); - QTRY_COMPARE(buttonReleasedSpy.count(), 1); - QTRY_COMPARE(buttonClickedSpy.count(), 1); + QTRY_COMPARE(buttonReleasedSpy.size(), 1); + QTRY_COMPARE(buttonClickedSpy.size(), 1); } void tst_QQuickControl::fractionalFontSize() diff --git a/tests/auto/quickcontrols2/qquickdrawer/data/itemPartialOverlayModal.qml b/tests/auto/quickcontrols2/qquickdrawer/data/itemPartialOverlayModal.qml new file mode 100644 index 0000000000..23aa4ca3c2 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickdrawer/data/itemPartialOverlayModal.qml @@ -0,0 +1,13 @@ +import QtQuick 2.15 +import QtQuick.Controls 2.15 + +Item { + width: 400; height: 400 + + Drawer { + edge: Qt.LeftEdge + height: 200 + width: 200 + modal: true + } +} diff --git a/tests/auto/quickcontrols2/qquickdrawer/tst_qquickdrawer.cpp b/tests/auto/quickcontrols2/qquickdrawer/tst_qquickdrawer.cpp index 48e1a541be..4b2260d4ea 100644 --- a/tests/auto/quickcontrols2/qquickdrawer/tst_qquickdrawer.cpp +++ b/tests/auto/quickcontrols2/qquickdrawer/tst_qquickdrawer.cpp @@ -14,14 +14,16 @@ #include <QtQml/QQmlComponent> #include <QtQuick/private/qquickwindow_p.h> #include <QtQuick/private/qquickflickable_p.h> +#include <QtQuick/qquickview.h> #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> -#include <QtQuickTemplates2/private/qquickoverlay_p.h> +#include <QtQuickTemplates2/private/qquickoverlay_p_p.h> #include <QtQuickTemplates2/private/qquickpopup_p_p.h> #include <QtQuickTemplates2/private/qquickdrawer_p.h> #include <QtQuickTemplates2/private/qquickbutton_p.h> #include <QtQuickTemplates2/private/qquickslider_p.h> +#include <QtQuickTestUtils/private/viewtestutils_p.h> #include <QtQuickControlsTestUtils/private/controlstestutils_p.h> #include <QtQuickControlsTestUtils/private/qtest_quickcontrols_p.h> @@ -90,6 +92,10 @@ private slots: void topEdgeScreenEdge(); + void bookkeepingInOverlay(); + + void touchOutsideOverlay(); + private: QScopedPointer<QPointingDevice> touchDevice; }; @@ -225,71 +231,71 @@ void tst_QQuickDrawer::state() // open programmatically... drawer->open(); - QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), ++aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), ++visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), ++aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), closedCount); // ...and wait until fully open QVERIFY(openedSpy.wait()); - QCOMPARE(visibleChangedSpy.count(), visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), ++openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), ++openedCount); + QCOMPARE(closedSpy.size(), closedCount); // close programmatically... drawer->close(); - QCOMPARE(visibleChangedSpy.count(), visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), ++aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), ++aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), closedCount); // ...and wait until fully closed QVERIFY(closedSpy.wait()); - QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), ++closedCount); + QCOMPARE(visibleChangedSpy.size(), ++visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), ++closedCount); // open interactively... QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, drawer->height() / 2)); QTest::mouseMove(window, QPoint(drawer->width() * 0.2, drawer->height() / 2), 16); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width() * 0.8, drawer->height() / 2), 16); - QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), ++aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), ++visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), ++aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), closedCount); // ...and wait until fully open QVERIFY(openedSpy.wait()); - QCOMPARE(visibleChangedSpy.count(), visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), ++openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), ++openedCount); + QCOMPARE(closedSpy.size(), closedCount); // close interactively... QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width(), drawer->height() / 2)); QTest::mouseMove(window, QPoint(drawer->width() * 0.8, drawer->height() / 2), 16); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width() * 0.2, drawer->height() / 2), 16); - QCOMPARE(visibleChangedSpy.count(), visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), ++aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), closedCount); + QCOMPARE(visibleChangedSpy.size(), visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), ++aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), closedCount); // ...and wait until fully closed QVERIFY(closedSpy.wait()); - QCOMPARE(visibleChangedSpy.count(), ++visibleChangedCount); - QCOMPARE(aboutToShowSpy.count(), aboutToShowCount); - QCOMPARE(aboutToHideSpy.count(), aboutToHideCount); - QCOMPARE(openedSpy.count(), openedCount); - QCOMPARE(closedSpy.count(), ++closedCount); + QCOMPARE(visibleChangedSpy.size(), ++visibleChangedCount); + QCOMPARE(aboutToShowSpy.size(), aboutToShowCount); + QCOMPARE(aboutToHideSpy.size(), aboutToHideCount); + QCOMPARE(openedSpy.size(), openedCount); + QCOMPARE(closedSpy.size(), ++closedCount); } void tst_QQuickDrawer::position_data() @@ -518,7 +524,7 @@ void tst_QQuickDrawer::header() QSignalSpy clickSpy(button, SIGNAL(clicked())); QVERIFY(clickSpy.isValid()); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + button->width() / 2, button->y() + button->height() / 2)); - QCOMPARE(clickSpy.count(), 1); + QCOMPARE(clickSpy.size(), 1); } void tst_QQuickDrawer::dragHandlerInteraction() @@ -577,7 +583,7 @@ void tst_QQuickDrawer::hover() QSignalSpy openedSpy(drawer, SIGNAL(opened())); QVERIFY(openedSpy.isValid()); drawer->open(); - QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + QVERIFY(openedSpy.size() == 1 || openedSpy.wait()); // hover the background button outside the drawer QTest::mouseMove(window, QPoint(window->width() - 1, window->height() - 1)); @@ -600,7 +606,7 @@ void tst_QQuickDrawer::hover() QSignalSpy closedSpy(drawer, SIGNAL(closed())); QVERIFY(closedSpy.isValid()); drawer->close(); - QVERIFY(closedSpy.count() == 1 || closedSpy.wait()); + QVERIFY(closedSpy.size() == 1 || closedSpy.wait()); // hover the background button after closing the drawer QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2)); @@ -665,7 +671,7 @@ void tst_QQuickDrawer::wheel() QSignalSpy openedSpy(drawer, SIGNAL(opened())); QVERIFY(openedSpy.isValid()); drawer->open(); - QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + QVERIFY(openedSpy.size() == 1 || openedSpy.wait()); { // wheel over the drawer content @@ -725,9 +731,9 @@ void tst_QQuickDrawer::multiple() // no drawers open, click the content QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 0); - QCOMPARE(rightClickSpy.count(), 0); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 0); + QCOMPARE(rightClickSpy.size(), 0); // drag the left drawer open QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, window->height() / 2)); @@ -754,30 +760,30 @@ void tst_QQuickDrawer::multiple() // click the left drawer's button QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 0); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 0); // click the left drawer's background (button disabled, don't leak through to the right drawer below) leftButton->setEnabled(false); QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 0); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 0); leftButton->setEnabled(true); // click the overlay of the left drawer (don't leak through to right drawer below) QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - (window->width() - leftDrawer->width()) / 2, window->height() / 2)); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 0); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 0); QTRY_VERIFY(!leftDrawer->isVisible()); // click the right drawer's button QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 1); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 1); // cannot drag the left drawer while the right drawer is open QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, window->height() / 2)); @@ -791,23 +797,23 @@ void tst_QQuickDrawer::multiple() // click the right drawer's background (button disabled, don't leak through to the content below) rightButton->setEnabled(false); QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 1); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 1); rightButton->setEnabled(true); // click the overlay of the right drawer (don't leak through to the content below) QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint((window->width() - rightDrawer->width()) / 2, window->height() / 2)); - QCOMPARE(contentClickSpy.count(), 1); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 1); + QCOMPARE(contentClickSpy.size(), 1); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 1); QTRY_VERIFY(!rightDrawer->isVisible()); // no drawers open, click the content QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(contentClickSpy.count(), 2); - QCOMPARE(leftClickSpy.count(), 1); - QCOMPARE(rightClickSpy.count(), 1); + QCOMPARE(contentClickSpy.size(), 2); + QCOMPARE(leftClickSpy.size(), 1); + QCOMPARE(rightClickSpy.size(), 1); // drag the right drawer open QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, window->height() / 2)); @@ -920,33 +926,33 @@ void tst_QQuickDrawer::multiTouch() QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(300, 100)); QVERIFY(popup->isVisible()); QVERIFY(drawer->isVisible()); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 1); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 1); // 2nd press (blocked & ignored) QTest::touchEvent(window, touchDevice.data()).stationary(0).press(1, QPoint(300, 200)); QVERIFY(popup->isVisible()); QVERIFY(drawer->isVisible()); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 2); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 2); // 2nd release (blocked & ignored) QTest::touchEvent(window, touchDevice.data()).stationary(0).release(1, QPoint(300, 200)); QVERIFY(popup->isVisible()); QVERIFY(drawer->isVisible()); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(buttonReleasedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 2); - QCOMPARE(overlayReleasedSpy.count(), 1); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(buttonReleasedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 2); + QCOMPARE(overlayReleasedSpy.size(), 1); // 1st release QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(300, 100)); QVERIFY(popup->isVisible()); QTRY_VERIFY(!drawer->isVisible()); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(buttonReleasedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 2); - QCOMPARE(overlayReleasedSpy.count(), 2); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(buttonReleasedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 2); + QCOMPARE(overlayReleasedSpy.size(), 2); drawer->open(); QVERIFY(drawer->isVisible()); @@ -954,8 +960,8 @@ void tst_QQuickDrawer::multiTouch() // 1st drag QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(300, 100)); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 3); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 3); for (int x = 300; x >= 100; x -= 10) { QTest::touchEvent(window, touchDevice.data()).move(0, QPoint(x, 100)); QVERIFY(popup->isVisible()); @@ -965,8 +971,8 @@ void tst_QQuickDrawer::multiTouch() // 2nd drag (blocked & ignored) QTest::touchEvent(window, touchDevice.data()).stationary(0).press(1, QPoint(300, 200)); - QCOMPARE(buttonPressedSpy.count(), 0); - QCOMPARE(overlayPressedSpy.count(), 4); + QCOMPARE(buttonPressedSpy.size(), 0); + QCOMPARE(overlayPressedSpy.size(), 4); for (int x = 300; x >= 0; x -= 10) { QTest::touchEvent(window, touchDevice.data()).stationary(0).move(1, QPoint(x, 200)); QVERIFY(popup->isVisible()); @@ -979,15 +985,15 @@ void tst_QQuickDrawer::multiTouch() QVERIFY(popup->isVisible()); QVERIFY(drawer->isVisible()); QCOMPARE(drawer->position(), 0.5); - QCOMPARE(buttonReleasedSpy.count(), 0); - QCOMPARE(overlayReleasedSpy.count(), 3); + QCOMPARE(buttonReleasedSpy.size(), 0); + QCOMPARE(overlayReleasedSpy.size(), 3); // 1st release QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(300, 100)); QVERIFY(popup->isVisible()); QTRY_VERIFY(!drawer->isVisible()); - QCOMPARE(buttonReleasedSpy.count(), 0); - QCOMPARE(overlayReleasedSpy.count(), 4); + QCOMPARE(buttonReleasedSpy.size(), 0); + QCOMPARE(overlayReleasedSpy.size(), 4); } void tst_QQuickDrawer::grabber() @@ -1021,10 +1027,10 @@ void tst_QQuickDrawer::grabber() QVERIFY(popupClosedSpy.isValid()); popup->open(); - QTRY_COMPARE(popupOpenedSpy.count(), 1); + QTRY_COMPARE(popupOpenedSpy.size(), 1); QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(100, 300)); - QTRY_COMPARE(popupClosedSpy.count(), 1); + QTRY_COMPARE(popupClosedSpy.size(), 1); } void tst_QQuickDrawer::interactive_data() @@ -1062,7 +1068,7 @@ void tst_QQuickDrawer::interactive() // click outside QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, QPoint(300, 100)); - QCOMPARE(aboutToHideSpy.count(), 0); + QCOMPARE(aboutToHideSpy.size(), 0); // drag inside QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(drawer->width(), 0)); @@ -1070,7 +1076,7 @@ void tst_QQuickDrawer::interactive() QCOMPARE(drawer->position(), 1.0); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); QCOMPARE(drawer->position(), 1.0); - QCOMPARE(aboutToHideSpy.count(), 0); + QCOMPARE(aboutToHideSpy.size(), 0); // drag outside QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(window->width() - 1, 0)); @@ -1078,11 +1084,11 @@ void tst_QQuickDrawer::interactive() QCOMPARE(drawer->position(), 1.0); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(0, 0)); QCOMPARE(drawer->position(), 1.0); - QCOMPARE(aboutToHideSpy.count(), 0); + QCOMPARE(aboutToHideSpy.size(), 0); // close on escape QTest::keyClick(window, Qt::Key_Escape); - QCOMPARE(aboutToHideSpy.count(), 0); + QCOMPARE(aboutToHideSpy.size(), 0); } void tst_QQuickDrawer::flickable_data() @@ -1362,6 +1368,66 @@ void tst_QQuickDrawer::topEdgeScreenEdge() QTRY_COMPARE(drawer->position(), 1.0); } +void tst_QQuickDrawer::bookkeepingInOverlay() +{ + QQmlEngine engine; + QQmlComponent component(&engine); + component.loadUrl(testFileUrl("window.qml")); + + QScopedPointer<QObject> root(component.create()); + QVERIFY2(!root.isNull(), qPrintable(component.errorString())); + QQuickWindow *window = qobject_cast<QQuickWindow *>(root.get()); + QVERIFY(window); + QQuickDrawer *drawer = window->property("drawer").value<QQuickDrawer *>(); + QVERIFY(drawer); + QQuickOverlay *overlay = QQuickOverlay::overlay(window); + QVERIFY(overlay); +#ifdef QT_BUILD_INTERNAL + QQuickOverlayPrivate *overlayD = QQuickOverlayPrivate::get(overlay); + QVERIFY(!overlayD->stackingOrderDrawers().isEmpty()); +#endif + + delete drawer; +#ifdef QT_BUILD_INTERNAL + QVERIFY(overlayD->stackingOrderDrawers().isEmpty()); +#endif +} + +void tst_QQuickDrawer::touchOutsideOverlay() // QTBUG-103811 +{ + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("itemPartialOverlayModal.qml"))); + auto *drawer = window.rootObject()->findChild<QQuickDrawer*>(); + QVERIFY(drawer); + QSignalSpy openedSpy(drawer, &QQuickDrawer::opened); + QSignalSpy closedSpy(drawer, &QQuickDrawer::closed); + + drawer->open(); + QVERIFY(openedSpy.size() == 1 || openedSpy.wait()); + QVERIFY(drawer->isOpened()); + + // tap-dance in bottom area beyond the overlay + QPoint p1(100, 250); + QPoint p2(300, 250); + QTest::touchEvent(&window, touchDevice.data()).press(1, p1); + p1 -= QPoint(1, 0); + QTest::touchEvent(&window, touchDevice.data()).move(1, p1).press(2, p2); + p2 -= QPoint(1, 0); + QTest::touchEvent(&window, touchDevice.data()).release(1, p1).move(2, p2); + QTest::touchEvent(&window, touchDevice.data()).press(1, p1).stationary(2); + QTest::touchEvent(&window, touchDevice.data()).release(1, p1).release(2, p2); + QQuickTouchUtils::flush(&window); + + // tap the overlay to try to close the drawer + QVERIFY(drawer->closePolicy().testFlag(QQuickPopup::CloseOnReleaseOutside)); + const QPoint p3(300, 100); + QTest::touchEvent(&window, touchDevice.data()).press(3, p3); + QTest::touchEvent(&window, touchDevice.data()).release(3, p3); + QQuickTouchUtils::flush(&window); + QVERIFY(closedSpy.size() == 1 || closedSpy.wait()); + QCOMPARE(drawer->isOpened(), false); +} + QTEST_QUICKCONTROLS_MAIN(tst_QQuickDrawer) #include "tst_qquickdrawer.moc" diff --git a/tests/auto/quickcontrols2/qquickheaderview/tst_qquickheaderview.cpp b/tests/auto/quickcontrols2/qquickheaderview/tst_qquickheaderview.cpp index d9d2ab5691..28b92fef71 100644 --- a/tests/auto/quickcontrols2/qquickheaderview/tst_qquickheaderview.cpp +++ b/tests/auto/quickcontrols2/qquickheaderview/tst_qquickheaderview.cpp @@ -329,16 +329,16 @@ void tst_QQuickHeaderView::testModel() QVERIFY(modelChangedSpy.isValid()); hhv->setModel(QVariant::fromValue(thm)); - QCOMPARE(modelChangedSpy.count(), 0); + QCOMPARE(modelChangedSpy.size(), 0); hhv->setModel(QVariant::fromValue(pm)); - QCOMPARE(modelChangedSpy.count(), 1); + QCOMPARE(modelChangedSpy.size(), 1); TestTableModel ttm2; ttm2.setRowCount(100); ttm2.setColumnCount(30); hhv->setModel(QVariant::fromValue(&ttm2)); - QCOMPARE(modelChangedSpy.count(), 2); + QCOMPARE(modelChangedSpy.size(), 2); } void tst_QQuickHeaderView::listModel() diff --git a/tests/auto/quickcontrols2/qquickiconlabel/tst_qquickiconlabel.cpp b/tests/auto/quickcontrols2/qquickiconlabel/tst_qquickiconlabel.cpp index 5aab4a0f09..8d42cf5faf 100644 --- a/tests/auto/quickcontrols2/qquickiconlabel/tst_qquickiconlabel.cpp +++ b/tests/auto/quickcontrols2/qquickiconlabel/tst_qquickiconlabel.cpp @@ -130,7 +130,7 @@ void tst_qquickiconlabel::display() // Test that the icon and text are correctly positioned and sized after // setting several different display types in succession. - for (QQuickIconLabel::Display displayType : qAsConst(displayTypes)) { + for (QQuickIconLabel::Display displayType : std::as_const(displayTypes)) { label->setDisplay(displayType); QCOMPARE(label->display(), displayType); diff --git a/tests/auto/quickcontrols2/qquickimaginestyle/data/tst_imagine.qml b/tests/auto/quickcontrols2/qquickimaginestyle/data/tst_imagine.qml index 01e9bed693..c6bb83f72a 100644 --- a/tests/auto/quickcontrols2/qquickimaginestyle/data/tst_imagine.qml +++ b/tests/auto/quickcontrols2/qquickimaginestyle/data/tst_imagine.qml @@ -141,9 +141,9 @@ TestCase { { target: testCase.Window.window, signalName: "afterRendering" }) verify(afterRenderingSpy.valid) - afterRenderingSpy.wait(100) + afterRenderingSpy.wait(1000) container.ninePatchImage.source = "" // Shouldn't result in a crash. - afterRenderingSpy.wait(100) + afterRenderingSpy.wait(1000) } } diff --git a/tests/auto/quickcontrols2/qquickmaterialstyle/CMakeLists.txt b/tests/auto/quickcontrols2/qquickmaterialstyle/CMakeLists.txt index 332f376d9f..3dabf123ad 100644 --- a/tests/auto/quickcontrols2/qquickmaterialstyle/CMakeLists.txt +++ b/tests/auto/quickcontrols2/qquickmaterialstyle/CMakeLists.txt @@ -17,7 +17,6 @@ qt_internal_add_test(tst_qquickmaterialstyle tst_qquickmaterialstyle.cpp PUBLIC_LIBRARIES Qt::Gui - Qt::Qml TESTDATA ${test_data} ) diff --git a/tests/auto/quickcontrols2/qquickmaterialstyle/data/tst_material.qml b/tests/auto/quickcontrols2/qquickmaterialstyle/data/tst_material.qml index a9c401d155..689d90ca25 100644 --- a/tests/auto/quickcontrols2/qquickmaterialstyle/data/tst_material.qml +++ b/tests/auto/quickcontrols2/qquickmaterialstyle/data/tst_material.qml @@ -8,8 +8,6 @@ import QtQuick.Templates as T import QtQuick.Controls import QtQuick.Controls.Material -import org.qtproject.Test - TestCase { id: testCase width: 200 @@ -18,6 +16,12 @@ TestCase { when: windowShown name: "Material" + function init() { + // This is particularly important for test_propertyBindingLoop, + // which relies on binding loop warnings failing the test. + failOnWarning(/.?/) + } + Component { id: button Button { } @@ -35,17 +39,12 @@ TestCase { } Component { - id: window + id: windowComponent Window { } } Component { - id: applicationWindow - ApplicationWindow { } - } - - Component { - id: styledWindow + id: styledWindowComponent Window { Material.theme: Material.Dark Material.primary: Material.Brown @@ -56,7 +55,7 @@ TestCase { } Component { - id: loader + id: buttonLoaderComponent Loader { active: false sourceComponent: Button { } @@ -64,7 +63,7 @@ TestCase { } Component { - id: swipeView + id: swipeViewComponent SwipeView { Material.theme: Material.Dark Button { } @@ -72,7 +71,7 @@ TestCase { } Component { - id: menu + id: menuComponent ApplicationWindow { Material.primary: Material.Blue Material.accent: Material.Red @@ -115,7 +114,7 @@ TestCase { } Component { - id: comboBox + id: comboBoxComponent ApplicationWindow { width: 200 height: 200 @@ -132,7 +131,7 @@ TestCase { } Component { - id: windowPane + id: windowPaneComponent ApplicationWindow { width: 200 height: 200 @@ -151,7 +150,7 @@ TestCase { } function test_defaults() { - var control = button.createObject(testCase) + let control = createTemporaryObject(button, testCase) verify(control) verify(control.Material) compare(control.Material.primary, Material.color(Material.Indigo)) @@ -159,11 +158,10 @@ TestCase { compare(control.Material.foreground, "#dd000000") compare(control.Material.background, "#fafafa") compare(control.Material.theme, Material.Light) - control.destroy() } function test_set() { - var control = button.createObject(testCase) + let control = createTemporaryObject(button, testCase) verify(control) control.Material.primary = Material.Green control.Material.accent = Material.Brown @@ -175,11 +173,10 @@ TestCase { compare(control.Material.background, Material.color(Material.Red, themeshade(control.Material.theme))) compare(control.Material.foreground, Material.color(Material.Blue)) compare(control.Material.theme, Material.Dark) - control.destroy() } function test_reset() { - var control = styledButton.createObject(testCase) + let control = createTemporaryObject(styledButton, testCase) verify(control) compare(control.Material.primary, Material.color(Material.DeepOrange)) compare(control.Material.accent, Material.color(Material.DeepPurple, themeshade(control.Material.theme))) @@ -196,7 +193,6 @@ TestCase { compare(control.Material.background, testCase.Material.background) compare(control.Material.foreground, testCase.Material.foreground) compare(control.Material.theme, testCase.Material.theme) - control.destroy() } function test_inheritance_data() { @@ -210,19 +206,19 @@ TestCase { } function test_inheritance(data) { - var prop = data.tag - var parent = button.createObject(testCase) + let prop = data.tag + let parent = createTemporaryObject(button, testCase) parent.Material[prop] = data.value1 compare(parent.Material[prop], data.value1) - var child1 = button.createObject(parent) + let child1 = button.createObject(parent) compare(child1.Material[prop], data.value1) parent.Material[prop] = data.value2 compare(parent.Material[prop], data.value2) compare(child1.Material[prop], data.value2) - var child2 = button.createObject(parent) + let child2 = button.createObject(parent) compare(child2.Material[prop], data.value2) child2.Material[prop] = data.value1 @@ -236,21 +232,19 @@ TestCase { compare(child1.Material[prop], parent.Material[prop]) verify(child2.Material[prop] !== parent.Material[prop]) - var grandChild1 = button.createObject(child1) - var grandChild2 = button.createObject(child2) + let grandChild1 = button.createObject(child1) + let grandChild2 = button.createObject(child2) compare(grandChild1.Material[prop], child1.Material[prop]) compare(grandChild2.Material[prop], child2.Material[prop]) - var themelessGrandGrandChild = button.createObject(grandChild1) - var grandGrandGrandChild1 = button.createObject(themelessGrandGrandChild) + let themelessGrandGrandChild = button.createObject(grandChild1) + let grandGrandGrandChild1 = button.createObject(themelessGrandGrandChild) compare(grandGrandGrandChild1.Material[prop], parent.Material[prop]) child1.Material[prop] = data.value2 compare(child1.Material[prop], data.value2) compare(grandChild1.Material[prop], data.value2) compare(grandGrandGrandChild1.Material[prop], data.value2) - - parent.destroy() } function test_inheritance_popup_data() { @@ -262,8 +256,8 @@ TestCase { } function test_inheritance_popup(data) { - var prop = data.tag - var popupObject = popupComponent.createObject(testCase) + let prop = data.tag + let popupObject = createTemporaryObject(popupComponent, testCase) compare(popupObject.popup.Material.textSelectionColor.toString(), popupObject.Material.textSelectionColor.toString()) compare(popupObject.label.color.toString(), popupObject.Material.textSelectionColor.toString()) compare(popupObject.label2.color.toString(), popupObject.Material.textSelectionColor.toString()) @@ -279,28 +273,26 @@ TestCase { compare(popupObject.popup.Material.textSelectionColor.toString(), popupObject.Material.textSelectionColor.toString()) compare(popupObject.label.color.toString(), popupObject.Material.textSelectionColor.toString()) compare(popupObject.label2.color.toString(), popupObject.Material.textSelectionColor.toString()) - - popupObject.destroy() } function test_window() { - var parent = window.createObject() + let parent = createTemporaryObject(windowComponent) - var control = button.createObject(parent.contentItem) + let control = button.createObject(parent.contentItem) compare(control.Material.primary, parent.Material.primary) compare(control.Material.accent, parent.Material.accent) compare(control.Material.background, parent.Material.background) compare(control.Material.foreground, parent.Material.foreground) compare(control.Material.theme, parent.Material.theme) - var styledChild = styledWindow.createObject(window) + let styledChild = styledWindowComponent.createObject(parent) verify(styledChild.Material.primary !== parent.Material.primary) verify(styledChild.Material.accent !== parent.Material.accent) verify(styledChild.Material.background !== parent.Material.background) verify(styledChild.Material.foreground !== parent.Material.foreground) verify(styledChild.Material.theme !== parent.Material.theme) - var unstyledChild = window.createObject(window) + let unstyledChild = windowComponent.createObject(parent) compare(unstyledChild.Material.primary, parent.Material.primary) compare(unstyledChild.Material.accent, parent.Material.accent) compare(unstyledChild.Material.background, parent.Material.background) @@ -326,12 +318,10 @@ TestCase { compare(control.Material.foreground, Material.color(Material.Pink)) verify(styledChild.Material.foreground !== Material.color(Material.Pink)) // ### TODO: compare(unstyledChild.Material.foreground, Material.color(Material.Pink)) - - parent.destroy() } function test_loader() { - var control = loader.createObject(testCase) + let control = createTemporaryObject(buttonLoaderComponent, testCase) control.Material.primary = Material.Yellow control.Material.accent = Material.Lime control.Material.background = Material.LightGreen @@ -359,26 +349,24 @@ TestCase { compare(control.item.Material.accent, Material.color(Material.Brown)) compare(control.item.Material.background, Material.color(Material.Red)) compare(control.item.Material.foreground, Material.color(Material.Pink)) - control.destroy() } function test_swipeView() { - var control = swipeView.createObject(testCase) + let control = createTemporaryObject(swipeViewComponent, testCase) verify(control) - var child = control.itemAt(0) + let child = control.itemAt(0) verify(child) compare(control.Material.theme, Material.Dark) compare(child.Material.theme, Material.Dark) - control.destroy() } function test_menu() { - var container = menu.createObject(testCase) + let container = createTemporaryObject(menuComponent, testCase) verify(container) verify(container.menu) container.menu.open() verify(container.menu.visible) - var child = container.menu.itemAt(0) + let child = container.menu.itemAt(0) verify(child) compare(container.Material.theme, Material.Light) compare(container.menu.Material.theme, Material.Dark) @@ -389,11 +377,10 @@ TestCase { compare(container.Material.accent, Material.color(Material.Red)) compare(container.menu.Material.accent, Material.color(Material.Red, themeshade(container.menu.Material.theme))) compare(child.Material.accent, Material.color(Material.Red, themeshade(child.Material.theme))) - container.destroy() } function test_comboBox() { - var window = comboBox.createObject(testCase) + let window = createTemporaryObject(comboBoxComponent, testCase) verify(window) verify(window.combo) waitForRendering(window.combo) @@ -401,9 +388,9 @@ TestCase { verify(window.combo.activeFocus) keyClick(Qt.Key_Space) verify(window.combo.popup.visible) - var listView = window.combo.popup.contentItem + let listView = window.combo.popup.contentItem verify(listView) - var child = listView.contentItem.children[0] + let child = listView.contentItem.children[0] verify(child) compare(window.Material.theme, Material.Light) compare(window.combo.Material.theme, Material.Dark) @@ -414,14 +401,13 @@ TestCase { compare(window.Material.accent, Material.color(Material.Red)) compare(window.combo.Material.accent, Material.color(Material.Red, themeshade(window.combo.Material.theme))) compare(child.Material.accent, Material.color(Material.Red, themeshade(child.Material.theme))) - window.destroy() } function test_windowChange() { - var ldr = loader.createObject() + let ldr = buttonLoaderComponent.createObject() verify(ldr) - var wnd = window.createObject() + let wnd = createTemporaryObject(windowComponent) verify(wnd) wnd.Material.theme = Material.Dark @@ -433,8 +419,6 @@ TestCase { ldr.parent = wnd.contentItem compare(ldr.item.Material.theme, Material.Dark) - - wnd.destroy() } function test_colors_data() { @@ -444,10 +428,10 @@ TestCase { } function test_colors(data) { - var control = button.createObject(testCase) + let control = createTemporaryObject(button, testCase) verify(control) - var prop = data.tag + let prop = data.tag // Material.Color - enum control.Material[prop] = Material.Red @@ -484,8 +468,6 @@ TestCase { control.Material[prop] = "foo" ignoreWarning(new RegExp("QML Button: unknown Material." + prop + " value: #1")) control.Material[prop] = "#1" - - control.destroy() } function test_font_data() { @@ -557,11 +539,11 @@ TestCase { } function test_font(data) { - var window = windowPane.createObject(testCase) + let window = createTemporaryObject(windowPaneComponent, testCase) verify(window) verify(window.pane) - var control = Qt.createQmlObject("import QtQuick.Controls; " + data.type + " { }", window.pane) + let control = Qt.createQmlObject("import QtQuick.Controls; " + data.type + " { }", window.pane) verify(control) compare(control.font[data.attribute], data.value) @@ -580,14 +562,11 @@ TestCase { compare(window.font[data.attribute], data.window) compare(window.pane.font[data.attribute], data.window) compare(control.font[data.attribute], data.window) - - window.destroy() } Component { - id: backgroundControls + id: backgroundControlsComponent ApplicationWindow { - id: window property Button button: Button { } property ComboBox combobox: ComboBox { } property Drawer drawer: Drawer { } @@ -621,16 +600,16 @@ TestCase { } function test_background(data) { - var window = backgroundControls.createObject(testCase) + let window = createTemporaryObject(backgroundControlsComponent, testCase) verify(window) - var control = window[data.tag] + let control = window[data.tag] verify(control) control.parent = window.contentItem control.visible = true - var defaultBackground = control.background.color + let defaultBackground = control.background.color window.Material.background = "#ff0000" compare(window.color, "#ff0000") @@ -652,23 +631,19 @@ TestCase { control.Material.background = "#0000ff" tryCompare(control.background, "color", "#0000ff") - - window.destroy() } Component { - id: busyIndicator + id: busyIndicatorComponent BusyIndicator { } } function test_shade() { - var control = busyIndicator.createObject(testCase) + let control = createTemporaryObject(busyIndicatorComponent, testCase) compare(control.contentItem.color.toString(), Material.color(Material.Pink, Material.Shade500)) control.Material.theme = Material.Dark compare(control.contentItem.color.toString(), Material.color(Material.Pink, Material.Shade200)) - - control.destroy() } // We can't declare components with JS syntax (when creating a data row), @@ -738,7 +713,5 @@ TestCase { function test_propertyBindingLoop(data) { let item = createTemporaryObject(data.component, testCase) verify(item) - verify(!BindingLoopDetector.bindingLoopDetected, "Detected binding loop") - BindingLoopDetector.reset() } } diff --git a/tests/auto/quickcontrols2/qquickmaterialstyle/tst_qquickmaterialstyle.cpp b/tests/auto/quickcontrols2/qquickmaterialstyle/tst_qquickmaterialstyle.cpp index 79238cff90..3594f4b1b0 100644 --- a/tests/auto/quickcontrols2/qquickmaterialstyle/tst_qquickmaterialstyle.cpp +++ b/tests/auto/quickcontrols2/qquickmaterialstyle/tst_qquickmaterialstyle.cpp @@ -1,42 +1,5 @@ // Copyright (C) 2017 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 -#include <QtQml/qqmlengine.h> -#include <QtQml/qqmlcontext.h> #include <QtQuickTest/quicktest.h> - -class Setup : public QObject -{ - Q_OBJECT - Q_PROPERTY(bool bindingLoopDetected READ wasBindingLoopDetected FINAL) - -public: - Setup() {} - - bool wasBindingLoopDetected() const { return mBindingLoopDetected; } - -public slots: - void reset() { mBindingLoopDetected = false; } - - void qmlEngineAvailable(QQmlEngine *engine) - { - connect(engine, &QQmlEngine::warnings, this, &Setup::qmlWarnings); - - qmlRegisterSingletonInstance("org.qtproject.Test", 1, 0, "BindingLoopDetector", this); - } - - void qmlWarnings(const QList<QQmlError> &warnings) - { - for (const auto &error : warnings) { - if (error.messageType() == QtWarningMsg && error.description().contains(QStringLiteral("Binding loop detected"))) - mBindingLoopDetected = true; - } - } - -private: - bool mBindingLoopDetected = false; -}; - -QUICK_TEST_MAIN_WITH_SETUP(tst_qquickmaterialstyle, Setup) - -#include "tst_qquickmaterialstyle.moc" +QUICK_TEST_MAIN(tst_qquickmaterialstyle) diff --git a/tests/auto/quickcontrols2/qquickmenu/data/popup.qml b/tests/auto/quickcontrols2/qquickmenu/data/popup.qml index 46ea45ef17..8201c9e03f 100644 --- a/tests/auto/quickcontrols2/qquickmenu/data/popup.qml +++ b/tests/auto/quickcontrols2/qquickmenu/data/popup.qml @@ -5,7 +5,7 @@ import QtQuick import QtQuick.Controls ApplicationWindow { - width: 400 + width: 500 height: 600 property alias menu: menu diff --git a/tests/auto/quickcontrols2/qquickmenu/tst_qquickmenu.cpp b/tests/auto/quickcontrols2/qquickmenu/tst_qquickmenu.cpp index fc5ea55b9b..0afb385fa9 100644 --- a/tests/auto/quickcontrols2/qquickmenu/tst_qquickmenu.cpp +++ b/tests/auto/quickcontrols2/qquickmenu/tst_qquickmenu.cpp @@ -854,16 +854,16 @@ void tst_QQuickMenu::popup() QCOMPARE(menu->parentItem(), window->contentItem()); QCOMPARE(menu->currentIndex(), -1); QCOMPARE(menu->contentItem()->property("currentIndex").toInt(), -1); - QTRY_VERIFY(qFuzzyCompare(menu->x(), 33)); - QTRY_VERIFY(qFuzzyCompare(menu->y(), 44)); + QTRY_VERIFY(qFuzzyCompare(menu->x(), qMax(qreal(33), menu->leftMargin()))); + QTRY_VERIFY(qFuzzyCompare(menu->y(), qMax(qreal(44), menu->topMargin()))); menu->close(); QVERIFY(QMetaObject::invokeMethod(window, "popupAtCoord", Q_ARG(QVariant, 55), Q_ARG(QVariant, 66))); QCOMPARE(menu->parentItem(), window->contentItem()); QCOMPARE(menu->currentIndex(), -1); QCOMPARE(menu->contentItem()->property("currentIndex").toInt(), -1); - QTRY_VERIFY(qFuzzyCompare(menu->x(), 55)); - QTRY_VERIFY(qFuzzyCompare(menu->y(), 66)); + QTRY_VERIFY(qFuzzyCompare(menu->x(), qMax(qreal(55), menu->leftMargin()))); + QTRY_VERIFY(qFuzzyCompare(menu->y(), qMax(qreal(66), menu->topMargin()))); menu->close(); menu->setParentItem(nullptr); @@ -1833,10 +1833,10 @@ void tst_QQuickMenu::disableWhenTriggered() QVERIFY(subMenuItem); // First, open the sub-menu. -#ifndef Q_OS_ANDROID +#if !defined(Q_OS_ANDROID) and !defined(Q_OS_WEBOS) QTest::mouseMove(window, menuItem->mapToScene(QPoint(1, 1)).toPoint()); #else - // On Android mouseHover does not open sub-menu, so just click on it + // On Android and webOS mouseHover does not open sub-menu, so just click on it QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, menuItem->mapToScene(QPointF(menuItem->width() / 2, menuItem->height() / 2)).toPoint()); #endif diff --git a/tests/auto/quickcontrols2/qquickmenubar/tst_qquickmenubar.cpp b/tests/auto/quickcontrols2/qquickmenubar/tst_qquickmenubar.cpp index 2544aa4d79..f4b3aaf210 100644 --- a/tests/auto/quickcontrols2/qquickmenubar/tst_qquickmenubar.cpp +++ b/tests/auto/quickcontrols2/qquickmenubar/tst_qquickmenubar.cpp @@ -568,19 +568,19 @@ void tst_qquickmenubar::mnemonics() // trigger a menu item to close the menu, which shouldn't trigger a button // action behind the menu (QTBUG-86276) - QCOMPARE(oopsButtonSpy.count(), 0); + QCOMPARE(oopsButtonSpy.size(), 0); keySim.click(Qt::Key_O); // "&Open..." keySim.release(Qt::Key_Alt); QVERIFY(!fileMenuBarItem->isHighlighted()); QVERIFY(!fileMenuBarMenu->isOpened()); QTRY_VERIFY(!fileMenuBarMenu->isVisible()); - QCOMPARE(oopsButtonSpy.count(), 0); + QCOMPARE(oopsButtonSpy.size(), 0); // trigger a button action while menu is closed keySim.press(Qt::Key_Alt); keySim.click(Qt::Key_O); // "&Oops" keySim.release(Qt::Key_Alt); - QCOMPARE(oopsButtonSpy.count(), 1); + QCOMPARE(oopsButtonSpy.size(), 1); } void tst_qquickmenubar::addRemove() diff --git a/tests/auto/quickcontrols2/qquickninepatchimage/CMakeLists.txt b/tests/auto/quickcontrols2/qquickninepatchimage/CMakeLists.txt index 56edab461d..b0fdebd1aa 100644 --- a/tests/auto/quickcontrols2/qquickninepatchimage/CMakeLists.txt +++ b/tests/auto/quickcontrols2/qquickninepatchimage/CMakeLists.txt @@ -7,11 +7,7 @@ # Collect test data file(GLOB_RECURSE test_data_glob RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/data/*.qml) -list(APPEND test_data ${test_data_glob}) -file(GLOB_RECURSE test_data_glob - RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/data/*.png) + ${CMAKE_CURRENT_SOURCE_DIR}/data/*) list(APPEND test_data ${test_data_glob}) qt_internal_add_test(tst_qquickninepatchimage diff --git a/tests/auto/quickcontrols2/qquickninepatchimage/data/logo.pkm b/tests/auto/quickcontrols2/qquickninepatchimage/data/logo.pkm Binary files differnew file mode 100644 index 0000000000..c0987c5c36 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickninepatchimage/data/logo.pkm diff --git a/tests/auto/quickcontrols2/qquickninepatchimage/data/o1_bc1.ktx b/tests/auto/quickcontrols2/qquickninepatchimage/data/o1_bc1.ktx Binary files differnew file mode 100644 index 0000000000..d61194a745 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickninepatchimage/data/o1_bc1.ktx diff --git a/tests/auto/quickcontrols2/qquickninepatchimage/data/qt4.astc b/tests/auto/quickcontrols2/qquickninepatchimage/data/qt4.astc Binary files differnew file mode 100644 index 0000000000..7f7a3f4739 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickninepatchimage/data/qt4.astc diff --git a/tests/auto/quickcontrols2/qquickninepatchimage/tst_qquickninepatchimage.cpp b/tests/auto/quickcontrols2/qquickninepatchimage/tst_qquickninepatchimage.cpp index d11e5c8536..dc88d0c5ed 100644 --- a/tests/auto/quickcontrols2/qquickninepatchimage/tst_qquickninepatchimage.cpp +++ b/tests/auto/quickcontrols2/qquickninepatchimage/tst_qquickninepatchimage.cpp @@ -11,8 +11,10 @@ #include <QtQuick/qquickview.h> #include <QtQuick/qquickitemgrabresult.h> #include <QtQuick/private/qquickimage_p.h> +#include <QtQuick/private/qquickimage_p_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> +#include <QtGui/private/qrhi_p.h> using namespace QQuickVisualTestUtils; @@ -32,6 +34,8 @@ private slots: void inset(); void implicitSize_data(); void implicitSize(); + void hwCompressedImages_data(); + void hwCompressedImages(); }; static QImage grabItemToImage(QQuickItem *item) @@ -152,7 +156,7 @@ void tst_qquickninepatchimage::inset_data() const QStringList files = QStringList() << "inset-all.9.png" << "inset-topleft.9.png" << "inset-bottomright.9.png"; const QList<QMarginsF> insets = QList<QMarginsF>() << QMarginsF(2, 1, 3, 4) << QMarginsF(2, 1, 0, 0) << QMarginsF(0, 0, 3, 4); - for (int i = 0; i < files.count(); ++i) { + for (int i = 0; i < files.size(); ++i) { QString file = files.at(i); for (int dpr = 1; dpr <= 4; ++dpr) QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file).arg(dpr))) << dpr << file << insets.at(i); @@ -230,6 +234,61 @@ void tst_qquickninepatchimage::implicitSize() QCOMPARE(ninePatchImage->implicitHeight(), implicitSize.height()); } +void tst_qquickninepatchimage::hwCompressedImages_data() +{ + QTest::addColumn<int>("dpr"); + QTest::addColumn<QString>("file"); + QTest::addColumn<QSize>("size"); + QTest::addColumn<QRhiTexture::Format>("format"); + + const struct TestFile { + QString name; + QSize size; + QRhiTexture::Format format; + } testFiles [] = { + { "o1_bc1.ktx", QSize(64, 64), QRhiTexture::BC1 }, + { "logo.pkm", QSize(256, 256), QRhiTexture::ETC2_RGB8 }, + { "qt4.astc", QSize(250, 200), QRhiTexture::ASTC_8x8 } + }; + + for (const TestFile &file : testFiles) { + for (int dpr = 1; dpr <= 4; ++dpr) + QTest::newRow(qPrintable(QString::fromLatin1("%1 DPR=%2").arg(file.name).arg(dpr))) << dpr << file.name << file.size << file.format; + } +} + +void tst_qquickninepatchimage::hwCompressedImages() +{ + QFETCH(int, dpr); + QFETCH(QString, file); + QFETCH(QSize, size); + QFETCH(QRhiTexture::Format, format); + + QHighDpiScaling::setGlobalFactor(dpr); + + QQuickView view(testFileUrl("ninepatchimage.qml")); + QCOMPARE(view.status(), QQuickView::Ready); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + if (!QSGRendererInterface::isApiRhiBased(view.rendererInterface()->graphicsApi())) + QSKIP("Skipping due to using software backend"); + + QRhi *rhi = static_cast<QRhi *>(view.rendererInterface()->getResource(&view, QSGRendererInterface::RhiResource)); + if (!rhi->isTextureFormatSupported(format)) + QSKIP(qPrintable(QString::fromLatin1("%1 not supported, skip").arg(format))); + + QQuickImage *ninePatchImage = qobject_cast<QQuickImage *>(view.rootObject()); + QVERIFY(ninePatchImage); + ninePatchImage->setSource(testFileUrl(file)); + ninePatchImage->setSize(size); + QSignalSpy spy(&view, SIGNAL(afterSynchronizing())); + QTRY_VERIFY(spy.size() >= 1); + + QQuickImagePrivate *ninePatchImagePrivate = static_cast<QQuickImagePrivate *>(QQuickItemPrivate::get(ninePatchImage)); + QVERIFY(ninePatchImagePrivate->paintNode); +} + QTEST_MAIN(tst_qquickninepatchimage) #include "tst_qquickninepatchimage.moc" diff --git a/tests/auto/quickcontrols2/qquickpopup/data/applicationwindow-wheel.qml b/tests/auto/quickcontrols2/qquickpopup/data/applicationwindow-wheel.qml index 073300a36c..1668b042e0 100644 --- a/tests/auto/quickcontrols2/qquickpopup/data/applicationwindow-wheel.qml +++ b/tests/auto/quickcontrols2/qquickpopup/data/applicationwindow-wheel.qml @@ -11,6 +11,7 @@ ApplicationWindow { height: 400 property alias popup: popup + property alias nestedPopup: nestedPopup property alias popupSlider: popupSlider property alias contentSlider: contentSlider @@ -30,5 +31,13 @@ ApplicationWindow { id: popupSlider wheelEnabled: true } + + Popup { + id: nestedPopup + x: 0; y: 0 + clip: true + implicitWidth: 50 + implicitHeight: 50 + } } } diff --git a/tests/auto/quickcontrols2/qquickpopup/data/mirroredCombobox.qml b/tests/auto/quickcontrols2/qquickpopup/data/mirroredCombobox.qml new file mode 100644 index 0000000000..ed48179bce --- /dev/null +++ b/tests/auto/quickcontrols2/qquickpopup/data/mirroredCombobox.qml @@ -0,0 +1,26 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Controls + +Window { + width: 400 + height: 400 + + contentItem.rotation: 180 + + ComboBox { + objectName: "first" + x: 100 + y: 300 // is missing space, needs to unroll in the "mirrored" direction + model: ["First", "Second", "Third", "Fourth", "Fifth"] + } + + ComboBox { + objectName: "second" + x: 200 + y: 100 // has enough space to unroll + model: ["A", "B", "C"] + } +} diff --git a/tests/auto/quickcontrols2/qquickpopup/data/nested-wheel.qml b/tests/auto/quickcontrols2/qquickpopup/data/nested-wheel.qml new file mode 100644 index 0000000000..a0b319fd24 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickpopup/data/nested-wheel.qml @@ -0,0 +1,44 @@ +import QtQuick +import QtQuick.Controls + +ApplicationWindow { + width: 400 + height: 400 + + property alias modalPopup: popup + property alias comboBox: combobox + + Popup { + id: popup + objectName: "Modal Dialog" + width: 300 + height: 300 + anchors.centerIn: parent + visible: true + modal: true + + ComboBox { + id: combobox + anchors.centerIn: parent + width: 120 + model: 30 + + popup: Popup { + objectName: "Combobox Popup" + y: combobox.height + width: combobox.width + height: contentItem.implicitHeight + contentItem: ListView { + objectName: "Combobox ListView" + clip: true + implicitHeight: 150 + model: combobox.delegateModel + currentIndex: combobox.highlightedIndex + ScrollBar.vertical: ScrollBar { + objectName: "vbar" + } + } + } + } + } +} diff --git a/tests/auto/quickcontrols2/qquickpopup/data/rotatedCombobox.qml b/tests/auto/quickcontrols2/qquickpopup/data/rotatedCombobox.qml new file mode 100644 index 0000000000..df217be4b7 --- /dev/null +++ b/tests/auto/quickcontrols2/qquickpopup/data/rotatedCombobox.qml @@ -0,0 +1,26 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick +import QtQuick.Controls + +Window { + width: 400 + height: 400 + + contentItem.rotation: 90 + + ComboBox { + objectName: "first" + x: 100 + y: 320 // is missing space, needs to unroll in the "mirrored" direction + model: ["First", "Second", "Third", "Fourth", "Fifth"] + } + + ComboBox { + objectName: "second" + x: 200 + y: 100 // has enough space to unroll + model: ["A", "B", "C"] + } +} diff --git a/tests/auto/quickcontrols2/qquickpopup/data/window-wheel.qml b/tests/auto/quickcontrols2/qquickpopup/data/window-wheel.qml index 315c3f2a78..ae9c2ecdfd 100644 --- a/tests/auto/quickcontrols2/qquickpopup/data/window-wheel.qml +++ b/tests/auto/quickcontrols2/qquickpopup/data/window-wheel.qml @@ -11,6 +11,7 @@ Window { height: 400 property alias popup: popup + property alias nestedPopup: nestedPopup property alias popupSlider: popupSlider property alias contentSlider: contentSlider @@ -30,5 +31,13 @@ Window { id: popupSlider wheelEnabled: true } + + Popup { + id: nestedPopup + x: 0; y: 0 + clip: true + implicitWidth: 50 + implicitHeight: 50 + } } } diff --git a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp index 5b14c6b867..c6e491618d 100644 --- a/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp +++ b/tests/auto/quickcontrols2/qquickpopup/tst_qquickpopup.cpp @@ -11,6 +11,7 @@ #include <QtQuick/qquickview.h> #include <QtQuick/private/qquickpalette_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtQuickTestUtils/private/viewtestutils_p.h> #include <QtQuickTestUtils/private/visualtestutils_p.h> #include <QtQuickTemplates2/private/qquickapplicationwindow_p.h> #include <QtQuickTemplates2/private/qquickcombobox_p.h> @@ -64,6 +65,7 @@ private slots: void wheel(); void parentDestroyed(); void nested(); + void nestedWheel(); void modelessOnModalOnModeless(); void grabber(); void cursorShape(); @@ -87,11 +89,16 @@ private slots: void dimmerContainmentMask(); void shrinkPopupThatWasLargerThanWindow_data(); void shrinkPopupThatWasLargerThanWindow(); + void mirroredCombobox(); + void rotatedCombobox(); private: static bool hasWindowActivation(); + QScopedPointer<QPointingDevice> touchScreen = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); }; +using namespace Qt::StringLiterals; + tst_QQuickPopup::tst_QQuickPopup() : QQmlDataTest(QT_QMLTEST_DATADIR) { @@ -176,18 +183,18 @@ void tst_QQuickPopup::state() QVERIFY(closedSpy.isValid()); popup->open(); - QCOMPARE(visibleChangedSpy.count(), 1); - QCOMPARE(aboutToShowSpy.count(), 1); - QCOMPARE(aboutToHideSpy.count(), 0); - QTRY_COMPARE(openedSpy.count(), 1); - QCOMPARE(closedSpy.count(), 0); + QCOMPARE(visibleChangedSpy.size(), 1); + QCOMPARE(aboutToShowSpy.size(), 1); + QCOMPARE(aboutToHideSpy.size(), 0); + QTRY_COMPARE(openedSpy.size(), 1); + QCOMPARE(closedSpy.size(), 0); popup->close(); - QTRY_COMPARE(visibleChangedSpy.count(), 2); - QCOMPARE(aboutToShowSpy.count(), 1); - QCOMPARE(aboutToHideSpy.count(), 1); - QCOMPARE(openedSpy.count(), 1); - QTRY_COMPARE(closedSpy.count(), 1); + QTRY_COMPARE(visibleChangedSpy.size(), 2); + QCOMPARE(aboutToShowSpy.size(), 1); + QCOMPARE(aboutToHideSpy.size(), 1); + QCOMPARE(openedSpy.size(), 1); + QTRY_COMPARE(closedSpy.size(), 1); } void tst_QQuickPopup::overlay_data() @@ -213,7 +220,6 @@ void tst_QQuickPopup::overlay() QFETCH(bool, modal); QFETCH(bool, dim); - QScopedPointer<QPointingDevice> device(QTest::createTouchDevice()); QQuickControlsApplicationHelper helper(this, source); QVERIFY2(helper.ready, helper.failureMessage()); @@ -232,8 +238,8 @@ void tst_QQuickPopup::overlay() QVERIFY(!overlay->isVisible()); // no popups open QTest::mouseClick(window, Qt::LeftButton); - QCOMPARE(overlayPressedSignal.count(), 0); - QCOMPARE(overlayReleasedSignal.count(), 0); + QCOMPARE(overlayPressedSignal.size(), 0); + QCOMPARE(overlayReleasedSignal.size(), 0); QQuickPopup *popup = window->property("popup").value<QQuickPopup*>(); QVERIFY(popup); @@ -259,19 +265,19 @@ void tst_QQuickPopup::overlay() QTRY_VERIFY(popup->isOpened()); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), ++overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); // no modal-popups open - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); // no modal-popups open + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); popup->setDim(dim); popup->setModal(modal); @@ -284,16 +290,16 @@ void tst_QQuickPopup::overlay() QTRY_VERIFY(popup->isOpened()); QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), ++overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), ++overlayReleaseCount); - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), ++overlayReleaseCount); + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); @@ -304,17 +310,17 @@ void tst_QQuickPopup::overlay() QVERIFY(overlay->isVisible()); QTRY_VERIFY(popup->isOpened()); - QTest::touchEvent(window, device.data()).press(0, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QTest::touchEvent(window, touchScreen.data()).press(0, QPoint(1, 1)); + QCOMPARE(overlayPressedSignal.size(), ++overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); - QTest::touchEvent(window, device.data()).release(0, QPoint(1, 1)); - QCOMPARE(overlayPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), ++overlayReleaseCount); - QCOMPARE(overlayAttachedPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayAttachedReleasedSignal.count(), overlayReleaseCount); + QTest::touchEvent(window, touchScreen.data()).release(0, QPoint(1, 1)); + QCOMPARE(overlayPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), ++overlayReleaseCount); + QCOMPARE(overlayAttachedPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayAttachedReleasedSignal.size(), overlayReleaseCount); QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); @@ -326,33 +332,33 @@ void tst_QQuickPopup::overlay() QVERIFY(!button->isPressed()); QTRY_VERIFY(popup->isOpened()); - QTest::touchEvent(window, device.data()).press(0, button->mapToScene(QPointF(1, 1)).toPoint()); + QTest::touchEvent(window, touchScreen.data()).press(0, button->mapToScene(QPointF(1, 1)).toPoint()); QVERIFY(popup->isVisible()); QVERIFY(overlay->isVisible()); QCOMPARE(button->isPressed(), !modal); - QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), ++overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); - QTest::touchEvent(window, device.data()).stationary(0).press(1, button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); + QTest::touchEvent(window, touchScreen.data()).stationary(0).press(1, button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); QVERIFY(popup->isVisible()); QVERIFY(overlay->isVisible()); QCOMPARE(button->isPressed(), !modal); - QCOMPARE(overlayPressedSignal.count(), ++overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), ++overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); - QTest::touchEvent(window, device.data()).release(0, button->mapToScene(QPointF(1, 1)).toPoint()).stationary(1); + QTest::touchEvent(window, touchScreen.data()).release(0, button->mapToScene(QPointF(1, 1)).toPoint()).stationary(1); QTRY_VERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); QVERIFY(!button->isPressed()); - QCOMPARE(overlayPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), ++overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), ++overlayReleaseCount); - QTest::touchEvent(window, device.data()).release(1, button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); + QTest::touchEvent(window, touchScreen.data()).release(1, button->mapToScene(QPointF(button->width() / 2, button->height() / 2)).toPoint()); QVERIFY(!popup->isVisible()); QVERIFY(!overlay->isVisible()); QVERIFY(!button->isPressed()); - QCOMPARE(overlayPressedSignal.count(), overlayPressCount); - QCOMPARE(overlayReleasedSignal.count(), overlayReleaseCount); + QCOMPARE(overlayPressedSignal.size(), overlayPressCount); + QCOMPARE(overlayReleasedSignal.size(), overlayReleaseCount); } void tst_QQuickPopup::zOrder_data() @@ -405,40 +411,40 @@ void tst_QQuickPopup::windowChange() QQuickItem item; popup.setParentItem(&item); QVERIFY(!popup.window()); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QQuickWindow window; item.setParentItem(window.contentItem()); QCOMPARE(popup.window(), &window); - QCOMPARE(spy.count(), 1); + QCOMPARE(spy.size(), 1); item.setParentItem(nullptr); QVERIFY(!popup.window()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); popup.setParentItem(window.contentItem()); QCOMPARE(popup.window(), &window); - QCOMPARE(spy.count(), 3); + QCOMPARE(spy.size(), 3); popup.resetParentItem(); QVERIFY(!popup.window()); - QCOMPARE(spy.count(), 4); + QCOMPARE(spy.size(), 4); popup.setParent(&window); popup.resetParentItem(); QCOMPARE(popup.window(), &window); - QCOMPARE(spy.count(), 5); + QCOMPARE(spy.size(), 5); popup.setParent(this); popup.resetParentItem(); QVERIFY(!popup.window()); - QCOMPARE(spy.count(), 6); + QCOMPARE(spy.size(), 6); item.setParentItem(window.contentItem()); popup.setParent(&item); popup.resetParentItem(); QCOMPARE(popup.window(), &window); - QCOMPARE(spy.count(), 7); + QCOMPARE(spy.size(), 7); popup.setParent(nullptr); } @@ -448,25 +454,44 @@ Q_DECLARE_METATYPE(QQuickPopup::ClosePolicy) void tst_QQuickPopup::closePolicy_data() { qRegisterMetaType<QQuickPopup::ClosePolicy>(); + const auto *mouse = QPointingDevice::primaryPointingDevice(); + const auto *touch = touchScreen.data(); QTest::addColumn<QString>("source"); + QTest::addColumn<const QPointingDevice *>("device"); QTest::addColumn<QQuickPopup::ClosePolicy>("closePolicy"); - QTest::newRow("Window:NoAutoClose") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); - QTest::newRow("Window:CloseOnPressOutside") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); - QTest::newRow("Window:CloseOnPressOutsideParent") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); - QTest::newRow("Window:CloseOnPressOutside|Parent") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); - QTest::newRow("Window:CloseOnReleaseOutside") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); - QTest::newRow("Window:CloseOnReleaseOutside|Parent") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); - QTest::newRow("Window:CloseOnEscape") << "window.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); - - QTest::newRow("ApplicationWindow:NoAutoClose") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); - QTest::newRow("ApplicationWindow:CloseOnPressOutside") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); - QTest::newRow("ApplicationWindow:CloseOnPressOutsideParent") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); - QTest::newRow("ApplicationWindow:CloseOnPressOutside|Parent") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); - QTest::newRow("ApplicationWindow:CloseOnReleaseOutside") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); - QTest::newRow("ApplicationWindow:CloseOnReleaseOutside|Parent") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); - QTest::newRow("ApplicationWindow:CloseOnEscape") << "applicationwindow.qml"<< static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); + QTest::newRow("Window:NoAutoClose mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); + QTest::newRow("Window:CloseOnPressOutside mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); + QTest::newRow("Window:CloseOnPressOutsideParent mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("Window:CloseOnPressOutside|Parent mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("Window:CloseOnReleaseOutside mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); + QTest::newRow("Window:CloseOnReleaseOutside|Parent mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); + QTest::newRow("Window:CloseOnEscape mouse") << "window.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); + + QTest::newRow("ApplicationWindow:NoAutoClose mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); + QTest::newRow("ApplicationWindow:CloseOnPressOutside mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); + QTest::newRow("ApplicationWindow:CloseOnPressOutsideParent mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnPressOutside|Parent mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnReleaseOutside mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); + QTest::newRow("ApplicationWindow:CloseOnReleaseOutside|Parent mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnEscape mouse") << "applicationwindow.qml" << mouse << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); + + QTest::newRow("Window:NoAutoClose touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); + QTest::newRow("Window:CloseOnPressOutside touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); + QTest::newRow("Window:CloseOnPressOutsideParent touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("Window:CloseOnPressOutside|Parent touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("Window:CloseOnReleaseOutside touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); + QTest::newRow("Window:CloseOnReleaseOutside|Parent touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); + QTest::newRow("Window:CloseOnEscape touch") << "window.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); + + QTest::newRow("ApplicationWindow:NoAutoClose touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::NoAutoClose); + QTest::newRow("ApplicationWindow:CloseOnPressOutside touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside); + QTest::newRow("ApplicationWindow:CloseOnPressOutsideParent touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnPressOutside|Parent touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnPressOutside | QQuickPopup::CloseOnPressOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnReleaseOutside touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside); + QTest::newRow("ApplicationWindow:CloseOnReleaseOutside|Parent touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnReleaseOutside | QQuickPopup::CloseOnReleaseOutsideParent); + QTest::newRow("ApplicationWindow:CloseOnEscape touch") << "applicationwindow.qml" << touch << static_cast<QQuickPopup::ClosePolicy>(QQuickPopup::CloseOnEscape); } void tst_QQuickPopup::closePolicy() @@ -475,6 +500,7 @@ void tst_QQuickPopup::closePolicy() QSKIP("Window activation is not supported"); QFETCH(QString, source); + QFETCH(const QPointingDevice *, device); QFETCH(QQuickPopup::ClosePolicy, closePolicy); QQuickControlsApplicationHelper helper(this, source); @@ -502,56 +528,58 @@ void tst_QQuickPopup::closePolicy() // wait for dimmer QTest::qWait(50); - // press outside popup and its parent - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) || closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) - QTRY_VERIFY(!popup->isVisible()); - else - QVERIFY(popup->isOpened()); + for (int i = 0; i < 2; ++i) { + // press outside popup and its parent + QQuickTest::pointerPress(device, window, 0, {1, 1}); + if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) || closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) + QTRY_VERIFY(!popup->isVisible()); + else + QVERIFY(popup->isOpened()); - popup->open(); - QVERIFY(popup->isVisible()); - QTRY_VERIFY(popup->isOpened()); + popup->open(); + QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); - // release outside popup and its parent - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) || closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent)) - QTRY_VERIFY(!popup->isVisible()); - else - QVERIFY(popup->isOpened()); + // release outside popup and its parent + QQuickTest::pointerRelease(device, window, 0, {1, 1}); + if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) || closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent)) + QTRY_VERIFY(!popup->isVisible()); + else + QVERIFY(popup->isOpened()); - popup->open(); - QVERIFY(popup->isVisible()); - QTRY_VERIFY(popup->isOpened()); + popup->open(); + QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); - // press outside popup but inside its parent - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + 1, button->y() + 1)); - if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) - QTRY_VERIFY(!popup->isVisible()); - else - QVERIFY(popup->isOpened()); + // press outside popup but inside its parent + QQuickTest::pointerPress(device, window, 0, QPoint(button->x() + 1, button->y() + 1)); + if (closePolicy.testFlag(QQuickPopup::CloseOnPressOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnPressOutsideParent)) + QTRY_VERIFY(!popup->isVisible()); + else + QVERIFY(popup->isOpened()); - popup->open(); - QVERIFY(popup->isVisible()); - QTRY_VERIFY(popup->isOpened()); + popup->open(); + QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); - // release outside popup but inside its parent - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + 1, button->y() + 1)); - if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent)) - QTRY_VERIFY(!popup->isVisible()); - else - QVERIFY(popup->isOpened()); + // release outside popup but inside its parent + QQuickTest::pointerRelease(device, window, 0, QPoint(button->x() + 1, button->y() + 1)); + if (closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutside) && !closePolicy.testFlag(QQuickPopup::CloseOnReleaseOutsideParent)) + QTRY_VERIFY(!popup->isVisible()); + else + QVERIFY(popup->isOpened()); - popup->open(); - QVERIFY(popup->isVisible()); - QTRY_VERIFY(popup->isOpened()); + popup->open(); + QVERIFY(popup->isVisible()); + QTRY_VERIFY(popup->isOpened()); - // press inside and release outside - QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, QPoint(button->x() + popup->x() + 1, - button->y() + popup->y() + 1)); - QVERIFY(popup->isOpened()); - QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1)); - QVERIFY(popup->isOpened()); + // press inside and release outside + QQuickTest::pointerPress(device, window, 0, QPoint(button->x() + popup->x() + 1, + button->y() + popup->y() + 1)); + QVERIFY(popup->isOpened()); + QQuickTest::pointerRelease(device, window, 0, {1, 1}); + QVERIFY(popup->isOpened()); + } // escape QTest::keyClick(window, Qt::Key_Escape); @@ -945,7 +973,7 @@ void tst_QQuickPopup::hover() QSignalSpy openedSpy(popup, SIGNAL(opened())); QVERIFY(openedSpy.isValid()); popup->open(); - QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + QVERIFY(openedSpy.size() == 1 || openedSpy.wait()); QTRY_VERIFY(popup->width() > 10); // somehow this can take a short time with macOS style // hover the parent button outside the popup @@ -966,7 +994,7 @@ void tst_QQuickPopup::hover() QSignalSpy closedSpy(popup, SIGNAL(closed())); QVERIFY(closedSpy.isValid()); popup->close(); - QVERIFY(closedSpy.count() == 1 || closedSpy.wait()); + QVERIFY(closedSpy.size() == 1 || closedSpy.wait()); // hover the parent button after closing the popup QTest::mouseMove(window, QPoint(window->width() / 2, window->height() / 2)); @@ -984,16 +1012,23 @@ void tst_QQuickPopup::wheel_data() QTest::newRow("ApplicationWindow:modeless") << "applicationwindow-wheel.qml" << false; } -static bool sendWheelEvent(QQuickItem *item, const QPoint &localPos, int degrees) +static bool sendWheelEvent(QQuickItem *item, const QPointF &localPos, int degrees) { QQuickWindow *window = item->window(); - QWheelEvent wheelEvent(localPos, item->window()->mapToGlobal(localPos), QPoint(0, 0), + const QPoint scenePos = item->mapToScene(localPos).toPoint(); + QWheelEvent wheelEvent(scenePos, window->mapToGlobal(scenePos), QPoint(0, 0), QPoint(0, 8 * degrees), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QSpontaneKeyEvent::setSpontaneous(&wheelEvent); return qGuiApp->notify(window, &wheelEvent); } +static bool sendWheelEvent(QQuickItem *item, int degrees) +{ + const QPointF localPos = QPointF(item->width() / 2, item->height() / 2); + return sendWheelEvent(item, localPos, degrees); +} + void tst_QQuickPopup::wheel() { QFETCH(QString, source); @@ -1012,6 +1047,10 @@ void tst_QQuickPopup::wheel() QVERIFY(popup && popup->contentItem()); popup->setModal(modal); + QQuickPopup *nestedPopup = window->property("nestedPopup").value<QQuickPopup*>(); + QVERIFY(nestedPopup && nestedPopup->contentItem()); + nestedPopup->setModal(modal); + QQuickSlider *popupSlider = window->property("popupSlider").value<QQuickSlider*>(); QVERIFY(popupSlider); @@ -1020,7 +1059,7 @@ void tst_QQuickPopup::wheel() qreal oldContentValue = contentSlider->value(); qreal oldPopupValue = popupSlider->value(); - QVERIFY(sendWheelEvent(contentSlider, QPoint(contentSlider->width() / 2, contentSlider->height() / 2), 15)); + QVERIFY(sendWheelEvent(contentSlider, 15)); QVERIFY(!qFuzzyCompare(contentSlider->value(), oldContentValue)); // must have moved QVERIFY(qFuzzyCompare(popupSlider->value(), oldPopupValue)); // must not have moved @@ -1029,25 +1068,41 @@ void tst_QQuickPopup::wheel() QSignalSpy openedSpy(popup, SIGNAL(opened())); QVERIFY(openedSpy.isValid()); popup->open(); - QVERIFY(openedSpy.count() == 1 || openedSpy.wait()); + QVERIFY(openedSpy.size() == 1 || openedSpy.wait()); { // wheel over the popup content qreal oldContentValue = contentSlider->value(); qreal oldPopupValue = popupSlider->value(); - QVERIFY(sendWheelEvent(popupSlider, QPoint(popupSlider->width() / 2, popupSlider->height() / 2), 15)); + QVERIFY(sendWheelEvent(popupSlider, 15)); QVERIFY(qFuzzyCompare(contentSlider->value(), oldContentValue)); // must not have moved QVERIFY(!qFuzzyCompare(popupSlider->value(), oldPopupValue)); // must have moved } + QSignalSpy nestedOpenedSpy(nestedPopup, SIGNAL(opened())); + QVERIFY(nestedOpenedSpy.isValid()); + nestedPopup->open(); + QVERIFY(nestedOpenedSpy.size() == 1 || nestedOpenedSpy.wait()); + + { + // wheel over the popup content + qreal oldContentValue = contentSlider->value(); + qreal oldPopupValue = popupSlider->value(); + + QVERIFY(sendWheelEvent(popupSlider, 15)); + + QVERIFY(qFuzzyCompare(contentSlider->value(), oldContentValue)); // must not have moved + QCOMPARE(qFuzzyCompare(popupSlider->value(), oldPopupValue), modal); // must not have moved unless modeless + } + { // wheel over the overlay qreal oldContentValue = contentSlider->value(); qreal oldPopupValue = popupSlider->value(); - QVERIFY(sendWheelEvent(QQuickOverlay::overlay(window), QPoint(0, 0), 15)); + QVERIFY(sendWheelEvent(QQuickOverlay::overlay(window), QPointF(0, 0), 15)); if (modal) { // the content below a modal overlay must not move @@ -1097,6 +1152,36 @@ void tst_QQuickPopup::nested() QCOMPARE(modalPopup->isVisible(), true); } +void tst_QQuickPopup::nestedWheel() +{ + QQuickControlsApplicationHelper helper(this, QStringLiteral("nested-wheel.qml")); + QVERIFY2(helper.ready, helper.failureMessage()); + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickPopup *modalPopup = window->property("modalPopup").value<QQuickPopup *>(); + QVERIFY(modalPopup); + + QQuickComboBox *comboBox = window->property("comboBox").value<QQuickComboBox *>(); + QVERIFY(comboBox); + + const QPoint comboBoxCenter = comboBox->mapToScene( + QPointF(comboBox->width() / 2, comboBox->height() / 2)).toPoint(); + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, comboBoxCenter); + QTRY_VERIFY(comboBox->popup()->isOpened()); + + QQuickItem *listView = comboBox->popup()->contentItem(); + QVERIFY(listView); + QQuickItem *vbar = listView->findChild<QQuickItem *>("vbar"); + QVERIFY(vbar); + + const double startPosition = vbar->property("position").toDouble(); + // wheel over the list view, verify that it scrolls + sendWheelEvent(listView, -30); + QTRY_COMPARE_GT(vbar->property("position").toDouble(), startPosition); +} + void tst_QQuickPopup::modelessOnModalOnModeless() { QQuickControlsApplicationHelper helper(this, QStringLiteral("modelessOnModalOnModeless.qml")); @@ -1353,12 +1438,12 @@ void tst_QQuickPopup::enabled() popup.setEnabled(false); QVERIFY(!popup.isEnabled()); QVERIFY(!popup.popupItem()->isEnabled()); - QCOMPARE(enabledSpy.count(), 1); + QCOMPARE(enabledSpy.size(), 1); popup.popupItem()->setEnabled(true); QVERIFY(popup.isEnabled()); QVERIFY(popup.popupItem()->isEnabled()); - QCOMPARE(enabledSpy.count(), 2); + QCOMPARE(enabledSpy.size(), 2); } void tst_QQuickPopup::orientation_data() @@ -1477,15 +1562,15 @@ void tst_QQuickPopup::disabledPalette() auto palette = QQuickPopupPrivate::get(popup)->palette(); palette->setBase(Qt::green); palette->disabled()->setBase(Qt::red); - QCOMPARE(popupPaletteSpy.count(), 2); - QCOMPARE(popupItemPaletteSpy.count(), 2); + QCOMPARE(popupPaletteSpy.size(), 2); + QCOMPARE(popupItemPaletteSpy.size(), 2); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::green); popup->setEnabled(false); - QCOMPARE(popupEnabledSpy.count(), 1); - QCOMPARE(popupItemEnabledSpy.count(), 1); - QCOMPARE(popupPaletteSpy.count(), 3); - QCOMPARE(popupItemPaletteSpy.count(), 3); + QCOMPARE(popupEnabledSpy.size(), 1); + QCOMPARE(popupItemEnabledSpy.size(), 1); + QCOMPARE(popupPaletteSpy.size(), 3); + QCOMPARE(popupItemPaletteSpy.size(), 3); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::red); } @@ -1517,8 +1602,8 @@ void tst_QQuickPopup::disabledParentPalette() auto palette = QQuickPopupPrivate::get(popup)->palette(); palette->setBase(Qt::green); palette->disabled()->setBase(Qt::red); - QCOMPARE(popupPaletteSpy.count(), 2); - QCOMPARE(popupItemPaletteSpy.count(), 2); + QCOMPARE(popupPaletteSpy.size(), 2); + QCOMPARE(popupItemPaletteSpy.size(), 2); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::green); // Disable the overlay (which is QQuickPopupItem's parent) to ensure that @@ -1529,10 +1614,10 @@ void tst_QQuickPopup::disabledParentPalette() QVERIFY(!popup->isEnabled()); QVERIFY(!popup->popupItem()->isEnabled()); QCOMPARE(popup->background()->property("color").value<QColor>(), Qt::red); - QCOMPARE(popupEnabledSpy.count(), 1); - QCOMPARE(popupItemEnabledSpy.count(), 1); - QCOMPARE(popupPaletteSpy.count(), 3); - QCOMPARE(popupItemPaletteSpy.count(), 3); + QCOMPARE(popupEnabledSpy.size(), 1); + QCOMPARE(popupItemEnabledSpy.size(), 1); + QCOMPARE(popupPaletteSpy.size(), 3); + QCOMPARE(popupItemPaletteSpy.size(), 3); popup->close(); QTRY_VERIFY(!popup->isVisible()); @@ -1690,7 +1775,7 @@ void tst_QQuickPopup::invisibleToolTipOpen() QVERIFY(componentLoadedSpy.isValid()); loader->setProperty("active", true); - QTRY_COMPARE(componentLoadedSpy.count(), 1); + QTRY_COMPARE(componentLoadedSpy.size(), 1); QTRY_VERIFY(toolTip->isVisible()); } @@ -1884,6 +1969,155 @@ void tst_QQuickPopup::shrinkPopupThatWasLargerThanWindow() .arg(popup->height()).arg(window->height()))); } +void tst_QQuickPopup::mirroredCombobox() +{ +#ifdef Q_OS_ANDROID + // Android screens might be pretty small, such that additional + // repositioning (apart from the mirroring) will happen to the + // popups and mess up the expected positions below. + QSKIP("Skipping test for Android."); +#endif + QStringList nativeStyles; + nativeStyles.append(u"macOS"_s); + nativeStyles.append(u"iOS"_s); + nativeStyles.append(u"Windows"_s); + if (nativeStyles.contains(QQuickStyle::name())) + QSKIP("Skipping test for native styles: they might rearrange their combobox the way they " + "want."); + + QQuickControlsApplicationHelper helper(this, "mirroredCombobox.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("first"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + const QSizeF popupSize(popup->contentItem()->size()); + + // ignore popup.{top,bottom}Padding() as not included in popup->contentItem()->size() + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = + comboBox->position().y() - popupSize.height() + comboBox->size().height() + == popupPos.y(); + // some styles prefer to draw the popup below (in y-axis direction) the combobox + const bool styleDrawsPopupBelowCombobox = + comboBox->position().y() - popupSize.height() + comboBox->topPadding() + == popupPos.y(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupBelowCombobox); + + popup->close(); + } + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("second"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = comboBox->position().y() + comboBox->topPadding() + + popup->topPadding() + popup->bottomPadding() + == popupPos.y(); + // some styles prefer to draw the popup above (in y-axis direction) the combobox + const bool styleDrawsPopupAboveCombobox = + comboBox->position().y() + comboBox->height() - comboBox->topPadding() + == popupPos.y(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupAboveCombobox); + + popup->close(); + } +} + +void tst_QQuickPopup::rotatedCombobox() +{ +#ifdef Q_OS_ANDROID + // Android screens might be pretty small, such that additional + // repositioning (apart from the rotating) will happen to the + // popups and mess up the expected positions below. + QSKIP("Skipping test for Android."); +#endif + QStringList nativeStyles; + nativeStyles.append(u"macOS"_s); + nativeStyles.append(u"iOS"_s); + nativeStyles.append(u"Windows"_s); + if (nativeStyles.contains(QQuickStyle::name())) + QSKIP("Skipping test for native styles: they might rearrange their combobox the way they " + "want."); + + QQuickControlsApplicationHelper helper(this, "rotatedCombobox.qml"); + QVERIFY2(helper.ready, helper.failureMessage()); + + QQuickWindow *window = helper.window; + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("first"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + const QSizeF popupSize(popup->contentItem()->size()); + + // ignore popup.{left,right}Padding() as not included in popup->contentItem()->size() + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = + comboBox->position().x() - popupSize.width() + comboBox->width() == popupPos.x(); + // some styles prefer to draw the popup right (in x-axis direction) of the combobox + const bool styleDrawsPopupBelowCombobox = + comboBox->position().x() - popupSize.width() - comboBox->leftPadding() + == popupPos.x(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupBelowCombobox); + } + + { + QQuickComboBox *comboBox = window->findChild<QQuickComboBox *>("second"); + QVERIFY(comboBox); + QQuickPopup *popup = comboBox->popup(); + QVERIFY(popup); + popup->open(); + QTRY_COMPARE(popup->isVisible(), true); + const QPointF popupPos(popup->contentItem()->mapToItem(comboBox->parentItem(), + popup->contentItem()->position())); + + // some styles prefer to draw the popup "over" (in z-axis direction) the combobox to hide + // the combobox + const bool styleDrawsPopupOverCombobox = comboBox->position().x() + comboBox->leftPadding() + + popup->leftPadding() + popup->rightPadding() + == popupPos.x(); + // some styles prefer to draw the popup left (in y-axis direction) of the combobox + const bool styleDrawsPopupAboveCombobox = + comboBox->position().x() + comboBox->width() - comboBox->leftPadding() + == popupPos.x(); + + QVERIFY(styleDrawsPopupOverCombobox || styleDrawsPopupAboveCombobox); + + popup->close(); + } +} + QTEST_QUICKCONTROLS_MAIN(tst_QQuickPopup) #include "tst_qquickpopup.moc" diff --git a/tests/auto/quickcontrols2/qquicktextarea/CMakeLists.txt b/tests/auto/quickcontrols2/qquicktextarea/CMakeLists.txt new file mode 100644 index 0000000000..553a1588ae --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +##################################################################### +## tst_qquicktextarea Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qquicktextarea + SOURCES + tst_qquicktextarea.cpp + DEFINES + QQC2_IMPORT_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/quickcontrols2\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::QmlPrivate + Qt::QuickControls2 + Qt::QuickControls2Private + Qt::QuickControlsTestUtilsPrivate + Qt::QuickPrivate + Qt::QuickTemplates2Private + Qt::QuickTest + Qt::QuickTestUtilsPrivate + Qt::TestPrivate + TESTDATA ${test_data} +) + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_qquicktextarea CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qquicktextarea CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_default.qml b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_default.qml new file mode 100644 index 0000000000..cb51b80545 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_default.qml @@ -0,0 +1,6 @@ +import QtQuick.Controls + +TextArea { + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + diff --git a/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_default.qml b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_default.qml new file mode 100644 index 0000000000..1401be36c1 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_default.qml @@ -0,0 +1,6 @@ +import QtQuick +import QtQuick.Controls 6.3 + +TextArea { + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} diff --git a/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_overridden.qml b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_overridden.qml new file mode 100644 index 0000000000..c0e6fb60a8 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/data/mouseselection_old_overridden.qml @@ -0,0 +1,7 @@ +import QtQuick +import QtQuick.Controls 6.3 + +TextArea { + selectByMouse: true + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} diff --git a/tests/auto/quickcontrols2/qquicktextarea/data/twoInAColumn.qml b/tests/auto/quickcontrols2/qquicktextarea/data/twoInAColumn.qml new file mode 100644 index 0000000000..944f5598ac --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/data/twoInAColumn.qml @@ -0,0 +1,35 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +ColumnLayout { + height: 200 + width: 400 + spacing: -6 + Rectangle { + border.color: top.activeFocus ? "steelblue" : "lightgrey" + Layout.fillHeight: true + Layout.fillWidth: true + Layout.margins: 6 + TextArea { + id: top + objectName: "top" + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + anchors.fill: parent + verticalAlignment: TextArea.AlignTop + } + } + Rectangle { + border.color: bottom.activeFocus ? "steelblue" : "lightgrey" + Layout.fillHeight: true + Layout.fillWidth: true + Layout.margins: 6 + TextArea { + id: bottom + objectName: "bottom" + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + anchors.fill: parent + verticalAlignment: TextArea.AlignTop + } + } +} diff --git a/tests/auto/quickcontrols2/qquicktextarea/tst_qquicktextarea.cpp b/tests/auto/quickcontrols2/qquicktextarea/tst_qquicktextarea.cpp new file mode 100644 index 0000000000..1c40b078f7 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextarea/tst_qquicktextarea.cpp @@ -0,0 +1,166 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QtTest/qtest.h> +#include <QtTest/qsignalspy.h> +#include <QtTest/qtesttouch.h> + +#include <QtGui/qfontmetrics.h> +#include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformintegration.h> +#include <QtGui/qtestsupport_gui.h> +#include <QtQuick/qquickview.h> +#include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtQuickTestUtils/private/viewtestutils_p.h> +#include <QtQuickTemplates2/private/qquicktextarea_p.h> +#include <QtQuickControlsTestUtils/private/qtest_quickcontrols_p.h> + +class tst_QQuickTextArea : public QQmlDataTest +{ + Q_OBJECT + +public: + tst_QQuickTextArea(); + +private slots: + void initTestCase() override; + void touchscreenDoesNotSelect_data(); + void touchscreenDoesNotSelect(); + void touchscreenSetsFocusAndMovesCursor(); + +private: + static bool hasWindowActivation(); + QScopedPointer<QPointingDevice> touchDevice = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); +}; + +tst_QQuickTextArea::tst_QQuickTextArea() + : QQmlDataTest(QT_QMLTEST_DATADIR) +{ +} + +void tst_QQuickTextArea::initTestCase() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() > 23) + QSKIP("Crashes on Android 7+, figure out why (QTBUG-107028)"); +#endif + QQmlDataTest::initTestCase(); + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); +} + +void tst_QQuickTextArea::touchscreenDoesNotSelect_data() +{ + QTest::addColumn<QUrl>("src"); + QTest::addColumn<bool>("setEnv"); + QTest::addColumn<bool>("selectByMouse"); + QTest::addColumn<bool>("selectByTouch"); + QTest::newRow("new default") << testFileUrl("mouseselection_default.qml") << false << true << false; +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + QTest::newRow("putenv") << testFileUrl("mouseselection_default.qml") << true << false << false; + QTest::newRow("old_import") << testFileUrl("mouseselection_old_default.qml") << false << true << false; + QTest::newRow("old+putenv") << testFileUrl("mouseselection_old_default.qml") << true << false << false; + QTest::newRow("old+putenv+selectByMouse") << testFileUrl("mouseselection_old_overridden.qml") << true << true << true; +#endif +} + +void tst_QQuickTextArea::touchscreenDoesNotSelect() +{ + QFETCH(QUrl, src); + QFETCH(bool, setEnv); + QFETCH(bool, selectByMouse); + QFETCH(bool, selectByTouch); + + if (setEnv) + qputenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR", "old"); + else + qunsetenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR"); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, src)); + + QQuickTextEdit *textEditObject = qobject_cast<QQuickTextEdit *>(window.rootObject()); + QVERIFY(textEditObject != nullptr); + QCOMPARE(textEditObject->selectByMouse(), selectByMouse); + textEditObject->setSelectByMouse(true); // enable selection with pre-6.4 import version + QVERIFY(textEditObject->selectedText().isEmpty()); + + if (selectByMouse) { + // press-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = QFontMetrics(textEditObject->font()).height() / 2; + QTest::touchEvent(&window, touchDevice.data()).press(0, QPoint(x1,y), &window); + QTest::touchEvent(&window, touchDevice.data()).move(0, QPoint(x2,y), &window); + QTest::touchEvent(&window, touchDevice.data()).release(0, QPoint(x2,y), &window); + QQuickTouchUtils::flush(&window); + // if the import version is old enough, fall back to old behavior: touch swipe _does_ select text if selectByMouse is true + QCOMPARE(textEditObject->selectedText().isEmpty(), !selectByTouch); + } +} + +void tst_QQuickTextArea::touchscreenSetsFocusAndMovesCursor() +{ + if (!hasWindowActivation()) + QSKIP("Window activation is not supported"); + qunsetenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR"); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, testFileUrl("twoInAColumn.qml"))); + window.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + QQuickTextEdit *top = window.rootObject()->findChild<QQuickTextEdit*>("top"); + QVERIFY(top); + QQuickTextEdit *bottom = window.rootObject()->findChild<QQuickTextEdit*>("bottom"); + QVERIFY(bottom); + const auto len = bottom->text().size(); + + // tap the bottom field + const qreal yOffset = bottom->topPadding() + 6; // where to tap or drag to hit the text + QPoint p1 = bottom->mapToScene({60, yOffset}).toPoint(); + QTest::touchEvent(&window, touchDevice.data()).press(0, p1, &window); + QQuickTouchUtils::flush(&window); + // text cursor is at 0 by default, on press + QCOMPARE(bottom->cursorPosition(), 0); + // the focus changes and the cursor moves after release (not after press, as in TextEdit) + QTest::touchEvent(&window, touchDevice.data()).release(0, p1, &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(qApp->focusObject(), bottom); + QTRY_COMPARE_GT(bottom->cursorPosition(), 0); + + // typing a character inserts it at the cursor position + QVERIFY(!bottom->text().contains('q')); + QTest::keyClick(&window, Qt::Key_Q); + QCOMPARE(bottom->text().size(), len + 1); + QCOMPARE_GT(bottom->text().indexOf('q'), 0); + + // press-drag-and-release from p1 to p2 on the top field + p1 = top->mapToScene({0, yOffset}).toPoint(); + QPoint p2 = top->mapToScene({76, yOffset}).toPoint(); + QTest::touchEvent(&window, touchDevice.data()).press(0, p1, &window); + QQuickTouchUtils::flush(&window); + QTest::touchEvent(&window, touchDevice.data()).move(0, p2, &window); + QQuickTouchUtils::flush(&window); + QTest::touchEvent(&window, touchDevice.data()).release(0, p2, &window); + QQuickTouchUtils::flush(&window); + QCOMPARE(qApp->focusObject(), top); + QVERIFY(top->selectedText().isEmpty()); + QCOMPARE_GT(top->cursorPosition(), 0); + + // touch-drag did not select text, but mouse-drag from p2 back to p1 + // does select the first part of the text, and leave the cursor at the beginning + QTest::mousePress(&window, Qt::LeftButton, {}, p2); + QTest::mouseMove(&window, p1); + QTest::mouseRelease(&window, Qt::LeftButton, {}, p1); + QCOMPARE(top->cursorPosition(), 0); + QCOMPARE_GT(top->selectedText().size(), 0); +} + +bool tst_QQuickTextArea::hasWindowActivation() +{ + return (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::WindowActivation)); +} + +QTEST_QUICKCONTROLS_MAIN(tst_QQuickTextArea) + +#include "tst_qquicktextarea.moc" diff --git a/tests/auto/quickcontrols2/qquicktextfield/CMakeLists.txt b/tests/auto/quickcontrols2/qquicktextfield/CMakeLists.txt new file mode 100644 index 0000000000..953e75d9d8 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextfield/CMakeLists.txt @@ -0,0 +1,46 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +##################################################################### +## tst_qquicktextfield Test: +##################################################################### + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + data/*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_qquicktextfield + SOURCES + tst_qquicktextfield.cpp + DEFINES + QQC2_IMPORT_PATH=\\\"${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/quickcontrols2\\\" + PUBLIC_LIBRARIES + Qt::CorePrivate + Qt::Gui + Qt::GuiPrivate + Qt::QmlPrivate + Qt::QuickControls2 + Qt::QuickControls2Private + Qt::QuickControlsTestUtilsPrivate + Qt::QuickPrivate + Qt::QuickTemplates2Private + Qt::QuickTest + Qt::QuickTestUtilsPrivate + Qt::TestPrivate + TESTDATA ${test_data} +) + +## Scopes: +##################################################################### + +qt_internal_extend_target(tst_qquicktextfield CONDITION ANDROID OR IOS + DEFINES + QT_QMLTEST_DATADIR=\\\":/data\\\" +) + +qt_internal_extend_target(tst_qquicktextfield CONDITION NOT ANDROID AND NOT IOS + DEFINES + QT_QMLTEST_DATADIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}/data\\\" +) diff --git a/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_default.qml b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_default.qml new file mode 100644 index 0000000000..2bcaf2abd4 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_default.qml @@ -0,0 +1,7 @@ +import QtQuick.Controls + +TextField { + width: 400 + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} + diff --git a/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_default.qml b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_default.qml new file mode 100644 index 0000000000..0eb774a322 --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_default.qml @@ -0,0 +1,7 @@ +import QtQuick +import QtQuick.Controls 6.3 + +TextField { + width: 400 + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} diff --git a/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_overridden.qml b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_overridden.qml new file mode 100644 index 0000000000..0e357e032f --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextfield/data/mouseselection_old_overridden.qml @@ -0,0 +1,8 @@ +import QtQuick +import QtQuick.Controls 6.3 + +TextField { + width: 400 + selectByMouse: true + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" +} diff --git a/tests/auto/quickcontrols2/qquicktextfield/tst_qquicktextfield.cpp b/tests/auto/quickcontrols2/qquicktextfield/tst_qquicktextfield.cpp new file mode 100644 index 0000000000..19219bb79e --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktextfield/tst_qquicktextfield.cpp @@ -0,0 +1,101 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include <QtTest/qtest.h> +#include <QtTest/qsignalspy.h> +#include <QtTest/qtesttouch.h> + +#include <QtGui/qfontmetrics.h> +#include <QtGui/private/qguiapplication_p.h> +#include <QtGui/qpa/qplatformintegration.h> +#include <QtGui/qtestsupport_gui.h> +#include <QtQuick/qquickview.h> +#include <QtQuickTestUtils/private/qmlutils_p.h> +#include <QtQuickTestUtils/private/viewtestutils_p.h> +#include <QtQuickTemplates2/private/qquicktextfield_p.h> +#include <QtQuickControlsTestUtils/private/qtest_quickcontrols_p.h> + +class tst_QQuickTextField : public QQmlDataTest +{ + Q_OBJECT + +public: + tst_QQuickTextField(); + +private slots: + void initTestCase() override; + void touchscreenDoesNotSelect_data(); + void touchscreenDoesNotSelect(); + +private: + QScopedPointer<QPointingDevice> touchDevice = QScopedPointer<QPointingDevice>(QTest::createTouchDevice()); +}; + +tst_QQuickTextField::tst_QQuickTextField() + : QQmlDataTest(QT_QMLTEST_DATADIR) +{ +} + +void tst_QQuickTextField::initTestCase() +{ +#ifdef Q_OS_ANDROID + if (QNativeInterface::QAndroidApplication::sdkVersion() > 23) + QSKIP("Crashes on Android 7+, figure out why (QTBUG-107028)"); +#endif + QQmlDataTest::initTestCase(); + qputenv("QML_NO_TOUCH_COMPRESSION", "1"); +} + +void tst_QQuickTextField::touchscreenDoesNotSelect_data() +{ + QTest::addColumn<QUrl>("src"); + QTest::addColumn<bool>("setEnv"); + QTest::addColumn<bool>("selectByMouse"); + QTest::addColumn<bool>("selectByTouch"); + QTest::newRow("new default") << testFileUrl("mouseselection_default.qml") << false << true << false; +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) + QTest::newRow("putenv") << testFileUrl("mouseselection_default.qml") << true << false << false; + QTest::newRow("old_import") << testFileUrl("mouseselection_old_default.qml") << false << true << false; + QTest::newRow("old+putenv") << testFileUrl("mouseselection_old_default.qml") << true << false << false; + QTest::newRow("old+putenv+selectByMouse") << testFileUrl("mouseselection_old_overridden.qml") << true << true << true; +#endif +} + +void tst_QQuickTextField::touchscreenDoesNotSelect() +{ + QFETCH(QUrl, src); + QFETCH(bool, setEnv); + QFETCH(bool, selectByMouse); + QFETCH(bool, selectByTouch); + + if (setEnv) + qputenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR", "old"); + else + qunsetenv("QT_QUICK_CONTROLS_TEXT_SELECTION_BEHAVIOR"); + + QQuickView window; + QVERIFY(QQuickTest::showView(window, src)); + + QQuickTextField *textField = qobject_cast<QQuickTextField *>(window.rootObject()); + QVERIFY(textField != nullptr); + QCOMPARE(textField->selectByMouse(), selectByMouse); + textField->setSelectByMouse(true); // enable selection with pre-6.4 import version + QVERIFY(textField->selectedText().isEmpty()); + + if (selectByMouse) { + // press-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = QFontMetrics(textField->font()).height() / 2; + QTest::touchEvent(&window, touchDevice.data()).press(0, QPoint(x1,y), &window); + QTest::touchEvent(&window, touchDevice.data()).move(0, QPoint(x2,y), &window); + QTest::touchEvent(&window, touchDevice.data()).release(0, QPoint(x2,y), &window); + QQuickTouchUtils::flush(&window); + // if the env var is set, fall back to old behavior: touch swipe _does_ select text if selectByMouse is true + QCOMPARE(textField->selectedText().isEmpty(), !selectByTouch); + } +} + +QTEST_QUICKCONTROLS_MAIN(tst_QQuickTextField) + +#include "tst_qquicktextfield.moc" diff --git a/tests/auto/quickcontrols2/qquicktreeviewdelegate/BLACKLIST b/tests/auto/quickcontrols2/qquicktreeviewdelegate/BLACKLIST new file mode 100644 index 0000000000..ed6d7fd2cf --- /dev/null +++ b/tests/auto/quickcontrols2/qquicktreeviewdelegate/BLACKLIST @@ -0,0 +1,6 @@ +# perhaps related to QTBUG-103072 +[dragToSelect] +android +# perhaps related to QTBUG-103064 +[pressAndHoldToSelect] +android diff --git a/tests/auto/quickcontrols2/qquicktreeviewdelegate/data/unmodified.qml b/tests/auto/quickcontrols2/qquicktreeviewdelegate/data/unmodified.qml index 02d8b39477..c3edb37d1c 100644 --- a/tests/auto/quickcontrols2/qquicktreeviewdelegate/data/unmodified.qml +++ b/tests/auto/quickcontrols2/qquicktreeviewdelegate/data/unmodified.qml @@ -10,6 +10,7 @@ Item { height: 600 property alias treeView: treeView + property alias selectionRectangle: selectionRectangle TreeView { id: treeView @@ -21,4 +22,9 @@ Item { delegate: TreeViewDelegate {} selectionModel: ItemSelectionModel { model: treeView.model } } + + SelectionRectangle { + id: selectionRectangle + target: treeView + } } diff --git a/tests/auto/quickcontrols2/qquicktreeviewdelegate/testmodel.cpp b/tests/auto/quickcontrols2/qquicktreeviewdelegate/testmodel.cpp index 06f7c09b5e..6c6da8452b 100644 --- a/tests/auto/quickcontrols2/qquicktreeviewdelegate/testmodel.cpp +++ b/tests/auto/quickcontrols2/qquicktreeviewdelegate/testmodel.cpp @@ -51,7 +51,7 @@ int TestModel::rowCount(const QModelIndex &parent) const { if (!parent.isValid()) return 1; // root of the tree - return treeItem(parent)->m_childItems.count(); + return treeItem(parent)->m_childItems.size(); } int TestModel::columnCount(const QModelIndex &) const @@ -87,7 +87,7 @@ QModelIndex TestModel::index(int row, int column, const QModelIndex &parent) con if (!hasIndex(row, column, parent)) return QModelIndex(); if (!parent.isValid()) - return createIndex(0, 0, m_rootItem.data()); + return createIndex(row, column, m_rootItem.data()); return createIndex(row, column, treeItem(parent)->m_childItems.at(row)); } diff --git a/tests/auto/quickcontrols2/qquicktreeviewdelegate/tst_qquicktreeviewdelegate.cpp b/tests/auto/quickcontrols2/qquicktreeviewdelegate/tst_qquicktreeviewdelegate.cpp index 79d8619567..834729e133 100644 --- a/tests/auto/quickcontrols2/qquicktreeviewdelegate/tst_qquicktreeviewdelegate.cpp +++ b/tests/auto/quickcontrols2/qquicktreeviewdelegate/tst_qquicktreeviewdelegate.cpp @@ -58,8 +58,11 @@ private slots: void checkPropertiesRoot(); void checkPropertiesChildren(); void checkCurrentIndex(); + void checkClickedSignal_data(); void checkClickedSignal(); void clearSelectionOnClick(); + void dragToSelect(); + void pressAndHoldToSelect(); }; tst_qquicktreeviewdelegate::tst_qquicktreeviewdelegate() @@ -131,32 +134,18 @@ void tst_qquicktreeviewdelegate::expandAndCollapseClickOnIndicator() const QPoint localPos = QPoint(indicator->width() / 2, indicator->height() / 2); const QPoint pos = item->window()->contentItem()->mapFromItem(indicator, localPos).toPoint(); - // When treeview is interactive, we toggle expanded on pointer release - // to not interfere with flicking. Otherwise we expand already on press. - if (interactive) - QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - else - QTest::mousePress(item->window(), Qt::LeftButton, Qt::NoModifier, pos); + QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); WAIT_UNTIL_POLISHED; // We now expect 5 rows, the root pluss it's 4 children QCOMPARE(treeViewPrivate->loadedRows.count(), 5); - if (!interactive) - QTest::mouseRelease(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - // Collapse the root again - if (interactive) - QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - else - QTest::mousePress(item->window(), Qt::LeftButton, Qt::NoModifier, pos); + QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); WAIT_UNTIL_POLISHED; // Check that the view only has one row loaded again (the root of the tree) QCOMPARE(treeViewPrivate->loadedRows.count(), 1); - - if (!interactive) - QTest::mouseRelease(item->window(), Qt::LeftButton, Qt::NoModifier, pos); } void tst_qquicktreeviewdelegate::pointerNavigationDisabled() @@ -281,11 +270,23 @@ void tst_qquicktreeviewdelegate::checkCurrentIndex() QVERIFY(item->selected()); } +void tst_qquicktreeviewdelegate::checkClickedSignal_data() +{ + QTest::addColumn<bool>("pointerNavigationEnabled"); + QTest::newRow("pointer navigation enabled") << true; + QTest::newRow("pointer navigation disabled") << false; +} + void tst_qquicktreeviewdelegate::checkClickedSignal() { - // Check that the delegate emits clicked when clicking on the - // label, but not when clicking on the indicator. + // Check that the delegate emits clicked when clicking on the + // label, but not when clicking on the indicator. This API is + // a part of the AbstractButton API, and should work with or + // without TableView.pointerNavigationEnabled set. + QFETCH(bool, pointerNavigationEnabled); + LOAD_TREEVIEW("unmodified.qml"); + treeView->setPointerNavigationEnabled(pointerNavigationEnabled); const auto item = treeView->itemAtCell(0, 0); QVERIFY(item); @@ -296,7 +297,8 @@ void tst_qquicktreeviewdelegate::checkClickedSignal() QPoint localPos = QPoint(item->width() / 2, item->height() / 2); QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint(); QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(clickedSpy.count(), 1); + QCOMPARE(clickedSpy.size(), 1); + clickedSpy.clear(); // Click on the indicator const auto indicator = item->property("indicator").value<QQuickItem *>(); @@ -304,7 +306,7 @@ void tst_qquicktreeviewdelegate::checkClickedSignal() localPos = QPoint(indicator->x() + indicator->width() / 2, indicator->y() + indicator->height() / 2); pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint(); QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(clickedSpy.count(), 1); + QCOMPARE(clickedSpy.size(), 0); } void tst_qquicktreeviewdelegate::clearSelectionOnClick() @@ -314,7 +316,7 @@ void tst_qquicktreeviewdelegate::clearSelectionOnClick() // Select root item const auto index = treeView->selectionModel()->model()->index(0, 0); treeView->selectionModel()->select(index, QItemSelectionModel::Select); - QCOMPARE(treeView->selectionModel()->selectedIndexes().count(), 1); + QCOMPARE(treeView->selectionModel()->selectedIndexes().size(), 1); // Click on a cell. This should remove the selection const auto item = qobject_cast<QQuickTreeViewDelegate *>(treeView->itemAtCell(0, 0)); @@ -322,7 +324,76 @@ void tst_qquicktreeviewdelegate::clearSelectionOnClick() QPoint localPos = QPoint(item->width() / 2, item->height() / 2); QPoint pos = item->window()->contentItem()->mapFromItem(item, localPos).toPoint(); QTest::mouseClick(item->window(), Qt::LeftButton, Qt::NoModifier, pos); - QCOMPARE(treeView->selectionModel()->selectedIndexes().count(), 0); + QCOMPARE(treeView->selectionModel()->selectedIndexes().size(), 0); +} + +void tst_qquicktreeviewdelegate::dragToSelect() +{ + // Check that the delegate is not blocking the user from + // being able to select cells using Drag. + LOAD_TREEVIEW("unmodified.qml"); + + // When TreeView is not interactive, SelectionRectangle + // will use Drag by default. + treeView->setInteractive(false); + treeView->expandRecursively(); + + WAIT_UNTIL_POLISHED; + + QVERIFY(!treeView->selectionModel()->hasSelection()); + QCOMPARE(treeView->selectionBehavior(), QQuickTableView::SelectRows); + + // Drag on from cell 0,0 to 0,1 + const auto item0_0 = treeView->itemAtCell(0, 0); + const auto item0_1 = treeView->itemAtCell(0, 1); + QVERIFY(item0_0); + QVERIFY(item0_1); + + QQuickWindow *window = treeView->window(); + QPoint localPos0_0 = QPoint(item0_0->width() / 2, item0_0->height() / 2); + QPoint windowPos0_0 = window->contentItem()->mapFromItem(item0_0, localPos0_0).toPoint(); + QPoint localPos0_1 = QPoint(item0_1->width() / 2, item0_1->height() / 2); + QPoint windowPos0_1 = window->contentItem()->mapFromItem(item0_1, localPos0_1).toPoint(); + + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, windowPos0_0); + QTest::mouseMove(window, windowPos0_1); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, windowPos0_1); + + // Since TreeView uses TableView.SelectRows by default, we + // now expect cells from 0,0 and 1,1 to be selected. + QCOMPARE(treeView->selectionModel()->selectedIndexes().size(), 4); +} + +void tst_qquicktreeviewdelegate::pressAndHoldToSelect() +{ + // Check that the delegate is not blocking the user from + // being able to select cells using PressAndHold + LOAD_TREEVIEW("unmodified.qml"); + + // When TreeView is interactive, SelectionRectangle + // will use PressAndHold by default. + treeView->setInteractive(true); + treeView->expandRecursively(); + + WAIT_UNTIL_POLISHED; + + QVERIFY(!treeView->selectionModel()->hasSelection()); + QCOMPARE(treeView->selectionBehavior(), QQuickTableView::SelectRows); + + // PressAndHold on cell 0,0 + const auto item0_0 = treeView->itemAtCell(0, 0); + QVERIFY(item0_0); + + QQuickWindow *window = treeView->window(); + QPoint localPos0_0 = QPoint(item0_0->width() / 2, item0_0->height() / 2); + QPoint windowPos0_0 = window->contentItem()->mapFromItem(item0_0, localPos0_0).toPoint(); + + QTest::mousePress(window, Qt::LeftButton, Qt::NoModifier, windowPos0_0); + QTRY_VERIFY(treeView->selectionModel()->hasSelection()); + // Since TreeView uses TableView.SelectRows by default, we + // now expect both cell 0,0 and 1,0 to be selected. + QCOMPARE(treeView->selectionModel()->selectedIndexes().size(), 2); + QTest::mouseRelease(window, Qt::LeftButton, Qt::NoModifier, windowPos0_0); } QTEST_MAIN(tst_qquicktreeviewdelegate) diff --git a/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp b/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp index 5a73ad429a..e2bb80fb4e 100644 --- a/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp +++ b/tests/auto/quickcontrols2/styleimports/tst_styleimports.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include <QtCore/qregularexpression.h> +#include <QtGui/qpalette.h> #include <QtTest/qtest.h> #include <QtQml/qqmlcomponent.h> #include <QtQml/qqmlcontext.h> @@ -195,6 +196,10 @@ void tst_StyleImports::customStyleSelector() QCOMPARE(customComponent->objectName(), "+FileSystemStyle/CustomComponent.qml"); } +QT_BEGIN_NAMESPACE +extern QPalette qt_fusionPalette(); +QT_END_NAMESPACE + void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme_data() { QTest::addColumn<QString>("style"); @@ -202,7 +207,8 @@ void tst_StyleImports::fallbackStyleShouldNotOverwriteTheme_data() QTest::addColumn<QColor>("expectedContentItemColor"); QTest::addRow("style=Fusion,fallbackStyle=Material") - << QString::fromLatin1("Fusion") << QString::fromLatin1("Material") << QColor::fromRgb(0x252525); + << QString::fromLatin1("Fusion") << QString::fromLatin1("Material") + << qt_fusionPalette().buttonText().color(); QTest::addRow("style=ResourceStyle,fallbackStyle=Material") << QString::fromLatin1("ResourceStyle") << QString::fromLatin1("Material") << QColor("salmon"); } diff --git a/tests/auto/quickcontrols2/translation/tst_translation.cpp b/tests/auto/quickcontrols2/translation/tst_translation.cpp index 76e3244cbd..f0798d0367 100644 --- a/tests/auto/quickcontrols2/translation/tst_translation.cpp +++ b/tests/auto/quickcontrols2/translation/tst_translation.cpp @@ -157,7 +157,7 @@ void tst_translation::stackView() QVERIFY(button); // Shouldn't crash when calling retranslate. QVERIFY(clickButton(button)); - QTRY_COMPARE(calledTranslateSpy.count(), 1); + QTRY_COMPARE(calledTranslateSpy.size(), 1); } QTEST_MAIN(tst_translation) diff --git a/tests/auto/quickdialogs/qquickcolordialogimpl/tst_qquickcolordialogimpl.cpp b/tests/auto/quickdialogs/qquickcolordialogimpl/tst_qquickcolordialogimpl.cpp index d7666498df..3a463c8b08 100644 --- a/tests/auto/quickdialogs/qquickcolordialogimpl/tst_qquickcolordialogimpl.cpp +++ b/tests/auto/quickdialogs/qquickcolordialogimpl/tst_qquickcolordialogimpl.cpp @@ -51,7 +51,6 @@ private slots: void changeHex(); void changeColorFromTextFields_data(); void changeColorFromTextFields(); - void eyeDropper(); void windowTitle_data(); void windowTitle(); @@ -168,7 +167,7 @@ void tst_QQuickColorDialogImpl::moveColorPickerHandle() // Move handle to where the saturation is the highest and the lightness is 'neutral' QTest::mouseClick(dialogHelper.window(), Qt::LeftButton, Qt::NoModifier, topCenter); - QCOMPARE(colorChangedSpy.count(), 1); + QCOMPARE(colorChangedSpy.size(), 1); const qreal floatingPointComparisonThreshold = 1.0 / colorPicker->width(); const QString floatComparisonErrorString( @@ -196,7 +195,7 @@ void tst_QQuickColorDialogImpl::moveColorPickerHandle() QCOMPARE(colorPicker->hue(), QColorConstants::Cyan.hslHueF()); QCOMPARE(colorPicker->color().rgba(), QColorConstants::Cyan.rgba()); - QCOMPARE(colorChangedSpy.count(), 2); + QCOMPARE(colorChangedSpy.size(), 2); QPoint bottomCenter = colorPicker->mapToScene({ colorPicker->width() / 2, colorPicker->height() }).toPoint(); @@ -209,7 +208,7 @@ void tst_QQuickColorDialogImpl::moveColorPickerHandle() // This means that the current color was changed twice. // (The press happens 1 pixel above the release, to work around an issue where the mouse event // wasn't received by the color picker) - QCOMPARE(colorChangedSpy.count(), 4); + QCOMPARE(colorChangedSpy.size(), 4); FUZZYCOMPARE(colorPicker->saturation(), 0.0, floatingPointComparisonThreshold, qPrintable(floatComparisonErrorString.arg("saturation()").arg(colorPicker->saturation()).arg(0.0).arg(floatingPointComparisonThreshold))); FUZZYCOMPARE(dialogHelper.quickDialog->saturation(), 0.0, floatingPointComparisonThreshold, @@ -318,7 +317,7 @@ void tst_QQuickColorDialogImpl::changeHex() // Modify the value in the TextField to something else. colorTextField->forceActiveFocus(); - colorTextField->select(1, colorTextField->text().length()); + colorTextField->select(1, colorTextField->text().size()); QVERIFY(colorTextField->hasActiveFocus()); QTest::keyClick(dialogHelper.window(), Qt::Key_Backspace); QTest::keyClick(dialogHelper.window(), '0'); @@ -432,53 +431,6 @@ void tst_QQuickColorDialogImpl::changeColorFromTextFields() CLOSE_DIALOG("Ok"); } -void tst_QQuickColorDialogImpl::eyeDropper() -{ -#ifdef Q_OS_QNX - QSKIP("Skipping the test for the QNX platform!"); -#endif - - DialogTestHelper<QQuickColorDialog, QQuickColorDialogImpl> dialogHelper(this, "colorDialog.qml"); - QVERIFY2(dialogHelper.isWindowInitialized(), dialogHelper.failureMessage()); - QVERIFY(dialogHelper.waitForWindowActive()); - - // Open the dialog. - QVERIFY(dialogHelper.openDialog()); - QTRY_VERIFY(dialogHelper.isQuickDialogOpen()); - - QQuickAbstractButton *eyeDropperButton = dialogHelper.quickDialog->findChild<QQuickAbstractButton *>("eyeDropperButton"); - QVERIFY(eyeDropperButton); - - // Only test on platforms that support grabbing of external windows. - const bool wayland = QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive) == 0; - const bool offscreen = qgetenv("QT_QPA_PLATFORM").compare(QLatin1String("offscreen"), Qt::CaseInsensitive) == 0; - if (QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing) && !wayland && !offscreen) - { - QVERIFY(eyeDropperButton->isVisible()); - - // Enable the eyeDropper. - QTest::mouseClick(dialogHelper.window(), Qt::LeftButton, Qt::NoModifier, eyeDropperButton->mapToScene({eyeDropperButton->width() / 2, eyeDropperButton->height() / 2}).toPoint()); - QTest::qWait(500); // Flaky - - // Pick the new color from the screen somewhere. - const auto p = dialogHelper.quickDialog->popupItem()->mapToScene({-10, 0}).toPoint(); - QTest::mouseMove(dialogHelper.window(), p); - QTest::mouseClick(dialogHelper.window(), Qt::LeftButton, Qt::NoModifier, p); - - // The color should be equal to the ApplicationWindows background color - const unsigned int yellow = QColorConstants::Yellow.rgba(); - if (dialogHelper.quickDialog->color().rgba() != yellow) - QFAIL(qPrintable(QStringLiteral("The picked color was %1, when yellow was expected. Window size: %2x%3").arg(dialogHelper.quickDialog->color().name()).arg(dialogHelper.window()->width()).arg(dialogHelper.window()->height()))); - } - else - { - // Feature should be hidden on unsupported platforms. - QVERIFY(!eyeDropperButton->isVisible()); - } - - CLOSE_DIALOG("Ok"); -} - void tst_QQuickColorDialogImpl::windowTitle_data() { QTest::addColumn<QString>("title"); diff --git a/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp b/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp index ae9db3dfd1..1a615ae948 100644 --- a/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp +++ b/tests/auto/quickdialogs/qquickfiledialogimpl/tst_qquickfiledialogimpl.cpp @@ -86,6 +86,8 @@ private slots: void done(); void setSelectedFile_data(); void setSelectedFile(); + void selectNewFileViaTextField_data(); + void selectNewFileViaTextField(); private: QTemporaryDir tempDir; @@ -97,6 +99,7 @@ private: QScopedPointer<QFile> tempSubFile2; QTemporaryDir largeTempDir; + QStringList largeTempDirPaths; QDir largeTempDirLargeSubDir; const int largeTempDirLargeSubDirIndex = 80; @@ -120,7 +123,7 @@ void tst_QQuickFileDialogImpl::initTestCase() qputenv("QT_QUICK_DIALOGS_PRESELECT_FIRST_FILE", "1"); - QVERIFY(tempDir.isValid()); + QVERIFY2(tempDir.isValid(), qPrintable(tempDir.errorString())); // QTEST_QUICKCONTROLS_MAIN constructs the test case object once, // and then calls qRun() for each style, and qRun() calls initTestCase(). // So, we need to check if we've already made the temporary directory. @@ -166,24 +169,23 @@ void tst_QQuickFileDialogImpl::initTestCase() /* Create another temporary directory that contains a large amount of folders. */ - QVERIFY(largeTempDir.isValid()); + QVERIFY2(largeTempDir.isValid(), qPrintable(largeTempDir.errorString())); const static int largeFileCount = 100; + const QDir largeTempDirectory(largeTempDir.path()); for (int i = 0; i < largeFileCount; ++i) { - QDir newDir(largeTempDir.path()); - QVERIFY(newDir.exists()); // Pad with zeroes so that the directories are ordered as we expect. - QVERIFY(newDir.mkdir(QString::fromLatin1("dir%1").arg(i, 3, 10, QLatin1Char('0')))); + const QString dirName = QString::fromLatin1("dir%1").arg(i, 3, 10, QLatin1Char('0')); + QVERIFY(largeTempDirectory.mkdir(dirName)); + largeTempDirPaths.append(largeTempDirectory.filePath(dirName)); } // ... and within one of those folders, more folders. largeTempDirLargeSubDir = QDir(largeTempDir.path() + "/dir" + QString::fromLatin1("%1").arg(largeTempDirLargeSubDirIndex, 3, 10, QLatin1Char('0'))); QVERIFY(largeTempDirLargeSubDir.exists()); - for (int i = 0; i < largeFileCount; ++i) { - QDir newDir(largeTempDirLargeSubDir.path()); - QVERIFY(newDir.exists()); - QVERIFY(newDir.mkdir(QString::fromLatin1("sub-dir%1").arg(i, 3, 10, QLatin1Char('0')))); - } + const QDir largeTempSubDirectory = QDir(largeTempDirLargeSubDir.path()); + for (int i = 0; i < largeFileCount; ++i) + QVERIFY(largeTempSubDirectory.mkdir(QString::fromLatin1("sub-dir%1").arg(i, 3, 10, QLatin1Char('0')))); // Ensure that each test starts off in the temporary directory. oldCurrentDir = QDir::current(); @@ -807,6 +809,9 @@ void tst_QQuickFileDialogImpl::goUpIntoLargeFolder() // Go up a directory via the keyboard shortcut. QTest::keySequence(dialogHelper.window(), goUpKeySequence); + QString failureMessage; + QTRY_VERIFY2(verifyFileDialogDelegates(dialogHelper.fileDialogListView, + largeTempDirPaths, failureMessage), qPrintable(failureMessage)); VERIFY_FILE_SELECTED_AND_FOCUSED(QUrl::fromLocalFile(largeTempDir.path()), QUrl::fromLocalFile(largeTempDirLargeSubDir.path()), largeTempDirLargeSubDirIndex); } @@ -1028,7 +1033,7 @@ void tst_QQuickFileDialogImpl::tabFocusNavigation() } // Tab through each item, checking the focus after each. - for (auto expectedFocusItem : qAsConst(expectedFocusItems)) { + for (auto expectedFocusItem : std::as_const(expectedFocusItems)) { // Check the focus item first so that we account for the first item. // Print detailed failure message as workaround for QTBUG-92102. QVERIFY2(dialogHelper.window()->activeFocusItem() == expectedFocusItem, qPrintable(QString::fromLatin1( @@ -1043,7 +1048,7 @@ void tst_QQuickFileDialogImpl::tabFocusNavigation() std::reverse(expectedFocusItems.begin(), expectedFocusItems.end()); // We know the first (last) item has focus already, so skip it. expectedFocusItems.removeFirst(); - for (auto expectedFocusItem : qAsConst(expectedFocusItems)) { + for (auto expectedFocusItem : std::as_const(expectedFocusItems)) { QTest::keyClick(dialogHelper.window(), Qt::Key_Tab, Qt::ShiftModifier); QCOMPARE(dialogHelper.window()->activeFocusItem(), expectedFocusItem); @@ -1370,6 +1375,48 @@ void tst_QQuickFileDialogImpl::setSelectedFile() } } +void tst_QQuickFileDialogImpl::selectNewFileViaTextField_data() +{ + fileMode_data(); +} +void tst_QQuickFileDialogImpl::selectNewFileViaTextField() +{ + QFETCH(QQuickFileDialog::FileMode, fileMode); + + // Open the dialog. + FileDialogTestHelper dialogHelper(this, "fileDialog.qml"); + dialogHelper.dialog->setFileMode(fileMode); + + if (fileMode == QQuickFileDialog::SaveFile) + dialogHelper.dialog->setSelectedFile(QUrl()); + + OPEN_QUICK_DIALOG(); + QQuickTest::qWaitForPolish(dialogHelper.window()); + + const QQuickTextField *fileNameTextField = + dialogHelper.quickDialog->findChild<QQuickTextField *>("fileNameTextField"); + QVERIFY(fileNameTextField); + + QVERIFY2(fileNameTextField->isVisible() == (fileMode == QQuickFileDialog::SaveFile), + "The TextField for file name should only be visible when the FileMode is 'SaveFile'"); + + if (fileMode == QQuickFileDialog::SaveFile) { + const QPoint textFieldCenterPos = + fileNameTextField->mapToScene({ fileNameTextField->width() / 2, fileNameTextField->height() / 2 }).toPoint(); + + QTest::mouseClick(dialogHelper.window(), Qt::LeftButton, Qt::NoModifier, textFieldCenterPos); + QTRY_VERIFY(fileNameTextField->hasActiveFocus()); + + const QByteArray newFileName("foo.txt"); + for (const auto &c : newFileName) + QTest::keyClick(dialogHelper.window(), c); + QTest::keyClick(dialogHelper.window(), Qt::Key_Enter); + + QTRY_COMPARE(fileNameTextField->text(), newFileName); + QCOMPARE(dialogHelper.dialog->selectedFile().fileName(), newFileName); + } +} + QTEST_MAIN(tst_QQuickFileDialogImpl) #include "tst_qquickfiledialogimpl.moc" diff --git a/tests/auto/quickdialogs/qquickfolderdialogimpl/tst_qquickfolderdialogimpl.cpp b/tests/auto/quickdialogs/qquickfolderdialogimpl/tst_qquickfolderdialogimpl.cpp index 097bc3a9af..01116aa7e9 100644 --- a/tests/auto/quickdialogs/qquickfolderdialogimpl/tst_qquickfolderdialogimpl.cpp +++ b/tests/auto/quickdialogs/qquickfolderdialogimpl/tst_qquickfolderdialogimpl.cpp @@ -231,10 +231,10 @@ void tst_QQuickFolderDialogImpl::chooseFolderViaStandardButtons() COMPARE_URL(dialogHelper.quickDialog->selectedFolder(), QUrl::fromLocalFile(tempSubDir2.path())); COMPARE_URL(dialogHelper.dialog->selectedFolder(), QUrl::fromLocalFile(tempSubDir2.path())); // Only selectedFile-related signals should be emitted. - QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.count(), 0); - QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.count(), 0); + QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.size(), 0); + QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.size(), 0); // Click the "Open" button. QVERIFY(dialogHelper.quickDialog->footer()); @@ -245,10 +245,10 @@ void tst_QQuickFolderDialogImpl::chooseFolderViaStandardButtons() QVERIFY(clickButton(openButton)); COMPARE_URL(dialogHelper.dialog->selectedFolder(), QUrl::fromLocalFile(tempSubDir2.path())); COMPARE_URL(dialogHelper.quickDialog->selectedFolder(), QUrl::fromLocalFile(tempSubDir2.path())); - QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.count(), 0); - QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.count(), 0); + QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.size(), 0); + QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.size(), 0); QTRY_VERIFY(!dialogHelper.quickDialog->isVisible()); QVERIFY(!dialogHelper.dialog->isVisible()); } @@ -323,10 +323,10 @@ void tst_QQuickFolderDialogImpl::changeFolderViaDoubleClick() COMPARE_URL(dialogHelper.dialog->selectedFolder(), QUrl()); // selectedFolder is set to the folder when clicked and then set to an empty URL after // the double click. - QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.count(), 2); - QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.count(), 2); - QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.count(), 1); + QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.size(), 2); + QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.size(), 2); + QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.size(), 1); // Since we only changed the current folder, the dialog should still be open. QVERIFY(dialogHelper.dialog->isVisible()); @@ -396,10 +396,10 @@ void tst_QQuickFolderDialogImpl::changeFolderViaEnter() QTest::keyClick(dialogHelper.window(), Qt::Key_Return); COMPARE_URL(dialogHelper.dialog->currentFolder(), QUrl::fromLocalFile(tempSubDir1.path())); COMPARE_URL(dialogHelper.dialog->selectedFolder(), QUrl::fromLocalFile(tempSubSubDir.path())); - QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.count(), 1); - QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.count(), 1); + QCOMPARE(signalHelper.dialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.quickDialogSelectedFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.dialogCurrentFolderChangedSpy.size(), 1); + QCOMPARE(signalHelper.quickDialogCurrentFolderChangedSpy.size(), 1); // Since we only changed the current folder, the dialog should still be open. QVERIFY(dialogHelper.dialog->isVisible()); @@ -687,7 +687,7 @@ void tst_QQuickFolderDialogImpl::tabFocusNavigation() } // Tab through each item, checking the focus after each. - for (auto expectedFocusItem : qAsConst(expectedFocusItems)) { + for (auto expectedFocusItem : std::as_const(expectedFocusItems)) { // Check the focus item first so that we account for the first item. // Print detailed failure message as workaround for QTBUG-92102. QVERIFY2(dialogHelper.window()->activeFocusItem() == expectedFocusItem, qPrintable(QString::fromLatin1( @@ -702,7 +702,7 @@ void tst_QQuickFolderDialogImpl::tabFocusNavigation() std::reverse(expectedFocusItems.begin(), expectedFocusItems.end()); // We know the first (last) item has focus already, so skip it. expectedFocusItems.removeFirst(); - for (auto expectedFocusItem : qAsConst(expectedFocusItems)) { + for (auto expectedFocusItem : std::as_const(expectedFocusItems)) { QTest::keyClick(dialogHelper.window(), Qt::Key_Tab, Qt::ShiftModifier); QCOMPARE(dialogHelper.window()->activeFocusItem(), expectedFocusItem); diff --git a/tests/auto/quickdialogs/qquickfontdialogimpl/tst_qquickfontdialogimpl.cpp b/tests/auto/quickdialogs/qquickfontdialogimpl/tst_qquickfontdialogimpl.cpp index 78a0060824..5de4fe291b 100644 --- a/tests/auto/quickdialogs/qquickfontdialogimpl/tst_qquickfontdialogimpl.cpp +++ b/tests/auto/quickdialogs/qquickfontdialogimpl/tst_qquickfontdialogimpl.cpp @@ -151,7 +151,7 @@ void tst_QQuickFontDialogImpl::changingWritingSystem() QVERIFY(anyDelegate); QCOMPARE(anyDelegate->text(), QFontDatabase::writingSystemName(QFontDatabase::Any)); - QCOMPARE(fontFamilyModelSpy.count(), 0); + QCOMPARE(fontFamilyModelSpy.size(), 0); // Select "Japanese" from the ComboBox. const int japaneseIndex = QFontDatabase::Japanese; @@ -162,7 +162,7 @@ void tst_QQuickFontDialogImpl::changingWritingSystem() QTRY_VERIFY(!writingSystemComboBox->popup()->isVisible()); // Check that the contents of the font family listview changed - QCOMPARE(fontFamilyModelSpy.count(), 1); + QCOMPARE(fontFamilyModelSpy.size(), 1); // And that the sample text is correctly set QCOMPARE(sampleEdit->text(), QFontDatabase::writingSystemSample(QFontDatabase::Japanese)); @@ -235,11 +235,11 @@ void tst_QQuickFontDialogImpl::clickAroundInTheFamilyListView() const QString expected2 = fontListModel[i], actual2 = dialogHelper.dialog->selectedFont().family(); QVERIFY2(expected2 == actual2, qPrintable(err.arg(expected2, actual2).append(", FONT ").append(fontDelegate->text()))); - const int selectedFontSpyCount = selectedFontSpy.count(); + const int selectedFontSpyCount = selectedFontSpy.size(); QVERIFY2(selectedFontSpyCount == 1, qPrintable(err.arg(1).arg(selectedFontSpyCount).append(", FONT ").append(fontDelegate->text()))); - QVERIFY2((oldStyleModel == fontStyleListView->model()) != (styleModelSpy.count() == 1), + QVERIFY2((oldStyleModel == fontStyleListView->model()) != (styleModelSpy.size() == 1), qPrintable(QString("LOOP INDEX %1").arg(i))); - QVERIFY2((oldSizeModel == fontSizeListView->model()) != (sizeModelSpy.count() == 1), + QVERIFY2((oldSizeModel == fontSizeListView->model()) != (sizeModelSpy.size() == 1), qPrintable(QString("LOOP INDEX %1").arg(i))); } @@ -269,25 +269,25 @@ void tst_QQuickFontDialogImpl::settingUnderlineAndStrikeoutEffects() QVERIFY(clickButton(underlineCheckBox)); - QCOMPARE(selectedFontSpy.count(), 1); + QCOMPARE(selectedFontSpy.size(), 1); QVERIFY(dialogHelper.dialog->selectedFont().underline()); QVERIFY(!dialogHelper.dialog->selectedFont().strikeOut()); QVERIFY(clickButton(underlineCheckBox)); - QCOMPARE(selectedFontSpy.count(), 2); + QCOMPARE(selectedFontSpy.size(), 2); QVERIFY(!dialogHelper.dialog->selectedFont().underline()); QVERIFY(!dialogHelper.dialog->selectedFont().strikeOut()); QVERIFY(clickButton(strikeoutCheckBox)); - QCOMPARE(selectedFontSpy.count(), 3); + QCOMPARE(selectedFontSpy.size(), 3); QVERIFY(!dialogHelper.dialog->selectedFont().underline()); QVERIFY(dialogHelper.dialog->selectedFont().strikeOut()); QVERIFY(clickButton(strikeoutCheckBox)); - QCOMPARE(selectedFontSpy.count(), 4); + QCOMPARE(selectedFontSpy.size(), 4); QVERIFY(!dialogHelper.dialog->selectedFont().underline()); QVERIFY(!dialogHelper.dialog->selectedFont().strikeOut()); @@ -401,7 +401,7 @@ public: do { m_searchText.append(searchText); - for (int i = 0; i < m_model.count(); ++i) { + for (int i = 0; i < m_model.size(); ++i) { if (m_model.at(i).startsWith(m_searchText, Qt::CaseInsensitive)) return i; } @@ -512,7 +512,7 @@ void tst_QQuickFontDialogImpl::setCurrentFontFromApi() QVERIFY(fontSizeEdit); // From when the listviews are populated - QCOMPARE(selectedFontSpy.count(), 1); + QCOMPARE(selectedFontSpy.size(), 1); selectedFontSpy.clear(); @@ -538,16 +538,16 @@ void tst_QQuickFontDialogImpl::setCurrentFontFromApi() QCOMPARE(styleModel.at(fontStyleListView->currentIndex()), style); QCOMPARE(fontSizeEdit->text(), QString::number(size++)); - QCOMPARE(selectedFontSpy.count(), ++spyCounter); + QCOMPARE(selectedFontSpy.size(), ++spyCounter); - for (int styleIt = 0; styleIt < qMin(styleModel.count(), maxNumberOfStyles); ++styleIt) { + for (int styleIt = 0; styleIt < qMin(styleModel.size(), maxNumberOfStyles); ++styleIt) { const QString currentStyle = styleModel.at(styleIt); const QFont f = QFontDatabase::font(*family, currentStyle, size); dialogHelper.dialog->setSelectedFont(f); QCOMPARE(styleModel.at(fontStyleListView->currentIndex()), currentStyle); - QCOMPARE(selectedFontSpy.count(), ++spyCounter); + QCOMPARE(selectedFontSpy.size(), ++spyCounter); } } diff --git a/tests/auto/quickdialogs/qquickmessagedialogimpl/tst_qquickmessagedialogimpl.cpp b/tests/auto/quickdialogs/qquickmessagedialogimpl/tst_qquickmessagedialogimpl.cpp index 93b29d6a16..b2f3d6456c 100644 --- a/tests/auto/quickdialogs/qquickmessagedialogimpl/tst_qquickmessagedialogimpl.cpp +++ b/tests/auto/quickdialogs/qquickmessagedialogimpl/tst_qquickmessagedialogimpl.cpp @@ -79,7 +79,7 @@ void tst_QQuickMessageDialogImpl::changeText() // update the text property dialogHelper.dialog->setText(testString1); - QCOMPARE(textSpy.count(), 1); + QCOMPARE(textSpy.size(), 1); // The textLabel is empty until dialog is re-opened QCOMPARE(dialogHelper.dialog->text(), testString1); @@ -91,7 +91,7 @@ void tst_QQuickMessageDialogImpl::changeText() // The textLabel isn't updated immediately dialogHelper.dialog->setText(testString2); - QCOMPARE(textSpy.count(), 2); + QCOMPARE(textSpy.size(), 2); QCOMPARE(textLabel->text(), testString1); dialogHelper.dialog->close(); @@ -128,7 +128,7 @@ void tst_QQuickMessageDialogImpl::changeInformativeText() // update the informativeText property dialogHelper.dialog->setInformativeText(testString1); - QCOMPARE(informativeTextSpy.count(), 1); + QCOMPARE(informativeTextSpy.size(), 1); // The textLabel is empty until dialog is re-opened QCOMPARE(dialogHelper.dialog->informativeText(), testString1); @@ -140,7 +140,7 @@ void tst_QQuickMessageDialogImpl::changeInformativeText() // The textLabel shouldn't update immediately dialogHelper.dialog->setInformativeText(testString2); - QCOMPARE(informativeTextSpy.count(), 2); + QCOMPARE(informativeTextSpy.size(), 2); QCOMPARE(informativeTextLabel->text(), testString1); dialogHelper.dialog->close(); @@ -169,7 +169,7 @@ void tst_QQuickMessageDialogImpl::changeStandardButtons() QPlatformDialogHelper::StandardButtons(QPlatformDialogHelper::StandardButton::Save | QPlatformDialogHelper::StandardButton::Cancel | QPlatformDialogHelper::StandardButton::Apply)); - QCOMPARE(buttonBoxSpy.count(), 1); + QCOMPARE(buttonBoxSpy.size(), 1); QCOMPARE(buttonBox->count(), 1); dialogHelper.dialog->close(); dialogHelper.dialog->open(); @@ -190,7 +190,7 @@ void tst_QQuickMessageDialogImpl::changeStandardButtons() dialogHelper.dialog->setButtons( QPlatformDialogHelper::StandardButton(QPlatformDialogHelper::StandardButton::Ok | QPlatformDialogHelper::StandardButton::Close)); - QCOMPARE(buttonBoxSpy.count(), 2); + QCOMPARE(buttonBoxSpy.size(), 2); QCOMPARE(buttonBox->count(), 3); dialogHelper.dialog->open(); QCOMPARE(buttonBox->count(), 2); @@ -233,7 +233,7 @@ void tst_QQuickMessageDialogImpl::detailedText() // Set the detailed text to a non-empty string dialogHelper.dialog->setDetailedText(nonEmptyString); QCOMPARE(dialogHelper.dialog->detailedText(), nonEmptyString); - QCOMPARE(detailedTextSpy.count(), 1); + QCOMPARE(detailedTextSpy.size(), 1); QCOMPARE(detailedTextArea->text(), emptyString); QVERIFY(!detailedTextButton->isVisible()); dialogHelper.dialog->close(); @@ -246,7 +246,7 @@ void tst_QQuickMessageDialogImpl::detailedText() // Set the detailed text to an empty string dialogHelper.dialog->setDetailedText(emptyString); - QCOMPARE(detailedTextSpy.count(), 2); + QCOMPARE(detailedTextSpy.size(), 2); QCOMPARE(dialogHelper.dialog->detailedText(), emptyString); QCOMPARE(detailedTextArea->text(), nonEmptyString); QVERIFY(detailedTextButton->isVisible()); @@ -260,7 +260,7 @@ void tst_QQuickMessageDialogImpl::detailedText() // Change the detailed text property while the dialog is already open, should not immediately // update the dialog ui dialogHelper.dialog->setDetailedText(nonEmptyString); - QCOMPARE(detailedTextSpy.count(), 3); + QCOMPARE(detailedTextSpy.size(), 3); QCOMPARE(dialogHelper.dialog->detailedText(), nonEmptyString); QCOMPARE(detailedTextArea->text(), emptyString); QVERIFY2(!detailedTextButton->isVisible(), diff --git a/tests/auto/quicktest/signalspy/tst_signalspy.cpp b/tests/auto/quicktest/signalspy/tst_signalspy.cpp index 559d16cea3..545f4d3cc7 100644 --- a/tests/auto/quicktest/signalspy/tst_signalspy.cpp +++ b/tests/auto/quicktest/signalspy/tst_signalspy.cpp @@ -54,7 +54,7 @@ void tst_SignalSpy::testCount() window.resize(200, 200); window.setSource(url); window.show(); - QVERIFY(QTest::qWaitForWindowActive(&window)); + QVERIFY(QTest::qWaitForWindowExposed(&window)); QVERIFY(window.rootObject() != nullptr); QObject *mouseSpy = window.rootObject()->findChild<QObject *>("mouseSpy"); diff --git a/tests/auto/quickwidgets/qquickwidget/CMakeLists.txt b/tests/auto/quickwidgets/qquickwidget/CMakeLists.txt index 24da087db5..5ce5cf3125 100644 --- a/tests/auto/quickwidgets/qquickwidget/CMakeLists.txt +++ b/tests/auto/quickwidgets/qquickwidget/CMakeLists.txt @@ -19,6 +19,7 @@ qt_internal_add_test(tst_qquickwidget Qt::GuiPrivate Qt::QmlPrivate Qt::QuickPrivate + Qt::QuickTemplates2Private Qt::QuickWidgets Qt::QuickWidgetsPrivate Qt::WidgetsPrivate diff --git a/tests/auto/quickwidgets/qquickwidget/data/button.qml b/tests/auto/quickwidgets/qquickwidget/data/button.qml new file mode 100644 index 0000000000..30698908d7 --- /dev/null +++ b/tests/auto/quickwidgets/qquickwidget/data/button.qml @@ -0,0 +1,27 @@ +import QtQuick +import QtQuick.Controls.Basic + +Item { + width: 100 + height: 100 + visible: true + + property bool wasPressed: false + property bool wasReleased: false + property bool wasClicked: false + + Popup { + closePolicy: Popup.NoAutoClose + visible: true + + Button { + objectName: "button" + text: "TAP ME" + anchors.fill: parent + + onPressed: wasPressed = true + onReleased: wasReleased = true + onClicked: wasClicked = true + } + } +} diff --git a/tests/auto/quickwidgets/qquickwidget/data/mouse.qml b/tests/auto/quickwidgets/qquickwidget/data/mouse.qml index 5d1c6e8443..25a7329a08 100644 --- a/tests/auto/quickwidgets/qquickwidget/data/mouse.qml +++ b/tests/auto/quickwidgets/qquickwidget/data/mouse.qml @@ -7,8 +7,10 @@ Rectangle { property bool wasClicked: false property bool wasDoubleClicked: false property bool wasMoved: false + color: ma.pressed ? "wheat" : "lightsteelblue" MouseArea { + id: ma anchors.fill: parent hoverEnabled: true onClicked: wasClicked = true diff --git a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp index fb86ef9e72..6ecf14fdff 100644 --- a/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp +++ b/tests/auto/quickwidgets/qquickwidget/tst_qquickwidget.cpp @@ -10,6 +10,8 @@ #include <QtQuick/qquickview.h> #include <QtQuick/qquickitem.h> #include <QtQuick/private/qquickitem_p.h> +#include <QtQuick/private/qquickmousearea_p.h> +#include <QtQuickTemplates2/private/qquickbutton_p.h> #include <QtQuickTestUtils/private/qmlutils_p.h> #include <QtGui/QWindow> #include <QtGui/QScreen> @@ -123,6 +125,9 @@ private slots: void mouseEventWindowPos(); void synthMouseFromTouch_data(); void synthMouseFromTouch(); + void touchTapMouseArea(); + void touchTapButton(); + void touchMultipleWidgets(); void tabKey(); void resizeOverlay(); void controls(); @@ -340,7 +345,7 @@ void tst_qquickwidget::errors() QQmlTestMessageHandler messageHandler; view->setSource(testFileUrl("error1.qml")); QCOMPARE(view->status(), QQuickWidget::Error); - QCOMPARE(view->errors().count(), 1); + QCOMPARE(view->errors().size(), 1); } void tst_qquickwidget::engine() @@ -613,13 +618,106 @@ void tst_qquickwidget::synthMouseFromTouch() QTest::touchEvent(&window, device).move(0, p2, &window); QTest::touchEvent(&window, device).release(0, p2, &window); - QCOMPARE(item->m_touchEvents.count(), synthMouse ? 0 : (acceptTouch ? 3 : 1)); - QCOMPARE(item->m_mouseEvents.count(), synthMouse ? 3 : 0); - QCOMPARE(childView->m_mouseEvents.count(), 0); + qCDebug(lcTests) << item->m_touchEvents << item->m_mouseEvents; + QCOMPARE(item->m_touchEvents.size(), synthMouse ? 0 : (acceptTouch ? 3 : 1)); + QCOMPARE(item->m_mouseEvents.size(), synthMouse ? 3 : 0); + QCOMPARE(childView->m_mouseEvents.size(), 0); for (const auto &ev : item->m_mouseEvents) QCOMPARE(ev, Qt::MouseEventSynthesizedByQt); } +void tst_qquickwidget::touchTapMouseArea() +{ + QWidget window; + window.resize(100, 100); + window.setObjectName("window widget"); + window.setAttribute(Qt::WA_AcceptTouchEvents); + QVERIFY(QCoreApplication::testAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents)); + QQuickWidget *quick = new QQuickWidget(&window); + quick->setSource(testFileUrl("mouse.qml")); + quick->move(50, 50); + quick->setObjectName("quick widget"); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + QQuickItem *rootItem = quick->rootObject(); + QVERIFY(rootItem); + QQuickMouseArea *ma = rootItem->findChild<QQuickMouseArea *>(); + QVERIFY(ma); + + QPoint p1 = QPoint(70, 70); + QTest::touchEvent(&window, device).press(0, p1, &window); + QTRY_COMPARE(ma->pressed(), true); + QTest::touchEvent(&window, device).move(0, p1, &window); + QTest::touchEvent(&window, device).release(0, p1, &window); + QTRY_COMPARE(ma->pressed(), false); + QVERIFY(rootItem->property("wasClicked").toBool()); +} + +void tst_qquickwidget::touchTapButton() +{ + QWidget window; + QQuickWidget *quick = new QQuickWidget; + quick->setSource(testFileUrl("button.qml")); + + QHBoxLayout hbox; + hbox.addWidget(quick); + window.setLayout(&hbox); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QQuickItem *rootItem = quick->rootObject(); + QVERIFY(rootItem); + QQuickButton *button = rootItem->findChild<QQuickButton *>("button"); + QVERIFY(button); + + const QPoint point = quick->mapTo(&window, button->mapToScene(button->boundingRect().center()).toPoint()); + QTest::touchEvent(&window, device).press(0, point, &window).commit(); + QTRY_VERIFY(rootItem->property("wasPressed").toBool()); + QTest::touchEvent(&window, device).release(0, point, &window).commit(); + QTRY_VERIFY(rootItem->property("wasReleased").toBool()); + QTRY_VERIFY(rootItem->property("wasClicked").toBool()); +} + +void tst_qquickwidget::touchMultipleWidgets() +{ + QWidget window; + QQuickWidget *leftQuick = new QQuickWidget; + leftQuick->setSource(testFileUrl("button.qml")); + QQuickWidget *rightQuick = new QQuickWidget; + rightQuick->setSource(testFileUrl("button.qml")); + + QHBoxLayout hbox; + hbox.addWidget(leftQuick); + hbox.addWidget(rightQuick); + window.setLayout(&hbox); + window.show(); + QVERIFY(QTest::qWaitForWindowExposed(&window)); + + QQuickItem *leftRootItem = leftQuick->rootObject(); + QQuickItem *rightRootItem = rightQuick->rootObject(); + QVERIFY(leftRootItem); + QVERIFY(rightRootItem); + QQuickButton *leftButton = leftRootItem->findChild<QQuickButton *>("button"); + QQuickButton *rightButton = rightRootItem->findChild<QQuickButton *>("button"); + QVERIFY(leftButton); + QVERIFY(rightButton); + + const QPoint leftPoint = leftQuick->mapTo(&window, leftButton->mapToScene( + leftButton->boundingRect().center()).toPoint()); + const QPoint rightPoint = rightQuick->mapTo(&window, rightButton->mapToScene( + rightButton->boundingRect().center()).toPoint()); + QTest::touchEvent(&window, device).press(0, leftPoint, &window).commit(); + QTRY_VERIFY(leftRootItem->property("wasPressed").toBool()); + QTest::touchEvent(&window, device).press(1, rightPoint, &window).commit(); + QTRY_VERIFY(rightRootItem->property("wasPressed").toBool()); + QTest::touchEvent(&window, device).release(1, rightPoint, &window).commit(); + QTRY_VERIFY(rightRootItem->property("wasReleased").toBool()); + QVERIFY(rightRootItem->property("wasClicked").toBool()); + QTest::touchEvent(&window, device).release(0, leftPoint, &window).commit(); + QTRY_VERIFY(leftRootItem->property("wasReleased").toBool()); + QVERIFY(leftRootItem->property("wasClicked").toBool()); +} + void tst_qquickwidget::tabKey() { if (QGuiApplication::styleHints()->tabFocusBehavior() != Qt::TabFocusAllControls) diff --git a/tests/baseline/controls/tst_baseline_controls.cpp b/tests/baseline/controls/tst_baseline_controls.cpp index 7e5833b786..1faed68311 100644 --- a/tests/baseline/controls/tst_baseline_controls.cpp +++ b/tests/baseline/controls/tst_baseline_controls.cpp @@ -182,9 +182,9 @@ void tst_Baseline_Controls::setupTestSuite() if (testFiles.isEmpty()) QSKIP("No .qml test files found in " + testSuitePath.toLatin1()); - for (const auto &filePath : qAsConst(testFiles)) { - QString itemName = filePath.sliced(testSuitePath.length() + 1); - itemName = itemName.left(itemName.length() - qmlExt.length()); + for (const auto &filePath : std::as_const(testFiles)) { + QString itemName = filePath.sliced(testSuitePath.size() + 1); + itemName = itemName.left(itemName.size() - qmlExt.size()); QBaselineTest::newRow(itemName.toLatin1()) << filePath; } } diff --git a/tests/baseline/scenegraph/data/text/text_nativerendering_no_antialiasing.qml b/tests/baseline/scenegraph/data/text/text_nativerendering_no_antialiasing.qml new file mode 100644 index 0000000000..92598eb490 --- /dev/null +++ b/tests/baseline/scenegraph/data/text/text_nativerendering_no_antialiasing.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +//vary font style, native rendering without antialiasing + +Item { + id: topLevel + width: 320 + height: 580 + + Repeater { + model: [Text.Normal, Text.Outline, Text.Raised, Text.Sunken] + Text { + y: 20 * index + clip: true + renderType: Text.NativeRendering + width: parent.width + wrapMode: Text.Wrap + font.pointSize: 10 + style: modelData + styleColor: "green" + antialiasing: false + text: "The quick fox jumps in style " + modelData + } + } +} diff --git a/tests/baseline/scenegraph/scenegraph/tst_baseline_scenegraph.cpp b/tests/baseline/scenegraph/scenegraph/tst_baseline_scenegraph.cpp index fe8eb66ce9..124580f3b6 100644 --- a/tests/baseline/scenegraph/scenegraph/tst_baseline_scenegraph.cpp +++ b/tests/baseline/scenegraph/scenegraph/tst_baseline_scenegraph.cpp @@ -159,15 +159,15 @@ void tst_Scenegraph::setupTestSuite(const QByteArray& filter) while (it.hasNext()) { QString fp = it.next(); if (fp.endsWith(".qml")) { - QString itemName = fp.mid(testSuitePath.length() + 1); + QString itemName = fp.mid(testSuitePath.size() + 1); if (!ignoreItems.contains(itemName) && (filter.isEmpty() || !itemName.startsWith(filter))) itemFiles.append(it.filePath()); } } std::sort(itemFiles.begin(), itemFiles.end()); - for (const QString &filePath : qAsConst(itemFiles)) { - QByteArray itemName = filePath.mid(testSuitePath.length() + 1).toLatin1(); + for (const QString &filePath : std::as_const(itemFiles)) { + QByteArray itemName = filePath.mid(testSuitePath.size() + 1).toLatin1(); QBaselineTest::newRow(itemName, checksumFileOrDir(filePath)) << filePath; numItems++; } diff --git a/tests/benchmarks/particles/affectors/tst_affectors.cpp b/tests/benchmarks/particles/affectors/tst_affectors.cpp index abce304f9a..172d986186 100644 --- a/tests/benchmarks/particles/affectors/tst_affectors.cpp +++ b/tests/benchmarks/particles/affectors/tst_affectors.cpp @@ -66,7 +66,7 @@ void tst_affectors::test_basic() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible. - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused @@ -106,7 +106,7 @@ void tst_affectors::test_filtered() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[1]->size(), 1000, 10));//Small simulation variance is permissible. - for (QQuickParticleData *d : qAsConst(system->groupData[1]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[1]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/benchmarks/particles/emission/tst_emission.cpp b/tests/benchmarks/particles/emission/tst_emission.cpp index 155e2c6cff..875906ad45 100644 --- a/tests/benchmarks/particles/emission/tst_emission.cpp +++ b/tests/benchmarks/particles/emission/tst_emission.cpp @@ -54,7 +54,7 @@ void tst_emission::test_basic() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible. - for (QQuickParticleData *d : qAsConst(system->groupData[0]->data)) { + for (QQuickParticleData *d : std::as_const(system->groupData[0]->data)) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp b/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp index c4400f4d1b..f64a44d66a 100644 --- a/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp +++ b/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp @@ -239,7 +239,7 @@ void tst_librarymetrics_performance::compilation() if (nResults.size() == 0) nResults.append(9999); for (int i = 0; i < nResults.size(); ++i) totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); + double average = ((double)totaltime) / nResults.size(); // and return it as the result QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); @@ -288,7 +288,7 @@ void tst_librarymetrics_performance::instantiation_cached() if (nResults.size() == 0) nResults.append(9999); for (int i = 0; i < nResults.size(); ++i) totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); + double average = ((double)totaltime) / nResults.size(); // and return it as the result QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); @@ -345,7 +345,7 @@ void tst_librarymetrics_performance::instantiation() if (nResults.size() == 0) nResults.append(9999); for (int i = 0; i < nResults.size(); ++i) totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); + double average = ((double)totaltime) / nResults.size(); // and return it as the result QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); @@ -411,7 +411,7 @@ void tst_librarymetrics_performance::positioners() if (nResults.size() == 0) nResults.append(9999); for (int i = 0; i < nResults.size(); ++i) totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); + double average = ((double)totaltime) / nResults.size(); // and return it as the result QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); diff --git a/tests/benchmarks/qml/qqmlchangeset/CMakeLists.txt b/tests/benchmarks/qml/qqmlchangeset/CMakeLists.txt index 2d6461eefd..ee61a372af 100644 --- a/tests/benchmarks/qml/qqmlchangeset/CMakeLists.txt +++ b/tests/benchmarks/qml/qqmlchangeset/CMakeLists.txt @@ -1,10 +1,10 @@ # Generated from qqmlchangeset.pro. ##################################################################### -## tst_qqmlchangeset Binary: +## tst_bench_qqmlchangeset Binary: ##################################################################### -qt_internal_add_benchmark(tst_qqmlchangeset +qt_internal_add_benchmark(tst_bench_qqmlchangeset SOURCES tst_qqmlchangeset.cpp DEFINES diff --git a/tests/benchmarks/quickcontrols2/creationtime/CMakeLists.txt b/tests/benchmarks/quickcontrols2/creationtime/CMakeLists.txt index 9e3a6d58c1..ad39b3ea0b 100644 --- a/tests/benchmarks/quickcontrols2/creationtime/CMakeLists.txt +++ b/tests/benchmarks/quickcontrols2/creationtime/CMakeLists.txt @@ -1,5 +1,11 @@ # Generated from creationtime.pro. +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_creationtime LANGUAGES C CXX ASM) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + ##################################################################### ## tst_creationtime Test: ##################################################################### diff --git a/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp b/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp index 2e37d00dd8..82259269d9 100644 --- a/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp +++ b/tests/benchmarks/quickcontrols2/creationtime/tst_creationtime.cpp @@ -57,7 +57,7 @@ static void doBenchmark(QQuickStyleHelper &styleHelper, const QUrl &url) QCOMPARE(styleAndFileName.size(), 2); QString style = styleAndFileName.first(); style[0] = style.at(0).toUpper(); - styleHelper.updateStyle(style); + QVERIFY(styleHelper.updateStyle(style)); QQmlComponent component(styleHelper.engine.data()); component.loadUrl(url); @@ -98,7 +98,7 @@ void tst_CreationTime::fusion_data() QTest::addColumn<QUrl>("url"); addTestRowForEachControl(styleHelper.engine.data(), QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion", QStringList() << "ApplicationWindow" << "ButtonPanel" << "CheckIndicator" - << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); + << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator" << "TreeViewDelegate"); } void tst_CreationTime::imagine() @@ -125,7 +125,7 @@ void tst_CreationTime::material_data() QTest::addColumn<QUrl>("url"); addTestRowForEachControl(styleHelper.engine.data(), QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material", QStringList() << "ApplicationWindow" << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" - << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate" << "TreeViewDelegate"); } void tst_CreationTime::universal() diff --git a/tests/benchmarks/quickcontrols2/objectcount/CMakeLists.txt b/tests/benchmarks/quickcontrols2/objectcount/CMakeLists.txt index 752230ec7e..e0434a08eb 100644 --- a/tests/benchmarks/quickcontrols2/objectcount/CMakeLists.txt +++ b/tests/benchmarks/quickcontrols2/objectcount/CMakeLists.txt @@ -1,5 +1,11 @@ # Generated from objectcount.pro. +if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_objectcount LANGUAGES C CXX ASM) + find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST) +endif() + ##################################################################### ## tst_objectcount Test: ##################################################################### diff --git a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp index aad8e7d571..e1d37eec8f 100644 --- a/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp +++ b/tests/benchmarks/quickcontrols2/objectcount/tst_objectcount.cpp @@ -67,11 +67,12 @@ static void initTestRows(QQmlEngine *engine) addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "basic", "QtQuick/Controls/Basic", QStringList() << "Calendar" << "TreeViewDelegate"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "fusion", "QtQuick/Controls/Fusion", - QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" << "SliderHandle" << "SwitchIndicator"); + QStringList() << "ButtonPanel" << "CheckIndicator" << "RadioIndicator" << "SliderGroove" + << "SliderHandle" << "SwitchIndicator" << "TreeViewDelegate"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "imagine", "QtQuick/Controls/Imagine"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "material", "QtQuick/Controls/Material", QStringList() << "Ripple" << "SliderHandle" << "CheckIndicator" << "RadioIndicator" - << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate"); + << "SwitchIndicator" << "BoxShadow" << "ElevationEffect" << "CursorDelegate" << "TreeViewDelegate"); addTestRowForEachControl(engine, QQC2_IMPORT_PATH, "universal", "QtQuick/Controls/Universal", QStringList() << "CheckIndicator" << "RadioIndicator" << "SwitchIndicator"); } @@ -88,7 +89,7 @@ static void doBenchmark(QQmlEngine *engine, const QUrl &url) QVERIFY2(object.data(), qPrintable(component.errorString())); QObjectList objects; - for (QObject *object : qAsConst(*qt_qobjects())) { + for (QObject *object : std::as_const(*qt_qobjects())) { if (qobject_cast<T *>(object)) objects += object; } @@ -98,7 +99,7 @@ static void doBenchmark(QQmlEngine *engine, const QUrl &url) qInfo() << "\t" << object; } - QTest::setBenchmarkResult(objects.count(), QTest::Events); + QTest::setBenchmarkResult(objects.size(), QTest::Events); } void tst_ObjectCount::qobjects() diff --git a/tests/manual/pointer/pinchNullTarget.qml b/tests/manual/pointer/pinchNullTarget.qml new file mode 100644 index 0000000000..79c6047991 --- /dev/null +++ b/tests/manual/pointer/pinchNullTarget.qml @@ -0,0 +1,50 @@ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick 2.15 + +Rectangle { + width: 1024; height: 600 + color: "#eee" + + function getTransformationDetails(item, pinchhandler) { + return "\n\npinch.scale:" + pinchhandler.scale.toFixed(2) + + "\npinch.activeScale:" + pinchhandler.activeScale.toFixed(2) + + "\npinch.rotation:" + pinchhandler.rotation.toFixed(2) + + "\npinch.translation:" + "(" + pinchhandler.translation.x.toFixed(2) + "," + pinchhandler.translation.y.toFixed(2) + ")" + + "\nrect.scale: " + item.scale.toFixed(2) + + "\nrect.rotation: " + item.rotation.toFixed(2) + + "\nrect.position: " + "(" + item.x.toFixed(2) + "," + item.y.toFixed(2) + ")" + } + + Rectangle { + width: parent.width - 100; height: parent.height - 100; x: 50; y: 50 + color: "lightsteelblue" + antialiasing: true + scale: pinch.scale + + PinchHandler { + id: pinch + target: null + minimumScale: 0.5 + maximumScale: 3 + } + + Text { + text: "Pinch with 2 fingers to scale, rotate and translate" + + getTransformationDetails(parent, pinch) + } + } + + Rectangle { + id: centroidIndicator + x: pinch.centroid.scenePosition.x - radius + y: pinch.centroid.scenePosition.y - radius + z: 1 + visible: pinch.active + radius: width / 2 + width: 10 + height: width + color: "red" + } +} diff --git a/tests/manual/quickcontrols2/headerview/main.qml b/tests/manual/quickcontrols2/headerview/main.qml index f8504b9f7f..89367d91bf 100644 --- a/tests/manual/quickcontrols2/headerview/main.qml +++ b/tests/manual/quickcontrols2/headerview/main.qml @@ -14,6 +14,7 @@ Window { width: 640 height: 480 title: qsTr("HeaderView Test") + color: Qt.styleHints.appearance === Qt.Light ? palette.mid : palette.midlight TestTableModelWithHeader { id: tableModel @@ -30,8 +31,8 @@ Window { model: tableModel rightMargin: 100 bottomMargin: 100 - columnSpacing: 4 - rowSpacing: 4 + columnSpacing: 1 + rowSpacing: 1 syncDirection: Qt.Vertical | Qt.Horizontal implicitWidth: parent.width + columnSpacing implicitHeight: parent.height + rowSpacing @@ -39,7 +40,7 @@ Window { delegate: Rectangle { implicitWidth: 150 implicitHeight: 50 - color: "#e6ecf5" + color: tableView.palette.base CheckBox { anchors.fill: parent @@ -68,12 +69,17 @@ Window { clip: true } - ToolButton { + Rectangle { width: verticalHeader.width height: horizontalHeader.height - onClicked: { - horizontalHeader.contentX = 0 - verticalHeader.contentY = 0 + color: palette.base + ToolButton { + anchors.fill: parent + text: "<<" + onClicked: { + horizontalHeader.contentX = 0 + verticalHeader.contentY = 0 + } } } } diff --git a/tests/manual/quickcontrols2/testbench/controls/Button.qml b/tests/manual/quickcontrols2/testbench/controls/Button.qml index 5c0b67d2b6..1dcf05da36 100644 --- a/tests/manual/quickcontrols2/testbench/controls/Button.qml +++ b/tests/manual/quickcontrols2/testbench/controls/Button.qml @@ -9,25 +9,47 @@ QtObject { [], ["disabled"], ["pressed"], - ["checked"], - ["checked", "disabled"], - ["checked"], + ["checkable", "checked"], + ["checkable", "checked", "disabled"], + ["checkable", "checked"], ["highlighted"], ["highlighted", "disabled"], ["highlighted", "pressed"], - ["highlighted", "checked"], + ["highlighted", "checkable"], ["highlighted", "checkable", "pressed"], ["highlighted", "checkable", "checked"], + ["icon"], + ["icon", "disabled"], + ["icon", "pressed"], + ["icon", "checkable", "checked"], + ["icon", "checkable", "checked", "disabled"], + ["icon", "checkable", "checked"], + ["icon", "highlighted"], + ["icon", "highlighted", "disabled"], + ["icon", "highlighted", "pressed"], + ["icon", "highlighted", "checkable"], + ["icon", "highlighted", "checkable", "pressed"], + ["icon", "highlighted", "checkable", "checked"], ["flat"], ["flat", "disabled"], ["flat", "pressed"], - ["flat", "checked"], ["flat", "checkable"], + ["flat", "checkable", "checked"], ["flat", "checkable", "pressed"], ["flat", "checkable", "checked", "pressed"], ["flat", "checkable", "highlighted"], ["flat", "checkable", "highlighted", "pressed"], - ["flat", "checkable", "highlighted", "checked"] + ["flat", "checkable", "highlighted", "checked"], + ["icon", "flat"], + ["icon", "flat", "disabled"], + ["icon", "flat", "pressed"], + ["icon", "flat", "checkable"], + ["icon", "flat", "checkable", "checked"], + ["icon", "flat", "checkable", "pressed"], + ["icon", "flat", "checkable", "checked", "pressed"], + ["icon", "flat", "checkable", "highlighted"], + ["icon", "flat", "checkable", "highlighted", "pressed"], + ["icon", "flat", "checkable", "highlighted", "checked"] ] property Component component: Button { @@ -39,5 +61,6 @@ QtObject { // Only set it if it's pressed, or the non-pressed examples will have no press effects down: is("pressed") ? true : undefined highlighted: is("highlighted") + icon.source: is("icon") ? "qrc:/qt-project.org/imports/QtQuick/Controls/Basic/images/check.png" : "" } } |