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();
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
A geometry is the spatial representation of a feature.
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.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
Handles GeoPDF export specific setup, cleanup and processing steps.
QStringList layerOrder() const
Optional list of map layer IDs in the order they should be shown in the generated GeoPDF layer tree.
QgsLayoutGeoPdfExporter(QgsLayout *layout)
Constructor for QgsLayoutGeoPdfExporter, associated with the specified layout.
~QgsLayoutGeoPdfExporter() override
Layout graphical items for displaying a map.
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map.
QgsLayoutSize pageSize() const
Returns the size of the page.
int page() const
Returns the page the item is currently on, with the first page returning 0.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, QgsUnitTypes::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
const QgsLayout * layout() const
Returns the layout the object is attached to.
QgsLayoutItemPage * page(int pageNumber)
Returns a specific page (by pageNumber) from the collection.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
double height() const
Returns the height of the size.
double width() const
Returns the width of the size.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout.
void layoutItems(QList< T * > &itemList) const
Returns a list of layout items of a specific type.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
QVariant customProperty(const QString &key, const QVariant &defaultValue=QVariant()) const
Read a custom property from the layout.
QgsProject * project() const
The project associated with the layout.
Base class for all map layer types.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
QgsLayerTree * layerTreeRoot() const
Returns pointer to the root (invisible) node of the project's layer tree.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
Contains information about the context of a rendering operation.
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
QgsExpressionContext & expressionContext()
Gets the expression context.
An interface for classes which provider custom handlers for features rendered as part of a map render...
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.
virtual QSet< QString > usedAttributes(QgsVectorLayer *layer, const QgsRenderContext &context) const
Returns a list of attributes required by this handler, for the specified layer.
Represents a vector layer which manages a vector based data sets.
Contains information about a feature rendered inside the PDF.
Contains information relating to a single PDF layer in the GeoPDF export.
const QgsRenderContext & renderContext
The render context which was used while rendering feature.