diff options
Diffstat (limited to 'tests/auto/quick')
36 files changed, 951 insertions, 442 deletions
diff --git a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp index f141a2546c..575139f851 100644 --- a/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp +++ b/tests/auto/quick/pointerhandlers/qquickhoverhandler/tst_qquickhoverhandler.cpp @@ -252,7 +252,7 @@ void tst_HoverHandler::movingItemWithHoverHandler() QTRY_COMPARE(window->isVisible(), false); QCursor::setPos(paddlePos); window->show(); - QTest::qWaitForWindowExposed(window); + QVERIFY(QTest::qWaitForWindowExposed(window)); QTRY_COMPARE(paddleHH->isHovered(), true); diff --git a/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro b/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro index 85f71bb605..a337473d99 100644 --- a/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro +++ b/tests/auto/quick/qquickanimatedsprite/qquickanimatedsprite.pro @@ -8,7 +8,7 @@ macx:CONFIG -= app_bundle TESTDATA = data/* -QT += core-private gui-private qml-private quick-private network testlib +QT += core-private gui-private qml-private quick-private network testlib qmltest OTHER_FILES += \ $$files(data/*.qml) diff --git a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp index 4ca31fd957..d2bbf9e6b1 100644 --- a/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp +++ b/tests/auto/quick/qquickanimatedsprite/tst_qquickanimatedsprite.cpp @@ -28,6 +28,7 @@ #include <QtTest/QtTest> #include "../../shared/util.h" #include <QtQuick/qquickview.h> +#include <QtQuickTest/QtQuickTest> #include <private/qabstractanimation_p.h> #include <private/qquickanimatedsprite_p.h> #include <private/qquickitem_p.h> @@ -290,8 +291,8 @@ void tst_qquickanimatedsprite::test_reparenting() sprite->setParentItem(window.rootObject()); // don't crash (QTBUG-51162) sprite->polish(); - QTRY_COMPARE(QQuickItemPrivate::get(sprite)->polishScheduled, true); - QTRY_COMPARE(QQuickItemPrivate::get(sprite)->polishScheduled, false); + QVERIFY(QQuickTest::qIsPolishScheduled(sprite)); + QVERIFY(QQuickTest::qWaitForItemPolished(sprite)); } class KillerThread : public QThread diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp index 0f095774e8..961506372a 100644 --- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp +++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp @@ -1207,7 +1207,7 @@ void tst_qquickanimations::easingProperties() QVERIFY(animObject != nullptr); QCOMPARE(animObject->easing().type(), QEasingCurve::BezierSpline); - QList<QPointF> points = animObject->easing().cubicBezierSpline(); + QVector<QPointF> points = animObject->easing().toCubicSpline(); QCOMPARE(points.count(), 3); QCOMPARE(points.at(0), QPointF(0.5, 0.2)); QCOMPARE(points.at(1), QPointF(0.13, 0.65)); diff --git a/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml index 09983645ef..0ac7f87c42 100644 --- a/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml +++ b/tests/auto/quick/qquickbehaviors/data/ItemWithInnerBehavior.qml @@ -5,6 +5,7 @@ Item { property bool someValue Behavior on someValue { + objectName: "behavior" ScriptAction { script: { parent.behaviorTriggered = true }} } } diff --git a/tests/auto/quick/qquickbehaviors/data/aliased.qml b/tests/auto/quick/qquickbehaviors/data/aliased.qml index e65e035d83..1840cdd22e 100644 --- a/tests/auto/quick/qquickbehaviors/data/aliased.qml +++ b/tests/auto/quick/qquickbehaviors/data/aliased.qml @@ -17,6 +17,7 @@ Rectangle { anchors.fill: parent value: accelerating ? 400 : 0 Behavior on value { + objectName: "behavior" NumberAnimation { duration: 500 } diff --git a/tests/auto/quick/qquickbehaviors/data/oneway.qml b/tests/auto/quick/qquickbehaviors/data/oneway.qml new file mode 100644 index 0000000000..0b438b80f6 --- /dev/null +++ b/tests/auto/quick/qquickbehaviors/data/oneway.qml @@ -0,0 +1,20 @@ +import QtQuick 2.0 +Rectangle { + width: 400 + height: 400 + Rectangle { + id: rect + objectName: "MyRectOneWay" + width: 100; height: 100; color: "green" + Behavior on x { + id: behavior + objectName: "MyBehaviorOneWay"; + enabled: (behavior.targetValue === 0) + NumberAnimation { + id: ani + objectName: "MyAnimationOneWay"; + duration: 200; + } + } + } +} diff --git a/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro b/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro index 51bc42c390..fd64eb1d40 100644 --- a/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro +++ b/tests/auto/quick/qquickbehaviors/qquickbehaviors.pro @@ -7,5 +7,5 @@ include (../../shared/util.pri) macx:CONFIG -= app_bundle TESTDATA = data/* - +DISTFILES = $$files(data/*) QT += core-private gui-private qml-private quick-private testlib diff --git a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp index fa9eba095d..6367f327da 100644 --- a/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp +++ b/tests/auto/quick/qquickbehaviors/tst_qquickbehaviors.cpp @@ -73,6 +73,7 @@ private slots: void disabledWriteWhileRunning(); void aliasedProperty(); void innerBehaviorOverwritten(); + void oneWay(); }; void tst_qquickbehaviors::simpleBehavior() @@ -516,6 +517,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() myRect->setProperty("x", 200); QCOMPARE(myAnimation->isRunning(), true); QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200)); + QCOMPARE(myBehavior->targetValue(), 200); // grabbed before starting the animation // set disabled while animation is in progress myBehavior->setProperty("enabled", false); @@ -526,6 +528,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() myRect->setProperty("x", 100); QCOMPARE(myAnimation->isRunning(), false); QCOMPARE(myRect->x(), qreal(100)); + QCOMPARE(myBehavior->targetValue(), 100); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); } @@ -546,17 +549,20 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() // initial values QCOMPARE(myBehavior->enabled(), true); + QCOMPARE(myBehavior->targetValue(), QVariant()); QCOMPARE(myAnimation->isRunning(), false); QCOMPARE(myRect->x(), qreal(0)); // start animation myRect->setProperty("x", 200); QCOMPARE(myAnimation->isRunning(), true); + QCOMPARE(myBehavior->targetValue(), 200); QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200)); //set second value myRect->setProperty("x", 300); QCOMPARE(myAnimation->isRunning(), true); + QCOMPARE(myBehavior->targetValue(), 300); QTRY_VERIFY(myRect->x() != qreal(0) && myRect->x() != qreal(200)); // set disabled while animation is in progress @@ -568,6 +574,7 @@ void tst_qquickbehaviors::disabledWriteWhileRunning() myRect->setProperty("x", 100); QCOMPARE(myAnimation->isRunning(), false); QCOMPARE(myRect->x(), qreal(100)); + QCOMPARE(myBehavior->targetValue(), 100); QTest::qWait(200); QCOMPARE(myRect->x(), qreal(100)); } @@ -580,7 +587,12 @@ void tst_qquickbehaviors::aliasedProperty() QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create())); QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); + QQuickBehavior* behavior = + qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("behavior")); + QSignalSpy targetValueSpy(behavior, SIGNAL(targetValueChanged())); QQuickItemPrivate::get(rect.data())->setState("moved"); + QCOMPARE(behavior->targetValue(), 400); + QCOMPARE(targetValueSpy.count(), 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); @@ -595,7 +607,44 @@ void tst_qquickbehaviors::innerBehaviorOverwritten() QQmlEngine engine; QQmlComponent c(&engine, testFileUrl("overwrittenbehavior.qml")); QScopedPointer<QQuickItem> item(qobject_cast<QQuickItem*>(c.create())); + QQuickBehavior* behavior = + qobject_cast<QQuickBehavior*>(item->findChild<QQuickBehavior*>("behavior")); QVERIFY(item->property("behaviorTriggered").toBool()); + QCOMPARE(behavior->targetValue(), true); +} + +void tst_qquickbehaviors::oneWay() +{ + QQmlEngine engine; + QQmlComponent c(&engine, testFileUrl("oneway.qml")); + QScopedPointer<QQuickRectangle> rect(qobject_cast<QQuickRectangle*>(c.create()));; + QVERIFY2(!rect.isNull(), qPrintable(c.errorString())); + QQuickBehavior* behavior = + qobject_cast<QQuickBehavior*>(rect->findChild<QQuickBehavior*>("MyBehaviorOneWay")); + QCOMPARE(behavior->enabled(), false); + QCOMPARE(behavior->targetValue(), QVariant()); + + QSignalSpy targetValueSpy(behavior, SIGNAL(targetValueChanged())); + QQuickRectangle *myRect = qobject_cast<QQuickRectangle*>(rect->findChild<QQuickRectangle*>("MyRectOneWay")); + myRect->setProperty("x", 100); + QCOMPARE(behavior->targetValue(), 100); + QCOMPARE(targetValueSpy.count(), 1); + QCOMPARE(behavior->enabled(), false); + qreal x = myRect->x(); + QCOMPARE(x, qreal(100)); //should change immediately + QQuickNumberAnimation *myAnimation = + qobject_cast<QQuickNumberAnimation*>(behavior->findChild<QQuickNumberAnimation*>("MyAnimationOneWay")); + QCOMPARE(myAnimation->isRunning(), false); + + myRect->setProperty("x", 0); + QCOMPARE(behavior->targetValue(), 0); + QCOMPARE(targetValueSpy.count(), 2); + QCOMPARE(behavior->enabled(), true); + QCOMPARE(myAnimation->isRunning(), true); + QVERIFY(myRect->x() > 0.0); + QTRY_VERIFY(myRect->x() < 100.0); + QTRY_COMPARE(myRect->x(), qreal(0)); + QCOMPARE(myAnimation->isRunning(), false); } QTEST_MAIN(tst_qquickbehaviors) diff --git a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp index 3c7159782c..cf01cc927b 100644 --- a/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp +++ b/tests/auto/quick/qquickdroparea/tst_qquickdroparea.cpp @@ -188,14 +188,16 @@ void tst_QQuickDropArea::containsDrag_external() const qreal dpr = window.devicePixelRatio(); const QPoint nativePos1 = QPoint(50, 50) * dpr; const QPoint nativePos2 = QPoint(150, 50) * dpr; - QWindowSystemInterface::handleDrag(&window, &data, nativePos1, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, nativePos1, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<bool>(dropArea, "hasDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(evaluate<int>(dropArea, "exitEvents"), 0); evaluate<void>(dropArea, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, nativePos1, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, nativePos1, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); QCOMPARE(evaluate<bool>(dropArea, "hasDrag"), false); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); @@ -203,13 +205,15 @@ void tst_QQuickDropArea::containsDrag_external() evaluate<void>(dropArea, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, nativePos2, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, nativePos2, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); QCOMPARE(evaluate<bool>(dropArea, "hasDrag"), false); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea, "exitEvents"), 0); - QWindowSystemInterface::handleDrag(&window, &data, nativePos1, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, nativePos1, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<bool>(dropArea, "hasDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); @@ -217,13 +221,15 @@ void tst_QQuickDropArea::containsDrag_external() evaluate<void>(dropArea, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, nativePos2, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, nativePos2, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); QCOMPARE(evaluate<bool>(dropArea, "hasDrag"), false); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea, "exitEvents"), 1); - QWindowSystemInterface::handleDrop(&window, &data, nativePos2, Qt::CopyAction); + QWindowSystemInterface::handleDrop(&window, &data, nativePos2, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); } void tst_QQuickDropArea::keys_internal() @@ -358,80 +364,96 @@ void tst_QQuickDropArea::keys_external() QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList() << "text/x-red" << "text/x-blue"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); evaluate<void>(dropArea, "keys = \"text/x-blue\""); QCOMPARE(dropArea->property("keys").toStringList(), QStringList() << "text/x-blue"); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList() << "text/x-blue"); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList() << "text/x-red" << "text/x-blue"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); evaluate<void>(dropArea, "keys = \"text/x-red\""); QCOMPARE(dropArea->property("keys").toStringList(), QStringList() << "text/x-red"); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList() << "text/x-red"); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList() << "text/x-red" << "text/x-blue"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); evaluate<void>(dropArea, "keys = \"text/x-green\""); QCOMPARE(dropArea->property("keys").toStringList(), QStringList() << "text/x-green"); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList() << "text/x-green"); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); evaluate<void>(dropArea, "keys = [\"text/x-red\", \"text/x-green\"]"); QCOMPARE(dropArea->property("keys").toStringList(), QStringList() << "text/x-red" << "text/x-green"); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList() << "text/x-red" << "text/x-green"); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList() << "text/x-red" << "text/x-blue"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); data.removeFormat("text/x-red"); data.removeFormat("text/x-blue"); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); evaluate<void>(dropArea, "keys = []"); QCOMPARE(dropArea->property("keys").toStringList(), QStringList()); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList()); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList()); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); data.setData("text/x-red", "red"); data.setData("text/x-blue", "blue"); QCOMPARE(dropArea->property("keys").toStringList(), QStringList()); QCOMPARE(dropArea->property("dropKeys").toStringList(), QStringList()); evaluate<void>(dropArea, "{ enterEvents = 0; dragKeys = undefined }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(dropArea->property("dragKeys").toStringList(), QStringList() << "text/x-red" << "text/x-blue"); - QWindowSystemInterface::handleDrop(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrop(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); } void tst_QQuickDropArea::source_internal() @@ -587,7 +609,8 @@ void tst_QQuickDropArea::position_external() QMimeData data; const qreal dpr = window.devicePixelRatio(); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50) * dpr, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50) * dpr, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 1); QCOMPARE(evaluate<int>(dropArea, "moveEvents"), 1); QCOMPARE(evaluate<qreal>(dropArea, "drag.x"), qreal(50)); @@ -598,7 +621,8 @@ void tst_QQuickDropArea::position_external() QCOMPARE(evaluate<qreal>(dropArea, "eventY"), qreal(50)); evaluate<void>(dropArea, "{ enterEvents = 0; moveEvents = 0; eventX = -1; eventY = -1 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(40, 50) * dpr, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(40, 50) * dpr, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea, "moveEvents"), 1); QCOMPARE(evaluate<qreal>(dropArea, "drag.x"), qreal(40)); @@ -609,7 +633,8 @@ void tst_QQuickDropArea::position_external() QCOMPARE(evaluate<qreal>(dropArea, "eventY"), qreal(50)); evaluate<void>(dropArea, "{ enterEvents = 0; moveEvents = 0; eventX = -1; eventY = -1 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(75, 25) * dpr, Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(75, 25) * dpr, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<int>(dropArea, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea, "moveEvents"), 1); QCOMPARE(evaluate<qreal>(dropArea, "drag.x"), qreal(75)); @@ -619,7 +644,8 @@ void tst_QQuickDropArea::position_external() QCOMPARE(evaluate<qreal>(dropArea, "eventX"), qreal(75)); QCOMPARE(evaluate<qreal>(dropArea, "eventY"), qreal(25)); - QWindowSystemInterface::handleDrop(&window, &data, QPoint(75, 25) * dpr, Qt::CopyAction); + QWindowSystemInterface::handleDrop(&window, &data, QPoint(75, 25) * dpr, Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); } void tst_QQuickDropArea::drop_internal() @@ -930,7 +956,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); //Same as in the first case, dropArea2 already contains a drag, dropArea1 will get the event QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 1); @@ -939,7 +966,8 @@ void tst_QQuickDropArea::simultaneousDrags() QCOMPARE(evaluate<int>(dropArea2, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea2, "exitEvents"), 0); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 1); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 1); @@ -947,7 +975,8 @@ void tst_QQuickDropArea::simultaneousDrags() QCOMPARE(evaluate<int>(dropArea2, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea2, "exitEvents"), 0); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 2); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 1); @@ -965,7 +994,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 1); @@ -976,7 +1006,8 @@ void tst_QQuickDropArea::simultaneousDrags() // external then internal. evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 0); @@ -1010,7 +1041,8 @@ void tst_QQuickDropArea::simultaneousDrags() QCOMPARE(evaluate<int>(dropArea2, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea2, "exitEvents"), 0); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 2); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 1); @@ -1106,7 +1138,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 0); @@ -1116,7 +1149,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 0); @@ -1126,7 +1160,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), true); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 0); @@ -1146,7 +1181,8 @@ void tst_QQuickDropArea::simultaneousDrags() evaluate<void>(dropArea1, "{ enterEvents = 0; exitEvents = 0 }"); evaluate<void>(dropArea2, "{ enterEvents = 0; exitEvents = 0 }"); - QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<bool>(dropArea1, "containsDrag"), false); QCOMPARE(evaluate<int>(dropArea1, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea1, "exitEvents"), 0); @@ -1154,7 +1190,8 @@ void tst_QQuickDropArea::simultaneousDrags() QCOMPARE(evaluate<int>(dropArea2, "enterEvents"), 0); QCOMPARE(evaluate<int>(dropArea2, "exitEvents"), 1); - QWindowSystemInterface::handleDrop(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrop(&alternateWindow, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); } void tst_QQuickDropArea::dropStuff() @@ -1179,8 +1216,10 @@ void tst_QQuickDropArea::dropStuff() QCOMPARE(evaluate<QVariant>(dropArea, "array"), QVariant()); - QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction); - QWindowSystemInterface::handleDrop(&window, &data, QPoint(50, 50), Qt::CopyAction); + QWindowSystemInterface::handleDrag(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); + QWindowSystemInterface::handleDrop(&window, &data, QPoint(50, 50), Qt::CopyAction, + Qt::MouseButtons(), Qt::KeyboardModifiers()); QCOMPARE(evaluate<int>(dropArea, "array.byteLength"), 3); QCOMPARE(evaluate<QByteArray>(dropArea, "array"), QByteArray("red")); } diff --git a/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp b/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp index 6e516f51e1..ef61c45225 100644 --- a/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp +++ b/tests/auto/quick/qquickfontmetrics/tst_quickfontmetrics.cpp @@ -127,7 +127,7 @@ void tst_QuickFontMetrics::functions() QFontMetricsF expected = QFontMetricsF(QFont()); QCOMPARE(metrics.elidedText(text, mode, width, flags), expected.elidedText(text, mode, width, flags)); - QCOMPARE(metrics.advanceWidth(text), expected.width(text)); + QCOMPARE(metrics.advanceWidth(text), expected.horizontalAdvance(text)); QCOMPARE(metrics.boundingRect(text), expected.boundingRect(text)); QCOMPARE(metrics.tightBoundingRect(text), expected.tightBoundingRect(text)); } diff --git a/tests/auto/quick/qquickgridview/qquickgridview.pro b/tests/auto/quick/qquickgridview/qquickgridview.pro index 3c33cc78fb..5051f8bc62 100644 --- a/tests/auto/quick/qquickgridview/qquickgridview.pro +++ b/tests/auto/quick/qquickgridview/qquickgridview.pro @@ -10,5 +10,5 @@ include (../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmltest diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index e346e25aaf..448096720c 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -29,6 +29,7 @@ #include <QtTest/QtTest> #include <QtCore/qstringlistmodel.h> #include <QtQuick/qquickview.h> +#include <QtQuickTest/QtQuickTest> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcomponent.h> #include <QtQml/qqmlcontext.h> @@ -535,7 +536,7 @@ void tst_QQuickGridView::inserted_defaultLayout(QQuickGridView::Flow flow, insertCount = insertCount_ttb; } if (setContentPos(gridview, contentYRowOffset)) - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QList<QPair<QString, QString> > newData; for (int i=0; i<insertCount; i++) @@ -721,13 +722,13 @@ void tst_QQuickGridView::insertBeforeVisible() QTRY_VERIFY(contentItem != nullptr); gridview->setCacheBuffer(cacheBuffer); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // trigger a refill (not just setting contentY) so that the visibleItems grid is updated int firstVisibleIndex = 12; // move to an index where the top item is not visible gridview->setContentY(firstVisibleIndex/3 * 60.0); gridview->setCurrentIndex(firstVisibleIndex); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QTRY_COMPARE(gridview->currentIndex(), firstVisibleIndex); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", firstVisibleIndex); @@ -744,7 +745,7 @@ void tst_QQuickGridView::insertBeforeVisible() // now, moving to the top of the view should position the inserted items correctly int itemsOffsetAfterMove = (insertCount / 3) * -60.0; gridview->setCurrentIndex(0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QTRY_COMPARE(gridview->currentIndex(), 0); QTRY_COMPARE(gridview->contentY(), 0.0 + itemsOffsetAfterMove); @@ -803,7 +804,7 @@ void tst_QQuickGridView::removed_basic() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.removeItem(1); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); @@ -890,7 +891,7 @@ void tst_QQuickGridView::removed_basic() QTRY_VERIFY(gridview->currentItem() != oldCurrent); gridview->setContentY(0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // Confirm items positioned correctly itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -966,7 +967,7 @@ void tst_QQuickGridView::removed_defaultLayout(QQuickGridView::Flow flow, firstVisible = firstVisible_ttb; } if (setContentPos(gridview, contentYRowOffset)) - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.removeItems(removeIndex, removeCount); gridview->forceLayout(); @@ -1182,7 +1183,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() gridview->setCurrentIndex(0); qApp->processEvents(); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // scroll down until item 0 is no longer drawn // (bug not triggered if we just move using content y, since that doesn't @@ -1193,7 +1194,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible() QTRY_COMPARE(gridview->currentIndex(), 24); QTRY_COMPARE(gridview->contentY(), 220.0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QTRY_VERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 0)); // 0 shouldn't be visible if (doAdd) { @@ -1254,7 +1255,7 @@ void tst_QQuickGridView::clear() QVERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.clear(); gridview->forceLayout(); @@ -1307,7 +1308,7 @@ void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow, QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *currentItem = gridview->currentItem(); QTRY_VERIFY(currentItem != nullptr); @@ -1318,10 +1319,10 @@ void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow, count = count_ttb; } if (setContentPos(gridview, contentYRowOffset)) - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.moveItems(from, to, count); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // Confirm items positioned correctly and indexes correct QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); @@ -1560,7 +1561,7 @@ void tst_QQuickGridView::multipleChanges(bool condensed) QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid"); QTRY_VERIFY(gridview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); for (int i=0; i<changes.count(); i++) { switch (changes[i].type) { @@ -1588,10 +1589,10 @@ void tst_QQuickGridView::multipleChanges(bool condensed) break; } if (condensed) { - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); } } - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(gridview->count(), newCount); QCOMPARE(gridview->count(), model.count()); @@ -1834,7 +1835,7 @@ void tst_QQuickGridView::currentIndex() QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid"); QVERIFY(gridview != nullptr); - QTRY_VERIFY(!QQuickItemPrivate::get(gridview)->polishScheduled); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); @@ -1936,7 +1937,7 @@ void tst_QQuickGridView::noCurrentIndex() QVERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // current index should be -1 QCOMPARE(gridview->currentIndex(), -1); @@ -1981,7 +1982,7 @@ void tst_QQuickGridView::keyNavigation() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -2491,7 +2492,7 @@ void tst_QQuickGridView::positionViewAtBeginningEnd() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // positionViewAtBeginning gridview->setContentY(150); @@ -2578,10 +2579,10 @@ void tst_QQuickGridView::positionViewAtIndex() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); window->rootObject()->setProperty("enforceRange", enforceRange); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); if (topToBottom) gridview->setContentX(initContentPos); @@ -2791,7 +2792,7 @@ void tst_QQuickGridView::resetModel() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QTRY_COMPARE(gridview->count(), model.rowCount()); @@ -2840,7 +2841,7 @@ void tst_QQuickGridView::enforceRange() QTRY_COMPARE(gridview->preferredHighlightBegin(), 100.0); QTRY_COMPARE(gridview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(gridview->highlightRangeMode(), QQuickGridView::StrictlyEnforceRange); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3023,7 +3024,7 @@ void tst_QQuickGridView::footer() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3272,7 +3273,7 @@ void tst_QQuickGridView::header() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3296,7 +3297,7 @@ void tst_QQuickGridView::header() QCOMPARE(item->position(), firstDelegatePos); model.clear(); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(header->position(), initialHeaderPos); // header should stay where it is if (flow == QQuickGridView::FlowLeftToRight) QCOMPARE(gridview->contentHeight(), header->height()); @@ -3349,7 +3350,7 @@ void tst_QQuickGridView::header() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); gridview->setWidth(240); gridview->setHeight(320); @@ -3494,7 +3495,7 @@ void tst_QQuickGridView::extents() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3655,7 +3656,7 @@ void tst_QQuickGridView::resizeViewAndRepaint() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // item at index 10 should not be currently visible QVERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 10)); @@ -3736,7 +3737,7 @@ void tst_QQuickGridView::resizeGrid() // items are aligned correctly in right-to-left window->rootObject()->setWidth(260); window->rootObject()->setHeight(320); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(gridview->contentX(), initialContentPos.x()); QCOMPARE(gridview->contentY(), initialContentPos.y()); @@ -3760,7 +3761,7 @@ void tst_QQuickGridView::resizeGrid() // change from 3x5 grid to 4x7 window->rootObject()->setWidth(window->rootObject()->width() + 80); window->rootObject()->setHeight(window->rootObject()->height() + 60*2); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // other than in LeftToRight+RightToLeft layout, the first item should not move // if view is resized @@ -3865,7 +3866,7 @@ void tst_QQuickGridView::changeColumnCount() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); // a single column of 6 items are visible int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -3879,7 +3880,7 @@ void tst_QQuickGridView::changeColumnCount() // now 6x3 grid is visible, plus 1 extra below for refill gridview->setWidth(240); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); QCOMPARE(itemCount, 6*3 + 1); for (int i = 0; i < model.count() && i < itemCount; ++i) { @@ -3891,7 +3892,7 @@ void tst_QQuickGridView::changeColumnCount() // back to single column gridview->setWidth(100); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); QCOMPARE(itemCount, 6); for (int i = 0; i < model.count() && i < itemCount; ++i) { @@ -4139,7 +4140,7 @@ void tst_QQuickGridView::margins() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(gridview->contentX(), -30.); QCOMPARE(gridview->originX(), 0.); @@ -4217,7 +4218,7 @@ void tst_QQuickGridView::margins() // remove item before visible and check that left margin is maintained // and originX is updated gridview->setContentX(-400); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.removeItems(0, 4); gridview->forceLayout(); QTRY_COMPARE(model.count(), gridview->count()); @@ -4259,7 +4260,7 @@ void tst_QQuickGridView::margins() QVERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(contentItem->x(), 200); QCOMPARE(contentItem->y(), 20); @@ -4341,7 +4342,7 @@ void tst_QQuickGridView::snapToRow() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode)); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -4461,7 +4462,7 @@ void tst_QQuickGridView::snapOneRow() gridview->setFlow(flow); gridview->setLayoutDirection(layoutDirection); gridview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode)); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QQuickItem *contentItem = gridview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -4623,7 +4624,7 @@ void tst_QQuickGridView::populateTransitions() QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), 0); QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 18); } else { - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QCOMPARE(gridview->property("countPopulateTransitions").toInt(), 0); QCOMPARE(gridview->property("countAddTransitions").toInt(), 0); } @@ -4659,7 +4660,7 @@ void tst_QQuickGridView::populateTransitions() for (int i = 0; i < 30; i++) model.addItem("item" + QString::number(i), ""); window->rootContext()->setContextProperty("testModel", &model); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QTRY_COMPARE(gridview->property("countPopulateTransitions").toInt(), usePopulateTransition ? 18 : 0); QTRY_COMPARE(gridview->property("countAddTransitions").toInt(), 0); @@ -4747,11 +4748,11 @@ void tst_QQuickGridView::addTransitions() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); if (contentYRowOffset != 0) { gridview->setContentY(contentYRowOffset * 60.0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -4956,7 +4957,7 @@ void tst_QQuickGridView::moveTransitions() if (contentYRowOffset != 0) { gridview->setContentY(contentYRowOffset * 60.0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -5197,11 +5198,11 @@ void tst_QQuickGridView::removeTransitions() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); if (contentYRowOffset != 0) { gridview->setContentY(contentYRowOffset * 60.0); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -5415,7 +5416,7 @@ void tst_QQuickGridView::displacedTransitions() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); gridview->setProperty("displaceTransitionsDone", false); @@ -5436,7 +5437,7 @@ void tst_QQuickGridView::displacedTransitions() break; case ListChange::Moved: model.moveItems(change.index, change.to, change.count); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); break; case ListChange::SetCurrent: case ListChange::SetContentY: @@ -5634,11 +5635,11 @@ void tst_QQuickGridView::multipleTransitions() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); if (contentY != 0) { gridview->setContentY(contentY); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); } int timeBetweenActions = window->rootObject()->property("timeBetweenActions").toInt(); @@ -5675,7 +5676,7 @@ void tst_QQuickGridView::multipleTransitions() case ListChange::Moved: model.moveItems(changes[i].index, changes[i].to, changes[i].count); gridview->forceLayout(); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); if (i == changes.count() - 1) { QTRY_VERIFY(!gridview->property("runningMoveTargets").toBool()); QTRY_VERIFY(!gridview->property("runningMoveDisplaced").toBool()); @@ -5685,12 +5686,12 @@ void tst_QQuickGridView::multipleTransitions() break; case ListChange::SetCurrent: gridview->setCurrentIndex(changes[i].index); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); gridview->forceLayout(); break; case ListChange::SetContentY: gridview->setContentY(changes[i].pos); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); gridview->forceLayout(); break; case ListChange::Polish: @@ -5804,7 +5805,7 @@ void tst_QQuickGridView::multipleDisplaced() QTRY_VERIFY(gridview != nullptr); QQuickItem *contentItem = gridview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.moveItems(12, 8, 1); QTest::qWait(window->rootObject()->property("duration").toInt() / 2); @@ -5854,7 +5855,7 @@ void tst_QQuickGridView::regression_QTBUG_57225() QQuickGridView *gridview = findItem<QQuickGridView>(window->rootObject(), "grid"); QVERIFY(gridview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(gridview)); model.removeItems(removeIndex, removeCount); QTRY_VERIFY(gridview->property("animationDone").toBool()); @@ -6127,7 +6128,7 @@ void tst_QQuickGridView::unrequestedVisibility() // move a non-visible item into view model.moveItems(10, 9, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QTRY_VERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 1)); QCOMPARE(delegateVisible(item), false); @@ -6150,7 +6151,7 @@ void tst_QQuickGridView::unrequestedVisibility() // move a visible item out of view model.moveItems(5, 3, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3)); QCOMPARE(delegateVisible(item), false); @@ -6163,7 +6164,7 @@ void tst_QQuickGridView::unrequestedVisibility() // move a non-visible item into view model.moveItems(3, 5, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3)); QCOMPARE(delegateVisible(item), false); @@ -6176,7 +6177,7 @@ void tst_QQuickGridView::unrequestedVisibility() // move a visible item out of view model.moveItems(9, 10, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3)); QCOMPARE(delegateVisible(item), false); @@ -6189,7 +6190,7 @@ void tst_QQuickGridView::unrequestedVisibility() // move a non-visible item into view model.moveItems(10, 9, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QVERIFY(item = findItem<QQuickItem>(leftContent, "wrapper", 3)); QCOMPARE(delegateVisible(item), false); diff --git a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp index 1a289a2087..2f90632841 100644 --- a/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp +++ b/tests/auto/quick/qquickitemlayer/tst_qquickitemlayer.cpp @@ -51,9 +51,8 @@ public: view.setSource(testFileUrl(fileName)); view.showNormal(); - QTest::qWaitForWindowExposed(&view); - - return view.grabWindow(); + return QTest::qWaitForWindowExposed(&view) + ? view.grabWindow() : QImage(); } private slots: @@ -153,6 +152,7 @@ void tst_QQuickItemLayer::layerSmooth() QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); QImage fb = runTest("Smooth.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0, 0xff)); @@ -177,6 +177,7 @@ void tst_QQuickItemLayer::layerEnabled() QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); QImage fb = runTest("Enabled.qml"); + QVERIFY(!fb.size().isEmpty()); // Verify the banding QCOMPARE(fb.pixel(0, 0), fb.pixel(0, 1)); // Verify the gradient @@ -212,6 +213,7 @@ void tst_QQuickItemLayer::layerEffect() QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); QImage fb = runTest("Effect.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0)); } @@ -229,6 +231,7 @@ void tst_QQuickItemLayer::layerSourceRect() QSKIP("Only OpenGL Renderer supports GLSL ShaderEffects"); QImage fb = runTest("SourceRect.qml"); + QVERIFY(!fb.size().isEmpty()); // Check that the edges are converted to blue QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff)); @@ -253,6 +256,7 @@ void tst_QQuickItemLayer::layerIsTextureProvider() QSKIP("Only OpenGL Renderer supports GLSL ShaderEffects"); QImage fb = runTest("TextureProvider.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(fb.width() - 1, 0), qRgb(0, 0xff, 0)); } @@ -448,6 +452,7 @@ void tst_QQuickItemLayer::changeSamplerName() QSKIP("Only OpenGL Renderer supports GLSL ShaderEffects"); QImage fb = runTest("SamplerNameChange.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0, 0, 0xff)); } @@ -459,6 +464,7 @@ void tst_QQuickItemLayer::itemEffect() QSKIP("Only OpenGL Renderer supports GLSL ShaderEffects"); QImage fb = runTest("ItemEffect.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(199, 0), qRgb(0xff, 0, 0)); QCOMPARE(fb.pixel(0, 199), qRgb(0, 0, 0xff)); @@ -472,6 +478,7 @@ void tst_QQuickItemLayer::rectangleEffect() QSKIP("Skipping due to grabWindow not functional on offscreen/minimimal platforms"); QImage fb = runTest("RectangleEffect.qml"); + QVERIFY(!fb.size().isEmpty()); QCOMPARE(fb.pixel(0, 0), qRgb(0, 0xff, 0)); QCOMPARE(fb.pixel(199, 0), qRgb(0, 0xff, 0)); QCOMPARE(fb.pixel(0, 199), qRgb(0, 0xff, 0)); diff --git a/tests/auto/quick/qquicklistview/data/listview-itematindex.qml b/tests/auto/quick/qquicklistview/data/listview-itematindex.qml new file mode 100644 index 0000000000..fba8b11933 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/listview-itematindex.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +ListView { + width: 400 + height: 400 + focus: true + model: 3 + + delegate: Text { + width: parent.width + height: 10 + property int idx: index + text: index + } +} diff --git a/tests/auto/quick/qquicklistview/qquicklistview.pro b/tests/auto/quick/qquicklistview/qquicklistview.pro index a95b6fdf33..fd96c269a2 100644 --- a/tests/auto/quick/qquicklistview/qquicklistview.pro +++ b/tests/auto/quick/qquicklistview/qquicklistview.pro @@ -16,6 +16,7 @@ include (../../shared/util.pri) include (../shared/util.pri) TESTDATA = data/* +DISTFILES += data/* -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmltest diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index fddba77f35..2ea8a477a8 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -31,6 +31,7 @@ #include <QtCore/QSortFilterProxyModel> #include <QtGui/QStandardItemModel> #include <QtQuick/qquickview.h> +#include <QtQuickTest/QtQuickTest> #include <QtQml/qqmlengine.h> #include <QtQml/qqmlcontext.h> #include <QtQml/qqmlexpression.h> @@ -166,6 +167,7 @@ private slots: void QTBUG_16037(); void indexAt_itemAt_data(); void indexAt_itemAt(); + void itemAtIndex(); void incrementalModel(); void onAdd(); void onAdd_data(); @@ -473,8 +475,7 @@ void tst_QQuickListView::items(const QUrl &source) // Force a layout, necessary if ListView is completed before DelegateModel. listview->forceLayout(); - int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); - QTRY_COMPARE(itemCount, 0); + QTRY_VERIFY(findItems<QQuickItem>(contentItem, "wrapper").isEmpty()); QTRY_COMPARE(listview->highlightResizeVelocity(), 1000.0); QTRY_COMPARE(listview->highlightMoveVelocity(), 100000.0); @@ -650,7 +651,7 @@ void tst_QQuickListView::inserted_more(QQuickItemView::VerticalLayoutDirection v if (verticalLayoutDirection == QQuickItemView::BottomToTop) { listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); contentY = -listview->height() - contentY; } listview->setContentY(contentY); @@ -663,7 +664,7 @@ void tst_QQuickListView::inserted_more(QQuickItemView::VerticalLayoutDirection v model.insertItems(insertIndex, newData); //Wait for polish (updates list to the model changes) - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->property("count").toInt(), model.count()); @@ -844,7 +845,7 @@ void tst_QQuickListView::insertBeforeVisible() QTRY_VERIFY(contentItem != nullptr); listview->setCacheBuffer(cacheBuffer); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // trigger a refill (not just setting contentY) so that the visibleItems grid is updated int firstVisibleIndex = 20; // move to an index where the top item is not visible @@ -852,7 +853,7 @@ void tst_QQuickListView::insertBeforeVisible() listview->setCurrentIndex(firstVisibleIndex); qApp->processEvents(); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), firstVisibleIndex); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", firstVisibleIndex); QVERIFY(item); @@ -872,7 +873,7 @@ void tst_QQuickListView::insertBeforeVisible() // now, moving to the top of the view should position the inserted items correctly int itemsOffsetAfterMove = (removeCount - insertCount) * 20; listview->setCurrentIndex(0); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), 0); QTRY_COMPARE(listview->contentY(), 0.0 + itemsOffsetAfterMove); @@ -955,7 +956,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.removeItem(1); QTRY_COMPARE(window->rootObject()->property("count").toInt(), model.count()); @@ -1034,7 +1035,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) listview->setContentY(20); // That's the top now // let transitions settle. - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -1048,7 +1049,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) // remove current item beyond visible items. listview->setCurrentIndex(20); listview->setContentY(40); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.removeItem(20); QTRY_COMPARE(listview->currentIndex(), 20); @@ -1056,7 +1057,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) // remove item before current, but visible listview->setCurrentIndex(8); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); oldCurrent = listview->currentItem(); model.removeItem(6); @@ -1064,7 +1065,7 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */) QTRY_COMPARE(listview->currentItem(), oldCurrent); listview->setContentY(80); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // remove all visible items model.removeItems(1, 18); @@ -1142,14 +1143,14 @@ void tst_QQuickListView::removed_more(const QUrl &source, QQuickItemView::Vertic if (verticalLayoutDirection == QQuickItemView::BottomToTop) { listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); contentY = -listview->height() - contentY; } listview->setContentY(contentY); model.removeItems(removeIndex, removeCount); //Wait for polish (updates list to the model changes) - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->property("count").toInt(), model.count()); @@ -1323,7 +1324,7 @@ void tst_QQuickListView::clear(const QUrl &source, QQuickItemView::VerticalLayou QTRY_VERIFY(contentItem != nullptr); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.clear(); @@ -1381,20 +1382,20 @@ void tst_QQuickListView::moved(const QUrl &source, QQuickItemView::VerticalLayou QTRY_VERIFY(contentItem != nullptr); // always need to wait for view to be painted before the first move() - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); bool waitForPolish = (contentY != 0); if (verticalLayoutDirection == QQuickItemView::BottomToTop) { listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); contentY = -listview->height() - contentY; } listview->setContentY(contentY); if (waitForPolish) - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.moveItems(from, to, count); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper"); int firstVisibleIndex = -1; @@ -1607,7 +1608,7 @@ void tst_QQuickListView::multipleChanges(bool condensed) QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i=0; i<changes.count(); i++) { switch (changes[i].type) { @@ -1635,10 +1636,10 @@ void tst_QQuickListView::multipleChanges(bool condensed) continue; } if (!condensed) { - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); } } - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(listview->count(), newCount); QCOMPARE(listview->count(), model.count()); @@ -1855,7 +1856,7 @@ void tst_QQuickListView::swapWithFirstItem() QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // ensure content position is stable listview->setContentY(0); @@ -1918,7 +1919,7 @@ void tst_QQuickListView::enforceRange() QTRY_COMPARE(listview->preferredHighlightBegin(), 100.0); QTRY_COMPARE(listview->preferredHighlightEnd(), 100.0); QTRY_COMPARE(listview->highlightRangeMode(), QQuickListView::StrictlyEnforceRange); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -1973,7 +1974,7 @@ void tst_QQuickListView::enforceRange_withoutHighlight() QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); qreal expectedPos = -100.0; @@ -2017,7 +2018,7 @@ void tst_QQuickListView::spacing() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -2076,7 +2077,7 @@ void tst_QQuickListView::sections(const QUrl &source) QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -2146,9 +2147,9 @@ void tst_QQuickListView::sections(const QUrl &source) // check that headers change when item changes listview->setContentY(0); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.modifyItem(0, "changed", "2"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); item = findItem<QQuickItem>(contentItem, "wrapper", 1); QTRY_VERIFY(item); @@ -2176,7 +2177,7 @@ void tst_QQuickListView::sectionsDelegate() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -2200,7 +2201,7 @@ void tst_QQuickListView::sectionsDelegate() model.modifyItem(2, "Three", "aaa"); model.modifyItem(3, "Four", "aaa"); model.modifyItem(4, "Five", "aaa"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 0; i < 3; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, @@ -2236,7 +2237,7 @@ void tst_QQuickListView::sectionsDelegate() model.modifyItem(9, "Two", "aaa"); model.modifyItem(10, "Two", "aaa"); model.modifyItem(11, "Two", "aaa"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(findItems<QQuickItem>(contentItem, "sect_aaa").count(), 1); window->rootObject()->setProperty("sectionProperty", "name"); // ensure view has settled. @@ -2286,7 +2287,7 @@ void tst_QQuickListView::sectionsDragOutsideBounds() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // QTBUG-17769 // Drag view up beyond bounds @@ -2332,11 +2333,11 @@ void tst_QQuickListView::sectionsDelegate_headerVisibility() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // ensure section header is maintained in view listview->setCurrentIndex(20); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_VERIFY(qFuzzyCompare(listview->contentY(), 200.0)); QTRY_VERIFY(!listview->isMoving()); listview->setCurrentIndex(0); @@ -2363,7 +2364,7 @@ void tst_QQuickListView::sectionsPositioning() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 0; i < 3; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "sect_" + QString::number(i)); @@ -2381,12 +2382,12 @@ void tst_QQuickListView::sectionsPositioning() // move down a little and check that section header is at top listview->setContentY(10); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(topItem->y(), 0.); // push the top header up listview->setContentY(110); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); topItem = findVisibleChild(contentItem, "sect_0"); // section header QVERIFY(topItem); QCOMPARE(topItem->y(), 100.); @@ -2401,13 +2402,13 @@ void tst_QQuickListView::sectionsPositioning() // Move past section 0 listview->setContentY(120); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); topItem = findVisibleChild(contentItem, "sect_0"); // section header QVERIFY(!topItem); // Push section footer down listview->setContentY(70); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); bottomItem = findVisibleChild(contentItem, "sect_4"); // section footer QVERIFY(bottomItem); QCOMPARE(bottomItem->y(), 380.); @@ -2419,7 +2420,7 @@ void tst_QQuickListView::sectionsPositioning() model.modifyItem(2, "Three", "aAa"); model.modifyItem(3, "Four", "aaA"); model.modifyItem(4, "Five", "Aaa"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentSection(), QString("aaa")); @@ -2435,7 +2436,7 @@ void tst_QQuickListView::sectionsPositioning() // remove section boundary listview->setContentY(120); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.removeItem(5); listview->forceLayout(); QTRY_COMPARE(listview->count(), model.count()); @@ -2452,27 +2453,27 @@ void tst_QQuickListView::sectionsPositioning() // Change the next section listview->setContentY(0); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); bottomItem = findVisibleChild(contentItem, "sect_3"); // section footer QVERIFY(bottomItem); QTRY_COMPARE(bottomItem->y(), 300.); model.modifyItem(14, "New", "new"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_new")); // section footer QTRY_COMPARE(bottomItem->y(), 300.); // delegate size increase should push section footer down listview->setContentY(70); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_VERIFY(bottomItem = findVisibleChild(contentItem, "sect_3")); // section footer QTRY_COMPARE(bottomItem->y(), 370.); QQuickItem *inlineSection = findVisibleChild(contentItem, "sect_new"); item = findItem<QQuickItem>(contentItem, "wrapper", 13); QVERIFY(item); item->setHeight(40.); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(bottomItem->y(), 380.); QCOMPARE(inlineSection->y(), 360.); item->setHeight(20.); @@ -2480,14 +2481,14 @@ void tst_QQuickListView::sectionsPositioning() // Turn sticky footer off listview->setContentY(20); window->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels | QQuickViewSection::CurrentLabelAtStart))); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_new")); // inline label restored QCOMPARE(item->y(), 340.); // Turn sticky header off listview->setContentY(30); window->rootObject()->setProperty("sectionPositioning", QVariant(int(QQuickViewSection::InlineLabels))); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_VERIFY(item = findVisibleChild(contentItem, "sect_aaa")); // inline label restored QCOMPARE(item->y(), 0.); @@ -2523,7 +2524,7 @@ void tst_QQuickListView::sectionPropertyChange() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly for (int i = 0; i < 2; ++i) { @@ -2533,7 +2534,7 @@ void tst_QQuickListView::sectionPropertyChange() } QMetaObject::invokeMethod(window->rootObject(), "switchGroups"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly for (int i = 0; i < 2; ++i) { @@ -2543,7 +2544,7 @@ void tst_QQuickListView::sectionPropertyChange() } QMetaObject::invokeMethod(window->rootObject(), "switchGroups"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly for (int i = 0; i < 2; ++i) { @@ -2553,7 +2554,7 @@ void tst_QQuickListView::sectionPropertyChange() } QMetaObject::invokeMethod(window->rootObject(), "switchGrouped"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly for (int i = 0; i < 2; ++i) { @@ -2563,7 +2564,7 @@ void tst_QQuickListView::sectionPropertyChange() } QMetaObject::invokeMethod(window->rootObject(), "switchGrouped"); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly for (int i = 0; i < 2; ++i) { @@ -2587,7 +2588,7 @@ void tst_QQuickListView::sectionDelegateChange() QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QQUICK_VERIFY_POLISH(listview); + QQuickTest::qWaitForItemPolished(listview); QVERIFY(findItems<QQuickItem>(contentItem, "section1").count() > 0); QCOMPARE(findItems<QQuickItem>(contentItem, "section2").count(), 0); @@ -2599,7 +2600,7 @@ void tst_QQuickListView::sectionDelegateChange() } QMetaObject::invokeMethod(window->rootObject(), "switchDelegates"); - QQUICK_VERIFY_POLISH(listview); + QQuickTest::qWaitForItemPolished(listview); QCOMPARE(findItems<QQuickItem>(contentItem, "section1").count(), 0); QVERIFY(findItems<QQuickItem>(contentItem, "section2").count() > 0); @@ -2631,7 +2632,7 @@ void tst_QQuickListView::sectionsItemInsertion() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 0; i < 3; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "sect_" + QString::number(i)); @@ -2647,7 +2648,7 @@ void tst_QQuickListView::sectionsItemInsertion() for (int i = 0; i < 10; i++) model.insertItem(i, "Item" + QString::number(i), QLatin1String("A")); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); QVERIFY(itemCount > 10); @@ -2785,7 +2786,7 @@ void tst_QQuickListView::currentIndex() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // currentIndex is initialized to 20 // currentItem should be in view @@ -2888,7 +2889,7 @@ void tst_QQuickListView::noCurrentIndex() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // current index should be -1 at startup // and we should not have a currentItem or highlightItem @@ -2933,7 +2934,7 @@ void tst_QQuickListView::keyNavigation() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); @@ -3248,7 +3249,7 @@ void tst_QQuickListView::positionViewAtBeginningEnd() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); listview->setContentY(100); @@ -3308,10 +3309,10 @@ void tst_QQuickListView::positionViewAtIndex() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); window->rootObject()->setProperty("enforceRange", enforceRange); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); listview->setContentY(initContentY); @@ -3388,7 +3389,7 @@ void tst_QQuickListView::resetModel() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->count(), model.rowCount()); @@ -3659,7 +3660,7 @@ void tst_QQuickListView::QTBUG_11105() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -3751,7 +3752,7 @@ void tst_QQuickListView::header() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3830,7 +3831,7 @@ void tst_QQuickListView::header() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); listview->setWidth(240); listview->setHeight(320); @@ -3937,7 +3938,7 @@ void tst_QQuickListView::headerChangesViewport() QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -3987,7 +3988,7 @@ void tst_QQuickListView::footer() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -4176,7 +4177,7 @@ void tst_QQuickListView::extents() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -4316,7 +4317,7 @@ void tst_QQuickListView::resizeView() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -4332,7 +4333,7 @@ void tst_QQuickListView::resizeView() QCOMPARE(heightRatio.toReal(), 0.4); listview->setHeight(200); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QMetaObject::invokeMethod(window->rootObject(), "heightRatio", Q_RETURN_ARG(QVariant, heightRatio)); QCOMPARE(heightRatio.toReal(), 0.25); @@ -4393,7 +4394,7 @@ void tst_QQuickListView::resizeViewAndRepaint() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // item at index 10 should not be currently visible QVERIFY(!findItem<QQuickItem>(contentItem, "wrapper", 10)); @@ -4428,7 +4429,7 @@ void tst_QQuickListView::sizeLessThan1() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Confirm items positioned correctly int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count(); @@ -4480,13 +4481,13 @@ void tst_QQuickListView::resizeDelegate() QVERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(listview->count(), model.rowCount()); listview->setCurrentIndex(25); listview->setContentY(0); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 0; i < 16; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -4498,7 +4499,7 @@ void tst_QQuickListView::resizeDelegate() QTRY_COMPARE(listview->highlightItem()->y(), 500.0); window->rootObject()->setProperty("delegateHeight", 30); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 0; i < 11; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -4512,7 +4513,7 @@ void tst_QQuickListView::resizeDelegate() listview->setCurrentIndex(1); listview->positionViewAtIndex(25, QQuickListView::Beginning); listview->positionViewAtIndex(5, QQuickListView::Beginning); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 5; i < 16; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -4524,7 +4525,7 @@ void tst_QQuickListView::resizeDelegate() QTRY_COMPARE(listview->highlightItem()->y(), 30.0); window->rootObject()->setProperty("delegateHeight", 20); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); for (int i = 5; i < 11; ++i) { QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i); @@ -4561,7 +4562,7 @@ void tst_QQuickListView::resizeFirstDelegate() QVERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *item = nullptr; for (int i = 0; i < model.count(); ++i) { @@ -4600,7 +4601,7 @@ void tst_QQuickListView::resizeFirstDelegate() listview->setCurrentIndex(19); qApp->processEvents(); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // items 0-2 should have been deleted for (int i=0; i<3; i++) { @@ -4631,7 +4632,7 @@ void tst_QQuickListView::repositionResizedDelegate() QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *positioner = findItem<QQuickItem>(window->rootObject(), "positioner"); QVERIFY(positioner); @@ -4646,7 +4647,7 @@ void tst_QQuickListView::repositionResizedDelegate() listview->setContentX(contentPos_itemFirstHalfVisible.x()); listview->setContentY(contentPos_itemFirstHalfVisible.y()); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); prevSpyCount = spy.count(); QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "incrementRepeater")); QTRY_COMPARE(positioner->boundingRect().size(), resizedPositionerRect.size()); @@ -4663,7 +4664,7 @@ void tst_QQuickListView::repositionResizedDelegate() listview->setContentX(contentPos_itemSecondHalfVisible.x()); listview->setContentY(contentPos_itemSecondHalfVisible.y()); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); prevSpyCount = spy.count(); QVERIFY(QMetaObject::invokeMethod(window->rootObject(), "incrementRepeater")); @@ -4771,7 +4772,7 @@ void tst_QQuickListView::indexAt_itemAt() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *item = nullptr; if (index >= 0) { @@ -4785,6 +4786,29 @@ void tst_QQuickListView::indexAt_itemAt() delete testObject; } +void tst_QQuickListView::itemAtIndex() +{ + QScopedPointer<QQuickView> window(createView()); + window->setSource(testFileUrl("listview-itematindex.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); + QVERIFY(listview != nullptr); + + QCOMPARE(listview->itemAtIndex(-1), nullptr); + QCOMPARE(listview->itemAtIndex(3), nullptr); + QQuickItem *item = listview->itemAtIndex(0); + QVERIFY(item); + QCOMPARE(item->property("idx"), 0); + item = listview->itemAtIndex(1); + QVERIFY(item); + QCOMPARE(item->property("idx"), 1); + item = listview->itemAtIndex(2); + QVERIFY(item); + QCOMPARE(item->property("idx"), 2); +} + void tst_QQuickListView::incrementalModel() { QScopedPointer<QQuickView> window(createView()); @@ -4929,7 +4953,7 @@ void tst_QQuickListView::rightToLeft() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQmlObjectModel *model = window->rootObject()->findChild<QQmlObjectModel*>("itemModel"); QTRY_VERIFY(model != nullptr); @@ -5042,7 +5066,7 @@ void tst_QQuickListView::margins() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(listview->contentY(), -30.); QCOMPARE(listview->originY(), 0.); @@ -5051,7 +5075,7 @@ void tst_QQuickListView::margins() listview->positionViewAtEnd(); qreal pos = listview->contentY(); listview->setContentY(pos + 80); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); listview->returnToBounds(); QTRY_COMPARE(listview->contentY(), pos + 50); @@ -5062,7 +5086,7 @@ void tst_QQuickListView::margins() listview->forceLayout(); QTRY_COMPARE(listview->count(), model.count()); listview->setContentY(-50); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); listview->returnToBounds(); QCOMPARE(listview->originY(), 20.); QTRY_COMPARE(listview->contentY(), -10.); @@ -5115,7 +5139,7 @@ void tst_QQuickListView::marginsResize() listview->setOrientation(orientation); listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // view is resized after componentCompleted - top margin should still be visible if (orientation == QQuickListView::Vertical) @@ -5255,7 +5279,7 @@ void tst_QQuickListView::snapToItem() listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); listview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode)); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -5307,7 +5331,7 @@ void tst_QQuickListView::snapToItemWithSpacing_QTBUG_59852() auto *listView = qobject_cast<QQuickListView*>(window->rootObject()); QVERIFY(listView); - QTRY_COMPARE(QQuickItemPrivate::get(listView)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listView)); // each item in the list is 100 pixels tall, and the spacing is 100 @@ -5338,14 +5362,14 @@ void tst_QQuickListView::snapOneItemResize_QTBUG_43555() QSignalSpy currentIndexSpy(listview, SIGNAL(currentIndexChanged())); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), 5); currentIndexSpy.clear(); window->resize(QSize(400, 320)); QTRY_COMPARE(int(listview->width()), 400); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), 5); QCOMPARE(currentIndexSpy.count(), 0); @@ -5655,7 +5679,7 @@ void tst_QQuickListView::snapOneItem() listview->setLayoutDirection(layoutDirection); listview->setVerticalLayoutDirection(verticalLayoutDirection); listview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode)); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); @@ -5724,14 +5748,14 @@ void tst_QQuickListView::snapOneItemCurrentIndexRemoveAnimation() QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), 0); QSignalSpy currentIndexSpy(listview, SIGNAL(currentIndexChanged())); QMetaObject::invokeMethod(window->rootObject(), "removeItemZero"); QTRY_COMPARE(listview->property("transitionsRun").toInt(), 1); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(listview->currentIndex(), 0); QCOMPARE(currentIndexSpy.count(), 0); @@ -5747,7 +5771,7 @@ void tst_QQuickListView::snapOneItemWrongDirection() QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject()); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QTRY_COMPARE(listview->currentIndex(), 0); listview->flick(0,500); @@ -5897,7 +5921,7 @@ void tst_QQuickListView::unrequestedVisibility() QCOMPARE(delegateVisible(item), false); model.moveItems(19, 1, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); QTRY_VERIFY((item = findItem<QQuickItem>(leftContent, wrapperObjectName, 1))); QCOMPARE(delegateVisible(item), false); @@ -5926,7 +5950,7 @@ void tst_QQuickListView::unrequestedVisibility() QCOMPARE(delegateVisible(item), false); model.moveItems(3, 4, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); item = findItem<QQuickItem>(leftContent, wrapperObjectName, 4); QVERIFY(item); @@ -5942,7 +5966,7 @@ void tst_QQuickListView::unrequestedVisibility() QCOMPARE(delegateVisible(item), false); model.moveItems(4, 3, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); item = findItem<QQuickItem>(leftContent, wrapperObjectName, 4); QVERIFY(item); @@ -5958,7 +5982,7 @@ void tst_QQuickListView::unrequestedVisibility() QCOMPARE(delegateVisible(item), false); model.moveItems(16, 17, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); item = findItem<QQuickItem>(leftContent, wrapperObjectName, 4); QVERIFY(item); @@ -5974,7 +5998,7 @@ void tst_QQuickListView::unrequestedVisibility() QCOMPARE(delegateVisible(item), false); model.moveItems(17, 16, 1); - QTRY_COMPARE(QQuickItemPrivate::get(leftview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(leftview)); item = findItem<QQuickItem>(leftContent, wrapperObjectName, 4); QVERIFY(item); @@ -6034,7 +6058,7 @@ void tst_QQuickListView::populateTransitions() QTRY_COMPARE(listview->property("countPopulateTransitions").toInt(), 0); QTRY_COMPARE(listview->property("countAddTransitions").toInt(), 16); } else { - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(listview->property("countPopulateTransitions").toInt(), 0); QCOMPARE(listview->property("countAddTransitions").toInt(), 0); } @@ -6145,7 +6169,7 @@ void tst_QQuickListView::sizeTransitions() QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list"); QTRY_VERIFY(listview != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // the following will start the transition model.addItem(QLatin1String("Test"), ""); @@ -6210,11 +6234,11 @@ void tst_QQuickListView::addTransitions() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); if (contentY != 0) { listview->setContentY(contentY); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -6410,7 +6434,7 @@ void tst_QQuickListView::moveTransitions() if (contentY != 0) { listview->setContentY(contentY); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -6609,11 +6633,11 @@ void tst_QQuickListView::removeTransitions() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); if (contentY != 0) { listview->setContentY(contentY); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); } QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); @@ -6821,7 +6845,7 @@ void tst_QQuickListView::displacedTransitions() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QList<QPair<QString,QString> > expectedDisplacedValues = expectedDisplacedIndexes.getModelDataValues(model); listview->setProperty("displaceTransitionsDone", false); @@ -6842,7 +6866,7 @@ void tst_QQuickListView::displacedTransitions() break; case ListChange::Moved: model.moveItems(change.index, change.to, change.count); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); break; case ListChange::SetCurrent: case ListChange::SetContentY: @@ -7041,11 +7065,11 @@ void tst_QQuickListView::multipleTransitions() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); if (contentY != 0) { listview->setContentY(contentY); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); } int timeBetweenActions = window->rootObject()->property("timeBetweenActions").toInt(); @@ -7079,7 +7103,7 @@ void tst_QQuickListView::multipleTransitions() break; case ListChange::Moved: model.moveItems(changes[i].index, changes[i].to, changes[i].count); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); if (i == changes.count() - 1) { QTRY_VERIFY(!listview->property("runningMoveTargets").toBool()); QTRY_VERIFY(!listview->property("runningMoveDisplaced").toBool()); @@ -7092,7 +7116,7 @@ void tst_QQuickListView::multipleTransitions() break; case ListChange::SetContentY: listview->setContentY(changes[i].pos); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); break; case ListChange::Polish: break; @@ -7198,7 +7222,7 @@ void tst_QQuickListView::multipleDisplaced() QTRY_VERIFY(listview != nullptr); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); model.moveItems(12, 8, 1); QTest::qWait(window->rootObject()->property("duration").toInt() / 2); @@ -7292,7 +7316,7 @@ void tst_QQuickListView::flickBeyondBounds() QQuickItem *contentItem = listview->contentItem(); QTRY_VERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); // Flick view up beyond bounds flick(window.data(), QPoint(10, 10), QPoint(10, -2000), 180); @@ -7404,7 +7428,7 @@ void tst_QQuickListView::destroyItemOnCreation() QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QCOMPARE(window->rootObject()->property("createdIndex").toInt(), -1); model.addItem("new item", ""); @@ -7428,7 +7452,7 @@ void tst_QQuickListView::parentBinding() QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem != nullptr); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", 0); QVERIFY(item); @@ -8832,7 +8856,7 @@ void tst_QQuickListView::QTBUG_34576_velocityZero() QVERIFY(listview); QQuickItem *contentItem = listview->contentItem(); QVERIFY(contentItem); - QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(listview)); QSignalSpy horizontalVelocitySpy(listview, SIGNAL(horizontalVelocityChanged())); diff --git a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp index d4ad282701..cd66fc4ede 100644 --- a/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp +++ b/tests/auto/quick/qquickmultipointtoucharea/tst_qquickmultipointtoucharea.cpp @@ -1145,16 +1145,18 @@ void tst_QQuickMultiPointTouchArea::transformedTouchArea() QQuickView *tst_QQuickMultiPointTouchArea::createAndShowView(const QString &file) { - QQuickView *window = new QQuickView(nullptr); + QScopedPointer<QQuickView> window(new QQuickView(nullptr)); window->setSource(testFileUrl(file)); + if (window->status() != QQuickView::Ready) + return nullptr; const QRect screenGeometry = window->screen()->availableGeometry(); const QSize size = window->size(); const QPoint offset = QPoint(size.width() / 2, size.height() / 2); window->setFramePosition(screenGeometry.center() - offset); window->show(); - QTest::qWaitForWindowExposed(window); - - return window; + if (!QTest::qWaitForWindowExposed(window.data())) + return nullptr; + return window.take(); } void tst_QQuickMultiPointTouchArea::mouseInteraction_data() diff --git a/tests/auto/quick/qquickpathview/qquickpathview.pro b/tests/auto/quick/qquickpathview/qquickpathview.pro index 90c1eb0c67..f21fb64fa4 100644 --- a/tests/auto/quick/qquickpathview/qquickpathview.pro +++ b/tests/auto/quick/qquickpathview/qquickpathview.pro @@ -9,5 +9,5 @@ include (../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private quick-private testlib +QT += core-private gui-private qml-private quick-private testlib qmltest qtHaveModule(widgets): QT += widgets diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp index 7491df5087..1a5ce39318 100644 --- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp +++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp @@ -38,6 +38,7 @@ #include <QtQuick/private/qquickpath_p.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQuick/private/qquickrectangle_p.h> +#include <QtQuickTest/QtQuickTest> #include <QtQml/private/qqmllistmodel_p.h> #include <QtQml/private/qqmlvaluetype_p.h> #include <QtGui/qstandarditemmodel.h> @@ -715,13 +716,13 @@ void tst_QQuickPathView::consecutiveModelChanges() pathview->setCurrentIndex(changes[i].index); break; case ListChange::Polish: - QQUICK_VERIFY_POLISH(pathview); + QQuickTest::qWaitForItemPolished(pathview); break; default: continue; } } - QQUICK_VERIFY_POLISH(pathview); + QQuickTest::qWaitForItemPolished(pathview); QCOMPARE(findItems<QQuickItem>(pathview, "wrapper").count(), count); QCOMPARE(pathview->count(), count); @@ -1394,7 +1395,7 @@ void tst_QQuickPathView::package() QSKIP("QTBUG-27170 view does not reliably receive polish without a running animation"); #endif - QQUICK_VERIFY_POLISH(pathView); + QQuickTest::qWaitForItemPolished(pathView); QQuickItem *item = findItem<QQuickItem>(pathView, "pathItem"); QVERIFY(item); QVERIFY(item->scale() != 1.0); diff --git a/tests/auto/quick/qquickpositioners/qquickpositioners.pro b/tests/auto/quick/qquickpositioners/qquickpositioners.pro index 6e85ba9db8..d1547df189 100644 --- a/tests/auto/quick/qquickpositioners/qquickpositioners.pro +++ b/tests/auto/quick/qquickpositioners/qquickpositioners.pro @@ -9,4 +9,4 @@ macx:CONFIG -= app_bundle TESTDATA = data/* -QT += testlib +QT += testlib qmltest diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp index 9881af690c..80be25d1b0 100644 --- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp +++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp @@ -31,6 +31,7 @@ #include <QtQuick/private/qquickrectangle_p.h> #include <QtQuick/private/qquickpositioners_p.h> #include <QtQuick/private/qquicktransition_p.h> +#include <QtQuickTest/QtQuickTest> #include <private/qquickitem_p.h> #include <qqmlexpression.h> #include "../shared/viewtestutil.h" @@ -1062,7 +1063,7 @@ void tst_qquickpositioners::populateTransitions(const QString &positionerObjectN QTRY_COMPARE(window->rootObject()->property("populateTransitionsDone").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("addTransitionsDone").toInt(), model.count()); } else { - QTRY_COMPARE(QQuickItemPrivate::get(positioner)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(positioner)); QTRY_COMPARE(window->rootObject()->property("populateTransitionsDone").toInt(), 0); QTRY_COMPARE(window->rootObject()->property("addTransitionsDone").toInt(), 0); } @@ -1128,7 +1129,7 @@ void tst_qquickpositioners::addTransitions(const QString &positionerObjectName) QQuickItem *positioner = window->rootObject()->findChild<QQuickItem*>(positionerObjectName); QVERIFY(positioner); positioner->findChild<QQuickItem*>("repeater")->setProperty("model", QVariant::fromValue(&model)); - QTRY_COMPARE(QQuickItemPrivate::get(positioner)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(positioner)); for (int i = 0; i < initialItemCount; i++) model.addItem("Original item" + QString::number(i), ""); @@ -1253,7 +1254,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) QQuickItem *positioner = window->rootObject()->findChild<QQuickItem*>(positionerObjectName); QVERIFY(positioner); positioner->findChild<QQuickItem*>("repeater")->setProperty("model", QVariant::fromValue(&model)); - QTRY_COMPARE(QQuickItemPrivate::get(positioner)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(positioner)); switch (change.type) { case ListChange::Removed: @@ -1262,7 +1263,7 @@ void tst_qquickpositioners::moveTransitions(const QString &positionerObjectName) break; case ListChange::Moved: model.moveItems(change.index, change.to, change.count); - QTRY_COMPARE(QQuickItemPrivate::get(positioner)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(positioner)); break; case ListChange::Inserted: case ListChange::SetCurrent: @@ -3815,7 +3816,7 @@ void tst_qquickpositioners::test_mirroring() QQuickItem *positionerB = itemB->parentItem(); positionerA->setWidth(positionerA->width() * 2); positionerB->setWidth(positionerB->width() * 2); - QTRY_VERIFY(!QQuickItemPrivate::get(positionerA)->polishScheduled && !QQuickItemPrivate::get(positionerB)->polishScheduled); + QVERIFY(QQuickTest::qWaitForItemPolished(positionerA) && QQuickTest::qWaitForItemPolished(positionerB)); QTRY_COMPARE(itemA->x(), itemB->x()); } diff --git a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp index 832b973d96..710caaa734 100644 --- a/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp +++ b/tests/auto/quick/qquickrectangle/tst_qquickrectangle.cpp @@ -134,7 +134,7 @@ void tst_qquickrectangle::gradient_separate() // Start off clean QQuickItemPrivate *rectPriv = QQuickItemPrivate::get(rect); - QTRY_COMPARE(rectPriv->dirtyAttributes & QQuickItemPrivate::Content, 0); + QTRY_COMPARE(rectPriv->dirtyAttributes & QQuickItemPrivate::Content, 0u); QMetaObject::invokeMethod(rect, "changeGradient"); diff --git a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp index f601f520bb..a57b7d4c1f 100644 --- a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp +++ b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp @@ -46,6 +46,10 @@ class TestShaderEffect : public QQuickShaderEffect Q_PROPERTY(QMatrix4x4 mat4x4 READ mat4x4Read NOTIFY dummyChanged) public: + TestShaderEffect(QQuickItem* parent = nullptr) : QQuickShaderEffect(parent) + { + } + QMatrix4x4 mat4x4Read() const { return QMatrix4x4(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1); } QVariant dummyRead() const { return QVariant(); } @@ -79,6 +83,8 @@ private slots: void deleteShaderEffectSource(); void twoImagesOneShaderEffect(); + void withoutQmlEngine(); + private: enum PresenceFlags { VertexPresent = 0x01, @@ -320,6 +326,16 @@ void tst_qquickshadereffect::twoImagesOneShaderEffect() delete view; } +void tst_qquickshadereffect::withoutQmlEngine() +{ + // using a shader without QML engine used to crash + auto window = new QQuickWindow; + auto shaderEffect = new TestShaderEffect(window->contentItem()); + shaderEffect->setVertexShader(""); + QVERIFY(shaderEffect->isComponentComplete()); + delete window; +} + QTEST_MAIN(tst_qquickshadereffect) #include "tst_qquickshadereffect.moc" diff --git a/tests/auto/quick/qquicktableview/data/hiderowsandcolumns.qml b/tests/auto/quick/qquicktableview/data/hiderowsandcolumns.qml new file mode 100644 index 0000000000..b11cb1476c --- /dev/null +++ b/tests/auto/quick/qquicktableview/data/hiderowsandcolumns.qml @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.12 +import QtQuick.Window 2.3 + +Item { + width: 640 + height: 450 + + property alias tableView: tableView + property var rowsToHide + property var columnsToHide + + TableView { + id: tableView + width: 600 + height: 400 + anchors.margins: 1 + clip: true + delegate: tableViewDelegate + columnSpacing: 1 + rowSpacing: 1 + columnWidthProvider: function(column) { + if (columnsToHide.includes(column)) + return 0; + } + rowHeightProvider: function(row) { + if (rowsToHide.includes(row)) + return 0; + } + } + + Component { + id: tableViewDelegate + Rectangle { + objectName: "tableViewDelegate" + color: "lightgray" + border.width: 1 + implicitWidth: 50 + implicitHeight: 50 + Text { + anchors.centerIn: parent + text: column + "," + row + } + } + } + +} diff --git a/tests/auto/quick/qquicktableview/data/usefaultyrowcolumnprovider.qml b/tests/auto/quick/qquicktableview/data/usefaultyrowcolumnprovider.qml index 32d1fc9d0d..1e35d65bcd 100644 --- a/tests/auto/quick/qquicktableview/data/usefaultyrowcolumnprovider.qml +++ b/tests/auto/quick/qquicktableview/data/usefaultyrowcolumnprovider.qml @@ -56,16 +56,14 @@ Item { delegate: tableViewDelegate columnSpacing: 1 rowSpacing: 1 - columnWidthProvider: function(column) { } - rowHeightProvider: function(row) { return 0 } + columnWidthProvider: function(column) { return "notAValidValue" } + rowHeightProvider: function(row) { return "notAValidValue" } } Component { id: tableViewDelegate Rectangle { objectName: "tableViewDelegate" - implicitWidth: 20 - implicitHeight: 20 color: "lightgray" border.width: 1 Text { diff --git a/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml b/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml index 04d12f8d20..e9f01b6abf 100644 --- a/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml +++ b/tests/auto/quick/qquicktableview/data/userowcolumnprovider.qml @@ -46,6 +46,8 @@ Item { property alias tableView: tableView property Component delegate: tableViewDelegate + property bool returnNegativeColumnWidth: false + property bool returnNegativeRowHeight: false TableView { id: tableView @@ -56,8 +58,16 @@ Item { delegate: tableViewDelegate columnSpacing: 1 rowSpacing: 1 - columnWidthProvider: function(column) { return column + 10 } - rowHeightProvider: function(row) { return row + 10 } + columnWidthProvider: function(column) { + if (returnNegativeColumnWidth) + return -1 + return column + 10 + } + rowHeightProvider: function(row) { + if (returnNegativeRowHeight) + return -1 + return row + 10 + } } Component { diff --git a/tests/auto/quick/qquicktableview/qquicktableview.pro b/tests/auto/quick/qquicktableview/qquicktableview.pro index f4d0265dd3..cf831ed5b5 100644 --- a/tests/auto/quick/qquicktableview/qquicktableview.pro +++ b/tests/auto/quick/qquicktableview/qquicktableview.pro @@ -1,4 +1,5 @@ CONFIG += testcase +QT += qmltest TARGET = tst_qquicktableview macos:CONFIG -= app_bundle diff --git a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp index 22f6e5d654..60d48bb59f 100644 --- a/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp +++ b/tests/auto/quick/qquicktableview/tst_qquicktableview.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include <QtTest/QtTest> +#include <QtQuickTest/quicktest.h> #include <QtQuick/qquickview.h> #include <QtQuick/private/qquicktableview_p.h> @@ -79,8 +80,8 @@ Q_DECLARE_METATYPE(QMarginsF); DECLARE_TABLEVIEW_VARIABLES #define WAIT_UNTIL_POLISHED \ - QVERIFY(tableViewPrivate->polishScheduled); \ - QTRY_VERIFY(!tableViewPrivate->polishScheduled) + QVERIFY(QQuickTest::qIsPolishScheduled(tableView)); \ + QVERIFY(QQuickTest::qWaitForItemPolished(tableView)) class tst_QQuickTableView : public QQmlDataTest { @@ -110,10 +111,12 @@ private slots: void checkDelegateWithAnchors(); void checkColumnWidthProvider(); void checkColumnWidthProviderInvalidReturnValues(); + void checkColumnWidthProviderNegativeReturnValue(); void checkColumnWidthProviderNotCallable(); void checkRowHeightWithoutProvider(); void checkRowHeightProvider(); void checkRowHeightProviderInvalidReturnValues(); + void checkRowHeightProviderNegativeReturnValue(); void checkRowHeightProviderNotCallable(); void checkForceLayoutFunction(); void checkContentWidthAndHeight(); @@ -156,6 +159,8 @@ private slots: void checkRebuildViewportOnly(); void useDelegateChooserWithoutDefault(); void checkTableviewInsideAsyncLoader(); + void hideRowsAndColumns_data(); + void hideRowsAndColumns(); void checkThatRevisionedPropertiesCannotBeUsedInOldImports(); }; @@ -251,8 +256,9 @@ void tst_QQuickTableView::checkPreload() WAIT_UNTIL_POLISHED; if (reuseItems) { - QSize visibleTableSize = tableViewPrivate->loadedTable.size(); - int expectedPoolSize = visibleTableSize.height() + visibleTableSize.width() + 1; + const int rowCount = tableViewPrivate->loadedRows.count(); + const int columnCount = tableViewPrivate->loadedColumns.count(); + const int expectedPoolSize = rowCount + columnCount + 1; QCOMPARE(tableViewPrivate->tableModel->poolSize(), expectedPoolSize); } else { QCOMPARE(tableViewPrivate->tableModel->poolSize(), 0); @@ -321,10 +327,9 @@ void tst_QQuickTableView::checkColumnWidthWithoutProvider() WAIT_UNTIL_POLISHED; - QRect table = tableViewPrivate->loadedTable; - for (int column = table.left(); column <= table.right(); ++column) { + for (const int column : tableViewPrivate->loadedColumns.keys()) { const qreal expectedColumnWidth = tableViewPrivate->sizeHintForColumn(column); - for (int row = table.top(); row <= table.bottom(); ++row) { + for (const int row : tableViewPrivate->loadedRows.keys()) { const auto item = tableViewPrivate->loadedTableItem(QPoint(column, row))->item; QCOMPARE(item->width(), expectedColumnWidth); } @@ -373,7 +378,7 @@ void tst_QQuickTableView::checkColumnWidthProviderInvalidReturnValues() tableView->setModel(model); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Provider.*valid")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*implicitHeight.*zero")); WAIT_UNTIL_POLISHED; @@ -381,6 +386,23 @@ void tst_QQuickTableView::checkColumnWidthProviderInvalidReturnValues() QCOMPARE(fxItem->item->width(), kDefaultColumnWidth); } +void tst_QQuickTableView::checkColumnWidthProviderNegativeReturnValue() +{ + // Check that we fall back to use the implicit width of the delegate + // items if the columnWidthProvider return a negative number. + LOAD_TABLEVIEW("userowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + view->rootObject()->setProperty("returnNegativeColumnWidth", true); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->width(), 20); +} + void tst_QQuickTableView::checkColumnWidthProviderNotCallable() { // Check that we fall back to use default columns widths, if you @@ -414,10 +436,9 @@ void tst_QQuickTableView::checkRowHeightWithoutProvider() WAIT_UNTIL_POLISHED; - QRect table = tableViewPrivate->loadedTable; - for (int row = table.top(); row <= table.bottom(); ++row) { + for (const int row : tableViewPrivate->loadedRows.keys()) { const qreal expectedRowHeight = tableViewPrivate->sizeHintForRow(row); - for (int column = table.left(); column <= table.right(); ++column) { + for (const int column : tableViewPrivate->loadedColumns.keys()) { const auto item = tableViewPrivate->loadedTableItem(QPoint(column, row))->item; QCOMPARE(item->height(), expectedRowHeight); } @@ -454,7 +475,7 @@ void tst_QQuickTableView::checkRowHeightProviderInvalidReturnValues() tableView->setModel(model); - QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*Provider.*valid")); + QTest::ignoreMessage(QtWarningMsg, QRegularExpression(".*implicitHeight.*zero")); WAIT_UNTIL_POLISHED; @@ -462,6 +483,23 @@ void tst_QQuickTableView::checkRowHeightProviderInvalidReturnValues() QCOMPARE(fxItem->item->height(), kDefaultRowHeight); } +void tst_QQuickTableView::checkRowHeightProviderNegativeReturnValue() +{ + // Check that we fall back to use the implicit height of the delegate + // items if the rowHeightProvider return a negative number. + LOAD_TABLEVIEW("userowcolumnprovider.qml"); + + auto model = TestModelAsVariant(10, 10); + view->rootObject()->setProperty("returnNegativeRowHeight", true); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + for (auto fxItem : tableViewPrivate->loadedItems) + QCOMPARE(fxItem->item->height(), 20); +} + void tst_QQuickTableView::checkRowHeightProviderNotCallable() { // Check that we fall back to use default row heights, if you @@ -539,6 +577,8 @@ void tst_QQuickTableView::checkContentWidthAndHeight() const qreal expectedSizeInit = (tableSize * cellSizeSmall) + ((tableSize - 1) * spacing); QCOMPARE(tableView->contentWidth(), expectedSizeInit); QCOMPARE(tableView->contentHeight(), expectedSizeInit); + QCOMPARE(tableViewPrivate->averageEdgeSize.width(), cellSizeSmall); + QCOMPARE(tableViewPrivate->averageEdgeSize.height(), cellSizeSmall); // Flick in 5 more rows and columns, but not so far that we start loading in // the ones that are bigger. Loading in more rows and columns of the same @@ -549,6 +589,8 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QCOMPARE(tableView->contentWidth(), expectedSizeInit); QCOMPARE(tableView->contentHeight(), expectedSizeInit); + QCOMPARE(tableViewPrivate->averageEdgeSize.width(), cellSizeSmall); + QCOMPARE(tableViewPrivate->averageEdgeSize.height(), cellSizeSmall); // Flick to row and column 20 (smallCellCount), since there the row and // column sizes increases with 100. Check that TableView then adjusts @@ -563,50 +605,61 @@ void tst_QQuickTableView::checkContentWidthAndHeight() QVERIFY(tableViewPrivate->rebuildScheduled); WAIT_UNTIL_POLISHED; + // Check that the average cell size is now matching the + // large cells since they fill up the whole view. + QCOMPARE(tableViewPrivate->averageEdgeSize.width(), cellSizeLarge); + QCOMPARE(tableViewPrivate->averageEdgeSize.height(), cellSizeLarge); + const int largeSizeCellCountInView = qCeil(tableView->width() / cellSizeLarge); const int columnCount = smallCellCount + largeSizeCellCountInView; - QCOMPARE(tableViewPrivate->loadedTable.left(), smallCellCount); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), smallCellCount); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); const qreal firstHalfLength = smallCellCount * cellSizeSmall; const qreal secondHalfOneScreenLength = largeSizeCellCountInView * cellSizeLarge; const qreal lengthAfterFlick = firstHalfLength + secondHalfOneScreenLength; - const qreal averageCellSize = lengthAfterFlick / columnCount; - const qreal expectedSizeHalf = (tableSize * averageCellSize) + accumulatedSpacing; - - QCOMPARE(tableView->contentWidth(), expectedSizeHalf); - QCOMPARE(tableView->contentHeight(), expectedSizeHalf); + // Check that loadedTableOuterRect has been calculated correct thus far + const qreal spacingAfterFlick = (smallCellCount + largeSizeCellCountInView - 1) * spacing; + QCOMPARE(tableViewPrivate->loadedTableOuterRect.left(), flickTo + spacing); + QCOMPARE(tableViewPrivate->loadedTableOuterRect.right(), lengthAfterFlick + spacingAfterFlick); + QCOMPARE(tableViewPrivate->loadedTableOuterRect.top(), flickTo + spacing); + QCOMPARE(tableViewPrivate->loadedTableOuterRect.bottom(), lengthAfterFlick + spacingAfterFlick); + + // At this point, we should have the exact content width/height set, because + // TableView knows where the large cells start in the viewport, and how many + // columns that remain in the model. It will assume that the rest of the the + // columns have the same average size as the ones currently inside the viewport. + const qreal expectedContentSize = (smallCellCount * cellSizeSmall) + (largeCellCount * cellSizeLarge) + accumulatedSpacing; + QCOMPARE(tableView->contentWidth(), expectedContentSize); + QCOMPARE(tableView->contentHeight(), expectedContentSize); // Flick to the end (row/column 100, and overshoot a bit), and // check that we then end up with the exact content width/height. const qreal secondHalfLength = largeCellCount * cellSizeLarge; const qreal expectedFullSize = (firstHalfLength + secondHalfLength) + accumulatedSpacing; - - // If we flick more than one page at a time, tableview will jump to the new - // position and rebuild the table without loading the edges in-between. Which - // row and column that ends up as new top-left is then based on a prediction, and - // therefore unreliable. To avoid this to happen (which will also affect the - // reported size of the table), we flick to the end position in smaller chuncks. - QVERIFY(!tableViewPrivate->polishScheduled); - QVERIFY(!tableViewPrivate->rebuildScheduled); - int pages = qCeil((expectedFullSize - tableView->contentX()) / tableView->width()); - for (int i = 0; i < pages; i++) { - tableView->setContentX(tableView->contentX() + tableView->width() - 1); - tableView->setContentY(tableView->contentY() + tableView->height() - 1); - QVERIFY(!tableViewPrivate->rebuildScheduled); - } + const qreal overshoot = 100; + const qreal endPosX = expectedFullSize - tableView->width() + overshoot; + const qreal endPosY = expectedFullSize - tableView->height() + overshoot; + tableView->setContentX(endPosX); + tableView->setContentY(endPosY); QCOMPARE(tableView->contentWidth(), expectedFullSize); QCOMPARE(tableView->contentHeight(), expectedFullSize); - // Flick back to start. Since we know the actual table - // size, contentWidth/Height shouldn't change. + // Flick back to start tableView->setContentX(0); tableView->setContentY(0); - QCOMPARE(tableView->contentWidth(), expectedFullSize); - QCOMPARE(tableView->contentHeight(), expectedFullSize); + // Since we move the viewport more than a page, tableview + // will jump to the new position and do a rebuild. + QVERIFY(tableViewPrivate->polishScheduled); + QVERIFY(tableViewPrivate->rebuildScheduled); + WAIT_UNTIL_POLISHED; + + // We should now have the same content width/height as when we started + QCOMPARE(tableView->contentWidth(), expectedSizeInit); + QCOMPARE(tableView->contentHeight(), expectedSizeInit); } void tst_QQuickTableView::checkPageFlicking() @@ -618,17 +671,18 @@ void tst_QQuickTableView::checkPageFlicking() const int cellWidth = 100; const int cellHeight = 50; auto model = TestModelAsVariant(10000, 10000); + const auto &loadedRows = tableViewPrivate->loadedRows; + const auto &loadedColumns = tableViewPrivate->loadedColumns; tableView->setModel(model); WAIT_UNTIL_POLISHED; // Sanity check startup table - QRect tableRect = tableViewPrivate->loadedTable; - QCOMPARE(tableRect.x(), 0); - QCOMPARE(tableRect.y(), 0); - QCOMPARE(tableRect.width(), tableView->width() / cellWidth); - QCOMPARE(tableRect.height(), tableView->height() / cellHeight); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(loadedRows.count(), tableView->height() / cellHeight); + QCOMPARE(loadedColumns.count(), tableView->width() / cellWidth); // Since all cells have the same size, the average row/column // size found by TableView should be exactly equal to this. @@ -652,11 +706,10 @@ void tst_QQuickTableView::checkPageFlicking() WAIT_UNTIL_POLISHED; - tableRect = tableViewPrivate->loadedTable; - QCOMPARE(tableRect.x(), flickToColumn); - QCOMPARE(tableRect.y(), 0); - QCOMPARE(tableRect.width(), tableView->width() / cellWidth); - QCOMPARE(tableRect.height(), tableView->height() / cellHeight); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->leftColumn(), flickToColumn); + QCOMPARE(loadedColumns.count(), tableView->width() / cellWidth); + QCOMPARE(loadedRows.count(), tableView->height() / cellHeight); // Flick 5000 rows down as well. Since flicking down should only calculate a new row (but // keep the current column), we deliberatly change the average width to check that it's @@ -675,11 +728,10 @@ void tst_QQuickTableView::checkPageFlicking() WAIT_UNTIL_POLISHED; - tableRect = tableViewPrivate->loadedTable; - QCOMPARE(tableRect.x(), flickToRow); - QCOMPARE(tableRect.y(), flickToColumn); - QCOMPARE(tableRect.width(), tableView->width() / cellWidth); - QCOMPARE(tableRect.height(), tableView->height() / cellHeight); + QCOMPARE(tableViewPrivate->topRow(), flickToColumn); + QCOMPARE(tableViewPrivate->leftColumn(), flickToRow); + QCOMPARE(loadedRows.count(), tableView->height() / cellHeight); + QCOMPARE(loadedColumns.count(), tableView->width() / cellWidth); } void tst_QQuickTableView::checkExplicitContentWidthAndHeight() @@ -729,8 +781,8 @@ void tst_QQuickTableView::checkContentXY() // Check that we end up at the correct top-left cell: const qreal delegateWidth = tableViewPrivate->loadedItems.values().first()->item->width(); const int expectedCellXY = qCeil(expectedXY / delegateWidth); - QCOMPARE(tableViewPrivate->loadedTable.left(), expectedCellXY); - QCOMPARE(tableViewPrivate->loadedTable.top(), expectedCellXY); + QCOMPARE(tableViewPrivate->leftColumn(), expectedCellXY); + QCOMPARE(tableViewPrivate->topRow(), expectedCellXY); } void tst_QQuickTableView::noDelegate() @@ -1004,7 +1056,8 @@ void tst_QQuickTableView::fillTableViewButNothingMore() auto const topLeftFxItem = tableViewPrivate->loadedTableItem(QPoint(0, 0)); auto const topLeftItem = topLeftFxItem->item; - auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(tableViewPrivate->loadedTable.bottomRight()); + auto const bottomRightLoadedCell = QPoint(tableViewPrivate->rightColumn(), tableViewPrivate->bottomRow()); + auto const bottomRightFxItem = tableViewPrivate->loadedTableItem(bottomRightLoadedCell); auto const bottomRightItem = bottomRightFxItem->item; const QPoint bottomRightCell = getContextRowAndColumn(bottomRightItem.data()); @@ -1182,15 +1235,13 @@ void tst_QQuickTableView::flick() WAIT_UNTIL_POLISHED; - const QRect loadedTable = tableViewPrivate->loadedTable; - - const int expectedTableLeft = cellsToFlick - int((margins.left() + spacing.width()) / cellWidth); - const int expectedTableTop = cellsToFlick - int((margins.top() + spacing.height()) / cellHeight); + const int expectedTableLeft = int(cellsToFlick - int((margins.left() + spacing.width()) / cellWidth)); + const int expectedTableTop = int(cellsToFlick - int((margins.top() + spacing.height()) / cellHeight)); - QCOMPARE(loadedTable.left(), expectedTableLeft); - QCOMPARE(loadedTable.right(), expectedTableLeft + visualColumnCount); - QCOMPARE(loadedTable.top(), expectedTableTop); - QCOMPARE(loadedTable.bottom(), expectedTableTop + visualRowCount); + QCOMPARE(tableViewPrivate->leftColumn(), expectedTableLeft); + QCOMPARE(tableViewPrivate->rightColumn(), expectedTableLeft + visualColumnCount); + QCOMPARE(tableViewPrivate->topRow(), expectedTableTop); + QCOMPARE(tableViewPrivate->bottomRow(), expectedTableTop + visualRowCount); } } @@ -1252,10 +1303,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), 0); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), 0); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); // Flick table out of view right tableView->setContentX(tableWidth + outsideMargin); @@ -1264,10 +1315,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); // Flick table out of view on top tableView->setContentX(0); @@ -1276,10 +1327,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), 0); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), 0); // Flick table out of view at the bottom tableView->setContentX(0); @@ -1288,10 +1339,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), rowCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), rowCount - 1); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); // Flick table out of view left and top at the same time tableView->setContentX(-tableView->width() - outsideMargin); @@ -1300,10 +1351,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), 0); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), 0); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), 0); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), 0); // Flick table back to origo tableView->setContentX(0); @@ -1312,10 +1363,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); // Flick table out of view right and bottom at the same time tableView->setContentX(tableWidth + outsideMargin); @@ -1324,10 +1375,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), rowCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), rowCount - 1); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); // Flick table back to origo tableView->setContentX(0); @@ -1336,10 +1387,10 @@ void tst_QQuickTableView::flickOvershoot() WAIT_UNTIL_POLISHED; - QCOMPARE(tableViewPrivate->loadedTable.left(), 0); - QCOMPARE(tableViewPrivate->loadedTable.right(), columnCount - 1); - QCOMPARE(tableViewPrivate->loadedTable.top(), 0); - QCOMPARE(tableViewPrivate->loadedTable.bottom(), rowCount - 1); + QCOMPARE(tableViewPrivate->leftColumn(), 0); + QCOMPARE(tableViewPrivate->rightColumn(), columnCount - 1); + QCOMPARE(tableViewPrivate->topRow(), 0); + QCOMPARE(tableViewPrivate->bottomRow(), rowCount - 1); } void tst_QQuickTableView::checkRowColumnCount() @@ -1353,6 +1404,8 @@ void tst_QQuickTableView::checkRowColumnCount() const qreal delegateWidth = 100; const qreal delegateHeight = 50; auto model = TestModelAsVariant(100, 100); + const auto &loadedRows = tableViewPrivate->loadedRows; + const auto &loadedColumns = tableViewPrivate->loadedColumns; tableView->setModel(model); @@ -1360,17 +1413,15 @@ void tst_QQuickTableView::checkRowColumnCount() // We expect that the number of created items after start-up should match //the size of the visible table, pluss one extra preloaded row and column. - const QSize visibleTableSize = tableViewPrivate->loadedTable.size(); const int qmlCountAfterInit = view->rootObject()->property(maxDelegateCountProp).toInt(); - const int expectedCount = (visibleTableSize.width() + 1) * (visibleTableSize.height() + 1); + const int expectedCount = (loadedColumns.count() + 1) * (loadedRows.count() + 1); QCOMPARE(qmlCountAfterInit, expectedCount); // This test will keep track of the maximum number of delegate items TableView // had to show at any point while flicking (in countingtableview.qml). Because // of the geometries chosen for TableView and the delegate, only complete columns // will be shown at start-up. - const QRect loadedTable = tableViewPrivate->loadedTable; - QVERIFY(loadedTable.height() > loadedTable.width()); + QVERIFY(loadedRows.count() > loadedColumns.count()); QCOMPARE(tableViewPrivate->loadedTableOuterRect.width(), tableView->width()); QCOMPARE(tableViewPrivate->loadedTableOuterRect.height(), tableView->height()); @@ -1619,8 +1670,8 @@ void tst_QQuickTableView::checkIfDelegatesAreReused() fxItem->item->setProperty("reusedCount", 0); } - const int visibleColumnCount = tableViewPrivate->loadedTable.width(); - const int visibleRowCount = tableViewPrivate->loadedTable.height(); + const int visibleColumnCount = tableViewPrivate->loadedColumns.count(); + const int visibleRowCount = tableViewPrivate->loadedRows.count(); const int delegateCountAfterInit = view->rootObject()->property(kDelegatesCreatedCountProp).toInt(); for (int column = 1; column <= (visibleColumnCount * pageFlickCount); ++column) { @@ -1687,7 +1738,7 @@ void tst_QQuickTableView::checkIfDelegatesAreReusedAsymmetricTableSize() // Since we have flicked half a delegate to the left, the number of visible // columns is now one more than the column count were when we started the test. - const int visibleColumnCount = tableViewPrivate->loadedTable.width(); + const int visibleColumnCount = tableViewPrivate->loadedColumns.count(); QCOMPARE(visibleColumnCount, columnCount + 1); // We expect no items to have been pooled so far @@ -1887,7 +1938,7 @@ void tst_QQuickTableView::checkChangingModelFromDelegate() // We now expect two rows in the table, one more than initially QCOMPARE(tableViewPrivate->tableSize.height(), 2); - QCOMPARE(tableViewPrivate->loadedTable.height(), 2); + QCOMPARE(tableViewPrivate->loadedRows.count(), 2); // And since the QML code tried to add another row as well, we // expect rebuildScheduled to be true, and a polish event to be pending. @@ -1897,7 +1948,7 @@ void tst_QQuickTableView::checkChangingModelFromDelegate() // After handling the polish event, we expect also the third row to now be added QCOMPARE(tableViewPrivate->tableSize.height(), 3); - QCOMPARE(tableViewPrivate->loadedTable.height(), 3); + QCOMPARE(tableViewPrivate->loadedRows.count(), 3); } void tst_QQuickTableView::checkRebuildViewportOnly() @@ -1982,8 +2033,8 @@ void tst_QQuickTableView::checkTableviewInsideAsyncLoader() const qreal delegateHeight = 50; int expectedColumns = qCeil(tableView->width() / delegateWidth); int expectedRows = qCeil(tableView->height() / delegateHeight); - QCOMPARE(tableViewPrivate->loadedTable.width(), expectedColumns); - QCOMPARE(tableViewPrivate->loadedTable.height(), expectedRows); + QCOMPARE(tableViewPrivate->loadedColumns.count(), expectedColumns); + QCOMPARE(tableViewPrivate->loadedRows.count(), expectedRows); // Check that the loader was still in a loading state while TableView was creating // delegate items. If we delayed creating delegate items until we got the first @@ -2004,6 +2055,92 @@ void tst_QQuickTableView::checkTableviewInsideAsyncLoader() QVERIFY(height > 0); }; +#define INT_LIST(indices) QVariant::fromValue(QList<int>() << indices) + +void tst_QQuickTableView::hideRowsAndColumns_data() +{ + QTest::addColumn<QVariant>("rowsToHide"); + QTest::addColumn<QVariant>("columnsToHide"); + + const auto emptyList = QVariant::fromValue(QList<int>()); + + // Hide rows + QTest::newRow("first") << INT_LIST(0) << emptyList; + QTest::newRow("middle 1") << INT_LIST(1) << emptyList; + QTest::newRow("middle 3") << INT_LIST(3) << emptyList; + QTest::newRow("last") << INT_LIST(4) << emptyList; + + QTest::newRow("subsequent 0,1") << INT_LIST(0 << 1) << emptyList; + QTest::newRow("subsequent 1,2") << INT_LIST(1 << 2) << emptyList; + QTest::newRow("subsequent 3,4") << INT_LIST(3 << 4) << emptyList; + + QTest::newRow("all but first") << INT_LIST(1 << 2 << 3 << 4) << emptyList; + QTest::newRow("all but last") << INT_LIST(0 << 1 << 2 << 3) << emptyList; + QTest::newRow("all but middle") << INT_LIST(0 << 1 << 3 << 4) << emptyList; + + // Hide columns + QTest::newRow("first") << emptyList << INT_LIST(0); + QTest::newRow("middle 1") << emptyList << INT_LIST(1); + QTest::newRow("middle 3") << emptyList << INT_LIST(3); + QTest::newRow("last") << emptyList << INT_LIST(4); + + QTest::newRow("subsequent 0,1") << emptyList << INT_LIST(0 << 1); + QTest::newRow("subsequent 1,2") << emptyList << INT_LIST(1 << 2); + QTest::newRow("subsequent 3,4") << emptyList << INT_LIST(3 << 4); + + QTest::newRow("all but first") << emptyList << INT_LIST(1 << 2 << 3 << 4); + QTest::newRow("all but last") << emptyList << INT_LIST(0 << 1 << 2 << 3); + QTest::newRow("all but middle") << emptyList << INT_LIST(0 << 1 << 3 << 4); + + // Hide both rows and columns at the same time + QTest::newRow("first") << INT_LIST(0) << INT_LIST(0); + QTest::newRow("middle 1") << INT_LIST(1) << INT_LIST(1); + QTest::newRow("middle 3") << INT_LIST(3) << INT_LIST(3); + QTest::newRow("last") << INT_LIST(4) << INT_LIST(4); + + QTest::newRow("subsequent 0,1") << INT_LIST(0 << 1) << INT_LIST(0 << 1); + QTest::newRow("subsequent 1,2") << INT_LIST(1 << 2) << INT_LIST(1 << 2); + QTest::newRow("subsequent 3,4") << INT_LIST(3 << 4) << INT_LIST(3 << 4); + + QTest::newRow("all but first") << INT_LIST(1 << 2 << 3 << 4) << INT_LIST(1 << 2 << 3 << 4); + QTest::newRow("all but last") << INT_LIST(0 << 1 << 2 << 3) << INT_LIST(0 << 1 << 2 << 3); + QTest::newRow("all but middle") << INT_LIST(0 << 1 << 3 << 4) << INT_LIST(0 << 1 << 3 << 4); + + // Hide all rows and columns + QTest::newRow("all") << INT_LIST(0 << 1 << 2 << 3 << 4) << INT_LIST(0 << 1 << 2 << 3 << 4); +} + +void tst_QQuickTableView::hideRowsAndColumns() +{ + // Check that you can hide the first row (corner case) + // and that we load the other columns as expected. + QFETCH(QVariant, rowsToHide); + QFETCH(QVariant, columnsToHide); + LOAD_TABLEVIEW("hiderowsandcolumns.qml"); + + const QList<int> rowsToHideList = qvariant_cast<QList<int>>(rowsToHide); + const QList<int> columnsToHideList = qvariant_cast<QList<int>>(columnsToHide); + const int modelSize = 5; + auto model = TestModelAsVariant(modelSize, modelSize); + view->rootObject()->setProperty("rowsToHide", rowsToHide); + view->rootObject()->setProperty("columnsToHide", columnsToHide); + + tableView->setModel(model); + + WAIT_UNTIL_POLISHED; + + const int expectedRowCount = modelSize - rowsToHideList.count(); + const int expectedColumnCount = modelSize - columnsToHideList.count(); + QCOMPARE(tableViewPrivate->loadedRows.count(), expectedRowCount); + QCOMPARE(tableViewPrivate->loadedColumns.count(), expectedColumnCount); + + for (const int row : tableViewPrivate->loadedRows.keys()) + QVERIFY(!rowsToHideList.contains(row)); + + for (const int column : tableViewPrivate->loadedColumns.keys()) + QVERIFY(!columnsToHideList.contains(column)); +} + void tst_QQuickTableView::checkThatRevisionedPropertiesCannotBeUsedInOldImports() { // Check that if you use a QQmlAdaptorModel together with a Repeater, the diff --git a/tests/auto/quick/qquicktext/qquicktext.pro b/tests/auto/quick/qquicktext/qquicktext.pro index f76e8c95b2..fdea9dcddd 100644 --- a/tests/auto/quick/qquicktext/qquicktext.pro +++ b/tests/auto/quick/qquicktext/qquicktext.pro @@ -11,4 +11,4 @@ include (../../shared/util.pri) TESTDATA = data/* -QT += core-private gui-private qml-private quick-private network testlib +QT += core-private gui-private qml-private quick-private network testlib qmltest diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp index a9c35e0cc4..fd0ba0f49b 100644 --- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp +++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp @@ -32,6 +32,7 @@ #include <QtQml/qqmlcomponent.h> #include <QtQuick/private/qquicktext_p.h> #include <QtQuick/private/qquickmousearea_p.h> +#include <QtQuickTest/QtQuickTest> #include <private/qquicktext_p_p.h> #include <private/qquicktextdocument_p.h> #include <private/qquickvaluetypes_p.h> @@ -3142,7 +3143,7 @@ void tst_qquicktext::fontSizeMode() QVERIFY(myText != nullptr); myText->setText(text); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); qreal originalWidth = myText->contentWidth(); qreal originalHeight = myText->contentHeight(); @@ -3156,7 +3157,7 @@ void tst_qquicktext::fontSizeMode() myText->setFont(font); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Font size reduced to fit within the width of the item. qreal horizontalFitWidth = myText->contentWidth(); qreal horizontalFitHeight = myText->contentHeight(); @@ -3165,28 +3166,28 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the size with HorizontalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Font size increased to fill the height of the item. qreal verticalFitHeight = myText->contentHeight(); QVERIFY(myText->contentWidth() > myText->width()); @@ -3195,57 +3196,57 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the height of a single line with VerticalFit but will crop the width. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as HorizontalFit with no wrapping. QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::FixedSize); myText->setWrapMode(QQuickText::Wrap); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); originalWidth = myText->contentWidth(); originalHeight = myText->contentHeight(); @@ -3255,7 +3256,7 @@ void tst_qquicktext::fontSizeMode() QVERIFY(originalHeight > myText->height()); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // HorizontalFit should reduce the font size to minimize wrapping, which brings it back to the // same size as without text wrapping. QCOMPARE(myText->contentWidth(), horizontalFitWidth); @@ -3263,16 +3264,16 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the size with HorizontalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // VerticalFit should reduce the size to the wrapped text within the vertical height. verticalFitHeight = myText->contentHeight(); qreal verticalFitWidth = myText->contentWidth(); @@ -3282,40 +3283,40 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the height or width of a wrapped text with VerticalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as VerticalFit with wrapping. QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::FixedSize); myText->setMaximumLineCount(2); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // The original text wrapped should exceed the height of the item. QVERIFY(originalWidth <= myText->width() + 2); QVERIFY(originalHeight > myText->height()); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // HorizontalFit should reduce the font size to minimize wrapping, which brings it back to the // same size as without text wrapping. QCOMPARE(myText->contentWidth(), horizontalFitWidth); @@ -3323,16 +3324,16 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the size with HorizontalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // VerticalFit should reduce the size to the wrapped text within the vertical height. verticalFitHeight = myText->contentHeight(); verticalFitWidth = myText->contentWidth(); @@ -3342,29 +3343,29 @@ void tst_qquicktext::fontSizeMode() // Elide won't affect the height or width of a wrapped text with VerticalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as VerticalFit with wrapping. QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); } void tst_qquicktext::fontSizeModeMultiline_data() @@ -3385,7 +3386,7 @@ void tst_qquicktext::fontSizeModeMultiline() QVERIFY(myText != nullptr); myText->setText(text); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); qreal originalWidth = myText->contentWidth(); qreal originalHeight = myText->contentHeight(); @@ -3400,7 +3401,7 @@ void tst_qquicktext::fontSizeModeMultiline() myText->setFont(font); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Font size reduced to fit within the width of the item. QCOMPARE(myText->lineCount(), 2); qreal horizontalFitWidth = myText->contentWidth(); @@ -3410,7 +3411,7 @@ void tst_qquicktext::fontSizeModeMultiline() // Right eliding will remove the last line myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QCOMPARE(myText->lineCount(), 1); QVERIFY(myText->contentWidth() <= myText->width() + 2); @@ -3418,22 +3419,22 @@ void tst_qquicktext::fontSizeModeMultiline() // Left or middle eliding wont have any effect. myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), horizontalFitWidth); QCOMPARE(myText->contentHeight(), horizontalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Font size reduced to fit within the height of the item. qreal verticalFitWidth = myText->contentWidth(); qreal verticalFitHeight = myText->contentHeight(); @@ -3442,58 +3443,58 @@ void tst_qquicktext::fontSizeModeMultiline() // Elide will have no effect. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as VerticalFit with no wrapping. QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideLeft); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideMiddle); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::FixedSize); myText->setWrapMode(QQuickText::Wrap); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); originalWidth = myText->contentWidth(); originalHeight = myText->contentHeight(); @@ -3503,7 +3504,7 @@ void tst_qquicktext::fontSizeModeMultiline() QVERIFY(originalHeight > myText->height()); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // HorizontalFit should reduce the font size to minimize wrapping, which brings it back to the // same size as without text wrapping. QCOMPARE(myText->contentWidth(), horizontalFitWidth); @@ -3511,16 +3512,16 @@ void tst_qquicktext::fontSizeModeMultiline() // Text will be elided vertically with HorizontalFit myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QVERIFY(myText->contentHeight() <= myText->height() + 2); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // VerticalFit should reduce the size to the wrapped text within the vertical height. verticalFitHeight = myText->contentHeight(); verticalFitWidth = myText->contentWidth(); @@ -3530,40 +3531,40 @@ void tst_qquicktext::fontSizeModeMultiline() // Elide won't affect the height or width of a wrapped text with VerticalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as VerticalFit with wrapping. QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::FixedSize); myText->setMaximumLineCount(2); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // The original text wrapped should exceed the height of the item. QVERIFY(originalWidth <= myText->width() + 2); QVERIFY(originalHeight > myText->height()); myText->setFontSizeMode(QQuickText::HorizontalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // HorizontalFit should reduce the font size to minimize wrapping, which brings it back to the // same size as without text wrapping. QCOMPARE(myText->contentWidth(), horizontalFitWidth); @@ -3571,16 +3572,16 @@ void tst_qquicktext::fontSizeModeMultiline() // Elide won't affect the size with HorizontalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(myText->truncated()); QVERIFY(myText->contentWidth() <= myText->width() + 2); QVERIFY(myText->contentHeight() <= myText->height() + 2); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::VerticalFit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // VerticalFit should reduce the size to the wrapped text within the vertical height. verticalFitHeight = myText->contentHeight(); verticalFitWidth = myText->contentWidth(); @@ -3590,29 +3591,29 @@ void tst_qquicktext::fontSizeModeMultiline() // Elide won't affect the height or width of a wrapped text with VerticalFit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); myText->setFontSizeMode(QQuickText::Fit); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); // Should be the same as VerticalFit with wrapping. QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); // Elide won't affect the size with Fit. myText->setElideMode(QQuickText::ElideRight); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QVERIFY(!myText->truncated()); QCOMPARE(myText->contentWidth(), verticalFitWidth); QCOMPARE(myText->contentHeight(), verticalFitHeight); myText->setElideMode(QQuickText::ElideNone); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); } void tst_qquicktext::multilengthStrings_data() @@ -3637,17 +3638,17 @@ void tst_qquicktext::multilengthStrings() const QString shortText = "fox jumped dog"; myText->setText(longText); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); const qreal longWidth = myText->contentWidth(); const qreal longHeight = myText->contentHeight(); myText->setText(mediumText); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); const qreal mediumWidth = myText->contentWidth(); const qreal mediumHeight = myText->contentHeight(); myText->setText(shortText); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); const qreal shortWidth = myText->contentWidth(); const qreal shortHeight = myText->contentHeight(); @@ -3655,21 +3656,21 @@ void tst_qquicktext::multilengthStrings() myText->setText(longText + QLatin1Char('\x9c') + mediumText + QLatin1Char('\x9c') + shortText); myText->setSize(QSizeF(longWidth, longHeight)); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QCOMPARE(myText->contentWidth(), longWidth); QCOMPARE(myText->contentHeight(), longHeight); QCOMPARE(myText->truncated(), false); myText->setSize(QSizeF(mediumWidth, mediumHeight)); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QCOMPARE(myText->contentWidth(), mediumWidth); QCOMPARE(myText->contentHeight(), mediumHeight); QCOMPARE(myText->truncated(), true); myText->setSize(QSizeF(shortWidth, shortHeight)); - QTRY_COMPARE(QQuickItemPrivate::get(myText)->polishScheduled, false); + QVERIFY(QQuickTest::qWaitForItemPolished(myText)); QCOMPARE(myText->contentWidth(), shortWidth); QCOMPARE(myText->contentHeight(), shortHeight); diff --git a/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml new file mode 100644 index 0000000000..24bd434830 --- /dev/null +++ b/tests/auto/quick/qquicktextedit/data/keys_shortcutoverride.qml @@ -0,0 +1,34 @@ +import QtQuick 2.10 + +Item { + width: 320 + height: 200 + property string who : "nobody" + + Shortcut { + sequence: "Esc" + onActivated: who = "Shortcut" + } + + TextEdit { + id: txt + x: 100 + text: "enter text" + Keys.onShortcutOverride: { + who = "TextEdit" + event.accepted = (event.key === Qt.Key_Escape) + } + } + + Rectangle { + objectName: "rectangle" + width: 90 + height: width + focus: true + color: focus ? "red" : "gray" + Keys.onShortcutOverride: { + who = "Rectangle" + event.accepted = (event.key === Qt.Key_Escape) + } + } +} diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp index da15ca6b48..ce2a8eb257 100644 --- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp +++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp @@ -36,6 +36,7 @@ #include <QtQml/qqmlexpression.h> #include <QtQml/qqmlcomponent.h> #include <QtGui/qguiapplication.h> +#include <private/qquickrectangle_p.h> #include <private/qquicktextedit_p.h> #include <private/qquicktextedit_p_p.h> #include <private/qquicktext_p.h> @@ -205,6 +206,7 @@ private slots: void padding(); void QTBUG_51115_readOnlyResetsSelection(); + void keys_shortcutoverride(); private: void simulateKeys(QWindow *window, const QList<Key> &keys); @@ -1260,6 +1262,34 @@ void tst_qquicktextedit::persistentSelection() edit->setFocus(true); QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + // QTBUG-50587 (persistentSelection with readOnly) + edit->setReadOnly(true); + + edit->setPersistentSelection(false); + QCOMPARE(edit->persistentSelection(), false); + QCOMPARE(spy.count(), 2); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QString()); + + edit->setPersistentSelection(true); + QCOMPARE(edit->persistentSelection(), true); + QCOMPARE(spy.count(), 3); + + edit->select(1, 4); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(false); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); + + edit->setFocus(true); + QCOMPARE(edit->property("selected").toString(), QLatin1String("ell")); } void tst_qquicktextedit::selectionOnFocusOut() @@ -5671,6 +5701,36 @@ void tst_qquicktextedit::QTBUG_51115_readOnlyResetsSelection() QCOMPARE(obj->selectedText(), QString()); } +void tst_qquicktextedit::keys_shortcutoverride() +{ + // Tests that QML TextEdit receives Keys.onShortcutOverride (QTBUG-68711) + QQuickView view; + view.setSource(testFileUrl("keys_shortcutoverride.qml")); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + QObject *root = view.rootObject(); + QVERIFY(root); + + QQuickTextEdit *textEdit = root->findChild<QQuickTextEdit*>(); + QVERIFY(textEdit); + QQuickRectangle *rectangle = root->findChild<QQuickRectangle*>(QLatin1String("rectangle")); + QVERIFY(rectangle); + + // Precondition: check if its not already changed + QCOMPARE(root->property("who").value<QString>(), QLatin1String("nobody")); + + // send Key_Escape to the Rectangle + QVERIFY(rectangle->hasActiveFocus()); + QTest::keyPress(&view, Qt::Key_Escape); + QCOMPARE(root->property("who").value<QString>(), QLatin1String("Rectangle")); + + // send Key_Escape to TextEdit + textEdit->setFocus(true); + QTest::keyPress(&view, Qt::Key_Escape); + QCOMPARE(root->property("who").value<QString>(), QLatin1String("TextEdit")); +} + QTEST_MAIN(tst_qquicktextedit) #include "tst_qquicktextedit.moc" diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp index 12d54c4bbe..5631ffe047 100644 --- a/tests/auto/quick/shared/viewtestutil.cpp +++ b/tests/auto/quick/shared/viewtestutil.cpp @@ -38,6 +38,7 @@ #include <private/qquickwindow_p.h> #include <private/qquickitemview_p_p.h> +QT_BEGIN_NAMESPACE QQuickView *QQuickViewTestUtil::createView() { @@ -478,3 +479,5 @@ namespace QQuickTest { return true; } } + +QT_END_NAMESPACE diff --git a/tests/auto/quick/shared/viewtestutil.h b/tests/auto/quick/shared/viewtestutil.h index 3b57a29777..5e725fdf11 100644 --- a/tests/auto/quick/shared/viewtestutil.h +++ b/tests/auto/quick/shared/viewtestutil.h @@ -37,6 +37,8 @@ QT_FORWARD_DECLARE_CLASS(QQuickView) QT_FORWARD_DECLARE_CLASS(QQuickItemViewPrivate) QT_FORWARD_DECLARE_CLASS(FxViewItem) +QT_BEGIN_NAMESPACE + namespace QQuickViewTestUtil { QQuickView *createView(); @@ -189,6 +191,8 @@ namespace QQuickTest { bool initView(QQuickView &v, const QUrl &url, bool moveMouseOut, QByteArray *errorMessage); } +QT_END_NAMESPACE + Q_DECLARE_METATYPE(QQuickViewTestUtil::QaimModel*) Q_DECLARE_METATYPE(QQuickViewTestUtil::ListChange) Q_DECLARE_METATYPE(QList<QQuickViewTestUtil::ListChange>) diff --git a/tests/auto/quick/shared/visualtestutil.h b/tests/auto/quick/shared/visualtestutil.h index 1cdbaf838b..e623e3e225 100644 --- a/tests/auto/quick/shared/visualtestutil.h +++ b/tests/auto/quick/shared/visualtestutil.h @@ -100,7 +100,4 @@ namespace QQuickVisualTestUtil bool compareImages(const QImage &ia, const QImage &ib, QString *errorMessage); } -#define QQUICK_VERIFY_POLISH(item) \ - QTRY_COMPARE(QQuickItemPrivate::get(item)->polishScheduled, false) - #endif // QQUICKVISUALTESTUTIL_H |