QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 #include "qgsmaskidprovider.h"
31 
32 
33 class QgsLabelingEngine;
34 class QgsLabelingResults;
38 
39 #ifndef SIP_RUN
40 
46 struct LayerRenderJob
47 {
48  QgsRenderContext context;
49 
55  QImage *img;
57  bool imageInitialized = false;
58  QgsMapLayerRenderer *renderer; // must be deleted
59  QPainter::CompositionMode blendMode;
60  double opacity;
62  bool cached;
64  int renderingTime;
65  QStringList errors;
66 
75  QString layerId;
76 
92  QImage *maskImage = nullptr;
94 
99  LayerRenderJob *firstPassJob = nullptr;
100 
107  QList<QPair<LayerRenderJob *, int>> maskJobs;
108 };
109 
110 typedef QList<LayerRenderJob> LayerRenderJobs;
111 
116 struct LabelRenderJob
117 {
118  QgsRenderContext context;
119 
124  QImage *img = nullptr;
125 
136  QVector<QImage *> maskImages;
137 
142  QgsMaskIdProvider maskIdProvider;
143 
145  bool cached = false;
147  bool canUseCache = false;
149  bool complete = false;
151  int renderingTime = -1;
153  QList< QPointer< QgsMapLayer > > participatingLayers;
154 };
155 
157 #endif
158 
186 class CORE_EXPORT QgsMapRendererJob : public QObject
187 {
188  Q_OBJECT
189  public:
190 
191  QgsMapRendererJob( const QgsMapSettings &settings );
192 
197  virtual void start() = 0;
198 
203  virtual void cancel() = 0;
204 
210  virtual void cancelWithoutBlocking() = 0;
211 
213  virtual void waitForFinished() = 0;
214 
216  virtual bool isActive() const = 0;
217 
225  virtual bool usedCachedLabels() const = 0;
226 
232  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
233 
241  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
242 
248  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
249 
250  struct Error
251  {
252  Error( const QString &lid, const QString &msg )
253  : layerID( lid )
254  , message( msg )
255  {}
256 
257  QString layerID;
258  QString message;
259  };
260 
261  typedef QList<QgsMapRendererJob::Error> Errors;
262 
264  Errors errors() const;
265 
266 
271  void setCache( QgsMapRendererCache *cache );
272 
277  int renderingTime() const { return mRenderingTime; }
278 
284  QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
285 
291  const QgsMapSettings &mapSettings() const;
292 
297  static const QString LABEL_CACHE_ID SIP_SKIP;
298 
299  signals:
300 
308  void renderingLayersFinished();
309 
311  void finished();
312 
313  protected:
314 
315  QgsMapSettings mSettings;
316  QElapsedTimer mRenderingStart;
317  Errors mErrors;
318 
319  QgsMapRendererCache *mCache = nullptr;
320 
321  int mRenderingTime = 0;
322 
324  QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
325 
329  bool mRecordRenderingTime = true;
330 
336  bool prepareLabelCache() const SIP_SKIP;
337 
349  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
350 
356  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
357 
366  LayerRenderJobs prepareSecondPassJobs( LayerRenderJobs &firstPassJobs, LabelRenderJob &labelJob ) SIP_SKIP;
367 
369  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
370 
377  static void composeSecondPass( LayerRenderJobs &secondPassJobs, LabelRenderJob &labelJob ) SIP_SKIP;
378 
380  void logRenderingTime( const LayerRenderJobs &jobs, const LayerRenderJobs &secondPassJobs, const LabelRenderJob &labelJob ) SIP_SKIP;
381 
383  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
384 
386  void cleanupSecondPassJobs( LayerRenderJobs &jobs ) SIP_SKIP;
387 
394  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
395 
400  Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
401 
403  static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
404 
405  private:
406 
414  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
415 
416  bool needTemporaryImage( QgsMapLayer *ml );
417 
418  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
419 
421  QImage *allocateImage( QString layerId );
422 
424  QPainter *allocateImageAndPainter( QString layerId, QImage *&image );
425 };
426 
427 
435 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
436 {
437  Q_OBJECT
438 
439  public:
440  QgsMapRendererQImageJob( const QgsMapSettings &settings );
441 
443  virtual QImage renderedImage() = 0;
444 
445 };
446 
447 
448 #endif // QGSMAPRENDERERJOB_H
QgsMapRendererJob::Error::Error
Error(const QString &lid, const QString &msg)
Definition: qgsmaprendererjob.h:252
QgsMapRendererJob::Error
Definition: qgsmaprendererjob.h:250
qgsmaskidprovider.h
QgsLabelingResults
Definition: qgspallabeling.h:1224
QgsRenderContext
Definition: qgsrendercontext.h:57
qgsmapsettings.h
QgsRectangle
Definition: qgsrectangle.h:41
QgsMapRendererCache
Definition: qgsmaprenderercache.h:42
QgsMapLayerRenderer
Definition: qgsmaplayerrenderer.h:50
QgsMapRendererJob::renderingTime
int renderingTime() const
Returns the total time it took to finish the job (in milliseconds).
Definition: qgsmaprendererjob.h:277
QgsMapRendererJob::setFeatureFilterProvider
void setFeatureFilterProvider(const QgsFeatureFilterProvider *f)
Set the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
Definition: qgsmaprendererjob.h:241
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
qgsrendercontext.h
QgsMapRendererJob::featureFilterProvider
const QgsFeatureFilterProvider * featureFilterProvider() const
Returns the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
Definition: qgsmaprendererjob.h:248
QgsWeakMapLayerPointer
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1670
QgsMapRendererJob::Error::message
QString message
Definition: qgsmaprendererjob.h:258
QgsLabelingEngine
The QgsLabelingEngine class provides map labeling functionality. The input for the engine is a list o...
Definition: qgslabelingengine.h:214
QgsMapRendererQImageJob
Definition: qgsmaprendererjob.h:435
QgsMaskIdProvider
Definition: qgsmaskidprovider.h:37
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsMapRendererJob
Definition: qgsmaprendererjob.h:186
QgsFeatureFilterProvider
Definition: qgsfeaturefilterprovider.h:40
QgsMapRendererJob::Errors
QList< QgsMapRendererJob::Error > Errors
Definition: qgsmaprendererjob.h:261
QgsMapSettings
Definition: qgsmapsettings.h:86
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
QgsMapRendererJob::Error::layerID
QString layerID
Definition: qgsmaprendererjob.h:257