QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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
59 LayerRenderJob( const LayerRenderJob & ) = delete;
60 LayerRenderJob &operator=( const LayerRenderJob & ) = delete;
61
62 LayerRenderJob( LayerRenderJob && );
63 LayerRenderJob &operator=( LayerRenderJob && );
64
71 void setContext( std::unique_ptr< QgsRenderContext > context ) { mContext = std::move( context ); }
72
78 QgsRenderContext *context() { return mContext.get(); }
79
85 QImage *img = nullptr;
86
94 QgsElevationMap *elevationMap = nullptr;
95
103 QImage *previewRenderImage = nullptr;
104
106 bool imageInitialized = false;
107
113 bool previewRenderImageInitialized = false;
114
115 bool imageCanBeComposed() const;
116
117 QgsMapLayerRenderer *renderer = nullptr; // must be deleted
118
119 QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
120
121 double opacity = 1.0;
122
124 bool cached = false;
125
127 bool renderAboveLabels = false;
128
130
137 bool completed = false;
138
140 int renderingTime = -1;
141
151 int estimatedRenderingTime = 0;
152
153 QStringList errors;
154
163 QString layerId;
164
181 std::unique_ptr<QPainter> maskPainter;
182
183
185 std::unique_ptr<QPaintDevice> maskPaintDevice;
186
191 bool maskRequiresLayerRasterization = false;
192
197 LayerRenderJob *firstPassJob = nullptr;
198
202 std::unique_ptr<QPicture> picture;
203
210 QList<QPair<LayerRenderJob *, int>> maskJobs;
211
212 private:
213 std::unique_ptr< QgsRenderContext > mContext;
214
215};
216
221struct LabelRenderJob
222{
223 QgsRenderContext context;
224
229 QImage *img = nullptr;
230
232 std::unique_ptr<QPicture> picture;
233
235 std::vector< std::unique_ptr<QPainter> > maskPainters;
236
247 std::vector< std::unique_ptr<QPaintDevice> > maskPaintDevices;
248
253 QgsMaskIdProvider maskIdProvider;
254
256 bool cached = false;
258 bool canUseCache = false;
260 bool complete = false;
262 int renderingTime = -1;
264 QList< QPointer< QgsMapLayer > > participatingLayers;
265};
266
268#endif
269
296class CORE_EXPORT QgsMapRendererJob : public QObject SIP_ABSTRACT
297{
298 Q_OBJECT
299 public:
300
302
304
309 void start();
310
315 virtual void cancel() = 0;
316
322 virtual void cancelWithoutBlocking() = 0;
323
325 virtual void waitForFinished() = 0;
326
328 virtual bool isActive() const = 0;
329
336 virtual bool usedCachedLabels() const = 0;
337
346 QStringList layersRedrawnFromCache() const;
347
354
363
370 void setFeatureFilterProvider( const QgsFeatureFilterProvider *f ) { mFeatureFilterProvider = f; }
371
376 const QgsFeatureFilterProvider *featureFilterProvider() const { return mFeatureFilterProvider; }
377
378 struct Error
379 {
380 Error( const QString &lid, const QString &msg )
381 : layerID( lid )
382 , message( msg )
383 {}
384
385 QString layerID;
386 QString message;
387 };
388
389 typedef QList<QgsMapRendererJob::Error> Errors;
390
392 Errors errors() const;
393
394
400
406 QgsLabelSink *labelSink() const { return mLabelSink; } SIP_SKIP
407
415 void setLabelSink( QgsLabelSink *sink ) { mLabelSink = sink; } SIP_SKIP
416
426
431 int renderingTime() const { return mRenderingTime; }
432
437 QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;
438
451 void setLayerRenderingTimeHints( const QHash< QString, int > &hints ) SIP_SKIP;
452
457 const QgsMapSettings &mapSettings() const;
458
463 static const QString LABEL_CACHE_ID SIP_SKIP;
464
470 static const QString LABEL_PREVIEW_CACHE_ID SIP_SKIP;
471
477 static const QString ELEVATION_MAP_CACHE_PREFIX SIP_SKIP;
478
479#ifndef SIP_RUN
482
489#endif
490
491 signals:
492
500
501
509 void layerRenderingStarted( const QString &layerId );
510
518 void layerRendered( const QString &layerId );
519
521 void finished();
522
523 protected:
524
526 QElapsedTimer mRenderingStart;
528
529 QgsMapRendererCache *mCache = nullptr;
530
531 int mRenderingTime = 0;
532
534 QHash< QgsWeakMapLayerPointer, int > mPerLayerRenderingTime;
535
541 QHash< QString, int > mLayerRenderingTimeHints;
542
546 QList< QPointer< QgsMapLayer > > mAdditionalLabelLayers;
547
551 bool mRecordRenderingTime = true;
552
553#ifndef SIP_RUN
554 std::unique_ptr< QgsRenderedItemResults > mRenderedItemResults;
555#endif
556
558
565
577 std::vector< LayerRenderJob > prepareJobs( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet = false ) SIP_SKIP;
578
583 LabelRenderJob prepareLabelingJob( QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache = true ) SIP_SKIP;
584
593 std::vector< LayerRenderJob > prepareSecondPassJobs( std::vector< LayerRenderJob > &firstPassJobs, LabelRenderJob &labelJob ) SIP_SKIP;
594
602 QList< QPointer< QgsMapLayer > > participatingLabelLayers( QgsLabelingEngine *engine ) SIP_SKIP;
603
608 void initSecondPassJobs( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob ) const SIP_SKIP;
609
611 static QImage composeImage( const QgsMapSettings &settings,
612 const std::vector< LayerRenderJob > &jobs,
613 const LabelRenderJob &labelJob,
614 const QgsMapRendererCache *cache = nullptr ) SIP_SKIP;
615
617 static QImage layerImageToBeComposed( const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache ) SIP_SKIP;
618
620 static QgsElevationMap layerElevationToBeComposed( const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache ) SIP_SKIP;
621
628 static void composeSecondPass( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob, bool forceVector = false ) SIP_SKIP;
629
631 void logRenderingTime( const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob ) SIP_SKIP;
632
634 void cleanupJobs( std::vector< LayerRenderJob > &jobs ) SIP_SKIP;
635
637 void cleanupSecondPassJobs( std::vector< LayerRenderJob > &jobs ) SIP_SKIP;
638
644 void cleanupLabelJob( LabelRenderJob &job ) SIP_SKIP;
645
650 Q_DECL_DEPRECATED static void drawLabeling( const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
651
653 static void drawLabeling( QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter ) SIP_SKIP;
654
655 private:
656
668 static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
669
670 const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
671
673 QImage *allocateImage( QString layerId );
674
676 QgsElevationMap *allocateElevationMap( QString layerId );
677
679 QPainter *allocateImageAndPainter( QString layerId, QImage *&image, const QgsRenderContext *context );
680
686 virtual void startPrivate() = 0;
687
688 QgsLabelSink *mLabelSink = nullptr;
689 QgsLabelingEngineFeedback *mLabelingEngineFeedback = nullptr;
690
691 typedef std::pair<std::unique_ptr<QPicture>, QPainter * > PictureAndPainter;
692
694 PictureAndPainter allocatePictureAndPainter( const QgsRenderContext *context );
695};
696
697
706{
707 Q_OBJECT
708
709 public:
711
713 virtual QImage renderedImage() = 0;
714
715};
716
717
718#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:76
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.
QList< QPointer< QgsMapLayer > > mAdditionalLabelLayers
Additional layers participating in labeling problem.
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)