QGIS API Documentation  2.4.0-Chugiak
 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 
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 
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.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
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 QgsMapSettings class contains configuration for rendering of the map.
QgsMapSettings mSettings
virtual ~QgsMapRendererJob()
Contains information about the context of a rendering operation.
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.