QGIS API Documentation  2.99.0-Master (d55fa22)
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 <QtConcurrentRun>
23 #include <QFutureWatcher>
24 #include <QImage>
25 #include <QPainter>
26 #include <QObject>
27 #include <QTime>
28 
29 #include "qgsrendercontext.h"
30 
31 #include "qgsmapsettings.h"
32 
33 
34 class QgsLabelingEngine;
35 class QgsLabelingResults;
39 
40 #ifndef SIP_RUN
41 
46 struct LayerRenderJob
47 {
48  QgsRenderContext context;
49  QImage *img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
51  bool imageInitialized = false;
52  QgsMapLayerRenderer *renderer; // must be deleted
53  QPainter::CompositionMode blendMode;
54  double opacity;
55  bool cached; // if true, img already contains cached image from previous rendering
57  int renderingTime;
58 };
59 
60 typedef QList<LayerRenderJob> LayerRenderJobs;
61 
65 struct LabelRenderJob
66 {
67  QgsRenderContext context;
68 
73  QImage *img = nullptr;
75  bool cached = false;
77  bool canUseCache = false;
79  bool complete = false;
81  int renderingTime = -1;
83  QList< QPointer< QgsMapLayer > > participatingLayers;
84 };
85 
87 #endif
88 
113 class CORE_EXPORT QgsMapRendererJob : public QObject
114 {
115  Q_OBJECT
116  public:
117 
118  QgsMapRendererJob( const QgsMapSettings &settings );
119 
122  virtual void start() = 0;
123 
126  virtual void cancel() = 0;
127 
133  virtual void cancelWithoutBlocking() = 0;
134 
136  virtual void waitForFinished() = 0;
137 
139  virtual bool isActive() const = 0;
140 
148  virtual bool usedCachedLabels() const = 0;
149 
155  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
156 
162  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
163 
167  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
168 
169  struct Error
170  {
171  Error( const QString &lid, const QString &msg )
172  : layerID( lid )
173  , message( msg )
174  {}
175 
176  QString layerID;
177  QString message;
178  };
179 
180  typedef QList<QgsMapRendererJob::Error> Errors;
181 
183  Errors errors() const;
184 
185 
188  void setCache( QgsMapRendererCache *cache );
189 
191  int renderingTime() const { return mRenderingTime; }
192 
198  const QgsMapSettings &mapSettings() const;
199 
204  static const QString LABEL_CACHE_ID SIP_SKIP;
205 
206  signals:
207 
215  void renderingLayersFinished();
216 
218  void finished();
219 
220  protected:
221 
224  Errors mErrors;
225 
226  QgsMapRendererCache *mCache = nullptr;
227 
228  int mRenderingTime = 0;
229 
235  bool prepareLabelCache() const SIP_SKIP;
236 
238  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2 ) SIP_SKIP;
239 
245  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
246 
248  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
249 
251  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
252 
254  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
255 
262  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
263 
265  static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
266 
267  private:
268 
275  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
276 
277  bool needTemporaryImage( QgsMapLayer *ml );
278 
279  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
280 };
281 
282 
289 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
290 {
291  Q_OBJECT
292 
293  public:
294  QgsMapRendererQImageJob( const QgsMapSettings &settings );
295 
297  virtual QImage renderedImage() = 0;
298 
299 };
300 
301 
302 #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:1090
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:87
#define SIP_TRANSFER
Definition: qgis_sip.h:24
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)