Skip to content

Commit afde31b

Browse files
committed
[layouts] Avoid a crash when no pages exist in layout
1 parent 2778266 commit afde31b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/core/layout/qgslayoutpagecollection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ int QgsLayoutPageCollection::pageNumberForPoint( QPointF point ) const
164164

165165
int QgsLayoutPageCollection::predictPageNumberForPoint( QPointF point ) const
166166
{
167+
if ( mPages.empty() )
168+
return 0;
169+
167170
int pageNumber = 0;
168171
double startNextPageY = 0;
169172
Q_FOREACH ( QgsLayoutItemPage *page, mPages )

tests/src/python/test_qgslayoutpagecollection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ def testPredictionPageNumberForPoint(self):
573573
l = QgsLayout(p)
574574
collection = l.pageCollection()
575575

576+
# no crash if no pages
577+
self.assertEqual(collection.predictPageNumberForPoint(QPointF(1, 1)), 0)
578+
576579
# add a page
577580
page = QgsLayoutItemPage(l)
578581
page.setPageSize(QgsLayoutSize(100, 100))

0 commit comments

Comments
 (0)