QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgsmaprenderertask.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaprenderertask.h
3  -------------------------
4  begin : Apr 2017
5  copyright : (C) 2017 by Mathieu Pellerin
6  email : nirvn dot asia at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgsannotation.h"
19 #include "qgsannotationmanager.h"
20 #include "qgsmaprenderertask.h"
21 #include "qgsmapsettingsutils.h"
22 #include "qgsogrutils.h"
23 #include "qgslogger.h"
27 #include "qgsfeaturerequest.h"
28 #include "qgsvectorlayer.h"
29 
30 #include <QFile>
31 #include <QTextStream>
32 #ifndef QT_NO_PRINTER
33 #include <QPrinter>
34 #endif
35 
36 #include "gdal.h"
37 #include "cpl_conv.h"
38 
40 
41 class QgsMapRendererTaskGeoPdfExporter : public QgsAbstractGeoPdfExporter
42 {
43 
44  public:
45 
46  QgsMapRendererTaskGeoPdfExporter( const QgsMapSettings &ms )
47  {
48  // collect details upfront, while we are still in the main thread
49  const QList< QgsMapLayer * > layers = ms.layers();
50  for ( const QgsMapLayer *layer : layers )
51  {
52  VectorComponentDetail detail;
53  detail.name = layer->name();
54  detail.mapLayerId = layer->id();
55  if ( const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
56  {
57  detail.displayAttribute = vl->displayField();
58  }
59  mLayerDetails[ layer->id() ] = detail;
60  }
61  }
62 
63  private:
64 
65  QgsAbstractGeoPdfExporter::VectorComponentDetail componentDetailForLayerId( const QString &layerId ) override
66  {
67  return mLayerDetails.value( layerId );
68  }
69 
70  QMap< QString, VectorComponentDetail > mLayerDetails;
71 };
72 
73 
74 class QgsMapRendererTaskRenderedFeatureHandler : public QgsRenderedFeatureHandlerInterface
75 {
76  public:
77 
78  QgsMapRendererTaskRenderedFeatureHandler( QgsMapRendererTaskGeoPdfExporter *exporter, const QgsMapSettings &settings )
79  : mExporter( exporter )
80  , mMapSettings( settings )
81  {
82  // PDF coordinate space uses a hardcoded DPI of 72, also vertical dimension is flipped from QGIS dimension
83  const double pageHeightPdfUnits = settings.outputSize().height() * 72.0 / settings.outputDpi();
84  mTransform = QTransform::fromTranslate( 0, pageHeightPdfUnits ).scale( 72.0 / mMapSettings.outputDpi(), -72.0 / mMapSettings.outputDpi() );
85  }
86 
87  void handleRenderedFeature( const QgsFeature &feature, const QgsGeometry &renderedBounds, const QgsRenderedFeatureHandlerInterface::RenderedFeatureContext &context ) override
88  {
89  // is it a hack retrieving the layer ID from an expression context like this? possibly... BUT
90  // the alternative is adding a layer ID member to QgsRenderContext, and that's just asking for people to abuse it
91  // and use it to retrieve QgsMapLayers mid-way through a render operation. Lesser of two evils it is!
92  const QString layerId = context.renderContext.expressionContext().variable( QStringLiteral( "layer_id" ) ).toString();
93 
94  QgsGeometry transformed = renderedBounds;
95  transformed.transform( mTransform );
96 
97  // always convert to multitype, to make things consistent
98  transformed.convertToMultiType();
99 
100  mExporter->pushRenderedFeature( layerId, QgsAbstractGeoPdfExporter::RenderedFeature( feature, transformed ) );
101  }
102 
103  QSet<QString> usedAttributes( QgsVectorLayer *, const QgsRenderContext & ) const override
104  {
105  return QSet< QString >() << QgsFeatureRequest::ALL_ATTRIBUTES;
106  }
107 
108  private:
109 
110  QgsMapRendererTaskGeoPdfExporter *mExporter = nullptr;
111  QgsMapSettings mMapSettings;
113  QTransform mTransform;
114 
115 };
116 
118 
119 QgsMapRendererTask::QgsMapRendererTask( const QgsMapSettings &ms, const QString &fileName, const QString &fileFormat, const bool forceRaster,
120  const bool geoPDF, const QgsAbstractGeoPdfExporter::ExportDetails &geoPdfExportDetails )
121  : QgsTask( fileFormat == QStringLiteral( "PDF" ) ? tr( "Saving as PDF" ) : tr( "Saving as image" ) )
122  , mMapSettings( ms )
123  , mFileName( fileName )
124  , mFileFormat( fileFormat )
125  , mForceRaster( forceRaster )
126  , mGeoPDF( geoPDF && mFileFormat == QStringLiteral( "PDF" ) && QgsAbstractGeoPdfExporter::geoPDFCreationAvailable() )
127  , mGeoPdfExportDetails( geoPdfExportDetails )
128 {
129  prepare();
130 }
131 
133  : QgsTask( tr( "Rendering to painter" ) )
134  , mMapSettings( ms )
135  , mPainter( p )
136 {
137  prepare();
138 }
139 
141 
142 void QgsMapRendererTask::addAnnotations( const QList< QgsAnnotation * > &annotations )
143 {
144  qDeleteAll( mAnnotations );
145  mAnnotations.clear();
146 
147  const auto constAnnotations = annotations;
148  for ( const QgsAnnotation *a : constAnnotations )
149  {
150  mAnnotations << a->clone();
151  }
152 }
153 
154 void QgsMapRendererTask::addDecorations( const QList< QgsMapDecoration * > &decorations )
155 {
156  mDecorations = decorations;
157 }
158 
159 
161 {
162  mJobMutex.lock();
163  if ( mJob )
164  mJob->cancelWithoutBlocking();
165  mJobMutex.unlock();
166 
167  QgsTask::cancel();
168 }
169 
171 {
172  if ( mErrored )
173  return false;
174 
175  if ( mGeoPDF )
176  {
177 #ifdef QT_NO_PRINTER
178  return false;
179 #else
180  QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > pdfComponents;
181 
182  QgsMapRendererStagedRenderJob *job = static_cast< QgsMapRendererStagedRenderJob * >( mJob.get() );
183  int outputLayer = 1;
184  while ( !job->isFinished() )
185  {
187 
188  component.name = QStringLiteral( "layer_%1" ).arg( outputLayer );
189  component.mapLayerId = job->currentLayerId();
190  component.opacity = job->currentLayerOpacity();
191  component.compositionMode = job->currentLayerCompositionMode();
192  component.sourcePdfPath = mGeoPdfExporter->generateTemporaryFilepath( QStringLiteral( "layer_%1.pdf" ).arg( outputLayer ) );
193  pdfComponents << component;
194 
195  QPrinter printer;
196  printer.setOutputFileName( component.sourcePdfPath );
197  printer.setOutputFormat( QPrinter::PdfFormat );
198  printer.setOrientation( QPrinter::Portrait );
199  // paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
200  QSizeF outputSize = mMapSettings.outputSize();
201  printer.setPaperSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPrinter::Millimeter );
202  printer.setPageMargins( 0, 0, 0, 0, QPrinter::Millimeter );
203  printer.setResolution( mMapSettings.outputDpi() );
204 
205  QPainter p( &printer );
206  job->renderCurrentPart( &p );
207  p.end();
208 
209  outputLayer++;
210  job->nextPart();
211  }
212  QgsAbstractGeoPdfExporter::ExportDetails exportDetails = mGeoPdfExportDetails;
213  const double pageWidthMM = mMapSettings.outputSize().width() * 25.4 / mMapSettings.outputDpi();
214  const double pageHeightMM = mMapSettings.outputSize().height() * 25.4 / mMapSettings.outputDpi();
215  exportDetails.pageSizeMm = QSizeF( pageWidthMM, pageHeightMM );
216  exportDetails.dpi = mMapSettings.outputDpi();
217 
218  exportDetails.layerIdToPdfLayerTreeNameMap = mLayerIdToLayerNameMap;
219  exportDetails.layerOrder = mMapLayerOrder;
220 
221  if ( mSaveWorldFile )
222  {
223  // setup georeferencing
225  georef.crs = mMapSettings.destinationCrs();
226  georef.pageBoundsMm = QgsRectangle( 0, 0, pageWidthMM, pageHeightMM );
227  georef.controlPoints.reserve( 4 );
229  georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( pageWidthMM, 0 ), mMapSettings.mapToPixel().toMapCoordinates( mMapSettings.outputSize().width(), 0 ) );
230  georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( pageWidthMM, pageHeightMM ), mMapSettings.mapToPixel().toMapCoordinates( mMapSettings.outputSize().width(), mMapSettings.outputSize().height() ) );
231  georef.controlPoints << QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( 0, pageHeightMM ), mMapSettings.mapToPixel().toMapCoordinates( 0, mMapSettings.outputSize().height() ) );
232  exportDetails.georeferencedSections << georef;
233  }
234 
235  const bool res = mGeoPdfExporter->finalize( pdfComponents, mFileName, exportDetails );
236  mGeoPdfExporter.reset();
237  mTempPainter.reset();
238  mPrinter.reset();
239  return res;
240 #endif
241  }
242  else
243  static_cast< QgsMapRendererCustomPainterJob *>( mJob.get() )->renderPrepared();
244 
245  mJobMutex.lock();
246  mJob.reset( nullptr );
247  mJobMutex.unlock();
248 
249  if ( isCanceled() )
250  return false;
251 
252  QgsRenderContext context = QgsRenderContext::fromMapSettings( mMapSettings );
253  context.setPainter( mDestPainter );
254 
255  const auto constMDecorations = mDecorations;
256  for ( QgsMapDecoration *decoration : constMDecorations )
257  {
258  decoration->render( mMapSettings, context );
259  }
260 
261  const auto constMAnnotations = mAnnotations;
262  for ( QgsAnnotation *annotation : constMAnnotations )
263  {
264  if ( isCanceled() )
265  return false;
266 
267  if ( !annotation || !annotation->isVisible() )
268  {
269  continue;
270  }
271  if ( annotation->mapLayer() && !mMapSettings.layers().contains( annotation->mapLayer() ) )
272  {
273  continue;
274  }
275 
276  context.painter()->save();
277  context.painter()->setRenderHint( QPainter::Antialiasing, context.flags() & QgsRenderContext::Antialiasing );
278 
279  double itemX, itemY;
280  if ( annotation->hasFixedMapPosition() )
281  {
282  itemX = mMapSettings.outputSize().width() * ( annotation->mapPosition().x() - mMapSettings.extent().xMinimum() ) / mMapSettings.extent().width();
283  itemY = mMapSettings.outputSize().height() * ( 1 - ( annotation->mapPosition().y() - mMapSettings.extent().yMinimum() ) / mMapSettings.extent().height() );
284  }
285  else
286  {
287  itemX = annotation->relativePosition().x() * mMapSettings.outputSize().width();
288  itemY = annotation->relativePosition().y() * mMapSettings.outputSize().height();
289  }
290 
291  context.painter()->translate( itemX, itemY );
292 
293  annotation->render( context );
294  context.painter()->restore();
295  }
296 
297  if ( !mFileName.isEmpty() )
298  {
299  mDestPainter->end();
300 
301  if ( mFileFormat == QStringLiteral( "PDF" ) )
302  {
303 #ifndef QT_NO_PRINTER
304  if ( mForceRaster )
305  {
306  QPainter pp;
307  pp.begin( mPrinter.get() );
308  QRectF rect( 0, 0, mImage.width(), mImage.height() );
309  pp.drawImage( rect, mImage, rect );
310  pp.end();
311  }
312 
313  if ( mSaveWorldFile || mExportMetadata )
314  {
315  CPLSetThreadLocalConfigOption( "GDAL_PDF_DPI", QString::number( mMapSettings.outputDpi() ).toLocal8Bit().constData() );
316  gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toLocal8Bit().constData(), GA_Update ) );
317  if ( outputDS )
318  {
319  if ( mSaveWorldFile )
320  {
321  double a, b, c, d, e, f;
322  QgsMapSettingsUtils::worldFileParameters( mMapSettings, a, b, c, d, e, f );
323  c -= 0.5 * a;
324  c -= 0.5 * b;
325  f -= 0.5 * d;
326  f -= 0.5 * e;
327  double geoTransform[6] = { c, a, b, f, d, e };
328  GDALSetGeoTransform( outputDS.get(), geoTransform );
329  GDALSetProjection( outputDS.get(), mMapSettings.destinationCrs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL ).toLocal8Bit().constData() );
330  }
331 
332  if ( mExportMetadata )
333  {
334  QString creationDateString;
335  const QDateTime creationDateTime = mGeoPdfExportDetails.creationDateTime;
336  if ( creationDateTime.isValid() )
337  {
338  creationDateString = QStringLiteral( "D:%1" ).arg( mGeoPdfExportDetails.creationDateTime.toString( QStringLiteral( "yyyyMMddHHmmss" ) ) );
339  if ( creationDateTime.timeZone().isValid() )
340  {
341  int offsetFromUtc = creationDateTime.timeZone().offsetFromUtc( creationDateTime );
342  creationDateString += ( offsetFromUtc >= 0 ) ? '+' : '-';
343  offsetFromUtc = std::abs( offsetFromUtc );
344  int offsetHours = offsetFromUtc / 3600;
345  int offsetMins = ( offsetFromUtc % 3600 ) / 60;
346  creationDateString += QStringLiteral( "%1'%2'" ).arg( offsetHours ).arg( offsetMins );
347  }
348  }
349  GDALSetMetadataItem( outputDS.get(), "CREATION_DATE", creationDateString.toLocal8Bit().constData(), nullptr );
350 
351  GDALSetMetadataItem( outputDS.get(), "AUTHOR", mGeoPdfExportDetails.author.toLocal8Bit().constData(), nullptr );
352  const QString creator = QStringLiteral( "QGIS %1" ).arg( Qgis::version() );
353  GDALSetMetadataItem( outputDS.get(), "CREATOR", creator.toLocal8Bit().constData(), nullptr );
354  GDALSetMetadataItem( outputDS.get(), "PRODUCER", creator.toLocal8Bit().constData(), nullptr );
355  GDALSetMetadataItem( outputDS.get(), "SUBJECT", mGeoPdfExportDetails.subject.toLocal8Bit().constData(), nullptr );
356  GDALSetMetadataItem( outputDS.get(), "TITLE", mGeoPdfExportDetails.title.toLocal8Bit().constData(), nullptr );
357 
358  const QgsAbstractMetadataBase::KeywordMap keywords = mGeoPdfExportDetails.keywords;
359  QStringList allKeywords;
360  for ( auto it = keywords.constBegin(); it != keywords.constEnd(); ++it )
361  {
362  allKeywords.append( QStringLiteral( "%1: %2" ).arg( it.key(), it.value().join( ',' ) ) );
363  }
364  const QString keywordString = allKeywords.join( ';' );
365  GDALSetMetadataItem( outputDS.get(), "KEYWORDS", keywordString.toLocal8Bit().constData(), nullptr );
366  }
367  }
368  CPLSetThreadLocalConfigOption( "GDAL_PDF_DPI", nullptr );
369  }
370 #else
371  mError = ImageUnsupportedFormat;
372  return false;
373 #endif // !QT_NO_PRINTER
374  }
375  else if ( mFileFormat != QStringLiteral( "PDF" ) )
376  {
377  bool success = mImage.save( mFileName, mFileFormat.toLocal8Bit().data() );
378  if ( !success )
379  {
380  mError = ImageSaveFail;
381  return false;
382  }
383 
384  if ( mSaveWorldFile )
385  {
386  QFileInfo info = QFileInfo( mFileName );
387 
388  // build the world file name
389  QString outputSuffix = info.suffix();
390  bool skipWorldFile = false;
391  if ( outputSuffix == QStringLiteral( "tif" ) || outputSuffix == QStringLiteral( "tiff" ) )
392  {
393  gdal::dataset_unique_ptr outputDS( GDALOpen( mFileName.toLocal8Bit().constData(), GA_Update ) );
394  if ( outputDS )
395  {
396  skipWorldFile = true;
397  double a, b, c, d, e, f;
398  QgsMapSettingsUtils::worldFileParameters( mMapSettings, a, b, c, d, e, f );
399  c -= 0.5 * a;
400  c -= 0.5 * b;
401  f -= 0.5 * d;
402  f -= 0.5 * e;
403  double geoTransform[] = { c, a, b, f, d, e };
404  GDALSetGeoTransform( outputDS.get(), geoTransform );
405  GDALSetProjection( outputDS.get(), mMapSettings.destinationCrs().toWkt( QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL ).toLocal8Bit().constData() );
406  }
407  }
408 
409  if ( !skipWorldFile )
410  {
411  QString worldFileName = info.absolutePath() + '/' + info.completeBaseName() + '.'
412  + outputSuffix.at( 0 ) + outputSuffix.at( info.suffix().size() - 1 ) + 'w';
413  QFile worldFile( worldFileName );
414 
415  if ( worldFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) //don't use QIODevice::Text
416  {
417  QTextStream stream( &worldFile );
418  stream << QgsMapSettingsUtils::worldFileContent( mMapSettings );
419  }
420  }
421  }
422  }
423  }
424 
425  mTempPainter.reset();
426 #ifndef QT_NO_PRINTER
427  mPrinter.reset();
428 #endif
429 
430  return true;
431 }
432 
433 void QgsMapRendererTask::finished( bool result )
434 {
435  qDeleteAll( mAnnotations );
436  mAnnotations.clear();
437 
438  if ( result )
439  emit renderingComplete();
440  else
441  emit errorOccurred( mError );
442 }
443 
444 void QgsMapRendererTask::prepare()
445 {
446  if ( mGeoPDF )
447  {
448  mGeoPdfExporter = qgis::make_unique< QgsMapRendererTaskGeoPdfExporter >( mMapSettings );
449  if ( mGeoPdfExportDetails.includeFeatures )
450  {
451  mRenderedFeatureHandler = qgis::make_unique< QgsMapRendererTaskRenderedFeatureHandler >( static_cast< QgsMapRendererTaskGeoPdfExporter * >( mGeoPdfExporter.get() ), mMapSettings );
452  mMapSettings.addRenderedFeatureHandler( mRenderedFeatureHandler.get() );
453  }
454 
455  const QList< QgsMapLayer * > layers = mMapSettings.layers();
456  for ( const QgsMapLayer *layer : layers )
457  {
458  mLayerIdToLayerNameMap.insert( layer->id(), layer->name() );
459  mMapLayerOrder << layer->id();
460  }
461 
463  mJob->start();
464  return;
465  }
466 
467  mDestPainter = mPainter;
468 
469  if ( mFileFormat == QStringLiteral( "PDF" ) )
470  {
471 #ifndef QT_NO_PRINTER
472  mPrinter.reset( new QPrinter() );
473  mPrinter->setOutputFileName( mFileName );
474  mPrinter->setOutputFormat( QPrinter::PdfFormat );
475  mPrinter->setOrientation( QPrinter::Portrait );
476  // paper size needs to be given in millimeters in order to be able to set a resolution to pass onto the map renderer
477  QSizeF outputSize = mMapSettings.outputSize();
478  mPrinter->setPaperSize( outputSize * 25.4 / mMapSettings.outputDpi(), QPrinter::Millimeter );
479  mPrinter->setPageMargins( 0, 0, 0, 0, QPrinter::Millimeter );
480  mPrinter->setResolution( mMapSettings.outputDpi() );
481 
482  if ( !mForceRaster )
483  {
484  mTempPainter.reset( new QPainter( mPrinter.get() ) );
485  mDestPainter = mTempPainter.get();
486  }
487 #else
488  mError = ImageUnsupportedFormat;
489 #endif // ! QT_NO_PRINTER
490  }
491 
492  if ( !mDestPainter )
493  {
494  // save rendered map to an image file
495  mImage = QImage( mMapSettings.outputSize(), QImage::Format_ARGB32 );
496  if ( mImage.isNull() )
497  {
498  mErrored = true;
499  mError = ImageAllocationFail;
500  return;
501  }
502 
503  mImage.setDotsPerMeterX( 1000 * mMapSettings.outputDpi() / 25.4 );
504  mImage.setDotsPerMeterY( 1000 * mMapSettings.outputDpi() / 25.4 );
505 
506  mTempPainter.reset( new QPainter( &mImage ) );
507  mDestPainter = mTempPainter.get();
508  }
509 
510  if ( !mDestPainter )
511  {
512  mErrored = true;
513  return;
514  }
515 
516  mJob.reset( new QgsMapRendererCustomPainterJob( mMapSettings, mDestPainter ) );
517  static_cast< QgsMapRendererCustomPainterJob *>( mJob.get() )->prepare();
518 }
QgsAbstractGeoPdfExporter::ExportDetails::layerOrder
QStringList layerOrder
Optional list of layer IDs, in the order desired to appear in the generated GeoPDF file.
Definition: qgsabstractgeopdfexporter.h:285
QgsAbstractGeoPdfExporter::ControlPoint
Contains details of a control point used during georeferencing GeoPDF outputs.
Definition: qgsabstractgeopdfexporter.h:144
QgsGeometry::transform
OperationResult transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection direction=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)
Transforms this geometry as described by the coordinate transform ct.
Definition: qgsgeometry.cpp:2836
Qgis::version
static QString version()
Version string.
Definition: qgis.cpp:276
qgsfeaturerequest.h
QgsRenderContext::expressionContext
QgsExpressionContext & expressionContext()
Gets the expression context.
Definition: qgsrendercontext.h:580
QgsMapSettings::outputSize
QSize outputSize() const
Returns the size of the resulting map image.
Definition: qgsmapsettings.cpp:234
QgsRenderContext::fromMapSettings
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
Definition: qgsrendercontext.cpp:170
QgsRenderedFeatureHandlerInterface::handleRenderedFeature
virtual void handleRenderedFeature(const QgsFeature &feature, const QgsGeometry &renderedBounds, const QgsRenderedFeatureHandlerInterface::RenderedFeatureContext &context)=0
Called whenever a feature is rendered during a map render job.
qgsannotation.h
QgsCoordinateReferenceSystem::WKT_PREFERRED_GDAL
@ WKT_PREFERRED_GDAL
Preferred format for conversion of CRS to WKT for use with the GDAL library.
Definition: qgscoordinatereferencesystem.h:680
QgsMapRendererStagedRenderJob::currentLayerOpacity
double currentLayerOpacity() const
Returns the opacity for the current layer about to be rendered in the next render operation.
Definition: qgsmaprendererstagedrenderjob.cpp:240
QgsMapRendererTask::run
bool run() override
Performs the task's operation.
Definition: qgsmaprenderertask.cpp:170
QgsRenderContext::setPainter
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
Definition: qgsrendercontext.h:475
QgsAbstractGeoPdfExporter::ComponentLayerDetail::mapLayerId
QString mapLayerId
Associated map layer ID, or an empty string if this component layer is not associated with a map laye...
Definition: qgsabstractgeopdfexporter.h:123
QgsMapRendererTask::renderingComplete
void renderingComplete()
Emitted when the map rendering is successfully completed.
QgsMapRendererStagedRenderJob::currentLayerCompositionMode
QPainter::CompositionMode currentLayerCompositionMode() const
Returns the composition mode for the current layer about to be rendered in the next render operation.
Definition: qgsmaprendererstagedrenderjob.cpp:250
qgsrenderedfeaturehandlerinterface.h
QgsRenderContext
Definition: qgsrendercontext.h:57
QgsMapRendererTask::addDecorations
void addDecorations(const QList< QgsMapDecoration * > &decorations)
Adds decorations to be rendered on the map.
Definition: qgsmaprenderertask.cpp:154
qgsogrutils.h
QgsAbstractGeoPdfExporter::ExportDetails
Definition: qgsabstractgeopdfexporter.h:197
qgsmaprendererstagedrenderjob.h
QgsAbstractGeoPdfExporter::GeoReferencedSection
Definition: qgsabstractgeopdfexporter.h:163
QgsMapToPixel::toMapCoordinates
QgsPointXY toMapCoordinates(int x, int y) const
Transform device coordinates to map (world) coordinates.
Definition: qgsmaptopixel.cpp:108
QgsAbstractGeoPdfExporter::ComponentLayerDetail::opacity
double opacity
Component opacity.
Definition: qgsabstractgeopdfexporter.h:135
QgsAbstractGeoPdfExporter::ExportDetails::layerIdToPdfLayerTreeNameMap
QMap< QString, QString > layerIdToPdfLayerTreeNameMap
Optional map of map layer ID to custom layer tree name to show in the created PDF file.
Definition: qgsabstractgeopdfexporter.h:268
QgsAbstractGeoPdfExporter::ExportDetails::title
QString title
Metadata title tag.
Definition: qgsabstractgeopdfexporter.h:224
QgsRenderedFeatureHandlerInterface::RenderedFeatureContext::renderContext
const QgsRenderContext & renderContext
The render context which was used while rendering feature.
Definition: qgsrenderedfeaturehandlerinterface.h:65
QgsExpressionContext::variable
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
Definition: qgsexpressioncontext.cpp:296
QgsRectangle
Definition: qgsrectangle.h:41
QgsAbstractGeoPdfExporter::ExportDetails::keywords
QgsAbstractMetadataBase::KeywordMap keywords
Metadata keyword map.
Definition: qgsabstractgeopdfexporter.h:227
QgsRenderedFeatureHandlerInterface
Definition: qgsrenderedfeaturehandlerinterface.h:46
QgsAbstractGeoPdfExporter::ExportDetails::georeferencedSections
QList< QgsAbstractGeoPdfExporter::GeoReferencedSection > georeferencedSections
List of georeferenced sections.
Definition: qgsabstractgeopdfexporter.h:206
QgsMapRendererTask::ImageAllocationFail
@ ImageAllocationFail
Image allocation failure.
Definition: qgsmaprenderertask.h:55
QgsMapSettings::extent
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
Definition: qgsmapsettings.cpp:74
QgsAbstractGeoPdfExporter::ComponentLayerDetail::compositionMode
QPainter::CompositionMode compositionMode
Component composition mode.
Definition: qgsabstractgeopdfexporter.h:132
QgsMapRendererTask::addAnnotations
void addAnnotations(const QList< QgsAnnotation * > &annotations)
Adds annotations to be rendered on the map.
Definition: qgsmaprenderertask.cpp:142
QgsTask::cancel
virtual void cancel()
Notifies the task that it should terminate.
Definition: qgstaskmanager.cpp:91
QgsFeatureRequest::ALL_ATTRIBUTES
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
Definition: qgsfeaturerequest.h:295
QgsMapSettings::addRenderedFeatureHandler
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
Definition: qgsmapsettings.cpp:685
QgsAnnotation
Abstract base class for annotation items which are drawn over a map.
Definition: qgsannotation.h:49
QgsAbstractGeoPdfExporter::VectorComponentDetail
Contains information relating to a single PDF layer in the GeoPDF export.
Definition: qgsabstractgeopdfexporter.h:327
QgsMapRendererTask::finished
void finished(bool result) override
If the task is managed by a QgsTaskManager, this will be called after the task has finished (whether ...
Definition: qgsmaprenderertask.cpp:433
qgsmapsettingsutils.h
QgsAbstractGeoPdfExporter::RenderedFeature
Contains information about a feature rendered inside the PDF.
Definition: qgsabstractgeopdfexporter.h:84
gdal::dataset_unique_ptr
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
Definition: qgsogrutils.h:134
QgsAbstractGeoPdfExporter::ComponentLayerDetail::sourcePdfPath
QString sourcePdfPath
File path to the (already created) PDF to use as the source for this component layer.
Definition: qgsabstractgeopdfexporter.h:129
QgsMapRendererTask::ImageUnsupportedFormat
@ ImageUnsupportedFormat
Format is unsupported on the platform.
Definition: qgsmaprenderertask.h:57
QgsCoordinateReferenceSystem::toWkt
QString toWkt(WktVariant variant=WKT1_GDAL, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Definition: qgscoordinatereferencesystem.cpp:1931
QgsMapRendererTask::errorOccurred
void errorOccurred(int error)
Emitted when map rendering failed.
QgsMapRendererStagedRenderJob::nextPart
bool nextPart()
Iterates to the next part to render.
Definition: qgsmaprendererstagedrenderjob.cpp:163
qgsannotationmanager.h
QgsMapRendererStagedRenderJob::currentLayerId
QString currentLayerId() const
Returns the ID of the current layer about to be rendered in the next render operation.
Definition: qgsmaprendererstagedrenderjob.cpp:225
QgsMapSettingsUtils::worldFileContent
static QString worldFileContent(const QgsMapSettings &mapSettings)
Creates the content of a world file.
Definition: qgsmapsettingsutils.cpp:128
QgsMapRendererStagedRenderJob::RenderLabelsByMapLayer
@ RenderLabelsByMapLayer
Labels should be rendered in individual stages by map layer. This allows separation of labels belongi...
Definition: qgsmaprendererstagedrenderjob.h:42
qgsvectorlayer.h
QgsPointXY
Definition: qgspointxy.h:43
QgsMapRendererTask::QgsMapRendererTask
QgsMapRendererTask(const QgsMapSettings &ms, const QString &fileName, const QString &fileFormat=QString("PNG"), bool forceRaster=false, bool geoPdf=false, const QgsAbstractGeoPdfExporter::ExportDetails &geoPdfExportDetails=QgsAbstractGeoPdfExporter::ExportDetails())
Constructor for QgsMapRendererTask to render a map to an image file.
Definition: qgsmaprenderertask.cpp:119
QgsMapSettings::destinationCrs
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
Definition: qgsmapsettings.cpp:317
QgsMapRendererCustomPainterJob
Definition: qgsmaprenderercustompainterjob.h:63
QgsRenderedFeatureHandlerInterface::RenderedFeatureContext
Definition: qgsrenderedfeaturehandlerinterface.h:51
QgsMapSettingsUtils::worldFileParameters
static void worldFileParameters(const QgsMapSettings &mapSettings, double &a, double &b, double &c, double &d, double &e, double &f)
Computes the six parameters of a world file.
Definition: qgsmapsettingsutils.cpp:83
QgsAbstractGeoPdfExporter::ExportDetails::includeFeatures
bool includeFeatures
true if feature vector information (such as attributes) should be exported.
Definition: qgsabstractgeopdfexporter.h:249
QgsAbstractGeoPdfExporter::ComponentLayerDetail
Contains details of a particular input component to be used during PDF composition.
Definition: qgsabstractgeopdfexporter.h:116
c
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
Definition: porting_processing.dox:1
QgsGeometry
Definition: qgsgeometry.h:122
QgsAbstractGeoPdfExporter::GeoReferencedSection::pageBoundsMm
QgsRectangle pageBoundsMm
Bounds of the georeferenced section on the page, in millimeters.
Definition: qgsabstractgeopdfexporter.h:171
QgsVectorLayer
Definition: qgsvectorlayer.h:385
QgsMapRendererStagedRenderJob::isFinished
bool isFinished() const
Returns true if the job is finished, and nothing remains to render.
Definition: qgsmaprendererstagedrenderjob.cpp:220
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsAbstractGeoPdfExporter::GeoReferencedSection::controlPoints
QList< QgsAbstractGeoPdfExporter::ControlPoint > controlPoints
List of control points corresponding to this georeferenced section.
Definition: qgsabstractgeopdfexporter.h:184
qgsabstractgeopdfexporter.h
QgsGeometry::convertToMultiType
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
Definition: qgsgeometry.cpp:1468
QgsAbstractGeoPdfExporter::ExportDetails::author
QString author
Metadata author tag.
Definition: qgsabstractgeopdfexporter.h:209
QgsRectangle::height
double height() const
Returns the height of the rectangle.
Definition: qgsrectangle.h:209
QgsAbstractGeoPdfExporter::GeoReferencedSection::crs
QgsCoordinateReferenceSystem crs
Coordinate reference system for georeferenced section.
Definition: qgsabstractgeopdfexporter.h:181
QgsRectangle::yMinimum
double yMinimum() const
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:177
QgsMapRendererStagedRenderJob
Definition: qgsmaprendererstagedrenderjob.h:32
QgsRenderContext::Antialiasing
@ Antialiasing
Use antialiasing while drawing.
Definition: qgsrendercontext.h:78
QgsMapRendererStagedRenderJob::renderCurrentPart
bool renderCurrentPart(QPainter *painter)
Renders the current part of the map to the specified painter.
Definition: qgsmaprendererstagedrenderjob.cpp:95
QgsAbstractMetadataBase::KeywordMap
QMap< QString, QStringList > KeywordMap
Map of vocabulary string to keyword list.
Definition: qgsabstractmetadatabase.h:78
QgsMapSettings::layers
QList< QgsMapLayer * > layers() const
Gets list of layers for map rendering The layers are stored in the reverse order of how they are rend...
Definition: qgsmapsettings.cpp:281
QgsAbstractGeoPdfExporter::ExportDetails::subject
QString subject
Metadata subject tag.
Definition: qgsabstractgeopdfexporter.h:221
QgsAbstractGeoPdfExporter::ExportDetails::creationDateTime
QDateTime creationDateTime
Metadata creation datetime.
Definition: qgsabstractgeopdfexporter.h:218
QgsFeature
Definition: qgsfeature.h:55
QgsMapDecoration
Interface for map decorations.
Definition: qgsmapdecoration.h:32
QgsMapRendererTask::~QgsMapRendererTask
~QgsMapRendererTask() override
qgslogger.h
QgsMapSettings::outputDpi
double outputDpi() const
Returns DPI used for conversion between real world units (e.g.
Definition: qgsmapsettings.cpp:262
QgsRenderContext::painter
QPainter * painter()
Returns the destination QPainter for the render operation.
Definition: qgsrendercontext.h:174
QgsMapRendererTask::ImageSaveFail
@ ImageSaveFail
Image save failure.
Definition: qgsmaprenderertask.h:56
QgsAbstractGeoPdfExporter::ComponentLayerDetail::name
QString name
User-friendly name for the generated PDF layer.
Definition: qgsabstractgeopdfexporter.h:120
QgsMapSettings
Definition: qgsmapsettings.h:86
qgsmaprenderertask.h
QgsMapRendererTask::cancel
void cancel() override
Notifies the task that it should terminate.
Definition: qgsmaprenderertask.cpp:160
QgsRenderedFeatureHandlerInterface::usedAttributes
virtual QSet< QString > usedAttributes(QgsVectorLayer *layer, const QgsRenderContext &context) const
Returns a list of attributes required by this handler, for the specified layer.
Definition: qgsrenderedfeaturehandlerinterface.h:93
QgsAbstractGeoPdfExporter
Definition: qgsabstractgeopdfexporter.h:54
QgsMapSettings::mapToPixel
const QgsMapToPixel & mapToPixel() const
Definition: qgsmapsettings.h:433
QgsAbstractGeoPdfExporter::ExportDetails::dpi
double dpi
Output DPI.
Definition: qgsabstractgeopdfexporter.h:203
QgsRectangle::width
double width() const
Returns the width of the rectangle.
Definition: qgsrectangle.h:202
QgsAbstractGeoPdfExporter::ExportDetails::pageSizeMm
QSizeF pageSizeMm
Page size, in millimeters.
Definition: qgsabstractgeopdfexporter.h:200
QgsRectangle::xMinimum
double xMinimum() const
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:167
QgsRenderContext::flags
Flags flags() const
Returns combination of flags used for rendering.
Definition: qgsrendercontext.cpp:160
QgsTask::isCanceled
bool isCanceled() const
Will return true if task should terminate ASAP.
Definition: qgstaskmanager.cpp:118
QgsTask
Abstract base class for long running background tasks. Tasks can be controlled directly,...
Definition: qgstaskmanager.h:52