on xenial help sign in
Do not crash if a component that is not an Item is given to sectionDelegate
8bfe40dAlbert Astals Cid
plugins/Dash/listviewwithpageheader.cpp+6−4
@@ -286,9 +286,11 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
286 m_sectionDelegate = delegate;
286 m_sectionDelegate = delegate;
287
287
288 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
288 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
289+ if (m_topSectionItem) {
289− m_topSectionItem->setZ(3);
290+ m_topSectionItem->setZ(3);
290− QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
291+ QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
291− connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
292+ connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
293+ }
292
294
293 // TODO create sections for existing items
295 // TODO create sections for existing items
294
296
@@ -775,7 +777,7 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
775 }
777 }
776 m_sectionDelegate->completeCreate();
778 m_sectionDelegate->completeCreate();
777
779
778− if (watchGeometry) {
780+ if (watchGeometry && sectionItem) {
779 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
781 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
780 }
782 }
781
783
tests/plugins/Dash/listviewwithpageheadersectiontest.cpp+6
@@ -2195,6 +2195,12 @@ private Q_SLOTS:
2195 verifyItem(1, 240., 220., false, "halfheight", false);
2195 verifyItem(1, 240., 220., false, "halfheight", false);
2196 }
2196 }
2197
2197
2198+ void testInvalidSectionDelegate()
2199+ {
2200+ lvwph->setProperty("useBrokenSectionDelegateComponent", true);
2201+ scrollToBottom();
2202+ }
2203+
2198private:
2204private:
2199 QQuickView *view;
2205 QQuickView *view;
2200 ListViewWithPageHeader *lvwph;
2206 ListViewWithPageHeader *lvwph;
tests/plugins/Dash/listviewwithpageheadertestsection.qml+12−1
@@ -94,8 +94,13 @@ Rectangle {
94 }
94 }
95 }
95 }
96
96
97+ property bool useBrokenSectionDelegateComponent: false
97 sectionProperty: "type"
98 sectionProperty: "type"
99+ sectionDelegate: useBrokenSectionDelegateComponent ? objectComponent
100+ : regularSectionDelegateComponent
101+
98− sectionDelegate: Component {
102+ Component {
103+ id: regularSectionDelegateComponent
99 Rectangle {
104 Rectangle {
100 color: "green"
105 color: "green"
101 height: section === "" ? 0 : section != "halfheight" ? 40 : 20;
106 height: section === "" ? 0 : section != "halfheight" ? 40 : 20;
@@ -103,5 +108,11 @@ Rectangle {
103 anchors { left: parent.left; right: parent.right }
108 anchors { left: parent.left; right: parent.right }
104 }
109 }
105 }
110 }
111+
112+ Component {
113+ id: objectComponent
114+ QtObject {
115+ }
116+ }
106 }
117 }
107}
118}