35 ,
mSize( QSize( 0, 0 ) )
38 ,
mFlags(
Qgis::MapSettingsFlag::Antialiasing |
Qgis::MapSettingsFlag::UseAdvancedEffects |
Qgis::MapSettingsFlag::DrawLabeling |
Qgis::MapSettingsFlag::DrawSelection )
57 ext.
scale( ratio, center );
63 QgsDebugMsgLevel( QStringLiteral(
"Magnification factor: %1 dpi: %2 ratio: %3" ).arg( factor ).arg(
mDpi ).arg( ratio ), 3 );
138 if (
extent.width() > 0 &&
145 const double xMean = ( std::fabs(
extent.xMinimum() ) + std::fabs(
extent.xMaximum() ) ) * 0.5;
146 const double yMean = ( std::fabs(
extent.yMinimum() ) + std::fabs(
extent.yMaximum() ) ) * 0.5;
148 const double xRange =
extent.width() / xMean;
149 const double yRange =
extent.height() / yMean;
151 static const double MIN_PROPORTION = 1e-12;
152 if ( xRange < MIN_PROPORTION || yRange < MIN_PROPORTION )
159 const double myHeight =
mSize.height();
160 const double myWidth =
mSize.width();
162 if ( !myWidth || !myHeight )
169 const double mapUnitsPerPixelY =
mExtent.height() / myHeight;
170 const double mapUnitsPerPixelX =
mExtent.width() / myWidth;
171 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
175 dymin =
mExtent.yMinimum(), dymax =
mExtent.yMaximum(), whitespace;
177 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
214 dxmin = std::min( p1.
x(), std::min( p2.
x(), std::min( p3.
x(), p4.
x() ) ) );
215 dymin = std::min( p1.
y(), std::min( p2.
y(), std::min( p3.
y(), p4.
y() ) ) );
216 dxmax = std::max( p1.
x(), std::max( p2.
x(), std::max( p3.
x(), p4.
x() ) ) );
217 dymax = std::max( p1.
y(), std::max( p2.
y(), std::max( p3.
y(), p4.
y() ) ) );
236void QgsMapSettings::matchRasterizedRenderingPolicyToFlags()
307 const QList<QgsMapLayer * > mapLayers =
layers( expandGroupLayers );
309 res.reserve( mapLayers.size() );
318 const QList<QgsMapLayer *> actualLayers = _qgis_listQPointerToRaw(
mLayers );
319 if ( !expandGroupLayers )
322 QList< QgsMapLayer * > result;
324 std::function< void(
const QList< QgsMapLayer * >&
layers ) > expandLayers;
325 expandLayers = [&result, &expandLayers](
const QList< QgsMapLayer * > &
layers )
329 if (
QgsGroupLayer *groupLayer = qobject_cast< QgsGroupLayer * >( layer ) )
331 expandLayers( groupLayer->childLayers() );
340 expandLayers( actualLayers );
347 const QList<QgsMapLayer *> actualLayers = _qgis_listQPointerToRaw(
mLayers );
352 T tLayer = qobject_cast<T>( layer );
364 auto filteredList =
layers;
365 filteredList.erase( std::remove_if( filteredList.begin(), filteredList.end(),
368 return !layer || !layer->isSpatial();
369 } ), filteredList.end() );
371 mLayers = _qgis_listRawToQPointer( filteredList );
426 matchRasterizedRenderingPolicyToFlags();
434 mFlags &= ~(
static_cast< int >( flag ) );
435 matchRasterizedRenderingPolicyToFlags();
445 return mFlags.testFlag( flag );
505 poly << m2p.
toMapCoordinates(
static_cast<double>( sz.width() + buffer ),
static_cast<double>( sz.height() + buffer ) ).
toQPointF();
524 if ( !mHasTransformContext )
525 QgsDebugMsgLevel( QStringLiteral(
"No QgsCoordinateTransformContext context set for transform" ), 4 );
535 mHasTransformContext =
true;
553 const double scaledWidthInInches = outputWidthInInches *
scale;
558 const double delta =
mExtent.width() / 100.;
559 QgsRectangle ext( center.
x() - delta, center.
y() - delta, center.
x() + delta, center.
y() + delta );
570 const double delta = 0.5 * scaledWidthInInches * conversionFactor;
571 return QgsRectangle( center.
x() - delta, center.
y() - delta, center.
x() + delta, center.
y() + delta );
654 double x = point.
x();
655 double y = point.
y();
656 double z = point.
z();
657 const double m = point.
m();
709 double x = point.
x();
710 double y = point.
y();
711 double z = point.
z();
712 const double m = point.
m();
757 const auto constMLayers =
mLayers;
765 if ( lyr->extent().isNull() )
790 const double padFactor = 1e-8;
791 const double widthPad =
fullExtent.xMinimum() * padFactor;
792 const double heightPad =
fullExtent.yMinimum() * padFactor;
793 const double xmin =
fullExtent.xMinimum() - widthPad;
794 const double xmax =
fullExtent.xMaximum() + widthPad;
795 const double ymin =
fullExtent.yMinimum() - heightPad;
796 const double ymax =
fullExtent.yMaximum() + heightPad;
810 const QDomNode srsNode = node.namedItem( QStringLiteral(
"destinationsrs" ) );
811 if ( !srsNode.isNull() )
818 const QDomNode extentNode = node.namedItem( QStringLiteral(
"extent" ) );
823 const QDomNode rotationNode = node.namedItem( QStringLiteral(
"rotation" ) );
824 const QString rotationVal = rotationNode.toElement().text();
825 if ( ! rotationVal.isEmpty() )
827 const double rot = rotationVal.toDouble();
832 const QDomElement renderMapTileElem = node.firstChildElement( QStringLiteral(
"rendermaptile" ) );
833 if ( !renderMapTileElem.isNull() )
850 QDomElement rotNode = doc.createElement( QStringLiteral(
"rotation" ) );
854 node.appendChild( rotNode );
859 QDomElement srsNode = doc.createElement( QStringLiteral(
"destinationsrs" ) );
860 node.appendChild( srsNode );
865 QDomElement renderMapTileElem = doc.createElement( QStringLiteral(
"rendermaptile" ) );
867 renderMapTileElem.appendChild( renderMapTileText );
868 node.appendChild( renderMapTileElem );
883 mClippingRegions.append( region );
888 mClippingRegions = regions;
893 return mClippingRegions;
903 mRenderedFeatureHandlers.append( handler );
908 return mRenderedFeatureHandlers;
Provides global constants and enumerations for use throughout the application.
RasterizedRenderingPolicy
Policies controlling when rasterisation of content during renders is permitted.
@ Default
Allow raster-based rendering in situations where it is required for correct rendering or where it wil...
@ PreferVector
Prefer vector-based rendering, when the result will still be visually near-identical to a raster-base...
@ ForceVector
Always force vector-based rendering, even when the result will be visually different to a raster-base...
QFlags< MapSettingsFlag > MapSettingsFlags
Map settings flags.
@ NoSimplification
No simplification can be applied.
DistanceUnit
Units of distance.
@ Unknown
Unknown distance unit.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ Group
Composite group layer. Added in QGIS 3.24.
ScaleCalculationMethod
Scale calculation logic.
RendererUsage
Usage of the renderer.
@ Forward
Forward transform (from source to destination).
@ Reverse
Reverse/inverse transform (from destination to source).
MapSettingsFlag
Flags which adjust the way maps are rendered.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
Represents a coordinate reference system (CRS).
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
Qgis::DistanceUnit mapUnits
Contains information about the context in which a coordinate transform is executed.
Custom exception class for Coordinate Reference System related exceptions.
QgsRange which stores a range of double values.
Renders elevation shading on an image with different methods (eye dome lighting, hillshading,...
static EllipsoidParameters ellipsoidParameters(const QString &ellipsoid)
Returns the parameters for the specified ellipsoid.
A geometry is the spatial representation of a feature.
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
A map clipping region (in map coordinates and CRS).
Base class for all map layer types.
QgsCoordinateReferenceSystem crs
void setElevationShadingRenderer(const QgsElevationShadingRenderer &renderer)
Sets the shading renderer used to render shading on the entire map.
QSize deviceOutputSize() const
Returns the device output size of the map render.
Qgis::DistanceUnit mapUnits() const
Returns the units of the map's geographical coordinates - used for scale calculation.
Qgis::RendererUsage rendererUsage() const
Returns the rendering usage.
QgsVectorSimplifyMethod mSimplifyMethod
void addClippingRegion(const QgsMapClippingRegion ®ion)
Adds a new clipping region to the map settings.
void writeXml(QDomNode &node, QDomDocument &doc)
Writes the map settings to an XML node.
QgsPointXY layerToMapCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from layer's CRS to output CRS
QgsMaskRenderSettings mMaskRenderSettings
QList< QgsMapLayer * > layers(bool expandGroupLayers=false) const
Returns the list of layers which will be rendered in the map.
Qgis::RendererUsage mRendererUsage
QgsRectangle mVisibleExtent
Extent with some additional white space that matches the output aspect ratio.
QPolygonF visiblePolygon() const
Returns the visible area as a polygon (may be rotated).
void addRenderedFeatureHandler(QgsRenderedFeatureHandlerInterface *handler)
Adds a rendered feature handler to use while rendering the map settings.
void setLayers(const QList< QgsMapLayer * > &layers)
Sets the list of layers to render in the map.
double scale() const
Returns the calculated map scale.
void setFrameRate(double rate)
Sets the frame rate of the map (in frames per second), for maps which are part of an animation.
void setFlags(Qgis::MapSettingsFlags flags)
Sets combination of flags that will be used for rendering.
Qgis::MapSettingsFlags mFlags
QgsCoordinateTransform layerTransform(const QgsMapLayer *layer) const
Returns the coordinate transform from layer's CRS to destination CRS.
QgsRectangle layerExtentToOutputExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from layer's CRS to output CRS
QgsDoubleRange zRange() const
Returns the range of z-values which will be visible in the map.
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
void setScaleMethod(Qgis::ScaleCalculationMethod method)
Sets the method to use for scale calculations for the map.
void setDpiTarget(double dpi)
Sets the target dpi (dots per inch) to be taken into consideration when rendering.
double magnificationFactor() const
Returns the magnification factor.
QgsGeometry labelBoundaryGeometry() const
Returns the label boundary geometry, which restricts where in the rendered map labels are permitted t...
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
QStringList layerIds(bool expandGroupLayers=false) const
Returns the list of layer IDs which will be rendered in the map.
void setDevicePixelRatio(float dpr)
Sets the device pixel ratio.
QString mEllipsoid
ellipsoid acronym (from table tbl_ellipsoids)
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which will be visible in the map.
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
long long currentFrame() const
Returns the current frame number of the map, for maps which are part of an animation.
bool mValid
Whether the actual settings are valid (set in updateDerived()).
void setOutputDpi(double dpi)
Sets the dpi (dots per inch) used for conversion between real world units (e.g.
const QgsMapToPixel & mapToPixel() const
double mapUnitsPerPixel() const
Returns the distance in geographical coordinates that equals to one pixel in the map.
void setRendererUsage(Qgis::RendererUsage rendererUsage)
Sets the rendering usage.
float devicePixelRatio() const
Returns the device pixel ratio.
void setRasterizedRenderingPolicy(Qgis::RasterizedRenderingPolicy policy)
Sets the policy controlling when rasterisation of content during renders is permitted.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QgsRectangle extent() const
Returns geographical coordinates of the rectangle that should be rendered.
void setMaskSettings(const QgsMaskRenderSettings &settings)
Sets the mask render settings, which control how masks are drawn and behave during the map render.
QMap< QString, QString > mLayerStyleOverrides
QgsGeometry mLabelBoundaryGeometry
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Sets the map of map layer style overrides (key: layer ID, value: style name) where a different style ...
QgsElevationShadingRenderer mShadingRenderer
QgsCoordinateTransformContext mTransformContext
void setExtent(const QgsRectangle &rect, bool magnified=true)
Sets the coordinates of the rectangle which should be rendered.
void setClippingRegions(const QList< QgsMapClippingRegion > ®ions)
Sets the list of clipping regions to apply to the map.
double layerToMapUnits(const QgsMapLayer *layer, const QgsRectangle &referenceExtent=QgsRectangle()) const
Computes an estimated conversion factor between layer and map units, where layerUnits × layerToMapUni...
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
QVector< T > layers() const
Returns a list of registered map layers with a specified layer type.
QgsScaleCalculator mScaleCalculator
Qgis::MapSettingsFlags flags() const
Returns combination of flags used for rendering.
Qgis::ScaleCalculationMethod scaleMethod() const
Returns the method to use for scale calculations for the map.
double frameRate() const
Returns the frame rate of the map (in frames per second), for maps which are part of an animation.
void setExtentBuffer(double buffer)
Sets the buffer in map units to use around the visible extent for rendering symbols whose correspondi...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QgsRectangle outputExtentToLayerExtent(const QgsMapLayer *layer, QgsRectangle extent) const
transform bounding box from output CRS to layer's CRS
QgsRectangle fullExtent() const
returns current extent of layer set
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the coordinate transform context, which stores various information regarding which datum transfo...
void setRotation(double rotation)
Sets the rotation of the resulting map image, in degrees clockwise.
double computeScaleForExtent(const QgsRectangle &extent) const
Compute the scale that corresponds to the specified extent.
QString ellipsoid() const
Returns ellipsoid's acronym.
double mMagnificationFactor
void setCurrentFrame(long long frame)
Sets the current frame of the map, for maps which are part of an animation.
const QgsElevationShadingRenderer & elevationShadingRenderer() const
Returns the shading renderer used to render shading on the entire map.
QgsCoordinateReferenceSystem mDestCRS
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
void setLabelBoundaryGeometry(const QgsGeometry &boundary)
Sets the label boundary geometry, which restricts where in the rendered map labels are permitted to b...
Qgis::RasterizedRenderingPolicy mRasterizedRenderingPolicy
QgsMapToPixel mMapToPixel
bool testFlag(Qgis::MapSettingsFlag flag) const
Check whether a particular flag is enabled.
QMap< QString, QString > layerStyleOverrides() const
Returns the map of map layer style overrides (key: layer ID, value: style name) where a different sty...
double rotation() const
Returns the rotation of the resulting map image, in degrees clockwise.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
bool hasValidSettings() const
Check whether the map settings are valid and can be used for rendering.
QgsWeakMapLayerPointerList mLayers
list of layers to be rendered (stored as weak pointers)
void setOutputSize(QSize size)
Sets the size of the resulting map image, in pixels.
Qgis::RasterizedRenderingPolicy rasterizedRenderingPolicy() const
Returns the policy controlling when rasterisation of content during renders is permitted.
QgsPointXY mapToLayerCoordinates(const QgsMapLayer *layer, QgsPointXY point) const
transform point coordinates from output CRS to layer's CRS
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QPolygonF visiblePolygonWithBuffer() const
Returns the visible area as a polygon (may be rotated) with extent buffer included.
void setFlag(Qgis::MapSettingsFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected).
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
Sets the destination crs (coordinate reference system) for the map render.
void readXml(QDomNode &node)
Restore the map settings from a XML node.
double mSegmentationTolerance
QgsRectangle computeExtentForScale(const QgsPointXY ¢er, double scale) const
Compute the extent such that its center is at the specified position (mapped to the destinatonCrs) an...
void setMagnificationFactor(double factor, const QgsPointXY *center=nullptr)
Set the magnification factor.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
Perform transforms between map coordinates and device coordinates.
QgsPointXY toMapCoordinates(int x, int y) const
Transforms device coordinates to map (world) coordinates.
Contains settings regarding how masks are calculated and handled during a map render.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
Adds a message to the log instance (and creates it if necessary).
Contains miscellaneous painting utility functions.
QPointF toQPointF() const
Converts a point to a QPointF.
Point geometry type, with support for z-dimension and m-values.
A rectangle specified with double values.
void scale(double scaleFactor, const QgsPointXY *c=nullptr)
Scale the rectangle around its center point.
An interface for classes which provide custom handlers for features rendered as part of a map render ...
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc, const QString &elementName=QStringLiteral("extent"))
Encodes a rectangle to a DOM element.
static QgsRectangle readRectangle(const QDomElement &element)
static QDomElement writeMapUnits(Qgis::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugMsgLevel(str, level)
QPointer< QgsMapLayer > QgsWeakMapLayerPointer
Weak pointer for QgsMapLayer.
Contains parameters for an ellipsoid.
bool valid
Whether ellipsoid parameters are valid.