QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
129  signals:
130 
132  void finished();
133 
134  protected:
135 
142  static bool reprojectToLayerExtent( const QgsCoordinateTransform* ct, bool layerCrsGeographic, QgsRectangle& extent, QgsRectangle& r2 );
143 
145  LayerRenderJobs prepareJobs( QPainter* painter, QgsPalLabeling* labelingEngine );
146 
148  void cleanupJobs( LayerRenderJobs& jobs );
149 
150  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
151 
152  bool needTemporaryImage( QgsMapLayer* ml );
153 
154  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine, QPainter* painter );
155  static void drawOldLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext );
156  static void drawNewLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine );
157 
159  void updateLayerGeometryCaches();
160 
162  Errors mErrors;
163 
165 
169  QMap<QString, QgsGeometryCache> mGeometryCaches;
170 
173 };
174 
175 
181 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
182 {
183  public:
184  QgsMapRendererQImageJob( const QgsMapSettings& settings );
185 
187  virtual QImage renderedImage() = 0;
188 };
189 
190 
191 #endif // QGSMAPRENDERERJOB_H
void setRequestedGeometryCacheForLayers(const QStringList &layerIds)
Set which vector layers should be cached while rendering.
Definition: qgsmaprendererjob.h:124
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
Abstract base class for map rendering implementations.
Definition: qgsmaprendererjob.h:78
Definition: qgspallabeling.h:705
QList< Error > Errors
Definition: qgsmaprendererjob.h:112
Errors mErrors
Definition: qgsmaprendererjob.h:162
QStringList mRequestedGeomCacheForLayers
list of layer IDs for which the geometry cache should be updated
Definition: qgsmaprendererjob.h:167
QTime mRenderingStart
Definition: qgsmaprendererjob.h:171
QMap< QString, QgsGeometryCache > mGeometryCaches
map of geometry caches
Definition: qgsmaprendererjob.h:169
bool cached
Definition: qgsmaprendererjob.h:47
QImage * img
Definition: qgsmaprendererjob.h:44
Definition: qgsmaprendererjob.h:104
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:52
int mRenderingTime
Definition: qgsmaprendererjob.h:172
QString layerID
Definition: qgsmaprendererjob.h:108
QgsMapSettings mSettings
Definition: qgsmaprendererjob.h:161
virtual ~QgsMapRendererJob()
Definition: qgsmaprendererjob.h:85
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:39
Intermediate base class adding functionality that allows client to query the rendered image...
Definition: qgsmaprendererjob.h:181
QgsMapLayerRenderer * renderer
Definition: qgsmaprendererjob.h:45
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:52
QgsRenderContext context
Definition: qgsmaprendererjob.h:43
Base class for utility classes that encapsulate information necessary for rendering of map layers...
Definition: qgsmaplayerrenderer.h:43
Class that stores computed placement from labeling engine.
Definition: qgspallabeling.h:685
This class is responsible for keeping cache of rendered images of individual layers.
Definition: qgsmaprenderercache.h:37
QList< LayerRenderJob > LayerRenderJobs
Definition: qgsmaprendererjob.h:51
QString layerId
Definition: qgsmaprendererjob.h:48
QPainter::CompositionMode blendMode
Definition: qgsmaprendererjob.h:46
QgsMapRendererCache * mCache
Definition: qgsmaprendererjob.h:164
int renderingTime() const
Find out how log it took to finish the job (in miliseconds)
Definition: qgsmaprendererjob.h:127
Error(const QString &lid, const QString &msg)
Definition: qgsmaprendererjob.h:106
QString message
Definition: qgsmaprendererjob.h:109
Structure keeping low-level rendering job information.
Definition: qgsmaprendererjob.h:41