QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
Loading...
Searching...
No Matches
qgsrendercontext.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsrendercontext.cpp
3 --------------------
4 begin : March 16, 2008
5 copyright : (C) 2008 by Marco Hugentobler
6 email : marco dot hugentobler at karto dot baug dot ethz dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#include "qgsrendercontext.h"
20
21#include "qgsmapsettings.h"
23#include "qgslogger.h"
24#include "qgselevationmap.h"
25#include "qgsunittypes.h"
26#include "qgssymbollayer.h"
27
28#define POINTS_TO_MM 2.83464567
29#define INCH_TO_MM 25.4
30
32 : mFlags( Qgis::RenderContextFlag::DrawEditingInfo | Qgis::RenderContextFlag::UseAdvancedEffects | Qgis::RenderContextFlag::DrawSelection | Qgis::RenderContextFlag::UseRenderingOptimization )
33{
35 // For RenderMetersInMapUnits support, when rendering in Degrees, the Ellipsoid must be set
36 // - for Previews/Icons the default Extent can be used
37 mDistanceArea.setEllipsoid( mDistanceArea.sourceCrs().ellipsoidAcronym() );
38}
39
41
44 , mFlags( rh.mFlags )
45 , mPainter( rh.mPainter )
46 , mPreviewRenderPainter( rh.mPreviewRenderPainter )
47 , mMaskPainter( rh.mMaskPainter )
48 , mCoordTransform( rh.mCoordTransform )
49 , mDistanceArea( rh.mDistanceArea )
50 , mExtent( rh.mExtent )
51 , mOriginalMapExtent( rh.mOriginalMapExtent )
52 , mMapToPixel( rh.mMapToPixel )
53 , mRenderingStopped( rh.mRenderingStopped )
54 , mFeedback( rh.mFeedback )
55 , mScaleFactor( rh.mScaleFactor )
56 , mDpiTarget( rh.mDpiTarget )
57 , mRendererScale( rh.mRendererScale )
58 , mSymbologyReferenceScale( rh.mSymbologyReferenceScale )
59 , mLabelingEngine( rh.mLabelingEngine )
60 , mLabelSink( rh.mLabelSink )
61 , mSelectionColor( rh.mSelectionColor )
62 , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
63 , mExpressionContext( rh.mExpressionContext )
64 , mGeometry( rh.mGeometry )
65 , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
66 , mSegmentationTolerance( rh.mSegmentationTolerance )
67 , mSegmentationToleranceType( rh.mSegmentationToleranceType )
68 , mTransformContext( rh.mTransformContext )
69 , mPathResolver( rh.mPathResolver )
70 , mTextRenderFormat( rh.mTextRenderFormat )
71 , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
72 , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
73 , mCustomRenderingFlags( rh.mCustomRenderingFlags )
74 , mDisabledSymbolLayers()
75 , mClippingRegions( rh.mClippingRegions )
76 , mFeatureClipGeometry( rh.mFeatureClipGeometry )
77 , mTextureOrigin( rh.mTextureOrigin )
78 , mZRange( rh.mZRange )
79 , mSize( rh.mSize )
80 , mDevicePixelRatio( rh.mDevicePixelRatio )
81 , mImageFormat( rh.mImageFormat )
82 , mRendererUsage( rh.mRendererUsage )
83 , mFrameRate( rh.mFrameRate )
84 , mCurrentFrame( rh.mCurrentFrame )
85 , mSymbolLayerClipPaths( rh.mSymbolLayerClipPaths )
86#ifdef QGISDEBUG
87 , mHasTransformContext( rh.mHasTransformContext )
88#endif
89 , mElevationMap( rh.mElevationMap )
90{
91}
92
94{
95 mFlags = rh.mFlags;
96 mPainter = rh.mPainter;
97 mPreviewRenderPainter = rh.mPreviewRenderPainter;
98 mMaskPainter = rh.mMaskPainter;
99 mCoordTransform = rh.mCoordTransform;
100 mExtent = rh.mExtent;
101 mOriginalMapExtent = rh.mOriginalMapExtent;
102 mMapToPixel = rh.mMapToPixel;
103 mRenderingStopped = rh.mRenderingStopped;
104 mFeedback = rh.mFeedback;
105 mScaleFactor = rh.mScaleFactor;
106 mDpiTarget = rh.mDpiTarget;
107 mRendererScale = rh.mRendererScale;
108 mSymbologyReferenceScale = rh.mSymbologyReferenceScale;
109 mLabelingEngine = rh.mLabelingEngine;
110 mLabelSink = rh.mLabelSink;
111 mSelectionColor = rh.mSelectionColor;
112 mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
113 mExpressionContext = rh.mExpressionContext;
114 mGeometry = rh.mGeometry;
115 mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
116 mSegmentationTolerance = rh.mSegmentationTolerance;
117 mSegmentationToleranceType = rh.mSegmentationToleranceType;
118 mDistanceArea = rh.mDistanceArea;
119 mTransformContext = rh.mTransformContext;
120 mPathResolver = rh.mPathResolver;
121 mTextRenderFormat = rh.mTextRenderFormat;
122 mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
123 mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
124 mCustomRenderingFlags = rh.mCustomRenderingFlags;
125 mClippingRegions = rh.mClippingRegions;
126 mFeatureClipGeometry = rh.mFeatureClipGeometry;
127 mTextureOrigin = rh.mTextureOrigin;
128 mZRange = rh.mZRange;
129 mSize = rh.mSize;
130 mDevicePixelRatio = rh.mDevicePixelRatio;
131 mImageFormat = rh.mImageFormat;
133 mRendererUsage = rh.mRendererUsage;
134 mFrameRate = rh.mFrameRate;
135 mCurrentFrame = rh.mCurrentFrame;
136 mSymbolLayerClipPaths = rh.mSymbolLayerClipPaths;
137 if ( isTemporal() )
139#ifdef QGISDEBUG
140 mHasTransformContext = rh.mHasTransformContext;
141#endif
142 mElevationMap = rh.elevationMap();
143
144 return *this;
145}
146
148{
149 QgsRenderContext context;
150 context.setPainter( painter );
151 if ( painter && painter->device() )
152 {
153 context.setScaleFactor( painter->device()->physicalDpiX() / 25.4 );
154 }
155 else
156 {
157 context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
158 }
159
160 if ( painter && painter->renderHints() & QPainter::Antialiasing )
162 if ( painter && painter->renderHints() & QPainter::SmoothPixmapTransform )
164 if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
166
167 return context;
168}
169
171{
172 if ( !painter )
173 painter = mPainter;
174
175 if ( !painter )
176 return;
177
178 painter->setRenderHint( QPainter::Antialiasing, mFlags & Qgis::RenderContextFlag::Antialiasing );
179 painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & Qgis::RenderContextFlag::LosslessImageRendering );
180 painter->setRenderHint( QPainter::SmoothPixmapTransform, mFlags & Qgis::RenderContextFlag::HighQualityImageTransforms );
181}
182
184{
185#ifdef QGISDEBUG
186 if ( !mHasTransformContext )
187 QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
188#endif
189 return mTransformContext;
190}
191
193{
194 mTransformContext = context;
195#ifdef QGISDEBUG
196 mHasTransformContext = true;
197#endif
198}
199
201{
202 mFeedback = feedback;
203}
204
206{
207 return mFeedback;
208}
209
210void QgsRenderContext::setFlags( Qgis::RenderContextFlags flags )
211{
212 mFlags = flags;
213}
214
216{
217 if ( on )
218 mFlags |= flag;
219 else
220 mFlags &= ~( static_cast< int >( flag ) );
221}
222
223Qgis::RenderContextFlags QgsRenderContext::flags() const
224{
225 return mFlags;
226}
227
229{
230 return mFlags.testFlag( flag );
231}
232
234{
236 QgsRectangle extent = mapSettings.visibleExtent();
237 extent.grow( mapSettings.extentBuffer() );
238 ctx.setMapToPixel( mapSettings.mapToPixel() );
239 ctx.setExtent( extent );
240 ctx.setMapExtent( mapSettings.visibleExtent() );
246 ctx.setSelectionColor( mapSettings.selectionColor() );
259 ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
260 ctx.setDpiTarget( mapSettings.dpiTarget() >= 0.0 ? mapSettings.dpiTarget() : -1.0 );
261 ctx.setRendererScale( mapSettings.scale() );
262 ctx.setExpressionContext( mapSettings.expressionContext() );
265 ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
266 ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
267 ctx.setTransformContext( mapSettings.transformContext() );
268 ctx.setPathResolver( mapSettings.pathResolver() );
269 ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
270 ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
271 ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
272 ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
273 //this flag is only for stopping during the current rendering progress,
274 //so must be false at every new render operation
275 ctx.setRenderingStopped( false );
276 ctx.mCustomRenderingFlags = mapSettings.customRenderingFlags();
277 ctx.setIsTemporal( mapSettings.isTemporal() );
278 if ( ctx.isTemporal() )
279 ctx.setTemporalRange( mapSettings.temporalRange() );
280
281 ctx.setZRange( mapSettings.zRange() );
282 ctx.setOutputSize( mapSettings.outputSize() );
283 ctx.setDevicePixelRatio( mapSettings.devicePixelRatio() );
284 ctx.setImageFormat( mapSettings.outputImageFormat() );
285
286 ctx.mClippingRegions = mapSettings.clippingRegions();
287
288 ctx.mRendererUsage = mapSettings.rendererUsage();
289 ctx.mFrameRate = mapSettings.frameRate();
290 ctx.mCurrentFrame = mapSettings.currentFrame();
291
292 return ctx;
293}
294
296{
297 return mFlags.testFlag( Qgis::RenderContextFlag::ForceVectorOutput );
298}
299
301{
302 return mFlags.testFlag( Qgis::RenderContextFlag::UseAdvancedEffects );
303}
304
309
311{
312 return mFlags.testFlag( Qgis::RenderContextFlag::DrawEditingInfo );
313}
314
316{
317 return mFlags.testFlag( Qgis::RenderContextFlag::DrawSelection );
318}
319
321{
322 mCoordTransform = t;
323}
324
329
334
339
344
349
351{
352 if ( ffp )
353 {
354 mFeatureFilterProvider.reset( ffp->clone() );
355 }
356 else
357 {
358 mFeatureFilterProvider.reset( nullptr );
359 }
360}
361
363{
364 return mFeatureFilterProvider.get();
365}
366
368{
369 double conversionFactor = 1.0;
370 bool isMapUnitHack = false;
371 switch ( unit )
372 {
374 conversionFactor = mScaleFactor;
375 break;
376
378 conversionFactor = mScaleFactor / POINTS_TO_MM;
379 break;
380
382 conversionFactor = mScaleFactor * INCH_TO_MM;
383 break;
384
386 {
387 if ( mMapToPixel.isValid() )
388 size = convertMetersToMapUnits( size );
390 // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
391 [[fallthrough]];
392 }
394 {
395 if ( mMapToPixel.isValid() )
396 {
397 const double mup = scale.computeMapUnitsPerPixel( *this );
398 if ( mup > 0 )
399 {
400 conversionFactor = 1.0 / mup;
401 }
402 else
403 {
404 conversionFactor = 1.0;
405 }
406 }
407 else
408 {
409 // invalid map to pixel. A size in map units can't be calculated, so treat the size as points
410 // and clamp it to a reasonable range. It's the best we can do in this situation!
411 isMapUnitHack = true;
412 conversionFactor = mScaleFactor / POINTS_TO_MM;
413 }
414 break;
415 }
417 conversionFactor = 1.0;
418 break;
419
422 //no sensible value
423 conversionFactor = 1.0;
424 break;
425 }
426
427 double convertedSize = size * conversionFactor;
428
429 if ( unit == Qgis::RenderUnit::MapUnits )
430 {
431 //check max/min size
432 if ( scale.minSizeMMEnabled )
433 convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
434 if ( scale.maxSizeMMEnabled )
435 convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
436 }
437
438 if ( isMapUnitHack )
439 {
440 // since we are arbitrarily treating map units as mm, we need to clamp to an (arbitrary!) reasonable range.
441 convertedSize = std::clamp( convertedSize, 10.0, 100.0 );
442 }
443 else
444 {
445 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
446 convertedSize *= symbologyReferenceScaleFactor;
447 }
448
450 {
451 // apply property based constraints in order to optimise symbol preview rendering
452 switch ( property )
453 {
455 break;
456
458 // excessively large shadow offset in symbol preview icons is undesirable -- it pushes the shadow outside of view
459 convertedSize = std::min( convertedSize, 100.0 );
460 break;
462 // excessively large blur in symbol preview icons is too slow to calculate
463 convertedSize = std::min<double>( convertedSize, 30 );
464 break;
466 // excessively large glow spread in symbol preview icons is too slow to calculate
467 convertedSize = std::min<double>( convertedSize, 50 );
468 break;
469 }
470 }
471
472 return convertedSize;
473}
474
475double QgsRenderContext::convertToMapUnits( double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale ) const
476{
477 const double mup = mMapToPixel.mapUnitsPerPixel();
478
479 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
480
481 switch ( unit )
482 {
484 {
485 size = convertMetersToMapUnits( size );
486 // Fall through to RenderMapUnits with values of meters converted to MapUnits
487 [[fallthrough]];
488 }
490 {
491 // check scale
492 double minSizeMU = std::numeric_limits<double>::lowest();
493 if ( scale.minSizeMMEnabled )
494 {
495 minSizeMU = scale.minSizeMM * mScaleFactor * mup;
496 }
497 if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
498 {
499 minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
500 }
501 size = std::max( size, minSizeMU );
502
503 double maxSizeMU = std::numeric_limits<double>::max();
504 if ( scale.maxSizeMMEnabled )
505 {
506 maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
507 }
508 if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
509 {
510 maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
511 }
512 size = std::min( size, maxSizeMU );
513
514 return size;
515 }
517 {
518 return size * mScaleFactor * mup / symbologyReferenceScaleFactor;
519 }
521 {
522 return size * mScaleFactor * mup / POINTS_TO_MM / symbologyReferenceScaleFactor;
523 }
525 {
526 return size * mScaleFactor * mup * INCH_TO_MM / symbologyReferenceScaleFactor;
527 }
529 {
530 return size * mup / symbologyReferenceScaleFactor;
531 }
532
535 //no sensible value
536 return 0.0;
537 }
538 return 0.0;
539}
540
541double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, Qgis::RenderUnit outputUnit ) const
542{
543 const double mup = mMapToPixel.mapUnitsPerPixel();
544 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
545
546 switch ( outputUnit )
547 {
549 {
550 return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
551 }
553 {
554 return sizeInMapUnits;
555 }
557 {
558 return sizeInMapUnits / ( mScaleFactor * mup ) * symbologyReferenceScaleFactor;
559 }
561 {
562 return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM ) * symbologyReferenceScaleFactor;
563 }
565 {
566 return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM ) * symbologyReferenceScaleFactor;
567 }
569 {
570 return sizeInMapUnits / mup * symbologyReferenceScaleFactor;
571 }
572
575 //no sensible value
576 return 0.0;
577 }
578 return 0.0;
579}
580
581double QgsRenderContext::convertMetersToMapUnits( double meters ) const
582{
583 switch ( mDistanceArea.sourceCrs().mapUnits() )
584 {
586 return meters;
588 {
589 if ( mExtent.isNull() )
590 {
591 // we don't have an extent to calculate exactly -- so just use a very rough approximation
593 }
594
595 QgsPointXY pointCenter = mExtent.center();
596 // The Extent is in the sourceCrs(), when different from destinationCrs()
597 // - the point must be transformed, since DistanceArea uses the destinationCrs()
598 // Note: the default QgsCoordinateTransform() : authid() will return an empty String
599 if ( !mCoordTransform.isShortCircuited() )
600 {
601 try
602 {
603 pointCenter = mCoordTransform.transform( pointCenter );
604 }
605 catch ( const QgsCsException & )
606 {
607 QgsDebugError( QStringLiteral( "QgsRenderContext::convertMetersToMapUnits(): failed to reproject pointCenter" ) );
608 // what should we return;.. ?
609 return meters;
610 }
611 }
612
613 const int multiplier = meters < 0 ? -1 : 1;
614 return multiplier * mDistanceArea.measureLineProjected( pointCenter, std::fabs( meters ) );
615 }
626 }
627 return meters;
628}
629
630QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
631{
632 return mRenderedFeatureHandlers;
633}
634
635QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
636{
637 return mClippingRegions;
638}
639
641{
642 return mFeatureClipGeometry;
643}
644
646{
647 mFeatureClipGeometry = geometry;
648}
649
651{
652 return mTextureOrigin;
653}
654
655void QgsRenderContext::setTextureOrigin( const QPointF &origin )
656{
657 mTextureOrigin = origin;
658}
659
661{
662 return mZRange;
663}
664
666{
667 mZRange = range;
668}
669
671{
672 return mSize;
673}
674
676{
677 mSize = size;
678}
679
681{
682 return mDevicePixelRatio;
683}
684
686{
687 mDevicePixelRatio = ratio;
688}
689
691{
692 return outputSize() * mDevicePixelRatio;
693}
694
696{
697 return mFrameRate;
698}
699
701{
702 mFrameRate = rate;
703}
704
706{
707 return mCurrentFrame;
708}
709
711{
712 mCurrentFrame = frame;
713}
714
716{
717 return mElevationMap;
718}
719
721{
722 mElevationMap = map;
723}
724
725void QgsRenderContext::addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path )
726{
727 mSymbolLayerClipPaths[ symbolLayerId ].append( path );
728}
729
730QList<QPainterPath> QgsRenderContext::symbolLayerClipPaths( const QString &symbolLayerId ) const
731{
732 return mSymbolLayerClipPaths[ symbolLayerId ];
733}
734
735void QgsRenderContext::setDisabledSymbolLayers( const QSet<const QgsSymbolLayer *> &symbolLayers )
736{
737 mDisabledSymbolLayers.clear();
738 for ( const QgsSymbolLayer *symbolLayer : symbolLayers )
739 mDisabledSymbolLayers << symbolLayer->id();
740}
741
742void QgsRenderContext::setDisabledSymbolLayersV2( const QSet<QString> &symbolLayers )
743{
744 mDisabledSymbolLayers = symbolLayers;
745}
746
747QSet<const QgsSymbolLayer *> QgsRenderContext::disabledSymbolLayers() const
748{
749 return QSet<const QgsSymbolLayer *>();
750}
751
753{
754 return mDisabledSymbolLayers;
755}
756
758{
759 return !mDisabledSymbolLayers.contains( layer->id() );
760}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
RenderSubcomponentProperty
Rendering subcomponent properties.
Definition qgis.h:2442
@ Generic
Generic subcomponent property.
@ Feet
Imperial feet.
@ Centimeters
Centimeters.
@ Millimeters
Millimeters.
@ Miles
Terrestrial miles.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ Inches
Inches (since QGIS 3.32)
@ NauticalMiles
Nautical miles.
@ Kilometers
Kilometers.
RenderUnit
Rendering size units.
Definition qgis.h:4193
@ Percentage
Percentage of another measurement (e.g., canvas size, feature size)
@ Millimeters
Millimeters.
@ Points
Points (e.g., for font sizes)
@ Unknown
Mixed or unknown units.
@ MapUnits
Map units.
@ MetersInMapUnits
Meters value as Map units.
RenderContextFlag
Flags which affect rendering operations.
Definition qgis.h:2232
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ RenderSymbolPreview
The render is for a symbol preview only and map based properties may not be available,...
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ 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.
@ RecordProfile
Enable run-time profiling while rendering (since QGIS 3.34)
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ 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...
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ Antialiasing
Use antialiasing while drawing.
@ SkipSymbolRendering
Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24)
@ Render3DMap
Render is for a 3D map.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ 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.
@ RecordProfile
Enable run-time profiling while rendering (since QGIS 3.34)
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ 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...
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ Antialiasing
Enable anti-aliasing for map rendering.
@ SkipSymbolRendering
Disable symbol rendering while still drawing labels if enabled (since QGIS 3.24)
@ Render3DMap
Render is for a 3D map.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ HighQualityImageTransforms
Enable high quality image transformations, which results in better appearance of scaled or rotated ra...
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
QString ellipsoidAcronym() const
Returns the ellipsoid acronym for the ellipsoid used by the CRS.
Contains information about the context in which a coordinate transform is executed.
Class for doing transforms between two map coordinate systems.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const
Transform the point from the source CRS to the destination CRS.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
Custom exception class for Coordinate Reference System related exceptions.
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.
Definition qgsrange.h:201
Stores digital elevation model in a raster image which may get updated as a part of map layer renderi...
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.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A geometry is the spatial representation of a feature.
The QgsMapSettings class contains configuration for rendering of the map.
Qgis::RendererUsage rendererUsage() const
Returns the rendering usage.
double scale() const
Returns the calculated map scale.
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.
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
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.
long long currentFrame() const
Returns the current frame number of the map, for maps which are part of an animation.
const QgsMapToPixel & mapToPixel() const
float devicePixelRatio() const
Returns the device pixel ratio.
QSize outputSize() const
Returns the size of the resulting map image, in pixels.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
double frameRate() const
Returns the frame rate of the map (in frames per second), for maps which are part of an animation.
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...
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes output image size into account.
QVariantMap customRenderingFlags() const
Returns any custom rendering flags.
QString ellipsoid() const
Returns ellipsoid's acronym.
Qgis::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
bool testFlag(Qgis::MapSettingsFlag flag) const
Check whether a particular flag is enabled.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
bool isValid() const
Returns true if the object is valid (i.e.
double mapUnitsPerPixel() const
Returns the 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.
Definition qgspointxy.h:60
A rectangle specified with double values.
bool isNull() const
Test if the rectangle is null (holding no spatial information).
QgsPointXY center() const
Returns the center point of the rectangle.
void grow(double delta)
Grows the rectangle in place by the specified amount.
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.
double convertToMapUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
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 setImageFormat(QImage::Format format)
Sets QImage format which should be used for QImages created during rendering.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
QSet< QString > disabledSymbolLayersV2() const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
void setDevicePixelRatio(float ratio)
Sets the device pixel ratio.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
void setCurrentFrame(long long frame)
Sets the current frame of the map, for maps which are part of an animation.
double convertToPainterUnits(double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
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 setTextRenderFormat(Qgis::TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
double convertFromMapUnits(double sizeInMapUnits, Qgis::RenderUnit outputUnit) const
Converts a size from map units to the specified units.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QSize outputSize() const
Returns the size of the resulting rendered image, in pixels.
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
QgsElevationMap * elevationMap() const
Returns the destination elevation map for the render operation.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
bool testFlag(Qgis::RenderContextFlag flag) const
Check whether a particular flag is enabled.
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
Q_DECL_DEPRECATED void setDisabledSymbolLayers(const QSet< const QgsSymbolLayer * > &symbolLayers)
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
long long currentFrame() const
Returns the current frame number of the map (in frames per second), for maps which are part of an ani...
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...
float devicePixelRatio() const
Returns the device pixel ratio.
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly during rendering to check if rendering should ...
void addSymbolLayerClipPath(const QString &symbolLayerId, QPainterPath path)
Add a clip path to be applied to the symbolLayer before rendering.
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
void setDisabledSymbolLayersV2(const QSet< QString > &symbolLayers)
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
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.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
double frameRate() const
Returns the frame rate of the map, for maps which are part of an animation.
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 setFrameRate(double rate)
Sets the frame rate of the map (in frames per second), for maps which are part of an animation.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the context's coordinate transform context, which stores various information regarding which dat...
void setFlags(Qgis::RenderContextFlags flags)
Set combination of flags that will be used for rendering.
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...
Q_DECL_DEPRECATED QSet< const QgsSymbolLayer * > disabledSymbolLayers() const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
void setOutputSize(QSize size)
Sets the size of the resulting rendered image, in pixels.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
QPointF textureOrigin() const
Returns the texture origin, which should be used as a brush transform when rendering using QBrush obj...
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.
bool isSymbolLayerEnabled(const QgsSymbolLayer *layer) const
When rendering a map layer in a second pass (for selective masking), some symbol layers may be disabl...
QSize deviceOutputSize() const
Returns the device output size of the render.
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.
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.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
QList< QPainterPath > symbolLayerClipPaths(const QString &symbolLayerId) const
Returns clip paths to be applied to the symbolLayer before rendering.
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
void setElevationMap(QgsElevationMap *map)
Sets the destination elevation map for the render operation.
QgsRenderContext & operator=(const QgsRenderContext &rh)
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.
QString id() const
Returns symbol layer identifier This id is unique in the whole project.
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.
static Q_INVOKABLE double fromUnitToUnitFactor(Qgis::DistanceUnit fromUnit, Qgis::DistanceUnit toUnit)
Returns the conversion factor between the specified distance 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)
Definition qgis.h:5144
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38
#define INCH_TO_MM
#define POINTS_TO_MM