QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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_sip.h"
22#include "qgis_core.h"
23#include "qgsannotation.h"
25#include "qgsmapsettings.h"
26#include "qgsmapdecoration.h"
27#include "qgstaskmanager.h"
30
31#include <QPainter>
32#include <QPdfWriter>
33
36
44class CORE_EXPORT QgsMapRendererTask : public QgsTask
45{
46 Q_OBJECT
47
48 public:
49
52 {
53 ImageAllocationFail = 1,
55 ImageUnsupportedFormat
56 };
57
58#ifndef SIP_RUN
59
69 const QString &fileName,
70 const QString &fileFormat = QString( "PNG" ),
71 bool forceRaster = false,
72 QgsTask::Flags flags = QgsTask::CanCancel, bool geoPdf = false, const QgsAbstractGeoPdfExporter::ExportDetails &geoPdfExportDetails = QgsAbstractGeoPdfExporter::ExportDetails()
73 );
74#else
75
82 const QString &fileName,
83 const QString &fileFormat = QString( "PNG" ),
84 bool forceRaster = false,
85 QgsTask::Flags flags = QgsTask::CanCancel );
86#endif
87
92 QPainter *p );
93
95
99 void addAnnotations( const QList<QgsAnnotation *> &annotations );
100
104 void addDecorations( const QList<QgsMapDecoration *> &decorations );
105
109 void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
110
114 void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
115
116 void cancel() override;
117
118 signals:
119
124
128 void errorOccurred( int error );
129
130 protected:
131
132 bool run() override;
133 void finished( bool result ) override;
134
135 private:
136
138 void prepare();
139 bool mErrored = false;
140
141 QgsMapSettings mMapSettings;
142
143 QMutex mJobMutex;
144 std::unique_ptr< QgsMapRendererJob > mJob;
145
146 std::unique_ptr< QgsAbstractGeoPdfExporter > mGeoPdfExporter;
147 std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
148
149 QPainter *mPainter = nullptr;
150 QPainter *mDestPainter = nullptr;
151 QImage mImage;
152 std::unique_ptr< QPdfWriter > mPdfWriter;
153
154 std::unique_ptr< QPainter > mTempPainter;
155
156 QString mFileName;
157 QString mFileFormat;
158 bool mForceRaster = false;
159 bool mSaveWorldFile = false;
160 bool mExportMetadata = false;
161 bool mGeoPDF = false;
162 QgsAbstractGeoPdfExporter::ExportDetails mGeoPdfExportDetails;
163
164 QList< QgsAnnotation * > mAnnotations;
165 QList< QgsMapDecoration * > mDecorations;
166 QMap< QString, QString> mLayerIdToLayerNameMap;
167 QStringList mMapLayerOrder;
168
169 int mError = 0;
170
171
172};
173
174// clazy:excludeall=qstring-allocations
175
176#endif
Abstract base class for GeoPDF 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 errorOccurred(int error)
Emitted when map rendering failed.
@ ImageSaveFail
Image save 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() override
void renderingComplete()
Emitted when the map rendering is successfully completed.
The QgsMapSettings class contains configuration for rendering of the map.
Abstract base class for long running background tasks.
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.
virtual void cancel()
Notifies the task that it should terminate.
@ CanCancel
Task can be canceled.