28 #include "cpl_string.h" 32 #include <QMutexLocker> 33 #include <QDomDocument> 34 #include <QDomElement> 42 : mExporter( exporter )
44 , mLayerIds( layerIds )
52 const double pageHeightPdfUnits = pageSizeInches.
height() * 72;
53 const double pageWidthPdfUnits = pageSizeInches.
width() * 72;
55 QTransform mapTransform;
56 QPolygonF mapRectPoly = QPolygonF( QRectF( 0, 0, map->rect().width(), map->rect().height() ) );
58 mapRectPoly.pop_back();
60 QPolygonF mapRectInLayout = map->mapToScene( mapRectPoly );
63 QTransform::quadToQuad( mapRectPoly, mapRectInLayout, mMapToLayoutTransform );
66 mLayoutToPdfTransform = QTransform::fromTranslate( 0, pageHeightPdfUnits ).scale( pageWidthPdfUnits / pageSizeLayoutUnits.width(),
67 -pageHeightPdfUnits / pageSizeLayoutUnits.height() );
76 if ( !mLayerIds.contains( layerId ) )
79 const QString theme = ( mMap->mExportThemes.isEmpty() || mMap->mExportThemeIt == mMap->mExportThemes.end() ) ? QString() : *mMap->mExportThemeIt;
84 transformed.
transform( pixelToMapItemTransform );
86 transformed.transform( mMapToLayoutTransform );
88 transformed.transform( mLayoutToPdfTransform );
91 transformed.convertToMultiType();
102 QTransform mMapToLayoutTransform;
103 QTransform mLayoutToPdfTransform;
106 QStringList mLayerIds;
114 QStringList exportableLayerIds;
115 const QMap< QString, QgsMapLayer * > layers = mLayout->
project()->
mapLayers(
true );
116 for (
auto it = layers.constBegin(); it != layers.constEnd(); ++it )
118 if (
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer * >( it.value() ) )
120 const QVariant v = vl->customProperty( QStringLiteral(
"geopdf/includeFeatures" ) );
121 if ( !v.isValid() || v.toBool() )
123 exportableLayerIds << vl->id();
126 const QString groupName = vl->customProperty( QStringLiteral(
"geopdf/groupName" ) ).toString();
127 if ( !groupName.isEmpty() )
128 mCustomLayerTreeGroups.insert( vl->id(), groupName );
133 QList< QgsLayoutItemMap * > maps;
137 QgsGeoPdfRenderedFeatureHandler *handler =
new QgsGeoPdfRenderedFeatureHandler( map,
this, exportableLayerIds );
138 mMapHandlers.insert( map, handler );
146 for (
auto it = mMapHandlers.constBegin(); it != mMapHandlers.constEnd(); ++it )
148 it.key()->removeRenderedFeatureHandler( it.value() );
158 detail.
name = layer ? layer->
name() : layerId;
160 if (
const QgsVectorLayer *vl = qobject_cast< const QgsVectorLayer * >( layer ) )
const QgsRenderContext & renderContext
The render context which was used while rendering feature.
Base class for all map layer types.
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.
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.
QgsLayoutMeasurement convert(QgsLayoutMeasurement measurement, QgsUnitTypes::LayoutUnit targetUnits) const
Converts a measurement from one unit to another.
Handles GeoPDF export specific setup, cleanup and processing steps.
A geometry is the spatial representation of a feature.
QString displayAttribute
Field name for display.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsLayoutGeoPdfExporter(QgsLayout *layout)
Constructor for QgsLayoutGeoPdfExporter, associated with the specified layout.
QgsLayoutRenderContext & renderContext()
Returns a reference to the layout's render context, which stores information relating to the current ...
QVariant variable(const QString &name) const
Fetches a matching variable from the context.
void layoutItems(QList< T *> &itemList) const
Returns a list of layout items of a specific type.
QString mapLayerId
Associated map layer ID.
Layout graphical items for displaying a map.
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.
QgsLayoutPageCollection * pageCollection()
Returns a pointer to the layout's page collection, which stores and manages page items in the layout...
An interface for classes which provider custom handlers for features rendered as part of a map render...
Contains information about a feature rendered inside the PDF.
static const QString ALL_ATTRIBUTES
A special attribute that if set matches all attributes.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts, annotations, canvases, etc.
int page() const
Returns the page the item is currently on, with the first page returning 0.
Contains information relating to a single PDF layer in the GeoPDF export.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
QMap< QString, QgsMapLayer * > mapLayers(const bool validOnly=false) const
Returns a map of all registered layers by layer ID.
QgsExpressionContext & expressionContext()
Gets the expression context.
~QgsLayoutGeoPdfExporter() override
virtual QSet< QString > usedAttributes(QgsVectorLayer *layer, const QgsRenderContext &context) const
Returns a list of attributes required by this handler, for the specified layer.
Contains information about the context of a rendering operation.
const QgsLayoutMeasurementConverter & measurementConverter() const
Returns the layout measurement converter to be used in the layout.
QgsProject * project() const
The project associated with the layout.
Q_INVOKABLE QgsMapLayer * mapLayer(const QString &layerId) const
Retrieve a pointer to a registered layer by layer ID.
double convertToLayoutUnits(QgsLayoutMeasurement measurement) const
Converts a measurement into the layout's native units.
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map.
This class provides a method of storing sizes, consisting of a width and height, for use in QGIS layo...
double scaleFactor() const
Returns the scaling factor for the render to convert painter units to physical sizes.
Represents a vector layer which manages a vector based data sets.
double height() const
Returns the height of the size.
QString name
User-friendly name for the generated PDF layer.
double width() const
Returns the width of the size.