aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/particles/particles.pro2
-rw-r--r--tests/auto/particles/qquickage/qquickage.pro2
-rw-r--r--tests/auto/particles/qquickangleddirection/qquickangleddirection.pro2
-rw-r--r--tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro2
-rw-r--r--tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro2
-rw-r--r--tests/auto/particles/qquickcustomparticle/data/deleteSourceItem.qml81
-rw-r--r--tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro2
-rw-r--r--tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp15
-rw-r--r--tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro2
-rw-r--r--tests/auto/particles/qquickfriction/qquickfriction.pro2
-rw-r--r--tests/auto/particles/qquickgravity/qquickgravity.pro2
-rw-r--r--tests/auto/particles/qquickgroupgoal/qquickgroupgoal.pro2
-rw-r--r--tests/auto/particles/qquickimageparticle/qquickimageparticle.pro2
-rw-r--r--tests/auto/particles/qquickitemparticle/qquickitemparticle.pro2
-rw-r--r--tests/auto/particles/qquicklineextruder/qquicklineextruder.pro2
-rw-r--r--tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro2
-rw-r--r--tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro2
-rw-r--r--tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro2
-rw-r--r--tests/auto/particles/qquickpointattractor/qquickpointattractor.pro2
-rw-r--r--tests/auto/particles/qquickpointdirection/qquickpointdirection.pro2
-rw-r--r--tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro2
-rw-r--r--tests/auto/particles/qquickspritegoal/data/basic.qml4
-rw-r--r--tests/auto/particles/qquickspritegoal/qquickspritegoal.pro2
-rw-r--r--tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro2
-rw-r--r--tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro2
-rw-r--r--tests/auto/particles/qquickturbulence/qquickturbulence.pro2
-rw-r--r--tests/auto/particles/qquickwander/qquickwander.pro2
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/data/test.qml6
-rw-r--r--tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp33
-rw-r--r--tests/auto/qml/debugger/qv8profilerservice/qv8profilerservice.pro2
-rw-r--r--tests/auto/qml/debugger/shared/debugutil_p.h1
-rw-r--r--tests/auto/qml/v4/data/variantHandling.qml67
-rw-r--r--tests/auto/qml/v4/tst_v4.cpp9
-rw-r--r--tests/auto/qmltest/qmltest.pro2
-rw-r--r--tests/auto/quick/qquickanimations/tst_qquickanimations.cpp29
-rw-r--r--tests/auto/quick/qquickcanvas/data/ownershipRootItem.qml11
-rw-r--r--tests/auto/quick/qquickcanvas/qquickcanvas.pro3
-rw-r--r--tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp74
-rw-r--r--tests/auto/quick/qquickgridview/data/gridview1.qml6
-rw-r--r--tests/auto/quick/qquickgridview/data/headerfooter.qml15
-rw-r--r--tests/auto/quick/qquickgridview/data/layouts.qml62
-rw-r--r--tests/auto/quick/qquickgridview/data/resizegrid.qml51
-rw-r--r--tests/auto/quick/qquickgridview/tst_qquickgridview.cpp2039
-rw-r--r--tests/auto/quick/qquicklistview/data/header.qml2
-rw-r--r--tests/auto/quick/qquicklistview/data/headerfooter.qml15
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp759
-rw-r--r--tests/auto/quick/qquickpixmapcache/qquickpixmapcache.pro2
-rw-r--r--tests/auto/quick/qquickpositioners/qquickpositioners.pro1
-rw-r--r--tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp4
-rw-r--r--tests/auto/quick/qquickshadereffect/data/deleteShaderEffectSource.qml74
-rw-r--r--tests/auto/quick/qquickshadereffect/data/deleteSourceItem.qml75
-rw-r--r--tests/auto/quick/qquickshadereffect/data/star.pngbin0 -> 1550 bytes
-rw-r--r--tests/auto/quick/qquickshadereffect/qquickshadereffect.pro1
-rw-r--r--tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp40
-rw-r--r--tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp70
-rw-r--r--tests/auto/quick/qquicktext/tst_qquicktext.cpp254
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp5
57 files changed, 2840 insertions, 1020 deletions
diff --git a/tests/auto/particles/particles.pro b/tests/auto/particles/particles.pro
index d376b9305e..265a1eabc7 100644
--- a/tests/auto/particles/particles.pro
+++ b/tests/auto/particles/particles.pro
@@ -7,6 +7,7 @@ PRIVATETESTS += \
qquickcustomaffector \
qquickcustomparticle \
qquickellipseextruder \
+ qquickgroupgoal \
qquickfriction \
qquickgravity \
qquickimageparticle \
@@ -18,6 +19,7 @@ PRIVATETESTS += \
qquickpointattractor \
qquickpointdirection \
qquickrectangleextruder \
+ qquickspritegoal \
qquicktargetdirection \
qquicktrailemitter \
qquickturbulence \
diff --git a/tests/auto/particles/qquickage/qquickage.pro b/tests/auto/particles/qquickage/qquickage.pro
index 8e5c2f0e33..71ea279ada 100644
--- a/tests/auto/particles/qquickage/qquickage.pro
+++ b/tests/auto/particles/qquickage/qquickage.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro b/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro
index df8d460d3e..0462fff1bd 100644
--- a/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro
+++ b/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro b/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro
index 4ea8739c21..e3f79d47fb 100644
--- a/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro
+++ b/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro b/tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro
index 0855187d47..41ceb8c1fc 100644
--- a/tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro
+++ b/tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickcustomparticle/data/deleteSourceItem.qml b/tests/auto/particles/qquickcustomparticle/data/deleteSourceItem.qml
new file mode 100644
index 0000000000..a68373e7e4
--- /dev/null
+++ b/tests/auto/particles/qquickcustomparticle/data/deleteSourceItem.qml
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Particles 2.0
+
+Rectangle {
+ color: "black"
+ width: 320
+ height: 320
+
+ ParticleSystem {
+ id: sys
+ objectName: "system"
+ anchors.fill: parent
+
+ CustomParticle {
+ id: cp
+ property variant source
+ }
+
+ Emitter{
+ //0,0 position
+ size: 32
+ emitRate: 1000
+ lifeSpan: 500
+ }
+ }
+
+ ShaderEffectSource {
+ id: doomedses
+ hideSource: true
+ sourceItem: Image {
+ id: doomed
+ source: "../../shared/star.png"
+ }
+ }
+
+ function setDeletedSourceItem() {
+ doomed.destroy();
+ cp.source = doomedses;
+ }
+}
diff --git a/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro b/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro
index d5c21abef3..0ee7fc9863 100644
--- a/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro
+++ b/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp b/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp
index a54e10afc6..a81edca35e 100644
--- a/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp
+++ b/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp
@@ -55,6 +55,7 @@ public:
private slots:
void initTestCase();
void test_basic();
+ void test_deleteSourceItem();
};
void tst_qquickcustomparticle::initTestCase()
@@ -94,6 +95,20 @@ void tst_qquickcustomparticle::test_basic()
QVERIFY(oneNonZero);//Zero is a valid value, but it also needs to be set to a random number
}
+void tst_qquickcustomparticle::test_deleteSourceItem()
+{
+ // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash
+ QQuickView* view = createView(testFileUrl("deleteSourceItem.qml"), 600);
+ QVERIFY(view);
+ QObject *obj = view->rootObject();
+ QVERIFY(obj);
+ QQuickParticleSystem* system = view->rootObject()->findChild<QQuickParticleSystem*>("system");
+ ensureAnimTime(200, system->m_animation);
+ QMetaObject::invokeMethod(obj, "setDeletedSourceItem");
+ ensureAnimTime(200, system->m_animation);
+ delete view;
+}
+
QTEST_MAIN(tst_qquickcustomparticle);
#include "tst_qquickcustomparticle.moc"
diff --git a/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro b/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro
index 33241a4792..9e6b95339f 100644
--- a/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro
+++ b/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickfriction/qquickfriction.pro b/tests/auto/particles/qquickfriction/qquickfriction.pro
index 36cf9aaa60..3bc61942d7 100644
--- a/tests/auto/particles/qquickfriction/qquickfriction.pro
+++ b/tests/auto/particles/qquickfriction/qquickfriction.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickgravity/qquickgravity.pro b/tests/auto/particles/qquickgravity/qquickgravity.pro
index 331def26b5..03610742c0 100644
--- a/tests/auto/particles/qquickgravity/qquickgravity.pro
+++ b/tests/auto/particles/qquickgravity/qquickgravity.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickgroupgoal/qquickgroupgoal.pro b/tests/auto/particles/qquickgroupgoal/qquickgroupgoal.pro
index f7f09ed9d0..9ae573fe13 100644
--- a/tests/auto/particles/qquickgroupgoal/qquickgroupgoal.pro
+++ b/tests/auto/particles/qquickgroupgoal/qquickgroupgoal.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private testlib
+QT += core-private gui-private v8-private qml-private testlib quick-private quickparticles-private
diff --git a/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro b/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro
index 226d844263..57909444af 100644
--- a/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro
+++ b/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro
@@ -6,4 +6,4 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro b/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro
index ec7fa48e26..047af9faf8 100644
--- a/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro
+++ b/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro b/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro
index a1297b1e26..83ff8eddcf 100644
--- a/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro
+++ b/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro b/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro
index 99f50a286d..90cf2da4a3 100644
--- a/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro
+++ b/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro b/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro
index c5c908e305..4fa17e2ce0 100644
--- a/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro
+++ b/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro b/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro
index 2179ae3ae9..e8cc4f2cbd 100644
--- a/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro
+++ b/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro b/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro
index 43c8022b0a..07dd50369e 100644
--- a/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro
+++ b/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro b/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro
index 71b21e5f56..e9c73305e1 100644
--- a/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro
+++ b/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro b/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro
index 5e595204cc..e968c4a1f7 100644
--- a/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro
+++ b/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickspritegoal/data/basic.qml b/tests/auto/particles/qquickspritegoal/data/basic.qml
index 622f6bdd70..23effe3a68 100644
--- a/tests/auto/particles/qquickspritegoal/data/basic.qml
+++ b/tests/auto/particles/qquickspritegoal/data/basic.qml
@@ -57,12 +57,12 @@ Rectangle {
name: "happy"
source: "../../shared/squarefacesprite.png"
frames: 6
- duration: 120
+ frameDuration: 120
}, Sprite {
name: "twoHappy"
source: "../../shared/squarefacesprite.png"
frames: 3
- duration: 240
+ frameDuration: 240
}]
}
diff --git a/tests/auto/particles/qquickspritegoal/qquickspritegoal.pro b/tests/auto/particles/qquickspritegoal/qquickspritegoal.pro
index cfe932aabd..a5f491aedc 100644
--- a/tests/auto/particles/qquickspritegoal/qquickspritegoal.pro
+++ b/tests/auto/particles/qquickspritegoal/qquickspritegoal.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private testlib
+QT += core-private gui-private v8-private qml-private testlib quick-private quickparticles-private
diff --git a/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro b/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro
index b7ba905f2e..2d2751e5ab 100644
--- a/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro
+++ b/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro b/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro
index 5a76e2fba4..a5d823911c 100644
--- a/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro
+++ b/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickturbulence/qquickturbulence.pro b/tests/auto/particles/qquickturbulence/qquickturbulence.pro
index 3bfb94addf..5ccf83b337 100644
--- a/tests/auto/particles/qquickturbulence/qquickturbulence.pro
+++ b/tests/auto/particles/qquickturbulence/qquickturbulence.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/particles/qquickwander/qquickwander.pro b/tests/auto/particles/qquickwander/qquickwander.pro
index 1cd4269074..65075e5417 100644
--- a/tests/auto/particles/qquickwander/qquickwander.pro
+++ b/tests/auto/particles/qquickwander/qquickwander.pro
@@ -6,5 +6,5 @@ macx:CONFIG -= app_bundle
include (../../shared/util.pri)
TESTDATA = data/*
-QT += core-private gui-private v8-private qml-private quick-private testlib
+QT += core-private gui-private v8-private qml-private quick-private quickparticles-private testlib
diff --git a/tests/auto/qml/debugger/qqmldebugjs/data/test.qml b/tests/auto/qml/debugger/qqmldebugjs/data/test.qml
index 200f26b1c3..e6c6faa912 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/data/test.qml
+++ b/tests/auto/qml/debugger/qqmldebugjs/data/test.qml
@@ -50,5 +50,11 @@ Item {
var c
var d = 12
}
+ function foo() {
+ var a = [1, 2]
+ var b = {a: "hello", d: 1 }
+ var c
+ var d = 12
+ }
}
diff --git a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
index 8293ec6cda..b93be16e0e 100644
--- a/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
+++ b/tests/auto/qml/debugger/qqmldebugjs/tst_qqmldebugjs.cpp
@@ -107,7 +107,6 @@ const char *GARBAGECOLLECTOR = "gc";
const char *CONNECT = "connect";
const char *INTERRUPT = "interrupt";
-const char *BREAKAFTERCOMPILE = "breakaftercompile";
const char *REQUEST = "request";
const char *IN = "in";
@@ -173,7 +172,6 @@ private slots:
void connect();
void interrupt();
- void breakAfterCompile();
void getVersion();
void getVersionWhenAttaching();
@@ -270,7 +268,6 @@ public:
void connect();
void interrupt();
- void breakAfterCompile(bool enabled);
void continueDebugging(StepAction stepAction, int stepCount = 1);
void evaluate(QString expr, bool global = false, bool disableBreak = false, int frame = -1, const QVariantMap &addContext = QVariantMap());
@@ -301,7 +298,6 @@ signals:
void enabled();
void connected();
void interruptRequested();
- void breakAfterCompileRequested();
void result();
void stopped();
void scriptsResult();
@@ -334,14 +330,6 @@ void QJSDebugClient::interrupt()
sendMessage(packMessage(INTERRUPT));
}
-void QJSDebugClient::breakAfterCompile(bool enabled)
-{
- QByteArray request;
- QDataStream rs(&request, QIODevice::WriteOnly);
- rs << enabled;
- sendMessage(packMessage(BREAKAFTERCOMPILE, request));
-}
-
void QJSDebugClient::continueDebugging(StepAction action, int count)
{
// { "seq" : <number>,
@@ -957,9 +945,6 @@ void QJSDebugClient::messageReceived(const QByteArray &data)
emit stopped();
}
- } else if (type == BREAKAFTERCOMPILE) {
- emit breakAfterCompileRequested();
-
}
}
}
@@ -1074,18 +1059,6 @@ void tst_QQmlDebugJS::interrupt()
QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(interruptRequested())));
}
-void tst_QQmlDebugJS::breakAfterCompile()
-{
- //void breakAfterCompile(bool enabled)
-
- QVERIFY(init());
- client->breakAfterCompile(true);
- client->connect();
-
- QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(breakAfterCompileRequested())));
- QVERIFY(QQmlDebugTest::waitForSignal(client, SIGNAL(stopped())));
-}
-
void tst_QQmlDebugJS::getVersion()
{
//void version()
@@ -1146,9 +1119,9 @@ void tst_QQmlDebugJS::listBreakpoints()
{
//void listBreakpoints()
- int sourceLine1 = 47;
- int sourceLine2 = 48;
- int sourceLine3 = 49;
+ int sourceLine1 = 53;
+ int sourceLine2 = 54;
+ int sourceLine3 = 55;
QVERIFY(init());
client->connect();
diff --git a/tests/auto/qml/debugger/qv8profilerservice/qv8profilerservice.pro b/tests/auto/qml/debugger/qv8profilerservice/qv8profilerservice.pro
index 5088953c92..13d39c0225 100644
--- a/tests/auto/qml/debugger/qv8profilerservice/qv8profilerservice.pro
+++ b/tests/auto/qml/debugger/qv8profilerservice/qv8profilerservice.pro
@@ -13,3 +13,5 @@ OTHER_FILES += data/test.qml
CONFIG += parallel_test declarative_debug
QT += qml testlib
+
+macx:CONFIG += insignificant_test # QTBUG-25288
diff --git a/tests/auto/qml/debugger/shared/debugutil_p.h b/tests/auto/qml/debugger/shared/debugutil_p.h
index 2ea295b822..4350056caf 100644
--- a/tests/auto/qml/debugger/shared/debugutil_p.h
+++ b/tests/auto/qml/debugger/shared/debugutil_p.h
@@ -48,6 +48,7 @@
#include <QThread>
#include <QTest>
#include <QProcess>
+#include <QMutex>
#include <QtQml/qqmlengine.h>
diff --git a/tests/auto/qml/v4/data/variantHandling.qml b/tests/auto/qml/v4/data/variantHandling.qml
new file mode 100644
index 0000000000..3d48eef57e
--- /dev/null
+++ b/tests/auto/qml/v4/data/variantHandling.qml
@@ -0,0 +1,67 @@
+import QtQuick 2.0
+
+QtObject {
+ property bool pBool: true
+ property int pInt: 666
+ property real pReal: 3.1415927
+ property string pString: 'foo'
+ property url pUrl: 'http://tools.ietf.org/html/rfc3986#section-1.1.2'
+ property color pColor: Qt.rgba(1, 0, 0, 0.5)
+ property QtObject pObject: QtObject { property string foo: 'bar' }
+
+ // Test assignment to variant
+ property variant pBoolVar: pBool
+ property variant pIntVar: pInt
+ property variant pRealVar: pReal
+ property variant pStringVar: pString
+ property variant pUrlVar: pUrl
+ property variant pColorVar: pColor
+ property variant pObjectVar: pObject
+ property variant pNullVar: null
+ property variant pVarVar: pUrlVar
+
+ // Test equivalence
+ property bool boolConversionSuccess: (pBoolVar == true)
+ property bool intConversionSuccess: (pIntVar == 666)
+ property bool realConversionSuccess: (pRealVar == 3.1415927)
+ property bool stringConversionSuccess: (pStringVar == 'foo')
+
+ property url comparisonUrl: 'http://tools.ietf.org/html/rfc3986#section-1.1.2'
+ property bool urlConversionSuccess: (pUrlVar == comparisonUrl)
+
+ property color comparisonColor: Qt.rgba(1, 0, 0, 0.5)
+ property bool colorConversionSuccess: (pColorVar == comparisonColor)
+
+ property bool objectConversionSuccess: (pObjectVar == pObject)
+ property bool nullConversionSuccess: (pNullVar == null)
+
+ property bool variantConversionSuccess: (pVarVar == comparisonUrl)
+
+ // Operations are not handled by V4 - they should pass through correctly
+ property variant pVarNot: !pBoolVar
+ property variant pVarComplement: ~pIntVar
+ property variant pVarEqual: (pBoolVar == pBoolVar)
+ property variant pVarLiteralEqual: (pBoolVar == true)
+ property variant pVarUnequal: (pUrlVar == pColorVar)
+ property variant pVarComparison: (pIntVar <= pIntVar)
+ property variant pVarShift: (pIntVar >> 1)
+
+ Component.onCompleted: {
+ if (!boolConversionSuccess) console.warn('QV4: bool conversion failed');
+ if (!intConversionSuccess) console.warn('QV4: int conversion failed');
+ if (!realConversionSuccess) console.warn('QV4: real conversion failed');
+ if (!stringConversionSuccess) console.warn('QV4: string conversion failed');
+ if (!urlConversionSuccess) console.warn('QV4: url conversion failed');
+ if (!colorConversionSuccess) console.warn('QV4: color conversion failed');
+ if (!objectConversionSuccess) console.warn('QV4: object conversion failed');
+ if (!nullConversionSuccess) console.warn('QV4: null conversion failed');
+ if (!variantConversionSuccess) console.warn('QV4: variant conversion failed');
+ if (pVarNot != false) console.warn('QV4: variant negation impeded');
+ if (pVarComplement != ~666) console.warn('QV4: variant complement impeded');
+ if (pVarEqual != true) console.warn('QV4: variant equality impeded');
+ if (pVarLiteralEqual != true) console.warn('QV4: variant/literal equality impeded');
+ if (pVarUnequal != false) console.warn('QV4: variant unequality impeded');
+ if (pVarComparison != true) console.warn('QV4: variant comparison impeded');
+ if (pVarShift != 333) console.warn('QV4: variant shift impeded');
+ }
+}
diff --git a/tests/auto/qml/v4/tst_v4.cpp b/tests/auto/qml/v4/tst_v4.cpp
index dfb7cc48c7..99a4405afa 100644
--- a/tests/auto/qml/v4/tst_v4.cpp
+++ b/tests/auto/qml/v4/tst_v4.cpp
@@ -150,6 +150,7 @@ void tst_v4::qtscript_data()
QTest::newRow("conversion from string") << "conversions.6.qml"; // QTBUG-24706
QTest::newRow("conversion from url") << "conversions.7.qml"; // QTBUG-24706
QTest::newRow("conversion from vec3") << "conversions.8.qml";
+ QTest::newRow("variantHandling") << "variantHandling.qml";
}
void tst_v4::unnecessaryReeval()
@@ -856,23 +857,31 @@ void tst_v4::debuggingDumpInstructions()
expectedPreAddress << "\t\tConvertBoolToInt\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertBoolToNumber\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertBoolToString\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertBoolToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertIntToBool\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertIntToNumber\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertIntToString\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertIntToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertNumberToBool\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertNumberToInt\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertNumberToString\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertNumberToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertStringToBool\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertStringToInt\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertStringToNumber\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertStringToUrl\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertStringToColor\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertStringToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertUrlToBool\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertUrlToString\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertUrlToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertColorToBool\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertColorToString\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertColorToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertObjectToBool\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertObjectToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tConvertNullToObject\tInput_Reg(0) -> Output_Reg(0)";
+ expectedPreAddress << "\t\tConvertNullToVariant\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tResolveUrl\t\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tMathSinNumber\t\tInput_Reg(0) -> Output_Reg(0)";
expectedPreAddress << "\t\tMathCosNumber\t\tInput_Reg(0) -> Output_Reg(0)";
diff --git a/tests/auto/qmltest/qmltest.pro b/tests/auto/qmltest/qmltest.pro
index b1b2ee2228..ca39dacdb9 100644
--- a/tests/auto/qmltest/qmltest.pro
+++ b/tests/auto/qmltest/qmltest.pro
@@ -9,4 +9,4 @@ importFiles.files = borderimage buttonclick createbenchmark events qqmlbindi
importFiles.path = .
DEPLOYMENT += importFiles
-CONFIG+=insignificant_test \ No newline at end of file
+CONFIG+=insignificant_test # QTBUG-25306
diff --git a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
index 166f4b8276..7460263d71 100644
--- a/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
+++ b/tests/auto/quick/qquickanimations/tst_qquickanimations.cpp
@@ -624,6 +624,32 @@ void tst_qquickanimations::resume()
QTest::qWait(400);
animation.stop();
QVERIFY(rect.x() > x);
+
+ animation.start();
+ QVERIFY(animation.isRunning());
+ animation.pause();
+ QVERIFY(animation.isPaused());
+ animation.resume();
+ QVERIFY(!animation.isPaused());
+
+ QSignalSpy spy(&animation, SIGNAL(pausedChanged(bool)));
+ animation.pause();
+ QCOMPARE(spy.count(), 1);
+ QVERIFY(animation.isPaused());
+ animation.stop();
+ QVERIFY(!animation.isPaused());
+ QCOMPARE(spy.count(), 2);
+
+ qmlRegisterType<QQuickPropertyAnimation>("QtQuick",2,0,"PropertyAnimation"); //make sure QQuickPropertyAnimation has correct qml type name
+ QByteArray message = "<Unknown File>: QML PropertyAnimation: setPaused() cannot be used when animation isn't running.";
+ QTest::ignoreMessage(QtWarningMsg, message);
+ animation.pause();
+ QCOMPARE(spy.count(), 2);
+ QVERIFY(!animation.isPaused());
+ animation.resume();
+ QVERIFY(!animation.isPaused());
+ QVERIFY(!animation.isRunning());
+ QCOMPARE(spy.count(), 2);
}
void tst_qquickanimations::dotProperty()
@@ -961,11 +987,12 @@ void tst_qquickanimations::disabledTransition()
QCOMPARE(myRect->x(),qreal(200));
trans->setEnabled(true);
-
+ QSignalSpy runningSpy(trans, SIGNAL(runningChanged()));
QQuickItemPrivate::get(rect)->setState("");
QCOMPARE(myRect->x(),qreal(200));
QTest::qWait(300);
QTIMED_COMPARE(myRect->x(),qreal(100));
+ QCOMPARE(runningSpy.count(), 2); //stopped, running, stopped
}
void tst_qquickanimations::invalidDuration()
diff --git a/tests/auto/quick/qquickcanvas/data/ownershipRootItem.qml b/tests/auto/quick/qquickcanvas/data/ownershipRootItem.qml
new file mode 100644
index 0000000000..dfc4159f4e
--- /dev/null
+++ b/tests/auto/quick/qquickcanvas/data/ownershipRootItem.qml
@@ -0,0 +1,11 @@
+import QtQuick 2.0
+import QtQuick.Window 2.0 as Window
+
+Window.Window {
+RootItemAccessor {
+ id:accessor
+ objectName:"accessor"
+ Component.onCompleted:accessor.rootItem();
+}
+
+} \ No newline at end of file
diff --git a/tests/auto/quick/qquickcanvas/qquickcanvas.pro b/tests/auto/quick/qquickcanvas/qquickcanvas.pro
index 817eb2534f..b9ed73d577 100644
--- a/tests/auto/quick/qquickcanvas/qquickcanvas.pro
+++ b/tests/auto/quick/qquickcanvas/qquickcanvas.pro
@@ -7,7 +7,7 @@ include (../../shared/util.pri)
macx:CONFIG -= app_bundle
CONFIG += parallel_test
-QT += core-private gui-private qml-private quick-private testlib
+QT += core-private gui-private qml-private quick-private v8-private testlib
TESTDATA = data/*
@@ -15,4 +15,3 @@ OTHER_FILES += \
data/AnimationsWhileHidden.qml \
data/Headless.qml
-
diff --git a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
index 7250504e73..ca2165d711 100644
--- a/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
+++ b/tests/auto/quick/qquickcanvas/tst_qquickcanvas.cpp
@@ -50,6 +50,7 @@
#include <QtGui/QWindowSystemInterface>
#include "../../shared/util.h"
#include <QSignalSpy>
+#include <private/qquickcanvas_p.h>
struct TouchEventData {
QEvent::Type type;
@@ -108,6 +109,36 @@ static TouchEventData makeTouchData(QEvent::Type type, QWindow *w, Qt::TouchPoin
} \
}
+
+class RootItemAccessor : public QQuickItem
+{
+ Q_OBJECT
+public:
+ RootItemAccessor()
+ : m_rootItemDestroyed(false)
+ , m_rootItem(0)
+ {
+ }
+ Q_INVOKABLE QQuickItem *rootItem()
+ {
+ if (!m_rootItem) {
+ QQuickCanvasPrivate *c = QQuickCanvasPrivate::get(canvas());
+ m_rootItem = c->rootItem;
+ QObject::connect(m_rootItem, SIGNAL(destroyed()), this, SLOT(rootItemDestroyed()));
+ }
+ return m_rootItem;
+ }
+ bool isRootItemDestroyed() {return m_rootItemDestroyed;}
+public slots:
+ void rootItemDestroyed() {
+ m_rootItemDestroyed = true;
+ }
+
+private:
+ bool m_rootItemDestroyed;
+ QQuickItem *m_rootItem;
+};
+
class TestTouchItem : public QQuickRectangle
{
Q_OBJECT
@@ -214,6 +245,7 @@ private slots:
void ignoreUnhandledMouseEvents();
+ void ownershipRootItem();
private:
QTouchDevice *touchDevice;
};
@@ -234,7 +266,7 @@ void tst_qquickcanvas::touchEvent_basic()
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
- canvas->move(100, 100);
+ canvas->setPos(100, 100);
canvas->show();
TestTouchItem *bottomItem = new TestTouchItem(canvas->rootItem());
@@ -355,7 +387,7 @@ void tst_qquickcanvas::touchEvent_propagation()
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
- canvas->move(100, 100);
+ canvas->setPos(100, 100);
canvas->show();
TestTouchItem *bottomItem = new TestTouchItem(canvas->rootItem());
@@ -483,7 +515,7 @@ void tst_qquickcanvas::touchEvent_cancel()
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
- canvas->move(100, 100);
+ canvas->setPos(100, 100);
canvas->show();
TestTouchItem *item = new TestTouchItem(canvas->rootItem());
@@ -529,7 +561,7 @@ void tst_qquickcanvas::mouseFiltering()
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
- canvas->move(100, 100);
+ canvas->setPos(100, 100);
canvas->show();
TestTouchItem *bottomItem = new TestTouchItem(canvas->rootItem());
@@ -586,7 +618,7 @@ void tst_qquickcanvas::clearColor()
//### Can we examine rendering to make sure it is really blue?
QQuickCanvas *canvas = new QQuickCanvas;
canvas->resize(250, 250);
- canvas->move(100, 100);
+ canvas->setPos(100, 100);
canvas->setClearColor(Qt::blue);
canvas->show();
QTest::qWaitForWindowShown(canvas);
@@ -620,7 +652,7 @@ void tst_qquickcanvas::multipleWindows()
c->setPos(100 + i * 30, 100 + i * 20);
c->show();
windows << c;
- QVERIFY(c->visible());
+ QVERIFY(c->isVisible());
}
// move them
@@ -647,15 +679,15 @@ void tst_qquickcanvas::animationsWhileHidden()
QQuickCanvas* canvas = qobject_cast<QQuickCanvas*>(created);
QVERIFY(canvas);
- QVERIFY(canvas->visible());
+ QVERIFY(canvas->isVisible());
// Now hide the window and verify that it went off screen
canvas->hide();
QTest::qWait(10);
- QVERIFY(!canvas->visible());
+ QVERIFY(!canvas->isVisible());
// Running animaiton should cause it to become visible again shortly.
- QTRY_VERIFY(canvas->visible());
+ QTRY_VERIFY(canvas->isVisible());
delete canvas;
}
@@ -672,7 +704,7 @@ void tst_qquickcanvas::headless()
QVERIFY(canvas);
QTest::qWaitForWindowShown(canvas);
- QVERIFY(canvas->visible());
+ QVERIFY(canvas->isVisible());
QSignalSpy initialized(canvas, SIGNAL(sceneGraphInitialized()));
QSignalSpy invalidated(canvas, SIGNAL(sceneGraphInvalidated()));
@@ -770,6 +802,28 @@ void tst_qquickcanvas::ignoreUnhandledMouseEvents()
delete canvas;
}
+
+void tst_qquickcanvas::ownershipRootItem()
+{
+ qmlRegisterType<RootItemAccessor>("QtQuick", 2, 0, "RootItemAccessor");
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.loadUrl(testFileUrl("ownershipRootItem.qml"));
+ QObject* created = component.create();
+
+ QQuickCanvas* canvas = qobject_cast<QQuickCanvas*>(created);
+ QVERIFY(canvas);
+ QTest::qWaitForWindowShown(canvas);
+
+ RootItemAccessor* accessor = canvas->findChild<RootItemAccessor*>("accessor");
+ QVERIFY(accessor);
+ engine.collectGarbage();
+
+ QCoreApplication::sendPostedEvents(0, QEvent::DeferredDelete);
+ QCoreApplication::processEvents();
+ QVERIFY(!accessor->isRootItemDestroyed());
+}
QTEST_MAIN(tst_qquickcanvas)
#include "tst_qquickcanvas.moc"
diff --git a/tests/auto/quick/qquickgridview/data/gridview1.qml b/tests/auto/quick/qquickgridview/data/gridview1.qml
index 4bf6f0b952..1424955689 100644
--- a/tests/auto/quick/qquickgridview/data/gridview1.qml
+++ b/tests/auto/quick/qquickgridview/data/gridview1.qml
@@ -26,8 +26,9 @@ Rectangle {
text: index
}
Text {
- x: 40
+ x: 30
text: wrapper.x + ", " + wrapper.y
+ font.pixelSize: 12
}
Text {
y: 20
@@ -58,12 +59,11 @@ Rectangle {
height: 320
cellWidth: 80
cellHeight: 60
- flow: (testTopToBottom == false) ? GridView.LeftToRight : GridView.TopToBottom
- layoutDirection: (testRightToLeft == true) ? Qt.RightToLeft : Qt.LeftToRight
model: testModel
delegate: myDelegate
header: root.showHeader ? headerFooter : null
footer: root.showFooter ? headerFooter : null
cacheBuffer: root.cacheBuffer
+ focus: true
}
}
diff --git a/tests/auto/quick/qquickgridview/data/headerfooter.qml b/tests/auto/quick/qquickgridview/data/headerfooter.qml
index 322cfed388..f0f73a0dac 100644
--- a/tests/auto/quick/qquickgridview/data/headerfooter.qml
+++ b/tests/auto/quick/qquickgridview/data/headerfooter.qml
@@ -2,24 +2,22 @@ import QtQuick 2.0
GridView {
id: view
- property bool horizontal: false
- property bool rtl: false
+
width: 240
height: 320
model: testModel
-
- flow: horizontal ? GridView.TopToBottom : GridView.LeftToRight
+
header: Rectangle {
objectName: "header"
- width: horizontal ? 20 : view.width
- height: horizontal ? view.height : 20
+ width: flow == GridView.TopToBottom ? 20 : view.width
+ height: flow == GridView.TopToBottom ? view.height : 20
color: "red"
}
footer: Rectangle {
objectName: "footer"
- width: horizontal ? 30 : view.width
- height: horizontal ? view.height : 30
+ width: flow == GridView.TopToBottom ? 30 : view.width
+ height: flow == GridView.TopToBottom ? view.height : 30
color: "blue"
}
@@ -27,5 +25,4 @@ GridView {
cellHeight: 80;
delegate: Text { width: 80; height: 80; text: index + "(" + x + ")" }
- layoutDirection: rtl ? Qt.RightToLeft : Qt.LeftToRight
}
diff --git a/tests/auto/quick/qquickgridview/data/layouts.qml b/tests/auto/quick/qquickgridview/data/layouts.qml
new file mode 100644
index 0000000000..e00351f1bf
--- /dev/null
+++ b/tests/auto/quick/qquickgridview/data/layouts.qml
@@ -0,0 +1,62 @@
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+ width: 240
+ height: 320
+
+ property bool showHeader: false
+ property bool showFooter: false
+
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ width: 80
+ height: 60
+ border.width: 1
+ Text { text: index }
+ Text {
+ x: 30
+ text: wrapper.x + ", " + wrapper.y
+ font.pixelSize: 12
+ }
+ Text {
+ y: 20
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ y: 40
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+
+ property string theName: name
+ color: GridView.isCurrentItem ? "lightsteelblue" : "white"
+ }
+ }
+
+ Component {
+ id: headerFooter
+ Rectangle { width: 30; height: 320; color: "blue" }
+ }
+
+ GridView {
+ objectName: "grid"
+ width: 240
+ height: 320
+ cellWidth: 80
+ cellHeight: 60
+ flow: (testTopToBottom == false) ? GridView.LeftToRight : GridView.TopToBottom
+ layoutDirection: (testRightToLeft == true) ? Qt.RightToLeft : Qt.LeftToRight
+ verticalLayoutDirection: (testBottomToTop == true) ? GridView.BottomToTop : GridView.TopToBottom
+ model: testModel
+ delegate: myDelegate
+ header: root.showHeader ? headerFooter : null
+ footer: root.showFooter ? headerFooter : null
+ }
+}
diff --git a/tests/auto/quick/qquickgridview/data/resizegrid.qml b/tests/auto/quick/qquickgridview/data/resizegrid.qml
new file mode 100644
index 0000000000..7ea2f120e8
--- /dev/null
+++ b/tests/auto/quick/qquickgridview/data/resizegrid.qml
@@ -0,0 +1,51 @@
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ width: 80
+ height: 60
+ border.width: 1
+ Text { text: index }
+ Text {
+ x: 30
+ text: wrapper.x + ", " + wrapper.y
+ font.pixelSize: 12
+ }
+ Text {
+ y: 20
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ color: GridView.isCurrentItem ? "lightsteelblue" : "white"
+ }
+ }
+
+ // the grid is specifically placed inside another item to test a bug where
+ // resizing from anchor changes did not update the content pos correctly
+ Item {
+ anchors.fill: parent
+
+ GridView {
+ clip: true
+ objectName: "grid"
+ anchors.fill: parent
+ cellWidth: 80
+ cellHeight: 60
+
+ flow: (testTopToBottom == false) ? GridView.LeftToRight : GridView.TopToBottom
+ layoutDirection: (testRightToLeft == true) ? Qt.RightToLeft : Qt.LeftToRight
+ verticalLayoutDirection: (testBottomToTop == true) ? GridView.BottomToTop : GridView.TopToBottom
+ model: testModel
+ delegate: myDelegate
+ }
+
+ }
+}
+
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
index 22c9004ccc..bc0108c842 100644
--- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
@@ -58,8 +58,10 @@
#include "../shared/visualtestutil.h"
#include <QtGui/qguiapplication.h>
-Q_DECLARE_METATYPE(Qt::LayoutDirection)
Q_DECLARE_METATYPE(QQuickGridView::Flow)
+Q_DECLARE_METATYPE(Qt::LayoutDirection)
+Q_DECLARE_METATYPE(QQuickItemView::VerticalLayoutDirection)
+Q_DECLARE_METATYPE(Qt::Key)
using namespace QQuickViewTestUtil;
using namespace QQuickVisualTestUtil;
@@ -76,25 +78,29 @@ private slots:
void init();
void items();
void changed();
- void inserted();
- void inserted_more();
- void inserted_more_data();
+ void inserted_basic();
+ void inserted_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+ void inserted_defaultLayout_data();
void insertBeforeVisible();
void insertBeforeVisible_data();
- void removed();
- void removed_more();
- void removed_more_data();
+ void removed_basic();
+ void removed_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+ void removed_defaultLayout_data();
void addOrRemoveBeforeVisible();
void addOrRemoveBeforeVisible_data();
void clear();
- void moved();
- void moved_data();
- void multipleChanges();
- void multipleChanges_data();
+ void moved_defaultLayout(QQuickGridView::Flow flow = QQuickGridView::FlowLeftToRight, Qt::LayoutDirection horizLayout = Qt::LeftToRight, QQuickItemView::VerticalLayoutDirection verticalLayout = QQuickItemView::TopToBottom);
+ void moved_defaultLayout_data();
+ void multipleChanges_condensed() { multipleChanges(true); }
+ void multipleChanges_condensed_data() { multipleChanges_data(); }
+ void multipleChanges_uncondensed() { multipleChanges(false); }
+ void multipleChanges_uncondensed_data() { multipleChanges_data(); }
void swapWithFirstItem();
void changeFlow();
void currentIndex();
void noCurrentIndex();
+ void keyNavigation();
+ void keyNavigation_data();
void defaultValues();
void properties();
void propertyChanges();
@@ -114,7 +120,11 @@ private slots:
void header();
void header_data();
void headerFooter();
+ void headerFooter_data();
+ void resetModel_headerFooter();
void resizeViewAndRepaint();
+ void resizeGrid();
+ void resizeGrid_data();
void changeColumnCount();
void indexAt_itemAt_data();
void indexAt_itemAt();
@@ -148,12 +158,117 @@ private slots:
void multipleTransitions_data();
void multipleDisplaced();
+ void inserted_leftToRight_RtL_TtB();
+ void inserted_leftToRight_RtL_TtB_data();
+ void inserted_leftToRight_LtR_BtT();
+ void inserted_leftToRight_LtR_BtT_data();
+ void inserted_leftToRight_RtL_BtT();
+ void inserted_leftToRight_RtL_BtT_data();
+ void inserted_topToBottom_LtR_TtB();
+ void inserted_topToBottom_LtR_TtB_data();
+ void inserted_topToBottom_RtL_TtB();
+ void inserted_topToBottom_RtL_TtB_data();
+ void inserted_topToBottom_LtR_BtT();
+ void inserted_topToBottom_LtR_BtT_data();
+ void inserted_topToBottom_RtL_BtT();
+ void inserted_topToBottom_RtL_BtT_data();
+
+ void removed_leftToRight_RtL_TtB();
+ void removed_leftToRight_RtL_TtB_data();
+ void removed_leftToRight_LtR_BtT();
+ void removed_leftToRight_LtR_BtT_data();
+ void removed_leftToRight_RtL_BtT();
+ void removed_leftToRight_RtL_BtT_data();
+ void removed_topToBottom_LtR_TtB();
+ void removed_topToBottom_LtR_TtB_data();
+ void removed_topToBottom_RtL_TtB();
+ void removed_topToBottom_RtL_TtB_data();
+ void removed_topToBottom_LtR_BtT();
+ void removed_topToBottom_LtR_BtT_data();
+ void removed_topToBottom_RtL_BtT();
+ void removed_topToBottom_RtL_BtT_data();
+
+ void moved_leftToRight_RtL_TtB();
+ void moved_leftToRight_RtL_TtB_data();
+ void moved_leftToRight_LtR_BtT();
+ void moved_leftToRight_LtR_BtT_data();
+ void moved_leftToRight_RtL_BtT();
+ void moved_leftToRight_RtL_BtT_data();
+ void moved_topToBottom_LtR_TtB();
+ void moved_topToBottom_LtR_TtB_data();
+ void moved_topToBottom_RtL_TtB();
+ void moved_topToBottom_RtL_TtB_data();
+ void moved_topToBottom_LtR_BtT();
+ void moved_topToBottom_LtR_BtT_data();
+ void moved_topToBottom_RtL_BtT();
+ void moved_topToBottom_RtL_BtT_data();
+
private:
QList<int> toIntList(const QVariantList &list);
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes);
void matchItemLists(const QVariantList &itemLists, const QList<QQuickItem *> &expectedItems);
+ void multipleChanges(bool condensed);
+ void multipleChanges_data();
+
+ QPointF expectedItemPos(QQuickGridView *grid, int index, qreal rowOffset = 0) {
+ qreal x;
+ qreal y;
+ if (grid->flow() == QQuickGridView::FlowLeftToRight) {
+ int columns = grid->width() / grid->cellWidth();
+ x = (index % columns) * grid->cellWidth();
+ y = (index / columns) * grid->cellHeight();
+ if (grid->effectiveLayoutDirection() == Qt::RightToLeft) {
+ int col = (index % columns) * grid->cellWidth();
+ x = grid->cellWidth() * (columns - 1) - col;
+ }
+
+ qreal offset = grid->cellHeight() * rowOffset;
+ if (grid->verticalLayoutDirection() == QQuickItemView::TopToBottom)
+ y += offset;
+ else
+ y = -grid->cellHeight() - y - offset;
+ } else {
+ int rows = grid->height() / grid->cellHeight();
+ x = (index / rows) * grid->cellWidth();
+ y = (index % rows) * grid->cellHeight();
+ if (grid->effectiveLayoutDirection() == Qt::RightToLeft)
+ x = -x - grid->cellWidth();
+
+ qreal offset = grid->cellWidth() * rowOffset;
+ if (grid->effectiveLayoutDirection() == Qt::RightToLeft)
+ x -= offset;
+ else
+ x += offset;
+ if (grid->verticalLayoutDirection() == QQuickItemView::BottomToTop)
+ y = -grid->cellHeight() - y;
+ }
+ return QPointF(x, y);
+ }
+
+ // Sets contentY (or contentX in TopToBottom flow) according to given row offset
+ // (in LeftToRight flow) or col offset (in TopToBottom).
+ bool setContentPos(QQuickGridView *gridview, qreal rowOrColOffset) {
+ bool contentPosChanged = (rowOrColOffset != 0);
+ qreal contentOffset = gridview->flow() == QQuickGridView::FlowLeftToRight
+ ? rowOrColOffset * gridview->cellHeight()
+ : rowOrColOffset * gridview->cellWidth();
+
+ if (gridview->flow() == QQuickGridView::FlowLeftToRight) {
+ if (gridview->verticalLayoutDirection() == QQuickItemView::BottomToTop)
+ contentOffset = -gridview->height() - contentOffset;
+ } else {
+ if (gridview->effectiveLayoutDirection() == Qt::RightToLeft)
+ contentOffset = -gridview->width() - contentOffset;
+ }
+ if (gridview->flow() == QQuickGridView::FlowLeftToRight)
+ gridview->setContentY(contentOffset);
+ else
+ gridview->setContentX(contentOffset);
+ return contentPosChanged;
+ }
+
#ifdef SHARE_VIEWS
QQuickView *getView() {
if (m_view) {
@@ -217,8 +332,6 @@ void tst_QQuickGridView::items()
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -267,8 +380,6 @@ void tst_QQuickGridView::changed()
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -290,7 +401,7 @@ void tst_QQuickGridView::changed()
delete canvas;
}
-void tst_QQuickGridView::inserted()
+void tst_QQuickGridView::inserted_basic()
{
QQuickView *canvas = createView();
canvas->show();
@@ -300,11 +411,7 @@ void tst_QQuickGridView::inserted()
model.addItem("John", "2345");
model.addItem("Bob", "54321");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -370,12 +477,16 @@ void tst_QQuickGridView::inserted()
delete canvas;
}
-void tst_QQuickGridView::inserted_more()
+void tst_QQuickGridView::inserted_defaultLayout(QQuickGridView::Flow flow,
+ Qt::LayoutDirection horizLayout,
+ QQuickItemView::VerticalLayoutDirection verticalLayout)
{
- QFETCH(qreal, contentY);
+ QFETCH(qreal, contentYRowOffset);
QFETCH(int, insertIndex);
QFETCH(int, insertCount);
- QFETCH(qreal, itemsOffsetAfterMove);
+ QFETCH(int, insertIndex_ttb);
+ QFETCH(int, insertCount_ttb);
+ QFETCH(qreal, rowOffsetAfterMove);
QaimModel model;
for (int i = 0; i < 30; i++)
@@ -384,10 +495,10 @@ void tst_QQuickGridView::inserted_more()
QQuickView *canvas = getView();
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
- canvas->setSource(testFileUrl("gridview1.qml"));
+ ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+ ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+ ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+ canvas->setSource(testFileUrl("layouts.qml"));
canvas->show();
qApp->processEvents();
@@ -396,8 +507,12 @@ void tst_QQuickGridView::inserted_more()
QQuickItem *contentItem = gridview->contentItem();
QTRY_VERIFY(contentItem != 0);
- gridview->setContentY(contentY);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+ if (flow == QQuickGridView::FlowTopToBottom) {
+ insertIndex = insertIndex_ttb;
+ insertCount = insertCount_ttb;
+ }
+ if (setContentPos(gridview, contentYRowOffset))
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
QList<QPair<QString, QString> > newData;
for (int i=0; i<insertCount; i++)
@@ -408,137 +523,152 @@ void tst_QQuickGridView::inserted_more()
// check visibleItems.first() is in correct position
QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
QVERIFY(item0);
- QCOMPARE(item0->y(), 0.0);
+ QPointF firstPos(0, 0);
+ if (horizLayout == Qt::RightToLeft)
+ firstPos.rx() = flow == QQuickGridView::FlowLeftToRight ? gridview->width() - gridview->cellWidth() : -gridview->cellWidth();
+ if (verticalLayout == QQuickItemView::BottomToTop)
+ firstPos.ry() -= gridview->cellHeight();
+ QCOMPARE(item0->pos(), firstPos);
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
- QQmlExpression e(qmlContext(items[i]), items[i], "index");
- firstVisibleIndex = e.evaluate().toInt();
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (item && item->isVisible()) {
+ firstVisibleIndex = i;
break;
}
}
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// Confirm items positioned correctly and indexes correct
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- QQuickText *name;
- QQuickText *number;
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-
- QCOMPARE(item->x(), (i%3)*80.0);
- QCOMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
-
- name = findItem<QQuickText>(contentItem, "textName", i);
+ QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+ QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QCOMPARE(name->text(), model.name(i));
- number = findItem<QQuickText>(contentItem, "textNumber", i);
- QVERIFY(number != 0);
- QCOMPARE(number->text(), model.number(i));
}
releaseView(canvas);
}
-void tst_QQuickGridView::inserted_more_data()
+void tst_QQuickGridView::inserted_defaultLayout_data()
{
- QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<qreal>("contentYRowOffset");
QTest::addColumn<int>("insertIndex");
QTest::addColumn<int>("insertCount");
- QTest::addColumn<qreal>("itemsOffsetAfterMove");
+ QTest::addColumn<int>("insertIndex_ttb");
+ QTest::addColumn<int>("insertCount_ttb");
+ QTest::addColumn<qreal>("rowOffsetAfterMove");
QTest::newRow("add 1, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 5 << 1
+ << 9 << 1
<< 0.0; // insert 1 above first visible, grid is rearranged; first visible moves forward within its row
// new 1st visible item is at 0
QTest::newRow("add 2, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 5 << 2
+ << 9 << 2
<< 0.0; // insert 2 above first visible, grid is rearranged; first visible moves forward within its row
QTest::newRow("add 3, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 5 << 3
- << -60.0; // insert 3 (1 row) above first visible in negative pos, first visible does not move
+ << 9 << 5
+ << -1.0; // insert 3 (1 row) above first visible in negative pos, first visible does not move
QTest::newRow("add 5, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 5 << 5
- << -60.0; // insert 1 row + 2 items above first visible, 1 row added at negative pos,
+ << 9 << 7
+ << -1.0; // insert 1 row + 2 items above first visible, 1 row added at negative pos,
// grid is rearranged and first visible moves forward within its row
QTest::newRow("add 6, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 5 << 6
- << -60.0 * 2; // insert 2 rows above first visible in negative pos, first visible does not move
+ << 9 << 10
+ << -1.0 * 2; // insert 2 rows above first visible in negative pos, first visible does not move
QTest::newRow("add 1, at start of visible, content at start")
<< 0.0
<< 0 << 1
+ << 0 << 1
<< 0.0;
QTest::newRow("add multiple, at start of visible, content at start")
<< 0.0
<< 0 << 3
+ << 0 << 5
<< 0.0;
QTest::newRow("add 1, at start of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 6 << 1
+ << 10 << 1
<< 0.0;
QTest::newRow("add multiple, at start of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 6 << 3
+ << 10 << 5
<< 0.0;
QTest::newRow("add 1, at end of visible, content at start")
<< 0.0
<< 17 << 1
+ << 14 << 1
<< 0.0;
- QTest::newRow("add 1, at end of visible, content at start")
+ QTest::newRow("add row, at end of visible, content at start")
<< 0.0
<< 17 << 3
+ << 14 << 5
<< 0.0;
QTest::newRow("add 1, at end of visible, content not at start")
- << 120.0 // show 6-23
- << 23 << 1
+ << 2.0 // show 6-23
+ << 17+6 << 1
+ << 14+10 << 1
<< 0.0;
QTest::newRow("add multiple, at end of visible, content not at start")
- << 120.0 // show 6-23
- << 23 << 3
+ << 2.0 // show 6-23
+ << 17+6 << 3
+ << 14+10 << 5
<< 0.0;
QTest::newRow("add 1, after visible, content at start")
<< 0.0
<< 20 << 1
+ << 18 << 1
<< 0.0;
- QTest::newRow("add 1, after visible, content at start")
+ QTest::newRow("add row, after visible, content at start")
<< 0.0
<< 20 << 3
+ << 18 << 5
<< 0.0;
QTest::newRow("add 1, after visible, content not at start")
- << 120.0 // show 6-23
- << 24 << 1
+ << 2.0 // show 6-23
+ << 20+6 << 1
+ << 18+10 << 1
<< 0.0;
QTest::newRow("add multiple, after visible, content not at start")
- << 120.0 // show 6-23
- << 24 << 3
+ << 2.0 // show 6-23
+ << 20+6 << 3
+ << 18+10 << 3
<< 0.0;
}
@@ -557,8 +687,6 @@ void tst_QQuickGridView::insertBeforeVisible()
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
@@ -633,7 +761,7 @@ void tst_QQuickGridView::insertBeforeVisible_data()
QTest::newRow("insert multiple at 1, 500 buffer") << 1 << 6 << 500;
}
-void tst_QQuickGridView::removed()
+void tst_QQuickGridView::removed_basic()
{
QQuickView *canvas = createView();
canvas->show();
@@ -642,11 +770,7 @@ void tst_QQuickGridView::removed()
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -778,16 +902,19 @@ void tst_QQuickGridView::removed()
delete canvas;
}
-void tst_QQuickGridView::removed_more()
+void tst_QQuickGridView::removed_defaultLayout(QQuickGridView::Flow flow,
+ Qt::LayoutDirection horizLayout,
+ QQuickItemView::VerticalLayoutDirection verticalLayout)
{
- QFETCH(qreal, contentY);
+ QFETCH(qreal, contentYRowOffset);
QFETCH(int, removeIndex);
QFETCH(int, removeCount);
- QFETCH(qreal, itemsOffsetAfterMove);
+ QFETCH(int, removeIndex_ttb);
+ QFETCH(int, removeCount_ttb);
+ QFETCH(qreal, rowOffsetAfterMove);
QFETCH(QString, firstVisible);
+ QFETCH(QString, firstVisible_ttb);
- QQuickText *name;
- QQuickText *number;
QQuickView *canvas = getView();
QaimModel model;
@@ -796,9 +923,10 @@ void tst_QQuickGridView::removed_more()
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
- canvas->setSource(testFileUrl("gridview1.qml"));
+ ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+ ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+ ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+ canvas->setSource(testFileUrl("layouts.qml"));
canvas->show();
qApp->processEvents();
@@ -807,8 +935,13 @@ void tst_QQuickGridView::removed_more()
QQuickItem *contentItem = gridview->contentItem();
QTRY_VERIFY(contentItem != 0);
- gridview->setContentY(contentY);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+ if (flow == QQuickGridView::FlowTopToBottom) {
+ removeIndex = removeIndex_ttb;
+ removeCount = removeCount_ttb;
+ firstVisible = firstVisible_ttb;
+ }
+ if (setContentPos(gridview, contentYRowOffset))
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
model.removeItems(removeIndex, removeCount);
QTRY_COMPARE(gridview->property("count").toInt(), model.count());
@@ -816,161 +949,183 @@ void tst_QQuickGridView::removed_more()
QString firstName;
int firstVisibleIndex = -1;
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+ QRectF viewRect(gridview->contentX(), gridview->contentY(), gridview->width(), gridview->height());
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
- QQmlExpression e(qmlContext(items[i]), items[i], "index");
- firstVisibleIndex = e.evaluate().toInt();
- QQmlExpression en(qmlContext(items[i]), items[i], "name");
- firstName = en.evaluate().toString();
- break;
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (item) {
+ QRectF itemRect(item->x(), item->y(), item->width(), item->height());
+ if (item->isVisible() && viewRect.intersects(itemRect)) {
+ firstVisibleIndex = i;
+ QQmlExpression en(qmlContext(item), item, "name");
+ firstName = en.evaluate().toString();
+ break;
+ }
}
}
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
QCOMPARE(firstName, firstVisible);
// Confirm items positioned correctly and indexes correct
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-
- QTRY_COMPARE(item->x(), (i%3)*80.0);
- QTRY_COMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
-
- name = findItem<QQuickText>(contentItem, "textName", i);
+ QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+ QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
- number = findItem<QQuickText>(contentItem, "textNumber", i);
- QVERIFY(number != 0);
- QTRY_COMPARE(number->text(), model.number(i));
}
releaseView(canvas);
}
-void tst_QQuickGridView::removed_more_data()
+void tst_QQuickGridView::removed_defaultLayout_data()
{
- QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<qreal>("contentYRowOffset");
QTest::addColumn<int>("removeIndex");
QTest::addColumn<int>("removeCount");
- QTest::addColumn<qreal>("itemsOffsetAfterMove");
+ QTest::addColumn<int>("removeIndex_ttb");
+ QTest::addColumn<int>("removeCount_ttb");
+ QTest::addColumn<qreal>("rowOffsetAfterMove");
QTest::addColumn<QString>("firstVisible");
+ QTest::addColumn<QString>("firstVisible_ttb");
QTest::newRow("remove 1, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 2 << 1
- << 0.0 << "Item7";
+ << 4 << 1
+ << 0.0 << "Item7" << "Item11";
QTest::newRow("remove 1, before visible position")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 3 << 1
- << 0.0 << "Item7";
+ << 5 << 1
+ << 0.0 << "Item7" << "Item11";
- QTest::newRow("remove multiple, all before visible items")
- << 120.0
+ QTest::newRow("remove multiple (1 row), all before visible items")
+ << 2.0
<< 1 << 3
- << 60.0 << "Item6"; // removed top row, slide down by 1 row
+ << 1 << 5
+ << 1.0 << "Item6" << "Item10"; // removed top row, slide down by 1 row
QTest::newRow("remove multiple, all before visible items, remove item 0")
- << 120.0
+ << 2.0
<< 0 << 4
- << 60.0 << "Item7"; // removed top row, slide down by 1 row
+ << 0 << 6
+ << 1.0 << "Item7" << "Item11"; // removed top row, slide down by 1 row
QTest::newRow("remove multiple rows, all before visible items")
- << 240.0 // show 12-29
+ << 4.0 // show 12-29
<< 1 << 7
- << 120.0 << "Item13";
+ << 1 << 12
+ << 2.0 << "Item13" << "Item17";
QTest::newRow("remove one row before visible, content y not on item border")
- << 100.0
+ << 1.5
<< 0 << 3
- << 60.0 << "Item6"; // 1 row removed
+ << 0 << 5
+ << 1.0 << "Item3" << "Item5"; // 1 row removed
QTest::newRow("remove mix of visible/non-visible")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 2 << 3
- << 60.0 << "Item6"; // 1 row removed
+ << 4 << 3
+ << 1.0 << "Item6" << "Item8"; // 1 row removed
// remove 3,4,5 before the visible pos, first row moves down to just before the visible pos,
// items 6,7 are removed from view, item 8 slides up to original pos of item 6 (120px)
QTest::newRow("remove multiple, mix of items from before and within visible items")
- << 120.0
+ << 2.0
<< 3 << 5
- << 60.0 << "Item8"; // adjust for the 1 row removed before the visible
+ << 5 << 7
+ << 1.0 << "Item8" << "Item12"; // adjust for the 1 row removed before the visible
QTest::newRow("remove multiple, mix of items from before and within visible items, remove item 0")
- << 120.0
+ << 2.0
<< 0 << 8
- << 60.0 * 2 << "Item8"; // adjust for the 2 rows removed before the visible
+ << 0 << 12
+ << 1.0 * 2 << "Item8" << "Item12"; // adjust for the 2 rows removed before the visible
QTest::newRow("remove 1, from start of visible, content at start")
<< 0.0
<< 0 << 1
- << 0.0 << "Item1";
+ << 0 << 1
+ << 0.0 << "Item1" << "Item1";
QTest::newRow("remove multiple, from start of visible, content at start")
<< 0.0
<< 0 << 3
- << 0.0 << "Item3";
+ << 0 << 5
+ << 0.0 << "Item3" << "Item5";
QTest::newRow("remove 1, from start of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 4 << 1
- << 0.0 << "Item7";
+ << 7 << 1
+ << 0.0 << "Item7" << "Item11";
QTest::newRow("remove multiple, from start of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 4 << 3
- << 0.0 << "Item9";
+ << 7 << 5
+ << 0.0 << "Item9" << "Item15";
QTest::newRow("remove 1, from middle of visible, content at start")
<< 0.0
<< 10 << 1
- << 0.0 << "Item0";
+ << 12 << 1
+ << 0.0 << "Item0" << "Item0";
QTest::newRow("remove multiple, from middle of visible, content at start")
<< 0.0
<< 10 << 5
- << 0.0 << "Item0";
+ << 12 << 5
+ << 0.0 << "Item0" << "Item0";
QTest::newRow("remove 1, from middle of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 10 << 1
- << 0.0 << "Item6";
+ << 12 << 1
+ << 0.0 << "Item6" << "Item10";
QTest::newRow("remove multiple, from middle of visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 10 << 5
- << 0.0 << "Item6";
+ << 12 << 7
+ << 0.0 << "Item6" << "Item10";
QTest::newRow("remove 1, after visible, content at start")
<< 0.0
<< 16 << 1
- << 0.0 << "Item0";
+ << 15 << 1
+ << 0.0 << "Item0" << "Item0";
QTest::newRow("remove multiple, after visible, content at start")
<< 0.0
<< 16 << 5
- << 0.0 << "Item0";
+ << 15 << 7
+ << 0.0 << "Item0" << "Item0";
QTest::newRow("remove 1, after visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 16+4 << 1
- << 0.0 << "Item6";
+ << 15+10 << 1
+ << 0.0 << "Item6" << "Item10";
QTest::newRow("remove multiple, after visible, content not at start")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 16+4 << 5
- << 0.0 << "Item6";
+ << 15+10 << 7
+ << 0.0 << "Item6" << "Item10";
QTest::newRow("remove multiple, mix of items from within and after visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 20 << 5
- << 0.0 << "Item6";
+ << 22 << 7
+ << 0.0 << "Item6" << "Item10";
}
void tst_QQuickGridView::addOrRemoveBeforeVisible()
@@ -988,10 +1143,7 @@ void tst_QQuickGridView::addOrRemoveBeforeVisible()
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
@@ -1067,11 +1219,7 @@ void tst_QQuickGridView::clear()
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
@@ -1098,28 +1246,31 @@ void tst_QQuickGridView::clear()
delete canvas;
}
-void tst_QQuickGridView::moved()
+void tst_QQuickGridView::moved_defaultLayout(QQuickGridView::Flow flow,
+ Qt::LayoutDirection horizLayout,
+ QQuickItemView::VerticalLayoutDirection verticalLayout)
{
- QFETCH(qreal, contentY);
+ QFETCH(qreal, contentYRowOffset);
QFETCH(int, from);
QFETCH(int, to);
QFETCH(int, count);
- QFETCH(qreal, itemsOffsetAfterMove);
+ QFETCH(int, from_ttb);
+ QFETCH(int, to_ttb);
+ QFETCH(int, count_ttb);
+ QFETCH(qreal, rowOffsetAfterMove);
- QQuickText *name;
- QQuickText *number;
QQuickView *canvas = getView();
QaimModel model;
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
+ QDeclarativeContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
- canvas->setSource(testFileUrl("gridview1.qml"));
+ ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+ ctxt->setContextProperty("testRightToLeft", horizLayout == Qt::RightToLeft);
+ ctxt->setContextProperty("testBottomToTop", verticalLayout == QQuickGridView::BottomToTop);
+ canvas->setSource(testFileUrl("layouts.qml"));
canvas->show();
qApp->processEvents();
@@ -1132,32 +1283,41 @@ void tst_QQuickGridView::moved()
QQuickItem *currentItem = gridview->currentItem();
QTRY_VERIFY(currentItem != 0);
- if (contentY != 0) {
- gridview->setContentY(contentY);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+ if (flow == QQuickGridView::FlowTopToBottom) {
+ from = from_ttb;
+ to = to_ttb;
+ count = count_ttb;
}
+ if (setContentPos(gridview, contentYRowOffset))
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
model.moveItems(from, to, count);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
// Confirm items positioned correctly and indexes correct
- int firstVisibleIndex = qCeil(contentY / 60.0) * 3;
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
- if (i >= firstVisibleIndex + 18) // index has moved out of view
- continue;
+ QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+ int firstVisibleIndex = -1;
+ for (int i=0; i<items.count(); i++) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
- QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
-
- QTRY_COMPARE(item->x(), (i%3)*80.0);
- QTRY_COMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
+ if (item && item->isVisible()) {
+ firstVisibleIndex = i;
+ break;
+ }
+ }
+ QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
- name = findItem<QQuickText>(contentItem, "textName", i);
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (!item &&
+ ( (flow == QQuickGridView::FlowLeftToRight && i >= firstVisibleIndex + (3*6))
+ || flow == QQuickGridView::FlowTopToBottom && i >= firstVisibleIndex + (5*3) ) ) {
+ continue; // index has moved out of view
+ }
+ QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+ QCOMPARE(item->pos(), expectedItemPos(gridview, i, rowOffsetAfterMove));
+ QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
- number = findItem<QQuickText>(contentItem, "textNumber", i);
- QVERIFY(number != 0);
- QTRY_COMPARE(number->text(), model.number(i));
// current index should have been updated
if (item == currentItem)
@@ -1167,13 +1327,16 @@ void tst_QQuickGridView::moved()
releaseView(canvas);
}
-void tst_QQuickGridView::moved_data()
+void tst_QQuickGridView::moved_defaultLayout_data()
{
- QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<qreal>("contentYRowOffset");
QTest::addColumn<int>("from");
QTest::addColumn<int>("to");
QTest::addColumn<int>("count");
- QTest::addColumn<qreal>("itemsOffsetAfterMove");
+ QTest::addColumn<int>("from_ttb");
+ QTest::addColumn<int>("to_ttb");
+ QTest::addColumn<int>("count_ttb");
+ QTest::addColumn<qreal>("rowOffsetAfterMove");
// model starts with 30 items, each 80x60, in area 240x320
// 18 items should be visible at a time
@@ -1185,143 +1348,170 @@ void tst_QQuickGridView::moved_data()
QTest::newRow("move 1 forwards, within visible items")
<< 0.0
<< 1 << 8 << 1
+ << 2 << 12 << 1
<< 0.0;
QTest::newRow("move 1 forwards, from non-visible -> visible")
- << 120.0 // show 6-23
- << 1 << 23 << 1
+ << 2.0 // show 6-23
+ << 1 << 8+6 << 1
+ << 2 << 12+10 << 1
<< 0.0;
QTest::newRow("move 1 forwards, from non-visible -> visible (move first item)")
- << 120.0 // // show 6-23
+ << 2.0 // // show 6-23
<< 0 << 6 << 1
+ << 0 << 10 << 1
<< 0.0;
QTest::newRow("move 1 forwards, from visible -> non-visible")
<< 0.0
<< 1 << 20 << 1
+ << 1 << 20 << 1
<< 0.0;
QTest::newRow("move 1 forwards, from visible -> non-visible (move first item)")
<< 0.0
<< 0 << 20 << 1
+ << 0 << 20 << 1
<< 0.0;
QTest::newRow("move 1 backwards, within visible items")
<< 0.0
<< 10 << 5 << 1
+ << 10 << 5 << 1
<< 0.0;
QTest::newRow("move 1 backwards, within visible items (to first index)")
<< 0.0
<< 10 << 0 << 1
+ << 10 << 0 << 1
<< 0.0;
QTest::newRow("move 1 backwards, from non-visible -> visible")
<< 0.0
<< 28 << 8 << 1
+ << 28 << 8 << 1
<< 0.0;
QTest::newRow("move 1 backwards, from non-visible -> visible (move last item)")
<< 0.0
<< 29 << 14 << 1
+ << 29 << 14 << 1
<< 0.0;
QTest::newRow("move 1 backwards, from visible -> non-visible")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 7 << 1 << 1
+ << 10 << 1 << 1
<< 0.0; // only 1 item moved back, so items shift accordingly and first row doesn't move
QTest::newRow("move 1 backwards, from visible -> non-visible (move first item)")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 7 << 0 << 1
+ << 10 << 0 << 1
<< 0.0; // only 1 item moved back, so items shift accordingly and first row doesn't move
QTest::newRow("move multiple forwards, within visible items")
<< 0.0
<< 0 << 5 << 3
+ << 0 << 7 << 5
<< 0.0;
QTest::newRow("move multiple backwards, within visible items (move first item)")
<< 0.0
<< 10 << 0 << 3
+ << 12 << 0 << 5
<< 0.0;
QTest::newRow("move multiple forwards, before visible items")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 3 << 4 << 3 // 3, 4, 5 move to after 6
- << 60.0; // row of 3,4,5 has moved down
+ << 5 << 6 << 5
+ << 1.0; // row of 3,4,5 has moved down
QTest::newRow("move multiple forwards, from non-visible -> visible")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 1 << 6 << 3
- << 60.0; // 1st row (it's above visible area) disappears, 0 drops down 1 row, first visible item (6) stays where it is
+ << 1 << 10 << 5
+ << 1.0; // 1st row (it's above visible area) disappears, 0 drops down 1 row, first visible item (6) stays where it is
QTest::newRow("move multiple forwards, from non-visible -> visible (move first item)")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 0 << 6 << 3
- << 60.0; // top row moved and shifted to below 3rd row, all items should shift down by 1 row
+ << 0 << 10 << 5
+ << 1.0; // top row moved and shifted to below 3rd row, all items should shift down by 1 row
QTest::newRow("move multiple forwards, mix of non-visible/visible")
- << 120.0
+ << 2.0
<< 3 << 16 << 6
- << 60.0; // top two rows removed, third row is now the first visible
+ << 5 << 18 << 10
+ << 1.0; // top two rows removed, third row is now the first visible
QTest::newRow("move multiple forwards, to bottom of view")
<< 0.0
<< 5 << 13 << 5
+ << 1 << 8 << 6
<< 0.0;
QTest::newRow("move multiple forwards, to bottom of view, first row -> last")
<< 0.0
<< 0 << 15 << 3
+ << 0 << 10 << 5
<< 0.0;
QTest::newRow("move multiple forwards, to bottom of view, content y not 0")
- << 120.0
+ << 2.0
<< 5+4 << 13+4 << 5
+ << 11 << 19 << 6
<< 0.0;
QTest::newRow("move multiple forwards, from visible -> non-visible")
<< 0.0
<< 1 << 16 << 3
+ << 1 << 18 << 5
<< 0.0;
QTest::newRow("move multiple forwards, from visible -> non-visible (move first item)")
<< 0.0
<< 0 << 16 << 3
+ << 1 << 18 << 5
<< 0.0;
QTest::newRow("move multiple backwards, within visible items")
<< 0.0
<< 4 << 1 << 3
+ << 7 << 1 << 5
<< 0.0;
QTest::newRow("move multiple backwards, from non-visible -> visible")
<< 0.0
<< 20 << 4 << 3
+ << 20 << 4 << 5
<< 0.0;
QTest::newRow("move multiple backwards, from non-visible -> visible (move last item)")
<< 0.0
<< 27 << 10 << 3
+ << 25 << 8 << 5
<< 0.0;
QTest::newRow("move multiple backwards, from visible -> non-visible")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 16 << 1 << 3
- << -60.0; // to minimize movement, items are added above visible area, all items move up by 1 row
+ << 17 << 1 << 5
+ << -1.0; // to minimize movement, items are added above visible area, all items move up by 1 row
QTest::newRow("move multiple backwards, from visible -> non-visible (move first item)")
- << 120.0 // show 6-23
+ << 2.0 // show 6-23
<< 16 << 0 << 3
- << -60.0; // 16,17,18 move to above item 0, all items move up by 1 row
+ << 17 << 0 << 5
+ << -1.0; // 16,17,18 move to above item 0, all items move up by 1 row
}
-void tst_QQuickGridView::multipleChanges()
+void tst_QQuickGridView::multipleChanges(bool condensed)
{
QFETCH(int, startCount);
QFETCH(QList<ListChange>, changes);
@@ -1334,11 +1524,7 @@ void tst_QQuickGridView::multipleChanges()
for (int i = 0; i < startCount; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
@@ -1359,26 +1545,26 @@ void tst_QQuickGridView::multipleChanges()
}
case ListChange::Removed:
model.removeItems(changes[i].index, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::Moved:
model.moveItems(changes[i].index, changes[i].to, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::SetCurrent:
gridview->setCurrentIndex(changes[i].index);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
case ListChange::SetContentY:
gridview->setContentY(changes[i].pos);
- QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
break;
}
+ if (condensed) {
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+ }
}
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- QTRY_COMPARE(gridview->count(), newCount);
+ QCOMPARE(gridview->count(), newCount);
QCOMPARE(gridview->count(), model.count());
- QTRY_COMPARE(gridview->currentIndex(), newCurrentIndex);
+ QCOMPARE(gridview->currentIndex(), newCurrentIndex);
QQuickText *name;
QQuickText *number;
@@ -1547,6 +1733,28 @@ void tst_QQuickGridView::multipleChanges_data()
<< ListChange::remove(0, 5)
<< ListChange::insert(0, 5)
) << 5 << -1;
+
+ QTest::newRow("remove, scroll") << 30 << (QList<ListChange>()
+ << ListChange::remove(20, 5)
+ << ListChange::setContentY(20)
+ ) << 25 << 0;
+
+ QTest::newRow("insert, scroll") << 10 << (QList<ListChange>()
+ << ListChange::insert(9, 5)
+ << ListChange::setContentY(20)
+ ) << 15 << 0;
+
+ QTest::newRow("move, scroll") << 20 << (QList<ListChange>()
+ << ListChange::move(15, 8, 3)
+ << ListChange::setContentY(0)
+ ) << 20 << 0;
+
+ QTest::newRow("clear, insert, scroll") << 30 << (QList<ListChange>()
+ << ListChange::setContentY(20)
+ << ListChange::remove(0, 30)
+ << ListChange::insert(0, 2)
+ << ListChange::setContentY(0)
+ ) << 2 << 0;
}
@@ -1559,11 +1767,7 @@ void tst_QQuickGridView::swapWithFirstItem()
for (int i = 0; i < 30; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
@@ -1610,57 +1814,11 @@ void tst_QQuickGridView::currentIndex()
QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y());
QCOMPARE(gridview->contentY(), 400.0);
- gridview->moveCurrentIndexRight();
- QCOMPARE(gridview->currentIndex(), 36);
- gridview->moveCurrentIndexDown();
- QCOMPARE(gridview->currentIndex(), 39);
- gridview->moveCurrentIndexUp();
- QCOMPARE(gridview->currentIndex(), 36);
- gridview->moveCurrentIndexLeft();
- QCOMPARE(gridview->currentIndex(), 35);
-
- // wait until motion stops
- QTRY_VERIFY(gridview->verticalVelocity() == 0.0);
-
- // no wrap
gridview->setCurrentIndex(0);
QCOMPARE(gridview->currentIndex(), 0);
// confirm that the velocity is updated
QTRY_VERIFY(gridview->verticalVelocity() != 0.0);
- gridview->moveCurrentIndexUp();
- QCOMPARE(gridview->currentIndex(), 0);
-
- gridview->moveCurrentIndexLeft();
- QCOMPARE(gridview->currentIndex(), 0);
-
- gridview->setCurrentIndex(model.count()-1);
- QCOMPARE(gridview->currentIndex(), model.count()-1);
-
- gridview->moveCurrentIndexRight();
- QCOMPARE(gridview->currentIndex(), model.count()-1);
-
- gridview->moveCurrentIndexDown();
- QCOMPARE(gridview->currentIndex(), model.count()-1);
-
- // with wrap
- gridview->setWrapEnabled(true);
-
- gridview->setCurrentIndex(0);
- QCOMPARE(gridview->currentIndex(), 0);
-
- gridview->moveCurrentIndexLeft();
- QCOMPARE(gridview->currentIndex(), model.count()-1);
-
- qApp->processEvents();
- QTRY_COMPARE(gridview->contentY(), 880.0);
-
- gridview->moveCurrentIndexRight();
- QCOMPARE(gridview->currentIndex(), 0);
-
- QTRY_COMPARE(gridview->contentY(), 0.0);
-
-
// footer should become visible if it is out of view, and then current index moves to the first row
canvas->rootObject()->setProperty("showFooter", true);
QTRY_VERIFY(gridview->footerItem());
@@ -1679,78 +1837,6 @@ void tst_QQuickGridView::currentIndex()
QTRY_COMPARE(gridview->contentY(), -gridview->headerItem()->height());
canvas->rootObject()->setProperty("showHeader", false);
-
- // Test keys
- canvas->requestActivateWindow();
- QTest::qWaitForWindowShown(canvas);
- QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
-
- gridview->setCurrentIndex(0);
-
- QTest::keyClick(canvas, Qt::Key_Down);
- QCOMPARE(gridview->currentIndex(), 3);
-
- QTest::keyClick(canvas, Qt::Key_Up);
- QCOMPARE(gridview->currentIndex(), 0);
-
- // hold down Key_Down
- for (int i=0; i<(model.count() / 3) - 1; i++) {
- QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
- QTRY_COMPARE(gridview->currentIndex(), i*3 + 3);
- }
- QTest::keyRelease(canvas, Qt::Key_Down);
- QTRY_COMPARE(gridview->currentIndex(), 57);
- QTRY_COMPARE(gridview->contentY(), 880.0);
-
- // hold down Key_Up
- for (int i=(model.count() / 3) - 1; i > 0; i--) {
- QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
- QTRY_COMPARE(gridview->currentIndex(), i*3 - 3);
- }
- QTest::keyRelease(canvas, Qt::Key_Up);
- QTRY_COMPARE(gridview->currentIndex(), 0);
- QTRY_COMPARE(gridview->contentY(), 0.0);
-
-
- gridview->setFlow(QQuickGridView::TopToBottom);
-
- canvas->requestActivateWindow();
- QTest::qWaitForWindowShown(canvas);
- QVERIFY(qGuiApp->focusWindow() == canvas);
- qApp->processEvents();
-
- QTest::keyClick(canvas, Qt::Key_Right);
- QCOMPARE(gridview->currentIndex(), 5);
-
- QTest::keyClick(canvas, Qt::Key_Left);
- QCOMPARE(gridview->currentIndex(), 0);
-
- QTest::keyClick(canvas, Qt::Key_Down);
- QCOMPARE(gridview->currentIndex(), 1);
-
- QTest::keyClick(canvas, Qt::Key_Up);
- QCOMPARE(gridview->currentIndex(), 0);
-
- // hold down Key_Right
- for (int i=0; i<(model.count() / 5) - 1; i++) {
- QTest::simulateEvent(canvas, true, Qt::Key_Right, Qt::NoModifier, "", true);
- QTRY_COMPARE(gridview->currentIndex(), i*5 + 5);
- }
-
- QTest::keyRelease(canvas, Qt::Key_Right);
- QTRY_COMPARE(gridview->currentIndex(), 55);
- QTRY_COMPARE(gridview->contentX(), 720.0);
-
- // hold down Key_Left
- for (int i=(model.count() / 5) - 1; i > 0; i--) {
- QTest::simulateEvent(canvas, true, Qt::Key_Left, Qt::NoModifier, "", true);
- QTRY_COMPARE(gridview->currentIndex(), i*5 - 5);
- }
- QTest::keyRelease(canvas, Qt::Key_Left);
- QTRY_COMPARE(gridview->currentIndex(), 0);
- QTRY_COMPARE(gridview->contentX(), 0.0);
-
-
// turn off auto highlight
gridview->setHighlightFollowsCurrentItem(false);
QVERIFY(gridview->highlightFollowsCurrentItem() == false);
@@ -1774,54 +1860,6 @@ void tst_QQuickGridView::currentIndex()
QVERIFY(!gridview->highlightItem());
QVERIFY(!gridview->currentItem());
- gridview->setHighlightFollowsCurrentItem(true);
-
- gridview->setFlow(QQuickGridView::LeftToRight);
- gridview->setLayoutDirection(Qt::RightToLeft);
-
- canvas->requestActivateWindow();
- QTest::qWaitForWindowShown(canvas);
- QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
- qApp->processEvents();
-
- gridview->setCurrentIndex(35);
-
- QTest::keyClick(canvas, Qt::Key_Right);
- QCOMPARE(gridview->currentIndex(), 34);
-
- QTest::keyClick(canvas, Qt::Key_Down);
- QCOMPARE(gridview->currentIndex(), 37);
-
- QTest::keyClick(canvas, Qt::Key_Up);
- QCOMPARE(gridview->currentIndex(), 34);
-
- QTest::keyClick(canvas, Qt::Key_Left);
- QCOMPARE(gridview->currentIndex(), 35);
-
-
- // turn off auto highlight
- gridview->setHighlightFollowsCurrentItem(false);
- QVERIFY(gridview->highlightFollowsCurrentItem() == false);
- QVERIFY(gridview->highlightItem());
- hlPosX = gridview->highlightItem()->x();
- hlPosY = gridview->highlightItem()->y();
-
- gridview->setCurrentIndex(5);
- QTRY_COMPARE(gridview->highlightItem()->x(), hlPosX);
- QTRY_COMPARE(gridview->highlightItem()->y(), hlPosY);
-
- // insert item before currentIndex
- gridview->setCurrentIndex(28);
- model.insertItem(0, "Foo", "1111");
- QTRY_COMPARE(canvas->rootObject()->property("current").toInt(), 29);
-
- // check removing highlight by setting currentIndex to -1;
- gridview->setCurrentIndex(-1);
-
- QCOMPARE(gridview->currentIndex(), -1);
- QVERIFY(!gridview->highlightItem());
- QVERIFY(!gridview->currentItem());
-
// moving currentItem out of view should make it invisible
gridview->setCurrentIndex(0);
QTRY_VERIFY(gridview->currentItem()->isVisible());
@@ -1868,6 +1906,199 @@ void tst_QQuickGridView::noCurrentIndex()
delete canvas;
}
+void tst_QQuickGridView::keyNavigation()
+{
+ QFETCH(QQuickGridView::Flow, flow);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+ QFETCH(Qt::Key, forwardsKey);
+ QFETCH(Qt::Key, backwardsKey);
+ QFETCH(QPointF, contentPosAtFirstItem);
+ QFETCH(QPointF, contentPosAtLastItem);
+ QFETCH(int, indexRightOf7);
+ QFETCH(int, indexLeftOf7);
+ QFETCH(int, indexUpFrom7);
+ QFETCH(int, indexDownFrom7);
+
+ QmlListModel model;
+ for (int i = 0; i < 18; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QQuickView *canvas = getView();
+ canvas->rootContext()->setContextProperty("testModel", &model);
+ canvas->setSource(testFileUrl("gridview1.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+ QTRY_VERIFY(gridview != 0);
+ gridview->setFlow(flow);
+ gridview->setLayoutDirection(layoutDirection);
+ gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+ canvas->requestActivateWindow();
+ QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
+ QCOMPARE(gridview->currentIndex(), 0);
+
+ QTest::keyClick(canvas, forwardsKey);
+ QCOMPARE(gridview->currentIndex(), 1);
+
+ QTest::keyClick(canvas, backwardsKey);
+ QCOMPARE(gridview->currentIndex(), 0);
+
+ gridview->setCurrentIndex(7);
+ gridview->moveCurrentIndexRight();
+ QCOMPARE(gridview->currentIndex(), indexRightOf7);
+ gridview->moveCurrentIndexLeft();
+ QCOMPARE(gridview->currentIndex(), 7);
+ gridview->moveCurrentIndexLeft();
+ QCOMPARE(gridview->currentIndex(), indexLeftOf7);
+ gridview->moveCurrentIndexRight();
+ QCOMPARE(gridview->currentIndex(), 7);
+ gridview->moveCurrentIndexUp();
+ QCOMPARE(gridview->currentIndex(), indexUpFrom7);
+ gridview->moveCurrentIndexDown();
+ QCOMPARE(gridview->currentIndex(), 7);
+ gridview->moveCurrentIndexDown();
+ QCOMPARE(gridview->currentIndex(), indexDownFrom7);
+
+ gridview->setCurrentIndex(7);
+ QTest::keyClick(canvas, Qt::Key_Right);
+ QCOMPARE(gridview->currentIndex(), indexRightOf7);
+ QTest::keyClick(canvas, Qt::Key_Left);
+ QCOMPARE(gridview->currentIndex(), 7);
+ QTest::keyClick(canvas, Qt::Key_Left);
+ QCOMPARE(gridview->currentIndex(), indexLeftOf7);
+ QTest::keyClick(canvas, Qt::Key_Right);
+ QCOMPARE(gridview->currentIndex(), 7);
+ QTest::keyClick(canvas, Qt::Key_Up);
+ QCOMPARE(gridview->currentIndex(), indexUpFrom7);
+ QTest::keyClick(canvas, Qt::Key_Down);
+ QCOMPARE(gridview->currentIndex(), 7);
+ QTest::keyClick(canvas, Qt::Key_Down);
+ QCOMPARE(gridview->currentIndex(), indexDownFrom7);
+
+ // hold down a key to go forwards
+ gridview->setCurrentIndex(0);
+ for (int i=0; i<model.count()-1; i++) {
+// QTest::qWait(500);
+ QTest::simulateEvent(canvas, true, forwardsKey, Qt::NoModifier, "", true);
+ QTRY_COMPARE(gridview->currentIndex(), i+1);
+ }
+ QTest::keyRelease(canvas, forwardsKey);
+ QTRY_COMPARE(gridview->currentIndex(), model.count()-1);
+ QTRY_COMPARE(gridview->contentX(), contentPosAtLastItem.x());
+ QTRY_COMPARE(gridview->contentY(), contentPosAtLastItem.y());
+
+ // hold down a key to go backwards
+ for (int i=model.count()-1; i > 0; i--) {
+ QTest::simulateEvent(canvas, true, backwardsKey, Qt::NoModifier, "", true);
+ QTRY_COMPARE(gridview->currentIndex(), i-1);
+ }
+ QTest::keyRelease(canvas, backwardsKey);
+ QTRY_COMPARE(gridview->currentIndex(), 0);
+ QTRY_COMPARE(gridview->contentX(), contentPosAtFirstItem.x());
+ QTRY_COMPARE(gridview->contentY(), contentPosAtFirstItem.y());
+
+ // no wrap
+ QVERIFY(!gridview->isWrapEnabled());
+ QTest::keyClick(canvas, forwardsKey);
+ QCOMPARE(gridview->currentIndex(), 1);
+ QTest::keyClick(canvas, backwardsKey);
+ QCOMPARE(gridview->currentIndex(), 0);
+
+ QTest::keyClick(canvas, backwardsKey);
+ QCOMPARE(gridview->currentIndex(), 0);
+
+ // with wrap
+ gridview->setWrapEnabled(true);
+ QVERIFY(gridview->isWrapEnabled());
+
+ QTest::keyClick(canvas, backwardsKey);
+ QCOMPARE(gridview->currentIndex(), model.count()-1);
+ QTRY_COMPARE(gridview->contentX(), contentPosAtLastItem.x());
+ QTRY_COMPARE(gridview->contentY(), contentPosAtLastItem.y());
+
+ QTest::keyClick(canvas, forwardsKey);
+ QCOMPARE(gridview->currentIndex(), 0);
+ QTRY_COMPARE(gridview->contentX(), contentPosAtFirstItem.x());
+ QTRY_COMPARE(gridview->contentY(), contentPosAtFirstItem.y());
+
+ releaseView(canvas);
+}
+
+void tst_QQuickGridView::keyNavigation_data()
+{
+ QTest::addColumn<QQuickGridView::Flow>("flow");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+ QTest::addColumn<Qt::Key>("forwardsKey");
+ QTest::addColumn<Qt::Key>("backwardsKey");
+ QTest::addColumn<QPointF>("contentPosAtFirstItem");
+ QTest::addColumn<QPointF>("contentPosAtLastItem");
+ QTest::addColumn<int>("indexRightOf7");
+ QTest::addColumn<int>("indexLeftOf7");
+ QTest::addColumn<int>("indexUpFrom7");
+ QTest::addColumn<int>("indexDownFrom7");
+
+ QTest::newRow("LeftToRight, LtR, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << Qt::Key_Right << Qt::Key_Left
+ << QPointF(0, 0)
+ << QPointF(0, 40)
+ << 8 << 6 << 4 << 10;
+
+ QTest::newRow("LeftToRight, RtL, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << Qt::Key_Left << Qt::Key_Right
+ << QPointF(0, 0)
+ << QPointF(0, 40)
+ << 6 << 8 << 4 << 10;
+
+ QTest::newRow("LeftToRight, LtR, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << Qt::Key_Right << Qt::Key_Left
+ << QPointF(0, -320)
+ << QPointF(0, -360)
+ << 8 << 6 << 10 << 4;
+
+ QTest::newRow("LeftToRight, RtL, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << Qt::Key_Left << Qt::Key_Right
+ << QPointF(0, -320)
+ << QPointF(0, -360)
+ << 6 << 8 << 10 << 4;
+
+ QTest::newRow("TopToBottom, LtR, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << Qt::Key_Down << Qt::Key_Up
+ << QPointF(0, 0)
+ << QPointF(80, 0)
+ << 12 << 2 << 6 << 8;
+
+ QTest::newRow("TopToBottom, RtL, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << Qt::Key_Down << Qt::Key_Up
+ << QPointF(-240, 0)
+ << QPointF(-320, 0)
+ << 2 << 12 << 6 << 8;
+
+ QTest::newRow("TopToBottom, LtR, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << Qt::Key_Up << Qt::Key_Down
+ << QPointF(0, -320)
+ << QPointF(80, -320)
+ << 12 << 2 << 8 << 6;
+
+ QTest::newRow("TopToBottom, RtL, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << Qt::Key_Up << Qt::Key_Down
+ << QPointF(-240, -320)
+ << QPointF(-320, -320)
+ << 2 << 12 << 8 << 6;
+}
+
void tst_QQuickGridView::changeFlow()
{
QQuickView *canvas = createView();
@@ -1880,8 +2111,9 @@ void tst_QQuickGridView::changeFlow()
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
+ ctxt->setContextProperty("testBottomToTop", QVariant(false));
- canvas->setSource(testFileUrl("gridview1.qml"));
+ canvas->setSource(testFileUrl("layouts.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
@@ -2027,15 +2259,15 @@ void tst_QQuickGridView::propertyChanges()
QTRY_COMPARE(gridView->isWrapEnabled(), true);
QTRY_COMPARE(gridView->cacheBuffer(), 10);
- QTRY_COMPARE(gridView->flow(), QQuickGridView::LeftToRight);
+ QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowLeftToRight);
gridView->setWrapEnabled(false);
gridView->setCacheBuffer(3);
- gridView->setFlow(QQuickGridView::TopToBottom);
+ gridView->setFlow(QQuickGridView::FlowTopToBottom);
QTRY_COMPARE(gridView->isWrapEnabled(), false);
QTRY_COMPARE(gridView->cacheBuffer(), 3);
- QTRY_COMPARE(gridView->flow(), QQuickGridView::TopToBottom);
+ QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom);
QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
QTRY_COMPARE(cacheBufferSpy.count(),1);
@@ -2043,14 +2275,14 @@ void tst_QQuickGridView::propertyChanges()
gridView->setWrapEnabled(false);
gridView->setCacheBuffer(3);
- gridView->setFlow(QQuickGridView::TopToBottom);
+ gridView->setFlow(QQuickGridView::FlowTopToBottom);
QTRY_COMPARE(keyNavigationWrapsSpy.count(),1);
QTRY_COMPARE(cacheBufferSpy.count(),1);
QTRY_COMPARE(flowSpy.count(),1);
- gridView->setFlow(QQuickGridView::LeftToRight);
- QTRY_COMPARE(gridView->flow(), QQuickGridView::LeftToRight);
+ gridView->setFlow(QQuickGridView::FlowLeftToRight);
+ QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowLeftToRight);
gridView->setWrapEnabled(true);
gridView->setCacheBuffer(5);
@@ -2074,11 +2306,11 @@ void tst_QQuickGridView::propertyChanges()
QTRY_COMPARE(layoutSpy.count(),1);
QTRY_COMPARE(flowSpy.count(),2);
- gridView->setFlow(QQuickGridView::TopToBottom);
- QTRY_COMPARE(gridView->flow(), QQuickGridView::TopToBottom);
+ gridView->setFlow(QQuickGridView::FlowTopToBottom);
+ QTRY_COMPARE(gridView->flow(), QQuickGridView::FlowTopToBottom);
QTRY_COMPARE(flowSpy.count(),3);
- gridView->setFlow(QQuickGridView::TopToBottom);
+ gridView->setFlow(QQuickGridView::FlowTopToBottom);
QTRY_COMPARE(flowSpy.count(),3);
delete canvas;
@@ -2179,8 +2411,9 @@ void tst_QQuickGridView::positionViewAtIndex()
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testRightToLeft", QVariant(false));
ctxt->setContextProperty("testTopToBottom", QVariant(false));
+ ctxt->setContextProperty("testBottomToTop", QVariant(false));
- canvas->setSource(testFileUrl("gridview1.qml"));
+ canvas->setSource(testFileUrl("layouts.qml"));
canvas->show();
qApp->processEvents();
@@ -2377,11 +2610,7 @@ void tst_QQuickGridView::snapping()
for (int i = 0; i < 40; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -2483,8 +2712,9 @@ void tst_QQuickGridView::positionViewAtIndex_rightToLeft()
ctxt->setContextProperty("testModel", &model);
ctxt->setContextProperty("testTopToBottom", QVariant(true));
ctxt->setContextProperty("testRightToLeft", QVariant(true));
+ ctxt->setContextProperty("testBottomToTop", QVariant(false));
- canvas->setSource(testFileUrl("gridview1.qml"));
+ canvas->setSource(testFileUrl("layouts.qml"));
qApp->processEvents();
QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
@@ -2812,8 +3042,8 @@ void tst_QQuickGridView::manualHighlight()
QTRY_COMPARE(gridview->highlightItem()->y() - 5, gridview->currentItem()->y());
QTRY_COMPARE(gridview->highlightItem()->x() - 5, gridview->currentItem()->x());
- gridview->setFlow(QQuickGridView::TopToBottom);
- QTRY_COMPARE(gridview->flow(), QQuickGridView::TopToBottom);
+ gridview->setFlow(QQuickGridView::FlowTopToBottom);
+ QTRY_COMPARE(gridview->flow(), QQuickGridView::FlowTopToBottom);
gridview->setCurrentIndex(0);
QTRY_COMPARE(gridview->currentIndex(), 0);
@@ -2829,10 +3059,10 @@ void tst_QQuickGridView::footer()
{
QFETCH(QQuickGridView::Flow, flow);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(QPointF, initialFooterPos);
QFETCH(QPointF, changedFooterPos);
QFETCH(QPointF, initialContentPos);
- QFETCH(QPointF, changedContentPos);
QFETCH(QPointF, firstDelegatePos);
QFETCH(QPointF, resizeContentPos);
@@ -2845,7 +3075,6 @@ void tst_QQuickGridView::footer()
QQmlContext *ctxt = canvas->rootContext();
ctxt->setContextProperty("testModel", &model);
-
canvas->setSource(testFileUrl("footer.qml"));
qApp->processEvents();
@@ -2853,13 +3082,14 @@ void tst_QQuickGridView::footer()
QTRY_VERIFY(gridview != 0);
gridview->setFlow(flow);
gridview->setLayoutDirection(layoutDirection);
+ gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
QQuickItem *contentItem = gridview->contentItem();
QTRY_VERIFY(contentItem != 0);
QQuickText *footer = findItem<QQuickText>(contentItem, "footer");
QVERIFY(footer);
-
QVERIFY(footer == gridview->footerItem());
QCOMPARE(footer->pos(), initialFooterPos);
@@ -2867,7 +3097,7 @@ void tst_QQuickGridView::footer()
QCOMPARE(footer->height(), 30.);
QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentHeight(), (model.count()+2) / 3 * 60. + footer->height());
else
QCOMPARE(gridview->contentWidth(), (model.count()+3) / 5 * 80. + footer->width());
@@ -2876,10 +3106,13 @@ void tst_QQuickGridView::footer()
QVERIFY(item);
QCOMPARE(item->pos(), firstDelegatePos);
- if (flow == QQuickGridView::LeftToRight) {
+ if (flow == QQuickGridView::FlowLeftToRight) {
// shrink by one row
model.removeItem(2);
- QTRY_COMPARE(footer->y(), initialFooterPos.y() - gridview->cellHeight());
+ if (verticalLayoutDirection == QQuickItemView::TopToBottom)
+ QTRY_COMPARE(footer->y(), initialFooterPos.y() - gridview->cellHeight());
+ else
+ QTRY_COMPARE(footer->y(), initialFooterPos.y() + gridview->cellHeight());
} else {
// shrink by one column
model.removeItem(2);
@@ -2895,10 +3128,12 @@ void tst_QQuickGridView::footer()
QPointF posWhenNoItems(0, 0);
if (layoutDirection == Qt::RightToLeft)
- posWhenNoItems.setX(flow == QQuickGridView::LeftToRight ? gridview->width() - footer->width() : -footer->width());
+ posWhenNoItems.setX(flow == QQuickGridView::FlowLeftToRight ? gridview->width() - footer->width() : -footer->width());
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ posWhenNoItems.setY(-footer->height());
QTRY_COMPARE(footer->pos(), posWhenNoItems);
- // if header is present, it's at a negative pos, so the footer should not move
+ // if header is toggled, it shouldn't affect the footer position
canvas->rootObject()->setProperty("showHeader", true);
QVERIFY(findItem<QQuickItem>(contentItem, "header") != 0);
QTRY_COMPARE(footer->pos(), posWhenNoItems);
@@ -2917,13 +3152,14 @@ void tst_QQuickGridView::footer()
QVERIFY(!footer);
footer = findItem<QQuickText>(contentItem, "footer2");
QVERIFY(footer);
-
QVERIFY(footer == gridview->footerItem());
QCOMPARE(footer->pos(), changedFooterPos);
QCOMPARE(footer->width(), 50.);
QCOMPARE(footer->height(), 20.);
- QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), changedContentPos);
+
+ // changing the footer shouldn't change the content pos
+ QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
item = findItem<QQuickItem>(contentItem, "wrapper", 0);
QVERIFY(item);
@@ -2941,10 +3177,10 @@ void tst_QQuickGridView::footer_data()
{
QTest::addColumn<QQuickGridView::Flow>("flow");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<QPointF>("initialFooterPos");
QTest::addColumn<QPointF>("changedFooterPos");
QTest::addColumn<QPointF>("initialContentPos");
- QTest::addColumn<QPointF>("changedContentPos");
QTest::addColumn<QPointF>("firstDelegatePos");
QTest::addColumn<QPointF>("resizeContentPos");
@@ -2955,46 +3191,84 @@ void tst_QQuickGridView::footer_data()
// view height = 320
// footer below items, bottom left
- QTest::newRow("flow left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight
+ QTest::newRow("LeftToRight, LtR, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(0, 3 * 60) // 180 = height of 3 rows (cell height is 60)
<< QPointF(0, 10 * 60) // 30 items = 10 rows
<< QPointF(0, 0)
<< QPointF(0, 0)
- << QPointF(0, 0)
- << QPointF(0, 10 * 60 - 320 + 10);
+ << QPointF(0, (10 * 60) - 320 + 10);
// footer below items, bottom right
- QTest::newRow("flow left to right, layout right to left") << QQuickGridView::LeftToRight << Qt::RightToLeft
+ QTest::newRow("LeftToRight, RtL, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(240 - 100, 3 * 60)
<< QPointF((240 - 100) + 50, 10 * 60) // 50 = width diff between old and new footers
<< QPointF(0, 0)
- << QPointF(0, 0)
<< QPointF(240 - 80, 0)
- << QPointF(0, 10 * 60 - 320 + 10);
-
- // footer to right of items
- QTest::newRow("flow top to bottom, layout left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight
+ << QPointF(0, (10 * 60) - 320 + 10);
+
+ // footer above items, top left
+ QTest::newRow("LeftToRight, LtR, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, -(3 * 60) - 30)
+ << QPointF(0, -(10 * 60) - 20)
+ << QPointF(0, -320)
+ << QPointF(0, -60)
+ << QPointF(0, -(10 * 60) - 10);
+
+ // footer above items, top right
+ QTest::newRow("LeftToRight, RtL, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(240 - 100, -(3 * 60) - 30)
+ << QPointF((240 - 100) + 50, -(10 * 60) - 20)
+ << QPointF(0, -320)
+ << QPointF(240 - 80, -60)
+ << QPointF(0, -(10 * 60) - 10);
+
+
+ // footer to right of items, bottom right
+ QTest::newRow("TopToBottom, LtR, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(2 * 80, 0) // 2 columns, cell width 80
<< QPointF(6 * 80, 0) // 30 items = 6 columns
<< QPointF(0, 0)
<< QPointF(0, 0)
- << QPointF(0, 0)
- << QPointF(6 * 80 - 240 + 40, 0);
+ << QPointF((6 * 80) - 240 + 40, 0);
- // footer to left of items
- QTest::newRow("flow top to bottom, layout right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft
+ // footer to left of items, bottom right
+ QTest::newRow("TopToBottom, RtL, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(-(2 * 80) - 100, 0)
<< QPointF(-(6 * 80) - 50, 0) // 50 = new footer width
<< QPointF(-240, 0)
- << QPointF(-240, 0) // unchanged, footer change doesn't change content pos
<< QPointF(-80, 0)
<< QPointF(-(6 * 80) - 40, 0);
+
+ // footer to right of items, top right
+ QTest::newRow("TopToBottom, LtR, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(2 * 80, -30)
+ << QPointF(6 * 80, -20)
+ << QPointF(0, -320)
+ << QPointF(0, -60)
+ << QPointF((6 * 80) - 240 + 40, -320);
+
+ // footer to left of items, top left
+ QTest::newRow("TopToBottom, RtL, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(-(2 * 80) - 100, -30)
+ << QPointF(-(6 * 80) - 50, -20)
+ << QPointF(-240, -320)
+ << QPointF(-80, -60)
+ << QPointF(-(6 * 80) - 40, -320);
}
void tst_QQuickGridView::header()
{
QFETCH(QQuickGridView::Flow, flow);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(QPointF, initialHeaderPos);
QFETCH(QPointF, changedHeaderPos);
QFETCH(QPointF, initialContentPos);
@@ -3018,6 +3292,7 @@ void tst_QQuickGridView::header()
QTRY_VERIFY(gridview != 0);
gridview->setFlow(flow);
gridview->setLayoutDirection(layoutDirection);
+ gridview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
QQuickItem *contentItem = gridview->contentItem();
@@ -3025,7 +3300,6 @@ void tst_QQuickGridView::header()
QQuickText *header = findItem<QQuickText>(contentItem, "header");
QVERIFY(header);
-
QVERIFY(header == gridview->headerItem());
QCOMPARE(header->pos(), initialHeaderPos);
@@ -3033,7 +3307,7 @@ void tst_QQuickGridView::header()
QCOMPARE(header->height(), 30.);
QCOMPARE(QPointF(gridview->contentX(), gridview->contentY()), initialContentPos);
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentHeight(), (model.count()+2) / 3 * 60. + header->height());
else
QCOMPARE(gridview->contentWidth(), (model.count()+3) / 5 * 80. + header->width());
@@ -3091,6 +3365,7 @@ void tst_QQuickGridView::header()
QTRY_VERIFY(gridview != 0);
gridview->setFlow(flow);
gridview->setLayoutDirection(layoutDirection);
+ gridview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
gridview->setWidth(240);
@@ -3105,6 +3380,7 @@ void tst_QQuickGridView::header_data()
{
QTest::addColumn<QQuickGridView::Flow>("flow");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<QPointF>("initialHeaderPos");
QTest::addColumn<QPointF>("changedHeaderPos");
QTest::addColumn<QPointF>("initialContentPos");
@@ -3118,7 +3394,8 @@ void tst_QQuickGridView::header_data()
// view width = 240
// header above items, top left
- QTest::newRow("flow left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight
+ QTest::newRow("LeftToRight, LtR, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(0, -30)
<< QPointF(0, -20)
<< QPointF(0, -30)
@@ -3127,7 +3404,8 @@ void tst_QQuickGridView::header_data()
<< QPointF(0, -10);
// header above items, top right
- QTest::newRow("flow left to right, layout right to left") << QQuickGridView::LeftToRight << Qt::RightToLeft
+ QTest::newRow("LeftToRight, RtL, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(240 - 100, -30)
<< QPointF((240 - 100) + 50, -20) // 50 = width diff between old and new headers
<< QPointF(0, -30)
@@ -3135,8 +3413,30 @@ void tst_QQuickGridView::header_data()
<< QPointF(160, 0)
<< QPointF(0, -10);
- // header to left of items
- QTest::newRow("flow top to bottom, layout left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight
+ // header below items, bottom left
+ QTest::newRow("LeftToRight, LtR, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, 0)
+ << QPointF(0, 0)
+ << QPointF(0, -320 + 30)
+ << QPointF(0, -320 + 20)
+ << QPointF(0, -60)
+ << QPointF(0, -320 + 10);
+
+ // header above items, top right
+ QTest::newRow("LeftToRight, RtL, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(240 - 100, 0)
+ << QPointF((240 - 100) + 50, 0)
+ << QPointF(0, -320 + 30)
+ << QPointF(0, -320 + 20)
+ << QPointF(160, -60)
+ << QPointF(0, -320 + 10);
+
+
+ // header to left of items, bottom left
+ QTest::newRow("TopToBottom, LtR, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(-100, 0)
<< QPointF(-50, 0)
<< QPointF(-100, 0)
@@ -3144,14 +3444,35 @@ void tst_QQuickGridView::header_data()
<< QPointF(0, 0)
<< QPointF(-40, 0);
- // header to right of items
- QTest::newRow("flow top to bottom, layout right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft
+ // header to right of items, bottom right
+ QTest::newRow("TopToBottom, RtL, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(0, 0)
<< QPointF(0, 0)
<< QPointF(-(240 - 100), 0)
<< QPointF(-(240 - 50), 0)
<< QPointF(-80, 0)
<< QPointF(-(240 - 40), 0);
+
+ // header to left of items, top left
+ QTest::newRow("TopToBottom, LtR, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(-100, -30)
+ << QPointF(-50, -20)
+ << QPointF(-100, -320)
+ << QPointF(-50, -320)
+ << QPointF(0, -60)
+ << QPointF(-40, -320);
+
+ // header to right of items, top right
+ QTest::newRow("TopToBottom, RtL, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(0, -30)
+ << QPointF(0, -20)
+ << QPointF(-(240 - 100), -320)
+ << QPointF(-(240 - 50), -320)
+ << QPointF(-80, -60)
+ << QPointF(-(240 - 40), -320);
}
class GVAccessor : public QQuickGridView
@@ -3165,138 +3486,144 @@ public:
void tst_QQuickGridView::headerFooter()
{
- {
- // Vertical
- QQuickView *canvas = createView();
-
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->setSource(testFileUrl("headerfooter.qml"));
- qApp->processEvents();
-
- QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
- QTRY_VERIFY(gridview != 0);
-
- QQuickItem *contentItem = gridview->contentItem();
- QTRY_VERIFY(contentItem != 0);
-
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
-
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 0.);
-
- QCOMPARE(static_cast<GVAccessor*>(gridview)->minY(), header->height());
- QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), header->height());
-
- delete canvas;
- }
- {
- // Horizontal
- QQuickView *canvas = createView();
-
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->setSource(testFileUrl("headerfooter.qml"));
- canvas->rootObject()->setProperty("horizontal", true);
- qApp->processEvents();
-
- QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
- QTRY_VERIFY(gridview != 0);
-
- QQuickItem *contentItem = gridview->contentItem();
- QTRY_VERIFY(contentItem != 0);
-
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->x(), -header->width());
+ QFETCH(QQuickGridView::Flow, flow);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+ QFETCH(QPointF, headerPos);
+ QFETCH(QPointF, footerPos);
+ QFETCH(QPointF, minPos);
+ QFETCH(QPointF, maxPos);
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->x(), 0.);
+ QQuickView *canvas = getView();
- QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), header->width());
- QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), header->width());
+ QmlListModel model;
+ QQmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ canvas->setSource(testFileUrl("headerfooter.qml"));
+ canvas->show();
+ qApp->processEvents();
- delete canvas;
- }
- {
- // Horizontal RTL
- QQuickView *canvas = createView();
+ QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
+ QTRY_VERIFY(gridview != 0);
+ gridview->setFlow(flow);
+ gridview->setLayoutDirection(layoutDirection);
+ gridview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ QQuickItem *contentItem = gridview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
- canvas->setSource(testFileUrl("headerfooter.qml"));
- canvas->rootObject()->setProperty("horizontal", true);
- canvas->rootObject()->setProperty("rtl", true);
- qApp->processEvents();
+ QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->pos(), headerPos);
- QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
- QTRY_VERIFY(gridview != 0);
+ QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->pos(), footerPos);
- QQuickItem *contentItem = gridview->contentItem();
- QTRY_VERIFY(contentItem != 0);
+ QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), minPos.x());
+ QCOMPARE(static_cast<GVAccessor*>(gridview)->minY(), minPos.y());
+ QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), maxPos.x());
+ QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), maxPos.y());
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->x(), 0.);
+ releaseView(canvas);
+}
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->x(), -footer->width());
+void tst_QQuickGridView::headerFooter_data()
+{
+ QTest::addColumn<QQuickGridView::Flow>("flow");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+ QTest::addColumn<QPointF>("headerPos");
+ QTest::addColumn<QPointF>("footerPos");
+ QTest::addColumn<QPointF>("minPos");
+ QTest::addColumn<QPointF>("maxPos");
+
+ // header is 240x20 (or 20x320 in TopToBottom)
+ // footer is 240x30 (or 30x320 in TopToBottom)
+
+ QTest::newRow("LeftToRight, LtR, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(0, -20) << QPointF(0, 0)
+ << QPointF(0, 20) << QPointF(240, 20);
+
+ QTest::newRow("LeftToRight, RtL, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << QPointF(0, -20) << QPointF(0, 0)
+ << QPointF(0, 20) << QPointF(240, 20);
+
+ QTest::newRow("LeftToRight, LtR, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, 0) << QPointF(0, -30)
+ << QPointF(0, 320 - 20) << QPointF(240, 320 - 20); // content flow is reversed
+
+ QTest::newRow("LeftToRight, RtL, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(0, 0) << QPointF(0, -30)
+ << QPointF(0, 320 - 20) << QPointF(240, 320 - 20); // content flow is reversed
+
+
+ QTest::newRow("TopToBottom, LtR, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(-20, 0) << QPointF(0, 0)
+ << QPointF(20, 0) << QPointF(20, 320);
+
+ QTest::newRow("TopToBottom, RtL, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << QPointF(0, 0) << QPointF(-30, 0)
+ << QPointF(240 - 20, 0) << QPointF(240 - 20, 320); // content flow is reversed
+
+ QTest::newRow("TopToBottom, LtR, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(-20, -320) << QPointF(0, -320)
+ << QPointF(20, 0) << QPointF(20, 320);
+
+ QTest::newRow("TopToBottom, RtL, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(0, -320) << QPointF(-30, -320)
+ << QPointF(240 - 20, 0) << QPointF(240 - 20, 320); // content flow is reversed
+}
- QCOMPARE(static_cast<GVAccessor*>(gridview)->minX(), 240. - header->width());
- QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), 240. - header->width());
+void tst_QQuickGridView::resetModel_headerFooter()
+{
+ // Resetting a model shouldn't crash in views with header/footer
- delete canvas;
- }
- {
- // Reset model
- QQuickView *canvas = createView();
+ QQuickView *canvas = createView();
- QaimModel model;
- for (int i = 0; i < 6; i++)
- model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ QaimModel model;
+ for (int i = 0; i < 6; i++)
+ model.addItem("Item" + QString::number(i), "");
+ QQmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
- canvas->setSource(testFileUrl("headerfooter.qml"));
- qApp->processEvents();
+ canvas->setSource(testFileUrl("headerfooter.qml"));
+ qApp->processEvents();
- QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
- QTRY_VERIFY(gridview != 0);
+ QQuickGridView *gridview = qobject_cast<QQuickGridView*>(canvas->rootObject());
+ QTRY_VERIFY(gridview != 0);
- QQuickItem *contentItem = gridview->contentItem();
- QTRY_VERIFY(contentItem != 0);
+ QQuickItem *contentItem = gridview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
+ QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), -header->height());
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 80.*2);
+ QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->y(), 80.*2);
- model.reset();
+ model.reset();
- header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
+ header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), -header->height());
- footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 80.*2);
+ footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->y(), 80.*2);
- delete canvas;
- }
+ delete canvas;
}
void tst_QQuickGridView::resizeViewAndRepaint()
@@ -3370,6 +3697,147 @@ void tst_QQuickGridView::resizeViewAndRepaint()
delete canvas;
}
+void tst_QQuickGridView::resizeGrid()
+{
+ QFETCH(QQuickGridView::Flow, flow);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+ QFETCH(QPointF, initialContentPos);
+ QFETCH(QPointF, firstItemPos);
+
+ QaimModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QQuickView *canvas = getView();
+ QQmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testTopToBottom", flow == QQuickGridView::FlowTopToBottom);
+ ctxt->setContextProperty("testRightToLeft", layoutDirection == Qt::RightToLeft);
+ ctxt->setContextProperty("testBottomToTop", verticalLayoutDirection == QQuickGridView::BottomToTop);
+ canvas->setSource(testFileUrl("resizegrid.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickGridView *gridview = findItem<QQuickGridView>(canvas->rootObject(), "grid");
+ QTRY_VERIFY(gridview != 0);
+ QQuickItem *contentItem = gridview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ // set the width to slightly larger than 3 items across, to test
+ // items are aligned correctly in right-to-left
+ canvas->rootObject()->setWidth(260);
+ canvas->rootObject()->setHeight(320);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+ QCOMPARE(gridview->contentX(), initialContentPos.x());
+ QCOMPARE(gridview->contentY(), initialContentPos.y());
+
+ QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
+ QVERIFY(item0);
+ QCOMPARE(item0->pos(), firstItemPos);
+
+ // Confirm items positioned correctly and indexes correct
+ QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+ QVERIFY(items.count() >= 18 && items.count() <= 21);
+ for (int i = 0; i < model.count() && i < items.count(); ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+ QCOMPARE(item->pos(), expectedItemPos(gridview, i, 0));
+ QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
+ QVERIFY(name != 0);
+ QCOMPARE(name->text(), model.name(i));
+ }
+
+ // change from 3x5 grid to 4x7
+ canvas->rootObject()->setWidth(canvas->rootObject()->width() + 80);
+ canvas->rootObject()->setHeight(canvas->rootObject()->height() + 60*2);
+ QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
+
+ // other than in LeftToRight+RightToLeft layout, the first item should not move
+ // if view is resized
+ QCOMPARE(findItem<QQuickItem>(contentItem, "wrapper", 0), item0);
+ if (flow == QQuickGridView::FlowLeftToRight && layoutDirection == Qt::RightToLeft)
+ firstItemPos.rx() += 80;
+ QCOMPARE(item0->pos(), firstItemPos);
+
+ QPointF newContentPos = initialContentPos;
+ if (flow == QQuickGridView::FlowTopToBottom && layoutDirection == Qt::RightToLeft)
+ newContentPos.rx() -= 80.0;
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ newContentPos.ry() -= 60.0 * 2;
+ QCOMPARE(gridview->contentX(), newContentPos.x());
+ QCOMPARE(gridview->contentY(), newContentPos.y());
+
+ // Confirm items positioned correctly and indexes correct
+ items = findItems<QQuickItem>(contentItem, "wrapper");
+ QVERIFY(items.count() >= 28);
+ for (int i = 0; i < model.count() && i < items.count(); ++i) {
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
+ QCOMPARE(item->pos(), expectedItemPos(gridview, i, 0));
+ QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
+ QVERIFY(name != 0);
+ QCOMPARE(name->text(), model.name(i));
+ }
+
+ releaseView(canvas);
+}
+
+void tst_QQuickGridView::resizeGrid_data()
+{
+ QTest::addColumn<QQuickGridView::Flow>("flow");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+ QTest::addColumn<QPointF>("initialContentPos");
+ QTest::addColumn<QPointF>("firstItemPos");
+
+ // Initial view width is 260, so in LeftToRight + right-to-left mode the
+ // content x should be -20
+
+ QTest::newRow("LeftToRight, LtR, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(0, 0)
+ << QPointF(0, 0);
+
+ QTest::newRow("LeftToRight, RtL, TtB")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << QPointF(-20.0, 0)
+ << QPointF(80.0 * 2, 0);
+
+ QTest::newRow("LeftToRight, LtR, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, -320)
+ << QPointF(0, -60.0);
+
+ QTest::newRow("LeftToRight, RtL, BtT")
+ << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(-20.0, -320)
+ << QPointF(80.0 * 2, -60.0);
+
+
+ QTest::newRow("TopToBottom, LtR, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(0, 0)
+ << QPointF(0, 0);
+
+ QTest::newRow("TopToBottom, RtL, TtB")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << QPointF(-260, 0)
+ << QPointF(-80.0, 0);
+
+ QTest::newRow("TopToBottom, LtR, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, -320)
+ << QPointF(0, -60.0);
+
+ QTest::newRow("TopToBottom, RtL, BtT")
+ << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
+ << QPointF(-260, -320)
+ << QPointF(-80.0, -60.0);
+}
+
+
void tst_QQuickGridView::changeColumnCount()
{
QmlListModel model;
@@ -3458,11 +3926,7 @@ void tst_QQuickGridView::indexAt_itemAt()
model.addItem("Ben", "04321");
model.addItem("Jim", "0780");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
qApp->processEvents();
@@ -3776,22 +4240,22 @@ void tst_QQuickGridView::snapToRow_data()
QTest::addColumn<qreal>("endExtent");
QTest::addColumn<qreal>("startExtent");
- QTest::newRow("vertical, left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, left to right") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 200) << QPoint(20, 20) << 60.0 << 800.0 << 0.0;
- QTest::newRow("horizontal, left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, left to right") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
<< QPoint(200, 20) << QPoint(20, 20) << 60.0 << 800.0 << 0.0;
- QTest::newRow("horizontal, right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, right to left") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 20) << QPoint(200, 20) << -60.0 << -800.0 - 240.0 << -240.0;
- QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 200) << QPoint(20, 20) << 60.0 << 940.0 << -20.0;
- QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(200, 20) << QPoint(20, 20) << 60.0 << 940.0 << -20.0;
- QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 20) << QPoint(200, 20) << -60.0 << -800.0 - 240.0 - 140.0 << -220.0;
}
@@ -3826,7 +4290,7 @@ void tst_QQuickGridView::snapToRow()
// confirm that a flick hits an item boundary
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(qreal(fmod(gridview->contentY(),80.0)), snapAlignment);
else
QCOMPARE(qreal(fmod(gridview->contentX(),80.0)), snapAlignment);
@@ -3835,11 +4299,11 @@ void tst_QQuickGridView::snapToRow()
do {
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- } while (flow == QQuickGridView::LeftToRight
+ } while (flow == QQuickGridView::FlowLeftToRight
? !gridview->isAtYEnd()
: layoutDirection == Qt::LeftToRight ? !gridview->isAtXEnd() : !gridview->isAtXBeginning());
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentY(), endExtent);
else
QCOMPARE(gridview->contentX(), endExtent);
@@ -3848,11 +4312,11 @@ void tst_QQuickGridView::snapToRow()
do {
flick(canvas, flickEnd, flickStart, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- } while (flow == QQuickGridView::LeftToRight
+ } while (flow == QQuickGridView::FlowLeftToRight
? !gridview->isAtYBeginning()
: layoutDirection == Qt::LeftToRight ? !gridview->isAtXBeginning() : !gridview->isAtXEnd());
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentY(), startExtent);
else
QCOMPARE(gridview->contentX(), startExtent);
@@ -3871,22 +4335,22 @@ void tst_QQuickGridView::snapOneRow_data()
QTest::addColumn<qreal>("endExtent");
QTest::addColumn<qreal>("startExtent");
- QTest::newRow("vertical, left to right") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, left to right") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 200) << QPoint(20, 20) << 100.0 << 240.0 << 0.0;
- QTest::newRow("horizontal, left to right") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, left to right") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
<< QPoint(200, 20) << QPoint(20, 20) << 100.0 << 240.0 << 0.0;
- QTest::newRow("horizontal, right to left") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, right to left") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 20) << QPoint(200, 20) << -340.0 << -240.0 - 240.0 << -240.0;
- QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::LeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, left to right, enforce range") << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 200) << QPoint(20, 20) << 100.0 << 340.0 << -20.0;
- QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::TopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, left to right, enforce range") << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(200, 20) << QPoint(20, 20) << 100.0 << 340.0 << -20.0;
- QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::TopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, right to left, enforce range") << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 20) << QPoint(200, 20) << -340.0 << -240.0 - 240.0 - 100.0 << -220.0;
}
@@ -3923,7 +4387,7 @@ void tst_QQuickGridView::snapOneRow()
// confirm that a flick hits next row boundary
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentY(), snapAlignment);
else
QCOMPARE(gridview->contentX(), snapAlignment);
@@ -3937,7 +4401,7 @@ void tst_QQuickGridView::snapOneRow()
do {
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- } while (flow == QQuickGridView::LeftToRight
+ } while (flow == QQuickGridView::FlowLeftToRight
? !gridview->isAtYEnd()
: layoutDirection == Qt::LeftToRight ? !gridview->isAtXEnd() : !gridview->isAtXBeginning());
@@ -3946,7 +4410,7 @@ void tst_QQuickGridView::snapOneRow()
QCOMPARE(currentIndexSpy.count(), 3);
}
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentY(), endExtent);
else
QCOMPARE(gridview->contentX(), endExtent);
@@ -3955,11 +4419,11 @@ void tst_QQuickGridView::snapOneRow()
do {
flick(canvas, flickEnd, flickStart, 180);
QTRY_VERIFY(gridview->isMoving() == false); // wait until it stops
- } while (flow == QQuickGridView::LeftToRight
+ } while (flow == QQuickGridView::FlowLeftToRight
? !gridview->isAtYBeginning()
: layoutDirection == Qt::LeftToRight ? !gridview->isAtXBeginning() : !gridview->isAtXEnd());
- if (flow == QQuickGridView::LeftToRight)
+ if (flow == QQuickGridView::FlowLeftToRight)
QCOMPARE(gridview->contentY(), startExtent);
else
QCOMPARE(gridview->contentX(), startExtent);
@@ -4171,7 +4635,7 @@ void tst_QQuickGridView::addTransitions()
{
QFETCH(int, initialItemCount);
QFETCH(bool, shouldAnimateTargets);
- QFETCH(qreal, contentY);
+ QFETCH(qreal, contentYRowOffset);
QFETCH(int, insertionIndex);
QFETCH(int, insertionCount);
QFETCH(ListRange, expectedDisplacedIndexes);
@@ -4204,8 +4668,8 @@ void tst_QQuickGridView::addTransitions()
QVERIFY(contentItem != 0);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- if (contentY != 0) {
- gridview->setContentY(contentY);
+ if (contentYRowOffset != 0) {
+ gridview->setContentY(contentYRowOffset * 60.0);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
}
@@ -4220,7 +4684,7 @@ void tst_QQuickGridView::addTransitions()
newData << qMakePair(QString("New item %1").arg(i), QString(""));
// last visible item is the first item of the row beneath the view
- if (i >= (contentY / 60)*3 && i < qCeil((contentY + gridview->height()) / 60.0)*3) {
+ if (i >= (gridview->contentY() / 60)*3 && i < qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) {
expectedTargetData << newData.last();
targetIndexes << i;
}
@@ -4264,7 +4728,7 @@ void tst_QQuickGridView::addTransitions()
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
+ if (items[i]->y() >= gridview->contentY()) {
QQmlExpression e(qmlContext(items[i]), items[i], "index");
firstVisibleIndex = e.evaluate().toInt();
break;
@@ -4273,8 +4737,7 @@ void tst_QQuickGridView::addTransitions()
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// verify all items moved to the correct final positions
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
QCOMPARE(item->x(), (i%3)*80.0);
@@ -4290,7 +4753,7 @@ void tst_QQuickGridView::addTransitions()
void tst_QQuickGridView::addTransitions_data()
{
QTest::addColumn<int>("initialItemCount");
- QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<qreal>("contentYRowOffset");
QTest::addColumn<bool>("shouldAnimateTargets");
QTest::addColumn<int>("insertionIndex");
QTest::addColumn<int>("insertionCount");
@@ -4298,19 +4761,19 @@ void tst_QQuickGridView::addTransitions_data()
// if inserting a full row before visible index, items don't appear or animate in, even if there are > 1 new items
QTest::newRow("insert 1, just before start")
- << 30 << 20.0 << false
+ << 30 << 1.0 << false
<< 0 << 1 << ListRange();
QTest::newRow("insert 1, way before start")
- << 30 << 20.0 << false
+ << 30 << 1.0 << false
<< 0 << 1 << ListRange();
QTest::newRow("insert multiple, just before start")
- << 30 << 100.0 << false
+ << 30 << 1.0 << false
<< 0 << 3 << ListRange();
QTest::newRow("insert multiple (< 1 row), just before start")
- << 30 << 100.0 << false
+ << 30 << 1.0 << false
<< 0 << 2 << ListRange();
QTest::newRow("insert multiple, way before start")
- << 30 << 100.0 << false
+ << 30 << 3.0 << false
<< 0 << 3 << ListRange();
QTest::newRow("insert 1 at start")
@@ -4323,13 +4786,13 @@ void tst_QQuickGridView::addTransitions_data()
<< 30 << 0.0 << true
<< 0 << 5 << ListRange(0, 17);
QTest::newRow("insert 1 at start, content y not 0")
- << 30 << 60.0 << true // first visible is index 3
+ << 30 << 1.0 << true // first visible is index 3
<< 3 << 1 << ListRange(0 + 3, 17 + 3);
QTest::newRow("insert multiple at start, content y not 0")
- << 30 << 60.0 << true // first visible is index 3
+ << 30 << 1.0 << true // first visible is index 3
<< 3 << 3 << ListRange(0 + 3, 17 + 3);
QTest::newRow("insert multiple (> 1 row) at start, content y not 0")
- << 30 << 60.0 << true // first visible is index 3
+ << 30 << 1.0 << true // first visible is index 3
<< 3 << 5 << ListRange(0 + 3, 17 + 3);
QTest::newRow("insert 1 at start, to empty grid")
@@ -4356,10 +4819,10 @@ void tst_QQuickGridView::addTransitions_data()
<< 30 << 0.0 << true
<< 17 << 3 << ListRange(17, 17);
QTest::newRow("insert 1 at bottom, content y not 0")
- << 30 << 20.0 * 3 << true
+ << 30 << 1.0 << true
<< 17 + 3 << 1 << ListRange(17 + 3, 17 + 3);
QTest::newRow("insert multiple at bottom, content y not 0")
- << 30 << 20.0 * 3 << true
+ << 30 << 1.0 << true
<< 17 + 3 << 3 << ListRange(17 + 3, 17 + 3);
@@ -4376,8 +4839,8 @@ void tst_QQuickGridView::addTransitions_data()
void tst_QQuickGridView::moveTransitions()
{
QFETCH(int, initialItemCount);
- QFETCH(qreal, contentY);
- QFETCH(qreal, itemsOffsetAfterMove);
+ QFETCH(qreal, contentYRowOffset);
+ QFETCH(qreal, rowOffsetAfterMove);
QFETCH(int, moveFrom);
QFETCH(int, moveTo);
QFETCH(int, moveCount);
@@ -4409,8 +4872,8 @@ void tst_QQuickGridView::moveTransitions()
QVERIFY(contentItem != 0);
QQuickText *name;
- if (contentY != 0) {
- gridview->setContentY(contentY);
+ if (contentYRowOffset != 0) {
+ gridview->setContentY(contentYRowOffset * 60.0);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
}
@@ -4422,8 +4885,8 @@ void tst_QQuickGridView::moveTransitions()
QList<int> targetIndexes;
for (int i=moveFrom; i<moveFrom+moveCount; i++) {
int toIndex = moveTo + (i - moveFrom);
- int firstVisibleIndex = (contentY / 60) * 3;
- int lastVisibleIndex = (qCeil((contentY + gridview->height()) / 60.0)*3) - 1;
+ int firstVisibleIndex = (gridview->contentY() / 60) * 3;
+ int lastVisibleIndex = (qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) - 1;
if ((i >= firstVisibleIndex && i <= lastVisibleIndex)
|| (toIndex >= firstVisibleIndex && toIndex <= lastVisibleIndex)) {
expectedTargetData << qMakePair(model.name(i), model.number(i));
@@ -4461,7 +4924,7 @@ void tst_QQuickGridView::moveTransitions()
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
+ if (items[i]->y() >= gridview->contentY()) {
QQmlExpression e(qmlContext(items[i]), items[i], "index");
firstVisibleIndex = e.evaluate().toInt();
break;
@@ -4470,12 +4933,12 @@ void tst_QQuickGridView::moveTransitions()
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// verify all items moved to the correct final positions
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i=firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ qreal pixelOffset = 60 * rowOffsetAfterMove;
+ for (int i=firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
QCOMPARE(item->x(), (i%3)*80.0);
- QCOMPARE(item->y(), (i/3)*60.0 + itemsOffsetAfterMove);
+ QCOMPARE(item->y(), (i/3)*60.0 + pixelOffset);
name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
@@ -4487,94 +4950,132 @@ void tst_QQuickGridView::moveTransitions()
void tst_QQuickGridView::moveTransitions_data()
{
QTest::addColumn<int>("initialItemCount");
- QTest::addColumn<qreal>("contentY");
- QTest::addColumn<qreal>("itemsOffsetAfterMove");
+ QTest::addColumn<qreal>("contentYRowOffset");
+ QTest::addColumn<qreal>("rowOffsetAfterMove");
QTest::addColumn<int>("moveFrom");
QTest::addColumn<int>("moveTo");
QTest::addColumn<int>("moveCount");
QTest::addColumn<ListRange>("expectedDisplacedIndexes");
- QTest::newRow("move from above view, outside visible items, move 1") << 30 << 120.0 << 0.0
+ QTest::newRow("move from above view, outside visible items, move 1")
+ << 30 << 2.0 << 0.0
<< 1 << 10 << 1 << ListRange(6, 10);
- QTest::newRow("move from above view, outside visible items, move 1 (first item)") << 30 << 120.0 << 0.0
+ QTest::newRow("move from above view, outside visible items, move 1 (first item)")
+ << 30 << 2.0 << 0.0
<< 0 << 10 << 1 << ListRange(6, 10);
- QTest::newRow("move from above view, outside visible items, move multiple") << 30 << 120.0 << 60.0
+ QTest::newRow("move from above view, outside visible items, move multiple")
+ << 30 << 2.0 << 1.0
<< 1 << 10 << 3 << ListRange(13, 23);
- QTest::newRow("move from above view, mix of visible/non-visible") << 30 << 120.0 << 60.0
+ QTest::newRow("move from above view, mix of visible/non-visible")
+ << 30 << 2.0 << 1.0
<< 1 << 10 << 6 << (ListRange(7, 15) + ListRange(16, 23));
- QTest::newRow("move from above view, mix of visible/non-visible (move first)") << 30 << 120.0 << 120.0
+ QTest::newRow("move from above view, mix of visible/non-visible (move first)")
+ << 30 << 2.0 << 2.0
<< 0 << 10 << 6 << ListRange(16, 23);
- QTest::newRow("move within view, move 1 down") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 down")
+ << 30 << 0.0 << 0.0
<< 1 << 10 << 1 << ListRange(2, 10);
- QTest::newRow("move within view, move 1 down, move first item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 down, move first item")
+ << 30 << 0.0 << 0.0
<< 0 << 10 << 1 << ListRange(1, 10);
- QTest::newRow("move within view, move 1 down, move first item, contentY not 0") << 30 << 120.0 << 0.0
+ QTest::newRow("move within view, move 1 down, move first item, contentY not 0")
+ << 30 << 2.0 << 0.0
<< 0+6 << 10+6 << 1 << ListRange(1+6, 10+6);
- QTest::newRow("move within view, move 1 down, to last item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 down, to last item")
+ << 30 << 0.0 << 0.0
<< 10 << 17 << 1 << ListRange(11, 17);
- QTest::newRow("move within view, move first->last") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move first->last")
+ << 30 << 0.0 << 0.0
<< 0 << 17 << 1 << ListRange(1, 17);
- QTest::newRow("move within view, move multiple down") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple down")
+ << 30 << 0.0 << 0.0
<< 1 << 10 << 3 << ListRange(4, 12);
- QTest::newRow("move within view, move multiple down, move first item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple down, move first item")
+ << 30 << 0.0 << 0.0
<< 0 << 10 << 3 << ListRange(3, 12);
- QTest::newRow("move within view, move multiple down, move first item, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move within view, move multiple down, move first item, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 0+3 << 10+3 << 3 << ListRange(3+3, 12+3);
- QTest::newRow("move within view, move multiple down, displace last item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple down, displace last item")
+ << 30 << 0.0 << 0.0
<< 5 << 15 << 3 << ListRange(8, 17);
- QTest::newRow("move within view, move multiple down, move first->last") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple down, move first->last")
+ << 30 << 0.0 << 0.0
<< 0 << 15 << 3 << ListRange(3, 17);
- QTest::newRow("move within view, move 1 up") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 up")
+ << 30 << 0.0 << 0.0
<< 10 << 1 << 1 << ListRange(1, 9);
- QTest::newRow("move within view, move 1 up, move to first index") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 up, move to first index")
+ << 30 << 0.0 << 0.0
<< 10 << 0 << 1 << ListRange(0, 9);
- QTest::newRow("move within view, move 1 up, move to first index, contentY not 0") << 30 << 120.0 << 0.0
+ QTest::newRow("move within view, move 1 up, move to first index, contentY not 0")
+ << 30 << 2.0 << 0.0
<< 10+6 << 0+6 << 1 << ListRange(0+6, 9+6);
- QTest::newRow("move within view, move 1 up, move to first index, contentY not on item border") << 30 << 80.0 << 0.0
+ QTest::newRow("move within view, move 1 up, move to first index, contentY not on item border")
+ << 30 << 1.5 << 0.0
<< 10+3 << 0+3 << 1 << ListRange(0+3, 9+3);
- QTest::newRow("move within view, move 1 up, move last item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 up, move last item")
+ << 30 << 0.0 << 0.0
<< 17 << 10 << 1 << ListRange(10, 16);
- QTest::newRow("move within view, move 1 up, move last->first") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move 1 up, move last->first")
+ << 30 << 0.0 << 0.0
<< 17 << 0 << 1 << ListRange(0, 16);
- QTest::newRow("move within view, move multiple up") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple up")
+ << 30 << 0.0 << 0.0
<< 10 << 1 << 3 << ListRange(1, 9);
- QTest::newRow("move within view, move multiple (> 1 row) up") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple (> 1 row) up")
+ << 30 << 0.0 << 0.0
<< 10 << 1 << 5 << ListRange(1, 9);
- QTest::newRow("move within view, move multiple up, move to first index") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple up, move to first index")
+ << 30 << 0.0 << 0.0
<< 10 << 0 << 3 << ListRange(0, 9);
- QTest::newRow("move within view, move multiple up, move to first index, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move within view, move multiple up, move to first index, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 10+3 << 0+3 << 3 << ListRange(0+3, 9+3);
- QTest::newRow("move within view, move multiple up (> 1 row), move to first index, contentY not on border") << 30 << 80.0 << 0.0
+ QTest::newRow("move within view, move multiple up (> 1 row), move to first index, contentY not on border")
+ << 30 << 1.5 << 0.0
<< 10+3 << 0+3 << 5 << ListRange(0+3, 9+3);
- QTest::newRow("move within view, move multiple up, move last item") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple up, move last item")
+ << 30 << 0.0 << 0.0
<< 15 << 5 << 3 << ListRange(5, 14);
- QTest::newRow("move within view, move multiple up, move last->first") << 30 << 0.0 << 0.0
+ QTest::newRow("move within view, move multiple up, move last->first")
+ << 30 << 0.0 << 0.0
<< 15 << 0 << 3 << ListRange(0, 14);
- QTest::newRow("move from below view, move 1 up") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move 1 up")
+ << 30 << 0.0 << 0.0
<< 20 << 5 << 1 << ListRange(5, 17);
- QTest::newRow("move from below view, move 1 up, move to top") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move 1 up, move to top")
+ << 30 << 0.0 << 0.0
<< 20 << 0 << 1 << ListRange(0, 17);
- QTest::newRow("move from below view, move 1 up, move to top, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move from below view, move 1 up, move to top, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 25 << 3 << 1 << ListRange(0+3, 17+3);
- QTest::newRow("move from below view, move multiple (> 1 row) up") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move multiple (> 1 row) up")
+ << 30 << 0.0 << 0.0
<< 20 << 5 << 5 << ListRange(5, 17);
- QTest::newRow("move from below view, move multiple up, move to top") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move multiple up, move to top")
+ << 30 << 0.0 << 0.0
<< 20 << 0 << 3 << ListRange(0, 17);
- QTest::newRow("move from below view, move multiple up, move to top, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move from below view, move multiple up, move to top, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 25 << 3 << 3 << ListRange(0+3, 17+3);
- QTest::newRow("move from below view, move 1 up, move to bottom") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move 1 up, move to bottom")
+ << 30 << 0.0 << 0.0
<< 20 << 17 << 1 << ListRange(17, 17);
- QTest::newRow("move from below view, move 1 up, move to bottom, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move from below view, move 1 up, move to bottom, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 25 << 17+3 << 1 << ListRange(17+3, 17+3);
- QTest::newRow("move from below view, move multiple up, move to to bottom") << 30 << 0.0 << 0.0
+ QTest::newRow("move from below view, move multiple up, move to to bottom")
+ << 30 << 0.0 << 0.0
<< 20 << 17 << 3 << ListRange(17, 17);
- QTest::newRow("move from below view, move multiple up, move to bottom, contentY not 0") << 30 << 60.0 << 0.0
+ QTest::newRow("move from below view, move multiple up, move to bottom, contentY not 0")
+ << 30 << 1.0 << 0.0
<< 25 << 17+3 << 3 << ListRange(17+3, 17+3);
}
@@ -4582,7 +5083,7 @@ void tst_QQuickGridView::removeTransitions()
{
QFETCH(int, initialItemCount);
QFETCH(bool, shouldAnimateTargets);
- QFETCH(qreal, contentY);
+ QFETCH(qreal, contentYRowOffset);
QFETCH(int, removalIndex);
QFETCH(int, removalCount);
QFETCH(ListRange, expectedDisplacedIndexes);
@@ -4615,8 +5116,8 @@ void tst_QQuickGridView::removeTransitions()
QVERIFY(contentItem != 0);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
- if (contentY != 0) {
- gridview->setContentY(contentY);
+ if (contentYRowOffset != 0) {
+ gridview->setContentY(contentYRowOffset * 60.0);
QTRY_COMPARE(QQuickItemPrivate::get(gridview)->polishScheduled, false);
}
@@ -4627,8 +5128,8 @@ void tst_QQuickGridView::removeTransitions()
QList<int> targetIndexes;
if (shouldAnimateTargets) {
for (int i=removalIndex; i<removalIndex+removalCount; i++) {
- int firstVisibleIndex = (contentY / 60.0)*3;
- int lastVisibleIndex = (qCeil((contentY + gridview->height()) / 60.0)*3) - 1;
+ int firstVisibleIndex = (gridview->contentY() / 60.0)*3;
+ int lastVisibleIndex = (qCeil((gridview->contentY() + gridview->height()) / 60.0)*3) - 1;
if (i >= firstVisibleIndex && i <= lastVisibleIndex) {
expectedTargetData << qMakePair(model.name(i), model.number(i));
targetIndexes << i;
@@ -4678,7 +5179,7 @@ void tst_QQuickGridView::removeTransitions()
for (int i=0; i<items.count(); i++) {
QQmlExpression e(qmlContext(items[i]), items[i], "index");
int index = e.evaluate().toInt();
- if (firstVisibleIndex < 0 && items[i]->y() >= contentY)
+ if (firstVisibleIndex < 0 && items[i]->y() >= gridview->contentY())
firstVisibleIndex = index;
else if (index < 0)
itemCount--; // exclude deleted items
@@ -4690,7 +5191,7 @@ void tst_QQuickGridView::removeTransitions()
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
QCOMPARE(item->x(), (i%3)*80.0);
- QCOMPARE(item->y(), contentY + ((i-firstVisibleIndex)/3) * 60.0);
+ QCOMPARE(item->y(), gridview->contentY() + ((i-firstVisibleIndex)/3) * 60.0);
QQuickText *name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
@@ -4702,7 +5203,7 @@ void tst_QQuickGridView::removeTransitions()
void tst_QQuickGridView::removeTransitions_data()
{
QTest::addColumn<int>("initialItemCount");
- QTest::addColumn<qreal>("contentY");
+ QTest::addColumn<qreal>("contentYRowOffset");
QTest::addColumn<bool>("shouldAnimateTargets");
QTest::addColumn<int>("removalIndex");
QTest::addColumn<int>("removalCount");
@@ -4714,19 +5215,19 @@ void tst_QQuickGridView::removeTransitions_data()
// For a GridView, removing any number of items other than a full row before the start
// should displace all items in the view
QTest::newRow("remove 1 before start")
- << 30 << 120.0 << false
+ << 30 << 2.0 << false
<< 2 << 1 << ListRange(6, 24); // 6-24 are displaced
QTest::newRow("remove 1 row, before start")
- << 30 << 120.0 << false
+ << 30 << 2.0 << false
<< 3 << 3 << ListRange();
QTest::newRow("remove between 1-2 rows, before start")
- << 30 << 120.0 << false
+ << 30 << 2.0 << false
<< 0 << 5 << ListRange(6, 25);
QTest::newRow("remove 2 rows, before start")
- << 30 << 120.0 << false
+ << 30 << 2.0 << false
<< 0 << 6 << ListRange();
QTest::newRow("remove mix of before and after start")
- << 30 << 60.0 << true
+ << 30 << 1.0 << true
<< 2 << 3 << ListRange(5, 23); // 5-23 are displaced into view
@@ -4737,10 +5238,10 @@ void tst_QQuickGridView::removeTransitions_data()
<< 30 << 0.0 << true
<< 0 << 3 << ListRange(3, 20); // 3-18 are displaced into view
QTest::newRow("remove 1 from start, content y not 0")
- << 30 << 60.0 << true
+ << 30 << 1.0 << true
<< 3 << 1 << ListRange(1 + 3, 18 + 3);
QTest::newRow("remove multiple from start, content y not 0")
- << 30 << 60.0 << true
+ << 30 << 1.0 << true
<< 3 << 3 << ListRange(3 + 3, 20 + 3);
@@ -4762,10 +5263,10 @@ void tst_QQuickGridView::removeTransitions_data()
<< 30 << 0.0 << true
<< 15 << 5 << ListRange(20, 22);
QTest::newRow("remove 1 from bottom, content y not 0")
- << 30 << 60.0 << true
+ << 30 << 1.0 << true
<< 17 + 3 << 1 << ListRange(18 + 3, 18 + 3);
QTest::newRow("remove multiple (1 row) from bottom, content y not 0")
- << 30 << 60.0 << true
+ << 30 << 1.0 << true
<< 15 + 3 << 3 << ListRange(18 + 3, 20 + 3);
@@ -5246,11 +5747,7 @@ void tst_QQuickGridView::cacheBuffer()
for (int i = 0; i < 90; i++)
model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
- ctxt->setContextProperty("testRightToLeft", QVariant(false));
- ctxt->setContextProperty("testTopToBottom", QVariant(false));
-
+ canvas->rootContext()->setContextProperty("testModel", &model);
canvas->setSource(testFileUrl("gridview1.qml"));
canvas->show();
qApp->processEvents();
@@ -5554,6 +6051,220 @@ void tst_QQuickGridView::unrequestedVisibility()
delete canvas;
}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_TtB()
+{
+ inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_TtB_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_TtB()
+{
+ inserted_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_TtB_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_TtB()
+{
+ inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_TtB_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_leftToRight_LtR_BtT()
+{
+ inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_LtR_BtT_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_BtT()
+{
+ inserted_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_leftToRight_RtL_BtT_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_BtT()
+{
+ inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_LtR_BtT_data()
+{
+ inserted_defaultLayout_data();
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_BtT()
+{
+ inserted_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::inserted_topToBottom_RtL_BtT_data()
+{
+ inserted_defaultLayout_data();
+}
+
+
+void tst_QQuickGridView::removed_leftToRight_RtL_TtB()
+{
+ removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_TtB_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_TtB()
+{
+ removed_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_TtB_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_TtB()
+{
+ removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_TtB_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_leftToRight_LtR_BtT()
+{
+ removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_leftToRight_LtR_BtT_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_BtT()
+{
+ removed_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_leftToRight_RtL_BtT_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_BtT()
+{
+ removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_topToBottom_LtR_BtT_data()
+{
+ removed_defaultLayout_data();
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_BtT()
+{
+ removed_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::removed_topToBottom_RtL_BtT_data()
+{
+ removed_defaultLayout_data();
+}
+
+
+void tst_QQuickGridView::moved_leftToRight_RtL_TtB()
+{
+ moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::moved_leftToRight_RtL_TtB_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_TtB()
+{
+ moved_defaultLayout(QQuickGridView::FlowTopToBottom);
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_TtB_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_TtB()
+{
+ moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft);
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_TtB_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_leftToRight_LtR_BtT()
+{
+ moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_leftToRight_LtR_BtT_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_leftToRight_RtL_BtT()
+{
+ moved_defaultLayout(QQuickGridView::FlowLeftToRight, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_leftToRight_RtL_BtT_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_BtT()
+{
+ moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::LeftToRight, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_topToBottom_LtR_BtT_data()
+{
+ moved_defaultLayout_data();
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_BtT()
+{
+ moved_defaultLayout(QQuickGridView::FlowTopToBottom, Qt::RightToLeft, QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickGridView::moved_topToBottom_RtL_BtT_data()
+{
+ moved_defaultLayout_data();
+}
+
+
QList<int> tst_QQuickGridView::toIntList(const QVariantList &list)
{
QList<int> ret;
diff --git a/tests/auto/quick/qquicklistview/data/header.qml b/tests/auto/quick/qquicklistview/data/header.qml
index bf70310630..1cc4ae09ee 100644
--- a/tests/auto/quick/qquicklistview/data/header.qml
+++ b/tests/auto/quick/qquicklistview/data/header.qml
@@ -15,7 +15,7 @@ Rectangle {
height: 30
width: 240
Text {
- text: index + " " + x + "," + y
+ text: index + " " + parent.x + "," + parent.y
}
color: ListView.isCurrentItem ? "lightsteelblue" : "white"
}
diff --git a/tests/auto/quick/qquicklistview/data/headerfooter.qml b/tests/auto/quick/qquicklistview/data/headerfooter.qml
index 4c3eeca328..07a331a4b7 100644
--- a/tests/auto/quick/qquicklistview/data/headerfooter.qml
+++ b/tests/auto/quick/qquicklistview/data/headerfooter.qml
@@ -2,27 +2,24 @@ import QtQuick 2.0
ListView {
id: view
- property bool horizontal: false
- property bool rtl: false
+
width: 240
height: 320
model: testModel
-
- orientation: horizontal ? ListView.Horizontal : ListView.Vertical
+
header: Rectangle {
objectName: "header"
- width: horizontal ? 20 : view.width
- height: horizontal ? view.height : 20
+ width: orientation == ListView.Horizontal ? 20 : view.width
+ height: orientation == ListView.Horizontal ? view.height : 20
color: "red"
}
footer: Rectangle {
objectName: "footer"
- width: horizontal ? 30 : view.width
- height: horizontal ? view.height : 30
+ width: orientation == ListView.Horizontal ? 30 : view.width
+ height: orientation == ListView.Horizontal ? view.height : 30
color: "blue"
}
delegate: Text { width: 30; height: 30; text: index + "(" + x + ")" }
- layoutDirection: rtl ? Qt.RightToLeft : Qt.LeftToRight
}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 1ef895d111..3369cf7933 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -58,7 +58,9 @@
#include <math.h>
Q_DECLARE_METATYPE(Qt::LayoutDirection)
+Q_DECLARE_METATYPE(QQuickItemView::VerticalLayoutDirection)
Q_DECLARE_METATYPE(QQuickListView::Orientation)
+Q_DECLARE_METATYPE(Qt::Key)
using namespace QQuickViewTestUtil;
using namespace QQuickVisualTestUtil;
@@ -89,6 +91,8 @@ private slots:
void qAbstractItemModel_inserted();
void qAbstractItemModel_inserted_more();
void qAbstractItemModel_inserted_more_data();
+ void qAbstractItemModel_inserted_more_bottomToTop();
+ void qAbstractItemModel_inserted_more_bottomToTop_data();
void qListModelInterface_removed();
void qListModelInterface_removed_more();
@@ -97,6 +101,8 @@ private slots:
void qAbstractItemModel_removed();
void qAbstractItemModel_removed_more();
void qAbstractItemModel_removed_more_data();
+ void qAbstractItemModel_removed_more_bottomToTop();
+ void qAbstractItemModel_removed_more_bottomToTop_data();
void qListModelInterface_moved();
void qListModelInterface_moved_data();
@@ -104,13 +110,18 @@ private slots:
void qListModelInterface_package_moved_data();
void qAbstractItemModel_moved();
void qAbstractItemModel_moved_data();
+ void qAbstractItemModel_moved_bottomToTop();
+ void qAbstractItemModel_moved_bottomToTop_data();
- void multipleChanges();
- void multipleChanges_data();
+ void multipleChanges_condensed() { multipleChanges(true); }
+ void multipleChanges_condensed_data() { multipleChanges_data(); }
+ void multipleChanges_uncondensed() { multipleChanges(false); }
+ void multipleChanges_uncondensed_data() { multipleChanges_data(); }
void qListModelInterface_clear();
void qListModelInterface_package_clear();
void qAbstractItemModel_clear();
+ void qAbstractItemModel_clear_bottomToTop();
void insertBeforeVisible();
void insertBeforeVisible_data();
@@ -120,6 +131,8 @@ private slots:
void currentIndex_delayedItemCreation_data();
void currentIndex();
void noCurrentIndex();
+ void keyNavigation();
+ void keyNavigation_data();
void enforceRange();
void enforceRange_withoutHighlight();
void spacing();
@@ -142,6 +155,8 @@ private slots:
void footer();
void footer_data();
void headerFooter();
+ void headerFooter_data();
+ void resetModel_headerFooter();
void resizeView();
void resizeViewAndRepaint();
void sizeLessThan1();
@@ -195,13 +210,16 @@ private:
template <class T> void items(const QUrl &source, bool forceLayout);
template <class T> void changed(const QUrl &source, bool forceLayout);
template <class T> void inserted(const QUrl &source);
- template <class T> void inserted_more();
+ template <class T> void inserted_more(QQuickItemView::VerticalLayoutDirection verticalLayoutDirection = QQuickItemView::TopToBottom);
template <class T> void removed(const QUrl &source, bool animated);
- template <class T> void removed_more(const QUrl &source);
- template <class T> void moved(const QUrl &source);
- template <class T> void clear(const QUrl &source);
+ template <class T> void removed_more(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection = QQuickItemView::TopToBottom);
+ template <class T> void moved(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection = QQuickItemView::TopToBottom);
+ template <class T> void clear(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection = QQuickItemView::TopToBottom);
template <class T> void sections(const QUrl &source);
+ void multipleChanges(bool condensed);
+ void multipleChanges_data();
+
QList<int> toIntList(const QVariantList &list);
void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes);
void matchItemsAndIndexes(const QVariantMap &items, const QaimModel &model, const QList<int> &expectedIndexes);
@@ -522,7 +540,7 @@ void tst_QQuickListView::inserted(const QUrl &source)
}
template <class T>
-void tst_QQuickListView::inserted_more()
+void tst_QQuickListView::inserted_more(QQuickItemView::VerticalLayoutDirection verticalLayoutDirection)
{
QFETCH(qreal, contentY);
QFETCH(int, insertIndex);
@@ -550,8 +568,15 @@ void tst_QQuickListView::inserted_more()
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
+ bool waitForPolish = (contentY != 0);
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop) {
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ contentY = -listview->height() - contentY;
+ }
listview->setContentY(contentY);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ if (waitForPolish)
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
QList<QPair<QString, QString> > newData;
for (int i=0; i<insertCount; i++)
@@ -562,27 +587,32 @@ void tst_QQuickListView::inserted_more()
// check visibleItems.first() is in correct position
QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
QVERIFY(item0);
- QCOMPARE(item0->y(), itemsOffsetAfterMove);
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ QCOMPARE(item0->y(), -item0->height() - itemsOffsetAfterMove);
+ else
+ QCOMPARE(item0->y(), itemsOffsetAfterMove);
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
- QQmlExpression e(qmlContext(items[i]), items[i], "index");
- firstVisibleIndex = e.evaluate().toInt();
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (item && item->isVisible()) {
+ firstVisibleIndex = i;
break;
}
}
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// Confirm items positioned correctly and indexes correct
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
QQuickText *name;
QQuickText *number;
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
- QTRY_COMPARE(item->y(), i*20.0 + itemsOffsetAfterMove);
+ qreal pos = i*20.0 + itemsOffsetAfterMove;
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ pos = -item0->height() - pos;
+ QTRY_COMPARE(item->y(), pos);
name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
@@ -952,15 +982,13 @@ void tst_QQuickListView::removed(const QUrl &source, bool /* animated */)
}
template <class T>
-void tst_QQuickListView::removed_more(const QUrl &source)
+void tst_QQuickListView::removed_more(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection)
{
QFETCH(qreal, contentY);
QFETCH(int, removeIndex);
QFETCH(int, removeCount);
QFETCH(qreal, itemsOffsetAfterMove);
- QQuickText *name;
- QQuickText *number;
QQuickView *canvas = getView();
T model;
@@ -983,13 +1011,15 @@ void tst_QQuickListView::removed_more(const QUrl &source)
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
+ bool waitForPolish = (contentY != 0);
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop) {
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ contentY = -listview->height() - contentY;
+ }
listview->setContentY(contentY);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
-
- // wait for refill (after refill, items above the firstVisibleIndex-1 should not be rendered)
- int firstVisibleIndex = contentY / 20;
- if (firstVisibleIndex - 2 >= 0)
- QTRY_VERIFY(!findItem<QQuickText>(contentItem, "textName", firstVisibleIndex - 2));
+ if (waitForPolish)
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
model.removeItems(removeIndex, removeCount);
QTRY_COMPARE(listview->property("count").toInt(), model.count());
@@ -997,24 +1027,33 @@ void tst_QQuickListView::removed_more(const QUrl &source)
// check visibleItems.first() is in correct position
QQuickItem *item0 = findItem<QQuickItem>(contentItem, "wrapper", 0);
QVERIFY(item0);
- QCOMPARE(item0->y(), itemsOffsetAfterMove);
+ QVERIFY(item0);
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ QCOMPARE(item0->y(), -item0->height() - itemsOffsetAfterMove);
+ else
+ QCOMPARE(item0->y(), itemsOffsetAfterMove);
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
+ int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
- QQmlExpression e(qmlContext(items[i]), items[i], "index");
- firstVisibleIndex = e.evaluate().toInt();
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (item && item->isVisible()) {
+ firstVisibleIndex = i;
break;
}
}
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// Confirm items positioned correctly and indexes correct
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
+ QQuickText *name;
+ QQuickText *number;
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
- QTRY_COMPARE(item->y(), i*20.0 + itemsOffsetAfterMove);
+ qreal pos = i*20.0 + itemsOffsetAfterMove;
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ pos = -item0->height() - pos;
+ QTRY_COMPARE(item->y(), pos);
name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
@@ -1131,7 +1170,7 @@ void tst_QQuickListView::removed_more_data()
}
template <class T>
-void tst_QQuickListView::clear(const QUrl &source)
+void tst_QQuickListView::clear(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection)
{
QQuickView *canvas = createView();
@@ -1153,13 +1192,19 @@ void tst_QQuickListView::clear(const QUrl &source)
QTRY_VERIFY(listview != 0);
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
+
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
model.clear();
+ QTRY_COMPARE(findItems<QQuickListView>(contentItem, "wrapper").count(), 0);
QTRY_VERIFY(listview->count() == 0);
QTRY_VERIFY(listview->currentItem() == 0);
- QTRY_VERIFY(listview->contentY() == 0);
+ if (verticalLayoutDirection == QQuickItemView::TopToBottom)
+ QTRY_COMPARE(listview->contentY(), 0.0);
+ else
+ QTRY_COMPARE(listview->contentY(), -listview->height());
QVERIFY(listview->currentIndex() == -1);
// confirm sanity when adding an item to cleared list
@@ -1173,7 +1218,7 @@ void tst_QQuickListView::clear(const QUrl &source)
}
template <class T>
-void tst_QQuickListView::moved(const QUrl &source)
+void tst_QQuickListView::moved(const QUrl &source, QQuickItemView::VerticalLayoutDirection verticalLayoutDirection)
{
QFETCH(qreal, contentY);
QFETCH(int, from);
@@ -1204,15 +1249,19 @@ void tst_QQuickListView::moved(const QUrl &source)
QTRY_VERIFY(listview != 0);
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- QQuickItem *currentItem = listview->currentItem();
- QTRY_VERIFY(currentItem != 0);
+ // always need to wait for view to be painted before the first move()
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- if (contentY != 0) {
- listview->setContentY(contentY);
+ bool waitForPolish = (contentY != 0);
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop) {
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ contentY = -listview->height() - contentY;
}
+ listview->setContentY(contentY);
+ if (waitForPolish)
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
model.moveItems(from, to, count);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
@@ -1220,22 +1269,22 @@ void tst_QQuickListView::moved(const QUrl &source)
QList<QQuickItem*> items = findItems<QQuickItem>(contentItem, "wrapper");
int firstVisibleIndex = -1;
for (int i=0; i<items.count(); i++) {
- if (items[i]->y() >= contentY) {
- QQmlExpression e(qmlContext(items[i]), items[i], "index");
- firstVisibleIndex = e.evaluate().toInt();
+ QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
+ if (item && item->isVisible()) {
+ firstVisibleIndex = i;
break;
}
}
QVERIFY2(firstVisibleIndex >= 0, QTest::toString(firstVisibleIndex));
// Confirm items positioned correctly and indexes correct
- int itemCount = findItems<QQuickItem>(contentItem, "wrapper").count();
- for (int i = firstVisibleIndex; i < model.count() && i < itemCount; ++i) {
- if (i >= firstVisibleIndex + 16) // index has moved out of view
- continue;
+ for (int i = firstVisibleIndex; i < model.count() && i < items.count(); ++i) {
QQuickItem *item = findItem<QQuickItem>(contentItem, "wrapper", i);
QVERIFY2(item, QTest::toString(QString("Item %1 not found").arg(i)));
- QTRY_COMPARE(item->y(), i*20.0 + itemsOffsetAfterMove);
+ qreal pos = i*20.0 + itemsOffsetAfterMove;
+ if (verticalLayoutDirection == QQuickItemView::BottomToTop)
+ pos = -item->height() - pos;
+ QTRY_COMPARE(item->y(), pos);
name = findItem<QQuickText>(contentItem, "textName", i);
QVERIFY(name != 0);
QTRY_COMPARE(name->text(), model.name(i));
@@ -1244,7 +1293,7 @@ void tst_QQuickListView::moved(const QUrl &source)
QTRY_COMPARE(number->text(), model.number(i));
// current index should have been updated
- if (item == currentItem)
+ if (item == listview->currentItem())
QTRY_COMPARE(listview->currentIndex(), i);
}
@@ -1403,7 +1452,7 @@ void tst_QQuickListView::moved_data()
<< -20.0 * 3; // to minimize movement, 16,17,18 move to above item 0, and other items do not move
}
-void tst_QQuickListView::multipleChanges()
+void tst_QQuickListView::multipleChanges(bool condensed)
{
QFETCH(int, startCount);
QFETCH(QList<ListChange>, changes);
@@ -1439,31 +1488,32 @@ void tst_QQuickListView::multipleChanges()
for (int j=changes[i].index; j<changes[i].index + changes[i].count; ++j)
items << qMakePair(QString("new item %1").arg(j), QString::number(j));
model.insertItems(changes[i].index, items);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
}
case ListChange::Removed:
model.removeItems(changes[i].index, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::Moved:
model.moveItems(changes[i].index, changes[i].to, changes[i].count);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::SetCurrent:
listview->setCurrentIndex(changes[i].index);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
case ListChange::SetContentY:
listview->setContentY(changes[i].pos);
- QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
break;
+ default:
+ continue;
+ }
+ if (!condensed) {
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
}
}
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- QTRY_COMPARE(listview->count(), newCount);
+ QCOMPARE(listview->count(), newCount);
QCOMPARE(listview->count(), model.count());
- QTRY_COMPARE(listview->currentIndex(), newCurrentIndex);
+ QCOMPARE(listview->currentIndex(), newCurrentIndex);
QQuickText *name;
QQuickText *number;
@@ -1626,13 +1676,34 @@ void tst_QQuickListView::multipleChanges_data()
<< ListChange::insert(3, 5)
) << 15 << 8;
-
QTest::newRow("clear current") << 0 << (QList<ListChange>()
<< ListChange::insert(0, 5)
<< ListChange::setCurrent(-1)
<< ListChange::remove(0, 5)
<< ListChange::insert(0, 5)
) << 5 << -1;
+
+ QTest::newRow("remove, scroll") << 30 << (QList<ListChange>()
+ << ListChange::remove(20, 5)
+ << ListChange::setContentY(20)
+ ) << 25 << 0;
+
+ QTest::newRow("insert, scroll") << 10 << (QList<ListChange>()
+ << ListChange::insert(9, 5)
+ << ListChange::setContentY(20)
+ ) << 15 << 0;
+
+ QTest::newRow("move, scroll") << 20 << (QList<ListChange>()
+ << ListChange::move(15, 8, 3)
+ << ListChange::setContentY(0)
+ ) << 20 << 0;
+
+ QTest::newRow("clear, insert, scroll") << 30 << (QList<ListChange>()
+ << ListChange::setContentY(20)
+ << ListChange::remove(0, 30)
+ << ListChange::insert(0, 2)
+ << ListChange::setContentY(0)
+ ) << 2 << 0;
}
void tst_QQuickListView::swapWithFirstItem()
@@ -2313,35 +2384,11 @@ void tst_QQuickListView::currentIndex()
QCOMPARE(listview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 20));
QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y());
- // no wrap
listview->setCurrentIndex(0);
QCOMPARE(listview->currentIndex(), 0);
// confirm that the velocity is updated
QTRY_VERIFY(listview->verticalVelocity() != 0.0);
- listview->incrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 1);
- listview->decrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 0);
-
- listview->decrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 0);
-
- // with wrap
- ctxt->setContextProperty("testWrap", QVariant(true));
- QVERIFY(listview->isWrapEnabled());
-
- listview->decrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), model.count()-1);
-
- QTRY_COMPARE(listview->contentY(), 280.0);
-
- listview->incrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 0);
-
- QTRY_COMPARE(listview->contentY(), 0.0);
-
-
// footer should become visible if it is out of view, and then current index is set to count-1
canvas->rootObject()->setProperty("showFooter", true);
QTRY_VERIFY(listview->footerItem());
@@ -2360,40 +2407,6 @@ void tst_QQuickListView::currentIndex()
QTRY_COMPARE(listview->contentY(), -listview->headerItem()->height());
canvas->rootObject()->setProperty("showHeader", false);
-
- // Test keys
- canvas->show();
- canvas->requestActivateWindow();
- QTest::qWaitForWindowShown(canvas);
- QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
-
- listview->setCurrentIndex(0);
-
- QTest::keyClick(canvas, Qt::Key_Down);
- QCOMPARE(listview->currentIndex(), 1);
-
- QTest::keyClick(canvas, Qt::Key_Up);
- QCOMPARE(listview->currentIndex(), 0);
-
- // hold down Key_Down
- for (int i=0; i<model.count()-1; i++) {
- QTest::simulateEvent(canvas, true, Qt::Key_Down, Qt::NoModifier, "", true);
- QTRY_COMPARE(listview->currentIndex(), i+1);
- }
- QTest::keyRelease(canvas, Qt::Key_Down);
- QTRY_COMPARE(listview->currentIndex(), model.count()-1);
- QTRY_COMPARE(listview->contentY(), 280.0);
-
- // hold down Key_Up
- for (int i=model.count()-1; i > 0; i--) {
- QTest::simulateEvent(canvas, true, Qt::Key_Up, Qt::NoModifier, "", true);
- QTRY_COMPARE(listview->currentIndex(), i-1);
- }
- QTest::keyRelease(canvas, Qt::Key_Up);
- QTRY_COMPARE(listview->currentIndex(), 0);
- QTRY_COMPARE(listview->contentY(), 0.0);
-
-
// turn off auto highlight
listview->setHighlightFollowsCurrentItem(false);
QVERIFY(listview->highlightFollowsCurrentItem() == false);
@@ -2416,6 +2429,7 @@ void tst_QQuickListView::currentIndex()
QVERIFY(!listview->highlightItem());
QVERIFY(!listview->currentItem());
+ // moving currentItem out of view should make it invisible
listview->setCurrentIndex(0);
QTRY_VERIFY(listview->currentItem()->isVisible());
listview->setContentY(200);
@@ -2462,6 +2476,129 @@ void tst_QQuickListView::noCurrentIndex()
delete canvas;
}
+void tst_QQuickListView::keyNavigation()
+{
+ QFETCH(QQuickListView::Orientation, orientation);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+ QFETCH(Qt::Key, forwardsKey);
+ QFETCH(Qt::Key, backwardsKey);
+ QFETCH(QPointF, contentPosAtFirstItem);
+ QFETCH(QPointF, contentPosAtLastItem);
+
+ QmlListModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QQuickView *canvas = getView();
+ TestObject *testObject = new TestObject;
+ canvas->rootContext()->setContextProperty("testModel", &model);
+ canvas->rootContext()->setContextProperty("testObject", testObject);
+ canvas->setSource(testFileUrl("listviewtest.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickListView *listview = findItem<QQuickListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ listview->setOrientation(orientation);
+ listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+ canvas->requestActivateWindow();
+ QTRY_VERIFY(qGuiApp->focusWindow() == canvas);
+ QCOMPARE(listview->currentIndex(), 0);
+
+ QTest::keyClick(canvas, forwardsKey);
+ QCOMPARE(listview->currentIndex(), 1);
+
+ QTest::keyClick(canvas, backwardsKey);
+ QCOMPARE(listview->currentIndex(), 0);
+
+ // hold down a key to go forwards
+ for (int i=0; i<model.count()-1; i++) {
+ QTest::simulateEvent(canvas, true, forwardsKey, Qt::NoModifier, "", true);
+ QTRY_COMPARE(listview->currentIndex(), i+1);
+ }
+ QTest::keyRelease(canvas, forwardsKey);
+ QTRY_COMPARE(listview->currentIndex(), model.count()-1);
+ QTRY_COMPARE(listview->contentX(), contentPosAtLastItem.x());
+ QTRY_COMPARE(listview->contentY(), contentPosAtLastItem.y());
+
+ // hold down a key to go backwards
+ for (int i=model.count()-1; i > 0; i--) {
+ QTest::simulateEvent(canvas, true, backwardsKey, Qt::NoModifier, "", true);
+ QTRY_COMPARE(listview->currentIndex(), i-1);
+ }
+ QTest::keyRelease(canvas, backwardsKey);
+ QTRY_COMPARE(listview->currentIndex(), 0);
+ QTRY_COMPARE(listview->contentX(), contentPosAtFirstItem.x());
+ QTRY_COMPARE(listview->contentY(), contentPosAtFirstItem.y());
+
+ // no wrap
+ QVERIFY(!listview->isWrapEnabled());
+ listview->incrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 1);
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+
+ // with wrap
+ listview->setWrapEnabled(true);
+ QVERIFY(listview->isWrapEnabled());
+
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), model.count()-1);
+ QTRY_COMPARE(listview->contentX(), contentPosAtLastItem.x());
+ QTRY_COMPARE(listview->contentY(), contentPosAtLastItem.y());
+
+ listview->incrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+ QTRY_COMPARE(listview->contentX(), contentPosAtFirstItem.x());
+ QTRY_COMPARE(listview->contentY(), contentPosAtFirstItem.y());
+
+ releaseView(canvas);
+ delete testObject;
+}
+
+void tst_QQuickListView::keyNavigation_data()
+{
+ QTest::addColumn<QQuickListView::Orientation>("orientation");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+ QTest::addColumn<Qt::Key>("forwardsKey");
+ QTest::addColumn<Qt::Key>("backwardsKey");
+ QTest::addColumn<QPointF>("contentPosAtFirstItem");
+ QTest::addColumn<QPointF>("contentPosAtLastItem");
+
+ QTest::newRow("Vertical, TopToBottom")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << Qt::Key_Down << Qt::Key_Up
+ << QPointF(0, 0)
+ << QPointF(0, 30*20 - 320);
+
+ QTest::newRow("Vertical, BottomToTop")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << Qt::Key_Up << Qt::Key_Down
+ << QPointF(0, -320)
+ << QPointF(0, -(30 * 20));
+
+ QTest::newRow("Horizontal, LeftToRight")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << Qt::Key_Right << Qt::Key_Left
+ << QPointF(0, 0)
+ << QPointF(30*240 - 240, 0);
+
+ QTest::newRow("Horizontal, RightToLeft")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << Qt::Key_Left << Qt::Key_Right
+ << QPointF(-240, 0)
+ << QPointF(-(30 * 240), 0);
+}
+
void tst_QQuickListView::itemList()
{
QQuickView *canvas = createView();
@@ -3083,11 +3220,12 @@ void tst_QQuickListView::header()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(QPointF, initialHeaderPos);
- QFETCH(QPointF, firstDelegatePos);
- QFETCH(QPointF, initialContentPos);
QFETCH(QPointF, changedHeaderPos);
+ QFETCH(QPointF, initialContentPos);
QFETCH(QPointF, changedContentPos);
+ QFETCH(QPointF, firstDelegatePos);
QFETCH(QPointF, resizeContentPos);
QmlListModel model;
@@ -3106,6 +3244,8 @@ void tst_QQuickListView::header()
QTRY_VERIFY(listview != 0);
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
QQuickItem *contentItem = listview->contentItem();
QTRY_VERIFY(contentItem != 0);
@@ -3156,6 +3296,11 @@ void tst_QQuickListView::header()
QVERIFY(item);
QCOMPARE(item->pos(), firstDelegatePos);
+ listview->positionViewAtBeginning();
+ header->setHeight(10);
+ header->setWidth(40);
+ QTRY_COMPARE(QPointF(listview->contentX(), listview->contentY()), resizeContentPos);
+
releaseView(canvas);
@@ -3173,6 +3318,7 @@ void tst_QQuickListView::header()
QTRY_VERIFY(listview != 0);
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
listview->setWidth(240);
@@ -3187,6 +3333,7 @@ void tst_QQuickListView::header_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<QPointF>("initialHeaderPos");
QTest::addColumn<QPointF>("changedHeaderPos");
QTest::addColumn<QPointF>("initialContentPos");
@@ -3196,11 +3343,11 @@ void tst_QQuickListView::header_data()
// header1 = 100 x 30
// header2 = 50 x 20
- // delegates = 240 x 20
+ // delegates = 240 x 30
// view width = 240
// header above items, top left
- QTest::newRow("vertical, left to right") << QQuickListView::Vertical << Qt::LeftToRight
+ QTest::newRow("vertical, left to right") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(0, -30)
<< QPointF(0, -20)
<< QPointF(0, -30)
@@ -3209,7 +3356,7 @@ void tst_QQuickListView::header_data()
<< QPointF(0, -10);
// header above items, top right
- QTest::newRow("vertical, layout right to left") << QQuickListView::Vertical << Qt::RightToLeft
+ QTest::newRow("vertical, layout right to left") << QQuickListView::Vertical << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(0, -30)
<< QPointF(0, -20)
<< QPointF(0, -30)
@@ -3218,7 +3365,7 @@ void tst_QQuickListView::header_data()
<< QPointF(0, -10);
// header to left of items
- QTest::newRow("horizontal, layout left to right") << QQuickListView::Horizontal << Qt::LeftToRight
+ QTest::newRow("horizontal, layout left to right") << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(-100, 0)
<< QPointF(-50, 0)
<< QPointF(-100, 0)
@@ -3227,13 +3374,22 @@ void tst_QQuickListView::header_data()
<< QPointF(-40, 0);
// header to right of items
- QTest::newRow("horizontal, layout right to left") << QQuickListView::Horizontal << Qt::RightToLeft
+ QTest::newRow("horizontal, layout right to left") << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(0, 0)
<< QPointF(0, 0)
<< QPointF(-240 + 100, 0)
<< QPointF(-240 + 50, 0)
<< QPointF(-240, 0)
<< QPointF(-240 + 40, 0);
+
+ // header below items
+ QTest::newRow("vertical, bottom to top") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, 0)
+ << QPointF(0, 0)
+ << QPointF(0, -320 + 30)
+ << QPointF(0, -320 + 20)
+ << QPointF(0, -30)
+ << QPointF(0, -320 + 10);
}
void tst_QQuickListView::header_delayItemCreation()
@@ -3268,6 +3424,7 @@ void tst_QQuickListView::footer()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(QPointF, initialFooterPos);
QFETCH(QPointF, firstDelegatePos);
QFETCH(QPointF, initialContentPos);
@@ -3292,6 +3449,7 @@ void tst_QQuickListView::footer()
QTRY_VERIFY(listview != 0);
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
QQuickItem *contentItem = listview->contentItem();
@@ -3320,7 +3478,8 @@ void tst_QQuickListView::footer()
model.removeItem(1);
if (orientation == QQuickListView::Vertical) {
- QTRY_COMPARE(footer->y(), initialFooterPos.y() - 20); // delegate height = 20
+ QTRY_COMPARE(footer->y(), verticalLayoutDirection == QQuickItemView::TopToBottom ?
+ initialFooterPos.y() - 20 : initialFooterPos.y() + 20); // delegate width = 40
} else {
QTRY_COMPARE(footer->x(), layoutDirection == Qt::LeftToRight ?
initialFooterPos.x() - 40 : initialFooterPos.x() + 40); // delegate width = 40
@@ -3332,6 +3491,8 @@ void tst_QQuickListView::footer()
QPointF posWhenNoItems(0, 0);
if (orientation == QQuickListView::Horizontal && layoutDirection == Qt::RightToLeft)
posWhenNoItems.setX(-100);
+ else if (orientation == QQuickListView::Vertical && verticalLayoutDirection == QQuickItemView::BottomToTop)
+ posWhenNoItems.setY(-30);
QTRY_COMPARE(footer->pos(), posWhenNoItems);
// if header is present, it's at a negative pos, so the footer should not move
@@ -3376,6 +3537,7 @@ void tst_QQuickListView::footer_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<QPointF>("initialFooterPos");
QTest::addColumn<QPointF>("changedFooterPos");
QTest::addColumn<QPointF>("initialContentPos");
@@ -3390,7 +3552,7 @@ void tst_QQuickListView::footer_data()
// view height = 320
// footer below items, bottom left
- QTest::newRow("vertical, layout left to right") << QQuickListView::Vertical << Qt::LeftToRight
+ QTest::newRow("vertical, layout left to right") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(0, 3 * 20)
<< QPointF(0, 30 * 20) // added 30 items
<< QPointF(0, 0)
@@ -3399,7 +3561,7 @@ void tst_QQuickListView::footer_data()
<< QPointF(0, 30 * 20 - 320 + 10);
// footer below items, bottom right
- QTest::newRow("vertical, layout right to left") << QQuickListView::Vertical << Qt::RightToLeft
+ QTest::newRow("vertical, layout right to left") << QQuickListView::Vertical << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(0, 3 * 20)
<< QPointF(0, 30 * 20)
<< QPointF(0, 0)
@@ -3408,7 +3570,7 @@ void tst_QQuickListView::footer_data()
<< QPointF(0, 30 * 20 - 320 + 10);
// footer to right of items
- QTest::newRow("horizontal, layout left to right") << QQuickListView::Horizontal << Qt::LeftToRight
+ QTest::newRow("horizontal, layout left to right") << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(40 * 3, 0)
<< QPointF(40 * 30, 0)
<< QPointF(0, 0)
@@ -3417,13 +3579,22 @@ void tst_QQuickListView::footer_data()
<< QPointF(40 * 30 - 240 + 40, 0);
// footer to left of items
- QTest::newRow("horizontal, layout right to left") << QQuickListView::Horizontal << Qt::RightToLeft
+ QTest::newRow("horizontal, layout right to left") << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
<< QPointF(-(40 * 3) - 100, 0)
<< QPointF(-(40 * 30) - 50, 0) // 50 = new footer width
<< QPointF(-240, 0)
<< QPointF(-240, 0)
<< QPointF(-40, 0)
<< QPointF(-(40 * 30) - 40, 0);
+
+ // footer above items
+ QTest::newRow("vertical, layout left to right") << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, -(3 * 20) - 30)
+ << QPointF(0, -(30 * 20) - 20)
+ << QPointF(0, -320)
+ << QPointF(0, -320)
+ << QPointF(0, -20)
+ << QPointF(0, -(30 * 20) - 10);
}
class LVAccessor : public QQuickListView
@@ -3435,140 +3606,127 @@ public:
qreal maxX() const { return maxXExtent(); }
};
+
void tst_QQuickListView::headerFooter()
{
- {
- // Vertical
- QQuickView *canvas = createView();
-
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->setSource(testFileUrl("headerfooter.qml"));
- qApp->processEvents();
-
- QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
- QTRY_VERIFY(listview != 0);
-
- QQuickItem *contentItem = listview->contentItem();
- QTRY_VERIFY(contentItem != 0);
-
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
-
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 0.);
-
- QCOMPARE(static_cast<LVAccessor*>(listview)->minY(), header->height());
- QCOMPARE(static_cast<LVAccessor*>(listview)->maxY(), header->height());
-
- delete canvas;
- }
- {
- // Horizontal
- QQuickView *canvas = createView();
-
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
-
- canvas->setSource(testFileUrl("headerfooter.qml"));
- canvas->rootObject()->setProperty("horizontal", true);
- qApp->processEvents();
-
- QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
- QTRY_VERIFY(listview != 0);
-
- QQuickItem *contentItem = listview->contentItem();
- QTRY_VERIFY(contentItem != 0);
-
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->x(), -header->width());
+ QFETCH(QQuickListView::Orientation, orientation);
+ QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
+ QFETCH(QPointF, headerPos);
+ QFETCH(QPointF, footerPos);
+ QFETCH(QPointF, minPos);
+ QFETCH(QPointF, maxPos);
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->x(), 0.);
+ QQuickView *canvas = getView();
- QCOMPARE(static_cast<LVAccessor*>(listview)->minX(), header->width());
- QCOMPARE(static_cast<LVAccessor*>(listview)->maxX(), header->width());
+ QmlListModel model;
+ QQmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ canvas->setSource(testFileUrl("headerfooter.qml"));
+ canvas->show();
+ qApp->processEvents();
- delete canvas;
- }
- {
- // Horizontal RTL
- QQuickView *canvas = createView();
+ QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
+ QTRY_VERIFY(listview != 0);
+ listview->setOrientation(orientation);
+ listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- QmlListModel model;
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ QQuickItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
- canvas->setSource(testFileUrl("headerfooter.qml"));
- canvas->rootObject()->setProperty("horizontal", true);
- canvas->rootObject()->setProperty("rtl", true);
- qApp->processEvents();
+ QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->pos(), headerPos);
- QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
- QTRY_VERIFY(listview != 0);
+ QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->pos(), footerPos);
- QQuickItem *contentItem = listview->contentItem();
- QTRY_VERIFY(contentItem != 0);
+ QCOMPARE(static_cast<LVAccessor*>(listview)->minX(), minPos.x());
+ QCOMPARE(static_cast<LVAccessor*>(listview)->minY(), minPos.y());
+ QCOMPARE(static_cast<LVAccessor*>(listview)->maxX(), maxPos.x());
+ QCOMPARE(static_cast<LVAccessor*>(listview)->maxY(), maxPos.y());
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->x(), 0.);
+ releaseView(canvas);
+}
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->x(), -footer->width());
+void tst_QQuickListView::headerFooter_data()
+{
+ QTest::addColumn<QQuickListView::Orientation>("orientation");
+ QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
+ QTest::addColumn<QPointF>("headerPos");
+ QTest::addColumn<QPointF>("footerPos");
+ QTest::addColumn<QPointF>("minPos");
+ QTest::addColumn<QPointF>("maxPos");
+
+ // header is 240x20 (or 20x320 in Horizontal orientation)
+ // footer is 240x30 (or 30x320 in Horizontal orientation)
+
+ QTest::newRow("Vertical, TopToBottom")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(0, -20) << QPointF(0, 0)
+ << QPointF(0, 20) << QPointF(240, 20);
+
+ QTest::newRow("Vertical, BottomToTop")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << QPointF(0, 0) << QPointF(0, -30)
+ << QPointF(0, 320 - 20) << QPointF(240, 320 - 20); // content flow is reversed
+
+
+ QTest::newRow("Horizontal, LeftToRight")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << QPointF(-20, 0) << QPointF(0, 0)
+ << QPointF(20, 0) << QPointF(20, 320);
+
+ QTest::newRow("Horizontal, RightToLeft")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << QPointF(0, 0) << QPointF(-30, 0)
+ << QPointF(240 - 20, 0) << QPointF(240 - 20, 320); // content flow is reversed
+}
- QCOMPARE(static_cast<LVAccessor*>(listview)->minX(), 240. - header->width());
- QCOMPARE(static_cast<LVAccessor*>(listview)->maxX(), 240. - header->width());
+void tst_QQuickListView::resetModel_headerFooter()
+{
+ // Resetting a model shouldn't crash in views with header/footer
- delete canvas;
- }
- {
- // Reset model
- QQuickView *canvas = createView();
+ QQuickView *canvas = createView();
- QaimModel model;
- for (int i = 0; i < 4; i++)
- model.addItem("Item" + QString::number(i), "");
- QQmlContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ QaimModel model;
+ for (int i = 0; i < 4; i++)
+ model.addItem("Item" + QString::number(i), "");
+ QQmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
- canvas->setSource(testFileUrl("headerfooter.qml"));
- qApp->processEvents();
+ canvas->setSource(testFileUrl("headerfooter.qml"));
+ qApp->processEvents();
- QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
- QTRY_VERIFY(listview != 0);
+ QQuickListView *listview = qobject_cast<QQuickListView*>(canvas->rootObject());
+ QTRY_VERIFY(listview != 0);
- QQuickItem *contentItem = listview->contentItem();
- QTRY_VERIFY(contentItem != 0);
+ QQuickItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
- QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
+ QQuickItem *header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), -header->height());
- QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 30.*4);
+ QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->y(), 30.*4);
- model.reset();
+ model.reset();
- header = findItem<QQuickItem>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), -header->height());
+ header = findItem<QQuickItem>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), -header->height());
- footer = findItem<QQuickItem>(contentItem, "footer");
- QVERIFY(footer);
- QCOMPARE(footer->y(), 30.*4);
+ footer = findItem<QQuickItem>(contentItem, "footer");
+ QVERIFY(footer);
+ QCOMPARE(footer->y(), 30.*4);
- delete canvas;
- }
+ delete canvas;
}
void tst_QQuickListView::resizeView()
@@ -4288,13 +4446,14 @@ void tst_QQuickListView::marginsResize()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(qreal, start);
QFETCH(qreal, end);
QPoint flickStart(20, 20);
QPoint flickEnd(20, 20);
if (orientation == QQuickListView::Vertical)
- flickStart.ry() += 180;
+ flickStart.ry() += (verticalLayoutDirection == QQuickItemView::TopToBottom) ? 180 : -180;
else
flickStart.rx() += (layoutDirection == Qt::LeftToRight) ? 180 : -180;
@@ -4309,6 +4468,7 @@ void tst_QQuickListView::marginsResize()
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
// view is resized after componentCompleted - top margin should still be visible
@@ -4354,20 +4514,34 @@ void tst_QQuickListView::marginsResize_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickListView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<qreal>("start");
QTest::addColumn<qreal>("end");
// in Right to Left mode, leftMargin still means leftMargin - it doesn't reverse to mean rightMargin
- QTest::newRow("vertical") << QQuickListView::Vertical << Qt::LeftToRight << -40.0 << 1020.0;
- QTest::newRow("horizontal") << QQuickListView::Horizontal << Qt::LeftToRight << -40.0 << 1020.0;
- QTest::newRow("horizontal, rtl") << QQuickListView::Horizontal << Qt::RightToLeft << -180.0 << -1240.0;
+ QTest::newRow("vertical")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
+ << -40.0 << 1020.0;
+
+ QTest::newRow("vertical, BottomToTop")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
+ << -180.0 << -1240.0;
+
+ QTest::newRow("horizontal")
+ << QQuickListView::Horizontal<< Qt::LeftToRight << QQuickItemView::TopToBottom
+ << -40.0 << 1020.0;
+
+ QTest::newRow("horizontal, rtl")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
+ << -180.0 << -1240.0;
}
void tst_QQuickListView::snapToItem_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<int>("highlightRangeMode");
QTest::addColumn<QPoint>("flickStart");
QTest::addColumn<QPoint>("flickEnd");
@@ -4375,22 +4549,36 @@ void tst_QQuickListView::snapToItem_data()
QTest::addColumn<qreal>("endExtent");
QTest::addColumn<qreal>("startExtent");
- QTest::newRow("vertical, left to right") << QQuickListView::Vertical << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, top to bottom")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 200) << QPoint(20, 20) << 60.0 << 560.0 << 0.0;
- QTest::newRow("horizontal, left to right") << QQuickListView::Horizontal << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, bottom to top")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop << int(QQuickItemView::NoHighlightRange)
+ << QPoint(20, 20) << QPoint(20, 200) << -60.0 << -560.0 - 240.0 << -240.0;
+
+ QTest::newRow("horizontal, left to right")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(200, 20) << QPoint(20, 20) << 60.0 << 560.0 << 0.0;
- QTest::newRow("horizontal, right to left") << QQuickListView::Horizontal << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, right to left")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 20) << QPoint(200, 20) << -60.0 << -560.0 - 240.0 << -240.0;
- QTest::newRow("vertical, left to right, enforce range") << QQuickListView::Vertical << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, top to bottom, enforce range")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 200) << QPoint(20, 20) << 60.0 << 700.0 << -20.0;
- QTest::newRow("horizontal, left to right, enforce range") << QQuickListView::Horizontal << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, bottom to top, enforce range")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop << int(QQuickItemView::StrictlyEnforceRange)
+ << QPoint(20, 20) << QPoint(20, 200) << -60.0 << -560.0 - 240.0 - 140.0 << -220.0;
+
+ QTest::newRow("horizontal, left to right, enforce range")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(200, 20) << QPoint(20, 20) << 60.0 << 700.0 << -20.0;
- QTest::newRow("horizontal, right to left, enforce range") << QQuickListView::Horizontal << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, right to left, enforce range")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 20) << QPoint(200, 20) << -60.0 << -560.0 - 240.0 - 140.0 << -220.0;
}
@@ -4398,6 +4586,7 @@ void tst_QQuickListView::snapToItem()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(int, highlightRangeMode);
QFETCH(QPoint, flickStart);
QFETCH(QPoint, flickEnd);
@@ -4416,6 +4605,7 @@ void tst_QQuickListView::snapToItem()
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
listview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode));
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
@@ -4435,7 +4625,7 @@ void tst_QQuickListView::snapToItem()
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(listview->isMoving() == false); // wait until it stops
} while (orientation == QQuickListView::Vertical
- ? !listview->isAtYEnd()
+ ? verticalLayoutDirection == QQuickItemView::TopToBottom ? !listview->isAtYEnd() : !listview->isAtYBeginning()
: layoutDirection == Qt::LeftToRight ? !listview->isAtXEnd() : !listview->isAtXBeginning());
if (orientation == QQuickListView::Vertical)
@@ -4448,7 +4638,7 @@ void tst_QQuickListView::snapToItem()
flick(canvas, flickEnd, flickStart, 180);
QTRY_VERIFY(listview->isMoving() == false); // wait until it stops
} while (orientation == QQuickListView::Vertical
- ? !listview->isAtYBeginning()
+ ? verticalLayoutDirection == QQuickItemView::TopToBottom ? !listview->isAtYBeginning() : !listview->isAtYEnd()
: layoutDirection == Qt::LeftToRight ? !listview->isAtXBeginning() : !listview->isAtXEnd());
if (orientation == QQuickListView::Vertical)
@@ -4524,6 +4714,16 @@ void tst_QQuickListView::qAbstractItemModel_inserted_more_data()
inserted_more_data();
}
+void tst_QQuickListView::qAbstractItemModel_inserted_more_bottomToTop()
+{
+ inserted_more<QaimModel>(QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickListView::qAbstractItemModel_inserted_more_bottomToTop_data()
+{
+ inserted_more_data();
+}
+
void tst_QQuickListView::qListModelInterface_removed()
{
removed<QmlListModel>(testFileUrl("listviewtest.qml"), false);
@@ -4562,6 +4762,16 @@ void tst_QQuickListView::qAbstractItemModel_removed_more_data()
removed_more_data();
}
+void tst_QQuickListView::qAbstractItemModel_removed_more_bottomToTop()
+{
+ removed_more<QaimModel>(testFileUrl("listviewtest.qml"), QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickListView::qAbstractItemModel_removed_more_bottomToTop_data()
+{
+ removed_more_data();
+}
+
void tst_QQuickListView::qListModelInterface_moved()
{
moved<QmlListModel>(testFileUrl("listviewtest.qml"));
@@ -4592,6 +4802,16 @@ void tst_QQuickListView::qAbstractItemModel_moved_data()
moved_data();
}
+void tst_QQuickListView::qAbstractItemModel_moved_bottomToTop()
+{
+ moved<QaimModel>(testFileUrl("listviewtest-package.qml"), QQuickItemView::BottomToTop);
+}
+
+void tst_QQuickListView::qAbstractItemModel_moved_bottomToTop_data()
+{
+ moved_data();
+}
+
void tst_QQuickListView::qListModelInterface_clear()
{
clear<QmlListModel>(testFileUrl("listviewtest.qml"));
@@ -4607,6 +4827,11 @@ void tst_QQuickListView::qAbstractItemModel_clear()
clear<QaimModel>(testFileUrl("listviewtest.qml"));
}
+void tst_QQuickListView::qAbstractItemModel_clear_bottomToTop()
+{
+ clear<QaimModel>(testFileUrl("listviewtest.qml"), QQuickItemView::BottomToTop);
+}
+
void tst_QQuickListView::qListModelInterface_sections()
{
sections<QmlListModel>(testFileUrl("listview-sections.qml"));
@@ -4705,6 +4930,7 @@ void tst_QQuickListView::snapOneItem_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
+ QTest::addColumn<QQuickItemView::VerticalLayoutDirection>("verticalLayoutDirection");
QTest::addColumn<int>("highlightRangeMode");
QTest::addColumn<QPoint>("flickStart");
QTest::addColumn<QPoint>("flickEnd");
@@ -4712,22 +4938,36 @@ void tst_QQuickListView::snapOneItem_data()
QTest::addColumn<qreal>("endExtent");
QTest::addColumn<qreal>("startExtent");
- QTest::newRow("vertical, left to right") << QQuickListView::Vertical << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, top to bottom")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 200) << QPoint(20, 20) << 180.0 << 560.0 << 0.0;
- QTest::newRow("horizontal, left to right") << QQuickListView::Horizontal << Qt::LeftToRight << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("vertical, bottom to top")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop << int(QQuickItemView::NoHighlightRange)
+ << QPoint(20, 20) << QPoint(20, 200) << -420.0 << -560.0 - 240.0 << -240.0;
+
+ QTest::newRow("horizontal, left to right")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(200, 20) << QPoint(20, 20) << 180.0 << 560.0 << 0.0;
- QTest::newRow("horizontal, right to left") << QQuickListView::Horizontal << Qt::RightToLeft << int(QQuickItemView::NoHighlightRange)
+ QTest::newRow("horizontal, right to left")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom << int(QQuickItemView::NoHighlightRange)
<< QPoint(20, 20) << QPoint(200, 20) << -420.0 << -560.0 - 240.0 << -240.0;
- QTest::newRow("vertical, left to right, enforce range") << QQuickListView::Vertical << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, top to bottom, enforce range")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 200) << QPoint(20, 20) << 180.0 << 580.0 << -20.0;
- QTest::newRow("horizontal, left to right, enforce range") << QQuickListView::Horizontal << Qt::LeftToRight << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("vertical, bottom to top, enforce range")
+ << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop << int(QQuickItemView::StrictlyEnforceRange)
+ << QPoint(20, 20) << QPoint(20, 200) << -420.0 << -580.0 - 240.0 << -220.0;
+
+ QTest::newRow("horizontal, left to right, enforce range")
+ << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(200, 20) << QPoint(20, 20) << 180.0 << 580.0 << -20.0;
- QTest::newRow("horizontal, right to left, enforce range") << QQuickListView::Horizontal << Qt::RightToLeft << int(QQuickItemView::StrictlyEnforceRange)
+ QTest::newRow("horizontal, right to left, enforce range")
+ << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom << int(QQuickItemView::StrictlyEnforceRange)
<< QPoint(20, 20) << QPoint(200, 20) << -420.0 << -580.0 - 240.0 << -220.0;
}
@@ -4735,6 +4975,7 @@ void tst_QQuickListView::snapOneItem()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
+ QFETCH(QQuickItemView::VerticalLayoutDirection, verticalLayoutDirection);
QFETCH(int, highlightRangeMode);
QFETCH(QPoint, flickStart);
QFETCH(QPoint, flickEnd);
@@ -4758,6 +4999,7 @@ void tst_QQuickListView::snapOneItem()
listview->setOrientation(orientation);
listview->setLayoutDirection(layoutDirection);
+ listview->setVerticalLayoutDirection(verticalLayoutDirection);
listview->setHighlightRangeMode(QQuickItemView::HighlightRangeMode(highlightRangeMode));
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
@@ -4784,7 +5026,7 @@ void tst_QQuickListView::snapOneItem()
flick(canvas, flickStart, flickEnd, 180);
QTRY_VERIFY(listview->isMoving() == false); // wait until it stops
} while (orientation == QQuickListView::Vertical
- ? !listview->isAtYEnd()
+ ? verticalLayoutDirection == QQuickItemView::TopToBottom ? !listview->isAtYEnd() : !listview->isAtYBeginning()
: layoutDirection == Qt::LeftToRight ? !listview->isAtXEnd() : !listview->isAtXBeginning());
if (orientation == QQuickListView::Vertical)
@@ -4802,7 +5044,7 @@ void tst_QQuickListView::snapOneItem()
flick(canvas, flickEnd, flickStart, 180);
QTRY_VERIFY(listview->isMoving() == false); // wait until it stops
} while (orientation == QQuickListView::Vertical
- ? !listview->isAtYBeginning()
+ ? verticalLayoutDirection == QQuickItemView::TopToBottom ? !listview->isAtYBeginning() : !listview->isAtYEnd()
: layoutDirection == Qt::LeftToRight ? !listview->isAtXBeginning() : !listview->isAtXEnd());
if (orientation == QQuickListView::Vertical)
@@ -6277,3 +6519,4 @@ QTEST_MAIN(tst_QQuickListView)
#include "tst_qquicklistview.moc"
+
diff --git a/tests/auto/quick/qquickpixmapcache/qquickpixmapcache.pro b/tests/auto/quick/qquickpixmapcache/qquickpixmapcache.pro
index a24ea52e11..831ffd3c35 100644
--- a/tests/auto/quick/qquickpixmapcache/qquickpixmapcache.pro
+++ b/tests/auto/quick/qquickpixmapcache/qquickpixmapcache.pro
@@ -15,6 +15,6 @@ TESTDATA = data/*
# LIBS += -lgcov
CONFIG += parallel_test
-CONFIG += insignificant_test
+CONFIG += insignificant_test # QTBUG-25307
QT += core-private gui-private qml-private quick-private network testlib concurrent
diff --git a/tests/auto/quick/qquickpositioners/qquickpositioners.pro b/tests/auto/quick/qquickpositioners/qquickpositioners.pro
index dbbfae0ebf..e4fce55548 100644
--- a/tests/auto/quick/qquickpositioners/qquickpositioners.pro
+++ b/tests/auto/quick/qquickpositioners/qquickpositioners.pro
@@ -1,4 +1,5 @@
CONFIG += testcase
+CONFIG += insignificant_test
TARGET = tst_qquickpositioners
SOURCES += tst_qquickpositioners.cpp
diff --git a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
index ae2bdc7fae..6ceacdfaf0 100644
--- a/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
+++ b/tests/auto/quick/qquickpositioners/tst_qquickpositioners.cpp
@@ -1875,11 +1875,15 @@ void tst_qquickpositioners::test_attachedproperties_dynamic()
QQuickView *tst_qquickpositioners::createView(const QString &filename, bool wait)
{
QQuickView *canvas = new QQuickView(0);
+ qDebug() << "1";
canvas->setSource(QUrl::fromLocalFile(filename));
+ qDebug() << "2";
canvas->show();
+ qDebug() << "3";
if (wait)
QTest::qWaitForWindowShown(canvas); //It may not relayout until the next frame, so it needs to be drawn
+ qDebug() << "4";
return canvas;
}
diff --git a/tests/auto/quick/qquickshadereffect/data/deleteShaderEffectSource.qml b/tests/auto/quick/qquickshadereffect/data/deleteShaderEffectSource.qml
new file mode 100644
index 0000000000..4e0eb4eb17
--- /dev/null
+++ b/tests/auto/quick/qquickshadereffect/data/deleteShaderEffectSource.qml
@@ -0,0 +1,74 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Particles 2.0
+
+Rectangle {
+ color: "black"
+ width: 320
+ height: 320
+
+ ShaderEffect {
+ id: sei
+ property variant source
+ }
+
+ ShaderEffectSource {
+ id: doomed
+ hideSource: true
+ sourceItem: Image {
+ source: "star.png"
+ }
+ }
+
+ function setDeletedShaderEffectSource() {
+ sei.source = doomed;
+ doomed.destroy();
+ // now set a fragment shader to trigger source texture detection.
+ sei.fragmentShader = "varying highp vec2 qt_TexCoord0;\
+ uniform sampler2D source;\
+ uniform lowp float qt_Opacity;\
+ void main() {\
+ gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity;\
+ }";
+ }
+}
diff --git a/tests/auto/quick/qquickshadereffect/data/deleteSourceItem.qml b/tests/auto/quick/qquickshadereffect/data/deleteSourceItem.qml
new file mode 100644
index 0000000000..ecf4cbd4bb
--- /dev/null
+++ b/tests/auto/quick/qquickshadereffect/data/deleteSourceItem.qml
@@ -0,0 +1,75 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+import QtQuick 2.0
+import QtQuick.Particles 2.0
+
+Rectangle {
+ color: "black"
+ width: 320
+ height: 320
+
+ ShaderEffect {
+ id: sei
+ property variant source
+ }
+
+ ShaderEffectSource {
+ id: doomedses
+ hideSource: true
+ sourceItem: Image {
+ id: doomed
+ source: "star.png"
+ }
+ }
+
+ function setDeletedSourceItem() {
+ doomed.destroy();
+ sei.source = doomedses;
+ // now set a fragment shader to trigger source texture detection.
+ sei.fragmentShader = "varying highp vec2 qt_TexCoord0;\
+ uniform sampler2D source;\
+ uniform lowp float qt_Opacity;\
+ void main() {\
+ gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity;\
+ }";
+ }
+}
diff --git a/tests/auto/quick/qquickshadereffect/data/star.png b/tests/auto/quick/qquickshadereffect/data/star.png
new file mode 100644
index 0000000000..0d592cfa87
--- /dev/null
+++ b/tests/auto/quick/qquickshadereffect/data/star.png
Binary files differ
diff --git a/tests/auto/quick/qquickshadereffect/qquickshadereffect.pro b/tests/auto/quick/qquickshadereffect/qquickshadereffect.pro
index 142d368aed..10aa3daecb 100644
--- a/tests/auto/quick/qquickshadereffect/qquickshadereffect.pro
+++ b/tests/auto/quick/qquickshadereffect/qquickshadereffect.pro
@@ -2,6 +2,7 @@ CONFIG += testcase
TARGET = tst_qquickshadereffect
SOURCES += tst_qquickshadereffect.cpp
+include (../../shared/util.pri)
macx:CONFIG -= app_bundle
CONFIG += parallel_test
diff --git a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp
index 1edf511ebf..2816fe62ea 100644
--- a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp
+++ b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp
@@ -45,6 +45,10 @@
#include <QByteArray>
#include <private/qquickshadereffect_p.h>
+#include <QtQuick/QQuickView>
+#include "../../shared/util.h"
+
+
class TestShaderEffect : public QQuickShaderEffect
{
Q_OBJECT
@@ -68,7 +72,7 @@ private:
QList<QByteArray> m_signals;
};
-class tst_qquickshadereffect : public QObject
+class tst_qquickshadereffect : public QQmlDataTest
{
Q_OBJECT
public:
@@ -81,6 +85,9 @@ private slots:
void lookThroughShaderCode_data();
void lookThroughShaderCode();
+ void deleteSourceItem();
+ void deleteShaderEffectSource();
+
private:
enum PresenceFlags {
VertexPresent = 0x01,
@@ -97,6 +104,7 @@ tst_qquickshadereffect::tst_qquickshadereffect()
void tst_qquickshadereffect::initTestCase()
{
+ QQmlDataTest::initTestCase();
}
void tst_qquickshadereffect::cleanupTestCase()
@@ -269,6 +277,36 @@ void tst_qquickshadereffect::lookThroughShaderCode()
QCOMPARE(item.isConnected(SIGNAL(dummyChanged())), (presenceFlags & PropertyPresent) != 0);
}
+void tst_qquickshadereffect::deleteSourceItem()
+{
+ // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash
+ QQuickView *view = new QQuickView(0);
+ view->setSource(QUrl::fromLocalFile(testFile("deleteSourceItem.qml")));
+ view->show();
+ QTest::qWaitForWindowShown(view);
+ QVERIFY(view);
+ QObject *obj = view->rootObject();
+ QVERIFY(obj);
+ QMetaObject::invokeMethod(obj, "setDeletedSourceItem");
+ QTest::qWait(50);
+ delete view;
+}
+
+void tst_qquickshadereffect::deleteShaderEffectSource()
+{
+ // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash
+ QQuickView *view = new QQuickView(0);
+ view->setSource(QUrl::fromLocalFile(testFile("deleteShaderEffectSource.qml")));
+ view->show();
+ QTest::qWaitForWindowShown(view);
+ QVERIFY(view);
+ QObject *obj = view->rootObject();
+ QVERIFY(obj);
+ QMetaObject::invokeMethod(obj, "setDeletedShaderEffectSource");
+ QTest::qWait(50);
+ delete view;
+}
+
QTEST_MAIN(tst_qquickshadereffect)
#include "tst_qquickshadereffect.moc"
diff --git a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp
index 35ce724a64..d6e5370711 100644
--- a/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp
+++ b/tests/auto/quick/qquickstyledtext/tst_qquickstyledtext.cpp
@@ -56,7 +56,8 @@ public:
enum Type {
Bold = 0x01,
Underline = 0x02,
- Italic = 0x04
+ Italic = 0x04,
+ Anchor = 0x08
};
Format(int t, int s, int l)
: type(t), start(s), length(l) {}
@@ -73,6 +74,9 @@ public:
private slots:
void textOutput();
void textOutput_data();
+ void anchors();
+ void anchors_data();
+ void longString();
};
Q_DECLARE_METATYPE(tst_qquickstyledtext::FormatList);
@@ -90,7 +94,13 @@ void tst_qquickstyledtext::textOutput_data()
QTest::addColumn<FormatList>("formats");
QTest::addColumn<bool>("modifiesFontSize");
+ QTest::newRow("empty") << "" << "" << FormatList() << false;
+ QTest::newRow("empty tag") << "<>test</>" << "test" << FormatList() << false;
+ QTest::newRow("nest opening") << "<b<b>>test</b>" << ">test" << FormatList() << false;
+ QTest::newRow("nest closing") << "<b>test<</b>/b>" << "test/b>" << (FormatList() << Format(Format::Bold, 0, 7)) << false;
QTest::newRow("bold") << "<b>bold</b>" << "bold" << (FormatList() << Format(Format::Bold, 0, 4)) << false;
+ QTest::newRow("bold 2") << "<b>>>>>bold</b>" << ">>>>bold" << (FormatList() << Format(Format::Bold, 0, 8)) << false;
+ QTest::newRow("bold 3") << "<b>bold<>/b>" << "bold/b>" << (FormatList() << Format(Format::Bold, 0, 7)) << false;
QTest::newRow("italic") << "<i>italic</i>" << "italic" << (FormatList() << Format(Format::Italic, 0, 6)) << false;
QTest::newRow("underline") << "<u>underline</u>" << "underline" << (FormatList() << Format(Format::Underline, 0, 9)) << false;
QTest::newRow("strong") << "<strong>strong</strong>" << "strong" << (FormatList() << Format(Format::Bold, 0, 6)) << false;
@@ -111,11 +121,10 @@ void tst_qquickstyledtext::textOutput_data()
QTest::newRow("extra space") << "<b >text</b>" << "text" << (FormatList() << Format(Format::Bold, 0, 4)) << false;
QTest::newRow("entities") << "&lt;b&gt;this &amp; that&lt;/b&gt;" << "<b>this & that</b>" << FormatList() << false;
QTest::newRow("newline") << "text<br>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << FormatList() << false;
+ QTest::newRow("self-closing newline") << "text<br/>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << FormatList() << false;
QTest::newRow("paragraph") << "text<p>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << FormatList() << false;
QTest::newRow("paragraph closed") << "text<p>more text</p>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << FormatList() << false;
QTest::newRow("paragraph closed bold") << "<b>text<p>more text</p>more text</b>" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << (FormatList() << Format(Format::Bold, 0, 24)) << false;
- QTest::newRow("self-closing newline") << "text<br/>more text" << QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("more text") << FormatList() << false;
- QTest::newRow("empty") << "" << "" << FormatList() << false;
QTest::newRow("unknown tag") << "<a href='#'><foo>underline</foo></a> not" << "underline not" << (FormatList() << Format(Format::Underline, 0, 9)) << false;
QTest::newRow("ordered list") << "<ol><li>one<li>two" << QChar(QChar::LineSeparator) + QString(6, QChar::Nbsp) + QLatin1String("1.") + QString(2, QChar::Nbsp) + QLatin1String("one") + QChar(QChar::LineSeparator) + QString(6, QChar::Nbsp) + QLatin1String("2.") + QString(2, QChar::Nbsp) + QLatin1String("two") << FormatList() << false;
QTest::newRow("ordered list closed") << "<ol><li>one</li><li>two</li></ol>" << QChar(QChar::LineSeparator) + QString(6, QChar::Nbsp) + QLatin1String("1.") + QString(2, QChar::Nbsp) + QLatin1String("one") + QChar(QChar::LineSeparator) + QString(6, QChar::Nbsp) + QLatin1String("2.") + QString(2, QChar::Nbsp) + QLatin1String("two") + QChar(QChar::LineSeparator) << FormatList() << false;
@@ -151,6 +160,7 @@ void tst_qquickstyledtext::textOutput_data()
QTest::newRow("space leading bold") << "this is<b> bold</b>" << "this is bold" << (FormatList() << Format(Format::Bold, 7, 5)) << false;
QTest::newRow("space trailing bold") << "this is <b>bold </b>" << "this is bold " << (FormatList() << Format(Format::Bold, 8, 5)) << false;
QTest::newRow("img") << "a<img src=\"blah.png\"/>b" << "a b" << FormatList() << false;
+ QTest::newRow("tag mix") << "<f6>ds<b></img><pro>gfh</b><w><w>ghj</stron><ql><sl><pl>dfg</j6><img><bol><r><prp>dfg<bkj></b><up><string>ewrq</al><bl>jklhj<zl>" << "dsgfhghjdfgdfgewrqjklhj" << (FormatList() << Format(Format::Bold, 2, 3)) << false;
}
void tst_qquickstyledtext::textOutput()
@@ -183,6 +193,60 @@ void tst_qquickstyledtext::textOutput()
QCOMPARE(fontSizeModified, modifiesFontSize);
}
+void tst_qquickstyledtext::anchors()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, output);
+ QFETCH(FormatList, formats);
+
+ QTextLayout layout;
+ QList<QQuickStyledTextImgTag*> imgTags;
+ bool fontSizeModified = false;
+ QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified);
+
+ QCOMPARE(layout.text(), output);
+
+ QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats();
+
+ QCOMPARE(layoutFormats.count(), formats.count());
+ for (int i = 0; i < formats.count(); ++i) {
+ QCOMPARE(layoutFormats.at(i).start, formats.at(i).start);
+ QCOMPARE(layoutFormats.at(i).length, formats.at(i).length);
+ QVERIFY(layoutFormats.at(i).format.isAnchor() == bool(formats.at(i).type & Format::Anchor));
+ }
+}
+
+void tst_qquickstyledtext::anchors_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("output");
+ QTest::addColumn<FormatList>("formats");
+
+ QTest::newRow("empty 1") << "Test string with <a href=>url</a>." << "Test string with url." << FormatList();
+ QTest::newRow("empty 2") << "Test string with <a href="">url</a>." << "Test string with url." << FormatList();
+ QTest::newRow("unknown attr") << "Test string with <a hfre=\"http://strange<username>@ok-hostname\">url</a>." << "Test string with url." << FormatList();
+ QTest::newRow("close") << "Test string with <a href=\"http://strange<username>@ok-hostname\"/>url." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 4));
+ QTest::newRow("username") << "Test string with <a href=\"http://strange<username>@ok-hostname\">url</a>." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 3));
+ QTest::newRow("query") << "Test string with <a href=\"http://www.foo.bar?hello=world\">url</a>." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 3));
+ QTest::newRow("ipv6") << "Test string with <a href=\"//user:pass@[56::56:56:56:127.0.0.1]:99\">url</a>." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 3));
+ QTest::newRow("uni") << "Test string with <a href=\"data:text/javascript,d5%20%3D%20'five\\u0027s'%3B\">url</a>." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 3));
+ QTest::newRow("utf8") << "Test string with <a href=\"http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl\">url</a>." << "Test string with url." << (FormatList() << Format(Format::Anchor, 17, 3));
+}
+
+void tst_qquickstyledtext::longString()
+{
+ QTextLayout layout;
+ QList<QQuickStyledTextImgTag*> imgTags;
+ bool fontSizeModified = false;
+
+ QString input(9999999, QChar('.'));
+ QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified);
+ QCOMPARE(layout.text(), input);
+
+ input = QString(9999999, QChar('\t')); // whitespace
+ QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified);
+ QCOMPARE(layout.text(), QString(""));
+}
QTEST_MAIN(tst_qquickstyledtext)
diff --git a/tests/auto/quick/qquicktext/tst_qquicktext.cpp b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
index 724b24280a..a31b30dc60 100644
--- a/tests/auto/quick/qquicktext/tst_qquicktext.cpp
+++ b/tests/auto/quick/qquicktext/tst_qquicktext.cpp
@@ -131,6 +131,9 @@ private slots:
void fontFormatSizes_data();
void fontFormatSizes();
+ void baselineOffset_data();
+ void baselineOffset();
+
private:
QStringList standard;
QStringList richText;
@@ -1579,18 +1582,20 @@ void tst_qquicktext::implicitSize()
QFETCH(QString, wrap);
QFETCH(QString, elide);
QString componentStr = "import QtQuick 2.0\nText { "
+ "property real iWidth: implicitWidth; "
"text: \"" + text + "\"; "
"width: " + width + "; "
"textFormat: " + format + "; "
"wrapMode: " + wrap + "; "
"elide: " + elide + "; "
- "maximumLineCount: 1 }";
+ "maximumLineCount: 2 }";
QQmlComponent textComponent(&engine);
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QQuickText *textObject = qobject_cast<QQuickText*>(textComponent.create());
QVERIFY(textObject->width() < textObject->implicitWidth());
QVERIFY(textObject->height() == textObject->implicitHeight());
+ QCOMPARE(textObject->property("iWidth").toReal(), textObject->implicitWidth());
textObject->resetWidth();
QVERIFY(textObject->width() == textObject->implicitWidth());
@@ -1692,7 +1697,7 @@ void tst_qquicktext::boundingRect()
QCOMPARE(text->boundingRect().x(), qreal(0));
QCOMPARE(text->boundingRect().y(), qreal(0));
QCOMPARE(text->boundingRect().width(), qreal(0));
- QCOMPARE(text->boundingRect().height(), QFontMetricsF(text->font()).height());
+ QCOMPARE(text->boundingRect().height(), qreal(qCeil(QFontMetricsF(text->font()).height())));
text->setText("Hello World");
@@ -2592,6 +2597,251 @@ void tst_qquicktext::fontFormatSizes()
delete view;
}
+typedef qreal (*ExpectedBaseline)(QQuickText *item);
+Q_DECLARE_METATYPE(ExpectedBaseline)
+
+static qreal expectedBaselineTop(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ return fm.ascent();
+}
+
+static qreal expectedBaselineBottom(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ return item->height() - item->contentHeight() + fm.ascent();
+}
+
+static qreal expectedBaselineCenter(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ return ((item->height() - item->contentHeight()) / 2) + fm.ascent();
+}
+
+static qreal expectedBaselineBold(QQuickText *item)
+{
+ QFont font = item->font();
+ font.setBold(true);
+ QFontMetricsF fm(font);
+ return fm.ascent();
+}
+
+static qreal expectedBaselineImage(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ // The line is positioned so the bottom of the line is aligned with the bottom of the image,
+ // or image height - line height and the baseline is line position + ascent. Because
+ // QTextLine's height is rounded up this can give slightly different results to image height
+ // - descent.
+ return 181 - qCeil(fm.height()) + fm.ascent();
+}
+
+static qreal expectedBaselineCustom(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ return 16 + fm.ascent();
+}
+
+static qreal expectedBaselineScaled(QQuickText *item)
+{
+ QFont font = item->font();
+ QTextLayout layout(item->text().replace(QLatin1Char('\n'), QChar::LineSeparator));
+ do {
+ layout.setFont(font);
+ qreal width = 0;
+ layout.beginLayout();
+ for (QTextLine line = layout.createLine(); line.isValid(); line = layout.createLine()) {
+ line.setLineWidth(FLT_MAX);
+ width = qMax(line.naturalTextWidth(), width);
+ }
+ layout.endLayout();
+
+ if (width < item->width()) {
+ QFontMetricsF fm(layout.font());
+ return fm.ascent();
+ }
+ font.setPointSize(font.pointSize() - 1);
+ } while (font.pointSize() > 0);
+ return 0;
+}
+
+static qreal expectedBaselineFixedBottom(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ qreal dy = item->text().contains(QLatin1Char('\n'))
+ ? 160
+ : 180;
+ return dy + fm.ascent();
+}
+
+static qreal expectedBaselineProportionalBottom(QQuickText *item)
+{
+ QFontMetricsF fm(item->font());
+ qreal dy = item->text().contains(QLatin1Char('\n'))
+ ? 200 - (qCeil(fm.height()) * 3)
+ : 200 - (qCeil(fm.height()) * 1.5);
+ return dy + fm.ascent();
+}
+
+void tst_qquicktext::baselineOffset_data()
+{
+ qRegisterMetaType<ExpectedBaseline>();
+ QTest::addColumn<QString>("text");
+ QTest::addColumn<QString>("wrappedText");
+ QTest::addColumn<QByteArray>("bindings");
+ QTest::addColumn<ExpectedBaseline>("expectedBaseline");
+ QTest::addColumn<ExpectedBaseline>("expectedBaselineEmpty");
+
+ QTest::newRow("top align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; verticalAlignment: Text.AlignTop")
+ << &expectedBaselineTop
+ << &expectedBaselineTop;
+ QTest::newRow("bottom align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; verticalAlignment: Text.AlignBottom")
+ << &expectedBaselineBottom
+ << &expectedBaselineBottom;
+ QTest::newRow("center align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; verticalAlignment: Text.AlignVCenter")
+ << &expectedBaselineCenter
+ << &expectedBaselineCenter;
+
+ QTest::newRow("bold")
+ << "<b>hello world</b>"
+ << "<b>hello<br/>world</b>"
+ << QByteArray("height: 200")
+ << &expectedBaselineTop
+ << &expectedBaselineBold;
+
+ QTest::newRow("richText")
+ << "<b>hello world</b>"
+ << "<b>hello<br/>world</b>"
+ << QByteArray("height: 200; textFormat: Text.RichText")
+ << &expectedBaselineTop
+ << &expectedBaselineTop;
+
+ QTest::newRow("elided")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("width: 20; height: 8; elide: Text.ElideRight")
+ << &expectedBaselineTop
+ << &expectedBaselineTop;
+
+ QTest::newRow("elided bottom align")
+ << "hello world"
+ << "hello\nworld!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
+ << QByteArray("width: 200; height: 200; elide: Text.ElideRight; verticalAlignment: Text.AlignBottom")
+ << &expectedBaselineBottom
+ << &expectedBaselineBottom;
+
+ QTest::newRow("image")
+ << "hello <img src=\"images/heart200.png\" /> world"
+ << "hello <img src=\"images/heart200.png\" /><br/>world"
+ << QByteArray("height: 200\n; baseUrl: \"") + testFileUrl("reference").toEncoded() + QByteArray("\"")
+ << &expectedBaselineImage
+ << &expectedBaselineTop;
+
+ QTest::newRow("customLine")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; onLineLaidOut: line.y += 16")
+ << &expectedBaselineCustom
+ << &expectedBaselineCustom;
+
+ QTest::newRow("scaled font")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("width: 200; minimumPointSize: 1; font.pointSize: 64; fontSizeMode: Text.HorizontalFit")
+ << &expectedBaselineScaled
+ << &expectedBaselineTop;
+
+ QTest::newRow("fixed line height top align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignTop")
+ << &expectedBaselineTop
+ << &expectedBaselineTop;
+
+ QTest::newRow("fixed line height bottom align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; lineHeightMode: Text.FixedHeight; lineHeight: 20; verticalAlignment: Text.AlignBottom")
+ << &expectedBaselineFixedBottom
+ << &expectedBaselineFixedBottom;
+
+ QTest::newRow("proportional line height top align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignTop")
+ << &expectedBaselineTop
+ << &expectedBaselineTop;
+
+ QTest::newRow("proportional line height bottom align")
+ << "hello world"
+ << "hello\nworld"
+ << QByteArray("height: 200; lineHeightMode: Text.ProportionalHeight; lineHeight: 1.5; verticalAlignment: Text.AlignBottom")
+ << &expectedBaselineProportionalBottom
+ << &expectedBaselineProportionalBottom;
+}
+
+void tst_qquicktext::baselineOffset()
+{
+ QFETCH(QString, text);
+ QFETCH(QString, wrappedText);
+ QFETCH(QByteArray, bindings);
+ QFETCH(ExpectedBaseline, expectedBaseline);
+ QFETCH(ExpectedBaseline, expectedBaselineEmpty);
+
+ QQmlComponent component(&engine);
+ component.setData(
+ "import QtQuick 2.0\n"
+ "Text {\n"
+ + bindings + "\n"
+ "}", QUrl());
+
+ QScopedPointer<QObject> object(component.create());
+
+ QQuickText *item = qobject_cast<QQuickText *>(object.data());
+ QVERIFY(item);
+
+ {
+ qreal baseline = expectedBaselineEmpty(item);
+
+ QCOMPARE(item->baselineOffset(), baseline);
+
+ item->setText(text);
+ if (expectedBaseline != expectedBaselineEmpty)
+ baseline = expectedBaseline(item);
+
+ QCOMPARE(item->baselineOffset(), baseline);
+
+ item->setText(wrappedText);
+ QCOMPARE(item->baselineOffset(), expectedBaseline(item));
+ }
+
+ QFont font = item->font();
+ font.setPointSize(font.pointSize() + 8);
+
+ {
+ QCOMPARE(item->baselineOffset(), expectedBaseline(item));
+
+ item->setText(text);
+ qreal baseline = expectedBaseline(item);
+ QCOMPARE(item->baselineOffset(), baseline);
+
+ item->setText(QString());
+ if (expectedBaselineEmpty != expectedBaseline)
+ baseline = expectedBaselineEmpty(item);
+
+ QCOMPARE(item->baselineOffset(), baseline);
+ }
+}
+
QTEST_MAIN(tst_qquicktext)
#include "tst_qquicktext.moc"
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index dd9aa0acad..7113141800 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -2379,6 +2379,11 @@ void tst_qquicktextedit::inputMethodUpdate()
QVERIFY(edit->selectionStart() != edit->selectionEnd());
QVERIFY(platformInputContext.m_updateCallCount > 0);
+ // programmatical selections trigger update
+ platformInputContext.clear();
+ edit->selectAll();
+ QCOMPARE(platformInputContext.m_updateCallCount, 1);
+
// font changes
platformInputContext.clear();
QFont font = edit->font();