QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
29 #include "cpl_string.h"
33 #include <QMutexLocker>
34 #include <QDomDocument>
35 #include <QDomElement>
43 : mExporter( exporter )
45 , mLayerIds( layerIds )
53 const double pageHeightPdfUnits = pageSizeInches.
height() * 72;
54 const double pageWidthPdfUnits = pageSizeInches.
width() * 72;
56 QTransform mapTransform;
57 QPolygonF mapRectPoly = QPolygonF( QRectF( 0, 0, map->rect().width(), map->rect().height() ) );
59 mapRectPoly.pop_back();
61 QPolygonF mapRectInLayout = map->mapToScene( mapRectPoly );
64 QTransform::quadToQuad( mapRectPoly, mapRectInLayout, mMapToLayoutTransform );
67 mLayoutToPdfTransform = QTransform::fromTranslate( 0, pageHeightPdfUnits ).scale( pageWidthPdfUnits / pageSizeLayoutUnits.width(),
68 -pageHeightPdfUnits / pageSizeLayoutUnits.height() );
77 if ( !mLayerIds.contains( layerId ) )
80 const QString theme = ( mMap->mExportThemes.isEmpty() || mMap->mExportThemeIt == mMap->mExportThemes.end() ) ? QString() : *mMap->mExportThemeIt;
85 transformed.
transform( pixelToMapItemTransform );
87 transformed.
transform( mMapToLayoutTransform );
89 transformed.
transform( mLayoutToPdfTransform );
103 QTransform mMapToLayoutTransform;
104 QTransform mLayoutToPdfTransform;
107 QStringList mLayerIds;
115 QStringList exportableLayerIds;
116 const QMap< QString, QgsMapLayer * > layers = mLayout->
project()->
mapLayers(
true );
117 for (
auto it = layers.constBegin(); it != layers.constEnd(); ++it )
121 const QVariant visibility = ml->customProperty( QStringLiteral(
"geopdf/initiallyVisible" ),
true );
122 mInitialLayerVisibility.insert( ml->id(), !visibility.isValid() ?
true : visibility.toBool() );
125 const QVariant v = ml->customProperty( QStringLiteral(
"geopdf/includeFeatures" ) );
126 if ( !v.isValid() || v.toBool() )
128 exportableLayerIds << ml->id();
132 const QString groupName = ml->customProperty( QStringLiteral(
"geopdf/groupName" ) ).toString();
133 if ( !groupName.isEmpty() )
134 mCustomLayerTreeGroups.insert( ml->id(), groupName );
139 QList< QgsLayoutItemMap * > maps;
143 QgsGeoPdfRenderedFeatureHandler *handler =
new QgsGeoPdfRenderedFeatureHandler( map,
this, exportableLayerIds );
144 mMapHandlers.insert( map, handler );
149 QStringList geoPdfLayerOrder;
150 const QString presetLayerOrder = mLayout->
customProperty( QStringLiteral(
"pdfLayerOrder" ) ).toString();
151 if ( !presetLayerOrder.isEmpty() )
152 geoPdfLayerOrder = presetLayerOrder.split( QStringLiteral(
"~~~" ) );
155 for (
auto it = geoPdfLayerOrder.rbegin(); it != geoPdfLayerOrder.rend(); ++it )
168 mLayerOrder << layer->id();
174 for (
auto it = mMapHandlers.constBegin(); it != mMapHandlers.constEnd(); ++it )
176 it.key()->removeRenderedFeatureHandler( it.value() );
184 VectorComponentDetail detail;
186 detail.
name = layer ? layer->
name() : layerId;
187 detail.mapLayerId = layerId;
188 if (
const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
190 detail.displayAttribute = vl->displayField();
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsLayoutGeoPdfExporter(QgsLayout *layout)
Constructor for QgsLayoutGeoPdfExporter, associated with the specified layout.
QgsLayoutSize pageSize() const
Returns the size of the page.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
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.
double width() const
Returns the width of the size.
QgsExpressionContext & expressionContext()
Gets the expression context.
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.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Handles GeoPDF export specific setup, cleanup and processing steps.
Contains information about the context of a rendering operation.
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map.
int page() const
Returns the page the item is currently on, with the first page returning 0.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
const QgsRenderContext & renderContext
The render context which was used while rendering feature.
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, QgsUnitTypes::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
An interface for classes which provider custom handlers for features rendered as part of a map render...
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
QStringList layerOrder() const
Optional list of map layer IDs in the order they should be shown in the generated GeoPDF layer tree.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
Contains information relating to a single PDF layer in the GeoPDF export.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
Contains information about a feature rendered inside the PDF.
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
double height() const
Returns the height of the size.
Layout graphical items for displaying a map.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
A geometry is the spatial representation of a feature.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Represents a vector layer which manages a vector based data sets.
Base class for all map layer types.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsProject * project() const
The project associated with the layout.
virtual QSet< QString > usedAttributes(QgsVectorLayer *layer, const QgsRenderContext &context) const
Returns a list of attributes required by this handler, for the specified layer.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
~QgsLayoutGeoPdfExporter() override