QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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#ifndef QT_NO_PRINTER
33#include <QPrinter>
34#endif
35
38
46class CORE_EXPORT QgsMapRendererTask : public QgsTask
47{
48 Q_OBJECT
49
50 public:
51
54 {
55 ImageAllocationFail = 1,
57 ImageUnsupportedFormat
58 };
59
60#ifndef SIP_RUN
61
71 const QString &fileName,
72 const QString &fileFormat = QString( "PNG" ),
73 bool forceRaster = false,
74 QgsTask::Flags flags = QgsTask::CanCancel, bool geoPdf = false, const QgsAbstractGeoPdfExporter::ExportDetails &geoPdfExportDetails = QgsAbstractGeoPdfExporter::ExportDetails()
75 );
76#else
77
84 const QString &fileName,
85 const QString &fileFormat = QString( "PNG" ),
86 bool forceRaster = false,
87 QgsTask::Flags flags = QgsTask::CanCancel );
88#endif
89
94 QPainter *p );
95
97
101 void addAnnotations( const QList<QgsAnnotation *> &annotations );
102
106 void addDecorations( const QList<QgsMapDecoration *> &decorations );
107
111 void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
112
116 void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
117
118 void cancel() override;
119
120 signals:
121
126
130 void errorOccurred( int error );
131
132 protected:
133
134 bool run() override;
135 void finished( bool result ) override;
136
137 private:
138
140 void prepare();
141 bool mErrored = false;
142
143 QgsMapSettings mMapSettings;
144
145 QMutex mJobMutex;
146 std::unique_ptr< QgsMapRendererJob > mJob;
147
148 std::unique_ptr< QgsAbstractGeoPdfExporter > mGeoPdfExporter;
149 std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
150
151 QPainter *mPainter = nullptr;
152 QPainter *mDestPainter = nullptr;
153 QImage mImage;
154#ifndef QT_NO_PRINTER
155 std::unique_ptr< QPrinter > mPrinter;
156#endif // ! QT_NO_PRINTER
157
158 std::unique_ptr< QPainter > mTempPainter;
159
160 QString mFileName;
161 QString mFileFormat;
162 bool mForceRaster = false;
163 bool mSaveWorldFile = false;
164 bool mExportMetadata = false;
165 bool mGeoPDF = false;
166 QgsAbstractGeoPdfExporter::ExportDetails mGeoPdfExportDetails;
167
168 QList< QgsAnnotation * > mAnnotations;
169 QList< QgsMapDecoration * > mDecorations;
170 QMap< QString, QString> mLayerIdToLayerNameMap;
171 QStringList mMapLayerOrder;
172
173 int mError = 0;
174
175
176};
177
178// clazy:excludeall=qstring-allocations
179
180#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.