summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-06 07:31:55 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-06 07:31:55 (GMT)
commit2c0aa64a1e59271c5cf212fee869070d881d3a51 (patch)
tree28316042b345accaf3c625a0a714f8edfaa373fe
parente3d14648ebf04ef2ed8bf2a72e8cff186bcd4871 (diff)
downloadQt-2c0aa64a1e59271c5cf212fee869070d881d3a51.zip
Qt-2c0aa64a1e59271c5cf212fee869070d881d3a51.tar.gz
Qt-2c0aa64a1e59271c5cf212fee869070d881d3a51.tar.bz2
More ListView tests.
-rw-r--r--src/declarative/graphicsitems/qmlgraphicslistview.cpp4
-rw-r--r--tests/auto/declarative/qmlgraphicslistview/data/listview-initCurrent.qml49
-rw-r--r--tests/auto/declarative/qmlgraphicslistview/data/listview.qml2
-rw-r--r--tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp112
4 files changed, 148 insertions, 19 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
index 59137a7..a9bc721 100644
--- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp
@@ -1488,6 +1488,8 @@ void QmlGraphicsListView::setHighlightMoveSpeed(qreal speed)
if (d->highlightMoveSpeed != speed)
{
d->highlightMoveSpeed = speed;
+ if (d->highlightPosAnimator)
+ d->highlightPosAnimator->setVelocity(d->highlightMoveSpeed);
emit highlightMoveSpeedChanged();
}
}
@@ -1509,6 +1511,8 @@ void QmlGraphicsListView::setHighlightResizeSpeed(qreal speed)
if (d->highlightResizeSpeed != speed)
{
d->highlightResizeSpeed = speed;
+ if (d->highlightSizeAnimator)
+ d->highlightSizeAnimator->setVelocity(d->highlightResizeSpeed);
emit highlightResizeSpeedChanged();
}
}
diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview-initCurrent.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview-initCurrent.qml
new file mode 100644
index 0000000..5b1fee6
--- /dev/null
+++ b/tests/auto/declarative/qmlgraphicslistview/data/listview-initCurrent.qml
@@ -0,0 +1,49 @@
+import Qt 4.6
+
+Rectangle {
+ width: 240
+ height: 320
+ color: "#ffffff"
+ resources: [
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ height: 20
+ width: 240
+ Text {
+ text: index
+ }
+ Text {
+ x: 30
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ x: 120
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+ Text {
+ x: 200
+ text: wrapper.y
+ }
+ color: ListView.isCurrentItem ? "lightsteelblue" : "white"
+ }
+ }
+ ]
+ ListView {
+ id: list
+ objectName: "list"
+ focus: true
+ currentIndex: 3
+ width: 240
+ height: 320
+ model: testModel
+ delegate: myDelegate
+ highlightMoveSpeed: 1000
+ }
+}
diff --git a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml
index b7b838b..93a3ae3 100644
--- a/tests/auto/declarative/qmlgraphicslistview/data/listview.qml
+++ b/tests/auto/declarative/qmlgraphicslistview/data/listview.qml
@@ -38,9 +38,11 @@ Rectangle {
ListView {
id: list
objectName: "list"
+ focus: true
width: 240
height: 320
model: testModel
delegate: myDelegate
+ highlightMoveSpeed: 1000
}
}
diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
index 0015c48..4a33770 100644
--- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
+++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
@@ -72,6 +72,7 @@ private slots:
void enforceRange();
void spacing();
void sections();
+ void currentIndex();
private:
template <class T> void items();
@@ -252,6 +253,9 @@ void tst_QmlGraphicsListView::items()
QCOMPARE(listview->count(), model.count());
QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
+ // current item should be first item
+ QCOMPARE(listview->currentItem(), findItem<QmlGraphicsItem>(viewport, "wrapper", 0));
+
for (int i = 0; i < model.count(); ++i) {
QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", i);
QVERIFY(name != 0);
@@ -261,11 +265,6 @@ void tst_QmlGraphicsListView::items()
QCOMPARE(number->text(), model.number(i));
}
- listview->incrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 1);
- listview->decrementCurrentIndex();
- QCOMPARE(listview->currentIndex(), 0);
-
// set an empty model and confirm that items are destroyed
T model2;
ctxt->setContextProperty("testModel", &model2);
@@ -334,7 +333,7 @@ void tst_QmlGraphicsListView::inserted()
model.insertItem(1, "Will", "9876");
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
@@ -354,7 +353,7 @@ void tst_QmlGraphicsListView::inserted()
model.insertItem(0, "Foo", "1111"); // zero index, and current item
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
QCOMPARE(viewport->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
@@ -375,14 +374,14 @@ void tst_QmlGraphicsListView::inserted()
for (int i = model.count(); i < 30; ++i)
model.insertItem(i, "Hello", QString::number(i));
- QTest::qWait(1000);
+ QTest::qWait(500);
listview->setViewportY(80);
- QTest::qWait(1000);
+ QTest::qWait(500);
// Insert item outside visible area
model.insertItem(1, "Hello", "1324");
- QTest::qWait(1000);
+ QTest::qWait(500);
QVERIFY(listview->viewportY() == 80);
@@ -420,7 +419,7 @@ void tst_QmlGraphicsListView::removed()
model.removeItem(1);
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", 1);
QVERIFY(name != 0);
@@ -442,7 +441,7 @@ void tst_QmlGraphicsListView::removed()
model.removeItem(0); // post: top item starts at 20
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
name = findItem<QmlGraphicsText>(viewport, "textName", 0);
QVERIFY(name != 0);
@@ -463,7 +462,7 @@ void tst_QmlGraphicsListView::removed()
// Remove items not visible
model.removeItem(18);
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
// Confirm items positioned correctly
itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
@@ -480,7 +479,7 @@ void tst_QmlGraphicsListView::removed()
model.removeItem(1); // post: top item will be at 40
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
// Confirm items positioned correctly
for (int i = 2; i < 18; ++i) {
@@ -492,7 +491,7 @@ void tst_QmlGraphicsListView::removed()
listview->setViewportY(40); // That's the top now
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
// Confirm items positioned correctly
itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count();
@@ -530,7 +529,7 @@ void tst_QmlGraphicsListView::moved()
model.moveItem(1, 4);
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", 1);
QVERIFY(name != 0);
@@ -561,7 +560,7 @@ void tst_QmlGraphicsListView::moved()
model.moveItem(1, 18);
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
// Confirm items positioned correctly and indexes correct
for (int i = 3; i < model.count() && i < itemCount; ++i) {
@@ -581,7 +580,7 @@ void tst_QmlGraphicsListView::moved()
model.moveItem(20, 4);
// let transitions settle.
- QTest::qWait(1000);
+ QTest::qWait(500);
// Confirm items positioned correctly and indexes correct
for (int i = 3; i < model.count() && i < itemCount; ++i) {
@@ -617,6 +616,9 @@ void tst_QmlGraphicsListView::enforceRange()
QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list");
QVERIFY(listview != 0);
+ QCOMPARE(listview->preferredHighlightBegin(), 100.0);
+ QCOMPARE(listview->preferredHighlightEnd(), 100.0);
+
QmlGraphicsItem *viewport = listview->viewport();
QVERIFY(viewport != 0);
@@ -634,7 +636,7 @@ void tst_QmlGraphicsListView::enforceRange()
// Check currentIndex is updated when viewport moves
listview->setViewportY(20);
- QTest::qWait(1000);
+ QTest::qWait(500);
QCOMPARE(listview->currentIndex(), 6);
@@ -762,6 +764,78 @@ void tst_QmlGraphicsListView::sections()
delete canvas;
}
+void tst_QmlGraphicsListView::currentIndex()
+{
+ QmlView *canvas = createView(SRCDIR "/data/listview-initCurrent.qml");
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list");
+ QVERIFY(listview != 0);
+
+ QmlGraphicsItem *viewport = listview->viewport();
+ QVERIFY(viewport != 0);
+
+ // current item should be third item
+ QCOMPARE(listview->currentItem(), findItem<QmlGraphicsItem>(viewport, "wrapper", 3));
+
+ // no wrap
+ listview->setCurrentIndex(0);
+ QCOMPARE(listview->currentIndex(), 0);
+
+ listview->incrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 1);
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+
+ // with wrap
+ listview->setWrapEnabled(true);
+
+ listview->decrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), model.count()-1);
+
+ QTest::qWait(1000);
+ QCOMPARE(listview->viewportY(), 279.0);
+
+ listview->incrementCurrentIndex();
+ QCOMPARE(listview->currentIndex(), 0);
+
+ QTest::qWait(1000);
+ QCOMPARE(listview->viewportY(), 0.0);
+
+ // Test keys
+ canvas->show();
+ qApp->processEvents();
+
+ QEvent wa(QEvent::WindowActivate);
+ QApplication::sendEvent(canvas, &wa);
+ QFocusEvent fe(QEvent::FocusIn);
+ QApplication::sendEvent(canvas, &fe);
+
+ QKeyEvent key(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QVERIFY(key.isAccepted());
+ QCOMPARE(listview->currentIndex(), 1);
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QVERIFY(key.isAccepted());
+ QCOMPARE(listview->currentIndex(), 0);
+
+ delete canvas;
+}
+
void tst_QmlGraphicsListView::qListModelInterface_items()
{
items<TestModel>();