QGIS API Documentation  3.6.0-Noosa (5873452)
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"
29 
30 #include <QPainter>
32 
40 class CORE_EXPORT QgsMapRendererTask : public QgsTask
41 {
42  Q_OBJECT
43 
44  public:
45 
47  enum ErrorType
48  {
49  ImageAllocationFail = 1,
51  ImageUnsupportedFormat
52  };
53 
58  const QString &fileName,
59  const QString &fileFormat = QString( "PNG" ),
60  bool forceRaster = false );
61 
66  QPainter *p );
67 
71  void addAnnotations( QList< QgsAnnotation * > annotations );
72 
76  void addDecorations( const QList<QgsMapDecoration *> &decorations );
77 
81  void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
82 
83  void cancel() override;
84 
85  signals:
86 
90  void renderingComplete();
91 
95  void errorOccurred( int error );
96 
97  protected:
98 
99  bool run() override;
100  void finished( bool result ) override;
101 
102  private:
103 
104  QgsMapSettings mMapSettings;
105 
106  QMutex mJobMutex;
107  std::unique_ptr< QgsMapRendererCustomPainterJob > mJob;
108 
109  QPainter *mPainter = nullptr;
110 
111  QString mFileName;
112  QString mFileFormat;
113  bool mForceRaster = false;
114  bool mSaveWorldFile = false;
115 
116  QList< QgsAnnotation * > mAnnotations;
117  QList< QgsMapDecoration * > mDecorations;
118 
119  int mError = 0;
120 };
121 
122 // clazy:excludeall=qstring-allocations
123 
124 #endif
Job implementation that renders everything sequentially using a custom painter.
void setSaveWorldFile(bool save)
Sets whether a world file will be created alongside an image file.
QgsTask task which draws a map to an image file or a painter as a background task.
The QgsMapSettings class contains configuration for rendering of the map.
Abstract base class for long running background tasks.
virtual void cancel()
Notifies the task that it should terminate.
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&#39;s operation.