QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 <QFutureWatcher>
22 #include <QImage>
23 #include <QPainter>
24 #include <QObject>
25 #include <QTime>
26 
27 #include "qgsrendercontext.h"
28 
29 #include "qgsmapsettings.h"
30 
31 
32 class QgsLabelingEngine;
33 class QgsLabelingResults;
37 
38 #ifndef SIP_RUN
39 
45 struct LayerRenderJob
46 {
47  QgsRenderContext context;
48 
54  QImage *img;
56  bool imageInitialized = false;
57  QgsMapLayerRenderer *renderer; // must be deleted
58  QPainter::CompositionMode blendMode;
59  double opacity;
61  bool cached;
63  int renderingTime;
64  QStringList errors;
65 
74  QString layerId;
75 };
76 
77 typedef QList<LayerRenderJob> LayerRenderJobs;
78 
83 struct LabelRenderJob
84 {
85  QgsRenderContext context;
86 
91  QImage *img = nullptr;
93  bool cached = false;
95  bool canUseCache = false;
97  bool complete = false;
99  int renderingTime = -1;
101  QList< QPointer< QgsMapLayer > > participatingLayers;
102 };
103 
105 #endif
106 
134 class CORE_EXPORT QgsMapRendererJob : public QObject
135 {
136  Q_OBJECT
137  public:
138 
139  QgsMapRendererJob( const QgsMapSettings &settings );
140 
145  virtual void start() = 0;
146 
151  virtual void cancel() = 0;
152 
158  virtual void cancelWithoutBlocking() = 0;
159 
161  virtual void waitForFinished() = 0;
162 
164  virtual bool isActive() const = 0;
165 
173  virtual bool usedCachedLabels() const = 0;
174 
180  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
181 
189  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
190 
196  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
197 
198  struct Error
199  {
200  Error( const QString &lid, const QString &msg )
201  : layerID( lid )
202  , message( msg )
203  {}
204 
205  QString layerID;
206  QString message;
207  };
208 
209  typedef QList<QgsMapRendererJob::Error> Errors;
210 
212  Errors errors() const;
213 
214 
219  void setCache( QgsMapRendererCache *cache );
220 
225  int renderingTime() const { return mRenderingTime; }
226 
232  QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
233 
239  const QgsMapSettings &mapSettings() const;
240 
245  static const QString LABEL_CACHE_ID SIP_SKIP;
246 
247  signals:
248 
256  void renderingLayersFinished();
257 
259  void finished();
260 
261  protected:
262 
265  Errors mErrors;
266 
267  QgsMapRendererCache *mCache = nullptr;
268 
269  int mRenderingTime = 0;
270 
272  QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
273 
277  bool mRecordRenderingTime = true;
278 
284  bool prepareLabelCache() const SIP_SKIP;
285 
297  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
298 
304  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
305 
307  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
308 
310  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
311 
313  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
314 
321  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
322 
327  Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
328 
330  static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
331 
332  private:
333 
341  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
342 
343  bool needTemporaryImage( QgsMapLayer *ml );
344 
345  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
346 };
347 
348 
356 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
357 {
358  Q_OBJECT
359 
360  public:
361  QgsMapRendererQImageJob( const QgsMapSettings &settings );
362 
364  virtual QImage renderedImage() = 0;
365 
366 };
367 
368 
369 #endif // QGSMAPRENDERERJOB_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1632
int renderingTime() const
Returns the total time it took to finish the job (in milliseconds).
void setFeatureFilterProvider(const QgsFeatureFilterProvider *f)
Set the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
The QgsMapSettings class contains configuration for rendering of the map.
QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime
Render time (in ms) per layer, by layer ID.
const QgsFeatureFilterProvider * featureFilterProvider() const
Returns the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
#define SIP_SKIP
Definition: qgis_sip.h:126
#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)