Skip to content

Commit

Permalink
Removed QgsMapRendererV2 again in favour of using jobs directly
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Oct 31, 2013
1 parent ef3c267 commit 159f135
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 255 deletions.
41 changes: 26 additions & 15 deletions src/app/maprenderertest.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "qgsmaprendererv2.h"
#include "qgsmaplayer.h"

#include "qgsmaprendererjob.h"

class TestWidget : public QLabel
{
Q_OBJECT
Expand All @@ -21,18 +23,18 @@ class TestWidget : public QLabel
i = QImage(size(), QImage::Format_ARGB32_Premultiplied);
i.fill(Qt::gray);

job = 0;

// init renderer
rend.setLayers(QStringList(layer->id()));
rend.setExtent(layer->extent());
rend.setOutputSize(i.size());
rend.setOutputDpi(120);
rend.updateDerived();
ms.setLayers(QStringList(layer->id()));
ms.setExtent(layer->extent());
ms.setOutputSize(i.size());
ms.setOutputDpi(120);
ms.updateDerived();

if (rend.hasValidSettings())
if (ms.hasValidSettings())
qDebug("map renderer settings valid");

connect(&rend, SIGNAL(finished()), SLOT(f()));

setPixmap(QPixmap::fromImage(i));

connect(&timer, SIGNAL(timeout()), SLOT(onMapUpdateTimeout()));
Expand All @@ -45,24 +47,32 @@ class TestWidget : public QLabel
{
qDebug("cancelling!");

rend.cancel();
if (job)
{
job->cancel();
delete job;
job = 0;
}
}
else
{
qDebug("starting!");

if (rend.isRendering())
if (job)
{
qDebug("need to cancel first!");
rend.cancel();

// TODO: need to ensure that finished slot has been called
job->cancel();
delete job;
job = 0;
}

i.fill(Qt::gray);

painter = new QPainter(&i);
rend.startWithCustomPainter(painter);

job = new QgsMapRendererCustomPainterJob(ms, painter);
connect(job, SIGNAL(finished()), SLOT(f()));

timer.start();
}
}
Expand Down Expand Up @@ -93,7 +103,8 @@ protected slots:
//QPixmap p;
QImage i;
QPainter* painter;
QgsMapRendererV2 rend;
QgsMapSettings ms;
QgsMapRendererJob* job;
QTimer timer;
};

Expand Down
22 changes: 14 additions & 8 deletions src/core/qgsmaprendererjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"

QgsMapRendererSequentialJob::QgsMapRendererSequentialJob(const QgsMapRendererSettings& settings)
: QgsMapRendererJob(SequentialJob, settings)

QgsMapRendererQImageJob::QgsMapRendererQImageJob(QgsMapRendererJob::Type type, const QgsMapSettings& settings)
: QgsMapRendererJob(type, settings)
{
}


QgsMapRendererSequentialJob::QgsMapRendererSequentialJob(const QgsMapSettings& settings)
: QgsMapRendererQImageJob(SequentialJob, settings)
, mInternalJob(0)
{
}
Expand Down Expand Up @@ -57,7 +64,7 @@ void QgsMapRendererSequentialJob::internalFinished()



QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob(const QgsMapRendererSettings& settings, QPainter* painter)
QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob(const QgsMapSettings& settings, QPainter* painter)
: QgsMapRendererJob(CustomPainterJob, settings)
, mPainter(painter)
{
Expand Down Expand Up @@ -122,8 +129,8 @@ void QgsMapRendererCustomPainterJob::startRender()
renderTime.start();
#endif

mRenderContext.setMapToPixel( QgsMapToPixel( mSettings.mapUnitsPerPixel, mSettings.size.height(), mSettings.visibleExtent.yMinimum(), mSettings.visibleExtent.xMinimum() ) );
mRenderContext.setExtent( mSettings.visibleExtent );
mRenderContext.setMapToPixel( QgsMapToPixel( mSettings.mapUnitsPerPixel(), mSettings.outputSize().height(), mSettings.visibleExtent().yMinimum(), mSettings.visibleExtent().xMinimum() ) );
mRenderContext.setExtent( mSettings.visibleExtent() );

mRenderContext.setDrawEditingInformation( false );
mRenderContext.setPainter( mPainter );
Expand Down Expand Up @@ -196,7 +203,7 @@ void QgsMapRendererCustomPainterJob::startRender()
}*/

// render all layers in the stack, starting at the base
QListIterator<QString> li( mSettings.layers );
QListIterator<QString> li( mSettings.layers() );
li.toBack();

QgsRectangle r1, r2;
Expand Down Expand Up @@ -251,7 +258,7 @@ void QgsMapRendererCustomPainterJob::startRender()
mypContextPainter->setCompositionMode( ml->blendMode() );
}

if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale && mSettings.scale < ml->maximumScale() ) ) //|| mOverview )
if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mSettings.scale() && mSettings.scale() < ml->maximumScale() ) ) //|| mOverview )
{
connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );

Expand Down Expand Up @@ -547,4 +554,3 @@ void QgsMapRendererCustomPainterJob::startRender()

}


16 changes: 9 additions & 7 deletions src/core/qgsmaprendererjob.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class QgsMapRendererJob : public QObject
};


QgsMapRendererJob(Type type, const QgsMapRendererSettings& settings) : mType(type), mSettings(settings) { }
QgsMapRendererJob(Type type, const QgsMapSettings& settings) : mType(type), mSettings(settings) { }

virtual ~QgsMapRendererJob() {}

Expand All @@ -34,6 +34,8 @@ class QgsMapRendererJob : public QObject
//! Stop the rendering job - does not return until the job has terminated.
virtual void cancel() = 0;

// TODO: isActive() ?

signals:

//! emitted when asynchronous rendering is finished (or canceled).
Expand All @@ -43,14 +45,14 @@ class QgsMapRendererJob : public QObject

Type mType;

QgsMapRendererSettings mSettings;
QgsMapSettings mSettings;
};


class QgsMapRendererJobWithPreview : public QgsMapRendererJob
class QgsMapRendererQImageJob : public QgsMapRendererJob
{

public:
QgsMapRendererQImageJob(Type type, const QgsMapSettings& settings);

//! Get a preview/resulting image - in case QPainter has not been provided.
//! With QPainter specified, it will return invalid QImage (there's no way to provide it).
Expand All @@ -62,11 +64,11 @@ class QgsMapRendererCustomPainterJob;


/** job implementation that renders everything sequentially in one thread */
class QgsMapRendererSequentialJob : public QgsMapRendererJobWithPreview
class QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
{
Q_OBJECT
public:
QgsMapRendererSequentialJob(const QgsMapRendererSettings& settings);
QgsMapRendererSequentialJob(const QgsMapSettings& settings);

virtual void start();
virtual void cancel();
Expand Down Expand Up @@ -103,7 +105,7 @@ class QgsMapRendererCustomPainterJob : public QgsMapRendererJob
{
Q_OBJECT
public:
QgsMapRendererCustomPainterJob(const QgsMapRendererSettings& settings, QPainter* painter);
QgsMapRendererCustomPainterJob(const QgsMapSettings& settings, QPainter* painter);

virtual void start();
virtual void cancel();
Expand Down
Loading

0 comments on commit 159f135

Please sign in to comment.