QGIS API Documentation  3.21.0-Master (5b68dc587e)
qgsabstractgeopdfexporter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsabstractgeopdfexporter.h
3  --------------------------
4  begin : August 2019
5  copyright : (C) 2019 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 #ifndef QGSABSTRACTGEOPDFEXPORTER_H
17 #define QGSABSTRACTGEOPDFEXPORTER_H
18 
19 #include "qgis_core.h"
20 #include <QList>
21 #include <QTemporaryDir>
22 #include <QMutex>
23 #include <QDateTime>
24 #include <QPainter>
25 
26 #include "qgsfeature.h"
28 #include "qgspolygon.h"
30 
31 #define SIP_NO_FILE
32 
33 
34 class QgsGeoPdfRenderedFeatureHandler;
35 
55 class CORE_EXPORT QgsAbstractGeoPdfExporter
56 {
57  public:
58 
65  static bool geoPDFCreationAvailable();
66 
73  static QString geoPDFAvailabilityExplanation();
74 
79 
80  virtual ~QgsAbstractGeoPdfExporter() = default;
81 
86  {
87 
91  RenderedFeature() = default;
92 
96  RenderedFeature( const QgsFeature &feature, const QgsGeometry &renderedBounds )
97  : feature( feature )
98  , renderedBounds( renderedBounds )
99  {}
100 
105 
110  };
111 
117  struct CORE_EXPORT ComponentLayerDetail
118  {
119 
121  QString name;
122 
124  QString mapLayerId;
125 
127  QString group;
128 
130  QString sourcePdfPath;
131 
133  QPainter::CompositionMode compositionMode = QPainter::CompositionMode_SourceOver;
134 
136  double opacity = 1.0;
137 
138  };
139 
146  {
147 
152  ControlPoint( const QgsPointXY &pagePoint, const QgsPointXY &geoPoint )
153  : pagePoint( pagePoint )
154  , geoPoint( geoPoint )
155  {}
156 
159 
162  };
163 
165  {
166 
173 
180 
183 
185  QList< QgsAbstractGeoPdfExporter::ControlPoint > controlPoints;
186 
187  };
188 
196  void pushRenderedFeature( const QString &layerId, const QgsAbstractGeoPdfExporter::RenderedFeature &feature, const QString &group = QString() );
197 
199  {
201  QSizeF pageSizeMm;
202 
204  double dpi = 300;
205 
207  QList< QgsAbstractGeoPdfExporter::GeoReferencedSection > georeferencedSections;
208 
210  QString author;
211 
213  QString producer;
214 
216  QString creator;
217 
219  QDateTime creationDateTime;
220 
222  QString subject;
223 
225  QString title;
226 
229 
236  bool useIso32000ExtensionFormatGeoreferencing = true;
237 
245  bool useOgcBestPracticeFormatGeoreferencing = false;
246 
250  bool includeFeatures = true;
251 
262  QMap< QString, QString > customLayerTreeGroups;
263 
269  QMap< QString, QString > layerIdToPdfLayerTreeNameMap;
270 
277  QMap< QString, bool > initialLayerVisibility;
278 
286  QStringList layerOrder;
287 
288  };
289 
303  bool finalize( const QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > &components, const QString &destinationFile, const ExportDetails &details );
304 
308  QString errorMessage() { return mErrorMessage; }
309 
313  QString generateTemporaryFilepath( const QString &filename ) const;
314 
321  static bool compositionModeSupported( QPainter::CompositionMode mode );
322 
323  protected:
324 
329  {
331  QString name;
332 
334  QString mapLayerId;
335 
337  QString group;
338 
341 
344 
347 
348  };
349 
350  private:
351 
352  QMutex mMutex;
353  QMap< QString, QMap< QString, QgsFeatureList > > mCollatedFeatures;
354 
358  virtual VectorComponentDetail componentDetailForLayerId( const QString &layerId ) = 0;
359 
360  QList< VectorComponentDetail > mVectorComponents;
361 
362  QString mErrorMessage;
363  QTemporaryDir mTemporaryDir;
364 
365 
366  bool saveTemporaryLayers();
367 
368  QString createCompositionXml( const QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > &components, const ExportDetails &details );
369 
373  static QString compositionModeToString( QPainter::CompositionMode mode );
374 
375  friend class TestQgsLayoutGeoPdfExport;
376  friend class TestQgsGeoPdfExport;
377 };
378 
379 #endif //QGSABSTRACTGEOPDFEXPORTER_H
380 
381 
382 
Abstract base class for GeoPDF exporters.
virtual ~QgsAbstractGeoPdfExporter()=default
QString errorMessage()
Returns the last error message encountered during the export.
QgsAbstractGeoPdfExporter()=default
Constructor for QgsAbstractGeoPdfExporter.
QMap< QString, QStringList > KeywordMap
Map of vocabulary string to keyword list.
This class represents a coordinate reference system (CRS).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
A class to represent a 2D point.
Definition: qgspointxy.h:59
Polygon geometry type.
Definition: qgspolygon.h:34
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains details of a particular input component to be used during PDF composition.
QString sourcePdfPath
File path to the (already created) PDF to use as the source for this component layer.
QString mapLayerId
Associated map layer ID, or an empty string if this component layer is not associated with a map laye...
QString group
Optional group name, for arranging layers in top-level groups.
QString name
User-friendly name for the generated PDF layer.
Contains details of a control point used during georeferencing GeoPDF outputs.
ControlPoint(const QgsPointXY &pagePoint, const QgsPointXY &geoPoint)
Constructor for ControlPoint, at the specified pagePoint (in millimeters) and geoPoint (in CRS units)...
QgsPointXY pagePoint
Coordinate on the page of the control point, in millimeters.
QgsPointXY geoPoint
Georeferenced coordinate of the control point, in CRS units.
QgsAbstractMetadataBase::KeywordMap keywords
Metadata keyword map.
QMap< QString, QString > layerIdToPdfLayerTreeNameMap
Optional map of map layer ID to custom layer tree name to show in the created PDF file.
QDateTime creationDateTime
Metadata creation datetime.
QList< QgsAbstractGeoPdfExporter::GeoReferencedSection > georeferencedSections
List of georeferenced sections.
QMap< QString, bool > initialLayerVisibility
Optional map of map layer ID to initial visibility state.
QMap< QString, QString > customLayerTreeGroups
Optional map of map layer ID to custom logical layer tree group in created PDF file.
QStringList layerOrder
Optional list of layer IDs, in the order desired to appear in the generated GeoPDF file.
QgsRectangle pageBoundsMm
Bounds of the georeferenced section on the page, in millimeters.
QgsCoordinateReferenceSystem crs
Coordinate reference system for georeferenced section.
QgsPolygon pageBoundsPolygon
Bounds of the georeferenced section on the page, in millimeters, as a free-form polygon.
QList< QgsAbstractGeoPdfExporter::ControlPoint > controlPoints
List of control points corresponding to this georeferenced section.
Contains information about a feature rendered inside the PDF.
RenderedFeature()=default
Constructor for RenderedFeature.
RenderedFeature(const QgsFeature &feature, const QgsGeometry &renderedBounds)
Constructor for RenderedFeature.
QgsGeometry renderedBounds
Bounds, in PDF units, of rendered feature.
Contains information relating to a single PDF layer in the GeoPDF export.
QString sourceVectorLayer
Layer name in vector dataset to use as the source.
QString sourceVectorPath
File path to the (already created) vector dataset to use as the source for this component layer.
QString name
User-friendly name for the generated PDF layer.