QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposerhtml.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerhtml.cpp
3  ------------------------------------------------------------
4  begin : July 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgscomposerhtml.h"
17 #include "qgscomposerframe.h"
18 #include "qgscomposition.h"
21 #include "qgsmessagelog.h"
22 #include "qgsexpression.h"
23 #include "qgslogger.h"
25 #include "qgsvectorlayer.h"
26 #include "qgsproject.h"
27 #include "qgsdistancearea.h"
28 
29 #include "qgswebpage.h"
30 #include "qgswebframe.h"
31 
32 #include <QCoreApplication>
33 #include <QPainter>
34 #include <QImage>
35 #include <QNetworkReply>
36 
37 QgsComposerHtml::QgsComposerHtml( QgsComposition* c, bool createUndoCommands )
38  : QgsComposerMultiFrame( c, createUndoCommands )
39  , mContentMode( QgsComposerHtml::Url )
40  , mWebPage( 0 )
41  , mLoaded( false )
42  , mHtmlUnitsToMM( 1.0 )
43  , mRenderedPage( 0 )
44  , mEvaluateExpressions( true )
45  , mUseSmartBreaks( true )
46  , mMaxBreakDistance( 10 )
47  , mExpressionFeature( 0 )
48  , mExpressionLayer( 0 )
49  , mDistanceArea( 0 )
50  , mEnableUserStylesheet( false )
51  , mFetcher( 0 )
52 {
53  mDistanceArea = new QgsDistanceArea();
54  mHtmlUnitsToMM = htmlUnitsToMM();
55  mWebPage = new QWebPage();
56  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
57  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
58 
59  //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
60  QPalette palette = mWebPage->palette();
61  palette.setBrush( QPalette::Base, Qt::transparent );
62  mWebPage->setPalette( palette );
63 
65  QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
66  if ( mComposition )
67  {
68  QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
69  }
70 
71  // data defined strings
72  mDataDefinedNames.insert( QgsComposerObject::SourceUrl, QString( "dataDefinedSourceUrl" ) );
73 
75  {
76  //a html item added while atlas preview is enabled needs to have the expression context set,
77  //otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457)
79  }
80 
81  //connect to atlas feature changes
82  //to update the expression context
83  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
84 
85  mFetcher = new QgsNetworkContentFetcher();
86  connect( mFetcher, SIGNAL( finished() ), this, SLOT( frameLoaded() ) );
87 
88 }
89 
91 {
92  delete mDistanceArea;
93  delete mWebPage;
94  delete mRenderedPage;
95  mFetcher->deleteLater();
96 }
97 
98 void QgsComposerHtml::setUrl( const QUrl& url )
99 {
100  if ( !mWebPage )
101  {
102  return;
103  }
104 
105  mUrl = url;
106  loadHtml( true );
107  emit changed();
108 }
109 
111 {
112  mHtml = html;
113  //TODO - this signal should be emitted, but without changing the signal which sets the html
114  //to an equivalent of editingFinished it causes a lot of problems. Need to investigate
115  //ways of doing this using QScintilla widgets.
116  //emit changed();
117 }
118 
119 void QgsComposerHtml::setEvaluateExpressions( bool evaluateExpressions )
120 {
121  mEvaluateExpressions = evaluateExpressions;
122  loadHtml( true );
123  emit changed();
124 }
125 
126 void QgsComposerHtml::loadHtml( const bool useCache )
127 {
128  if ( !mWebPage )
129  {
130  return;
131  }
132 
133  QString loadedHtml;
134  switch ( mContentMode )
135  {
137  {
138 
139  QString currentUrl = mUrl.toString();
140 
141  //data defined url set?
142  QVariant exprVal;
144  {
145  currentUrl = exprVal.toString().trimmed();;
146  QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
147  }
148  if ( currentUrl.isEmpty() )
149  {
150  return;
151  }
152  if ( !( useCache && currentUrl == mLastFetchedUrl ) )
153  {
154  loadedHtml = fetchHtml( QUrl( currentUrl ) );
155  mLastFetchedUrl = currentUrl;
156  }
157  else
158  {
159  loadedHtml = mFetchedHtml;
160  }
161 
162  break;
163  }
165  loadedHtml = mHtml;
166  break;
167  }
168 
169  //evaluate expressions
170  if ( mEvaluateExpressions )
171  {
172  loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, mExpressionFeature, mExpressionLayer, 0, mDistanceArea );
173  }
174 
175  mLoaded = false;
176 
177  //reset page size. otherwise viewport size increases but never decreases again
178  mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToMM, 0 ) );
179 
180  //set html, using the specified url as base if in Url mode
181  mWebPage->mainFrame()->setHtml( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl( mActualFetchedUrl ) : QUrl() );
182 
183  //set user stylesheet
184  QWebSettings* settings = mWebPage->settings();
185  if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
186  {
187  QByteArray ba;
188  ba.append( mUserStylesheet.toUtf8() );
189  QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
190  settings->setUserStyleSheetUrl( cssFileURL );
191  }
192  else
193  {
194  settings->setUserStyleSheetUrl( QUrl() );
195  }
196 
197  while ( !mLoaded )
198  {
199  qApp->processEvents();
200  }
201 
203  //trigger a repaint
204  emit contentsChanged();
205 }
206 
207 void QgsComposerHtml::frameLoaded( bool ok )
208 {
209  Q_UNUSED( ok );
210  mLoaded = true;
211 }
212 
213 double QgsComposerHtml::maxFrameWidth() const
214 {
215  double maxWidth = 0;
217  for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
218  {
219  maxWidth = qMax( maxWidth, ( double )(( *frameIt )->boundingRect().width() ) );
220  }
221 
222  return maxWidth;
223 }
224 
226 {
227  if ( frameCount() < 1 ) return;
228 
229  QSize contentsSize = mWebPage->mainFrame()->contentsSize();
230 
231  //find maximum frame width
232  double maxWidth = maxFrameWidth();
233  //set content width to match maximum frame width
234  contentsSize.setWidth( maxWidth * mHtmlUnitsToMM );
235 
236  mWebPage->setViewportSize( contentsSize );
237  mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
238  mSize.setHeight( contentsSize.height() / mHtmlUnitsToMM );
239  if ( contentsSize.isValid() )
240  {
241  renderCachedImage();
242  }
244  emit changed();
245 }
246 
247 void QgsComposerHtml::renderCachedImage()
248 {
249  //render page to cache image
250  if ( mRenderedPage )
251  {
252  delete mRenderedPage;
253  }
254  mRenderedPage = new QImage( mWebPage->viewportSize(), QImage::Format_ARGB32 );
255  if ( mRenderedPage->isNull() )
256  {
257  return;
258  }
259  mRenderedPage->fill( Qt::transparent );
260  QPainter painter;
261  painter.begin( mRenderedPage );
262  mWebPage->mainFrame()->render( &painter );
263  painter.end();
264 }
265 
266 QString QgsComposerHtml::fetchHtml( QUrl url )
267 {
268  //pause until HTML fetch
269  mLoaded = false;
270  mFetcher->fetchContent( url );
271 
272  while ( !mLoaded )
273  {
274  qApp->processEvents();
275  }
276 
277  mFetchedHtml = mFetcher->contentAsString();
278  mActualFetchedUrl = mFetcher->reply()->url().toString();
279  return mFetchedHtml;
280 }
281 
283 {
284  return mSize;
285 }
286 
287 void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent, const int frameIndex )
288 {
289  Q_UNUSED( frameIndex );
290 
291  if ( !mWebPage )
292  {
293  return;
294  }
295 
296  p->save();
297  p->setRenderHint( QPainter::Antialiasing );
298  p->scale( 1.0 / mHtmlUnitsToMM, 1.0 / mHtmlUnitsToMM );
299  p->translate( 0.0, -renderExtent.top() * mHtmlUnitsToMM );
300  mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top() * mHtmlUnitsToMM, renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );
301  p->restore();
302 }
303 
304 double QgsComposerHtml::htmlUnitsToMM()
305 {
306  if ( !mComposition )
307  {
308  return 1.0;
309  }
310 
311  return ( mComposition->printResolution() / 72.0 ); //webkit seems to assume a standard dpi of 96
312 }
313 
314 void QgsComposerHtml::addFrame( QgsComposerFrame* frame, bool recalcFrameSizes )
315 {
316  mFrameItems.push_back( frame );
317  QObject::connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
318  if ( mComposition )
319  {
320  mComposition->addComposerHtmlFrame( this, frame );
321  }
322 
323  if ( recalcFrameSizes )
324  {
326  }
327 }
328 
329 bool candidateSort( const QPair<int, int> &c1, const QPair<int, int> &c2 )
330 {
331  if ( c1.second < c2.second )
332  return true;
333  else if ( c1.second > c2.second )
334  return false;
335  else if ( c1.first > c2.first )
336  return true;
337  else
338  return false;
339 }
340 
342 {
343  if ( !mWebPage || !mRenderedPage || !mUseSmartBreaks )
344  {
345  return yPos;
346  }
347 
348  //convert yPos to pixels
349  int idealPos = yPos * htmlUnitsToMM();
350 
351  //if ideal break pos is past end of page, there's nothing we need to do
352  if ( idealPos >= mRenderedPage->height() )
353  {
354  return yPos;
355  }
356 
357  int maxSearchDistance = mMaxBreakDistance * htmlUnitsToMM();
358 
359  //loop through all lines just before ideal break location, up to max distance
360  //of maxSearchDistance
361  int changes = 0;
362  QRgb currentColor;
363  bool currentPixelTransparent = false;
364  bool previousPixelTransparent = false;
365  QRgb pixelColor;
366  QList< QPair<int, int> > candidates;
367  int minRow = qMax( idealPos - maxSearchDistance, 0 );
368  for ( int candidateRow = idealPos; candidateRow >= minRow; --candidateRow )
369  {
370  changes = 0;
371  currentColor = qRgba( 0, 0, 0, 0 );
372  //check all pixels in this line
373  for ( int col = 0; col < mRenderedPage->width(); ++col )
374  {
375  //count how many times the pixels change color in this row
376  //eventually, we select a row to break at with the minimum number of color changes
377  //since this is likely a line break, or gap between table cells, etc
378  //but very unlikely to be midway through a text line or picture
379  pixelColor = mRenderedPage->pixel( col, candidateRow );
380  currentPixelTransparent = qAlpha( pixelColor ) == 0;
381  if ( pixelColor != currentColor && !( currentPixelTransparent && previousPixelTransparent ) )
382  {
383  //color has changed
384  currentColor = pixelColor;
385  changes++;
386  }
387  previousPixelTransparent = currentPixelTransparent;
388  }
389  candidates.append( qMakePair( candidateRow, changes ) );
390  }
391 
392  //sort candidate rows by number of changes ascending, row number descending
393  qSort( candidates.begin(), candidates.end(), candidateSort );
394  //first candidate is now the largest row with smallest number of changes
395 
396  //ok, now take the mid point of the best candidate position
397  //we do this so that the spacing between text lines is likely to be split in half
398  //otherwise the html will be broken immediately above a line of text, which
399  //looks a little messy
400  int maxCandidateRow = candidates[0].first;
401  int minCandidateRow = maxCandidateRow + 1;
402  int minCandidateChanges = candidates[0].second;
403 
404  QList< QPair<int, int> >::iterator it;
405  for ( it = candidates.begin(); it != candidates.end(); ++it )
406  {
407  if (( *it ).second != minCandidateChanges || ( *it ).first != minCandidateRow - 1 )
408  {
409  //no longer in a consecutive block of rows of minimum pixel color changes
410  //so return the row mid-way through the block
411  //first converting back to mm
412  return ( minCandidateRow + ( maxCandidateRow - minCandidateRow ) / 2 ) / htmlUnitsToMM();
413  }
414  minCandidateRow = ( *it ).first;
415  }
416 
417  //above loop didn't work for some reason
418  //return first candidate converted to mm
419  return candidates[0].first / htmlUnitsToMM();
420 }
421 
422 void QgsComposerHtml::setUseSmartBreaks( bool useSmartBreaks )
423 {
424  mUseSmartBreaks = useSmartBreaks;
426  emit changed();
427 }
428 
429 void QgsComposerHtml::setMaxBreakDistance( double maxBreakDistance )
430 {
431  mMaxBreakDistance = maxBreakDistance;
433  emit changed();
434 }
435 
437 {
438  mUserStylesheet = stylesheet;
439  //TODO - this signal should be emitted, but without changing the signal which sets the css
440  //to an equivalent of editingFinished it causes a lot of problems. Need to investigate
441  //ways of doing this using QScintilla widgets.
442  //emit changed();
443 }
444 
445 void QgsComposerHtml::setUserStylesheetEnabled( const bool stylesheetEnabled )
446 {
447  if ( mEnableUserStylesheet != stylesheetEnabled )
448  {
449  mEnableUserStylesheet = stylesheetEnabled;
450  loadHtml( true );
451  emit changed();
452  }
453 }
454 
456 {
457  return tr( "<HTML frame>" );
458 }
459 
460 bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
461 {
462  QDomElement htmlElem = doc.createElement( "ComposerHtml" );
463  htmlElem.setAttribute( "contentMode", QString::number(( int ) mContentMode ) );
464  htmlElem.setAttribute( "url", mUrl.toString() );
465  htmlElem.setAttribute( "html", mHtml );
466  htmlElem.setAttribute( "evaluateExpressions", mEvaluateExpressions ? "true" : "false" );
467  htmlElem.setAttribute( "useSmartBreaks", mUseSmartBreaks ? "true" : "false" );
468  htmlElem.setAttribute( "maxBreakDistance", QString::number( mMaxBreakDistance ) );
469  htmlElem.setAttribute( "stylesheet", mUserStylesheet );
470  htmlElem.setAttribute( "stylesheetEnabled", mEnableUserStylesheet ? "true" : "false" );
471 
472  bool state = _writeXML( htmlElem, doc, ignoreFrames );
473  elem.appendChild( htmlElem );
474  return state;
475 }
476 
477 bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
478 {
479  if ( !ignoreFrames )
480  {
481  deleteFrames();
482  }
483 
484  //first create the frames
485  if ( !_readXML( itemElem, doc, ignoreFrames ) )
486  {
487  return false;
488  }
489 
490  bool contentModeOK;
491  mContentMode = ( QgsComposerHtml::ContentMode )itemElem.attribute( "contentMode" ).toInt( &contentModeOK );
492  if ( !contentModeOK )
493  {
494  mContentMode = QgsComposerHtml::Url;
495  }
496  mEvaluateExpressions = itemElem.attribute( "evaluateExpressions", "true" ) == "true" ? true : false;
497  mUseSmartBreaks = itemElem.attribute( "useSmartBreaks", "true" ) == "true" ? true : false;
498  mMaxBreakDistance = itemElem.attribute( "maxBreakDistance", "10" ).toDouble();
499  mHtml = itemElem.attribute( "html" );
500  mUserStylesheet = itemElem.attribute( "stylesheet" );
501  mEnableUserStylesheet = itemElem.attribute( "stylesheetEnabled", "false" ) == "true" ? true : false;
502 
503  //finally load the set url
504  QString urlString = itemElem.attribute( "url" );
505  if ( !urlString.isEmpty() )
506  {
507  mUrl = urlString;
508  }
509  loadHtml( true );
510 
511  //since frames had to be created before, we need to emit a changed signal to refresh the widget
512  emit changed();
513  return true;
514 }
515 
516 void QgsComposerHtml::setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer )
517 {
518  mExpressionFeature = feature;
519  mExpressionLayer = layer;
520 
521  //setup distance area conversion
522  if ( layer )
523  {
524  mDistanceArea->setSourceCrs( layer->crs().srsid() );
525  }
526  else if ( mComposition )
527  {
528  //set to composition's mapsettings' crs
529  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
530  }
531  if ( mComposition )
532  {
534  }
535  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
536 }
537 
539 {
540  QgsVectorLayer * vl = 0;
541  QgsFeature* feature = 0;
542 
544  {
546  }
548  {
550  }
551 
552  setExpressionContext( feature, vl );
553  loadHtml( true );
554 }
555 
557 {
558  //updates data defined properties and redraws item to match
559  if ( property == QgsComposerObject::SourceUrl || property == QgsComposerObject::AllProperties )
560  {
561  loadHtml( true );
562  }
564 }
void setBrush(ColorRole role, const QBrush &brush)
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of it's component frames...
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
QString contentAsString() const
Returns the fetched content as a string.
bool isValid() const
int width() const
bool end()
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void push_back(const T &value)
QString attribute(const QString &name, const QString &defValue) const
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const override
Stores state information about multiframe in DOM element.
virtual QString displayName() const override
Get multiframe display name.
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
void setHtml(const QString html)
Sets the HTML to display in the item when the item is using the QgsComposerHtml::ManualHtml mode...
void scale(qreal sx, qreal sy)
void setUserStylesheet(const QString stylesheet)
Sets the user stylesheet CSS rules to use while rendering the HTML content.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
A item that forms part of a map composition.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties) override
void save()
bool enabled() const
Returns whether the atlas generation is enabled.
void fetchContent(const QUrl url)
Fetches content from a remote URL and handles redirects.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
QgsComposerHtml(QgsComposition *c, bool createUndoCommands)
qreal top() const
QNetworkReply * reply()
Returns a reference to the network reply.
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
bool isNull() const
void setEvaluateExpressions(bool evaluateExpressions)
Sets whether the html item will evaluate QGIS expressions prior to rendering the HTML content...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:162
double toDouble(bool *ok) const
QString toString(QFlags< QUrl::FormattingOption > options) const
QString tr(const char *sourceText, const char *disambiguation, int n)
qreal left() const
DataDefinedProperty
Data defined properties for different item types.
QSizeF totalSize() const override
Returns the total size of the multiframe's content.
const QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
Definition: qgis.cpp:74
bool dataDefinedEvaluate(const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue)
Evaluate a data defined property and return the calculated value.
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
QString html() const
Returns the HTML source displayed in the item if the item is using the QgsComposerHtml::ManualHtml mo...
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)
Restores state information about base multiframe object from a DOM element.
QRgb pixel(int x, int y) const
QString number(int n, int base)
void append(const T &value)
void setHtml(const QString &html, const QUrl &baseUrl)
void setUserStyleSheetUrl(const QUrl &location)
void fill(uint pixelValue)
HTTP network content fetcher.
int printResolution() const
int width() const
void setAttribute(const QString &name, const QString &value)
void setWidth(qreal width)
void recalculateFrameSizes() override
Recalculates the frame sizes for the current viewport dimensions.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
void setWidth(int width)
Abstract base class for composer items with the ability to distribute the content to several frames (...
void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true) override
Adds a frame to the multiframe.
bool isEmpty() const
QString trimmed() const
QList< QgsComposerFrame * > mFrameItems
QWebFrame * mainFrame() const
bool _writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const
Stores state information about base multiframe object in DOM element.
void setMaxBreakDistance(double maxBreakDistance)
Sets the maximum distance allowed when calculating where to place page breaks in the html...
bool evaluateExpressions() const
Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content...
The QWebPage class is a collection of stubs to mimic the API of a QWebPage on systems where QtWebkit ...
Definition: qgswebpage.h:99
void setUseSmartBreaks(bool useSmartBreaks)
Sets whether the html item should use smart breaks.
void deleteLater()
T & first()
int frameCount() const
Returns the number of frames associated with this multiframe.
void loadHtml(const bool useCache=false)
Reloads the html source from the url and redraws the item.
Graphics scene for map printing.
QgsFeature * currentFeature()
Returns the current atlas feature.
Frame item for a composer multiframe item.
QByteArray & append(char ch)
iterator end()
const QUrl & url() const
Returns the URL of the content displayed in the item if the item is using the QgsComposerHtml::Url mo...
QWebSettings * settings() const
void restore()
General purpose distance and area calculator.
QgsComposition * mComposition
void deleteFrames()
Removes and deletes all child frames.
void refreshExpressionContext()
void render(QPainter *painter)
void contentsChanged()
Emitted when the contents of the multi frame have changed and the frames must be redrawn.
qreal width() const
static QgsNetworkAccessManager * instance()
returns a pointer to the single instance
double maxBreakDistance() const
Returns the maximum distance allowed when calculating where to place page breaks in the html...
void addComposerHtmlFrame(QgsComposerHtml *html, QgsComposerFrame *frame)
Adds composer html frame and advises composer to create a widget for it (through signal) ...
void setUrl(const QUrl &url)
Sets the URL for content to display in the item when the item is using the QgsComposerHtml::Url mode...
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:351
void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
int height() const
QUrl url() const
void translate(const QPointF &offset)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
qreal height() const
int height() const
QgsAtlasComposition & atlasComposition()
iterator insert(const Key &key, const T &value)
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
QByteArray toBase64() const
void setUserStylesheetEnabled(const bool stylesheetEnabled)
Sets whether user stylesheets are enabled for the HTML content.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false) override
Reads multiframe state information from a DOM element.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
const_iterator constBegin() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Represents a vector layer which manages a vector based data sets.
bool begin(QPaintDevice *device)
ContentMode
Source modes for the HTML content to render in the item.
void setHeight(qreal height)
void setViewportSize(const QSize &size) const
double findNearbyPageBreak(double yPos) override
Finds the optimal position to break a frame at.
QString toString() const
void setNetworkAccessManager(QNetworkAccessManager *manager)
void handleFrameRemoval(QgsComposerItem *item)
Called before a frame is going to be removed.
bool candidateSort(const QPair< int, int > &c1, const QPair< int, int > &c2)
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
iterator begin()
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
The QWebSettings class is a collection of stubs to mimic the API of a QWebSettings on systems where Q...
Definition: qgswebpage.h:36
void render(QPainter *p, const QRectF &renderExtent, const int frameIndex) override
Renders a portion of the multiframe's content into a painter.
void changed()
Emitted when the properties of a multi frame have changed, and the GUI item widget must be updated...
QByteArray toUtf8() const
static QString replaceExpressionText(const QString &action, const QgsFeature *feat, QgsVectorLayer *layer, const QMap< QString, QVariant > *substitutionMap=0, const QgsDistanceArea *distanceArea=0)
This function currently replaces each expression between [% and %] in the string with the result of i...