aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <[email protected]>2012-07-18 10:36:17 +1000
committerQt by Nokia <[email protected]>2012-07-23 03:30:23 +0200
commit0fc361f96b06ba318e70610e46beb421753cae9d (patch)
tree8b5ea97dc869f3896f7fc565fc15def3ad131254 /src
parent33fcc79a88fbc66a3a714913392a331f2bb601b3 (diff)
Changing PathView model after componentComplete should reset position
If the model is changed after the component is completed, the offset and currentIndex should be reset to 0. Change-Id: Ie36eb0c17ce6602c6ae15b5ee7aeb8b1a6e7854b Reviewed-by: Bea Lam <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/quick/doc/src/whatsnew.qdoc2
-rw-r--r--src/quick/items/qquickpathview.cpp60
2 files changed, 39 insertions, 23 deletions
diff --git a/src/quick/doc/src/whatsnew.qdoc b/src/quick/doc/src/whatsnew.qdoc
index c82ddf7de5..813656c10b 100644
--- a/src/quick/doc/src/whatsnew.qdoc
+++ b/src/quick/doc/src/whatsnew.qdoc
@@ -319,6 +319,8 @@ the window loses focus.
\li New \l{PathView::}{maximumFlickVelocity} property controls the maximum flick velocity of the
view.
\li New \l{PathView::}{snapMode} property controls the snap model when flicking between items
+ \li If the model is changed after the component is completed, the offset and currentIndex are
+ reset to 0.
\endlist
\endlist
diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp
index cb56dd265f..272fdce679 100644
--- a/src/quick/items/qquickpathview.cpp
+++ b/src/quick/items/qquickpathview.cpp
@@ -250,6 +250,7 @@ void QQuickPathViewPrivate::clear()
releaseItem(p);
}
items.clear();
+ tl.clear();
}
void QQuickPathViewPrivate::updateMappedRange()
@@ -579,6 +580,8 @@ QQuickPathView::~QQuickPathView()
For large or dynamic datasets the model is usually provided by a C++ model object.
Models can also be created directly in QML, using the ListModel type.
+ \note changing the model will reset the offset and currentIndex to 0.
+
\sa {qmlmodels}{Data Models}
*/
QVariant QQuickPathView::model() const
@@ -600,11 +603,7 @@ void QQuickPathView::setModel(const QVariant &model)
this, QQuickPathView, SLOT(createdItem(int,QQuickItem*)));
qmlobject_disconnect(d->model, QQuickVisualModel, SIGNAL(initItem(int,QQuickItem*)),
this, QQuickPathView, SLOT(initItem(int,QQuickItem*)));
- for (int i=0; i<d->items.count(); i++){
- QQuickItem *p = d->items[i];
- d->releaseItem(p);
- }
- d->items.clear();
+ d->clear();
}
d->modelVariant = model;
@@ -626,6 +625,7 @@ void QQuickPathView::setModel(const QVariant &model)
if (QQuickVisualDataModel *dataModel = qobject_cast<QQuickVisualDataModel*>(d->model))
dataModel->setModel(model);
}
+ int oldModelCount = d->modelCount;
d->modelCount = 0;
if (d->model) {
qmlobject_connect(d->model, QQuickVisualModel, SIGNAL(modelUpdated(QQuickChangeSet,bool)),
@@ -635,17 +635,20 @@ void QQuickPathView::setModel(const QVariant &model)
qmlobject_connect(d->model, QQuickVisualModel, SIGNAL(initItem(int,QQuickItem*)),
this, QQuickPathView, SLOT(initItem(int,QQuickItem*)));
d->modelCount = d->model->count();
- if (d->model->count())
- d->offset = qmlMod(d->offset, qreal(d->model->count()));
- if (d->offset < 0)
- d->offset = d->model->count() + d->offset;
-}
+ }
+ if (isComponentComplete()) {
+ if (d->currentIndex != 0) {
+ d->currentIndex = 0;
+ emit currentIndexChanged();
+ }
+ if (d->offset != 0.0) {
+ d->offset = 0;
+ emit offsetChanged();
+ }
+ }
d->regenerate();
- if (d->currentIndex < d->modelCount)
- setOffset(qmlMod(d->modelCount - d->currentIndex, d->modelCount));
- else
- d->fixOffset();
- emit countChanged();
+ if (d->modelCount != oldModelCount)
+ emit countChanged();
emit modelChanged();
}
@@ -705,6 +708,14 @@ int QQuickPathView::currentIndex() const
void QQuickPathView::setCurrentIndex(int idx)
{
Q_D(QQuickPathView);
+ if (!isComponentComplete()) {
+ if (idx != d->currentIndex) {
+ d->currentIndex = idx;
+ emit currentIndexChanged();
+ }
+ return;
+ }
+
idx = d->modelCount
? ((idx % d->modelCount) + d->modelCount) % d->modelCount
: 0;
@@ -1600,14 +1611,14 @@ void QQuickPathView::componentComplete()
QQuickItem::componentComplete();
- d->createHighlight();
- // It is possible that a refill has already happended to to Path
- // bindings being handled in the componentComplete(). If so
- // don't do it again.
- if (d->items.count() == 0 && d->model) {
+ if (d->model) {
d->modelCount = d->model->count();
- d->regenerate();
+ if (d->modelCount && d->currentIndex != 0) // an initial value has been provided for currentIndex
+ d->offset = qmlMod(d->modelCount - d->currentIndex, d->modelCount);
}
+
+ d->createHighlight();
+ d->regenerate();
d->updateHighlight();
d->updateCurrent();
@@ -1920,16 +1931,19 @@ void QQuickPathViewPrivate::updateCurrent()
return;
int idx = calcCurrentIndex();
- if (model && idx != currentIndex) {
+ if (model && (idx != currentIndex || !currentItem)) {
if (currentItem) {
if (QQuickPathViewAttached *att = attached(currentItem))
att->setIsCurrentItem(false);
releaseItem(currentItem);
}
+ int oldCurrentIndex = currentIndex;
currentIndex = idx;
currentItem = 0;
createCurrentItem();
- emit q->currentIndexChanged();
+ if (oldCurrentIndex != currentIndex)
+ emit q->currentIndexChanged();
+ emit q->currentItemChanged();
}
}