Skip to content

Commit

Permalink
[layouts] Fix crash when opening layout with dynamic image in html label
Browse files Browse the repository at this point in the history
Fixes #28996
  • Loading branch information
nyalldawson committed Sep 19, 2019
1 parent f9737a9 commit 5db6165
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/core/layout/qgslayoutitemlabel.cpp
Expand Up @@ -157,7 +157,10 @@ void QgsLayoutItemLabel::contentChanged()
//For very basic html labels with no external assets, the html load will already be
//complete before we even get a chance to start the QEventLoop. Make sure we check
//this before starting the loop
if ( !mHtmlLoaded )

// important -- we CAN'T do this when it's a render inside the designer, otherwise the
// event loop will mess with the paint event and cause it to be deleted, and BOOM!
if ( !mHtmlLoaded && ( !mLayout || !mLayout->renderContext().isPreviewRender() ) )
{
//Setup event loop and timeout for rendering html
QEventLoop loop;
Expand Down Expand Up @@ -185,6 +188,8 @@ void QgsLayoutItemLabel::loadingHtmlFinished( bool result )
{
Q_UNUSED( result )
mHtmlLoaded = true;
invalidateCache();
update();
}

double QgsLayoutItemLabel::htmlUnitsToLayoutUnits()
Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutrendercontext.h
Expand Up @@ -345,6 +345,7 @@ class CORE_EXPORT QgsLayoutRenderContext : public QObject
friend class TestQgsLayout;
friend class LayoutContextPreviewSettingRestorer;
friend class TestQgsLayoutMap;
friend class TestQgsLayoutLabel;

};

Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgslayoutlabel.cpp
Expand Up @@ -299,6 +299,7 @@ void TestQgsLayoutLabel::renderAsHtmlRelative()
{
QgsLayout l( QgsProject::instance() );
l.initializeDefaults();
l.renderContext().mIsPreviewRender = false;
QgsLayoutItemLabel *label = new QgsLayoutItemLabel( &l );
label->setMargin( 1 );
l.addLayoutItem( label );
Expand Down

0 comments on commit 5db6165

Please sign in to comment.