QGIS API Documentation  3.20.0-Odense (decaadbb31)
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"
24 #include "qgsannotationmanager.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 
46 class CORE_EXPORT QgsMapRendererTask : public QgsTask
47 {
48  Q_OBJECT
49 
50  public:
51 
53  enum ErrorType
54  {
55  ImageAllocationFail = 1,
57  ImageUnsupportedFormat
58  };
59 
66 #ifndef SIP_RUN
68  const QString &fileName,
69  const QString &fileFormat = QString( "PNG" ),
70  bool forceRaster = false,
71  bool geoPdf = false, const QgsAbstractGeoPdfExporter::ExportDetails &geoPdfExportDetails = QgsAbstractGeoPdfExporter::ExportDetails() );
72 #else
74  const QString &fileName,
75  const QString &fileFormat = QString( "PNG" ),
76  bool forceRaster = false );
77 #endif
78 
83  QPainter *p );
84 
85  ~QgsMapRendererTask() override;
86 
90  void addAnnotations( const QList<QgsAnnotation *> &annotations );
91 
95  void addDecorations( const QList<QgsMapDecoration *> &decorations );
96 
100  void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
101 
105  void setExportMetadata( bool exportMetadata ) { mExportMetadata = exportMetadata; }
106 
107  void cancel() override;
108 
109  signals:
110 
115 
119  void errorOccurred( int error );
120 
121  protected:
122 
123  bool run() override;
124  void finished( bool result ) override;
125 
126  private:
127 
129  void prepare();
130  bool mErrored = false;
131 
132  QgsMapSettings mMapSettings;
133 
134  QMutex mJobMutex;
135  std::unique_ptr< QgsMapRendererJob > mJob;
136 
137  std::unique_ptr< QgsAbstractGeoPdfExporter > mGeoPdfExporter;
138  std::unique_ptr< QgsRenderedFeatureHandlerInterface > mRenderedFeatureHandler;
139 
140  QPainter *mPainter = nullptr;
141  QPainter *mDestPainter = nullptr;
142  QImage mImage;
143 #ifndef QT_NO_PRINTER
144  std::unique_ptr< QPrinter > mPrinter;
145 #endif // ! QT_NO_PRINTER
146 
147  std::unique_ptr< QPainter > mTempPainter;
148 
149  QString mFileName;
150  QString mFileFormat;
151  bool mForceRaster = false;
152  bool mSaveWorldFile = false;
153  bool mExportMetadata = false;
154  bool mGeoPDF = false;
155  QgsAbstractGeoPdfExporter::ExportDetails mGeoPdfExportDetails;
156 
157  QList< QgsAnnotation * > mAnnotations;
158  QList< QgsMapDecoration * > mDecorations;
159  QMap< QString, QString> mLayerIdToLayerNameMap;
160  QStringList mMapLayerOrder;
161 
162  int mError = 0;
163 
164 
165 };
166 
167 // clazy:excludeall=qstring-allocations
168 
169 #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.