QGIS API Documentation  3.9.0-Master (224899f119)
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 
132 class CORE_EXPORT QgsMapRendererJob : public QObject
133 {
134  Q_OBJECT
135  public:
136 
137  QgsMapRendererJob( const QgsMapSettings &settings );
138 
143  virtual void start() = 0;
144 
149  virtual void cancel() = 0;
150 
156  virtual void cancelWithoutBlocking() = 0;
157 
159  virtual void waitForFinished() = 0;
160 
162  virtual bool isActive() const = 0;
163 
171  virtual bool usedCachedLabels() const = 0;
172 
178  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
179 
187  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
188 
194  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
195 
196  struct Error
197  {
198  Error( const QString &lid, const QString &msg )
199  : layerID( lid )
200  , message( msg )
201  {}
202 
203  QString layerID;
204  QString message;
205  };
206 
207  typedef QList<QgsMapRendererJob::Error> Errors;
208 
210  Errors errors() const;
211 
212 
217  void setCache( QgsMapRendererCache *cache );
218 
223  int renderingTime() const { return mRenderingTime; }
224 
230  QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
231 
237  const QgsMapSettings &mapSettings() const;
238 
243  static const QString LABEL_CACHE_ID SIP_SKIP;
244 
245  signals:
246 
254  void renderingLayersFinished();
255 
257  void finished();
258 
259  protected:
260 
263  Errors mErrors;
264 
265  QgsMapRendererCache *mCache = nullptr;
266 
267  int mRenderingTime = 0;
268 
270  QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
271 
275  bool mRecordRenderingTime = true;
276 
282  bool prepareLabelCache() const SIP_SKIP;
283 
295  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
296 
302  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
303 
305  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
306 
308  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
309 
311  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
312 
319  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
320 
325  Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
326 
328  static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
329 
330  private:
331 
339  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
340 
341  bool needTemporaryImage( QgsMapLayer *ml );
342 
343  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
344 };
345 
346 
354 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
355 {
356  Q_OBJECT
357 
358  public:
359  QgsMapRendererQImageJob( const QgsMapSettings &settings );
360 
362  virtual QImage renderedImage() = 0;
363 
364 };
365 
366 
367 #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:1617
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)