QGIS API Documentation  2.99.0-Master (e077efd)
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 QgsLabelingEngine;
33 class QgsLabelingResults;
36 class QgsPalLabeling;
37 
38 
44 {
46  QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
47  QgsMapLayerRenderer* renderer; // must be deleted
48  QPainter::CompositionMode blendMode;
49  double opacity;
50  bool cached; // if true, img already contains cached image from previous rendering
51  QString layerId;
53 };
54 
55 typedef QList<LayerRenderJob> LayerRenderJobs;
56 
57 
82 class CORE_EXPORT QgsMapRendererJob : public QObject
83 {
84  Q_OBJECT
85  public:
86 
87  QgsMapRendererJob( const QgsMapSettings& settings );
88 
89  virtual ~QgsMapRendererJob() {}
90 
93  virtual void start() = 0;
94 
97  virtual void cancel() = 0;
98 
100  virtual void waitForFinished() = 0;
101 
103  virtual bool isActive() const = 0;
104 
106  virtual QgsLabelingResults* takeLabelingResults() = 0;
107 
108  struct Error
109  {
110  Error( const QString& lid, const QString& msg )
111  : layerID( lid )
112  , message( msg )
113  {}
114 
115  QString layerID;
116  QString message;
117  };
118 
119  typedef QList<Error> Errors;
120 
122  Errors errors() const;
123 
124 
127  void setCache( QgsMapRendererCache* cache );
128 
131  void setRequestedGeometryCacheForLayers( const QStringList& layerIds ) { mRequestedGeomCacheForLayers = layerIds; }
132 
134  int renderingTime() const { return mRenderingTime; }
135 
141  const QgsMapSettings& mapSettings() const;
142 
143  signals:
144 
152  void renderingLayersFinished();
153 
155  void finished();
156 
157  protected:
158 
165  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
166 
168  LayerRenderJobs prepareJobs( QPainter* painter, QgsLabelingEngine* labelingEngine2 );
169 
171  void cleanupJobs( LayerRenderJobs& jobs );
172 
174  void logRenderingTime( const LayerRenderJobs& jobs );
175 
176  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
177 
178  bool needTemporaryImage( QgsMapLayer* ml );
179 
181  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsLabelingEngine* labelingEngine2, QPainter* painter );
182 
184  void updateLayerGeometryCaches();
185 
187  Errors mErrors;
188 
190 
194  QMap<QString, QgsGeometryCache> mGeometryCaches;
195 
198 };
199 
200 
207 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
208 {
209  Q_OBJECT
210 
211  public:
212  QgsMapRendererQImageJob( const QgsMapSettings& settings );
213 
215  virtual QImage renderedImage() = 0;
216 };
217 
218 
219 #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
int renderingTime() const
Find out how log it took to finish the job (in miliseconds)
The QgsMapSettings class contains configuration for rendering of the map.
QgsMapSettings mSettings
virtual ~QgsMapRendererJob()
The QgsLabelingEngine class provides map labeling functionality.
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
Error(const QString &lid, const QString &msg)
Structure keeping low-level rendering job information.