QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsmaprenderertask.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmaprenderertask.h
3 -------------------------
4 begin : Apr 2017
5 copyright : (C) 2017 by Mathieu Pellerin
6 email : nirvn dot asia at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSMAPRENDERERTASK_H
19#define QGSMAPRENDERERTASK_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24#include "qgsannotation.h"
26#include "qgsmapdecoration.h"
28#include "qgsmapsettings.h"
29#include "qgstaskmanager.h"
30
31#include <QPainter>
32#include <QPdfWriter>
33
36
45class CORE_EXPORT QgsMapRendererTask : public QgsTask
46{
47 Q_OBJECT
48
49 public:
50
58
59#ifndef SIP_RUN
60
70 const QString &fileName,
71 const QString &fileFormat = QString( "PNG" ),
72 bool forceRaster = false,
74 );
75#else
76
83 const QString &fileName,
84 const QString &fileFormat = QString( "PNG" ),
85 bool forceRaster = false,
87#endif
88
93 QPainter *p );
94
96
100 void addAnnotations( const QList<QgsAnnotation *> &annotations );
101
105 void addDecorations( const QList<QgsMapDecoration *> &decorations );
106
110 void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
111
115 void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
116
117 void cancel() override;
118
119 signals:
120
125
129 void errorOccurred( int error );
130
131 protected:
132
133 bool run() override;
134 void finished( bool result ) override;
135
136 private:
137
139 void prepare();
140 bool mErrored = false;
141
142 QgsMapSettings mMapSettings;
143
144 QMutex mJobMutex;
145 std::unique_ptr< QgsMapRendererJob > mJob;
146
147 std::unique_ptr< QgsAbstractGeospatialPdfExporter > mGeospatialPdfExporter;
148 std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
149
150 QPainter *mPainter = nullptr;
151 QPainter *mDestPainter = nullptr;
152 QImage mImage;
153 std::unique_ptr< QPdfWriter > mPdfWriter;
154
155 std::unique_ptr< QPainter > mTempPainter;
156
157 QString mFileName;
158 QString mFileFormat;
159 bool mForceRaster = false;
160 bool mSaveWorldFile = false;
161 bool mExportMetadata = false;
162 bool mGeospatialPDF = false;
163 QgsAbstractGeospatialPdfExporter::ExportDetails mGeospatialPdfExportDetails;
164
165 QList< QgsAnnotation * > mAnnotations;
166 QList< QgsMapDecoration * > mDecorations;
167 QMap< QString, QString> mLayerIdToLayerNameMap;
168 QStringList mMapLayerOrder;
169
170 int mError = 0;
171
172
173};
174
175// clazy:excludeall=qstring-allocations
176
177#endif
Abstract base class for Geospatial PDF exporters.
Job implementation that renders everything sequentially using a custom painter.
QgsTask task which draws a map to an image file or a painter as a background task.
void addDecorations(const QList< QgsMapDecoration * > &decorations)
Adds decorations to be rendered on the map.
void errorOccurred(int error)
Emitted when map rendering failed.
@ ImageUnsupportedFormat
Format is unsupported on the platform.
@ ImageSaveFail
Image save failure.
@ ImageAllocationFail
Image allocation failure.
void setSaveWorldFile(bool save)
Sets whether the image file will be georeferenced (embedded or via a world file).
void setExportMetadata(bool exportMetadata)
Sets whether metadata such as title and subject will be exported whenever possible.
QgsMapRendererTask(const QgsMapSettings &ms, const QString &fileName, const QString &fileFormat=QString("PNG"), bool forceRaster=false, QgsTask::Flags flags=QgsTask::CanCancel, bool geospatialPdf=false, const QgsAbstractGeospatialPdfExporter::ExportDetails &geospatialPdfExportDetails=QgsAbstractGeospatialPdfExporter::ExportDetails())
Constructor for QgsMapRendererTask to render a map to an image file.
void addAnnotations(const QList< QgsAnnotation * > &annotations)
Adds annotations to be rendered on the map.
~QgsMapRendererTask() override
void renderingComplete()
Emitted when the map rendering is successfully completed.
Contains configuration for rendering maps.
virtual void finished(bool result)
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
virtual bool run()=0
Performs the task's operation.
QFlags< Flag > Flags
virtual void cancel()
Notifies the task that it should terminate.
QgsTask(const QString &description=QString(), QgsTask::Flags flags=AllFlags)
Constructor for QgsTask.
@ CanCancel
Task can be canceled.