[layouts] Fix a crash when using multiframe items when no pages exist

This commit is contained in:
Nyall Dawson 2018-06-20 16:39:47 +10:00
parent afde31b94f
commit fb3ff6d226
2 changed files with 32 additions and 1 deletions

View File

@ -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 )
{

View File

@ -50,6 +50,7 @@ class TestQgsLayoutMultiFrame : public QObject
void registry();
void deleteFrame();
void writeReadXml();
void noPageNoCrash();
private:
QgsLayout *mLayout = nullptr;
@ -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"