QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmaprendererjob.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaprendererjob.h
3  --------------------------------------
4  Date : December 2013
5  Copyright : (C) 2013 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
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 QGSMAPRENDERERJOB_H
17 #define QGSMAPRENDERERJOB_H
18 
19 #include <QtConcurrentRun>
20 #include <QFutureWatcher>
21 #include <QImage>
22 #include <QPainter>
23 #include <QObject>
24 #include <QTime>
25 
26 #include "qgsrendercontext.h"
27 
28 #include "qgsmapsettings.h"
29 
30 #include "qgsgeometrycache.h"
31 
32 class QgsLabelingResults;
35 class QgsPalLabeling;
36 
37 
42 {
44  QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
45  QgsMapLayerRenderer* renderer; // must be deleted
46  QPainter::CompositionMode blendMode;
47  bool cached; // if true, img already contains cached image from previous rendering
48  QString layerId;
49 };
50 
51 typedef QList<LayerRenderJob> LayerRenderJobs;
52 
53 
78 class CORE_EXPORT QgsMapRendererJob : public QObject
79 {
80  Q_OBJECT
81  public:
82 
83  QgsMapRendererJob( const QgsMapSettings& settings );
84 
85  virtual ~QgsMapRendererJob() {}
86 
89  virtual void start() = 0;
90 
93  virtual void cancel() = 0;
94 
96  virtual void waitForFinished() = 0;
97 
99  virtual bool isActive() const = 0;
100 
102  virtual QgsLabelingResults* takeLabelingResults() = 0;
103 
104  struct Error
105  {
106  Error( const QString& lid, const QString& msg ) : layerID( lid ), message( msg ) {}
107 
108  QString layerID;
109  QString message;
110  };
111 
112  typedef QList<Error> Errors;
113 
115  Errors errors() const;
116 
117 
120  void setCache( QgsMapRendererCache* cache );
121 
124  void setRequestedGeometryCacheForLayers( const QStringList& layerIds ) { mRequestedGeomCacheForLayers = layerIds; }
125 
127  int renderingTime() const { return mRenderingTime; }
128 
134  const QgsMapSettings& mapSettings() const;
135 
136  signals:
137 
139  void finished();
140 
141  protected:
142 
149  static bool reprojectToLayerExtent( const QgsCoordinateTransform* ct, bool layerCrsGeographic, QgsRectangle& extent, QgsRectangle& r2 );
150 
152  LayerRenderJobs prepareJobs( QPainter* painter, QgsPalLabeling* labelingEngine );
153 
155  void cleanupJobs( LayerRenderJobs& jobs );
156 
157  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
158 
159  bool needTemporaryImage( QgsMapLayer* ml );
160 
161  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine, QPainter* painter );
162  static void drawOldLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext );
163  static void drawNewLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine );
164 
166  void updateLayerGeometryCaches();
167 
170 
172 
176  QMap<QString, QgsGeometryCache> mGeometryCaches;
177 
180 };
181 
182 
188 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
189 {
190  public:
191  QgsMapRendererQImageJob( const QgsMapSettings& settings );
192 
194  virtual QImage renderedImage() = 0;
195 };
196 
197 
198 #endif // QGSMAPRENDERERJOB_H