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 
120  QSizeF totalSize() const;
121  void render( QPainter* p, const QRectF& renderExtent );
122 
123  bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
124  bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
125 
126  void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
127 
128  //overriden to break frames without dividing lines of text
129  double findNearbyPageBreak( double yPos );
130 
136  bool useSmartBreaks() const { return mUseSmartBreaks; }
137 
144  void setUseSmartBreaks( bool useSmartBreaks );
145 
158  void setMaxBreakDistance( double maxBreakDistance );
159 
169  double maxBreakDistance() const { return mMaxBreakDistance; }
170 
181  void setUserStylesheet( const QString stylesheet );
182 
190  QString userStylesheet() const { return mUserStylesheet; }
191 
198  void setUserStylesheetEnabled( const bool stylesheetEnabled );
199 
206  bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
207 
208  virtual QString displayName() const;
209 
210  public slots:
211 
216  void loadHtml();
217 
218  void refreshExpressionContext();
219 
221 
222  private slots:
223  void frameLoaded( bool ok = true );
224 
225  private:
226  ContentMode mContentMode;
227  QUrl mUrl;
228  QWebPage* mWebPage;
229  QString mHtml;
230  QString mFetchedHtml;
231  QString mLastFetchedUrl;
232  QString mActualFetchedUrl; //may be different if page was redirected
233  bool mLoaded;
234  QSizeF mSize; //total size in mm
235  double mHtmlUnitsToMM;
236  QImage* mRenderedPage;
237  bool mEvaluateExpressions;
238  bool mUseSmartBreaks;
239  double mMaxBreakDistance;
240 
241  QgsFeature* mExpressionFeature;
242  QgsVectorLayer* mExpressionLayer;
243  QString mUserStylesheet;
244  bool mEnableUserStylesheet;
245 
246  double htmlUnitsToMM(); //calculate scale factor
247 
248  //renders a snapshot of the page to a cached image
249  void renderCachedImage();
250 
251  //fetches html content from a url and returns it as a string
252  QString fetchHtml( QUrl url );
253 
255  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
256 };
257 
258 #endif // QGSCOMPOSERHTML_H
virtual void render(QPainter *p, const QRectF &renderExtent)=0
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:187
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
Definition: qgscomposermultiframe.h:58
Definition: qgscomposerhtml.h:36
virtual QSizeF totalSize() const =0
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:190
bool useSmartBreaks() const
Returns whether html item is using smart breaks.
Definition: qgscomposerhtml.h:136
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
Abstract base class for composer entries with the ability to distribute the content to several frames...
Definition: qgscomposermultiframe.h:33
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:70
Frame for html, table, text which can be divided onto several frames.
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:206
virtual bool writeXML(QDomElement &elem, QDomDocument &doc, bool ignoreFrames=false) const =0
double maxBreakDistance() const
Returns the maximum distance allowed when calculating where to place page breaks in the html...
Definition: qgscomposerhtml.h:169
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)=0
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