QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  public slots:
209 
214  void loadHtml();
215 
216  void refreshExpressionContext();
217 
219 
220  private slots:
221  void frameLoaded( bool ok = true );
222 
223  private:
225  QUrl mUrl;
226  QWebPage* mWebPage;
227  QString mHtml;
228  QString mFetchedHtml;
230  bool mLoaded;
231  QSizeF mSize; //total size in mm
233  QImage* mRenderedPage;
237 
242 
243  double htmlUnitsToMM(); //calculate scale factor
244 
245  //renders a snapshot of the page to a cached image
246  void renderCachedImage();
247 
248  //fetches html content from a url and returns it as a string
249  QString fetchHtml( QUrl url );
250 
252  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
253 };
254 
255 #endif // QGSCOMPOSERHTML_H
QWebPage * mWebPage
virtual void render(QPainter *p, const QRectF &renderExtent)=0
ContentMode contentMode() const
Returns the source mode for item's HTML content.
virtual double findNearbyPageBreak(double yPos)
Finds the optimal position to break a frame at.
virtual QSizeF totalSize() const =0
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:113
DataDefinedProperty
Data defined properties for different item types.
QString userStylesheet() const
Returns the user stylesheet CSS rules used while rendering the HTML content.
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...
virtual void addFrame(QgsComposerFrame *frame, bool recalcFrameSizes=true)=0
QImage * mRenderedPage
Abstract base class for composer entries with the ability to distribute the content to several frames...
bool evaluateExpressions() const
Returns whether html item will evaluate QGIS expressions prior to rendering the HTML content...
Graphics scene for map printing.
Frame for html, table, text which can be divided onto several frames.
const QUrl & url() const
Returns the URL of the content displayed in the item if the item is using the QgsComposerHtml::Url mo...
void setContentMode(ContentMode mode)
Sets the source mode for item's HTML content.
QgsVectorLayer * mExpressionLayer
ContentMode mContentMode
bool userStylesheetEnabled() const
Returns whether user stylesheets are enabled for the HTML content.
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...
QgsFeature * mExpressionFeature
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc, bool ignoreFrames=false)=0
Represents a vector layer which manages a vector based data sets.
ContentMode
Source modes for the HTML content to render in the item.
virtual void refreshDataDefinedProperty(const DataDefinedProperty property=AllProperties)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...