QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 
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
Some rendering operations may need multiple mask images.
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:79
QElapsedTimer mRenderingStart
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1650
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)