QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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;
44
45#ifndef SIP_RUN
47
52class LayerRenderJob
53{
54 public:
55
56 LayerRenderJob() = default;
57
59 LayerRenderJob( const LayerRenderJob & ) = delete;
60
62 LayerRenderJob &operator=( const LayerRenderJob & ) = delete;
63
64 LayerRenderJob( LayerRenderJob && );
65 LayerRenderJob &operator=( LayerRenderJob && );
66
73 void setContext( std::unique_ptr< QgsRenderContext > context ) { mContext = std::move( context ); }
74
80 QgsRenderContext *context() { return mContext.get(); }
81
87 QImage *img = nullptr;
88
96 QgsElevationMap *elevationMap = nullptr;
97
105 QImage *previewRenderImage = nullptr;
106
108 bool imageInitialized = false;
109
115 bool previewRenderImageInitialized = false;
116
117 bool imageCanBeComposed() const;
118
119 QgsMapLayerRenderer *renderer = nullptr; // must be deleted
120
121 QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
122
123 double opacity = 1.0;
124
126 bool cached = false;
127
129 bool renderAboveLabels = false;
130
132
139 bool completed = false;
140
142 int renderingTime = -1;
143
153 int estimatedRenderingTime = 0;
154
155 QStringList errors;
156
165 QString layerId;
166
183 std::unique_ptr<QPainter> maskPainter;
184
185
187 std::unique_ptr<QPaintDevice> maskPaintDevice;
188
193 bool maskRequiresLayerRasterization = false;
194
199 LayerRenderJob *firstPassJob = nullptr;
200
204 std::unique_ptr<QPicture> picture;
205
212 QList<QPair<LayerRenderJob *, int>> maskJobs;
213
214 private:
215 std::unique_ptr< QgsRenderContext > mContext;
216
217};
218
223struct LabelRenderJob
224{
225 QgsRenderContext context;
226
231 QImage *img = nullptr;
232
234 std::unique_ptr<QPicture> picture;
235
237 std::vector< std::unique_ptr<QPainter> > maskPainters;
238
249 std::vector< std::unique_ptr<QPaintDevice> > maskPaintDevices;
250
255 QgsMaskIdProvider maskIdProvider;
256
258 bool cached = false;
260 bool canUseCache = false;
262 bool complete = false;
264 int renderingTime = -1;
266 QList< QPointer< QgsMapLayer > > participatingLayers;
267};
268
270#endif
271
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
340 virtual bool usedCachedLabels() const = 0;
341
350 QStringList layersRedrawnFromCache() const;
351
358
367
375 void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
376
382 const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
383
384 struct Error
385 {
386 Error( const QString &lid, const QString &msg )
387 : layerID( lid )
388 , message( msg )
389 {}
390
391 QString layerID;
392 QString message;
393 };
394
395 typedef QList<QgsMapRendererJob::Error> Errors;
396
398 Errors errors() const;
399
400
406
412 QgsLabelSink *labelSink() const { return mLabelSink; } SIP_SKIP
413
421 void setLabelSink( QgsLabelSink *sink ) { mLabelSink = sink; } SIP_SKIP
422
432
437 int renderingTime() const { return mRenderingTime; }
438
444 QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
445
458 void setLayerRenderingTimeHints( const QHash< QString, int > &hints ) SIP_SKIP;
459
465 const QgsMapSettings &mapSettings() const;
466
471 static const QString LABEL_CACHE_ID SIP_SKIP;
472
478 static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP;
479
485 static const QString ELEVATION_MAP_CACHE_PREFIX SIP_SKIP;
486
487#ifndef SIP_RUN
490#endif
491
492 signals:
493
502
503
511 void layerRenderingStarted( const QString &layerId );
512
520 void layerRendered( const QString &layerId );
521
523 void finished();
524
525 protected:
526
528 QElapsedTimer mRenderingStart;
530
531 QgsMapRendererCache *mCache = nullptr;
532
533 int mRenderingTime = 0;
534
536 QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
537
543 QHash< QString, int > mLayerRenderingTimeHints;
544
548 bool mRecordRenderingTime = true;
549
550#ifndef SIP_RUN
551 std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults;
552#endif
553
555
562
574 std::vector< LayerRenderJob > prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
575
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
634 void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
635
640 Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
641
643 static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
644
645 private:
646
658 static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
659
660 const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
661
663 QImage *allocateImage( QString layerId );
664
666 QgsElevationMap *allocateElevationMap( QString layerId );
667
669 QPainter *allocateImageAndPainter( QString layerId, QImage *&image, const QgsRenderContext *context );
670
676 virtual void startPrivate() = 0;
677
678 QgsLabelSink *mLabelSink = nullptr;
679 QgsLabelingEngineFeedback *mLabelingEngineFeedback = nullptr;
680
681 typedef std::pair<std::unique_ptr<QPicture>, QPainter * > PictureAndPainter;
682
684 PictureAndPainter allocatePictureAndPainter( const QgsRenderContext *context );
685};
686
687
697{
698 Q_OBJECT
699
700 public:
702
704 virtual QImage renderedImage() = 0;
705
706};
707
708
709#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:74
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.
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.
#define SIP_SKIP
Definition qgis_sip.h:126
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_ABSTRACT
Definition qgis_sip.h:208
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Error(const QString &lid, const QString &msg)