QGIS API Documentation  2.15.0-Master (972fc9f)
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 
33 class QgsLabelingResults;
36 class QgsPalLabeling;
37 
38 
43 {
45  QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
46  QgsMapLayerRenderer* renderer; // must be deleted
47  QPainter::CompositionMode blendMode;
48  bool cached; // if true, img already contains cached image from previous rendering
51 };
52 
54 
55 
80 class CORE_EXPORT QgsMapRendererJob : public QObject
81 {
82  Q_OBJECT
83  public:
84 
85  QgsMapRendererJob( const QgsMapSettings& settings );
86 
87  virtual ~QgsMapRendererJob() {}
88 
91  virtual void start() = 0;
92 
95  virtual void cancel() = 0;
96 
98  virtual void waitForFinished() = 0;
99 
101  virtual bool isActive() const = 0;
102 
104  virtual QgsLabelingResults* takeLabelingResults() = 0;
105 
106  struct Error
107  {
108  Error( const QString& lid, const QString& msg )
109  : layerID( lid )
110  , message( msg )
111  {}
112 
115  };
116 
118 
120  Errors errors() const;
121 
122 
125  void setCache( QgsMapRendererCache* cache );
126 
129  void setRequestedGeometryCacheForLayers( const QStringList& layerIds ) { mRequestedGeomCacheForLayers = layerIds; }
130 
132  int renderingTime() const { return mRenderingTime; }
133 
139  const QgsMapSettings& mapSettings() const;
140 
141  signals:
142 
144  void finished();
145 
146  protected:
147 
154  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform *ct, QgsRectangle &extent, QgsRectangle &r2 );
155 
157  LayerRenderJobs prepareJobs( QPainter* painter, QgsPalLabeling* labelingEngine, QgsLabelingEngineV2* labelingEngine2 );
158 
160  void cleanupJobs( LayerRenderJobs& jobs );
161 
163  void logRenderingTime( const LayerRenderJobs& jobs );
164 
165  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
166 
167  bool needTemporaryImage( QgsMapLayer* ml );
168 
170  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine, QgsLabelingEngineV2* labelingEngine2, QPainter* painter );
171  static void drawOldLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext );
172  static void drawNewLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine );
173 
175  void updateLayerGeometryCaches();
176 
178  Errors mErrors;
179 
181 
186 
189 };
190 
191 
197 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
198 {
199  Q_OBJECT
200 
201  public:
202  QgsMapRendererQImageJob( const QgsMapSettings& settings );
203 
205  virtual QImage renderedImage() = 0;
206 };
207 
208 
209 #endif // QGSMAPRENDERERJOB_H
void setRequestedGeometryCacheForLayers(const QStringList &layerIds)
Set which vector layers should be cached while rendering.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
Abstract base class for map rendering implementations.
QList< Error > Errors
QStringList mRequestedGeomCacheForLayers
list of layer IDs for which the geometry cache should be updated
QMap< QString, QgsGeometryCache > mGeometryCaches
map of geometry caches
The QgsLabelingEngineV2 class provides map labeling functionality.
The QgsMapSettings class contains configuration for rendering of the map.
QgsMapSettings mSettings
virtual ~QgsMapRendererJob()
Contains information about the context of a rendering operation.
int renderingTime
time it took to render the layer in ms (it is -1 if not rendered or still rendering) ...
Intermediate base class adding functionality that allows client to query the rendered image...
QgsMapLayerRenderer * renderer
Class for doing transforms between two map coordinate systems.
QgsRenderContext context
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Class that stores computed placement from labeling engine.
This class is responsible for keeping cache of rendered images of individual layers.
QList< LayerRenderJob > LayerRenderJobs
QPainter::CompositionMode blendMode
QgsMapRendererCache * mCache
int renderingTime() const
Find out how log it took to finish the job (in miliseconds)
Error(const QString &lid, const QString &msg)
Structure keeping low-level rendering job information.