diff options
Diffstat (limited to 'src/declarative/fx')
-rw-r--r-- | src/declarative/fx/qfxflickable.cpp | 4 | ||||
-rw-r--r-- | src/declarative/fx/qfxlistview.cpp | 49 | ||||
-rw-r--r-- | src/declarative/fx/qfxpathview.cpp | 7 | ||||
-rw-r--r-- | src/declarative/fx/qfxpathview.h | 1 |
4 files changed, 45 insertions, 16 deletions
diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index 890bb31..4ace811 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -129,10 +129,12 @@ void QFxFlickablePrivate::fixupX() vTime = _tl.time(); if (_moveX.value() > q->minXExtent() || q->maxXExtent() > 0) { + _tl.clear(); _tl.move(_moveX, q->minXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); flicked = false; //emit flickingChanged(); } else if (_moveX.value() < q->maxXExtent()) { + _tl.clear(); _tl.move(_moveX, q->maxXExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); flicked = false; //emit flickingChanged(); @@ -148,9 +150,11 @@ void QFxFlickablePrivate::fixupY() vTime = _tl.time(); if (_moveY.value() > q->minYExtent() || (q->maxYExtent() > q->minYExtent())) { + _tl.clear(); _tl.move(_moveY, q->minYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else if (_moveY.value() < q->maxYExtent()) { + _tl.clear(); _tl.move(_moveY, q->maxYExtent(), QEasingCurve(QEasingCurve::InOutQuad), 200); //emit flickingChanged(); } else { diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index ad752a7..bb71a91 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -293,6 +293,29 @@ public: } return -1; // Not in visibleList } + + bool mapRangeFromModel(int &index, int &count) const { + if (index + count < visibleIndex) + return false; + + int lastIndex = -1; + for (int i = visibleItems.count()-1; i >= 0; --i) { + FxListItem *listItem = visibleItems.at(i); + if (listItem->index != -1) { + lastIndex = listItem->index; + break; + } + } + + if (index > lastIndex) + return false; + + int last = qMin(index + count - 1, lastIndex); + index = qMax(index, visibleIndex); + count = last - index + 1; + + return true; + } // for debugging only void checkVisible() const { @@ -468,7 +491,7 @@ void QFxListViewPrivate::refill(qreal from, qreal to) ++modelIndex; changed = true; } - while (visibleIndex > 0 && visiblePos > from) { + while (visibleIndex > 0 && visibleIndex <= model->count() && visiblePos > from) { //qDebug() << "refill: prepend item" << visibleIndex-1 << "current top pos" << visiblePos; item = getItem(visibleIndex-1); --visibleIndex; @@ -1388,20 +1411,19 @@ void QFxListView::itemsInserted(int modelIndex, int count) { Q_D(QFxListView); if (!d->visibleItems.count() || d->model->count() <= 1) { - refill(); + d->layout(); d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); emit countChanged(); return; } - int index = d->mapFromModel(modelIndex); - if (index == -1) { + if (!d->mapRangeFromModel(modelIndex, count)) { int i = d->visibleItems.count() - 1; while (i > 0 && d->visibleItems.at(i)->index == -1) --i; if (d->visibleItems.at(i)->index + 1 == modelIndex) { // Special case of appending an item to the model. - index = d->visibleIndex + d->visibleItems.count(); + modelIndex = d->visibleIndex + d->visibleItems.count(); } else { if (modelIndex + count - 1 < d->visibleIndex) { // Insert before visible items @@ -1418,27 +1440,22 @@ void QFxListView::itemsInserted(int modelIndex, int count) if (d->currentItem) d->currentItem->index = d->currentIndex; } + d->layout(); emit countChanged(); return; } } // At least some of the added items will be visible - int insertCount = count; - if (index < d->visibleIndex) { - insertCount -= d->visibleIndex - index; - index = d->visibleIndex; - modelIndex = d->visibleIndex; - } - index -= d->visibleIndex; + int index = modelIndex - d->visibleIndex; int to = d->buffer+d->position()+d->size()-1; // index can be the next item past the end of the visible items list (i.e. appended) int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() : d->visibleItems.at(index-1)->endPosition()+1; int initialPos = pos; QList<FxListItem*> added; - for (int i = 0; i < insertCount && pos <= to; ++i) { + for (int i = 0; i < count && pos <= to; ++i) { FxListItem *item = d->createItem(modelIndex + i); d->visibleItems.insert(index, item); item->setPosition(pos); @@ -1479,8 +1496,7 @@ void QFxListView::itemsInserted(int modelIndex, int count) void QFxListView::itemsRemoved(int modelIndex, int count) { Q_D(QFxListView); - int index = d->mapFromModel(modelIndex); - if (index == -1) { + if (!d->mapRangeFromModel(modelIndex, count)) { if (modelIndex + count - 1 < d->visibleIndex) { // Items removed before our visible items. d->visibleIndex -= count; @@ -1504,6 +1520,7 @@ void QFxListView::itemsRemoved(int modelIndex, int count) d->currentIndex = -1; d->updateCurrent(qMin(modelIndex, d->model->count()-1)); } + d->layout(); emit countChanged(); return; } @@ -1561,6 +1578,8 @@ void QFxListView::itemsRemoved(int modelIndex, int count) if (d->visibleItems.isEmpty()) { d->visibleIndex = 0; + d->visiblePos = 0; + d->_tl.clear(); d->setPosition(0); if (d->model->count() == 0) update(); diff --git a/src/declarative/fx/qfxpathview.cpp b/src/declarative/fx/qfxpathview.cpp index 77d5fa2..b7215cf 100644 --- a/src/declarative/fx/qfxpathview.cpp +++ b/src/declarative/fx/qfxpathview.cpp @@ -66,6 +66,11 @@ public: { } + ~QFxPathViewAttached() + { + QFxPathView::attachedProperties.remove(parent()); + } + QVariant value(const QByteArray &name) const { return mo->value(name); @@ -583,7 +588,7 @@ void QFxPathViewPrivate::regenerate() void QFxPathViewPrivate::updateItem(QFxItem *item, qreal percent) { - if (QObject *obj = QFxPathView::attachedProperties.value(item)) { + if (QObject *obj = QFxPathView::qmlAttachedProperties(item)) { foreach(const QString &attr, path->attributes()) static_cast<QFxPathViewAttached *>(obj)->setValue(attr.toLatin1(), path->attributeAt(attr, percent)); } diff --git a/src/declarative/fx/qfxpathview.h b/src/declarative/fx/qfxpathview.h index 0e1ac6f..2ecd04e 100644 --- a/src/declarative/fx/qfxpathview.h +++ b/src/declarative/fx/qfxpathview.h @@ -122,6 +122,7 @@ protected: QFxPathView(QFxPathViewPrivate &dd, QFxItem *parent); private: + friend class QFxPathViewAttached; static QHash<QObject*, QObject*> attachedProperties; Q_DISABLE_COPY(QFxPathView) Q_DECLARE_PRIVATE(QFxPathView) |