QGIS API Documentation  2.6.0-Brighton
 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;
27 class QgsDistanceArea;
28 
29 class CORE_EXPORT QgsComposerHtml: public QgsComposerMultiFrame
30 {
31  Q_OBJECT
32  public:
33 
37  {
38  Url, /*< Using this mode item fetches its content via a url*/
39  ManualHtml /*< HTML content is manually set for the item*/
40  };
41 
42  QgsComposerHtml( QgsComposition* c, bool createUndoCommands );
43 
44  //should be private - fix for QGIS 3.0
46 
47  ~QgsComposerHtml();
48 
56  void setContentMode( ContentMode mode ) { mContentMode = mode; }
57 
65  ContentMode contentMode() const { return mContentMode; }
66 
74  void setUrl( const QUrl& url );
75 
82  const QUrl& url() const { return mUrl; }
83 
94  void setHtml( const QString html );
95 
103  QString html() const { return mHtml; }
104 
113  bool evaluateExpressions() const { return mEvaluateExpressions; }
114 
123  void setEvaluateExpressions( bool evaluateExpressions );
124 
130  bool useSmartBreaks() const { return mUseSmartBreaks; }
131 
138  void setUseSmartBreaks( bool useSmartBreaks );
139 
152  void setMaxBreakDistance( double maxBreakDistance );
153 
163  double maxBreakDistance() const { return mMaxBreakDistance; }
164 
175  void setUserStylesheet( const QString stylesheet );
176 
184  QString userStylesheet() const { return mUserStylesheet; }
185 
192  void setUserStylesheetEnabled( const bool stylesheetEnabled );
193 
200  bool userStylesheetEnabled() const { return mEnableUserStylesheet; }
201 
202  virtual QString displayName() const;
203  QSizeF totalSize() const;
204  void render( QPainter* p, const QRectF& renderExtent, const int frameIndex );
205  bool writeXML( QDomElement& elem, QDomDocument & doc, bool ignoreFrames = false ) const;
206  bool readXML( const QDomElement& itemElem, const QDomDocument& doc, bool ignoreFrames = false );
207  void addFrame( QgsComposerFrame* frame, bool recalcFrameSizes = true );
208  //overriden to break frames without dividing lines of text
209  double findNearbyPageBreak( double yPos );
210 
211  public slots:
212 
217  void loadHtml();
218 
220  void recalculateFrameSizes();
221  void refreshExpressionContext();
222 
224 
225  private slots:
226  void frameLoaded( bool ok = true );
227 
228  private:
229  ContentMode mContentMode;
230  QUrl mUrl;
231  QWebPage* mWebPage;
232  QString mHtml;
233  QString mFetchedHtml;
234  QString mLastFetchedUrl;
235  QString mActualFetchedUrl; //may be different if page was redirected
236  bool mLoaded;
237  QSizeF mSize; //total size in mm
238  double mHtmlUnitsToMM;
239  QImage* mRenderedPage;
240  bool mEvaluateExpressions;
241  bool mUseSmartBreaks;
242  double mMaxBreakDistance;
243 
244  QgsFeature* mExpressionFeature;
245  QgsVectorLayer* mExpressionLayer;
246  QgsDistanceArea* mDistanceArea;
247 
248  QString mUserStylesheet;
249  bool mEnableUserStylesheet;
250 
251  QgsNetworkContentFetcher* mFetcher;
252 
253  double htmlUnitsToMM(); //calculate scale factor
254 
255  //renders a snapshot of the page to a cached image
256  void renderCachedImage();
257 
258  //fetches html content from a url and returns it as a string
259  QString fetchHtml( QUrl url );
260 
262  void setExpressionContext( QgsFeature* feature, QgsVectorLayer* layer );
263 
265  double maxFrameWidth() const;
266 };
267 
268 #endif // QGSCOMPOSERHTML_H