summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-11-27 04:26:49 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-11-27 04:26:49 (GMT)
commita47c6ddde353b1ffe8fd4037817143ff9f338654 (patch)
tree25b8250c786c4b0f52aa27766903d4bca2a09fd2 /src/declarative
parentdd6262e2c4e977f7a02cd8bdc740a08adb0cad49 (diff)
downloadQt-a47c6ddde353b1ffe8fd4037817143ff9f338654.zip
Qt-a47c6ddde353b1ffe8fd4037817143ff9f338654.tar.gz
Qt-a47c6ddde353b1ffe8fd4037817143ff9f338654.tar.bz2
Add GridView.positionViewAtIndex().
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview.cpp41
-rw-r--r--src/declarative/graphicsitems/qmlgraphicsgridview_p.h1
2 files changed, 36 insertions, 6 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
index e36ea50..81128e7 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp
@@ -388,9 +388,9 @@ void QmlGraphicsGridViewPrivate::refill(qreal from, qreal to)
to += buffer;
bool changed = false;
- int colPos = 0;
- int rowPos = 0;
- int modelIndex = 0;
+ int colPos = colPosAt(visibleIndex);
+ int rowPos = rowPosAt(visibleIndex);
+ int modelIndex = visibleIndex;
if (visibleItems.count()) {
rowPos = visibleItems.last()->rowPos();
colPos = visibleItems.last()->colPos() + colSize();
@@ -822,14 +822,14 @@ void QmlGraphicsGridView::setModel(const QVariant &model)
}
/*!
- \qmlproperty component GridView::delegate
+ \qmlproperty component GridView::delegate
The delegate provides a template defining each item instantiated by the view.
The index is exposed as an accessible \c index property. Properties of the
model are also available depending upon the type of \l {qmlmodels}{Data Model}.
- Here is an example delegate:
- \snippet doc/src/snippets/declarative/gridview/gridview.qml 0
+ Here is an example delegate:
+ \snippet doc/src/snippets/declarative/gridview/gridview.qml 0
*/
QmlComponent *QmlGraphicsGridView::delegate() const
{
@@ -1292,6 +1292,35 @@ void QmlGraphicsGridView::moveCurrentIndexRight()
}
}
+void QmlGraphicsGridView::positionViewAtIndex(int index)
+{
+ Q_D(QmlGraphicsGridView);
+ if (!d->isValid() || index < 0 || index >= d->model->count())
+ return;
+
+ qreal maxExtent = d->flow == QmlGraphicsGridView::LeftToRight ? -maxYExtent() : -maxXExtent();
+ FxGridItem *item = d->visibleItem(index);
+ if (item) {
+ // Already created - just move to top of view
+ int pos = qMin(item->rowPos(), maxExtent);
+ d->setPosition(pos);
+ } else {
+ int pos = d->rowPosAt(index);
+ // save the currently visible items in case any of them end up visible again
+ QList<FxGridItem*> oldVisible = d->visibleItems;
+ d->visibleItems.clear();
+ d->visibleIndex = index - index % d->columns;
+ d->setPosition(pos);
+ // setPosition() will cause refill. Adjust if we have moved beyond range
+ if (d->position() > maxExtent)
+ d->setPosition(maxExtent);
+ // now release the reference to all the old visible items.
+ for (int i = 0; i < oldVisible.count(); ++i)
+ d->releaseItem(oldVisible.at(i));
+ }
+}
+
+
void QmlGraphicsGridView::componentComplete()
{
Q_D(QmlGraphicsGridView);
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
index 3e09cf3..99515a3 100644
--- a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
+++ b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h
@@ -121,6 +121,7 @@ public Q_SLOTS:
void moveCurrentIndexDown();
void moveCurrentIndexLeft();
void moveCurrentIndexRight();
+ void positionViewAtIndex(int index);
Q_SIGNALS:
void countChanged();