1 /***************************************************************************
2   qgsmaprendererparalleljob.h
3   --------------------------------------
4   Date                 : December 2013
5   Copyright            : (C) 2013 by Martin Dobias
6   Email                : wonder dot sk at gmail dot com
7  ***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPRENDERERPARALLELJOB_H
17 #define QGSMAPRENDERERPARALLELJOB_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgsmaprendererjob.h"
22 
23 /**
24  * \ingroup core
25  * \brief Job implementation that renders all layers in parallel.
26  *
27  * The resulting map image can be retrieved with renderedImage() function.
28  * It is safe to call that function while rendering is active to see preview of the map.
29  *
30  * \since QGIS 2.4
31  */
32 class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
33 {
34     Q_OBJECT
35   public:
36     QgsMapRendererParallelJob( const QgsMapSettings &settings );
37     ~QgsMapRendererParallelJob() override;
38 
39     void start() override;
40     void cancel() override;
41     void cancelWithoutBlocking() override;
42     void waitForFinished() override;
43     bool isActive() const override;
44 
45     bool usedCachedLabels() const override;
46     QgsLabelingResults *takeLabelingResults() SIP_TRANSFER override;
47 
48     // from QgsMapRendererJobWithPreview
49     QImage renderedImage() override;
50 
51   private slots:
52     //! layers are rendered, labeling is still pending
53     void renderLayersFinished();
54     //! the second pass of layer rendering is finished
55     void renderLayersSecondPassFinished();
56     //! all rendering is finished, including labeling
57     void renderingFinished();
58 
59   private:
60 
61     //! \note not available in Python bindings
62     static void renderLayerStatic( LayerRenderJob &job ) SIP_SKIP;
63     //! \note not available in Python bindings
64     static void renderLabelsStatic( QgsMapRendererParallelJob *self ) SIP_SKIP;
65 
66     QImage mFinalImage;
67 
68     //! \note not available in Python bindings
69     enum { Idle, RenderingLayers, RenderingSecondPass, RenderingLabels } mStatus SIP_SKIP;
70 
71     QFuture<void> mFuture;
72     QFutureWatcher<void> mFutureWatcher;
73 
74     LayerRenderJobs mLayerJobs;
75     LabelRenderJob mLabelJob;
76 
77     LayerRenderJobs mSecondPassLayerJobs;
78     QFuture<void> mSecondPassFuture;
79     QFutureWatcher<void> mSecondPassFutureWatcher;
80 
81     //! New labeling engine
82     std::unique_ptr< QgsLabelingEngine > mLabelingEngineV2;
83     QFuture<void> mLabelingFuture;
84     QFutureWatcher<void> mLabelingFutureWatcher;
85 
86 };
87 
88 
89 #endif // QGSMAPRENDERERPARALLELJOB_H
90