on xenial help sign in
Do not crash if a component that is not an Item is given to sectionDelegate

It doesn't matter much since this is not a public component, but it is always nice to be correct

commit8bfe40da37f252de66314d80f6860898b8e89025 authorAlbert Astals Cid <albert.astals@canonical.com> dateThu 26 May 2016, 14:37 (10 years ago) parent64d3f31
3 files changed+24−5
plugins/Dash/listviewwithpageheader.cpp+6−4 tests/plugins/Dash/listviewwithpageheadersectiontest.cpp+6 tests/plugins/Dash/listviewwithpageheadertestsection.qml+12−1
plugins/Dash/listviewwithpageheader.cpp+6−4
@@ -286,9 +286,11 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
286286 m_sectionDelegate = delegate;
287287
288288 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
289− m_topSectionItem->setZ(3);
290− QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
291− connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
289+ if (m_topSectionItem) {
290+ m_topSectionItem->setZ(3);
291+ QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
292+ connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
293+ }
292294
293295 // TODO create sections for existing items
294296
@@ -775,7 +777,7 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
775777 }
776778 m_sectionDelegate->completeCreate();
777779
778− if (watchGeometry) {
780+ if (watchGeometry && sectionItem) {
779781 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
780782 }
781783
tests/plugins/Dash/listviewwithpageheadersectiontest.cpp+6
@@ -2195,6 +2195,12 @@ private Q_SLOTS:
21952195 verifyItem(1, 240., 220., false, "halfheight", false);
21962196 }
21972197
2198+ void testInvalidSectionDelegate()
2199+ {
2200+ lvwph->setProperty("useBrokenSectionDelegateComponent", true);
2201+ scrollToBottom();
2202+ }
2203+
21982204private:
21992205 QQuickView *view;
22002206 ListViewWithPageHeader *lvwph;
tests/plugins/Dash/listviewwithpageheadertestsection.qml+12−1
@@ -94,8 +94,13 @@ Rectangle {
9494 }
9595 }
9696
97+ property bool useBrokenSectionDelegateComponent: false
9798 sectionProperty: "type"
98− sectionDelegate: Component {
99+ sectionDelegate: useBrokenSectionDelegateComponent ? objectComponent
100+ : regularSectionDelegateComponent
101+
102+ Component {
103+ id: regularSectionDelegateComponent
99104 Rectangle {
100105 color: "green"
101106 height: section === "" ? 0 : section != "halfheight" ? 40 : 20;
@@ -103,5 +108,11 @@ Rectangle {
103108 anchors { left: parent.left; right: parent.right }
104109 }
105110 }
111+
112+ Component {
113+ id: objectComponent
114+ QtObject {
115+ }
116+ }
106117 }
107118}