summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNils Jeisecke <jeisecke@saltation.de>2013-02-15 17:00:15 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-02-20 09:41:58 (GMT)
commita4c225257cd502ccf549140d2e74b15e7d03ac05 (patch)
treec9420cc6409b43124db1d8df57ef32e4ffcade44
parentbe81e1e2e49db99f709273079680e4026e9e77b6 (diff)
downloadQt-a4c225257cd502ccf549140d2e74b15e7d03ac05.zip
Qt-a4c225257cd502ccf549140d2e74b15e7d03ac05.tar.gz
Qt-a4c225257cd502ccf549140d2e74b15e7d03ac05.tar.bz2
Fix QDeclarativeListView currentSection property update
Model modifications that did not trigger the refill logic caused the view's currentSection property to contain an outdated value. A new autotest has been added to catch the bug. Task-number: QTBUG-29712 Change-Id: I88cf1295ac55dad7596b6ba1fe475ebf98a31026 Reviewed-by: Alan Alpert <aalpert@rim.com> (cherry picked from qtquick1/d31f965b72a1bb8aba0b846471780e90fcc895ba)
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp31
2 files changed, 33 insertions, 0 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index b078c31..38b3c4d 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -896,6 +896,8 @@ void QDeclarativeListViewPrivate::layout()
fixupPosition();
q->refill();
}
+ if (sectionCriteria)
+ updateCurrentSection();
if (header)
updateHeader();
if (footer)
diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
index a99b4aa..9462a52 100644
--- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
+++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp
@@ -91,6 +91,7 @@ private slots:
void enforceRange();
void spacing();
void sections();
+ void currentSection();
void sectionsDelegate();
void cacheBuffer();
void positionViewAtIndex();
@@ -1055,6 +1056,36 @@ void tst_QDeclarativeListView::sections()
delete canvas;
}
+void tst_QDeclarativeListView::currentSection()
+{
+ // QTBUG-29712
+ // update currentSection correctly if model modifications
+ // do not trigger a refill
+ QDeclarativeView *canvas = createView();
+
+ TestModel model;
+ for (int i = 0; i < 5; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview-sections.qml"));
+ qApp->processEvents();
+
+ QDeclarativeListView *listview = findItem<QDeclarativeListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ // make sure the listView won't trigger refill when removing the first row
+ QTRY_VERIFY(listview->height() > model.count() * 40);
+
+ QTRY_COMPARE(listview->currentSection(), QString("0"));
+ model.removeItem(0);
+ QTRY_COMPARE(listview->currentSection(), QString("1"));
+
+ delete canvas;
+}
+
void tst_QDeclarativeListView::sectionsDelegate()
{
QDeclarativeView *canvas = createView();