QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 <QFutureWatcher>
23 #include <QImage>
24 #include <QPainter>
25 #include <QObject>
26 #include <QTime>
27 
28 #include "qgsrendercontext.h"
29 
30 #include "qgsmapsettings.h"
31 
32 
33 class QgsLabelingEngine;
34 class QgsLabelingResults;
38 
39 #ifndef SIP_RUN
40 
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 
66 struct LabelRenderJob
67 {
68  QgsRenderContext context;
69 
74  QImage *img = nullptr;
76  bool cached = false;
78  bool canUseCache = false;
80  bool complete = false;
82  int renderingTime = -1;
84  QList< QPointer< QgsMapLayer > > participatingLayers;
85 };
86 
88 #endif
89 
115 class CORE_EXPORT QgsMapRendererJob : public QObject
116 {
117  Q_OBJECT
118  public:
119 
120  QgsMapRendererJob( const QgsMapSettings &settings );
121 
126  virtual void start() = 0;
127 
132  virtual void cancel() = 0;
133 
139  virtual void cancelWithoutBlocking() = 0;
140 
142  virtual void waitForFinished() = 0;
143 
145  virtual bool isActive() const = 0;
146 
154  virtual bool usedCachedLabels() const = 0;
155 
161  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
162 
170  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
171 
177  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
178 
179  struct Error
180  {
181  Error( const QString &lid, const QString &msg )
182  : layerID( lid )
183  , message( msg )
184  {}
185 
186  QString layerID;
187  QString message;
188  };
189 
190  typedef QList<QgsMapRendererJob::Error> Errors;
191 
193  Errors errors() const;
194 
195 
200  void setCache( QgsMapRendererCache *cache );
201 
206  int renderingTime() const { return mRenderingTime; }
207 
213  QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
214 
220  const QgsMapSettings &mapSettings() const;
221 
226  static const QString LABEL_CACHE_ID SIP_SKIP;
227 
228  signals:
229 
237  void renderingLayersFinished();
238 
240  void finished();
241 
242  protected:
243 
246  Errors mErrors;
247 
248  QgsMapRendererCache *mCache = nullptr;
249 
250  int mRenderingTime = 0;
251 
253  QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
254 
260  bool prepareLabelCache() const SIP_SKIP;
261 
263  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2 ) SIP_SKIP;
264 
270  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
271 
273  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
274 
276  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
277 
279  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
280 
287  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
288 
293  Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
294 
296  static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
297 
298  private:
299 
307  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
308 
309  bool needTemporaryImage( QgsMapLayer *ml );
310 
311  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
312 };
313 
314 
322 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
323 {
324  Q_OBJECT
325 
326  public:
327  QgsMapRendererQImageJob( const QgsMapSettings &settings );
328 
330  virtual QImage renderedImage() = 0;
331 
332 };
333 
334 
335 #endif // QGSMAPRENDERERJOB_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for all map layer types.
Definition: qgsmaplayer.h:63
const QgsFeatureFilterProvider * featureFilterProvider() const
Returns the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1482
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.
#define SIP_SKIP
Definition: qgis_sip.h:119
#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...
int renderingTime() const
Returns the total time it took to finish the job (in milliseconds).
Error(const QString &lid, const QString &msg)