QGIS API Documentation  2.99.0-Master (7d4f81d)
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 "qgis_sip.h"
21 #include "qgis.h"
22 #include <QFutureWatcher>
23 #include <QImage>
24 #include <QPainter>
25 #include <QObject>
26 #include <QTime>
27 
28 #include "qgsrendercontext.h"
29 
30 #include "qgsmapsettings.h"
31 
32 
33 class QgsLabelingEngine;
34 class QgsLabelingResults;
38 
39 #ifndef SIP_RUN
40 
45 struct LayerRenderJob
46 {
47  QgsRenderContext context;
48  QImage *img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
50  bool imageInitialized = false;
51  QgsMapLayerRenderer *renderer; // must be deleted
52  QPainter::CompositionMode blendMode;
53  double opacity;
54  bool cached; // if true, img already contains cached image from previous rendering
56  int renderingTime;
57 };
58 
59 typedef QList<LayerRenderJob> LayerRenderJobs;
60 
64 struct LabelRenderJob
65 {
66  QgsRenderContext context;
67 
72  QImage *img = nullptr;
74  bool cached = false;
76  bool canUseCache = false;
78  bool complete = false;
80  int renderingTime = -1;
82  QList< QPointer< QgsMapLayer > > participatingLayers;
83 };
84 
86 #endif
87 
112 class CORE_EXPORT QgsMapRendererJob : public QObject
113 {
114  Q_OBJECT
115  public:
116 
117  QgsMapRendererJob( const QgsMapSettings &settings );
118 
121  virtual void start() = 0;
122 
125  virtual void cancel() = 0;
126 
132  virtual void cancelWithoutBlocking() = 0;
133 
135  virtual void waitForFinished() = 0;
136 
138  virtual bool isActive() const = 0;
139 
147  virtual bool usedCachedLabels() const = 0;
148 
154  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
155 
161  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
162 
166  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
167 
168  struct Error
169  {
170  Error( const QString &lid, const QString &msg )
171  : layerID( lid )
172  , message( msg )
173  {}
174 
175  QString layerID;
176  QString message;
177  };
178 
179  typedef QList<QgsMapRendererJob::Error> Errors;
180 
182  Errors errors() const;
183 
184 
187  void setCache( QgsMapRendererCache *cache );
188 
190  int renderingTime() const { return mRenderingTime; }
191 
197  const QgsMapSettings &mapSettings() const;
198 
203  static const QString LABEL_CACHE_ID SIP_SKIP;
204 
205  signals:
206 
214  void renderingLayersFinished();
215 
217  void finished();
218 
219  protected:
220 
223  Errors mErrors;
224 
225  QgsMapRendererCache *mCache = nullptr;
226 
227  int mRenderingTime = 0;
228 
234  bool prepareLabelCache() const SIP_SKIP;
235 
237  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2 ) SIP_SKIP;
238 
244  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
245 
247  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
248 
250  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
251 
253  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
254 
261  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
262 
264  static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
265 
266  private:
267 
274  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
275 
276  bool needTemporaryImage( QgsMapLayer *ml );
277 
278  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
279 };
280 
281 
288 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
289 {
290  Q_OBJECT
291 
292  public:
293  QgsMapRendererQImageJob( const QgsMapSettings &settings );
294 
296  virtual QImage renderedImage() = 0;
297 
298 };
299 
300 
301 #endif // QGSMAPRENDERERJOB_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for all map layer types.
Definition: qgsmaplayer.h:54
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1094
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
#define SIP_SKIP
Definition: qgis_sip.h:119
#define SIP_TRANSFER
Definition: qgis_sip.h:36
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.
QList< QgsMapRendererJob::Error > Errors
Intermediate base class adding functionality that allows client to query the rendered image...
Class for doing transforms between two map coordinate systems.
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 resulting from a map rendering job...
Error(const QString &lid, const QString &msg)