QGIS API Documentation  2.99.0-Master (9fdd060)
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 
203  int renderingTime() const { return mRenderingTime; }
204 
210  const QgsMapSettings &mapSettings() const;
211 
216  static const QString LABEL_CACHE_ID SIP_SKIP;
217 
218  signals:
219 
227  void renderingLayersFinished();
228 
230  void finished();
231 
232  protected:
233 
236  Errors mErrors;
237 
238  QgsMapRendererCache *mCache = nullptr;
239 
240  int mRenderingTime = 0;
241 
247  bool prepareLabelCache() const SIP_SKIP;
248 
250  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2 ) SIP_SKIP;
251 
257  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
258 
260  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
261 
263  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
264 
266  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
267 
274  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
275 
277  static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
278 
279  private:
280 
288  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
289 
290  bool needTemporaryImage( QgsMapLayer *ml );
291 
292  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
293 };
294 
295 
303 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
304 {
305  Q_OBJECT
306 
307  public:
308  QgsMapRendererQImageJob( const QgsMapSettings &settings );
309 
311  virtual QImage renderedImage() = 0;
312 
313 };
314 
315 
316 #endif // QGSMAPRENDERERJOB_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
Base class for all map layer types.
Definition: qgsmaplayer.h:56
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1230
int renderingTime() const
Find out how long it took to finish the job (in milliseconds)
void setFeatureFilterProvider(const QgsFeatureFilterProvider *f)
The QgsMapSettings class contains configuration for rendering of the map.
const QgsFeatureFilterProvider * featureFilterProvider() const
#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...
Error(const QString &lid, const QString &msg)