QGIS API Documentation 3.39.0-Master (bca3cdb6021)
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"
28
29#define POINTS_TO_MM 2.83464567
30#define INCH_TO_MM 25.4
31
33 : mFlags( Qgis::RenderContextFlag::DrawEditingInfo | Qgis::RenderContextFlag::UseAdvancedEffects | Qgis::RenderContextFlag::DrawSelection | Qgis::RenderContextFlag::UseRenderingOptimization )
34{
36 // For RenderMetersInMapUnits support, when rendering in Degrees, the Ellipsoid must be set
37 // - for Previews/Icons the default Extent can be used
38 mDistanceArea.setEllipsoid( mDistanceArea.sourceCrs().ellipsoidAcronym() );
39}
40
42
45 , mFlags( rh.mFlags )
46 , mPainter( rh.mPainter )
47 , mPreviewRenderPainter( rh.mPreviewRenderPainter )
48 , mMaskPainter( rh.mMaskPainter )
49 , mCoordTransform( rh.mCoordTransform )
50 , mDistanceArea( rh.mDistanceArea )
51 , mExtent( rh.mExtent )
52 , mOriginalMapExtent( rh.mOriginalMapExtent )
53 , mMapToPixel( rh.mMapToPixel )
54 , mRenderingStopped( rh.mRenderingStopped )
55 , mFeedback( rh.mFeedback )
56 , mScaleFactor( rh.mScaleFactor )
57 , mDpiTarget( rh.mDpiTarget )
58 , mRendererScale( rh.mRendererScale )
59 , mSymbologyReferenceScale( rh.mSymbologyReferenceScale )
60 , mLabelingEngine( rh.mLabelingEngine )
61 , mLabelSink( rh.mLabelSink )
62 , mSelectionColor( rh.mSelectionColor )
63 , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
64 , mExpressionContext( rh.mExpressionContext )
65 , mGeometry( rh.mGeometry )
66 , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
67 , mSegmentationTolerance( rh.mSegmentationTolerance )
68 , mSegmentationToleranceType( rh.mSegmentationToleranceType )
69 , mTransformContext( rh.mTransformContext )
70 , mPathResolver( rh.mPathResolver )
71 , mTextRenderFormat( rh.mTextRenderFormat )
72 , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
73 , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
74 , mCustomProperties( rh.mCustomProperties )
75 , mDisabledSymbolLayers()
76 , mClippingRegions( rh.mClippingRegions )
77 , mFeatureClipGeometry( rh.mFeatureClipGeometry )
78 , mTextureOrigin( rh.mTextureOrigin )
79 , mZRange( rh.mZRange )
80 , mSize( rh.mSize )
81 , mDevicePixelRatio( rh.mDevicePixelRatio )
82 , mImageFormat( rh.mImageFormat )
83 , mRendererUsage( rh.mRendererUsage )
84 , mFrameRate( rh.mFrameRate )
85 , mCurrentFrame( rh.mCurrentFrame )
86 , mSymbolLayerClippingGeometries( rh.mSymbolLayerClippingGeometries )
87 , mMaskRenderSettings( rh.mMaskRenderSettings )
88#ifdef QGISDEBUG
89 , mHasTransformContext( rh.mHasTransformContext )
90#endif
91 , mElevationMap( rh.mElevationMap )
92{
93}
94
96{
97 mFlags = rh.mFlags;
98 mPainter = rh.mPainter;
99 mPreviewRenderPainter = rh.mPreviewRenderPainter;
100 mMaskPainter = rh.mMaskPainter;
101 mCoordTransform = rh.mCoordTransform;
102 mExtent = rh.mExtent;
103 mOriginalMapExtent = rh.mOriginalMapExtent;
104 mMapToPixel = rh.mMapToPixel;
105 mRenderingStopped = rh.mRenderingStopped;
106 mFeedback = rh.mFeedback;
107 mScaleFactor = rh.mScaleFactor;
108 mDpiTarget = rh.mDpiTarget;
109 mRendererScale = rh.mRendererScale;
110 mSymbologyReferenceScale = rh.mSymbologyReferenceScale;
111 mLabelingEngine = rh.mLabelingEngine;
112 mLabelSink = rh.mLabelSink;
113 mSelectionColor = rh.mSelectionColor;
114 mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
115 mExpressionContext = rh.mExpressionContext;
116 mGeometry = rh.mGeometry;
117 mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
118 mSegmentationTolerance = rh.mSegmentationTolerance;
119 mSegmentationToleranceType = rh.mSegmentationToleranceType;
120 mDistanceArea = rh.mDistanceArea;
121 mTransformContext = rh.mTransformContext;
122 mPathResolver = rh.mPathResolver;
123 mTextRenderFormat = rh.mTextRenderFormat;
124 mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
125 mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
126 mCustomProperties = rh.mCustomProperties;
127 mClippingRegions = rh.mClippingRegions;
128 mFeatureClipGeometry = rh.mFeatureClipGeometry;
129 mTextureOrigin = rh.mTextureOrigin;
130 mZRange = rh.mZRange;
131 mSize = rh.mSize;
132 mDevicePixelRatio = rh.mDevicePixelRatio;
133 mImageFormat = rh.mImageFormat;
135 mRendererUsage = rh.mRendererUsage;
136 mFrameRate = rh.mFrameRate;
137 mCurrentFrame = rh.mCurrentFrame;
138 mSymbolLayerClippingGeometries = rh.mSymbolLayerClippingGeometries;
139 mMaskRenderSettings = rh.mMaskRenderSettings;
140 if ( isTemporal() )
142#ifdef QGISDEBUG
143 mHasTransformContext = rh.mHasTransformContext;
144#endif
145 mElevationMap = rh.elevationMap();
146
147 return *this;
148}
149
151{
152 QgsRenderContext context;
153 context.setPainter( painter );
154 if ( painter && painter->device() )
155 {
156 context.setScaleFactor( painter->device()->physicalDpiX() / 25.4 );
157 }
158 else
159 {
160 context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
161 }
162
163 if ( painter && painter->renderHints() & QPainter::Antialiasing )
165 if ( painter && painter->renderHints() & QPainter::SmoothPixmapTransform )
167 if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
169
170 return context;
171}
172
174{
175 if ( !painter )
176 painter = mPainter;
177
178 if ( !painter )
179 return;
180
181 painter->setRenderHint( QPainter::Antialiasing, mFlags & Qgis::RenderContextFlag::Antialiasing );
182 painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & Qgis::RenderContextFlag::LosslessImageRendering );
183 painter->setRenderHint( QPainter::SmoothPixmapTransform, mFlags & Qgis::RenderContextFlag::HighQualityImageTransforms );
184}
185
187{
188#ifdef QGISDEBUG
189 if ( !mHasTransformContext )
190 QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
191#endif
192 return mTransformContext;
193}
194
196{
197 mTransformContext = context;
198#ifdef QGISDEBUG
199 mHasTransformContext = true;
200#endif
201}
202
204{
205 mFeedback = feedback;
206}
207
209{
210 return mFeedback;
211}
212
214{
215 mFlags = flags;
216}
217
219{
220 if ( on )
221 mFlags |= flag;
222 else
223 mFlags &= ~( static_cast< int >( flag ) );
224}
225
227{
228 return mFlags;
229}
230
232{
233 return mFlags.testFlag( flag );
234}
235
237{
239 QgsRectangle extent = mapSettings.visibleExtent();
240 extent.grow( mapSettings.extentBuffer() );
241 ctx.setMapToPixel( mapSettings.mapToPixel() );
242 ctx.setExtent( extent );
243 ctx.setMapExtent( mapSettings.visibleExtent() );
249 ctx.setSelectionColor( mapSettings.selectionColor() );
263 ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
264 ctx.setDpiTarget( mapSettings.dpiTarget() >= 0.0 ? mapSettings.dpiTarget() : -1.0 );
265 ctx.setRendererScale( mapSettings.scale() );
266 ctx.setExpressionContext( mapSettings.expressionContext() );
269 ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
270 ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
271 ctx.setTransformContext( mapSettings.transformContext() );
272 ctx.setPathResolver( mapSettings.pathResolver() );
273 ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
274 ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
275 ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
276 ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
277 //this flag is only for stopping during the current rendering progress,
278 //so must be false at every new render operation
279 ctx.setRenderingStopped( false );
280 ctx.mCustomProperties = mapSettings.customRenderingFlags();
281 ctx.setIsTemporal( mapSettings.isTemporal() );
282 if ( ctx.isTemporal() )
283 ctx.setTemporalRange( mapSettings.temporalRange() );
284
285 ctx.setZRange( mapSettings.zRange() );
286 ctx.setOutputSize( mapSettings.outputSize() );
287 ctx.setDevicePixelRatio( mapSettings.devicePixelRatio() );
288 ctx.setImageFormat( mapSettings.outputImageFormat() );
289
290 ctx.mClippingRegions = mapSettings.clippingRegions();
291
292 ctx.setMaskSettings( mapSettings.maskSettings() );
293
294 ctx.mRendererUsage = mapSettings.rendererUsage();
295 ctx.mFrameRate = mapSettings.frameRate();
296 ctx.mCurrentFrame = mapSettings.currentFrame();
297
298 const QStringList layerIds = mapSettings.layerIds( true );
299 if ( !layerIds.empty() )
300 ctx.setCustomProperty( QStringLiteral( "visible_layer_ids" ), layerIds );
301
302 return ctx;
303}
304
306{
307 return mFlags.testFlag( Qgis::RenderContextFlag::ForceVectorOutput );
308}
309
311{
312 return mFlags.testFlag( Qgis::RenderContextFlag::UseAdvancedEffects );
313}
314
319
321{
322 return mFlags.testFlag( Qgis::RenderContextFlag::DrawEditingInfo );
323}
324
326{
327 return mFlags.testFlag( Qgis::RenderContextFlag::DrawSelection );
328}
329
331{
332 mCoordTransform = t;
333}
334
339
344
349
354
359
361{
362 if ( ffp )
363 {
364 mFeatureFilterProvider.reset( ffp->clone() );
365 }
366 else
367 {
368 mFeatureFilterProvider.reset( nullptr );
369 }
370}
371
373{
374 return mFeatureFilterProvider.get();
375}
376
378{
379 double conversionFactor = 1.0;
380 bool isMapUnitHack = false;
381 switch ( unit )
382 {
384 conversionFactor = mScaleFactor;
385 break;
386
388 conversionFactor = mScaleFactor / POINTS_TO_MM;
389 break;
390
392 conversionFactor = mScaleFactor * INCH_TO_MM;
393 break;
394
396 {
397 if ( mMapToPixel.isValid() )
398 size = convertMetersToMapUnits( size );
400 // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
401 [[fallthrough]];
402 }
404 {
405 if ( mMapToPixel.isValid() )
406 {
407 const double mup = scale.computeMapUnitsPerPixel( *this );
408 if ( mup > 0 )
409 {
410 conversionFactor = 1.0 / mup;
411 }
412 else
413 {
414 conversionFactor = 1.0;
415 }
416 }
417 else
418 {
419 // invalid map to pixel. A size in map units can't be calculated, so treat the size as points
420 // and clamp it to a reasonable range. It's the best we can do in this situation!
421 isMapUnitHack = true;
422 conversionFactor = mScaleFactor / POINTS_TO_MM;
423 }
424 break;
425 }
427 conversionFactor = 1.0;
428 break;
429
432 //no sensible value
433 conversionFactor = 1.0;
434 break;
435 }
436
437 double convertedSize = size * conversionFactor;
438
439 if ( unit == Qgis::RenderUnit::MapUnits )
440 {
441 //check max/min size
442 if ( scale.minSizeMMEnabled )
443 convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
444 if ( scale.maxSizeMMEnabled )
445 convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
446 }
447
448 if ( isMapUnitHack )
449 {
450 // since we are arbitrarily treating map units as mm, we need to clamp to an (arbitrary!) reasonable range.
451 convertedSize = std::clamp( convertedSize, 10.0, 100.0 );
452 }
453 else
454 {
455 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
456 convertedSize *= symbologyReferenceScaleFactor;
457 }
458
460 {
461 // apply property based constraints in order to optimise symbol preview rendering
462 switch ( property )
463 {
465 break;
466
468 // excessively large shadow offset in symbol preview icons is undesirable -- it pushes the shadow outside of view
469 convertedSize = std::min( convertedSize, 100.0 );
470 break;
472 // excessively large blur in symbol preview icons is too slow to calculate
473 convertedSize = std::min<double>( convertedSize, 30 );
474 break;
476 // excessively large glow spread in symbol preview icons is too slow to calculate
477 convertedSize = std::min<double>( convertedSize, 50 );
478 break;
479 }
480 }
481
482 return convertedSize;
483}
484
486{
487 double conversionFactor = 1.0;
488 // NOLINTBEGIN(bugprone-branch-clone)
489 switch ( unit )
490 {
492 conversionFactor = 1 / mScaleFactor;
493 break;
494
496 conversionFactor = POINTS_TO_MM / mScaleFactor;
497 break;
498
500 conversionFactor = 1 / ( mScaleFactor * INCH_TO_MM );
501 break;
502
504 {
505 if ( mMapToPixel.isValid() )
506 size = 1 / convertMetersToMapUnits( size );
507 // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
508 [[fallthrough]];
509 }
511 {
512 if ( mMapToPixel.isValid() )
513 {
514 const double mup = mapToPixel().mapUnitsPerPixel();;
515 if ( mup > 0 )
516 {
517 conversionFactor = mup / 1.0;
518 }
519 else
520 {
521 conversionFactor = 1.0;
522 }
523 }
524 else
525 {
526 // invalid map to pixel. A size in map units can't be calculated, so treat the size as points.
527 // It's the best we can do in this situation!
528 conversionFactor = POINTS_TO_MM / mScaleFactor;
529 }
530 break;
531 }
533 conversionFactor = 1.0;
534 break;
535
538 //no sensible value
539 conversionFactor = 1.0;
540 break;
541 }
542 // NOLINTEND(bugprone-branch-clone)
543
544 return size * conversionFactor;
545}
546
547double QgsRenderContext::convertToMapUnits( double size, Qgis::RenderUnit unit, const QgsMapUnitScale &scale ) const
548{
549 const double mup = mMapToPixel.mapUnitsPerPixel();
550
551 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
552
553 switch ( unit )
554 {
556 {
557 size = convertMetersToMapUnits( size );
558 // Fall through to RenderMapUnits with values of meters converted to MapUnits
559 [[fallthrough]];
560 }
562 {
563 // check scale
564 double minSizeMU = std::numeric_limits<double>::lowest();
565 if ( scale.minSizeMMEnabled )
566 {
567 minSizeMU = scale.minSizeMM * mScaleFactor * mup;
568 }
569 if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
570 {
571 minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
572 }
573 size = std::max( size, minSizeMU );
574
575 double maxSizeMU = std::numeric_limits<double>::max();
576 if ( scale.maxSizeMMEnabled )
577 {
578 maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
579 }
580 if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
581 {
582 maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
583 }
584 size = std::min( size, maxSizeMU );
585
586 return size;
587 }
589 {
590 return size * mScaleFactor * mup / symbologyReferenceScaleFactor;
591 }
593 {
594 return size * mScaleFactor * mup / POINTS_TO_MM / symbologyReferenceScaleFactor;
595 }
597 {
598 return size * mScaleFactor * mup * INCH_TO_MM / symbologyReferenceScaleFactor;
599 }
601 {
602 return size * mup / symbologyReferenceScaleFactor;
603 }
604
607 //no sensible value
608 return 0.0;
609 }
610 return 0.0;
611}
612
613double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, Qgis::RenderUnit outputUnit ) const
614{
615 const double mup = mMapToPixel.mapUnitsPerPixel();
616 const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
617
618 switch ( outputUnit )
619 {
621 {
622 return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
623 }
625 {
626 return sizeInMapUnits;
627 }
629 {
630 return sizeInMapUnits / ( mScaleFactor * mup ) * symbologyReferenceScaleFactor;
631 }
633 {
634 return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM ) * symbologyReferenceScaleFactor;
635 }
637 {
638 return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM ) * symbologyReferenceScaleFactor;
639 }
641 {
642 return sizeInMapUnits / mup * symbologyReferenceScaleFactor;
643 }
644
647 //no sensible value
648 return 0.0;
649 }
650 return 0.0;
651}
652
653double QgsRenderContext::convertMetersToMapUnits( double meters ) const
654{
655 switch ( mDistanceArea.sourceCrs().mapUnits() )
656 {
658 return meters;
660 {
661 if ( mExtent.isNull() )
662 {
663 // we don't have an extent to calculate exactly -- so just use a very rough approximation
665 }
666
667 QgsPointXY pointCenter = mExtent.center();
668 // The Extent is in the sourceCrs(), when different from destinationCrs()
669 // - the point must be transformed, since DistanceArea uses the destinationCrs()
670 // Note: the default QgsCoordinateTransform() : authid() will return an empty String
671 if ( !mCoordTransform.isShortCircuited() )
672 {
673 try
674 {
675 pointCenter = mCoordTransform.transform( pointCenter );
676 }
677 catch ( const QgsCsException & )
678 {
679 QgsDebugError( QStringLiteral( "QgsRenderContext::convertMetersToMapUnits(): failed to reproject pointCenter" ) );
680 // what should we return;.. ?
681 return meters;
682 }
683 }
684
685 const int multiplier = meters < 0 ? -1 : 1;
686 return multiplier * mDistanceArea.measureLineProjected( pointCenter, std::fabs( meters ) );
687 }
737 }
738 return meters;
739}
740
741QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
742{
743 return mRenderedFeatureHandlers;
744}
745
746QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
747{
748 return mClippingRegions;
749}
750
752{
753 return mFeatureClipGeometry;
754}
755
757{
758 mFeatureClipGeometry = geometry;
759}
760
762{
763 return mTextureOrigin;
764}
765
766void QgsRenderContext::setTextureOrigin( const QPointF &origin )
767{
768 mTextureOrigin = origin;
769}
770
772{
773 mMaskRenderSettings = settings;
774}
775
777{
778 return mZRange;
779}
780
782{
783 mZRange = range;
784}
785
787{
788 return mSize;
789}
790
792{
793 mSize = size;
794}
795
797{
798 return mDevicePixelRatio;
799}
800
802{
803 mDevicePixelRatio = ratio;
804}
805
807{
808 return outputSize() * mDevicePixelRatio;
809}
810
812{
813 return mFrameRate;
814}
815
817{
818 mFrameRate = rate;
819}
820
822{
823 return mCurrentFrame;
824}
825
827{
828 mCurrentFrame = frame;
829}
830
832{
833 return mElevationMap;
834}
835
837{
838 mElevationMap = map;
839}
840
841void QgsRenderContext::addSymbolLayerClipPath( const QString &symbolLayerId, QPainterPath path )
842{
844 if ( !geometry.isEmpty() )
845 addSymbolLayerClipGeometry( symbolLayerId, geometry );
846}
847
848QList<QPainterPath> QgsRenderContext::symbolLayerClipPaths( const QString &symbolLayerId ) const
849{
850 const QVector<QgsGeometry> geometries = symbolLayerClipGeometries( symbolLayerId );
851 QList<QPainterPath> res;
852 res.reserve( geometries.size() );
853 for ( const QgsGeometry &geometry : geometries )
854 {
855 res << geometry.constGet()->asQPainterPath();
856 }
857 return res;
858}
859
860void QgsRenderContext::addSymbolLayerClipGeometry( const QString &symbolLayerId, const QgsGeometry &geometry )
861{
862 if ( geometry.isMultipart() )
863 {
864 mSymbolLayerClippingGeometries[ symbolLayerId ].append( geometry.asGeometryCollection() );
865 }
866 else
867 {
868 mSymbolLayerClippingGeometries[ symbolLayerId ].append( geometry );
869 }
870}
871
872bool QgsRenderContext::symbolLayerHasClipGeometries( const QString &symbolLayerId ) const
873{
874 auto it = mSymbolLayerClippingGeometries.constFind( symbolLayerId );
875 if ( it == mSymbolLayerClippingGeometries.constEnd() )
876 return false;
877 return !it.value().isEmpty();
878}
879
880QVector<QgsGeometry> QgsRenderContext::symbolLayerClipGeometries( const QString &symbolLayerId ) const
881{
882 return mSymbolLayerClippingGeometries[ symbolLayerId ];
883}
884
885void QgsRenderContext::setDisabledSymbolLayers( const QSet<const QgsSymbolLayer *> &symbolLayers )
886{
887 mDisabledSymbolLayers.clear();
888 for ( const QgsSymbolLayer *symbolLayer : symbolLayers )
889 mDisabledSymbolLayers << symbolLayer->id();
890}
891
892void QgsRenderContext::setDisabledSymbolLayersV2( const QSet<QString> &symbolLayers )
893{
894 mDisabledSymbolLayers = symbolLayers;
895}
896
897QSet<const QgsSymbolLayer *> QgsRenderContext::disabledSymbolLayers() const
898{
899 return QSet<const QgsSymbolLayer *>();
900}
901
903{
904 return mDisabledSymbolLayers;
905}
906
908{
909 return !mDisabledSymbolLayers.contains( layer->id() );
910}
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
RenderSubcomponentProperty
Rendering subcomponent properties.
Definition qgis.h:2821
@ Generic
Generic subcomponent property.
@ NoSimplification
No simplification can be applied.
@ YardsBritishSears1922Truncated
British yards (Sears 1922 truncated)
@ Feet
Imperial feet.
@ MilesUSSurvey
US Survey miles.
@ LinksBritishSears1922
British links (Sears 1922)
@ YardsBritishBenoit1895A
British yards (Benoit 1895 A)
@ LinksBritishBenoit1895A
British links (Benoit 1895 A)
@ Centimeters
Centimeters.
@ YardsIndian1975
Indian yards (1975)
@ FeetUSSurvey
US Survey feet.
@ Millimeters
Millimeters.
@ FeetBritishSears1922
British feet (Sears 1922)
@ YardsClarkes
Clarke's yards.
@ YardsIndian
Indian yards.
@ FeetBritishBenoit1895B
British feet (Benoit 1895 B)
@ Miles
Terrestrial miles.
@ LinksUSSurvey
US Survey links.
@ ChainsUSSurvey
US Survey chains.
@ FeetClarkes
Clarke's feet.
@ Unknown
Unknown distance unit.
@ Yards
Imperial yards.
@ FeetBritish1936
British feet (1936)
@ FeetIndian1962
Indian feet (1962)
@ YardsBritishSears1922
British yards (Sears 1922)
@ FeetIndian1937
Indian feet (1937)
@ YardsIndian1937
Indian yards (1937)
@ Degrees
Degrees, for planar geographic CRS distance measurements.
@ ChainsBritishBenoit1895B
British chains (Benoit 1895 B)
@ LinksBritishSears1922Truncated
British links (Sears 1922 truncated)
@ ChainsBritishBenoit1895A
British chains (Benoit 1895 A)
@ YardsBritishBenoit1895B
British yards (Benoit 1895 B)
@ FeetBritish1865
British feet (1865)
@ YardsIndian1962
Indian yards (1962)
@ FeetBritishSears1922Truncated
British feet (Sears 1922 truncated)
@ MetersGermanLegal
German legal meter.
@ LinksBritishBenoit1895B
British links (Benoit 1895 B)
@ ChainsInternational
International chains.
@ LinksInternational
International links.
@ ChainsBritishSears1922Truncated
British chains (Sears 1922 truncated)
@ FeetIndian
Indian (geodetic) feet.
@ NauticalMiles
Nautical miles.
@ ChainsClarkes
Clarke's chains.
@ LinksClarkes
Clarke's links.
@ ChainsBritishSears1922
British chains (Sears 1922)
@ Kilometers
Kilometers.
@ FeetIndian1975
Indian feet (1975)
@ FeetGoldCoast
Gold Coast feet.
@ FeetBritishBenoit1895A
British feet (Benoit 1895 A)
QFlags< RenderContextFlag > RenderContextFlags
Render context flags.
Definition qgis.h:2591
RenderUnit
Rendering size units.
Definition qgis.h:4819
@ 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:2566
@ 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.
@ 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...
@ AlwaysUseGlobalMasks
When applying clipping paths for selective masking, always use global ("entire map") paths,...
@ 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.
@ 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.
@ 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...
@ AlwaysUseGlobalMasks
When applying clipping paths for selective masking, always use global ("entire map") paths,...
@ 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.
@ 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)...
virtual bool isEmpty() const
Returns true if the geometry is empty.
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
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:231
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
static QgsGeometry painterPathToGeometry(const QPainterPath &path)
Converts a painter path to a QgsGeometry.
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.
QStringList layerIds(bool expandGroupLayers=false) const
Returns the list of layer IDs which will be rendered in the map.
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
long long currentFrame() const
Returns the current frame number of the map, for maps which are part of an animation.
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.
const QgsMaskRenderSettings & maskSettings() const
Returns a reference to the mask render settings, which control how masks are drawn and behave during ...
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.
Contains settings regarding how masks are calculated and handled during a map render.
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...
bool symbolLayerHasClipGeometries(const QString &symbolLayerId) const
Returns true if the symbol layer with matching ID has any associated clip geometries.
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.
double convertFromPainterUnits(double size, Qgis::RenderUnit unit) const
Converts a size from painter units (pixels) to the specified render unit.
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 setMaskSettings(const QgsMaskRenderSettings &settings)
Sets the mask render settings, which control how masks are drawn and behave during render operations.
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 ...
Q_DECL_DEPRECATED 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.
const QgsMapToPixel & mapToPixel() const
Returns the context's map to pixel transform, which transforms between map coordinates and device coo...
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.
void setCustomProperty(const QString &property, const QVariant &value)
Sets a custom rendering property.
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.
QVector< QgsGeometry > symbolLayerClipGeometries(const QString &symbolLayerId) const
Returns clipping geometries to be applied to the symbolLayer before rendering.
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.
void addSymbolLayerClipGeometry(const QString &symbolLayerId, const QgsGeometry &geometry)
Add a clip geometry to be applied to the symbolLayer before rendering.
Qgis::RenderContextFlags flags() const
Returns combination of flags used for rendering.
Q_DECL_DEPRECATED 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(Qgis::VectorRenderingSimplificationFlags simplifyHints)
Sets the simplification hints of the vector layer managed.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:5883
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:39
#define QgsDebugError(str)
Definition qgslogger.h:38
#define INCH_TO_MM
#define POINTS_TO_MM