diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index 82658c73fc706b7b9278c92adc3d023cdef52464..2c03903f3674e078a3b639fd5df85787410065d4 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -1524,7 +1524,7 @@ void QQuickGridView::setHighlightFollowsCurrentItem(bool autoHighlight) This property determines whether delegates are retained outside the visible area of the view. - If non-zero the view may keep as many delegates + If this value is greater than zero, the view may keep as many delegates instantiated as will fit within the buffer specified. For example, if in a vertical view the delegate is 20 pixels high, there are 3 columns and \c cacheBuffer is @@ -1535,7 +1535,7 @@ void QQuickGridView::setHighlightFollowsCurrentItem(bool autoHighlight) delegates outside the visible area are not painted. The default value of this property is platform dependent, but will usually - be a non-zero value. + be a value greater than zero. Negative values are ignored. Note that cacheBuffer is not a pixel buffer - it only maintains additional instantiated delegates. diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index b4f6c34c6a6a13dc6097411f343442870c70e4ab..87e6728f86bfbe048bb4562b8ce931aa7e028f1c 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -454,6 +454,11 @@ int QQuickItemView::cacheBuffer() const void QQuickItemView::setCacheBuffer(int b) { Q_D(QQuickItemView); + if (b < 0) { + qmlInfo(this) << "Cannot set a negative cache buffer"; + return; + } + if (d->buffer != b) { d->buffer = b; if (isComponentComplete()) { diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp index 8f9dbb567f56cca4cff85cf386c1e2d760311a07..ba4f1c53baa824615439250da52091279f350441 100644 --- a/src/quick/items/qquicklistview.cpp +++ b/src/quick/items/qquicklistview.cpp @@ -2138,7 +2138,7 @@ void QQuickListView::setOrientation(QQuickListView::Orientation orientation) This property determines whether delegates are retained outside the visible area of the view. - If this value is non-zero, the view may keep as many delegates + If this value is greater than zero, the view may keep as many delegates instantiated as it can fit within the buffer specified. For example, if in a vertical view the delegate is 20 pixels high and \c cacheBuffer is set to 40, then up to 2 delegates above and 2 delegates below the visible @@ -2148,7 +2148,7 @@ void QQuickListView::setOrientation(QQuickListView::Orientation orientation) delegates outside the visible area are not painted. The default value of this property is platform dependent, but will usually - be a non-zero value. + be a value greater than zero. Negative values are ignored. Note that cacheBuffer is not a pixel buffer - it only maintains additional instantiated delegates. diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index 29755e389040b88ee888297640382f4b0c117ecf..5cc3c7e642c237356c7e86e8fe568994db55b27c 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -3012,6 +3012,10 @@ void tst_QQuickListView::cacheBuffer() controller.incubateWhile(&b); } + // negative cache buffer is ignored + listview->setCacheBuffer(-1); + QCOMPARE(listview->cacheBuffer(), 200); + delete window; delete testObject; }