QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgscomposerhtml.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerhtml.h
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 #ifndef QGSCOMPOSERHTML_H
17 #define QGSCOMPOSERHTML_H
18 
19 #include "qgscomposermultiframe.h"
20 #include <QUrl>
21 
22 class QWebPage;
23 class QImage;
24 class QgsFeature;
25 class QgsVectorLayer;
27 
28 class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
29 {
30  Q_OBJECT
31  public:
32 
36  {
37  Url, /*< Using this mode item fetches its content via a url*/
38  ManualHtml /*< HTML content is manually set for the item*/
39  };
40 
41  QgsComposerHtml( QgsComposition* c, bool createUndoCommands );
42 
43  //should be private - fix for QGIS 3.0
45 
46  ~QgsComposerHtml();
47 
55  void setContentMode( ContentMode mode ) { mContentMode = mode; }
56 
64  ContentMode contentMode() const { return mContentMode; }
65 
73  void setUrl( const QUrl& url );
74 
81  const QUrl& url() const { return mUrl; }
82 
93  void setHtml( const QString html );
94 
102  QString html() const { return mHtml; }
103 
112  bool evaluateExpressions() const { return mEvaluateExpressions; }
113 
122  void setEvaluateExpressions( bool evaluateExpressions );
123 
129  bool useSmartBreaks() const { return mUseSmartBreaks; }
130 
137  void setUseSmartBreaks( bool useSmartBreaks );
138 
151  void setMaxBreakDistance( double maxBreakDistance );
152 
162  double maxBreakDistance() const { return mMaxBreakDistance; }
163 
174  void setUserStylesheet( const QString stylesheet );
175 
183  QString userStylesheet() const { return mUserStylesheet; }
184 
191  void setUserStylesheetEnabled( const bool stylesheetEnabled );
192 
199  bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
200 
201  virtual QString displayName() const;
202  QSizeF totalSize() const;
203  void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
204  bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
205  bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
206  void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
207  //overriden to break frames without dividing lines of text
208  double findNearbyPageBreak( double yPos );
209 
210  public slots:
211 
216  void loadHtml();
217 
219  void recalculateFrameSizes();
220  void refreshExpressionContext();
221 
223 
224  private slots:
225  void frameLoaded( bool ok = true );
226 
227  private:
228  ContentMode mContentMode;
229  QUrl mUrl;
230  QWebPage* mWebPage;
231  QString mHtml;
232  QString mFetchedHtml;
233  QString mLastFetchedUrl;
234  QString mActualFetchedUrl; //may be different if page was redirected
235  bool mLoaded;
236  QSizeF mSize; //total size in mm
237  double mHtmlUnitsToMM;
238  QImage* mRenderedPage;
239  bool mEvaluateExpressions;
240  bool mUseSmartBreaks;
241  double mMaxBreakDistance;
242 
243  QgsFeature* mExpressionFeature;
244  QgsVectorLayer* mExpressionLayer;
245  QString mUserStylesheet;
246  bool mEnableUserStylesheet;
247 
248  QgsNetworkContentFetcher* mFetcher;
249 
250  double htmlUnitsToMM(); //calculate scale factor
251 
252  //renders a snapshot of the page to a cached image
253  void renderCachedImage();
254 
255  //fetches html content from a url and returns it as a string
256  QString fetchHtml( QUrl url );
257 
259  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
260 
262  double maxFrameWidth() const;
263 };
264 
265 #endif // QGSCOMPOSERHTML_H
virtual void recalculateFrameSizes()
Recalculates the portion of the multiframe item which is shown in each of it's component frames...
Definition: qgscomposermultiframe.cpp:69
ContentMode contentMode() const
Returns the source mode for item's HTML content.
Definition: qgscomposerhtml.h:64
virtual QString displayName() const
Get multiframe display name.
Definition: qgscomposermultiframe.cpp:225
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
Definition: qgscomposermultiframe.h:121
Definition: qgscomposerhtml.h:37
virtual QSizeF totalSize() const =0
Returns the total size of the multiframe's content.
DataDefinedProperty
Data defined properties for different item types.
Definition: qgscomposerobject.h:40
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
Definition: qgscomposerobject.h:43
QString userStylesheet() const
Returns the user stylesheet CSS rules used while rendering the HTML content.
Definition: qgscomposerhtml.h:183
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
Definition: qgscomposerhtml.h:129
QString html() const
Returns the HTML source displayed in the item if the item is using the QgsComposerHtml::ManualHtml mo...
Definition: qgscomposerhtml.h:102
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)=0
Adds a frame to the multiframe.
HTTP network content fetcher.
Definition: qgsnetworkcontentfetcher.h:35
Abstract base class for composer items with the ability to distribute the content to several frames (...
Definition: qgscomposermultiframe.h:39
bool evaluateExpressions() const
Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content...
Definition: qgscomposerhtml.h:112
Definition: qgscomposerhtml.h:28
Graphics scene for map printing.
Definition: qgscomposition.h:72
Frame item for a composer multiframe item.
Definition: qgscomposerframe.h:25
const QUrl & url() const
Returns the URL of the content displayed in the item if the item is using the QgsComposerHtml::Url mo...
Definition: qgscomposerhtml.h:81
void setContentMode(ContentMode mode)
Sets the source mode for item's HTML content.
Definition: qgscomposerhtml.h:55
bool userStylesheetEnabled() const
Returns whether user stylesheets are enabled for the HTML content.
Definition: qgscomposerhtml.h:199
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const =0
Stores state information about multiframe in DOM element.
double maxBreakDistance() const
Returns the maximum distance allowed when calculating where to place page breaks in the html...
Definition: qgscomposerhtml.h:162
virtual Q_DECL_DEPRECATED void render(QPainter *p, const QRectF &renderExtent)
Renders a portion of the multiframe's content into a painter.
Definition: qgscomposermultiframe.cpp:43
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)=0
Reads multiframe state information from a DOM element.
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
ContentMode
Source modes for the HTML content to render in the item.
Definition: qgscomposerhtml.h:35
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
Definition: qgscomposerobject.cpp:141