QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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  , mExpressionLayer( 0 )
48  , mDistanceArea( 0 )
49  , mEnableUserStylesheet( false )
50  , mFetcher( 0 )
51 {
52  mDistanceArea = new QgsDistanceArea();
53  mHtmlUnitsToMM = htmlUnitsToMM();
54  mWebPage = new QWebPage();
55  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Horizontal, Qt::ScrollBarAlwaysOff );
56  mWebPage->mainFrame()->setScrollBarPolicy( Qt::Vertical, Qt::ScrollBarAlwaysOff );
57 
58  //This makes the background transparent. Found on http://blog.qt.digia.com/blog/2009/06/30/transparent-qwebview-or-qwebpage/
59  QPalette palette = mWebPage->palette();
60  palette.setBrush( QPalette::Base, Qt::transparent );
61  mWebPage->setPalette( palette );
62 
64  QObject::connect( mWebPage, SIGNAL( loadFinished( bool ) ), this, SLOT( frameLoaded( bool ) ) );
65  if ( mComposition )
66  {
67  QObject::connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( handleFrameRemoval( QgsComposerItem* ) ) );
68  }
69 
70  // data defined strings
71  mDataDefinedNames.insert( QgsComposerObject::SourceUrl, QString( "dataDefinedSourceUrl" ) );
72 
74  {
75  //a html item added while atlas preview is enabled needs to have the expression context set,
76  //otherwise fields in the html aren't correctly evaluated until atlas preview feature changes (#9457)
78  }
79 
80  //connect to atlas feature changes
81  //to update the expression context
82  connect( &mComposition->atlasComposition(), SIGNAL( featureChanged( QgsFeature* ) ), this, SLOT( refreshExpressionContext() ) );
83 
84  mFetcher = new QgsNetworkContentFetcher();
85  connect( mFetcher, SIGNAL( finished() ), this, SLOT( frameLoaded() ) );
86 
87 }
88 
90 {
91  delete mDistanceArea;
92  delete mWebPage;
93  delete mRenderedPage;
94  mFetcher->deleteLater();
95 }
96 
97 void QgsComposerHtml::setUrl( const QUrl& url )
98 {
99  if ( !mWebPage )
100  {
101  return;
102  }
103 
104  mUrl = url;
105  loadHtml( true );
106  emit changed();
107 }
108 
110 {
111  mHtml = html;
112  //TODO - this signal should be emitted, but without changing the signal which sets the html
113  //to an equivalent of editingFinished it causes a lot of problems. Need to investigate
114  //ways of doing this using QScintilla widgets.
115  //emit changed();
116 }
117 
118 void QgsComposerHtml::setEvaluateExpressions( bool evaluateExpressions )
119 {
120  mEvaluateExpressions = evaluateExpressions;
121  loadHtml( true );
122  emit changed();
123 }
124 
125 void QgsComposerHtml::loadHtml( const bool useCache, const QgsExpressionContext *context )
126 {
127  if ( !mWebPage )
128  {
129  return;
130  }
131 
132  const QgsExpressionContext* evalContext = context;
134  if ( !evalContext )
135  {
136  scopedContext.reset( createExpressionContext() );
137  evalContext = scopedContext.data();
138  }
139 
140  QString loadedHtml;
141  switch ( mContentMode )
142  {
144  {
145 
146  QString currentUrl = mUrl.toString();
147 
148  //data defined url set?
149  QVariant exprVal;
150  if ( dataDefinedEvaluate( QgsComposerObject::SourceUrl, exprVal, *evalContext ) )
151  {
152  currentUrl = exprVal.toString().trimmed();;
153  QgsDebugMsg( QString( "exprVal Source Url:%1" ).arg( currentUrl ) );
154  }
155  if ( currentUrl.isEmpty() )
156  {
157  return;
158  }
159  if ( !( useCache && currentUrl == mLastFetchedUrl ) )
160  {
161  loadedHtml = fetchHtml( QUrl( currentUrl ) );
162  mLastFetchedUrl = currentUrl;
163  }
164  else
165  {
166  loadedHtml = mFetchedHtml;
167  }
168 
169  break;
170  }
172  loadedHtml = mHtml;
173  break;
174  }
175 
176  //evaluate expressions
177  if ( mEvaluateExpressions )
178  {
179  loadedHtml = QgsExpression::replaceExpressionText( loadedHtml, evalContext, 0, mDistanceArea );
180  }
181 
182  mLoaded = false;
183 
184  //reset page size. otherwise viewport size increases but never decreases again
185  mWebPage->setViewportSize( QSize( maxFrameWidth() * mHtmlUnitsToMM, 0 ) );
186 
187  //set html, using the specified url as base if in Url mode
188  mWebPage->mainFrame()->setHtml( loadedHtml, mContentMode == QgsComposerHtml::Url ? QUrl( mActualFetchedUrl ) : QUrl() );
189 
190  //set user stylesheet
191  QWebSettings* settings = mWebPage->settings();
192  if ( mEnableUserStylesheet && ! mUserStylesheet.isEmpty() )
193  {
194  QByteArray ba;
195  ba.append( mUserStylesheet.toUtf8() );
196  QUrl cssFileURL = QUrl( "data:text/css;charset=utf-8;base64," + ba.toBase64() );
197  settings->setUserStyleSheetUrl( cssFileURL );
198  }
199  else
200  {
201  settings->setUserStyleSheetUrl( QUrl() );
202  }
203 
204  while ( !mLoaded )
205  {
206  qApp->processEvents();
207  }
208 
210  //trigger a repaint
211  emit contentsChanged();
212 }
213 
214 void QgsComposerHtml::frameLoaded( bool ok )
215 {
216  Q_UNUSED( ok );
217  mLoaded = true;
218 }
219 
220 double QgsComposerHtml::maxFrameWidth() const
221 {
222  double maxWidth = 0;
224  for ( ; frameIt != mFrameItems.constEnd(); ++frameIt )
225  {
226  maxWidth = qMax( maxWidth, ( double )(( *frameIt )->boundingRect().width() ) );
227  }
228 
229  return maxWidth;
230 }
231 
233 {
234  if ( frameCount() < 1 ) return;
235 
236  QSize contentsSize = mWebPage->mainFrame()->contentsSize();
237 
238  //find maximum frame width
239  double maxWidth = maxFrameWidth();
240  //set content width to match maximum frame width
241  contentsSize.setWidth( maxWidth * mHtmlUnitsToMM );
242 
243  mWebPage->setViewportSize( contentsSize );
244  mSize.setWidth( contentsSize.width() / mHtmlUnitsToMM );
245  mSize.setHeight( contentsSize.height() / mHtmlUnitsToMM );
246  if ( contentsSize.isValid() )
247  {
248  renderCachedImage();
249  }
251  emit changed();
252 }
253 
254 void QgsComposerHtml::renderCachedImage()
255 {
256  //render page to cache image
257  if ( mRenderedPage )
258  {
259  delete mRenderedPage;
260  }
261  mRenderedPage = new QImage( mWebPage->viewportSize(), QImage::Format_ARGB32 );
262  if ( mRenderedPage->isNull() )
263  {
264  return;
265  }
266  mRenderedPage->fill( Qt::transparent );
267  QPainter painter;
268  painter.begin( mRenderedPage );
269  mWebPage->mainFrame()->render( &painter );
270  painter.end();
271 }
272 
273 QString QgsComposerHtml::fetchHtml( QUrl url )
274 {
275  //pause until HTML fetch
276  mLoaded = false;
277  mFetcher->fetchContent( url );
278 
279  while ( !mLoaded )
280  {
281  qApp->processEvents();
282  }
283 
284  mFetchedHtml = mFetcher->contentAsString();
285  mActualFetchedUrl = mFetcher->reply()->url().toString();
286  return mFetchedHtml;
287 }
288 
290 {
291  return mSize;
292 }
293 
294 void QgsComposerHtml::render( QPainter* p, const QRectF& renderExtent, const int frameIndex )
295 {
296  Q_UNUSED( frameIndex );
297 
298  if ( !mWebPage )
299  {
300  return;
301  }
302 
303  p->save();
304  p->setRenderHint( QPainter::Antialiasing );
305  p->scale( 1.0 / mHtmlUnitsToMM, 1.0 / mHtmlUnitsToMM );
306  p->translate( 0.0, -renderExtent.top() * mHtmlUnitsToMM );
307  mWebPage->mainFrame()->render( p, QRegion( renderExtent.left(), renderExtent.top() * mHtmlUnitsToMM, renderExtent.width() * mHtmlUnitsToMM, renderExtent.height() * mHtmlUnitsToMM ) );
308  p->restore();
309 }
310 
311 double QgsComposerHtml::htmlUnitsToMM()
312 {
313  if ( !mComposition )
314  {
315  return 1.0;
316  }
317 
318  return ( mComposition->printResolution() / 72.0 ); //webkit seems to assume a standard dpi of 96
319 }
320 
321 void QgsComposerHtml::addFrame( QgsComposerFrame* frame, bool recalcFrameSizes )
322 {
323  mFrameItems.push_back( frame );
324  QObject::connect( frame, SIGNAL( sizeChanged() ), this, SLOT( recalculateFrameSizes() ) );
325  if ( mComposition )
326  {
327  mComposition->addComposerHtmlFrame( this, frame );
328  }
329 
330  if ( recalcFrameSizes )
331  {
333  }
334 }
335 
336 bool candidateSort( const QPair<int, int> &c1, const QPair<int, int> &c2 )
337 {
338  if ( c1.second < c2.second )
339  return true;
340  else if ( c1.second > c2.second )
341  return false;
342  else if ( c1.first > c2.first )
343  return true;
344  else
345  return false;
346 }
347 
349 {
350  if ( !mWebPage || !mRenderedPage || !mUseSmartBreaks )
351  {
352  return yPos;
353  }
354 
355  //convert yPos to pixels
356  int idealPos = yPos * htmlUnitsToMM();
357 
358  //if ideal break pos is past end of page, there's nothing we need to do
359  if ( idealPos >= mRenderedPage->height() )
360  {
361  return yPos;
362  }
363 
364  int maxSearchDistance = mMaxBreakDistance * htmlUnitsToMM();
365 
366  //loop through all lines just before ideal break location, up to max distance
367  //of maxSearchDistance
368  int changes = 0;
369  QRgb currentColor;
370  bool currentPixelTransparent = false;
371  bool previousPixelTransparent = false;
372  QRgb pixelColor;
373  QList< QPair<int, int> > candidates;
374  int minRow = qMax( idealPos - maxSearchDistance, 0 );
375  for ( int candidateRow = idealPos; candidateRow >= minRow; --candidateRow )
376  {
377  changes = 0;
378  currentColor = qRgba( 0, 0, 0, 0 );
379  //check all pixels in this line
380  for ( int col = 0; col < mRenderedPage->width(); ++col )
381  {
382  //count how many times the pixels change color in this row
383  //eventually, we select a row to break at with the minimum number of color changes
384  //since this is likely a line break, or gap between table cells, etc
385  //but very unlikely to be midway through a text line or picture
386  pixelColor = mRenderedPage->pixel( col, candidateRow );
387  currentPixelTransparent = qAlpha( pixelColor ) == 0;
388  if ( pixelColor != currentColor && !( currentPixelTransparent && previousPixelTransparent ) )
389  {
390  //color has changed
391  currentColor = pixelColor;
392  changes++;
393  }
394  previousPixelTransparent = currentPixelTransparent;
395  }
396  candidates.append( qMakePair( candidateRow, changes ) );
397  }
398 
399  //sort candidate rows by number of changes ascending, row number descending
400  qSort( candidates.begin(), candidates.end(), candidateSort );
401  //first candidate is now the largest row with smallest number of changes
402 
403  //ok, now take the mid point of the best candidate position
404  //we do this so that the spacing between text lines is likely to be split in half
405  //otherwise the html will be broken immediately above a line of text, which
406  //looks a little messy
407  int maxCandidateRow = candidates[0].first;
408  int minCandidateRow = maxCandidateRow + 1;
409  int minCandidateChanges = candidates[0].second;
410 
411  QList< QPair<int, int> >::iterator it;
412  for ( it = candidates.begin(); it != candidates.end(); ++it )
413  {
414  if (( *it ).second != minCandidateChanges || ( *it ).first != minCandidateRow - 1 )
415  {
416  //no longer in a consecutive block of rows of minimum pixel color changes
417  //so return the row mid-way through the block
418  //first converting back to mm
419  return ( minCandidateRow + ( maxCandidateRow - minCandidateRow ) / 2 ) / htmlUnitsToMM();
420  }
421  minCandidateRow = ( *it ).first;
422  }
423 
424  //above loop didn't work for some reason
425  //return first candidate converted to mm
426  return candidates[0].first / htmlUnitsToMM();
427 }
428 
429 void QgsComposerHtml::setUseSmartBreaks( bool useSmartBreaks )
430 {
431  mUseSmartBreaks = useSmartBreaks;
433  emit changed();
434 }
435 
436 void QgsComposerHtml::setMaxBreakDistance( double maxBreakDistance )
437 {
438  mMaxBreakDistance = maxBreakDistance;
440  emit changed();
441 }
442 
444 {
445  mUserStylesheet = stylesheet;
446  //TODO - this signal should be emitted, but without changing the signal which sets the css
447  //to an equivalent of editingFinished it causes a lot of problems. Need to investigate
448  //ways of doing this using QScintilla widgets.
449  //emit changed();
450 }
451 
452 void QgsComposerHtml::setUserStylesheetEnabled( const bool stylesheetEnabled )
453 {
454  if ( mEnableUserStylesheet != stylesheetEnabled )
455  {
456  mEnableUserStylesheet = stylesheetEnabled;
457  loadHtml( true );
458  emit changed();
459  }
460 }
461 
463 {
464  return tr( "<HTML frame>" );
465 }
466 
467 bool QgsComposerHtml::writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames ) const
468 {
469  QDomElement htmlElem = doc.createElement( "ComposerHtml" );
470  htmlElem.setAttribute( "contentMode", QString::number(( int ) mContentMode ) );
471  htmlElem.setAttribute( "url", mUrl.toString() );
472  htmlElem.setAttribute( "html", mHtml );
473  htmlElem.setAttribute( "evaluateExpressions", mEvaluateExpressions ? "true" : "false" );
474  htmlElem.setAttribute( "useSmartBreaks", mUseSmartBreaks ? "true" : "false" );
475  htmlElem.setAttribute( "maxBreakDistance", QString::number( mMaxBreakDistance ) );
476  htmlElem.setAttribute( "stylesheet", mUserStylesheet );
477  htmlElem.setAttribute( "stylesheetEnabled", mEnableUserStylesheet ? "true" : "false" );
478 
479  bool state = _writeXML( htmlElem, doc, ignoreFrames );
480  elem.appendChild( htmlElem );
481  return state;
482 }
483 
484 bool QgsComposerHtml::readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames )
485 {
486  if ( !ignoreFrames )
487  {
488  deleteFrames();
489  }
490 
491  //first create the frames
492  if ( !_readXML( itemElem, doc, ignoreFrames ) )
493  {
494  return false;
495  }
496 
497  bool contentModeOK;
498  mContentMode = ( QgsComposerHtml::ContentMode )itemElem.attribute( "contentMode" ).toInt( &contentModeOK );
499  if ( !contentModeOK )
500  {
501  mContentMode = QgsComposerHtml::Url;
502  }
503  mEvaluateExpressions = itemElem.attribute( "evaluateExpressions", "true" ) == "true" ? true : false;
504  mUseSmartBreaks = itemElem.attribute( "useSmartBreaks", "true" ) == "true" ? true : false;
505  mMaxBreakDistance = itemElem.attribute( "maxBreakDistance", "10" ).toDouble();
506  mHtml = itemElem.attribute( "html" );
507  mUserStylesheet = itemElem.attribute( "stylesheet" );
508  mEnableUserStylesheet = itemElem.attribute( "stylesheetEnabled", "false" ) == "true" ? true : false;
509 
510  //finally load the set url
511  QString urlString = itemElem.attribute( "url" );
512  if ( !urlString.isEmpty() )
513  {
514  mUrl = urlString;
515  }
516  loadHtml( true );
517 
518  //since frames had to be created before, we need to emit a changed signal to refresh the widget
519  emit changed();
520  return true;
521 }
522 
523 void QgsComposerHtml::setExpressionContext( const QgsFeature &feature, QgsVectorLayer* layer )
524 {
525  mExpressionFeature = feature;
526  mExpressionLayer = layer;
527 
528  //setup distance area conversion
529  if ( layer )
530  {
531  mDistanceArea->setSourceCrs( layer->crs().srsid() );
532  }
533  else if ( mComposition )
534  {
535  //set to composition's mapsettings' crs
536  mDistanceArea->setSourceCrs( mComposition->mapSettings().destinationCrs().srsid() );
537  }
538  if ( mComposition )
539  {
541  }
542  mDistanceArea->setEllipsoid( QgsProject::instance()->readEntry( "Measure", "/Ellipsoid", GEO_NONE ) );
543 }
544 
546 {
547  QgsVectorLayer * vl = 0;
548  QgsFeature feature;
549 
551  {
553  }
555  {
556  feature = mComposition->atlasComposition().feature();
557  }
558 
559  setExpressionContext( feature, vl );
560  loadHtml( true );
561 }
562 
564 {
565  const QgsExpressionContext* evalContext = context;
567  if ( !evalContext )
568  {
569  scopedContext.reset( createExpressionContext() );
570  evalContext = scopedContext.data();
571  }
572 
573  //updates data defined properties and redraws item to match
574  if ( property == QgsComposerObject::SourceUrl || property == QgsComposerObject::AllProperties )
575  {
576  loadHtml( true, evalContext );
577  }
579 }
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 loadHtml(const bool useCache=false, const QgsExpressionContext *context=0)
Reloads the html source from the url and redraws the item.
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.
long srsid() const
Get the SrsId - if possible.
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.
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
QgsFeature feature() const
Returns the current atlas feature.
QNetworkReply * reply()
Returns a reference to the network reply.
DataDefinedProperty
Data defined properties for different item types.
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
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 useSmartBreaks() const
Returns whether html item is using smart breaks.
void reset(T *other)
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.
virtual QgsExpressionContext * createExpressionContext() const
Creates an expression context relating to the objects's current state.
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)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
Graphics scene for map printing.
Frame item for a composer multiframe item.
QByteArray & append(char ch)
T * data() const
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...
bool dataDefinedEvaluate(const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext &context=QgsExpressionContext()) const
Evaluate a data defined property and return the calculated value.
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
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties, const QgsExpressionContext *context=0)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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:352
void setScrollBarPolicy(Qt::Orientation orientation, Qt::ScrollBarPolicy policy)
int height() const
QUrl url() const
void translate(const QPointF &offset)
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=0) override
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)
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 Q_DECL_DEPRECATED 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...