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;
26 
27 class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
28 {
29  Q_OBJECT
30  public:
31 
35  {
36  Url, /*< Using this mode item fetches its content via a url*/
37  ManualHtml /*< HTML content is manually set for the item*/
38  };
39 
40  QgsComposerHtml( QgsComposition* c, bool createUndoCommands );
42  ~QgsComposerHtml();
43 
51  void setContentMode( ContentMode mode ) { mContentMode = mode; }
52 
60  ContentMode contentMode() const { return mContentMode; }
61 
69  void setUrl( const QUrl& url );
70 
77  const QUrl& url() const { return mUrl; }
78 
89  void setHtml( const QString html );
90 
98  QString html() const { return mHtml; }
99 
108  bool evaluateExpressions() const { return mEvaluateExpressions; }
109 
118  void setEvaluateExpressions( bool evaluateExpressions );
119 
125  bool useSmartBreaks() const { return mUseSmartBreaks; }
126 
133  void setUseSmartBreaks( bool useSmartBreaks );
134 
147  void setMaxBreakDistance( double maxBreakDistance );
148 
158  double maxBreakDistance() const { return mMaxBreakDistance; }
159 
170  void setUserStylesheet( const QString stylesheet );
171 
179  QString userStylesheet() const { return mUserStylesheet; }
180 
187  void setUserStylesheetEnabled( const bool stylesheetEnabled );
188 
195  bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
196 
197  virtual QString displayName() const;
198  QSizeF totalSize() const;
199  void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
200  bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
201  bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
202  void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
203  //overriden to break frames without dividing lines of text
204  double findNearbyPageBreak( double yPos );
205 
206  public slots:
207 
212  void loadHtml();
213 
214  void refreshExpressionContext();
215 
217 
218  private slots:
219  void frameLoaded( bool ok = true );
220 
221  private:
222  ContentMode mContentMode;
223  QUrl mUrl;
224  QWebPage* mWebPage;
225  QString mHtml;
226  QString mFetchedHtml;
227  QString mLastFetchedUrl;
228  QString mActualFetchedUrl; //may be different if page was redirected
229  bool mLoaded;
230  QSizeF mSize; //total size in mm
231  double mHtmlUnitsToMM;
232  QImage* mRenderedPage;
233  bool mEvaluateExpressions;
234  bool mUseSmartBreaks;
235  double mMaxBreakDistance;
236 
237  QgsFeature* mExpressionFeature;
238  QgsVectorLayer* mExpressionLayer;
239  QString mUserStylesheet;
240  bool mEnableUserStylesheet;
241 
242  double htmlUnitsToMM(); //calculate scale factor
243 
244  //renders a snapshot of the page to a cached image
245  void renderCachedImage();
246 
247  //fetches html content from a url and returns it as a string
248  QString fetchHtml( QUrl url );
249 
251  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
252 };
253 
254 #endif // QGSCOMPOSERHTML_H
ContentMode contentMode() const
Returns the source mode for item's HTML content.
Definition: qgscomposerhtml.h:60
virtual QString displayName() const
Get multiframe display name.
Definition: qgscomposermultiframe.cpp:219
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
Definition: qgscomposermultiframe.h:121
Definition: qgscomposerhtml.h:36
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:179
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
Definition: qgscomposerhtml.h:125
QString html() const
Returns the HTML source displayed in the item if the item is using the QgsComposerHtml::ManualHtml mo...
Definition: qgscomposerhtml.h:98
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)=0
Adds a frame to the multiframe.
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:108
Definition: qgscomposerhtml.h:27
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:77
void setContentMode(ContentMode mode)
Sets the source mode for item's HTML content.
Definition: qgscomposerhtml.h:51
bool userStylesheetEnabled() const
Returns whether user stylesheets are enabled for the HTML content.
Definition: qgscomposerhtml.h:195
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:158
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:34
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