QGIS API Documentation  3.8.0-Zanzibar (11aff65)
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 };
66 
67 typedef QList<LayerRenderJob> LayerRenderJobs;
68 
73 struct LabelRenderJob
74 {
75  QgsRenderContext context;
76 
81  QImage *img = nullptr;
83  bool cached = false;
85  bool canUseCache = false;
87  bool complete = false;
89  int renderingTime = -1;
91  QList< QPointer< QgsMapLayer > > participatingLayers;
92 };
93 
95 #endif
96 
122 class CORE_EXPORT QgsMapRendererJob : public QObject
123 {
124  Q_OBJECT
125  public:
126 
127  QgsMapRendererJob( const QgsMapSettings &settings );
128 
133  virtual void start() = 0;
134 
139  virtual void cancel() = 0;
140 
146  virtual void cancelWithoutBlocking() = 0;
147 
149  virtual void waitForFinished() = 0;
150 
152  virtual bool isActive() const = 0;
153 
161  virtual bool usedCachedLabels() const = 0;
162 
168  virtual QgsLabelingResults *takeLabelingResults() = 0 SIP_TRANSFER;
169 
177  void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
178 
184  const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
185 
186  struct Error
187  {
188  Error( const QString &lid, const QString &msg )
189  : layerID( lid )
190  , message( msg )
191  {}
192 
193  QString layerID;
194  QString message;
195  };
196 
197  typedef QList<QgsMapRendererJob::Error> Errors;
198 
200  Errors errors() const;
201 
202 
207  void setCache( QgsMapRendererCache *cache );
208 
213  int renderingTime() const { return mRenderingTime; }
214 
220  QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
221 
227  const QgsMapSettings &mapSettings() const;
228 
233  static const QString LABEL_CACHE_ID SIP_SKIP;
234 
235  signals:
236 
244  void renderingLayersFinished();
245 
247  void finished();
248 
249  protected:
250 
253  Errors mErrors;
254 
255  QgsMapRendererCache *mCache = nullptr;
256 
257  int mRenderingTime = 0;
258 
260  QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
261 
267  bool prepareLabelCache() const SIP_SKIP;
268 
270  LayerRenderJobs prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2 ) SIP_SKIP;
271 
277  LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
278 
280  static QImage composeImage( const QgsMapSettings &settings, const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
281 
283  void logRenderingTime( const LayerRenderJobs &jobs, const LabelRenderJob &labelJob ) SIP_SKIP;
284 
286  void cleanupJobs( LayerRenderJobs &jobs ) SIP_SKIP;
287 
294  void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
295 
300  Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
301 
303  static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
304 
305  private:
306 
314  static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
315 
316  bool needTemporaryImage( QgsMapLayer *ml );
317 
318  const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
319 };
320 
321 
329 class CORE_EXPORT QgsMapRendererQImageJob : public QgsMapRendererJob
330 {
331  Q_OBJECT
332 
333  public:
334  QgsMapRendererQImageJob( const QgsMapSettings &settings );
335 
337  virtual QImage renderedImage() = 0;
338 
339 };
340 
341 
342 #endif // QGSMAPRENDERERJOB_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
Base class for all map layer types.
Definition: qgsmaplayer.h:78
Abstract base class for map rendering implementations.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Definition: qgsmaplayer.h:1576
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: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)