Skip to content
Permalink
Browse files

[composer] Fix calculation of height of HTML content (fix #11353)

  • Loading branch information
nyalldawson committed Oct 9, 2014
1 parent ac71e60 commit 2d49b59cc1b8f1c1dda215ec27358ca7d5093b1b
Showing with 19 additions and 9 deletions.
  1. +16 −9 src/core/composer/qgscomposerhtml.cpp
  2. +3 −0 src/core/composer/qgscomposerhtml.h
@@ -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() );
@@ -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 );
@@ -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.
You can’t perform that action at this time.