QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
57
58#ifndef SIP_RUN
59
69 const QgsMapSettings &ms,
70 const QString &fileName,
71 const QString &fileFormat = QString( "PNG" ),
72 bool forceRaster = false,
74 bool geospatialPdf = false,
76 );
77#else
78
84 QgsMapRendererTask( const QgsMapSettings &ms, const QString &fileName, const QString &fileFormat = QString( "PNG" ), bool forceRaster = false, QgsTask::Flags flags = QgsTask::CanCancel );
85#endif
86
90 QgsMapRendererTask( const QgsMapSettings &ms, QPainter *p );
91
93
97 void addAnnotations( const QList<QgsAnnotation *> &annotations );
98
102 void addDecorations( const QList<QgsMapDecoration *> &decorations );
103
107 void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
108
112 void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
113
114 void cancel() override;
115
116 signals:
117
122
126 void errorOccurred( int error );
127
128 protected:
129 bool run() override;
130 void finished( bool result ) override;
131
132 private:
134 void prepare();
135 bool mErrored = false;
136
137 QgsMapSettings mMapSettings;
138
139 QMutex mJobMutex;
140 std::unique_ptr< QgsMapRendererJob > mJob;
141
142 std::unique_ptr< QgsAbstractGeospatialPdfExporter > mGeospatialPdfExporter;
143 std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
144
145 QPainter *mPainter = nullptr;
146 QPainter *mDestPainter = nullptr;
147 QImage mImage;
148 std::unique_ptr< QPdfWriter > mPdfWriter;
149
150 std::unique_ptr< QPainter > mTempPainter;
151
152 QString mFileName;
153 QString mFileFormat;
154 bool mForceRaster = false;
155 bool mSaveWorldFile = false;
156 bool mExportMetadata = false;
157 bool mGeospatialPDF = false;
158 QgsAbstractGeospatialPdfExporter::ExportDetails mGeospatialPdfExportDetails;
159
160 QList< QgsAnnotation * > mAnnotations;
161 QList< QgsMapDecoration * > mDecorations;
162 QMap< QString, QString> mLayerIdToLayerNameMap;
163 QStringList mMapLayerOrder;
164
165 int mError = 0;
166};
167
168// clazy:excludeall=qstring-allocations
169
170#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.