16#ifndef QGSMAPRENDERERJOB_H
17#define QGSMAPRENDERERJOB_H
27#include <QElapsedTimer>
28#include <QFutureWatcher>
57 LayerRenderJob() =
default;
59 LayerRenderJob(
const LayerRenderJob & ) =
delete;
60 LayerRenderJob &operator=(
const LayerRenderJob & ) =
delete;
62 LayerRenderJob( LayerRenderJob && );
63 LayerRenderJob &operator=( LayerRenderJob && );
71 void setContext( std::unique_ptr< QgsRenderContext > context ) { mContext = std::move( context ); }
78 QgsRenderContext *context() {
return mContext.get(); }
85 std::unique_ptr< QImage > destinationImage;
87 std::unique_ptr< QPainter > destinationPainter;
96 std::unique_ptr< QgsElevationMap > elevationMap;
105 std::unique_ptr< QImage > previewRenderImage;
107 std::unique_ptr< QPainter > previewRenderPainter;
110 bool imageInitialized =
false;
117 bool previewRenderImageInitialized =
false;
119 bool imageCanBeComposed()
const;
122 std::unique_ptr< QgsMapLayerRenderer > renderer;
124 QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
126 double opacity = 1.0;
132 bool renderAboveLabels =
false;
142 bool completed =
false;
145 int renderingTime = -1;
156 int estimatedRenderingTime = 0;
186 std::unique_ptr<QPaintDevice> maskPaintDevice;
189 std::unique_ptr<QPainter> maskPainter;
195 bool maskRequiresLayerRasterization =
false;
201 LayerRenderJob *firstPassJob =
nullptr;
206 std::unique_ptr<QPicture> picture;
211 LayerRenderJob *layerRenderJob =
nullptr;
214 int maskPaintDeviceId = -1;
220 std::vector<MaskJob> maskJobs;
223 std::unique_ptr< QgsRenderContext > mContext;
232 QgsRenderContext context;
238 std::unique_ptr< QImage > img;
241 std::unique_ptr<QPicture> picture;
244 std::vector< std::unique_ptr<QPainter> > maskPainters;
256 std::vector< std::unique_ptr<QPaintDevice> > maskPaintDevices;
262 QgsMaskIdProvider maskIdProvider;
267 bool canUseCache =
false;
269 bool complete =
false;
271 int renderingTime = -1;
273 QList< QPointer< QgsMapLayer > > participatingLayers;
397 Error(
const QString &lid,
const QString &msg )
406 typedef QList<QgsMapRendererJob::Error>
Errors;
654 static
void composeSecondPass( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob,
bool forceVector = false )
SIP_SKIP;
657 void logRenderingTime( const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob )
SIP_SKIP;
700 std::unique_ptr< QImage > allocateImage( const QString &layerId );
703 std::unique_ptr<
QgsElevationMap > allocateElevationMap( const QString &layerId );
706 std::tuple< std::unique_ptr< QImage >, std::unique_ptr< QPainter > > allocateImageAndPainter( const QString &layerId, const
QgsRenderContext &context );
713 virtual
void startPrivate() = 0;
719 std::tuple<std::unique_ptr<QPicture>, std::unique_ptr< QPainter > > allocatePictureAndPainter( const
QgsRenderContext &context );
Stores a digital elevation model in a raster image which may get updated as a part of the map layer r...
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.
Provides map labeling functionality.
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.
Responsible for keeping a cache of rendered images resulting from a map rendering job.
void logRenderingTime(const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob)
QList< QPointer< QgsMapLayer > > participatingLabelLayers(QgsLabelingEngine *engine)
Returns a list of the layers participating in the map labeling.
static QgsElevationMap layerElevationToBeComposed(const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache)
virtual void waitForFinished()=0
Block until the job has finished.
static QImage composeImage(const QgsMapSettings &settings, const std::vector< LayerRenderJob > &jobs, const LabelRenderJob &labelJob, const QgsMapRendererCache *cache=nullptr)
void cleanupSecondPassJobs(std::vector< LayerRenderJob > &jobs)
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...
void initSecondPassJobs(std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob) const
Initialize secondPassJobs according to what have been rendered (mask clipping path e....
static QImage layerImageToBeComposed(const QgsMapSettings &settings, const LayerRenderJob &job, const QgsMapRendererCache *cache)
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...
static Q_DECL_DEPRECATED void drawLabeling(const QgsMapSettings &settings, QgsRenderContext &renderContext, QgsLabelingEngine *labelingEngine2, QPainter *painter)
void layerRendered(const QString &layerId)
Emitted when a layer has completed rendering.
static const QString LABEL_PREVIEW_CACHE_ID
QgsMapRendererCache ID string for cached label image during preview compositions only.
QList< QPointer< QgsMapLayer > > mAdditionalLabelLayers
Additional layers participating in labeling problem.
std::vector< LayerRenderJob > prepareJobs(QPainter *painter, QgsLabelingEngine *labelingEngine2, bool deferredPainterSet=false)
Creates a list of layer rendering jobs and prepares them for later render.
void renderingLayersFinished()
Emitted when the layers are rendered.
void cleanupJobs(std::vector< LayerRenderJob > &jobs)
QElapsedTimer mRenderingStart
const QgsMapSettings & mapSettings() const
Returns map settings with which this job was started.
QgsMapRendererCache * mCache
void setPerLayerTemporalRange(QHash< QgsMapLayer *, QgsDateTimeRange > perLayerTemporalRange)
Set a temporal range used by the QgsRenderContext of each LayerRenderJob If set this temporal range o...
void finished()
emitted when asynchronous rendering is finished (or canceled).
bool labelingHasNonDefaultCompositionModes() const
Returns true if any component of the map labeling requires non-default composition modes.
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.
bool mRecordRenderingTime
true if layer rendering time should be recorded.
int renderingTime() const
Returns the total time it took to finish the job (in milliseconds).
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
static const QString LABEL_CACHE_ID
QgsMapRendererCache ID string for cached label image.
static const QString ELEVATION_MAP_CACHE_PREFIX
QgsMapRendererCache prefix string for cached elevation map image.
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.
static void composeSecondPass(std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob, bool forceVector=false)
Compose second pass images into first pass images.
virtual QgsLabelingResults * takeLabelingResults()=0
Gets pointer to internal labeling engine (in order to get access to the results).
void setFeatureFilterProvider(const QgsFeatureFilterProvider *f)
Set the feature filter provider used by the QgsRenderContext of each LayerRenderJob.
virtual void cancel()=0
Stop the rendering job - does not return until the job has terminated.
std::vector< LayerRenderJob > prepareSecondPassJobs(std::vector< LayerRenderJob > &firstPassJobs, LabelRenderJob &labelJob)
Prepares jobs for a second pass, if selective masks exist (from labels or symbol layers).
static const QgsSettingsEntryString * settingsMaskBackend
Settings entry for mask painting backend engine.
LabelRenderJob prepareLabelingJob(QPainter *painter, QgsLabelingEngine *labelingEngine2, bool canUseLabelCache=true)
Prepares a labeling job.
void setLayerRenderingTimeHints(const QHash< QString, int > &hints)
Sets approximate render times (in ms) for map layers.
void cleanupLabelJob(LabelRenderJob &job)
Handles clean up tasks for a label job, including deletion of images and storing cached label results...
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.
QgsMapRendererQImageJob(const QgsMapSettings &settings)
virtual QImage renderedImage()=0
Gets a preview/resulting image.
Contains configuration for rendering maps.
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.
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Error(const QString &lid, const QString &msg)