QGIS API Documentation  2.10.1-Pisa
 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
49 };
50 
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 
110  };
111 
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 
134  const QgsMapSettings& mapSettings() const;
135 
136  signals:
137 
139  void finished();
140 
141  protected:
142 
149  static bool reprojectToLayerExtent( const QgsCoordinateTransform* ct, bool layerCrsGeographic, QgsRectangle& extent, QgsRectangle& r2 );
150 
152  LayerRenderJobs prepareJobs( QPainter* painter, QgsPalLabeling* labelingEngine );
153 
155  void cleanupJobs( LayerRenderJobs& jobs );
156 
157  static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
158 
159  bool needTemporaryImage( QgsMapLayer* ml );
160 
161  static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine, QPainter* painter );
162  static void drawOldLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext );
163  static void drawNewLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsPalLabeling* labelingEngine );
164 
166  void updateLayerGeometryCaches();
167 
170 
172 
177 
180 };
181 
182 
188 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
189 {
190  public:
191  QgsMapRendererQImageJob( const QgsMapSettings& settings );
192 
194  virtual QImage renderedImage() = 0;
195 };
196 
197 
198 #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 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.