Fix: ListView footer positioned wrong after last item removed
The refill() method would bail out early on an empty model. Make sure that it at least updates the header and footer in such situations. Fixes: QTBUG-31677 Change-Id: I1f3a1848ff263a8f7f9ccfc3b20f16b61348f57b Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
This commit is contained in:
parent
b8a85408d9
commit
692b2da774
|
@ -1717,8 +1717,14 @@ void QQuickItemViewPrivate::refill()
|
|||
void QQuickItemViewPrivate::refill(qreal from, qreal to)
|
||||
{
|
||||
Q_Q(QQuickItemView);
|
||||
if (!isValid() || !q->isComponentComplete())
|
||||
if (!model || !model->isValid() || !q->isComponentComplete())
|
||||
return;
|
||||
if (!model->count()) {
|
||||
updateHeader();
|
||||
updateFooter();
|
||||
updateViewport();
|
||||
return;
|
||||
}
|
||||
|
||||
do {
|
||||
bufferPause.stop();
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
import QtQuick 2.0
|
||||
|
||||
Rectangle {
|
||||
width: 240
|
||||
height: 320
|
||||
|
||||
Timer {
|
||||
running: true
|
||||
repeat: false
|
||||
interval: 100
|
||||
onTriggered: {
|
||||
list.model -= 3;
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: list
|
||||
objectName: "list"
|
||||
anchors.fill: parent
|
||||
model: 3
|
||||
delegate: Rectangle {
|
||||
color: "red"
|
||||
width: 240
|
||||
height: 10
|
||||
}
|
||||
footer: Rectangle {
|
||||
color: "blue"
|
||||
width: 240
|
||||
height: 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -152,6 +152,7 @@ private slots:
|
|||
void headerChangesViewport();
|
||||
void footer();
|
||||
void footer_data();
|
||||
void footer2();
|
||||
void extents();
|
||||
void extents_data();
|
||||
void resetModel_headerFooter();
|
||||
|
@ -4138,6 +4139,21 @@ void tst_QQuickListView::footer_data()
|
|||
<< QPointF(0, -(30 * 20) - 10);
|
||||
}
|
||||
|
||||
void tst_QQuickListView::footer2() // QTBUG-31677
|
||||
{
|
||||
QQuickView *window = getView();
|
||||
window->setSource(testFileUrl("footer2.qml"));
|
||||
window->show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(window));
|
||||
|
||||
QQuickListView *listview = findItem<QQuickListView>(window->rootObject(), "list");
|
||||
QTRY_VERIFY(listview != nullptr);
|
||||
|
||||
QQuickItem *footer = listview->footerItem();
|
||||
QVERIFY(footer != nullptr);
|
||||
QTRY_COMPARE(footer->y(), 0.0);
|
||||
}
|
||||
|
||||
class LVAccessor : public QQuickListView
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in New Issue