Skip to content
Permalink
Browse files

Removed QgsMapRendererV2 again in favour of using jobs directly

  • Loading branch information
wonder-sk committed Oct 31, 2013
1 parent ef3c267 commit 159f135d939eb38b3bedac51f78b07383676c84f
@@ -9,6 +9,8 @@
#include "qgsmaprendererv2.h"
#include "qgsmaplayer.h"

#include "qgsmaprendererjob.h"

class TestWidget : public QLabel
{
Q_OBJECT
@@ -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()));
@@ -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();
}
}
@@ -93,7 +103,8 @@ protected slots:
//QPixmap p;
QImage i;
QPainter* painter;
QgsMapRendererV2 rend;
QgsMapSettings ms;
QgsMapRendererJob* job;
QTimer timer;
};

@@ -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)
{
}
@@ -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)
{
@@ -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 );
@@ -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;
@@ -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 ) ) );

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

}


@@ -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() {}

@@ -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).
@@ -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).
@@ -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();
@@ -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();

0 comments on commit 159f135

Please sign in to comment.
You can’t perform that action at this time.