QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
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 
96  ~QgsMapRendererTask() override;
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 
125  void renderingComplete();
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
QgsMapRendererTask::setExportMetadata
void setExportMetadata(bool exportMetadata)
Sets whether metadata such as title and subject will be exported whenever possible.
Definition: qgsmaprenderertask.h:116
qgsannotation.h
qgstaskmanager.h
qgsmaprenderercustompainterjob.h
QgsAbstractGeoPdfExporter::ExportDetails
Definition: qgsabstractgeopdfexporter.h:198
qgsmapsettings.h
QgsTask::finished
virtual void finished(bool result)
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
Definition: qgstaskmanager.h:284
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
QgsTask::CanCancel
@ CanCancel
Task can be canceled.
Definition: qgstaskmanager.h:74
QgsMapRendererTask::ErrorType
ErrorType
Error type.
Definition: qgsmaprenderertask.h:53
qgsmapdecoration.h
qgis_sip.h
qgsannotationmanager.h
QgsMapRendererCustomPainterJob
Job implementation that renders everything sequentially using a custom painter.
Definition: qgsmaprenderercustompainterjob.h:63
qgsabstractgeopdfexporter.h
QgsMapRendererTask::ImageSaveFail
@ ImageSaveFail
Image save failure.
Definition: qgsmaprenderertask.h:56
QgsMapRendererTask
QgsTask task which draws a map to an image file or a painter as a background task....
Definition: qgsmaprenderertask.h:46
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsTask::run
virtual bool run()=0
Performs the task's operation.
QgsAbstractGeoPdfExporter
Abstract base class for GeoPDF exporters.
Definition: qgsabstractgeopdfexporter.h:55
QgsMapRendererTask::setSaveWorldFile
void setSaveWorldFile(bool save)
Sets whether the image file will be georeferenced (embedded or via a world file).
Definition: qgsmaprenderertask.h:111
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:54