Skip to content

Commit

Permalink
Move QgsRendererJob subclasses to new files (no code changes)
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jun 22, 2014
1 parent cfe43c3 commit 436b05e
Show file tree
Hide file tree
Showing 20 changed files with 1,050 additions and 929 deletions.
3 changes: 3 additions & 0 deletions python/core/core.sip
Expand Up @@ -51,7 +51,10 @@
%Include qgsmaplayerrenderer.sip
%Include qgsmaprenderer.sip
%Include qgsmaprenderercache.sip
%Include qgsmaprenderercustompainterjob.sip
%Include qgsmaprendererjob.sip
%Include qgsmaprendererparalleljob.sip
%Include qgsmaprenderersequentialjob.sip
%Include qgsmapsettings.sip
%Include qgsmaptopixel.sip
%Include qgsmapunitscale.sip
Expand Down
57 changes: 57 additions & 0 deletions python/core/qgsmaprenderercustompainterjob.sip
@@ -0,0 +1,57 @@

/** job implementation that renders everything sequentially using a custom painter.
* The returned image is always invalid (because there is none available).
*/
class QgsMapRendererCustomPainterJob : QgsMapRendererJob
{
%TypeHeaderCode
#include <qgsmaprenderercustompainterjob.h>
%End

public:
QgsMapRendererCustomPainterJob( const QgsMapSettings& settings, QPainter* painter );
~QgsMapRendererCustomPainterJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;
virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

//! @note not available in python bindings
// const LayerRenderJobs& jobs() const { return mLayerJobs; }

/**
* Wait for the job to be finished - and keep the thread's event loop running while waiting.
*
* With a call to waitForFinished(), the waiting is done with a synchronization primitive
* and does not involve processing of messages. That may cause issues to code which requires
* some events to be handled in the main thread. Some plugins hooking into the rendering
* pipeline may require this in order to work properly - for example, OpenLayers plugin
* which uses a QWebPage in the main thread.
*
* Ideally the "wait for finished" method should not be used at all. The code triggering
* rendering should not need to actively wait for rendering to finish.
*/
void waitForFinishedWithEventLoop( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents );

/**
* Render the map synchronously in this thread. The function does not return until the map
* is completely rendered.
*
* This is an alternative to ordinary API (using start() + waiting for finished() signal).
* Users are discouraged to use this method unless they have a strong reason for doing it.
* The synchronous rendering blocks the main thread, making the application unresponsive.
* Also, it is not possible to cancel rendering while it is in progress.
*/
void renderSynchronously();

protected slots:
void futureFinished();

protected:
static void staticRender( QgsMapRendererCustomPainterJob* self ); // function to be used within the thread

// these methods are called within worker thread
void doRender();
};
123 changes: 0 additions & 123 deletions python/core/qgsmaprendererjob.sip
Expand Up @@ -115,126 +115,3 @@ class QgsMapRendererQImageJob : QgsMapRendererJob
//! Get a preview/resulting image
virtual QImage renderedImage() = 0;
};



/** job implementation that renders everything sequentially in one thread */
class QgsMapRendererSequentialJob : QgsMapRendererQImageJob
{
%TypeHeaderCode
#include <qgsmaprendererjob.h>
%End

public:
QgsMapRendererSequentialJob( const QgsMapSettings& settings );
~QgsMapRendererSequentialJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

// from QgsMapRendererJobWithPreview
virtual QImage renderedImage();

public slots:

void internalFinished();
};




/** job implementation that renders all layers in parallel */
class QgsMapRendererParallelJob : QgsMapRendererQImageJob
{
%TypeHeaderCode
#include <qgsmaprendererjob.h>
%End

public:
QgsMapRendererParallelJob( const QgsMapSettings& settings );
~QgsMapRendererParallelJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

// from QgsMapRendererJobWithPreview
virtual QImage renderedImage();

protected slots:
//! layers are rendered, labeling is still pending
void renderLayersFinished();
//! all rendering is finished, including labeling
void renderingFinished();

protected:

static void renderLayerStatic( LayerRenderJob& job );
static void renderLabelsStatic( QgsMapRendererParallelJob* self );
};



/** job implementation that renders everything sequentially using a custom painter.
* The returned image is always invalid (because there is none available).
*/
class QgsMapRendererCustomPainterJob : QgsMapRendererJob
{
%TypeHeaderCode
#include <qgsmaprendererjob.h>
%End

public:
QgsMapRendererCustomPainterJob( const QgsMapSettings& settings, QPainter* painter );
~QgsMapRendererCustomPainterJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;
virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

//! @note not available in python bindings
// const LayerRenderJobs& jobs() const { return mLayerJobs; }

/**
* Wait for the job to be finished - and keep the thread's event loop running while waiting.
*
* With a call to waitForFinished(), the waiting is done with a synchronization primitive
* and does not involve processing of messages. That may cause issues to code which requires
* some events to be handled in the main thread. Some plugins hooking into the rendering
* pipeline may require this in order to work properly - for example, OpenLayers plugin
* which uses a QWebPage in the main thread.
*
* Ideally the "wait for finished" method should not be used at all. The code triggering
* rendering should not need to actively wait for rendering to finish.
*/
void waitForFinishedWithEventLoop( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents );

/**
* Render the map synchronously in this thread. The function does not return until the map
* is completely rendered.
*
* This is an alternative to ordinary API (using start() + waiting for finished() signal).
* Users are discouraged to use this method unless they have a strong reason for doing it.
* The synchronous rendering blocks the main thread, making the application unresponsive.
* Also, it is not possible to cancel rendering while it is in progress.
*/
void renderSynchronously();

protected slots:
void futureFinished();

protected:
static void staticRender( QgsMapRendererCustomPainterJob* self ); // function to be used within the thread

// these methods are called within worker thread
void doRender();
};
33 changes: 33 additions & 0 deletions python/core/qgsmaprendererparalleljob.sip
@@ -0,0 +1,33 @@

/** job implementation that renders all layers in parallel */
class QgsMapRendererParallelJob : QgsMapRendererQImageJob
{
%TypeHeaderCode
#include <qgsmaprendererparalleljob.h>
%End

public:
QgsMapRendererParallelJob( const QgsMapSettings& settings );
~QgsMapRendererParallelJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

// from QgsMapRendererJobWithPreview
virtual QImage renderedImage();

protected slots:
//! layers are rendered, labeling is still pending
void renderLayersFinished();
//! all rendering is finished, including labeling
void renderingFinished();

protected:

static void renderLayerStatic( LayerRenderJob& job );
static void renderLabelsStatic( QgsMapRendererParallelJob* self );
};
27 changes: 27 additions & 0 deletions python/core/qgsmaprenderersequentialjob.sip
@@ -0,0 +1,27 @@


/** job implementation that renders everything sequentially in one thread */
class QgsMapRendererSequentialJob : QgsMapRendererQImageJob
{
%TypeHeaderCode
#include <qgsmaprenderersequentialjob.h>
%End

public:
QgsMapRendererSequentialJob( const QgsMapSettings& settings );
~QgsMapRendererSequentialJob();

virtual void start();
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

// from QgsMapRendererJobWithPreview
virtual QImage renderedImage();

public slots:

void internalFinished();
};
2 changes: 1 addition & 1 deletion src/app/maprenderertest.h
Expand Up @@ -9,7 +9,7 @@
#include "qgsmapsettings.h"
#include "qgsmaplayer.h"

#include "qgsmaprendererjob.h"
#include "qgsmaprenderersequentialjob.h"

class TestWidget : public QLabel
{
Expand Down
6 changes: 6 additions & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -7,6 +7,9 @@ SET(QGIS_CORE_SRCS
qgsxmlutils.cpp
qgsmapsettings.cpp
qgsmaprendererjob.cpp
qgsmaprenderercustompainterjob.cpp
qgsmaprendererparalleljob.cpp
qgsmaprenderersequentialjob.cpp
qgsvectorlayerrenderer.cpp
raster/qgsrasterlayerrenderer.cpp

Expand Down Expand Up @@ -323,6 +326,9 @@ SET(QGIS_CORE_MOC_HDRS

qgsmaprenderercache.h
qgsmaprendererjob.h
qgsmaprenderercustompainterjob.h
qgsmaprendererparalleljob.h
qgsmaprenderersequentialjob.h

qgsapplication.h
qgsbrowsermodel.h
Expand Down
2 changes: 1 addition & 1 deletion src/core/composer/qgscomposermap.cpp
Expand Up @@ -20,7 +20,7 @@
#include "qgscoordinatetransform.h"
#include "qgslogger.h"
#include "qgsmaprenderer.h"
#include "qgsmaprendererjob.h"
#include "qgsmaprenderercustompainterjob.h"
#include "qgsmaplayerregistry.h"
#include "qgsmaptopixel.h"
#include "qgsproject.h"
Expand Down

0 comments on commit 436b05e

Please sign in to comment.