16#ifndef QGSMAPRENDERERJOB_H
17#define QGSMAPRENDERERJOB_H
26#include <QElapsedTimer>
27#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 QImage *img =
nullptr;
94 QgsElevationMap *elevationMap =
nullptr;
103 QImage *previewRenderImage =
nullptr;
106 bool imageInitialized =
false;
113 bool previewRenderImageInitialized =
false;
115 bool imageCanBeComposed()
const;
117 QgsMapLayerRenderer *renderer =
nullptr;
119 QPainter::CompositionMode blendMode = QPainter::CompositionMode_SourceOver;
121 double opacity = 1.0;
127 bool renderAboveLabels =
false;
137 bool completed =
false;
140 int renderingTime = -1;
151 int estimatedRenderingTime = 0;
181 std::unique_ptr<QPainter> maskPainter;
185 std::unique_ptr<QPaintDevice> maskPaintDevice;
191 bool maskRequiresLayerRasterization =
false;
197 LayerRenderJob *firstPassJob =
nullptr;
202 std::unique_ptr<QPicture> picture;
210 QList<QPair<LayerRenderJob *, int>> maskJobs;
213 std::unique_ptr< QgsRenderContext > mContext;
223 QgsRenderContext context;
229 QImage *img =
nullptr;
232 std::unique_ptr<QPicture> picture;
235 std::vector< std::unique_ptr<QPainter> > maskPainters;
247 std::vector< std::unique_ptr<QPaintDevice> > maskPaintDevices;
253 QgsMaskIdProvider maskIdProvider;
258 bool canUseCache =
false;
260 bool complete =
false;
262 int renderingTime = -1;
264 QList< QPointer< QgsMapLayer > > participatingLayers;
380 Error(
const QString &lid,
const QString &msg )
389 typedef QList<QgsMapRendererJob::Error>
Errors;
625 const std::vector< LayerRenderJob > &jobs,
626 const LabelRenderJob &labelJob,
641 static
void composeSecondPass( std::vector< LayerRenderJob > &secondPassJobs, LabelRenderJob &labelJob,
bool forceVector = false )
SIP_SKIP;
644 void logRenderingTime( const std::vector< LayerRenderJob > &jobs, const std::vector< LayerRenderJob > &secondPassJobs, const LabelRenderJob &labelJob )
SIP_SKIP;
686 QImage *allocateImage( QString layerId );
692 QPainter *allocateImageAndPainter( QString layerId, QImage *&image, const
QgsRenderContext *context );
699 virtual
void startPrivate() = 0;
704 typedef std::pair<std::unique_ptr<QPicture>, QPainter * > PictureAndPainter;
707 PictureAndPainter 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 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.
Error(const QString &lid, const QString &msg)