Skip to content

Commit 2d49b59

Browse files
committedOct 9, 2014
[composer] Fix calculation of height of HTML content (fix #11353)
1 parent ac71e60 commit 2d49b59

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed
 

‎src/core/composer/qgscomposerhtml.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void QgsComposerHtml::loadHtml()
185185
mLoaded = false;
186186

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

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

223+
double QgsComposerHtml::maxFrameWidth() const
224+
{
225+
double maxWidth = 0;
226+
QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems.constBegin();
227+
for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
228+
{
229+
maxWidth = qMax( maxWidth, ( *frameIt )->boundingRect().width() );
230+
}
231+
232+
return maxWidth;
233+
}
234+
223235
void QgsComposerHtml::recalculateFrameSizes()
224236
{
225-
if ( frameCount() < 1 ) return;
237+
if ( frameCount() < 1 ) return;
226238

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

229241
//find maximum frame width
230-
double maxFrameWidth = 0;
231-
QList<QgsComposerFrame*>::const_iterator frameIt = mFrameItems.constBegin();
232-
for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
233-
{
234-
maxFrameWidth = qMax( maxFrameWidth, ( *frameIt )->boundingRect().width() );
235-
}
242+
double maxWidth = maxFrameWidth();
236243
//set content width to match maximum frame width
237-
contentsSize.setWidth( maxFrameWidth * mHtmlUnitsToMM );
244+
contentsSize.setWidth( maxWidth * mHtmlUnitsToMM );
238245

239246
mWebPage->setViewportSize( contentsSize );
240247
mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );

‎src/core/composer/qgscomposerhtml.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
257257

258258
/** Sets the current feature, the current layer and a list of local variable substitutions for evaluating expressions */
259259
void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
260+
261+
/**calculates the max width of frames in the html multiframe*/
262+
double maxFrameWidth() const;
260263
};
261264

262265
#endif // QGSCOMPOSERHTML_H

0 commit comments

Comments
 (0)
Please sign in to comment.