diff options
-rw-r--r-- | examples/quick/views/listview/displaymargin.qml | 93 | ||||
-rw-r--r-- | examples/quick/views/views.qml | 1 | ||||
-rw-r--r-- | examples/quick/views/views.qrc | 1 | ||||
-rw-r--r-- | src/quick/items/qquickgridview.cpp | 40 | ||||
-rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 1 | ||||
-rw-r--r-- | src/quick/items/qquickitemview.cpp | 40 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p.h | 10 | ||||
-rw-r--r-- | src/quick/items/qquickitemview_p_p.h | 2 | ||||
-rw-r--r-- | src/quick/items/qquicklistview.cpp | 39 | ||||
-rw-r--r-- | tests/auto/quick/qquickgridview/data/displayMargin.qml | 85 | ||||
-rw-r--r-- | tests/auto/quick/qquickgridview/tst_qquickgridview.cpp | 39 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/data/displayMargin.qml | 82 | ||||
-rw-r--r-- | tests/auto/quick/qquicklistview/tst_qquicklistview.cpp | 38 |
13 files changed, 456 insertions, 15 deletions
diff --git a/examples/quick/views/listview/displaymargin.qml b/examples/quick/views/listview/displaymargin.qml new file mode 100644 index 0000000000..c3402f6baa --- /dev/null +++ b/examples/quick/views/listview/displaymargin.qml @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.3 + +Item { + width: 480; height: 320 + + ListView { + id: view + anchors.top: header.bottom + anchors.bottom: footer.top + width: parent.width + + cacheBuffer: 0 + displayMarginBeginning: 40 + displayMarginEnd: 40 + + model: 100 + delegate: Rectangle { + objectName: "delegate" + width: parent.width + height: 25 + color: index % 2 ? "steelblue" : "lightsteelblue" + Text { + anchors.centerIn: parent + color: "white" + text: "Item " + (index + 1) + } + } + } + + Rectangle { + id: header + width: parent.width; height: 40 + color: "#AAFF0000" + + Text { + anchors.centerIn: parent + font.pixelSize: 24 + text: "Header" + } + } + + Rectangle { + id: footer + anchors.bottom: parent.bottom + width: parent.width; height: 40 + color: "#AAFF0000" + + Text { + anchors.centerIn: parent + font.pixelSize: 24 + text: "Footer" + } + } +} diff --git a/examples/quick/views/views.qml b/examples/quick/views/views.qml index 1bc6f6a3d8..2fbf9c5470 100644 --- a/examples/quick/views/views.qml +++ b/examples/quick/views/views.qml @@ -58,6 +58,7 @@ Item { addExample("Packages", "Transitions between a ListView and GridView", Qt.resolvedUrl("package/view.qml")) addExample("PathView", "A simple PathView", Qt.resolvedUrl("pathview/pathview-example.qml")) addExample("ObjectModel", "Using a ObjectModel", Qt.resolvedUrl("objectmodel/objectmodel.qml")) + addExample("Display Margins", "A ListView with display margins", Qt.resolvedUrl("listview/displaymargin.qml")) } } } diff --git a/examples/quick/views/views.qrc b/examples/quick/views/views.qrc index 434fa788bf..52abb68659 100644 --- a/examples/quick/views/views.qrc +++ b/examples/quick/views/views.qrc @@ -65,5 +65,6 @@ <file>visualdatamodel/dragselection.qml</file> <file>objectmodel/objectmodel.qml</file> <file>views.qml</file> + <file>listview/displaymargin.qml</file> </qresource> </RCC> diff --git a/src/quick/items/qquickgridview.cpp b/src/quick/items/qquickgridview.cpp index c9e6d4d7e2..43eb9ff6be 100644 --- a/src/quick/items/qquickgridview.cpp +++ b/src/quick/items/qquickgridview.cpp @@ -630,8 +630,8 @@ void QQuickGridViewPrivate::updateViewport() void QQuickGridViewPrivate::layoutVisibleItems(int fromModelIndex) { if (visibleItems.count()) { - 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; FxGridItemSG *firstItem = static_cast<FxGridItemSG*>(visibleItems.first()); qreal rowPos = firstItem->rowPos(); @@ -1534,7 +1534,35 @@ void QQuickGridView::setHighlightFollowsCurrentItem(bool autoHighlight) 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 may be scrolled. + + The cacheBuffer operates outside of any display margins specified by + displayMarginBeginning or displayMarginEnd. +*/ + +/*! + \qmlproperty int QtQuick::GridView::displayMarginBeginning + \qmlproperty int QtQuick::GridView::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, + there are 3 columns, and + \c displayMarginBeginning and \c displayMarginEnd are both set to 40, + then 6 delegates above and 6 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. */ + void QQuickGridView::setHighlightMoveDuration(int duration) { Q_D(QQuickGridView); @@ -2000,8 +2028,8 @@ void QQuickGridView::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) { FxGridItemSG *item = static_cast<FxGridItemSG*>(d->visibleItems.at(i)); QQuickItemPrivate::get(item->item)->setCulled(item->rowPos() + d->rowSize() < from || item->rowPos() > to); @@ -2350,7 +2378,7 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQmlChangeSet::Insert &ch // Insert items before the visible item. int insertionIdx = index; int i = count - 1; - int from = tempPos - buffer; + int from = tempPos - buffer - displayMarginBeginning; while (i >= 0) { if (rowPos > from && insertionIdx < visibleIndex) { @@ -2387,7 +2415,7 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QQmlChangeSet::Insert &ch } } else { int i = 0; - int to = buffer+tempPos+size()-1; + int to = buffer+displayMarginEnd+tempPos+size()-1; while (i < count && rowPos <= to + rowSize()*(columns - colNum)/qreal(columns+1)) { FxViewItem *item = 0; if (change.isMove() && (item = currentChanges.removedItems.take(change.moveKey(modelIndex + i)))) diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index a5b78b28e1..8b2b5d4fc8 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -261,6 +261,7 @@ 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")); + qmlRegisterUncreatableType<QQuickItemView, 2>(uri, 2, 3, "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 d9ff024d9f..6d4c2e7877 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -459,6 +459,41 @@ void QQuickItemView::setCacheBuffer(int b) } } +int QQuickItemView::displayMarginBeginning() const +{ + Q_D(const QQuickItemView); + return d->displayMarginBeginning; +} + +void QQuickItemView::setDisplayMarginBeginning(int margin) +{ + Q_D(QQuickItemView); + if (d->displayMarginBeginning != margin) { + d->displayMarginBeginning = margin; + if (isComponentComplete()) { + d->refillOrLayout(); + } + emit displayMarginBeginningChanged(); + } +} + +int QQuickItemView::displayMarginEnd() const +{ + Q_D(const QQuickItemView); + return d->displayMarginEnd; +} + +void QQuickItemView::setDisplayMarginEnd(int margin) +{ + Q_D(QQuickItemView); + if (d->displayMarginEnd != margin) { + d->displayMarginEnd = margin; + if (isComponentComplete()) { + d->refillOrLayout(); + } + emit displayMarginEndChanged(); + } +} Qt::LayoutDirection QQuickItemView::layoutDirection() const { @@ -1443,6 +1478,7 @@ void QQuickItemView::componentComplete() QQuickItemViewPrivate::QQuickItemViewPrivate() : itemCount(0) , buffer(QML_VIEW_DEFAULTCACHEBUFFER), bufferMode(BufferBefore | BufferAfter) + , displayMarginBeginning(0), displayMarginEnd(0) , layoutDirection(Qt::LeftToRight), verticalLayoutDirection(QQuickItemView::TopToBottom) , moveReason(Other) , visibleIndex(0) @@ -1682,9 +1718,9 @@ void QQuickItemViewPrivate::refill() { qreal s = qMax(size(), qreal(0.)); if (isContentFlowReversed()) - refill(-position()-s, -position()); + refill(-position()-displayMarginBeginning-s, -position()+displayMarginEnd); else - refill(position(), position()+s); + refill(position()-displayMarginBeginning, position()+displayMarginEnd+s); } void QQuickItemViewPrivate::refill(qreal from, qreal to) diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h index 318f5361b5..5931d6c09e 100644 --- a/src/quick/items/qquickitemview_p.h +++ b/src/quick/items/qquickitemview_p.h @@ -63,6 +63,8 @@ class Q_AUTOTEST_EXPORT QQuickItemView : public QQuickFlickable Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled NOTIFY keyNavigationWrapsChanged) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer NOTIFY cacheBufferChanged) + Q_PROPERTY(int displayMarginBeginning READ displayMarginBeginning WRITE setDisplayMarginBeginning NOTIFY displayMarginBeginningChanged REVISION 2) + Q_PROPERTY(int displayMarginEnd READ displayMarginEnd WRITE setDisplayMarginEnd NOTIFY displayMarginEndChanged REVISION 2) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) @@ -133,6 +135,12 @@ public: int cacheBuffer() const; void setCacheBuffer(int); + int displayMarginBeginning() const; + void setDisplayMarginBeginning(int); + + int displayMarginEnd() const; + void setDisplayMarginEnd(int); + Qt::LayoutDirection layoutDirection() const; void setLayoutDirection(Qt::LayoutDirection); Qt::LayoutDirection effectiveLayoutDirection() const; @@ -218,6 +226,8 @@ Q_SIGNALS: void keyNavigationWrapsChanged(); void cacheBufferChanged(); + void displayMarginBeginningChanged(); + void displayMarginEndChanged(); void layoutDirectionChanged(); void effectiveLayoutDirectionChanged(); diff --git a/src/quick/items/qquickitemview_p_p.h b/src/quick/items/qquickitemview_p_p.h index c528fa3b2c..bb1b7927c2 100644 --- a/src/quick/items/qquickitemview_p_p.h +++ b/src/quick/items/qquickitemview_p_p.h @@ -256,6 +256,8 @@ public: int itemCount; int buffer; int bufferMode; + int displayMarginBeginning; + int displayMarginEnd; Qt::LayoutDirection layoutDirection; QQuickItemView::VerticalLayoutDirection verticalLayoutDirection; 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)))) diff --git a/tests/auto/quick/qquickgridview/data/displayMargin.qml b/tests/auto/quick/qquickgridview/data/displayMargin.qml new file mode 100644 index 0000000000..1086b8defd --- /dev/null +++ b/tests/auto/quick/qquickgridview/data/displayMargin.qml @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.3 + +Item { + width: 400; height: 400 + + GridView { + id: view + anchors.top: header.bottom + anchors.bottom: footer.top + width: parent.width + + cellWidth: 50 + cellHeight: 25 + + cacheBuffer: 0 + displayMarginBeginning: 60 + displayMarginEnd: 60 + + model: 200 + delegate: Rectangle { + objectName: "delegate" + width: 50 + height: 25 + color: index % 2 ? "steelblue" : "lightsteelblue" + Text { + anchors.centerIn: parent + text: index + } + } + } + + Rectangle { + id: header + width: parent.width; height: 60 + color: "#80FF0000" + } + + Rectangle { + id: footer + anchors.bottom: parent.bottom + width: parent.width; height: 60 + color: "#80FF0000" + } +} diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index f1adb7858f..2ee98c6c61 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -207,6 +207,8 @@ private slots: void moved_topToBottom_RtL_BtT(); void moved_topToBottom_RtL_BtT_data(); + void displayMargin(); + private: QList<int> toIntList(const QVariantList &list); void matchIndexLists(const QVariantList &indexLists, const QList<int> &expectedIndexes); @@ -6307,6 +6309,43 @@ void tst_QQuickGridView::matchItemLists(const QVariantList &itemLists, const QLi } } +void tst_QQuickGridView::displayMargin() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("displayMargin.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickGridView *gridview = window->rootObject()->findChild<QQuickGridView*>(); + QVERIFY(gridview != 0); + + QQuickItem *content = gridview->contentItem(); + QVERIFY(content != 0); + + QQuickItem *item0; + QQuickItem *item97; + + QVERIFY(item0 = findItem<QQuickItem>(content, "delegate", 0)); + QCOMPARE(delegateVisible(item0), true); + + // the 97th item should be within the end margin + QVERIFY(item97 = findItem<QQuickItem>(content, "delegate", 96)); + QCOMPARE(delegateVisible(item97), true); + + // GridView staggers item creation, so the 118th item should be outside the end margin. + QVERIFY(findItem<QQuickItem>(content, "delegate", 117) == 0); + + // the first delegate should still be within the begin margin + gridview->positionViewAtIndex(20, QQuickGridView::Beginning); + QCOMPARE(delegateVisible(item0), true); + + // the first delegate should now be outside the begin margin + gridview->positionViewAtIndex(36, QQuickGridView::Beginning); + QCOMPARE(delegateVisible(item0), false); + + delete window; +} + QTEST_MAIN(tst_QQuickGridView) #include "tst_qquickgridview.moc" diff --git a/tests/auto/quick/qquicklistview/data/displayMargin.qml b/tests/auto/quick/qquicklistview/data/displayMargin.qml new file mode 100644 index 0000000000..fde48bc5b9 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/displayMargin.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Jolla Ltd. +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.3 + +Item { + width: 400; height: 400 + + ListView { + id: view + anchors.top: header.bottom + anchors.bottom: footer.top + width: parent.width + + cacheBuffer: 0 + displayMarginBeginning: 60 + displayMarginEnd: 60 + + model: 100 + delegate: Rectangle { + objectName: "delegate" + width: parent.width + height: 25 + color: index % 2 ? "steelblue" : "lightsteelblue" + Text { + anchors.centerIn: parent + text: index + } + } + } + + Rectangle { + id: header + width: parent.width; height: 60 + color: "#80FF0000" + } + + Rectangle { + id: footer + anchors.bottom: parent.bottom + width: parent.width; height: 60 + color: "#80FF0000" + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index fb0b1c95ca..c3a5c64ba1 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -215,6 +215,7 @@ private slots: void testProxyModelChangedAfterMove(); void typedModel(); + void displayMargin(); private: template <class T> void items(const QUrl &source); @@ -7010,6 +7011,43 @@ void tst_QQuickListView::typedModel() QCOMPARE(listview->count(), 0); } +void tst_QQuickListView::displayMargin() +{ + QQuickView *window = createView(); + window->setSource(testFileUrl("displayMargin.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QQuickListView *listview = window->rootObject()->findChild<QQuickListView*>(); + QVERIFY(listview != 0); + + QQuickItem *content = listview->contentItem(); + QVERIFY(content != 0); + + QQuickItem *item0; + QQuickItem *item14; + + QVERIFY(item0 = findItem<QQuickItem>(content, "delegate", 0)); + QCOMPARE(delegateVisible(item0), true); + + // the 14th item should be within the end margin + QVERIFY(item14 = findItem<QQuickItem>(content, "delegate", 13)); + QCOMPARE(delegateVisible(item14), true); + + // the 15th item should be outside the end margin + QVERIFY(findItem<QQuickItem>(content, "delegate", 14) == 0); + + // the first delegate should still be within the begin margin + listview->positionViewAtIndex(3, QQuickListView::Beginning); + QCOMPARE(delegateVisible(item0), true); + + // the first delegate should now be outside the begin margin + listview->positionViewAtIndex(4, QQuickListView::Beginning); + QCOMPARE(delegateVisible(item0), false); + + delete window; +} + QTEST_MAIN(tst_QQuickListView) #include "tst_qquicklistview.moc" |