diff options
author | Alan Alpert <[email protected]> | 2013-04-11 16:57:19 -0700 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-04-26 21:17:42 +0200 |
commit | 53e317468626284fe26877659dff551ce3bc0e55 (patch) | |
tree | bb129a2df33f3a283bcb7e6f33be6b00659b4467 /src | |
parent | 8563adb737cec5d440197ddbd514fe201c5f18ff (diff) |
No longer apply pending changes when accessing ItemView properties
Applying changes in the getters can lead to binding loops, and is
currently inconsistently applied. Removing the applyPendingChanges calls
from remaining getters, and adding a forceLayout() function for cases
where the immediate-apply behavior is needed.
Task-number: QTBUG-30555
Parts-of-patch-by: Albert Astals Cid
Change-Id: I64632601e02f2a53060296ab7739577a749d916f
Reviewed-by: Andrew den Exter <[email protected]>
Reviewed-by: Albert Astals Cid <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/quick/items/qquickgridview.cpp | 16 | ||||
-rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 3 | ||||
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 13 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p.h | 1 | ||||
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 15 |
5 files changed, 41 insertions, 7 deletions
diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index e40d21b498..f4e34da318 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -2564,6 +2564,22 @@ bool QQuickGridViewPrivate::needsRefillForAddedOrRemovedIndex(int modelIndex) co \b Note: methods should only be called after the Component has completed. */ + +/*! + \qmlmethod QtQuick2::GridView::forceLayout() + + Responding to changes in the model is usually batched to happen only once + per frame. This means that inside script blocks it is possible for the + underlying model to have changed, but the GridView has not caught up yet. + + This method forces the GridView to immediately respond to any outstanding + changes in the model. + + \since 5.1 + + \b Note: methods should only be called after the Component has completed. +*/ + QQuickGridViewAttached *QQuickGridView::qmlAttachedProperties(QObject *obj) { return new QQuickGridViewAttached(obj); diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 741583a95d..f5bcf3596f 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -230,6 +230,9 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickItem, 1>(uri, 2, 1,"Item"); qmlRegisterType<QQuickGrid, 1>(uri, 2, 1, "Grid"); + qmlRegisterUncreatableType<QQuickItemView, 1>(uri, 2, 1, "ItemView", QQuickItemView::tr("ItemView is an abstract base class")); + qmlRegisterType<QQuickListView, 1>(uri, 2, 1, "ListView"); + qmlRegisterType<QQuickGridView, 1>(uri, 2, 1, "GridView"); qmlRegisterType<QQuickTextEdit, 1>(uri, 2, 1, "TextEdit"); } diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 03e16f2ebf..d774091ef5 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -249,7 +249,6 @@ QQuickItemView::~QQuickItemView() QQuickItem *QQuickItemView::currentItem() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->currentItem ? d->currentItem->item : 0; } @@ -379,14 +378,12 @@ int QQuickItemView::count() const Q_D(const QQuickItemView); if (!d->model) return 0; - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->model->count(); } int QQuickItemView::currentIndex() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->currentIndex; } @@ -496,7 +493,6 @@ QQmlComponent *QQuickItemView::header() const QQuickItem *QQuickItemView::headerItem() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->header ? d->header->item : 0; } @@ -532,7 +528,6 @@ QQmlComponent *QQuickItemView::footer() const QQuickItem *QQuickItemView::footerItem() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->footer ? d->footer->item : 0; } @@ -559,7 +554,6 @@ void QQuickItemView::setFooter(QQmlComponent *footerComponent) QQmlComponent *QQuickItemView::highlight() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->highlightComponent; } @@ -579,7 +573,6 @@ void QQuickItemView::setHighlight(QQmlComponent *highlightComponent) QQuickItem *QQuickItemView::highlightItem() const { Q_D(const QQuickItemView); - const_cast<QQuickItemViewPrivate*>(d)->applyPendingChanges(); return d->highlight ? d->highlight->item : 0; } @@ -965,6 +958,12 @@ QQuickItem *QQuickItemView::itemAt(qreal x, qreal y) const return 0; } +void QQuickItemView::forceLayout() +{ + Q_D(QQuickItemView); + d->applyPendingChanges(); +} + void QQuickItemViewPrivate::applyPendingChanges() { Q_Q(QQuickItemView); diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index b0f910680a..d7812bcdad 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -202,6 +202,7 @@ public: Q_INVOKABLE QQuickItem *itemAt(qreal x, qreal y) const; Q_INVOKABLE void positionViewAtBeginning(); Q_INVOKABLE void positionViewAtEnd(); + Q_REVISION(1) Q_INVOKABLE void forceLayout(); virtual void setContentX(qreal pos); virtual void setContentY(qreal pos); diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 53dc715469..b99fba4e4c 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -3108,6 +3108,21 @@ void QQuickListViewPrivate::translateAndTransitionItemsAfter(int afterModelIndex \b Note: methods should only be called after the Component has completed. */ +/*! + \qmlmethod QtQuick2::ListView::forceLayout() + + Responding to changes in the model is usually batched to happen only once + per frame. This means that inside script blocks it is possible for the + underlying model to have changed, but the ListView has not caught up yet. + + This method forces the ListView to immediately respond to any outstanding + changes in the model. + + \since 5.1 + + \b Note: methods should only be called after the Component has completed. +*/ + QQuickListViewAttached *QQuickListView::qmlAttachedProperties(QObject *obj) { return new QQuickListViewAttached(obj); |