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 
171  public slots:
172 
177  void loadHtml();
178 
179  void refreshExpressionContext();
180 
182 
183  private slots:
184  void frameLoaded( bool ok = true );
185 
186  private:
188  QUrl mUrl;
189  QWebPage* mWebPage;
190  QString mHtml;
191  QString mFetchedHtml;
193  bool mLoaded;
194  QSizeF mSize; //total size in mm
196  QImage* mRenderedPage;
200 
203 
204  double htmlUnitsToMM(); //calculate scale factor
205 
206  //renders a snapshot of the page to a cached image
207  void renderCachedImage();
208 
209  //fetches html content from a url and returns it as a string
210  QString fetchHtml( QUrl url );
211 
213  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
214 };
215 
216 #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.
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
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...