QGIS API Documentation 3.39.0-Master (47f7b3a4989)
Loading...
Searching...
No Matches
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#include <QElapsedTimer>
27#include <QPicture>
28
29#include "qgsrendercontext.h"
30#include "qgslabelsink.h"
31#include "qgsmapsettings.h"
32#include "qgsmaskidprovider.h"
33
34class QPicture;
35
42class QgsElevationMap;
45
46#ifndef SIP_RUN
48
53class LayerRenderJob
54{
55 public:
56
57 LayerRenderJob() = default;
58
60 LayerRenderJob( const LayerRenderJob & ) = delete;
61
63 LayerRenderJob &operator=( const LayerRenderJob & ) = delete;
64
65 LayerRenderJob( LayerRenderJob && );
66 LayerRenderJob &operator=( LayerRenderJob && );
67
74 void setContext( std::unique_ptr< QgsRenderContext > context ) { mContext = std::move( context ); }
75
81 QgsRenderContext *context() { return mContext.get(); }
82
88 QImage *img = nullptr;
89
97 QgsElevationMap *elevationMap = nullptr;
98
106 QImage *previewRenderImage = nullptr;
107
109 bool imageInitialized = false;
110
116 bool previewRenderImageInitialized = false;
117
118 bool imageCanBeComposed() const;
119
120 QgsMapLayerRenderer *renderer = nullptr; // must be deleted
121
122 QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
123
124 double opacity = 1.0;
125
127 bool cached = false;
128
130 bool renderAboveLabels = false;
131
133
140 bool completed = false;
141
143 int renderingTime = -1;
144
154 int estimatedRenderingTime = 0;
155
156 QStringList errors;
157
166 QString layerId;
167
184 std::unique_ptr<QPainter> maskPainter;
185
186
188 std::unique_ptr<QPaintDevice> maskPaintDevice;
189
194 bool maskRequiresLayerRasterization = false;
195
200 LayerRenderJob *firstPassJob = nullptr;
201
205 std::unique_ptr<QPicture> picture;
206
213 QList<QPair<LayerRenderJob *, int>> maskJobs;
214
215 private:
216 std::unique_ptr< QgsRenderContext > mContext;
217
218};
219
224struct LabelRenderJob
225{
226 QgsRenderContext context;
227
232 QImage *img = nullptr;
233
235 std::unique_ptr<QPicture> picture;
236
238 std::vector< std::unique_ptr<QPainter> > maskPainters;
239
250 std::vector< std::unique_ptr<QPaintDevice> > maskPaintDevices;
251
256 QgsMaskIdProvider maskIdProvider;
257
259 bool cached = false;
261 bool canUseCache = false;
263 bool complete = false;
265 int renderingTime = -1;
267 QList< QPointer< QgsMapLayer > > participatingLayers;
268};
269
271#endif
272
299class CORE_EXPORT QgsMapRendererJob : public QObject SIP_ABSTRACT
300{
301 Q_OBJECT
302 public:
303
305
307
312 void start();
313
318 virtual void cancel() = 0;
319
325 virtual void cancelWithoutBlocking() = 0;
326
328 virtual void waitForFinished() = 0;
329
331 virtual bool isActive() const = 0;
332
339 virtual bool usedCachedLabels() const = 0;
340
349 QStringList layersRedrawnFromCache() const;
350
357
366
373 void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
374
379 const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
380
381 struct Error
382 {
383 Error( const QString &lid, const QString &msg )
384 : layerID( lid )
385 , message( msg )
386 {}
387
388 QString layerID;
389 QString message;
390 };
391
392 typedef QList<QgsMapRendererJob::Error> Errors;
393
395 Errors errors() const;
396
397
403
409 QgsLabelSink *labelSink() const { return mLabelSink; } SIP_SKIP
410
418 void setLabelSink( QgsLabelSink *sink ) { mLabelSink = sink; } SIP_SKIP
419
429
434 int renderingTime() const { return mRenderingTime; }
435
440 QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
441
454 void setLayerRenderingTimeHints( const QHash< QString, int > &hints ) SIP_SKIP;
455
460 const QgsMapSettings &mapSettings() const;
461
466 static const QString LABEL_CACHE_ID SIP_SKIP;
467
473 static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP;
474
480 static const QString ELEVATION_MAP_CACHE_PREFIX SIP_SKIP;
481
482#ifndef SIP_RUN
485
492#endif
493
494 signals:
495
503
504
512 void layerRenderingStarted( const QString &layerId );
513
521 void layerRendered( const QString &layerId );
522
524 void finished();
525
526 protected:
527
529 QElapsedTimer mRenderingStart;
531
532 QgsMapRendererCache *mCache = nullptr;
533
534 int mRenderingTime = 0;
535
537 QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
538
544 QHash< QString, int > mLayerRenderingTimeHints;
545
549 bool mRecordRenderingTime = true;
550
551#ifndef SIP_RUN
552 std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults;
553#endif
554
556
563
575 std::vector< LayerRenderJob > prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
576
581 LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
582
591 std::vector< LayerRenderJob > prepareSecondPassJobs( std::vector< LayerRenderJob > &firstPassJobs, LabelRenderJob &labelJob ) SIP_SKIP;
592
597 void initSecondPassJobs( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob ) const SIP_SKIP;
598
600 static QImage composeImage( const QgsMapSettings &settings,
601 const std::vector< LayerRenderJob > &jobs,
602 const LabelRenderJob &labelJob,
603 const QgsMapRendererCache *cache = nullptr ) SIP_SKIP;
604
606 static QImage layerImageToBeComposed( const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache ) SIP_SKIP;
607
609 static QgsElevationMap layerElevationToBeComposed( const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache ) SIP_SKIP;
610
617 static void composeSecondPass( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob, bool forceVector = false ) SIP_SKIP;
618
620 void logRenderingTime( const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob ) SIP_SKIP;
621
623 void cleanupJobs( std::vector< LayerRenderJob > &jobs ) SIP_SKIP;
624
626 void cleanupSecondPassJobs( std::vector< LayerRenderJob > &jobs ) SIP_SKIP;
627
633 void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
634
639 Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
640
642 static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
643
644 private:
645
657 static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
658
659 const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
660
662 QImage *allocateImage( QString layerId );
663
665 QgsElevationMap *allocateElevationMap( QString layerId );
666
668 QPainter *allocateImageAndPainter( QString layerId, QImage *&image, const QgsRenderContext *context );
669
675 virtual void startPrivate() = 0;
676
677 QgsLabelSink *mLabelSink = nullptr;
678 QgsLabelingEngineFeedback *mLabelingEngineFeedback = nullptr;
679
680 typedef std::pair<std::unique_ptr<QPicture>, QPainter * > PictureAndPainter;
681
683 PictureAndPainter allocatePictureAndPainter( const QgsRenderContext *context );
684};
685
686
695{
696 Q_OBJECT
697
698 public:
700
702 virtual QImage renderedImage() = 0;
703
704};
705
706
707#endif // QGSMAPRENDERERJOB_H
Class for doing transforms between two map coordinate systems.
Stores digital elevation model in a raster image which may get updated as a part of map layer renderi...
Abstract interface for use by classes that filter the features or attributes of a layer.
Abstract base class that can be used to intercept rendered labels from a labeling / rendering job.
QgsFeedback subclass for granular reporting of labeling engine progress.
The QgsLabelingEngine class provides map labeling functionality.
Class that stores computed placement from labeling engine.
Base class for utility classes that encapsulate information necessary for rendering of map layers.
Base class for all map layer types.
Definition qgsmaplayer.h:75
This class is responsible for keeping cache of rendered images resulting from a map rendering job.
Abstract base class for map rendering implementations.
virtual void waitForFinished()=0
Block until the job has finished.
void setCache(QgsMapRendererCache *cache)
Assign a cache to be used for reading and storing rendered images of individual layers.
QHash< QgsMapLayer *, int > perLayerRenderingTime() const
Returns the render time (in ms) per layer.
virtual bool usedCachedLabels() const =0
Returns true if the render job was able to use a cached labeling solution.
void setLabelSink(QgsLabelSink *sink)
Assigns the label sink which will take over responsibility for handling labels during the rendering j...
QHash< QString, int > mLayerRenderingTimeHints
Approximate expected layer rendering time per layer, by layer ID.
std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults
Errors errors() const
List of errors that happened during the rendering job - available when the rendering has been finishe...
void layerRendered(const QString &layerId)
Emitted when a layer has completed rendering.
void renderingLayersFinished()
Emitted when the layers are rendered.
QElapsedTimer mRenderingStart
void finished()
emitted when asynchronous rendering is finished (or canceled).
QgsMapSettings mSettings
const QgsFeatureFilterProvider * featureFilterProvider() const
Returns the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
static const QgsSettingsEntryBool * settingsLogCanvasRefreshEvent
Settings entry log canvas refresh event.
QgsMapRendererJob(const QgsMapSettings &settings)
~QgsMapRendererJob() override
void start()
Start the rendering job and immediately return.
void layerRenderingStarted(const QString &layerId)
Emitted just before rendering starts for a particular layer.
QStringList mLayersRedrawnFromCache
QStringList layersRedrawnFromCache() const
Returns a list of the layer IDs for all layers which were redrawn from cached images.
QList< QgsMapRendererJob::Error > Errors
QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime
Render time (in ms) per layer, by layer ID.
QgsRenderedItemResults * takeRenderedItemResults()
Takes the rendered item results from the map render job and returns them.
virtual bool isActive() const =0
Tell whether the rendering job is currently running in background.
QgsLabelingEngineFeedback * labelingEngineFeedback()
Returns the associated labeling engine feedback object.
virtual QgsLabelingResults * takeLabelingResults()=0
Gets pointer to internal labeling engine (in order to get access to the results).
virtual void cancel()=0
Stop the rendering job - does not return until the job has terminated.
static const QgsSettingsEntryString * settingsMaskBackend
Settings entry for mask painting backend engine.
virtual void cancelWithoutBlocking()=0
Triggers cancellation of the rendering job without blocking.
QgsLabelSink * labelSink() const
Returns the label sink associated to this rendering job.
bool prepareLabelCache() const
Prepares the cache for storing the result of labeling.
Intermediate base class adding functionality that allows client to query the rendered image.
QgsMapRendererQImageJob(const QgsMapSettings &settings)
virtual QImage renderedImage()=0
Gets a preview/resulting image.
The QgsMapSettings class contains configuration for rendering of the map.
This class allows the creation of mask ids based on the different label layers and to give a mask id ...
A rectangle specified with double values.
Contains information about the context of a rendering operation.
Stores collated details of rendered items during a map rendering operation.
A boolean settings entry.
A string settings entry.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_ABSTRACT
Definition qgis_sip.h:213
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Error(const QString &lid, const QString &msg)