void QgsMapRendererParallelJob::start() { if ( isActive() ) return; mRenderingStart.start(); mStatus = RenderingLayers; mLabelingEngineV2.reset(); if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngineV2.reset( new QgsLabelingEngine() ); mLabelingEngineV2->setMapSettings( mSettings ); } bool canUseLabelCache = prepareLabelCache(); mLayerJobs = prepareJobs( nullptr, mLabelingEngineV2.get() ); mLabelJob = prepareLabelingJob( nullptr, mLabelingEngineV2.get(), canUseLabelCache ); QgsDebugMsg( QString( "QThreadPool max thread count is %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) ); // start async job connect( &mFutureWatcher, &QFutureWatcher<void>::finished, this, &QgsMapRendererParallelJob::renderLayersFinished ); mFuture = QtConcurrent::map( mLayerJobs, renderLayerStatic ); mFutureWatcher.setFuture( mFuture ); }
void QgsMapRendererCustomPainterJob::start() { if ( isActive() ) return; mRenderingStart.start(); mActive = true; mErrors.clear(); QgsDebugMsg( "QPAINTER run!" ); QgsDebugMsg( "Preparing list of layer jobs for rendering" ); QTime prepareTime; prepareTime.start(); // clear the background mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() ); mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) ); QPaintDevice* thePaintDevice = mPainter->device(); QString errMsg = QString( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() ); Q_ASSERT_X( thePaintDevice->logicalDpiX() == mSettings.outputDpi(), "Job::startRender()", errMsg.toAscii().data() ); delete mLabelingEngine; mLabelingEngine = 0; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngine = new QgsPalLabeling; mLabelingEngine->loadEngineSettings(); mLabelingEngine->init( mSettings ); } mLayerJobs = prepareJobs( mPainter, mLabelingEngine ); QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) ); // now we are ready to start rendering! if ( !mLayerJobs.isEmpty() ) { connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) ); mFuture = QtConcurrent::run( staticRender, this ); mFutureWatcher.setFuture( mFuture ); } else { // just make sure we will clean up and emit finished() signal QTimer::singleShot( 0, this, SLOT( futureFinished() ) ); } }
void QgsMapRendererCustomPainterJob::start() { if ( isActive() ) return; mRenderingStart.start(); mActive = true; mErrors.clear(); QgsDebugMsg( "QPAINTER run!" ); QgsDebugMsg( "Preparing list of layer jobs for rendering" ); QTime prepareTime; prepareTime.start(); // clear the background mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() ); mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) ); #ifndef QT_NO_DEBUG QPaintDevice* thePaintDevice = mPainter->device(); QString errMsg = QStringLiteral( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() ); Q_ASSERT_X( qgsDoubleNear( thePaintDevice->logicalDpiX(), mSettings.outputDpi() ), "Job::startRender()", errMsg.toLatin1().data() ); #endif delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { mLabelingEngineV2 = new QgsLabelingEngine(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); } mLayerJobs = prepareJobs( mPainter, mLabelingEngineV2 ); QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) ); if ( mRenderSynchronously ) { // do the rendering right now! doRender(); return; } // now we are ready to start rendering! connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) ); mFuture = QtConcurrent::run( staticRender, this ); mFutureWatcher.setFuture( mFuture ); }
void QgsMapRendererParallelJob::start() { if ( isActive() ) return; mRenderingStart.start(); mStatus = RenderingLayers; delete mLabelingEngine; mLabelingEngine = nullptr; delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { #ifdef LABELING_V2 mLabelingEngineV2 = new QgsLabelingEngineV2(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); #else mLabelingEngine = new QgsPalLabeling; mLabelingEngine->loadEngineSettings(); mLabelingEngine->init( mSettings ); #endif } mLayerJobs = prepareJobs( nullptr, mLabelingEngine, mLabelingEngineV2 ); // prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider, // whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a // QEventLoop waiting for the network request to complete. If unluckily someone calls // mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is // called, deleting the QgsMapRendererCustomPainterJob while this function is running. // Hence we need to check whether the job is still active before proceeding if ( !isActive() ) return; QgsDebugMsg( QString( "QThreadPool max thread count is %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) ); // start async job connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( renderLayersFinished() ) ); mFuture = QtConcurrent::map( mLayerJobs, renderLayerStatic ); mFutureWatcher.setFuture( mFuture ); }
void QgsMapRendererParallelJob::start() { if ( isActive() ) return; mRenderingStart.start(); mStatus = RenderingLayers; delete mLabelingEngine; mLabelingEngine = nullptr; delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { #ifdef LABELING_V2 mLabelingEngineV2 = new QgsLabelingEngineV2(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); #else mLabelingEngine = new QgsPalLabeling; mLabelingEngine->loadEngineSettings(); mLabelingEngine->init( mSettings ); #endif } mLayerJobs = prepareJobs( nullptr, mLabelingEngine, mLabelingEngineV2 ); QgsDebugMsg( QString( "QThreadPool max thread count is %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) ); // start async job connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( renderLayersFinished() ) ); mFuture = QtConcurrent::map( mLayerJobs, renderLayerStatic ); mFutureWatcher.setFuture( mFuture ); }
void QgsMapRendererCustomPainterJob::start() { if ( isActive() ) return; mRenderingStart.start(); mActive = true; mErrors.clear(); QgsDebugMsg( "QPAINTER run!" ); QgsDebugMsg( "Preparing list of layer jobs for rendering" ); QTime prepareTime; prepareTime.start(); // clear the background mPainter->fillRect( 0, 0, mSettings.outputSize().width(), mSettings.outputSize().height(), mSettings.backgroundColor() ); mPainter->setRenderHint( QPainter::Antialiasing, mSettings.testFlag( QgsMapSettings::Antialiasing ) ); #ifndef QT_NO_DEBUG QPaintDevice* thePaintDevice = mPainter->device(); QString errMsg = QString( "pre-set DPI not equal to painter's DPI (%1 vs %2)" ).arg( thePaintDevice->logicalDpiX() ).arg( mSettings.outputDpi() ); Q_ASSERT_X( qgsDoubleNear( thePaintDevice->logicalDpiX(), mSettings.outputDpi() ), "Job::startRender()", errMsg.toAscii().data() ); #endif delete mLabelingEngine; mLabelingEngine = nullptr; delete mLabelingEngineV2; mLabelingEngineV2 = nullptr; if ( mSettings.testFlag( QgsMapSettings::DrawLabeling ) ) { #ifdef LABELING_V2 mLabelingEngineV2 = new QgsLabelingEngineV2(); mLabelingEngineV2->readSettingsFromProject(); mLabelingEngineV2->setMapSettings( mSettings ); #else mLabelingEngine = new QgsPalLabeling; mLabelingEngine->loadEngineSettings(); mLabelingEngine->init( mSettings ); #endif } mLayerJobs = prepareJobs( mPainter, mLabelingEngine, mLabelingEngineV2 ); // prepareJobs calls mapLayer->createMapRenderer may involve cloning a RasterDataProvider, // whose constructor may need to download some data (i.e. WMS, AMS) and doing so runs a // QEventLoop waiting for the network request to complete. If unluckily someone calls // mapCanvas->refresh() while this is happening, QgsMapRendererCustomPainterJob::cancel is // called, deleting the QgsMapRendererCustomPainterJob while this function is running. // Hence we need to check whether the job is still active before proceeding if ( !isActive() ) return; QgsDebugMsg( "Rendering prepared in (seconds): " + QString( "%1" ).arg( prepareTime.elapsed() / 1000.0 ) ); if ( mRenderSynchronously ) { // do the rendering right now! doRender(); return; } // now we are ready to start rendering! connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( futureFinished() ) ); mFuture = QtConcurrent::run( staticRender, this ); mFutureWatcher.setFuture( mFuture ); }