summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2010-12-01 07:30:52 (GMT)
committerMartin Jones <martin.jones@nokia.com>2010-12-01 07:30:52 (GMT)
commit1337a3e031477aa4d628d01252557dee622629ff (patch)
tree806bfbd9aa75ed94adddac06d4213e820b8a3eaf
parente46bf51f830dcc80932b9219fe608d1bc1a388ad (diff)
downloadQt-1337a3e031477aa4d628d01252557dee622629ff.zip
Qt-1337a3e031477aa4d628d01252557dee622629ff.tar.gz
Qt-1337a3e031477aa4d628d01252557dee622629ff.tar.bz2
ListView header is not visible initially.
If the header size was not set explicitly, but determined implicitly from Text height, the view was not positioned so that the header was visible when first shown. Task-number: QTBUG-15599 Reviewed-by: Bea Lam
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp16
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp22
-rw-r--r--tests/auto/declarative/qdeclarativelistview/data/header1.qml33
-rw-r--r--tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp67
4 files changed, 108 insertions, 30 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 4454284..1615b0f 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -1769,8 +1769,10 @@ void QDeclarativeGridView::setFooter(QDeclarativeComponent *footer)
d->footer = 0;
}
d->footerComponent = footer;
- d->updateFooter();
- d->updateGrid();
+ if (isComponentComplete()) {
+ d->updateFooter();
+ d->updateGrid();
+ }
emit footerChanged();
}
}
@@ -1799,9 +1801,11 @@ void QDeclarativeGridView::setHeader(QDeclarativeComponent *header)
d->header = 0;
}
d->headerComponent = header;
- d->updateHeader();
- d->updateFooter();
- d->updateGrid();
+ if (isComponentComplete()) {
+ d->updateHeader();
+ d->updateFooter();
+ d->updateGrid();
+ }
emit headerChanged();
}
}
@@ -2226,6 +2230,8 @@ void QDeclarativeGridView::componentComplete()
{
Q_D(QDeclarativeGridView);
QDeclarativeFlickable::componentComplete();
+ d->updateHeader();
+ d->updateFooter();
d->updateGrid();
if (d->isValid()) {
refill();
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index d1f52be..845da79 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -402,6 +402,8 @@ public:
void itemGeometryChanged(QDeclarativeItem *item, const QRectF &newGeometry, const QRectF &oldGeometry) {
Q_Q(QDeclarativeListView);
QDeclarativeFlickablePrivate::itemGeometryChanged(item, newGeometry, oldGeometry);
+ if (!q->isComponentComplete())
+ return;
if (item != contentItem && (!highlight || item != highlight->item)) {
if ((orient == QDeclarativeListView::Vertical && newGeometry.height() != oldGeometry.height())
|| (orient == QDeclarativeListView::Horizontal && newGeometry.width() != oldGeometry.width())) {
@@ -1123,8 +1125,6 @@ void QDeclarativeListViewPrivate::updateHeader()
QDeclarativeItemPrivate *itemPrivate = static_cast<QDeclarativeItemPrivate*>(QGraphicsItemPrivate::get(item));
itemPrivate->addItemChangeListener(this, QDeclarativeItemPrivate::Geometry);
header = new FxListItem(item, q);
- if (visibleItems.isEmpty())
- visiblePos = header->size();
}
}
if (header) {
@@ -1137,6 +1137,8 @@ void QDeclarativeListViewPrivate::updateHeader()
header->setPosition(startPos - header->size());
}
} else {
+ if (itemCount == 0)
+ visiblePos = header->size();
header->setPosition(0);
}
}
@@ -2215,8 +2217,10 @@ void QDeclarativeListView::setFooter(QDeclarativeComponent *footer)
d->footerComponent = footer;
d->minExtentDirty = true;
d->maxExtentDirty = true;
- d->updateFooter();
- d->updateViewport();
+ if (isComponentComplete()) {
+ d->updateFooter();
+ d->updateViewport();
+ }
emit footerChanged();
}
}
@@ -2247,9 +2251,11 @@ void QDeclarativeListView::setHeader(QDeclarativeComponent *header)
d->headerComponent = header;
d->minExtentDirty = true;
d->maxExtentDirty = true;
- d->updateHeader();
- d->updateFooter();
- d->updateViewport();
+ if (isComponentComplete()) {
+ d->updateHeader();
+ d->updateFooter();
+ d->updateViewport();
+ }
emit headerChanged();
}
}
@@ -2659,6 +2665,8 @@ void QDeclarativeListView::componentComplete()
Q_D(QDeclarativeListView);
QDeclarativeFlickable::componentComplete();
updateSections();
+ d->updateHeader();
+ d->updateFooter();
if (d->isValid()) {
refill();
d->moveReason = QDeclarativeListViewPrivate::SetIndex;
diff --git a/tests/auto/declarative/qdeclarativelistview/data/header1.qml b/tests/auto/declarative/qdeclarativelistview/data/header1.qml
new file mode 100644
index 0000000..f2ab4c1
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativelistview/data/header1.qml
@@ -0,0 +1,33 @@
+import QtQuick 1.0
+
+Rectangle {
+ width: 240
+ height: 320
+ color: "#ffffff"
+
+ ListModel { id: testModel }
+
+ ListView {
+ id: list
+ objectName: "list"
+ width: parent.width
+ anchors.top: parent.top
+ anchors.bottom: parent.bottom
+ model: testModel
+ delegate: Text {
+ objectName: "wrapper"
+ font.pointSize: 20
+ text: index
+ }
+ footer: Rectangle {
+ width: parent.width
+ height: 40
+ color: "green"
+ }
+ header: Text { objectName: "header"; text: "Header" }
+ }
+
+ Component.onCompleted: {
+ for (var i=0; i<30; i++) testModel.append({"name" : i, "val": i})
+ }
+}
diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
index 295a75d..759caf2 100644
--- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
+++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
@@ -1664,32 +1664,63 @@ void tst_QDeclarativeListView::QTBUG_11105()
void tst_QDeclarativeListView::header()
{
- QDeclarativeView *canvas = createView();
+ {
+ QDeclarativeView *canvas = createView();
- TestModel model;
- for (int i = 0; i < 30; i++)
- model.addItem("Item" + QString::number(i), "");
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
- QDeclarativeContext *ctxt = canvas->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
- canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header.qml"));
- qApp->processEvents();
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header.qml"));
+ qApp->processEvents();
- QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list");
- QTRY_VERIFY(listview != 0);
+ QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
- QDeclarativeItem *contentItem = listview->contentItem();
- QTRY_VERIFY(contentItem != 0);
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
- QDeclarativeText *header = findItem<QDeclarativeText>(contentItem, "header");
- QVERIFY(header);
- QCOMPARE(header->y(), 0.0);
+ QDeclarativeText *header = findItem<QDeclarativeText>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), 0.0);
- QCOMPARE(listview->contentY(), 0.0);
+ QCOMPARE(listview->contentY(), 0.0);
- model.clear();
- QTRY_COMPARE(header->y(), 0.0);
+ model.clear();
+ QTRY_COMPARE(header->y(), 0.0);
+
+ delete canvas;
+ }
+ {
+ QDeclarativeView *canvas = createView();
+
+ TestModel model;
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header1.qml"));
+ qApp->processEvents();
+
+ QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ QDeclarativeItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ QDeclarativeText *header = findItem<QDeclarativeText>(contentItem, "header");
+ QVERIFY(header);
+ QCOMPARE(header->y(), 0.0);
+
+ QCOMPARE(listview->contentY(), 0.0);
+
+ model.clear();
+ QTRY_COMPARE(header->y(), 0.0);
+
+ delete canvas;
+ }
}
void tst_QDeclarativeListView::footer()