on xenial help sign in
Update the section header on list change events
572c1b9Albert Astals
plugins/ListViewWithPageHeader/listviewwithpageheader.cpp+14
@@ -199,6 +199,7 @@ void ListViewWithPageHeader::setModel(QAbstractItemModel *model)
199 connect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
199 connect(m_delegateModel, SIGNAL(modelUpdated(QQmlChangeSet,bool)), this, SLOT(onModelUpdated(QQmlChangeSet,bool)));
200#endif
200#endif
201 Q_EMIT modelChanged();
201 Q_EMIT modelChanged();
202+ polish();
202 // TODO?
203 // TODO?
203// Q_EMIT contentHeightChanged();
204// Q_EMIT contentHeightChanged();
204// Q_EMIT contentYChanged();
205// Q_EMIT contentYChanged();
@@ -1006,6 +1007,18 @@ void ListViewWithPageHeader::onModelUpdated(const QQmlChangeSet &changeSet, bool
1006 }
1007 }
1007 }
1008 }
1008
1009
1010+ Q_FOREACH(const QQuickChangeSet::Change &change, changeSet.changes()) {
1011+// qDebug() << "ListViewWithPageHeader::onModelUpdated Change" << change.index << change.count;
1012+ for (int i = change.index; i < change.count; ++i) {
1013+ ListItem *item = itemAtIndex(i);
1014+ if (item && item->m_sectionItem) {
1015+ QQmlContext *context = QQmlEngine::contextForObject(item->m_sectionItem)->parentContext();
1016+ const QString sectionText = m_delegateModel->stringValue(i, m_sectionProperty);
1017+ context->setContextProperty(QLatin1String("section"), sectionText);
1018+ }
1019+ }
1020+ }
1021+
1009 if (m_firstVisibleIndex != oldFirstVisibleIndex) {
1022 if (m_firstVisibleIndex != oldFirstVisibleIndex) {
1010 adjustMinYExtent();
1023 adjustMinYExtent();
1011 }
1024 }
@@ -1154,6 +1167,7 @@ void ListViewWithPageHeader::layout()
1154 // Update the top sticky section header
1167 // Update the top sticky section header
1155 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1168 const QString section = m_delegateModel->stringValue(modelIndex, m_sectionProperty);
1156 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1169 QQmlContext *context = QQmlEngine::contextForObject(m_topSectionItem)->parentContext();
1170+ qDebug() << modelIndex << section;
1157 context->setContextProperty(QLatin1String("section"), section);
1171 context->setContextProperty(QLatin1String("section"), section);
1158
1172
1159 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
1173 QQuickItemPrivate::get(m_topSectionItem)->setCulled(false);
plugins/ListViewWithPageHeader/listviewwithpageheader.h+1
@@ -63,6 +63,7 @@ class ListViewWithPageHeader : public QQuickFlickable, public QQuickItemChangeLi
63
63
64 friend class ListViewWithPageHeaderTest;
64 friend class ListViewWithPageHeaderTest;
65 friend class ListViewWithPageHeaderTestSection;
65 friend class ListViewWithPageHeaderTestSection;
66+ friend class ListViewWithPageHeaderTestExternalModel;
66
67
67public:
68public:
68 ListViewWithPageHeader();
69 ListViewWithPageHeader();
tests/plugins/ListViewWithPageHeader/CMakeLists.txt+6
@@ -32,5 +32,11 @@ qt5_use_modules(listviewwithpageheadertestsectionExec Test Core Qml)
32target_link_libraries(listviewwithpageheadertestsectionExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
32target_link_libraries(listviewwithpageheadertestsectionExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
33add_custom_target(testlistviewwithpageheadersection ${CMAKE_CURRENT_BINARY_DIR}/listviewwithpageheadertestsectionExec -o ${CMAKE_BINARY_DIR}/testlistviewwithpageheadersection.xml,xunitxml -o -,txt)
33add_custom_target(testlistviewwithpageheadersection ${CMAKE_CURRENT_BINARY_DIR}/listviewwithpageheadertestsectionExec -o ${CMAKE_BINARY_DIR}/testlistviewwithpageheadersection.xml,xunitxml -o -,txt)
34
34
35+add_executable(listviewwithpageheadertestsectionexternalmodelExec listviewwithpageheadertestsectionexternalmodel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../../plugins/ListViewWithPageHeader/listviewwithpageheader.cpp)
36+qt5_use_modules(listviewwithpageheadertestsectionexternalmodelExec Test Core Qml)
37+target_link_libraries(listviewwithpageheadertestsectionexternalmodelExec ${Qt5Gui_LIBRARIES} ${Qt5Quick_LIBRARIES})
38+add_custom_target(testlistviewwithpageheadersectionexternalmodel ${CMAKE_CURRENT_BINARY_DIR}/listviewwithpageheadertestsectionexternalmodelExec -o ${CMAKE_BINARY_DIR}/testlistviewwithpageheadersectionexternalmodel.xml,xunitxml -o -,txt)
39+
35add_dependencies(qmluitests testlistviewwithpageheader)
40add_dependencies(qmluitests testlistviewwithpageheader)
36add_dependencies(qmluitests testlistviewwithpageheadersection)
41add_dependencies(qmluitests testlistviewwithpageheadersection)
42+add_dependencies(qmluitests testlistviewwithpageheadersectionexternalmodel)
tests/plugins/ListViewWithPageHeader/listviewwithpageheadertestsection.cpp+1
@@ -20,6 +20,7 @@
20#include <QQmlEngine>
20#include <QQmlEngine>
21#include <QQuickView>
21#include <QQuickView>
22#include <QSignalSpy>
22#include <QSignalSpy>
23+#include <QSortFilterProxyModel>
23#include <QtTestGui>
24#include <QtTestGui>
24#pragma GCC diagnostic push
25#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-pedantic"
26#pragma GCC diagnostic ignored "-pedantic"