QGIS API Documentation 3.41.0-Master (3440c17df1d)
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_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
43class CORE_EXPORT QgsMapRendererTask : public QgsTask
44{
45 Q_OBJECT
46
47 public:
48
51 {
52 ImageAllocationFail = 1,
54 ImageUnsupportedFormat
55 };
56
57#ifndef SIP_RUN
58
68 const QString &fileName,
69 const QString &fileFormat = QString( "PNG" ),
70 bool forceRaster = false,
72 );
73#else
74
81 const QString &fileName,
82 const QString &fileFormat = QString( "PNG" ),
83 bool forceRaster = false,
85#endif
86
91 QPainter *p );
92
94
98 void addAnnotations( const QList<QgsAnnotation *> &annotations );
99
103 void addDecorations( const QList<QgsMapDecoration *> &decorations );
104
108 void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
109
113 void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
114
115 void cancel() override;
116
117 signals:
118
123
127 void errorOccurred( int error );
128
129 protected:
130
131 bool run() override;
132 void finished( bool result ) override;
133
134 private:
135
137 void prepare();
138 bool mErrored = false;
139
140 QgsMapSettings mMapSettings;
141
142 QMutex mJobMutex;
143 std::unique_ptr< QgsMapRendererJob > mJob;
144
145 std::unique_ptr< QgsAbstractGeospatialPdfExporter > mGeospatialPdfExporter;
146 std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
147
148 QPainter *mPainter = nullptr;
149 QPainter *mDestPainter = nullptr;
150 QImage mImage;
151 std::unique_ptr< QPdfWriter > mPdfWriter;
152
153 std::unique_ptr< QPainter > mTempPainter;
154
155 QString mFileName;
156 QString mFileFormat;
157 bool mForceRaster = false;
158 bool mSaveWorldFile = false;
159 bool mExportMetadata = false;
160 bool mGeospatialPDF = false;
161 QgsAbstractGeospatialPdfExporter::ExportDetails mGeospatialPdfExportDetails;
162
163 QList< QgsAnnotation * > mAnnotations;
164 QList< QgsMapDecoration * > mDecorations;
165 QMap< QString, QString> mLayerIdToLayerNameMap;
166 QStringList mMapLayerOrder;
167
168 int mError = 0;
169
170
171};
172
173// clazy:excludeall=qstring-allocations
174
175#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 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.
QFlags< Flag > Flags
virtual void cancel()
Notifies the task that it should terminate.
@ CanCancel
Task can be canceled.