Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[layouts] Avoid a crash when no pages exist in layout
  • Loading branch information
nyalldawson committed Jun 20, 2018
1 parent 2778266 commit afde31b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/layout/qgslayoutpagecollection.cpp
Expand Up @@ -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 )
Expand Down
3 changes: 3 additions & 0 deletions tests/src/python/test_qgslayoutpagecollection.py
Expand Up @@ -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))
Expand Down

0 comments on commit afde31b

Please sign in to comment.