Skip to content

Commit

Permalink
[composer] Fix calculation of height of HTML content (fix #11353)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 9, 2014
1 parent ac71e60 commit 2d49b59
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/core/composer/qgscomposerhtml.cpp
Expand Up @@ -185,7 +185,7 @@ void QgsComposerHtml::loadHtml()
mLoaded = false;

//reset page size. otherwise viewport size increases but never decreases again
mWebPage->setViewportSize( QSize( 0, 0 ) );
mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToMM, 0 ) );

//set html, using the specified url as base if in Url mode
mWebPage->mainFrame()->setHtml( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl( mActualFetchedUrl ) : QUrl() );
Expand Down Expand Up @@ -220,21 +220,28 @@ void QgsComposerHtml::frameLoaded( bool ok )
mLoaded = true;
}

double QgsComposerHtml::maxFrameWidth() const
{
double maxWidth = 0;
QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems.constBegin();
for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
{
maxWidth = qMax( maxWidth, ( *frameIt )->boundingRect().width() );
}

return maxWidth;
}

void QgsComposerHtml::recalculateFrameSizes()
{
if ( frameCount() < 1 ) return;
if ( frameCount() < 1 ) return;

QSize contentsSize = mWebPage->mainFrame()->contentsSize();

//find maximum frame width
double maxFrameWidth = 0;
QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems.constBegin();
for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
{
maxFrameWidth = qMax( maxFrameWidth, ( *frameIt )->boundingRect().width() );
}
double maxWidth = maxFrameWidth();
//set content width to match maximum frame width
contentsSize.setWidth( maxFrameWidth * mHtmlUnitsToMM );
contentsSize.setWidth( maxWidth * mHtmlUnitsToMM );

mWebPage->setViewportSize( contentsSize );
mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposerhtml.h
Expand Up @@ -257,6 +257,9 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame

/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions */
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );

/**calculates the max width of frames in the html multiframe*/
double maxFrameWidth() const;
};

#endif // QGSCOMPOSERHTML_H

0 comments on commit 2d49b59

Please sign in to comment.