Skip to content

Commit

Permalink
[layouts] Fix a crash when using multiframe items when no pages exist
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jun 20, 2018
1 parent afde31b commit fb3ff6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutmultiframe.cpp
Expand Up @@ -148,7 +148,7 @@ void QgsLayoutMultiFrame::recalculateFrameSizes()
}

//at end of frames but there is still content left. Add other pages if ResizeMode ==
if ( currentItem && mResizeMode != UseExistingFrames )
if ( mLayout->pageCollection()->pageCount() > 0 && currentItem && mResizeMode != UseExistingFrames )
{
while ( ( mResizeMode == RepeatOnEveryPage ) || currentY < totalHeight )
{
Expand Down
31 changes: 31 additions & 0 deletions tests/src/core/testqgslayoutmultiframe.cpp
Expand Up @@ -50,6 +50,7 @@ class TestQgsLayoutMultiFrame : public QObject
void registry();
void deleteFrame();
void writeReadXml();
void noPageNoCrash();

private:
QgsLayout *mLayout = nullptr;
Expand Down Expand Up @@ -620,5 +621,35 @@ void TestQgsLayoutMultiFrame::writeReadXml()
QCOMPARE( html2->frames(), QList< QgsLayoutFrame * >() << frame2 );
}

void TestQgsLayoutMultiFrame::noPageNoCrash()
{
QgsProject p;

// create layout, no pages
QgsLayout c( &p );
// add an multiframe
QgsLayoutItemHtml *html = new QgsLayoutItemHtml( &c );
c.addMultiFrame( html );
html->setContentMode( QgsLayoutItemHtml::ManualHtml );
html->setHtml( QStringLiteral( "<div style=\"height: 2000px\">hi</div>" ) );
QgsLayoutFrame *frame = new QgsLayoutFrame( &c, html );
frame->attemptSetSceneRect( QRectF( 1, 1, 10, 1 ) );
c.addLayoutItem( frame );
html->addFrame( frame );

html->setResizeMode( QgsLayoutMultiFrame::UseExistingFrames );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::ExtendToNextPage );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::RepeatOnEveryPage );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
html->setResizeMode( QgsLayoutMultiFrame::RepeatUntilFinished );
html->recalculateFrameSizes();
QCOMPARE( html->frameCount(), 1 );
}

QGSTEST_MAIN( TestQgsLayoutMultiFrame )
#include "testqgslayoutmultiframe.moc"

0 comments on commit fb3ff6d

Please sign in to comment.