From 0a06e7437763fca81d77c4fdd938a3c1aa890ed2 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 8 May 2009 14:28:17 +1000 Subject: Fix removal of items that span a range greater than the visible range. --- src/declarative/fx/qfxflickable.cpp | 4 +++ src/declarative/fx/qfxlistview.cpp | 49 +++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 15 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 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(); -- cgit v0.12 From 74d43d285f611a332d239c3669b7c90e23741b25 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 11 May 2009 09:21:21 +1000 Subject: Make sure we correctly remove the PathView attached property object. If we don't, we get some nasty random crashes. --- src/declarative/fx/qfxpathview.cpp | 7 ++++++- src/declarative/fx/qfxpathview.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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(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 attachedProperties; Q_DISABLE_COPY(QFxPathView) Q_DECLARE_PRIVATE(QFxPathView) -- cgit v0.12 From a365bd8f0cc53353ec8d3335ffec2d7810cf1d2a Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 11 May 2009 09:49:01 +1000 Subject: Change QList_int typedef back to QList - broke signal connection. --- src/declarative/3rdparty/qlistmodelinterface.cpp | 19 ++++--------------- src/declarative/3rdparty/qlistmodelinterface.h | 12 +++++------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/declarative/3rdparty/qlistmodelinterface.cpp b/src/declarative/3rdparty/qlistmodelinterface.cpp index 7e50378..e440cac 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.cpp +++ b/src/declarative/3rdparty/qlistmodelinterface.cpp @@ -69,22 +69,22 @@ QT_BEGIN_NAMESPACE Returns the number of data entries in the model. */ -/*! \fn QHash_int QListModelInterface::data(int index, const QList_int &roles) const +/*! \fn QHash_int QListModelInterface::data(int index, const QList &roles) const Returns the data at the given \a index for the specifed \a roles. */ -/*! \fn bool QListModelInterface::setData(int index, const QHash_int &values) +/*! \fn bool QListModelInterface::setData(int index, const QHash &values) Sets the data at the given \a index. \a values is a mapping of QVariant values to roles. */ /*! \fn bool QListModelInterface::setData(int index, const QVariant &value, int role) - This convenience function builds a QHash_int from + This convenience function builds a QHash from the specified \a role and \a value and calls the other setData() with the QHash and the \a index. */ -/*! \fn QList_int QListModelInterface::roles() const +/*! \fn QList QListModelInterface::roles() const Returns the list of roles for which the list model interface provides data. */ @@ -102,15 +102,4 @@ QT_BEGIN_NAMESPACE \value IconRole */ -/*! - \typedef QListModelInterface::QHash_int - - Synonym for QHash. -*/ - -/*! - \typedef QListModelInterface::QList_int - - Synonym for QList. -*/ QT_END_NAMESPACE diff --git a/src/declarative/3rdparty/qlistmodelinterface.h b/src/declarative/3rdparty/qlistmodelinterface.h index 8a0cf44..fd69edd 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.h +++ b/src/declarative/3rdparty/qlistmodelinterface.h @@ -68,21 +68,19 @@ class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject virtual int count() const = 0; - typedef QHash QHash_int; - typedef QList QList_int; - virtual QHash_int data(int index, const QList_int &roles = QList_int()) const = 0; + virtual QHash data(int index, const QList &roles = (QList())) const = 0; - virtual bool setData(int index, const QHash_int &values) + virtual bool setData(int index, const QHash &values) { Q_UNUSED(index); Q_UNUSED(values); return false; } inline bool setData(int index, const QVariant &value, int role) { - QHash_int values; + QHash values; values.insert(role, value); return setData(index, values); } - virtual QList_int roles() const = 0; + virtual QList roles() const = 0; virtual QString toString(int role) const = 0; //void bind(int index, int role, QObject *object, const char *propertyName, bool readOnly = true); @@ -91,7 +89,7 @@ class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject void itemsInserted(int index, int count); void itemsRemoved(int index, int count); void itemsMoved(int from, int to, int count); - void itemsChanged(int index, int count, const QList_int &roles); + void itemsChanged(int index, int count, const QList &roles); protected: QListModelInterface(QObjectPrivate &dd, QObject *parent) -- cgit v0.12 From de9825bf51ccb79f645c9ceeded3230c9be14175 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 11 May 2009 09:54:34 +1000 Subject: Get QListModelInterface back in line with itemviews_ng. --- src/declarative/3rdparty/qlistmodelinterface.cpp | 6 ------ src/declarative/3rdparty/qlistmodelinterface.h | 17 ----------------- 2 files changed, 23 deletions(-) diff --git a/src/declarative/3rdparty/qlistmodelinterface.cpp b/src/declarative/3rdparty/qlistmodelinterface.cpp index e440cac..d327b58 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.cpp +++ b/src/declarative/3rdparty/qlistmodelinterface.cpp @@ -78,12 +78,6 @@ QT_BEGIN_NAMESPACE QVariant values to roles. */ -/*! \fn bool QListModelInterface::setData(int index, const QVariant &value, int role) - This convenience function builds a QHash from - the specified \a role and \a value and calls the other setData() - with the QHash and the \a index. -*/ - /*! \fn QList QListModelInterface::roles() const Returns the list of roles for which the list model interface provides data. diff --git a/src/declarative/3rdparty/qlistmodelinterface.h b/src/declarative/3rdparty/qlistmodelinterface.h index fd69edd..191a95b 100644 --- a/src/declarative/3rdparty/qlistmodelinterface.h +++ b/src/declarative/3rdparty/qlistmodelinterface.h @@ -60,31 +60,14 @@ class Q_DECLARATIVE_EXPORT QListModelInterface : public QObject QListModelInterface(QObject *parent = 0) : QObject(parent) {} virtual ~QListModelInterface() {} - // ### move these into the Qt namespace - enum Roles { - TextRole = Qt::DisplayRole, - IconRole = Qt::DecorationRole - }; - virtual int count() const = 0; - virtual QHash data(int index, const QList &roles = (QList())) const = 0; - virtual bool setData(int index, const QHash &values) { Q_UNUSED(index); Q_UNUSED(values); return false; } - inline bool setData(int index, const QVariant &value, int role) - { - QHash values; - values.insert(role, value); - return setData(index, values); - } - virtual QList roles() const = 0; virtual QString toString(int role) const = 0; - //void bind(int index, int role, QObject *object, const char *propertyName, bool readOnly = true); - Q_SIGNALS: void itemsInserted(int index, int count); void itemsRemoved(int index, int count); -- cgit v0.12 From ac19c9a30a47bfe8b374d390525b06ebdb26b4ca Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 11 May 2009 10:21:47 +1000 Subject: Compile --- src/declarative/qml/qmlscriptparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp index 0092ec2..169e2ea 100644 --- a/src/declarative/qml/qmlscriptparser.cpp +++ b/src/declarative/qml/qmlscriptparser.cpp @@ -226,9 +226,9 @@ ProcessAST::defineObjectBinding_helper(int line, return 0; } - SourceLocation loc = typeLocation; + LocationSpan loc = ProcessAST::location(typeLocation, typeLocation); if (propertyName) - loc = location(propertyName); + loc = ProcessAST::location(propertyName); _stateStack.pushProperty(objectType, loc); accept(initializer); -- cgit v0.12