Skip to content
Permalink
Browse files

[layouts] Avoid a crash when no pages exist in layout

  • Loading branch information
nyalldawson committed Jun 20, 2018
1 parent 2778266 commit afde31b94f3b599eae8e4ce693c14279cf0a72f4
Showing with 6 additions and 0 deletions.
  1. +3 −0 src/core/layout/qgslayoutpagecollection.cpp
  2. +3 −0 tests/src/python/test_qgslayoutpagecollection.py
@@ -164,6 +164,9 @@ int QgsLayoutPageCollection::pageNumberForPoint( QPointF point ) const

int QgsLayoutPageCollection::predictPageNumberForPoint( QPointF point ) const
{
if ( mPages.empty() )
return 0;

int pageNumber = 0;
double startNextPageY = 0;
Q_FOREACH ( QgsLayoutItemPage *page, mPages )
@@ -573,6 +573,9 @@ def testPredictionPageNumberForPoint(self):
l = QgsLayout(p)
collection = l.pageCollection()

# no crash if no pages
self.assertEqual(collection.predictPageNumberForPoint(QPointF(1, 1)), 0)

# add a page
page = QgsLayoutItemPage(l)
page.setPageSize(QgsLayoutSize(100, 100))

0 comments on commit afde31b

Please sign in to comment.
You can’t perform that action at this time.