QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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.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, // Image allocation failure
50  ImageSaveFail // Image save failure
51  };
52 
57  const QString &fileName,
58  const QString &fileFormat = QString( "PNG" ),
59  bool forceRaster = false );
60 
65  QPainter *p );
66 
70  void addAnnotations( QList< QgsAnnotation * > annotations );
71 
75  void addDecorations( const QList<QgsMapDecoration *> &decorations );
76 
80  void setSaveWorldFile( bool save ) { mSaveWorldFile = save; }
81 
82  void cancel() override;
83 
84  signals:
85 
89  void renderingComplete();
90 
94  void errorOccurred( int error );
95 
96  protected:
97 
98  bool run() override;
99  void finished( bool result ) override;
100 
101  private:
102 
103  QgsMapSettings mMapSettings;
104 
105  QMutex mJobMutex;
106  std::unique_ptr< QgsMapRendererCustomPainterJob > mJob;
107 
108  QPainter *mPainter = nullptr;
109 
110  QString mFileName;
111  QString mFileFormat;
112  bool mForceRaster = false;
113  bool mSaveWorldFile = false;
114 
115  QList< QgsAnnotation * > mAnnotations;
116  QList< QgsMapDecoration * > mDecorations;
117 
118  int mError = 0;
119 };
120 
121 // clazy:excludeall=qstring-allocations
122 
123 #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.