summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-11-19 04:56:30 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-11-19 04:56:30 (GMT)
commitea44f6e9b6935c2dbd7fd17c95ffcbb08347c1a0 (patch)
tree7877ddf126a9a85a40f281a5ee7350ca89112bbe
parentc9333d1700bb7d063d6e1fe98b5a5900109a5d43 (diff)
parent2b386e05e495df97fffcdfb58096756ba6f394cd (diff)
downloadQt-ea44f6e9b6935c2dbd7fd17c95ffcbb08347c1a0.zip
Qt-ea44f6e9b6935c2dbd7fd17c95ffcbb08347c1a0.tar.gz
Qt-ea44f6e9b6935c2dbd7fd17c95ffcbb08347c1a0.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview.cpp21
-rw-r--r--tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp32
-rw-r--r--tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp75
3 files changed, 121 insertions, 7 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
index 473f9e5..7e2d983 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
@@ -1302,12 +1302,21 @@ void QmlGraphicsGridView::trackedPositionChanged()
if (!d->trackedItem)
return;
if (!isFlicking() && !d->moving && d->moveReason != QmlGraphicsGridViewPrivate::Mouse) {
- if (d->trackedItem->rowPos() < d->position()) {
- d->setPosition(d->trackedItem->rowPos());
- } else if (d->trackedItem->endRowPos() > d->position() + d->size()) {
- qreal pos = d->trackedItem->endRowPos() - d->size();
- if (d->rowSize() > d->size())
- pos = d->trackedItem->rowPos();
+ const qreal viewPos = d->position();
+ if (d->trackedItem->rowPos() < viewPos && d->currentItem->rowPos() < viewPos) {
+ d->setPosition(d->currentItem->rowPos() < d->trackedItem->rowPos() ? d->trackedItem->rowPos() : d->currentItem->rowPos());
+ } else if (d->trackedItem->endRowPos() > viewPos + d->size()
+ && d->currentItem->endRowPos() > viewPos + d->size()) {
+ qreal pos;
+ if (d->trackedItem->endRowPos() < d->currentItem->endRowPos()) {
+ pos = d->trackedItem->endRowPos() - d->size();
+ if (d->rowSize() > d->size())
+ pos = d->trackedItem->rowPos();
+ } else {
+ pos = d->currentItem->endRowPos() - d->size();
+ if (d->rowSize() > d->size())
+ pos = d->currentItem->rowPos();
+ }
d->setPosition(pos);
}
}
diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp
index 197191e..f31ea49 100644
--- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp
+++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp
@@ -394,6 +394,9 @@ void tst_QmlGraphicsGridView::removed()
// let transitions settle.
QTest::qWait(300);
+ // Setting currentIndex above shouldn't cause view to scroll
+ QCOMPARE(gridview->viewportY(), 120.0);
+
model.removeItem(1);
// let transitions settle.
@@ -408,6 +411,14 @@ void tst_QmlGraphicsGridView::removed()
QVERIFY(item->y() == (i/3)*60);
}
+ // Remove currentIndex
+ QmlGraphicsItem *oldCurrent = gridview->currentItem();
+ model.removeItem(9);
+ QTest::qWait(500);
+
+ QCOMPARE(gridview->currentIndex(), 9);
+ QVERIFY(gridview->currentItem() != oldCurrent);
+
gridview->setViewportY(0);
// let transitions settle.
QTest::qWait(300);
@@ -430,6 +441,27 @@ void tst_QmlGraphicsGridView::removed()
model.removeItem(30);
QVERIFY(gridview->currentIndex() == 31);
+ // remove current item beyond visible items.
+ gridview->setCurrentIndex(20);
+ QTest::qWait(500);
+ gridview->setViewportY(0);
+ model.removeItem(20);
+ QTest::qWait(500);
+
+ QCOMPARE(gridview->currentIndex(), 20);
+ QVERIFY(gridview->currentItem() != 0);
+
+ // remove item before current, but visible
+ gridview->setCurrentIndex(8);
+ QTest::qWait(500);
+ gridview->setViewportY(240);
+ oldCurrent = gridview->currentItem();
+ model.removeItem(6);
+ QTest::qWait(500);
+
+ QCOMPARE(gridview->currentIndex(), 7);
+ QVERIFY(gridview->currentItem() == oldCurrent);
+
delete canvas;
}
diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
index e9f785b..08043f3 100644
--- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
+++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp
@@ -70,6 +70,9 @@ private slots:
void qListModelInterface_moved();
void qAbstractItemModel_moved();
+ void qListModelInterface_clear();
+ void qAbstractItemModel_clear();
+
void itemList();
void currentIndex();
void enforceRange();
@@ -83,6 +86,7 @@ private:
template <class T> void inserted();
template <class T> void removed(bool animated);
template <class T> void moved();
+ template <class T> void clear();
QmlView *createView(const QString &filename);
template<typename T>
T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1);
@@ -201,6 +205,12 @@ public:
emit itemsChanged(index, 1, roles());
}
+ void clear() {
+ int count = list.count();
+ list.clear();
+ emit itemsRemoved(0, count);
+ }
+
private:
QList<QPair<QString,QString> > list;
};
@@ -262,6 +272,13 @@ public:
emit dataChanged(index(idx,0), index(idx,0));
}
+ void clear() {
+ int count = list.count();
+ emit beginRemoveRows(QModelIndex(), 0, count-1);
+ list.clear();
+ emit endRemoveRows();
+ }
+
private:
QList<QPair<QString,QString> > list;
};
@@ -571,6 +588,15 @@ void tst_QmlGraphicsListView::removed(bool animated)
QCOMPARE(item->y(),40+i*20.0);
}
+ // Remove current index
+ QVERIFY(listview->currentIndex() == 9);
+ QmlGraphicsItem *oldCurrent = listview->currentItem();
+ model.removeItem(9);
+ QTest::qWait(500);
+
+ QCOMPARE(listview->currentIndex(), 9);
+ QVERIFY(listview->currentItem() != oldCurrent);
+
listview->setViewportY(40); // That's the top now
// let transitions settle.
QTest::qWait(500);
@@ -587,6 +613,7 @@ void tst_QmlGraphicsListView::removed(bool animated)
// remove current item beyond visible items.
listview->setCurrentIndex(20);
QTest::qWait(500);
+ listview->setViewportY(40);
model.removeItem(20);
QTest::qWait(500);
@@ -596,7 +623,7 @@ void tst_QmlGraphicsListView::removed(bool animated)
// remove item before current, but visible
listview->setCurrentIndex(8);
QTest::qWait(500);
- QmlGraphicsItem *oldCurrent = listview->currentItem();
+ oldCurrent = listview->currentItem();
model.removeItem(6);
QTest::qWait(500);
@@ -607,6 +634,43 @@ void tst_QmlGraphicsListView::removed(bool animated)
}
template <class T>
+void tst_QmlGraphicsListView::clear()
+{
+ QmlView *canvas = createView(SRCDIR "/data/listview.qml");
+
+ T model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QmlContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ TestObject *testObject = new TestObject;
+ ctxt->setContextProperty("testObject", testObject);
+
+ canvas->execute();
+ qApp->processEvents();
+
+ QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list");
+ QVERIFY(listview != 0);
+
+ QmlGraphicsItem *viewport = listview->viewport();
+ QVERIFY(viewport != 0);
+
+ model.clear();
+
+ // let transitions settle.
+ QTest::qWait(500);
+
+ QVERIFY(listview->count() == 0);
+ QVERIFY(listview->currentItem() == 0);
+ QVERIFY(listview->viewportY() == 0);
+
+ delete canvas;
+}
+
+
+template <class T>
void tst_QmlGraphicsListView::moved()
{
QmlView *canvas = createView(SRCDIR "/data/listview.qml");
@@ -1123,6 +1187,15 @@ void tst_QmlGraphicsListView::qAbstractItemModel_moved()
moved<TestModel2>();
}
+void tst_QmlGraphicsListView::qListModelInterface_clear()
+{
+ clear<TestModel>();
+}
+
+void tst_QmlGraphicsListView::qAbstractItemModel_clear()
+{
+ clear<TestModel2>();
+}
QmlView *tst_QmlGraphicsListView::createView(const QString &filename)
{