aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquicklistview.cpp
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@jollamobile.com>2013-08-29 07:48:29 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-11 23:17:51 +0100
commita46312b3b5f97802b8a74e53a86ce4a57df320ef (patch)
tree51c6469883f911e11e20d89f97c1d7d81c89e0ec /src/quick/items/qquicklistview.cpp
parentb3d881f4defa836446410febbdabd1e714001a3f (diff)
Add displayMarginBeginning/End to ListView and GridView.
This allows displaying content outside the visible area of the view. [ChangeLog][QtQuick] Add displayMarginBeginning/End to ListView and GridView. Change-Id: Idf9b5a0cd34a781c9603a9ad98ea189754972ba1 Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com>
Diffstat (limited to 'src/quick/items/qquicklistview.cpp')
-rw-r--r--src/quick/items/qquicklistview.cpp39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index c55f9ef696..7f6c7fdbb9 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -774,8 +774,8 @@ void QQuickListViewPrivate::visibleItemsChanged()
void QQuickListViewPrivate::layoutVisibleItems(int fromModelIndex)
{
if (!visibleItems.isEmpty()) {
- const qreal from = isContentFlowReversed() ? -position() - size() : position();
- const qreal to = isContentFlowReversed() ? -position() : position() + size();
+ const qreal from = isContentFlowReversed() ? -position()-displayMarginBeginning-size() : position()-displayMarginBeginning;
+ const qreal to = isContentFlowReversed() ? -position()+displayMarginEnd : position()+size()+displayMarginEnd;
FxViewItem *firstItem = *visibleItems.constBegin();
bool fixedCurrent = currentItem && firstItem->item == currentItem->item;
@@ -2126,8 +2126,33 @@ void QQuickListView::setOrientation(QQuickListView::Orientation orientation)
of additional memory usage. It is not a substitute for creating efficient
delegates; the fewer objects and bindings in a delegate, the faster a view can be
scrolled.
+
+ The cacheBuffer operates outside of any display margins specified by
+ displayMarginBeginning or displayMarginEnd.
*/
+/*!
+ \qmlproperty int QtQuick::ListView::displayMarginBeginning
+ \qmlproperty int QtQuick::ListView::displayMarginEnd
+ \since QtQuick 2.3
+
+ This property allows delegates to be displayed outside of the view geometry.
+
+ If this value is non-zero, the view will create extra delegates before the
+ start of the view, or after the end. The view will create as many delegates
+ as it can fit into the pixel size specified.
+
+ For example, if in a vertical view the delegate is 20 pixels high and
+ \c displayMarginBeginning and \c displayMarginEnd are both set to 40,
+ then 2 delegates above and 2 delegates below will be created and shown.
+
+ The default value is 0.
+
+ This property is meant for allowing certain UI configurations,
+ and not as a performance optimization. If you wish to create delegates
+ outside of the view geometry for performance reasons, you probably
+ want to use the cacheBuffer property instead.
+*/
/*!
\qmlproperty string QtQuick::ListView::section.property
@@ -2679,8 +2704,8 @@ void QQuickListView::viewportMoved(Qt::Orientations orient)
d->refillOrLayout();
// Set visibility of items to eliminate cost of items outside the visible area.
- qreal from = d->isContentFlowReversed() ? -d->position()-d->size() : d->position();
- qreal to = d->isContentFlowReversed() ? -d->position() : d->position()+d->size();
+ qreal from = d->isContentFlowReversed() ? -d->position()-d->displayMarginBeginning-d->size() : d->position()-d->displayMarginBeginning;
+ qreal to = d->isContentFlowReversed() ? -d->position()+d->displayMarginEnd : d->position()+d->size()+d->displayMarginEnd;
for (int i = 0; i < d->visibleItems.count(); ++i) {
FxViewItem *item = static_cast<FxListItemSG*>(d->visibleItems.at(i));
QQuickItemPrivate::get(item->item)->setCulled(item->endPosition() < from || item->position() > to);
@@ -2886,7 +2911,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Insert &ch
// there are no visible items except items marked for removal
index = visibleItems.count();
} else if (visibleItems.at(i)->index + 1 == modelIndex
- && visibleItems.at(i)->endPosition() <= buffer+tempPos+size()) {
+ && visibleItems.at(i)->endPosition() <= buffer+displayMarginEnd+tempPos+size()) {
// Special case of appending an item to the model.
index = visibleItems.count();
} else {
@@ -2915,7 +2940,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Insert &ch
// Insert items before the visible item.
int insertionIdx = index;
int i = 0;
- int from = tempPos - buffer;
+ int from = tempPos - displayMarginBeginning - buffer;
for (i = count-1; i >= 0; --i) {
if (pos > from && insertionIdx < visibleIndex) {
@@ -2946,7 +2971,7 @@ bool QQuickListViewPrivate::applyInsertionChange(const QQmlChangeSet::Insert &ch
}
} else {
int i = 0;
- int to = buffer+tempPos+size();
+ int to = buffer+displayMarginEnd+tempPos+size();
for (i = 0; i < count && pos <= to; ++i) {
FxViewItem *item = 0;
if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i))))