QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 , 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 , mFeedback( rh.mFeedback )
54 , mScaleFactor( rh.mScaleFactor )
55 , mDpiTarget( rh.mDpiTarget )
56 , mRendererScale( rh.mRendererScale )
57 , mSymbologyReferenceScale( rh.mSymbologyReferenceScale )
58 , mLabelingEngine( rh.mLabelingEngine )
59 , mLabelSink( rh.mLabelSink )
60 , mSelectionColor( rh.mSelectionColor )
61 , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
62 , mExpressionContext( rh.mExpressionContext )
63 , mGeometry( rh.mGeometry )
64 , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
65 , mSegmentationTolerance( rh.mSegmentationTolerance )
66 , mSegmentationToleranceType( rh.mSegmentationToleranceType )
67 , mTransformContext( rh.mTransformContext )
68 , mPathResolver( rh.mPathResolver )
69 , mTextRenderFormat( rh.mTextRenderFormat )
70 , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
71 , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
72 , mCustomRenderingFlags( rh.mCustomRenderingFlags )
73 , mDisabledSymbolLayers()
74 , mClippingRegions( rh.mClippingRegions )
75 , mFeatureClipGeometry( rh.mFeatureClipGeometry )
76 , mTextureOrigin( rh.mTextureOrigin )
77 , mZRange( rh.mZRange )
78 , mSize( rh.mSize )
79 , mDevicePixelRatio( rh.mDevicePixelRatio )
80 , mImageFormat( rh.mImageFormat )
81 , mRendererUsage( rh.mRendererUsage )
82 , mFrameRate( rh.mFrameRate )
83 , mCurrentFrame( rh.mCurrentFrame )
84 , mSymbolLayerClipPaths( rh.mSymbolLayerClipPaths )
85#ifdef QGISDEBUG
86 , mHasTransformContext( rh.mHasTransformContext )
87#endif
88 , mElevationMap( rh.mElevationMap )
89{
90}
91
93{
94 mFlags = rh.mFlags;
95 mPainter = rh.mPainter;
96 mMaskPainter = rh.mMaskPainter;
97 mCoordTransform = rh.mCoordTransform;
98 mExtent = rh.mExtent;
99 mOriginalMapExtent = rh.mOriginalMapExtent;
100 mMapToPixel = rh.mMapToPixel;
101 mRenderingStopped = rh.mRenderingStopped;
102 mFeedback = rh.mFeedback;
103 mScaleFactor = rh.mScaleFactor;
104 mDpiTarget = rh.mDpiTarget;
105 mRendererScale = rh.mRendererScale;
106 mSymbologyReferenceScale = rh.mSymbologyReferenceScale;
107 mLabelingEngine = rh.mLabelingEngine;
108 mLabelSink = rh.mLabelSink;
109 mSelectionColor = rh.mSelectionColor;
110 mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
111 mExpressionContext = rh.mExpressionContext;
112 mGeometry = rh.mGeometry;
113 mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
114 mSegmentationTolerance = rh.mSegmentationTolerance;
115 mSegmentationToleranceType = rh.mSegmentationToleranceType;
116 mDistanceArea = rh.mDistanceArea;
117 mTransformContext = rh.mTransformContext;
118 mPathResolver = rh.mPathResolver;
119 mTextRenderFormat = rh.mTextRenderFormat;
120 mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
121 mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
122 mCustomRenderingFlags = rh.mCustomRenderingFlags;
123 mClippingRegions = rh.mClippingRegions;
124 mFeatureClipGeometry = rh.mFeatureClipGeometry;
125 mTextureOrigin = rh.mTextureOrigin;
126 mZRange = rh.mZRange;
127 mSize = rh.mSize;
128 mDevicePixelRatio = rh.mDevicePixelRatio;
129 mImageFormat = rh.mImageFormat;
131 mRendererUsage = rh.mRendererUsage;
132 mFrameRate = rh.mFrameRate;
133 mCurrentFrame = rh.mCurrentFrame;
134 mSymbolLayerClipPaths = rh.mSymbolLayerClipPaths;
135 if ( isTemporal() )
137#ifdef QGISDEBUG
138 mHasTransformContext = rh.mHasTransformContext;
139#endif
140 mElevationMap = rh.elevationMap();
141
142 return *this;
143}
144
146{
147 QgsRenderContext context;
148 context.setPainter( painter );
149 if ( painter && painter->device() )
150 {
151 context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
152 }
153 else
154 {
155 context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
156 }
157
158 if ( painter && painter->renderHints() & QPainter::Antialiasing )
160 if ( painter && painter->renderHints() & QPainter::SmoothPixmapTransform )
162 if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
164
165 return context;
166}
167
169{
170 if ( !painter )
171 painter = mPainter;
172
173 if ( !painter )
174 return;
175
176 painter->setRenderHint( QPainter::Antialiasing, mFlags & Qgis::RenderContextFlag::Antialiasing );
177 painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & Qgis::RenderContextFlag::LosslessImageRendering );
178 painter->setRenderHint( QPainter::SmoothPixmapTransform, mFlags & Qgis::RenderContextFlag::HighQualityImageTransforms );
179}
180
182{
183#ifdef QGISDEBUG
184 if ( !mHasTransformContext )
185 QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
186#endif
187 return mTransformContext;
188}
189
191{
192 mTransformContext = context;
193#ifdef QGISDEBUG
194 mHasTransformContext = true;
195#endif
196}
197
199{
200 mFeedback = feedback;
201}
202
204{
205 return mFeedback;
206}
207
208void QgsRenderContext::setFlags( Qgis::RenderContextFlags flags )
209{
210 mFlags = flags;
211}
212
214{
215 if ( on )
216 mFlags |= flag;
217 else
218 mFlags &= ~( static_cast< int >( flag ) );
219}
220
221Qgis::RenderContextFlags QgsRenderContext::flags() const
222{
223 return mFlags;
224}
225
227{
228 return mFlags.testFlag( flag );
229}
230
232{
234 QgsRectangle extent = mapSettings.visibleExtent();
235 extent.grow( mapSettings.extentBuffer() );
236 ctx.setMapToPixel( mapSettings.mapToPixel() );
237 ctx.setExtent( extent );
238 ctx.setMapExtent( mapSettings.visibleExtent() );
244 ctx.setSelectionColor( mapSettings.selectionColor() );
256 ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
257 ctx.setDpiTarget( mapSettings.dpiTarget() >= 0.0 ? mapSettings.dpiTarget() : -1.0 );
258 ctx.setRendererScale( mapSettings.scale() );
259 ctx.setExpressionContext( mapSettings.expressionContext() );
262 ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
263 ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
264 ctx.setTransformContext( mapSettings.transformContext() );
265 ctx.setPathResolver( mapSettings.pathResolver() );
266 ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
267 ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
268 ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
269 ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
270 //this flag is only for stopping during the current rendering progress,
271 //so must be false at every new render operation
272 ctx.setRenderingStopped( false );
273 ctx.mCustomRenderingFlags = mapSettings.customRenderingFlags();
274 ctx.setIsTemporal( mapSettings.isTemporal() );
275 if ( ctx.isTemporal() )
276 ctx.setTemporalRange( mapSettings.temporalRange() );
277
278 ctx.setZRange( mapSettings.zRange() );
279 ctx.setOutputSize( mapSettings.outputSize() );
280 ctx.setDevicePixelRatio( mapSettings.devicePixelRatio() );
281 ctx.setImageFormat( mapSettings.outputImageFormat() );
282
283 ctx.mClippingRegions = mapSettings.clippingRegions();
284
285 ctx.mRendererUsage = mapSettings.rendererUsage();
286 ctx.mFrameRate = mapSettings.frameRate();
287 ctx.mCurrentFrame = mapSettings.currentFrame();
288
289 return ctx;
290}
291
293{
294 return mFlags.testFlag( Qgis::RenderContextFlag::ForceVectorOutput );
295}
296
298{
299 return mFlags.testFlag( Qgis::RenderContextFlag::UseAdvancedEffects );
300}
301
303{
305}
306
308{
309 return mFlags.testFlag( Qgis::RenderContextFlag::DrawEditingInfo );
310}
311
313{
314 return mFlags.testFlag( Qgis::RenderContextFlag::DrawSelection );
315}
316
318{
319 mCoordTransform = t;
320}
321
323{
325}
326
328{
330}
331
332void QgsRenderContext::setShowSelection( const bool showSelection )
333{
335}
336
338{
340}
341
343{
345}
346
348{
349 if ( ffp )
350 {
351 mFeatureFilterProvider.reset( ffp->clone() );
352 }
353 else
354 {
355 mFeatureFilterProvider.reset( nullptr );
356 }
357}
358
360{
361 return mFeatureFilterProvider.get();
362}
363
365{
366 double conversionFactor = 1.0;
367 bool isMapUnitHack = false;
368 switch ( unit )
369 {
370 case Qgis::RenderUnit::Millimeters:
371 conversionFactor = mScaleFactor;
372 break;
373
374 case Qgis::RenderUnit::Points:
375 conversionFactor = mScaleFactor / POINTS_TO_MM;
376 break;
377
378 case Qgis::RenderUnit::Inches:
379 conversionFactor = mScaleFactor * INCH_TO_MM;
380 break;
381
382 case Qgis::RenderUnit::MetersInMapUnits:
383 {
384 if ( mMapToPixel.isValid() )
385 size = convertMetersToMapUnits( size );
386 unit = Qgis::RenderUnit::MapUnits;
387 // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
389 }
390 case Qgis::RenderUnit::MapUnits:
391 {
392 if ( mMapToPixel.isValid() )
393 {
394 const double mup = scale.computeMapUnitsPerPixel( *this );
395 if ( mup > 0 )
396 {
397 conversionFactor = 1.0 / mup;
398 }
399 else
400 {
401 conversionFactor = 1.0;
402 }
403 }
404 else
405 {
406 // invalid map to pixel. A size in map units can't be calculated, so treat the size as points
407 // and clamp it to a reasonable range. It's the best we can do in this situation!
408 isMapUnitHack = true;
409 conversionFactor = mScaleFactor / POINTS_TO_MM;
410 }
411 break;
412 }
413 case Qgis::RenderUnit::Pixels:
414 conversionFactor = 1.0;
415 break;
416
417 case Qgis::RenderUnit::Unknown:
418 case Qgis::RenderUnit::Percentage:
419 //no sensible value
420 conversionFactor = 1.0;
421 break;
422 }
423
424 double convertedSize = size * conversionFactor;
425
426 if ( unit == Qgis::RenderUnit::MapUnits )
427 {
428 //check max/min size
429 if ( scale.minSizeMMEnabled )
430 convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
431 if ( scale.maxSizeMMEnabled )
432 convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
433 }
434
435 if ( isMapUnitHack )
436 {
437 // since we are arbitrarily treating map units as mm, we need to clamp to an (arbitrary!) reasonable range.
438 convertedSize = std::clamp( convertedSize, 10.0, 100.0 );
439 }
440 else
441 {
442 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
443 convertedSize *= symbologyReferenceScaleFactor;
444 }
445
447 {
448 // apply property based constraints in order to optimise symbol preview rendering
449 switch ( property )
450 {
452 break;
453
455 // excessively large shadow offset in symbol preview icons is undesirable -- it pushes the shadow outside of view
456 convertedSize = std::min( convertedSize, 100.0 );
457 break;
459 // excessively large blur in symbol preview icons is too slow to calculate
460 convertedSize = std::min<double>( convertedSize, 30 );
461 break;
463 // excessively large glow spread in symbol preview icons is too slow to calculate
464 convertedSize = std::min<double>( convertedSize, 50 );
465 break;
466 }
467 }
468
469 return convertedSize;
470}
471
472double QgsRenderContext::convertToMapUnits( double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale ) const
473{
474 const double mup = mMapToPixel.mapUnitsPerPixel();
475
476 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
477
478 switch ( unit )
479 {
480 case Qgis::RenderUnit::MetersInMapUnits:
481 {
482 size = convertMetersToMapUnits( size );
483 // Fall through to RenderMapUnits with values of meters converted to MapUnits
485 }
486 case Qgis::RenderUnit::MapUnits:
487 {
488 // check scale
489 double minSizeMU = std::numeric_limits<double>::lowest();
490 if ( scale.minSizeMMEnabled )
491 {
492 minSizeMU = scale.minSizeMM * mScaleFactor * mup;
493 }
494 if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
495 {
496 minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
497 }
498 size = std::max( size, minSizeMU );
499
500 double maxSizeMU = std::numeric_limits<double>::max();
501 if ( scale.maxSizeMMEnabled )
502 {
503 maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
504 }
505 if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
506 {
507 maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
508 }
509 size = std::min( size, maxSizeMU );
510
511 return size;
512 }
513 case Qgis::RenderUnit::Millimeters:
514 {
515 return size * mScaleFactor * mup / symbologyReferenceScaleFactor;
516 }
517 case Qgis::RenderUnit::Points:
518 {
519 return size * mScaleFactor * mup / POINTS_TO_MM / symbologyReferenceScaleFactor;
520 }
521 case Qgis::RenderUnit::Inches:
522 {
523 return size * mScaleFactor * mup * INCH_TO_MM / symbologyReferenceScaleFactor;
524 }
525 case Qgis::RenderUnit::Pixels:
526 {
527 return size * mup / symbologyReferenceScaleFactor;
528 }
529
530 case Qgis::RenderUnit::Unknown:
531 case Qgis::RenderUnit::Percentage:
532 //no sensible value
533 return 0.0;
534 }
535 return 0.0;
536}
537
538double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, Qgis::RenderUnit outputUnit ) const
539{
540 const double mup = mMapToPixel.mapUnitsPerPixel();
541 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
542
543 switch ( outputUnit )
544 {
545 case Qgis::RenderUnit::MetersInMapUnits:
546 {
547 return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
548 }
549 case Qgis::RenderUnit::MapUnits:
550 {
551 return sizeInMapUnits;
552 }
553 case Qgis::RenderUnit::Millimeters:
554 {
555 return sizeInMapUnits / ( mScaleFactor * mup ) * symbologyReferenceScaleFactor;
556 }
557 case Qgis::RenderUnit::Points:
558 {
559 return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM ) * symbologyReferenceScaleFactor;
560 }
561 case Qgis::RenderUnit::Inches:
562 {
563 return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM ) * symbologyReferenceScaleFactor;
564 }
565 case Qgis::RenderUnit::Pixels:
566 {
567 return sizeInMapUnits / mup * symbologyReferenceScaleFactor;
568 }
569
570 case Qgis::RenderUnit::Unknown:
571 case Qgis::RenderUnit::Percentage:
572 //no sensible value
573 return 0.0;
574 }
575 return 0.0;
576}
577
578double QgsRenderContext::convertMetersToMapUnits( double meters ) const
579{
580 switch ( mDistanceArea.sourceCrs().mapUnits() )
581 {
582 case Qgis::DistanceUnit::Meters:
583 return meters;
584 case Qgis::DistanceUnit::Degrees:
585 {
586 if ( mExtent.isNull() )
587 {
588 // we don't have an extent to calculate exactly -- so just use a very rough approximation
589 return meters * QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, Qgis::DistanceUnit::Degrees );
590 }
591
592 QgsPointXY pointCenter = mExtent.center();
593 // The Extent is in the sourceCrs(), when different from destinationCrs()
594 // - the point must be transformed, since DistanceArea uses the destinationCrs()
595 // Note: the default QgsCoordinateTransform() : authid() will return an empty String
596 if ( !mCoordTransform.isShortCircuited() )
597 {
598 pointCenter = mCoordTransform.transform( pointCenter );
599 }
600
601 const int multiplier = meters < 0 ? -1 : 1;
602 return multiplier * mDistanceArea.measureLineProjected( pointCenter, std::fabs( meters ) );
603 }
604 case Qgis::DistanceUnit::Kilometers:
605 case Qgis::DistanceUnit::Feet:
606 case Qgis::DistanceUnit::NauticalMiles:
607 case Qgis::DistanceUnit::Yards:
608 case Qgis::DistanceUnit::Miles:
609 case Qgis::DistanceUnit::Centimeters:
610 case Qgis::DistanceUnit::Millimeters:
611 case Qgis::DistanceUnit::Unknown:
612 return ( meters * QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, mDistanceArea.sourceCrs().mapUnits() ) );
613 }
614 return meters;
615}
616
617QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
618{
619 return mRenderedFeatureHandlers;
620}
621
622QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
623{
624 return mClippingRegions;
625}
626
628{
629 return mFeatureClipGeometry;
630}
631
633{
634 mFeatureClipGeometry = geometry;
635}
636
638{
639 return mTextureOrigin;
640}
641
642void QgsRenderContext::setTextureOrigin( const QPointF &origin )
643{
644 mTextureOrigin = origin;
645}
646
648{
649 return mZRange;
650}
651
653{
654 mZRange = range;
655}
656
658{
659 return mSize;
660}
661
663{
664 mSize = size;
665}
666
668{
669 return mDevicePixelRatio;
670}
671
673{
674 mDevicePixelRatio = ratio;
675}
676
678{
679 return outputSize() * mDevicePixelRatio;
680}
681
683{
684 return mFrameRate;
685}
686
688{
689 mFrameRate = rate;
690}
691
693{
694 return mCurrentFrame;
695}
696
698{
699 mCurrentFrame = frame;
700}
701
703{
704 return mElevationMap;
705}
706
708{
709 mElevationMap = map;
710}
711
712void QgsRenderContext::addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path )
713{
714 mSymbolLayerClipPaths[ symbolLayerId ].append( path );
715}
716
717QList<QPainterPath> QgsRenderContext::symbolLayerClipPaths( const QString &symbolLayerId ) const
718{
719 return mSymbolLayerClipPaths[ symbolLayerId ];
720}
721
722void QgsRenderContext::setDisabledSymbolLayers( const QSet<const QgsSymbolLayer *> &symbolLayers )
723{
724 mDisabledSymbolLayers.clear();
725 for ( const QgsSymbolLayer *symbolLayer : symbolLayers )
726 mDisabledSymbolLayers << symbolLayer->id();
727}
728
729void QgsRenderContext::setDisabledSymbolLayersV2( const QSet<QString> &symbolLayers )
730{
731 mDisabledSymbolLayers = symbolLayers;
732}
733
734QSet<const QgsSymbolLayer *> QgsRenderContext::disabledSymbolLayers() const
735{
736 return QSet<const QgsSymbolLayer *>();
737}
738
740{
741 return mDisabledSymbolLayers;
742}
743
745{
746 return !mDisabledSymbolLayers.contains( layer->id() );
747}
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:55
RenderSubcomponentProperty
Rendering subcomponent properties.
Definition: qgis.h:1882
@ Generic
Generic subcomponent property.
RenderUnit
Rendering size units.
Definition: qgis.h:3176
RenderContextFlag
Flags which affect rendering operations.
Definition: qgis.h:1693
@ 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.
@ 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.
@ 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)...
Q_GADGET Qgis::DistanceUnit mapUnits
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.
bool isShortCircuited() const
Returns true if the transform short circuits because the source and destination are equivalent.
QgsPointXY transform(const QgsPointXY &point, Qgis::TransformDirection direction=Qgis::TransformDirection::Forward) const SIP_THROW(QgsCsException)
Transform the point from the source CRS to the destination CRS.
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:203
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:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
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.
Definition: qgsmaptopixel.h:83
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:59
A rectangle specified with double values.
Definition: qgsrectangle.h:42
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
void grow(double delta)
Grows the rectangle in place by the specified amount.
Definition: qgsrectangle.h:296
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:251
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.
#define FALLTHROUGH
Definition: qgis.h:4120
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:3509
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define INCH_TO_MM
#define POINTS_TO_MM