1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/***************************************************************************
qgsmaprenderersequentialjob.cpp
--------------------------------------
Date : December 2013
Copyright : (C) 2013 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsmaprenderersequentialjob.h"
#include "qgslogger.h"
#include "qgsmaprenderercustompainterjob.h"
#include "qgspallabeling.h"
QgsMapRendererSequentialJob::QgsMapRendererSequentialJob( const QgsMapSettings& settings )
: QgsMapRendererQImageJob( settings )
, mInternalJob( 0 )
, mPainter( 0 )
, mLabelingResults( 0 )
{
QgsDebugMsg( "SEQUENTIAL construct" );
mImage = QImage( mSettings.outputSize(), mSettings.outputImageFormat() );
}
QgsMapRendererSequentialJob::~QgsMapRendererSequentialJob()
{
QgsDebugMsg( "SEQUENTIAL destruct" );
if ( isActive() )
{
// still running!
QgsDebugMsg( "SEQUENTIAL destruct -- still running! (cancelling)" );
cancel();
}
Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
delete mLabelingResults;
mLabelingResults = 0;
}
void QgsMapRendererSequentialJob::start()
{
if ( isActive() )
return; // do nothing if we are already running
mRenderingStart.start();
mErrors.clear();
QgsDebugMsg( "SEQUENTIAL START" );
Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
mPainter = new QPainter( &mImage );
mInternalJob = new QgsMapRendererCustomPainterJob( mSettings, mPainter );
mInternalJob->setCache( mCache );
connect( mInternalJob, SIGNAL( finished() ), SLOT( internalFinished() ) );
mInternalJob->start();
}
void QgsMapRendererSequentialJob::cancel()
{
if ( !isActive() )
return;
QgsDebugMsg( "sequential - cancel internal" );
mInternalJob->cancel();
Q_ASSERT( mInternalJob == 0 && mPainter == 0 );
}
void QgsMapRendererSequentialJob::waitForFinished()
{
if ( !isActive() )
return;
mInternalJob->waitForFinished();
}
bool QgsMapRendererSequentialJob::isActive() const
{
return mInternalJob != 0;
}
QgsLabelingResults* QgsMapRendererSequentialJob::takeLabelingResults()
{
QgsLabelingResults* tmp = mLabelingResults;
mLabelingResults = 0;
return tmp;
}
QImage QgsMapRendererSequentialJob::renderedImage()
{
if ( isActive() && mCache )
// this will allow immediate display of cached layers and at the same time updates of the layer being rendered
return composeImage( mSettings, mInternalJob->jobs() );
else
return mImage;
}
void QgsMapRendererSequentialJob::internalFinished()
{
QgsDebugMsg( "SEQUENTIAL finished" );
mPainter->end();
delete mPainter;
mPainter = 0;
mLabelingResults = mInternalJob->takeLabelingResults();
mErrors = mInternalJob->errors();
// now we are in a slot called from mInternalJob - do not delete it immediately
// so the class is still valid when the execution returns to the class
mInternalJob->deleteLater();
mInternalJob = 0;
mRenderingTime = mRenderingStart.elapsed();
emit finished();
}
|