QGIS API Documentation  2.99.0-Master (7fe5405)
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 "qgis_core.h"
20 #include <QtConcurrentRun>
21 #include <QFutureWatcher>
22 #include <QImage>
23 #include <QPainter>
24 #include <QObject>
25 #include <QTime>
26 
27 #include "qgsrendercontext.h"
28 
29 #include "qgsmapsettings.h"
30 
31 #include "qgsgeometrycache.h"
32 
33 class QgsLabelingEngine;
34 class QgsLabelingResults;
37 class QgsPalLabeling;
39 
40 
46 {
48  QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
49  QgsMapLayerRenderer* renderer; // must be deleted
50  QPainter::CompositionMode blendMode;
51  double opacity;
52  bool cached; // if true, img already contains cached image from previous rendering
53  QString layerId;
55 };
56 
57 typedef QList<LayerRenderJob> LayerRenderJobs;
58 
59 
84 class CORE_EXPORT QgsMapRendererJob : public QObject
85 {
86  Q_OBJECT
87  public:
88 
89  QgsMapRendererJob( const QgsMapSettings& settings );
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 
113  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; };
114 
118  const QgsFeatureFilterProvider* featureFilterProvider() const { return mFeatureFilterProvider; };
119 
120  struct Error
121  {
122  Error( const QString& lid, const QString& msg )
123  : layerID( lid )
124  , message( msg )
125  {}
126 
127  QString layerID;
128  QString message;
129  };
130 
131  typedef QList<Error> Errors;
132 
134  Errors errors() const;
135 
136 
139  void setCache( QgsMapRendererCache* cache );
140 
143  void setRequestedGeometryCacheForLayers( const QStringList& layerIds ) { mRequestedGeomCacheForLayers = layerIds; }
144 
146  int renderingTime() const { return mRenderingTime; }
147 
153  const QgsMapSettings& mapSettings() const;
154 
155  signals:
156 
164  void renderingLayersFinished();
165 
167  void finished();
168 
169  protected:
170 
177  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
178 
180  LayerRenderJobs prepareJobs( QPainter* painter, QgsLabelingEngine* labelingEngine2 );
181 
183  void cleanupJobs( LayerRenderJobs& jobs );
184 
186  void logRenderingTime( const LayerRenderJobs& jobs );
187 
188  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
189 
190  bool needTemporaryImage( QgsMapLayer* ml );
191 
193  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsLabelingEngine* labelingEngine2, QPainter* painter );
194 
196  void updateLayerGeometryCaches();
198  Errors mErrors;
199 
201 
205  QMap<QString, QgsGeometryCache> mGeometryCaches;
206 
209 
211 };
212 
213 
220 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
221 {
222  Q_OBJECT
223 
224  public:
225  QgsMapRendererQImageJob( const QgsMapSettings& settings );
226 
228  virtual QImage renderedImage() = 0;
229 };
230 
231 
232 #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:36
Base class for all map layer types.
Definition: qgsmaplayer.h:50
Abstract base class for map rendering implementations.
const QgsFeatureFilterProvider * mFeatureFilterProvider
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 long it took to finish the job (in milliseconds)
void setFeatureFilterProvider(const QgsFeatureFilterProvider *f)
The QgsMapSettings class contains configuration for rendering of the map.
const QgsFeatureFilterProvider * featureFilterProvider() const
Abstract interface for use by classes that filter the features of a layer.
QgsMapSettings mSettings
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.