28 #define POINTS_TO_MM 2.83464567
29 #define INCH_TO_MM 25.4
32 : mFlags( DrawEditingInfo | UseAdvancedEffects | DrawSelection | UseRenderingOptimization )
45 , mPainter( rh.mPainter )
46 , mMaskPainter( rh.mMaskPainter )
47 , mCoordTransform( rh.mCoordTransform )
48 , mDistanceArea( rh.mDistanceArea )
49 , mExtent( rh.mExtent )
50 , mOriginalMapExtent( rh.mOriginalMapExtent )
51 , mMapToPixel( rh.mMapToPixel )
52 , mRenderingStopped( rh.mRenderingStopped )
53 , mScaleFactor( rh.mScaleFactor )
54 , mDpiTarget( rh.mDpiTarget )
55 , mRendererScale( rh.mRendererScale )
56 , mLabelingEngine( rh.mLabelingEngine )
57 , mSelectionColor( rh.mSelectionColor )
58 , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
59 , mExpressionContext( rh.mExpressionContext )
60 , mGeometry( rh.mGeometry )
61 , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
62 , mSegmentationTolerance( rh.mSegmentationTolerance )
63 , mSegmentationToleranceType( rh.mSegmentationToleranceType )
64 , mTransformContext( rh.mTransformContext )
65 , mPathResolver( rh.mPathResolver )
66 , mTextRenderFormat( rh.mTextRenderFormat )
67 , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
68 , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
69 , mCustomRenderingFlags( rh.mCustomRenderingFlags )
70 , mDisabledSymbolLayers()
71 , mClippingRegions( rh.mClippingRegions )
72 , mFeatureClipGeometry( rh.mFeatureClipGeometry )
73 , mTextureOrigin( rh.mTextureOrigin )
74 , mZRange( rh.mZRange )
76 , mHasTransformContext( rh.mHasTransformContext )
84 mPainter = rh.mPainter;
85 mMaskPainter = rh.mMaskPainter;
86 mCoordTransform = rh.mCoordTransform;
88 mOriginalMapExtent = rh.mOriginalMapExtent;
89 mMapToPixel = rh.mMapToPixel;
90 mRenderingStopped = rh.mRenderingStopped;
91 mScaleFactor = rh.mScaleFactor;
92 mDpiTarget = rh.mDpiTarget;
93 mRendererScale = rh.mRendererScale;
94 mLabelingEngine = rh.mLabelingEngine;
95 mSelectionColor = rh.mSelectionColor;
96 mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
97 mExpressionContext = rh.mExpressionContext;
98 mGeometry = rh.mGeometry;
99 mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() :
nullptr );
100 mSegmentationTolerance = rh.mSegmentationTolerance;
101 mSegmentationToleranceType = rh.mSegmentationToleranceType;
102 mDistanceArea = rh.mDistanceArea;
103 mTransformContext = rh.mTransformContext;
104 mPathResolver = rh.mPathResolver;
105 mTextRenderFormat = rh.mTextRenderFormat;
106 mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
107 mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
108 mCustomRenderingFlags = rh.mCustomRenderingFlags;
109 mClippingRegions = rh.mClippingRegions;
110 mFeatureClipGeometry = rh.mFeatureClipGeometry;
111 mTextureOrigin = rh.mTextureOrigin;
112 mZRange = rh.mZRange;
117 mHasTransformContext = rh.mHasTransformContext;
139 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
140 if (
painter &&
painter->renderHints() & QPainter::LosslessImageRendering )
156 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
164 if ( !mHasTransformContext )
165 QgsDebugMsgLevel( QStringLiteral(
"No QgsCoordinateTransformContext context set for transform" ), 4 );
167 return mTransformContext;
172 mTransformContext = context;
174 mHasTransformContext =
true;
198 return mFlags.testFlag( flag );
312 mFeatureFilterProvider.reset( ffp->
clone() );
316 mFeatureFilterProvider.reset(
nullptr );
322 return mFeatureFilterProvider.get();
327 double conversionFactor = 1.0;
331 conversionFactor = mScaleFactor;
354 conversionFactor = 1.0 / mup;
358 conversionFactor = 1.0;
363 conversionFactor = 1.0;
369 conversionFactor = 1.0;
373 double convertedSize = size * conversionFactor;
379 convertedSize = std::max( convertedSize, scale.
minSizeMM * mScaleFactor );
381 convertedSize = std::min( convertedSize, scale.
maxSizeMM * mScaleFactor );
384 return convertedSize;
402 double minSizeMU = std::numeric_limits<double>::lowest();
405 minSizeMU = scale.
minSizeMM * mScaleFactor * mup;
409 minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.
minScale ) );
411 size = std::max( size, minSizeMU );
413 double maxSizeMU = std::numeric_limits<double>::max();
416 maxSizeMU = scale.
maxSizeMM * mScaleFactor * mup;
420 maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.
maxScale ) );
422 size = std::min( size, maxSizeMU );
428 return size * mScaleFactor * mup;
436 return size * mScaleFactor * mup *
INCH_TO_MM;
455 switch ( outputUnit )
463 return sizeInMapUnits;
467 return sizeInMapUnits / ( mScaleFactor * mup );
471 return sizeInMapUnits / ( mScaleFactor * mup /
POINTS_TO_MM );
475 return sizeInMapUnits / ( mScaleFactor * mup *
INCH_TO_MM );
479 return sizeInMapUnits / mup;
510 pointCenter = mCoordTransform.
transform( pointCenter );
529 return mRenderedFeatureHandlers;
534 return mClippingRegions;
539 return mFeatureClipGeometry;
549 return mTextureOrigin;
554 mTextureOrigin = origin;
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
Contains information about the context in which a coordinate transform is executed.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the source spatial reference system.
void setSourceCrs(const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &context)
Sets source spatial reference system crs.
double measureLineProjected(const QgsPointXY &p1, double distance=1, double azimuth=M_PI_2, QgsPointXY *projectedPoint=nullptr) const
Calculates the distance from one point with distance in meters and azimuth (direction) When the sourc...
bool setEllipsoid(const QString &ellipsoid)
Sets the ellipsoid by its acronym.
QgsRange which stores a range of double values.
Abstract interface for use by classes that filter the features or attributes of a layer.
virtual QgsFeatureFilterProvider * clone() const =0
Create a clone of the feature filter provider.
A geometry is the spatial representation of a feature.
The QgsMapSettings class contains configuration for rendering of the map.
double scale() const
Returns the calculated map scale.
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QgsDoubleRange zRange() const
Returns the range of z-values which will be visible in the map.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Antialiasing
Enable anti-aliasing for map rendering.
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ Render3DMap
Render is for a 3D map.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
const QgsMapToPixel & mapToPixel() const
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QVariantMap customRenderingFlags() const
Returns any custom rendering flags.
QString ellipsoid() const
Returns ellipsoid's acronym.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
double mapUnitsPerPixel() const
Returns current map units per pixel.
Struct for storing maximum and minimum scales for measurements in map units.
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
double maxScale
The maximum scale, or 0.0 if unset.
double minScale
The minimum scale, or 0.0 if unset.
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
A class to represent a 2D point.
A rectangle specified with double values.
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
void grow(double delta)
Grows the rectangle in place by the specified amount.
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Contains information about the context of a rendering operation.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
void setMapExtent(const QgsRectangle &extent)
Sets the original extent of the map being rendered.
void setTextureOrigin(const QPointF &origin)
Sets the texture origin, which should be used as a brush transform when rendering using QBrush object...
void setRenderingStopped(bool stopped)
Sets whether the rendering operation has been stopped and any ongoing rendering should be canceled im...
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
void setShowSelection(bool showSelection)
Sets whether vector selections should be shown in the rendered map.
void setDrawEditingInformation(bool b)
Sets whether edit markers should be drawn during the render operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
void setTextRenderFormat(TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
double convertFromMapUnits(double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit) const
Converts a size from map units to the specified units.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
void setDpiTarget(double dpi)
Sets the targeted dpi for rendering.
~QgsRenderContext() override
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply during the render.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the context's coordinate transform context, which stores various information regarding which dat...
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
Flag
Enumeration of flags that affect rendering operations.
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ Antialiasing
Use antialiasing while drawing.
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Render3DMap
Render is for a 3D map.
Flags flags() const
Returns combination of flags used for rendering.
QPointF textureOrigin() const
Returns the texture origin, which should be used as a brush transform when rendering using QBrush obj...
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void setUseRenderingOptimization(bool enabled)
Sets whether the rendering optimization (geometry simplification) should be executed.
void setRendererScale(double scale)
Sets the renderer map scale.
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which should be rendered.
double convertMetersToMapUnits(double meters) const
Convert meter distances to active MapUnit values for QgsUnitTypes::RenderMetersInMapUnits.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsRenderContext & operator=(const QgsRenderContext &rh)
void setFlags(QgsRenderContext::Flags flags)
Set combination of flags that will be used for rendering.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
void setSelectionColor(const QColor &color)
Sets the color to use when rendering selected features.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
void setFeatureFilterProvider(const QgsFeatureFilterProvider *ffp)
Set a filter feature provider used for additional filtering of rendered features.
Base class for objects with an associated (optional) temporal range.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
@ DistanceKilometers
Kilometers.
@ DistanceMiles
Terrestrial miles.
@ DistanceUnknownUnit
Unknown distance unit.
@ DistanceMillimeters
Millimeters.
@ DistanceYards
Imperial yards.
@ DistanceFeet
Imperial feet.
@ DistanceNauticalMiles
Nautical miles.
@ DistanceCentimeters
Centimeters.
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
RenderUnit
Rendering size units.
@ RenderUnknownUnit
Mixed or unknown units.
@ RenderMetersInMapUnits
Meters value as Map units.
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
@ RenderPoints
Points (e.g., for font sizes)
@ RenderMillimeters
Millimeters.
@ RenderMapUnits
Map units.
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
@ NoSimplification
No simplification can be applied.
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)