on xenial help sign in
Fix 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

commit21a217de02f970089f855cf825e43443e60ac091 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 17 Jun 2016, 01:15 (10 years ago) parent8ff91818bfe40d
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
@@ -287,9 +287,11 @@ void ListViewWithPageHeader::setSectionDelegate(QQmlComponent *delegate)
287287 m_sectionDelegate = delegate;
288288
289289 m_topSectionItem = getSectionItem(QString(), false /*watchGeometry*/);
290− m_topSectionItem->setZ(3);
291− QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
292− connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
290+ if (m_topSectionItem) {
291+ m_topSectionItem->setZ(3);
292+ QQuickItemPrivate::get(m_topSectionItem)->setCulled(true);
293+ connect(m_topSectionItem, &QQuickItem::heightChanged, this, &ListViewWithPageHeader::stickyHeaderHeightChanged);
294+ }
293295
294296 // TODO create sections for existing items
295297
@@ -776,7 +778,7 @@ QQuickItem *ListViewWithPageHeader::getSectionItem(const QString &sectionText, b
776778 }
777779 m_sectionDelegate->completeCreate();
778780
779− if (watchGeometry) {
781+ if (watchGeometry && sectionItem) {
780782 QQuickItemPrivate::get(sectionItem)->addItemChangeListener(this, QQuickItemPrivate::Geometry);
781783 }
782784
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 property alias text: theText.text
101106 color: "green"
@@ -104,5 +109,11 @@ Rectangle {
104109 anchors { left: parent.left; right: parent.right }
105110 }
106111 }
112+
113+ Component {
114+ id: objectComponent
115+ QtObject {
116+ }
117+ }
107118 }
108119}