aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@jollamobile.com>2013-11-29 11:56:49 +1000
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-30 13:30:16 +0100
commit39b715f32a44c136271aecf2c3e28704cbf9e546 (patch)
treee747e3b0323a829329e2de1d633656623420cbc1
parent7a94cd02f7f45a4b58b494ec81fa425725ca9e0c (diff)
Set all attached section properties before emitting change signals.
If we have bindings to the section properties, e.g. implementing manual section header creation, we want previousSection, section and nextSection to be set before emitting the change signals to prevent different results each time the binding is run. Change-Id: Id3a0b4a53419681f35102c9e7c620b5c6112ebb0 Reviewed-by: Martin Jones <martin.jones@jollamobile.com>
-rw-r--r--src/quick/items/qquickitemview_p.h15
-rw-r--r--src/quick/items/qquicklistview.cpp16
-rw-r--r--tests/auto/quick/qquicklistview/data/listview-sections.qml25
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp2
4 files changed, 50 insertions, 8 deletions
diff --git a/src/quick/items/qquickitemview_p.h b/src/quick/items/qquickitemview_p.h
index 318f5361b5..17d150f480 100644
--- a/src/quick/items/qquickitemview_p.h
+++ b/src/quick/items/qquickitemview_p.h
@@ -324,6 +324,21 @@ public:
}
}
+ void setSections(const QString &prev, const QString &sect, const QString &next) {
+ bool prevChanged = prev != m_prevSection;
+ bool sectChanged = sect != m_section;
+ bool nextChanged = next != m_nextSection;
+ m_prevSection = prev;
+ m_section = sect;
+ m_nextSection = next;
+ if (prevChanged)
+ Q_EMIT prevSectionChanged();
+ if (sectChanged)
+ Q_EMIT sectionChanged();
+ if (nextChanged)
+ Q_EMIT nextSectionChanged();
+ }
+
void emitAdd() { Q_EMIT add(); }
void emitRemove() { Q_EMIT remove(); }
diff --git a/src/quick/items/qquicklistview.cpp b/src/quick/items/qquicklistview.cpp
index c55f9ef696..d6754ddfd1 100644
--- a/src/quick/items/qquicklistview.cpp
+++ b/src/quick/items/qquicklistview.cpp
@@ -487,7 +487,7 @@ QString QQuickListViewPrivate::sectionAt(int modelIndex)
return item->attached->section();
QString section;
- if (sectionCriteria) {
+ if (sectionCriteria && modelIndex >= 0 && modelIndex < itemCount) {
QString propValue = model->stringValue(modelIndex, sectionCriteria->property());
section = sectionCriteria->sectionString(propValue);
}
@@ -565,19 +565,19 @@ FxViewItem *QQuickListViewPrivate::newViewItem(int modelIndex, QQuickItem *item)
// initialise attached properties
if (sectionCriteria) {
QString propValue = model->stringValue(modelIndex, sectionCriteria->property());
- listItem->attached->setSection(sectionCriteria->sectionString(propValue));
+ QString section = sectionCriteria->sectionString(propValue);
+ QString prevSection;
+ QString nextSection;
if (modelIndex > 0) {
if (FxViewItem *item = itemBefore(modelIndex))
- listItem->attached->setPrevSection(item->attached->section());
+ prevSection = item->attached->section();
else
- listItem->attached->setPrevSection(sectionAt(modelIndex-1));
+ prevSection = sectionAt(modelIndex-1);
}
if (modelIndex < model->count()-1) {
- if (FxViewItem *item = visibleItem(modelIndex+1))
- listItem->attached->setNextSection(static_cast<QQuickListViewAttached*>(item->attached)->section());
- else
- listItem->attached->setNextSection(sectionAt(modelIndex+1));
+ nextSection = sectionAt(modelIndex+1);
}
+ listItem->attached->setSections(prevSection, section, nextSection);
}
return listItem;
diff --git a/tests/auto/quick/qquicklistview/data/listview-sections.qml b/tests/auto/quick/qquicklistview/data/listview-sections.qml
index d5b8a4400d..e9fb83910a 100644
--- a/tests/auto/quick/qquicklistview/data/listview-sections.qml
+++ b/tests/auto/quick/qquicklistview/data/listview-sections.qml
@@ -1,6 +1,7 @@
import QtQuick 2.0
Rectangle {
+ property bool sectionsInvalidOnCompletion
width: 240
height: 320
color: "#ffffff"
@@ -9,6 +10,26 @@ Rectangle {
id: myDelegate
Item {
id: wrapper
+
+ function validateInitialSections() {
+ var invalid = false
+ if (index == 0) {
+ invalid |= wrapper.ListView.previousSection != ""
+ }
+ if (index == model.count - 1) {
+ invalid |= wrapper.ListView.nextSection != ""
+ }
+ if (index % 5 == 0 && index > 0) {
+ invalid |= wrapper.ListView.previousSection != Number(wrapper.ListView.section) - 1
+ } else if ((index + 1) % 5 == 0 && index < model.count - 1) {
+ invalid |= wrapper.ListView.nextSection != Number(wrapper.ListView.section) + 1
+ } else if (index > 0 && index < model.count - 1) {
+ invalid |= wrapper.ListView.previousSection != wrapper.ListView.section
+ invalid |= wrapper.ListView.nextSection != wrapper.ListView.section
+ }
+ sectionsInvalidOnCompletion |= invalid
+ }
+
objectName: "wrapper"
height: ListView.previousSection != ListView.section ? 40 : 20;
width: 240
@@ -49,6 +70,10 @@ Rectangle {
visible: wrapper.ListView.previousSection != wrapper.ListView.section ? true : false
Text { text: wrapper.ListView.section }
}
+ ListView.onPreviousSectionChanged: validateInitialSections()
+ ListView.onNextSectionChanged: validateInitialSections()
+ ListView.onSectionChanged: validateInitialSections()
+ Component.onCompleted: validateInitialSections()
}
}
]
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index fb0b1c95ca..d888ba2b5c 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -1956,6 +1956,8 @@ void tst_QQuickListView::sections(const QUrl &source)
QCOMPARE(next->text().toInt(), (i+1)/5);
}
+ QVERIFY(!listview->property("sectionsInvalidOnCompletion").toBool());
+
QSignalSpy currentSectionChangedSpy(listview, SIGNAL(currentSectionChanged()));
// Remove section boundary