QGIS API Documentation  3.21.0-Master (5b68dc587e)
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"
22 #include "qgsexpression.h"
23 #include "qgsvectorlayer.h"
25 #include "qgslogger.h"
26 #include "qgspoint.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  , mSelectionColor( rh.mSelectionColor )
60  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
61  , mExpressionContext( rh.mExpressionContext )
62  , mGeometry( rh.mGeometry )
63  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
64  , mSegmentationTolerance( rh.mSegmentationTolerance )
65  , mSegmentationToleranceType( rh.mSegmentationToleranceType )
66  , mTransformContext( rh.mTransformContext )
67  , mPathResolver( rh.mPathResolver )
68  , mTextRenderFormat( rh.mTextRenderFormat )
69  , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
70  , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
71  , mCustomRenderingFlags( rh.mCustomRenderingFlags )
72  , mDisabledSymbolLayers()
73  , mClippingRegions( rh.mClippingRegions )
74  , mFeatureClipGeometry( rh.mFeatureClipGeometry )
75  , mTextureOrigin( rh.mTextureOrigin )
76  , mZRange( rh.mZRange )
77 #ifdef QGISDEBUG
78  , mHasTransformContext( rh.mHasTransformContext )
79 #endif
80 {
81 }
82 
84 {
85  mFlags = rh.mFlags;
86  mPainter = rh.mPainter;
87  mMaskPainter = rh.mMaskPainter;
88  mCoordTransform = rh.mCoordTransform;
89  mExtent = rh.mExtent;
90  mOriginalMapExtent = rh.mOriginalMapExtent;
91  mMapToPixel = rh.mMapToPixel;
92  mRenderingStopped = rh.mRenderingStopped;
93  mFeedback = rh.mFeedback;
94  mScaleFactor = rh.mScaleFactor;
95  mDpiTarget = rh.mDpiTarget;
96  mRendererScale = rh.mRendererScale;
97  mSymbologyReferenceScale = rh.mSymbologyReferenceScale;
98  mLabelingEngine = rh.mLabelingEngine;
99  mSelectionColor = rh.mSelectionColor;
100  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
101  mExpressionContext = rh.mExpressionContext;
102  mGeometry = rh.mGeometry;
103  mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
104  mSegmentationTolerance = rh.mSegmentationTolerance;
105  mSegmentationToleranceType = rh.mSegmentationToleranceType;
106  mDistanceArea = rh.mDistanceArea;
107  mTransformContext = rh.mTransformContext;
108  mPathResolver = rh.mPathResolver;
109  mTextRenderFormat = rh.mTextRenderFormat;
110  mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
111  mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
112  mCustomRenderingFlags = rh.mCustomRenderingFlags;
113  mClippingRegions = rh.mClippingRegions;
114  mFeatureClipGeometry = rh.mFeatureClipGeometry;
115  mTextureOrigin = rh.mTextureOrigin;
116  mZRange = rh.mZRange;
117  setIsTemporal( rh.isTemporal() );
118  if ( isTemporal() )
120 #ifdef QGISDEBUG
121  mHasTransformContext = rh.mHasTransformContext;
122 #endif
123 
124  return *this;
125 }
126 
128 {
129  QgsRenderContext context;
130  context.setPainter( painter );
131  if ( painter && painter->device() )
132  {
133  context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
134  }
135  else
136  {
137  context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
138  }
139 
140  if ( painter && painter->renderHints() & QPainter::Antialiasing )
142 
143 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
144  if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
146 #endif
147 
148  return context;
149 }
150 
151 void QgsRenderContext::setPainterFlagsUsingContext( QPainter *painter ) const
152 {
153  if ( !painter )
154  painter = mPainter;
155 
156  if ( !painter )
157  return;
158 
159  painter->setRenderHint( QPainter::Antialiasing, mFlags & Qgis::RenderContextFlag::Antialiasing );
160 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
161  painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & Qgis::RenderContextFlag::LosslessImageRendering );
162 #endif
163 }
164 
166 {
167 #ifdef QGISDEBUG
168  if ( !mHasTransformContext )
169  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
170 #endif
171  return mTransformContext;
172 }
173 
175 {
176  mTransformContext = context;
177 #ifdef QGISDEBUG
178  mHasTransformContext = true;
179 #endif
180 }
181 
183 {
184  mFeedback = feedback;
185 }
186 
188 {
189  return mFeedback;
190 }
191 
192 void QgsRenderContext::setFlags( Qgis::RenderContextFlags flags )
193 {
194  mFlags = flags;
195 }
196 
198 {
199  if ( on )
200  mFlags |= flag;
201  else
202  mFlags &= ~( static_cast< int >( flag ) );
203 }
204 
205 Qgis::RenderContextFlags QgsRenderContext::flags() const
206 {
207  return mFlags;
208 }
209 
211 {
212  return mFlags.testFlag( flag );
213 }
214 
216 {
217  QgsRenderContext ctx;
218  QgsRectangle extent = mapSettings.visibleExtent();
219  extent.grow( mapSettings.extentBuffer() );
220  ctx.setMapToPixel( mapSettings.mapToPixel() );
221  ctx.setExtent( extent );
222  ctx.setMapExtent( mapSettings.visibleExtent() );
228  ctx.setSelectionColor( mapSettings.selectionColor() );
238  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
239  ctx.setDpiTarget( mapSettings.dpiTarget() >= 0.0 ? mapSettings.dpiTarget() : -1.0 );
240  ctx.setRendererScale( mapSettings.scale() );
241  ctx.setExpressionContext( mapSettings.expressionContext() );
242  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
244  ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
245  ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
246  ctx.setTransformContext( mapSettings.transformContext() );
247  ctx.setPathResolver( mapSettings.pathResolver() );
248  ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
249  ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
250  ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
251  ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
252  //this flag is only for stopping during the current rendering progress,
253  //so must be false at every new render operation
254  ctx.setRenderingStopped( false );
255  ctx.mCustomRenderingFlags = mapSettings.customRenderingFlags();
256  ctx.setIsTemporal( mapSettings.isTemporal() );
257  if ( ctx.isTemporal() )
258  ctx.setTemporalRange( mapSettings.temporalRange() );
259 
260  ctx.setZRange( mapSettings.zRange() );
261 
262  ctx.mClippingRegions = mapSettings.clippingRegions();
263 
264  return ctx;
265 }
266 
268 {
269  return mFlags.testFlag( Qgis::RenderContextFlag::ForceVectorOutput );
270 }
271 
273 {
274  return mFlags.testFlag( Qgis::RenderContextFlag::UseAdvancedEffects );
275 }
276 
278 {
280 }
281 
283 {
284  return mFlags.testFlag( Qgis::RenderContextFlag::DrawEditingInfo );
285 }
286 
288 {
289  return mFlags.testFlag( Qgis::RenderContextFlag::DrawSelection );
290 }
291 
293 {
294  mCoordTransform = t;
295 }
296 
298 {
300 }
301 
303 {
305 }
306 
307 void QgsRenderContext::setShowSelection( const bool showSelection )
308 {
310 }
311 
313 {
314  return mFlags.testFlag( Qgis::RenderContextFlag::UseRenderingOptimization );
315 }
316 
318 {
320 }
321 
323 {
324  if ( ffp )
325  {
326  mFeatureFilterProvider.reset( ffp->clone() );
327  }
328  else
329  {
330  mFeatureFilterProvider.reset( nullptr );
331  }
332 }
333 
335 {
336  return mFeatureFilterProvider.get();
337 }
338 
340 {
341  double conversionFactor = 1.0;
342  bool isMapUnitHack = false;
343  switch ( unit )
344  {
346  conversionFactor = mScaleFactor;
347  break;
348 
350  conversionFactor = mScaleFactor / POINTS_TO_MM;
351  break;
352 
354  conversionFactor = mScaleFactor * INCH_TO_MM;
355  break;
356 
358  {
359  if ( mMapToPixel.isValid() )
360  size = convertMetersToMapUnits( size );
362  // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
364  }
366  {
367  if ( mMapToPixel.isValid() )
368  {
369  const double mup = scale.computeMapUnitsPerPixel( *this );
370  if ( mup > 0 )
371  {
372  conversionFactor = 1.0 / mup;
373  }
374  else
375  {
376  conversionFactor = 1.0;
377  }
378  }
379  else
380  {
381  // invalid map to pixel. A size in map units can't be calculated, so treat the size as points
382  // and clamp it to a reasonable range. It's the best we can do in this situation!
383  isMapUnitHack = true;
384  conversionFactor = mScaleFactor / POINTS_TO_MM;
385  }
386  break;
387  }
389  conversionFactor = 1.0;
390  break;
391 
394  //no sensible value
395  conversionFactor = 1.0;
396  break;
397  }
398 
399  double convertedSize = size * conversionFactor;
400 
401  if ( unit == QgsUnitTypes::RenderMapUnits )
402  {
403  //check max/min size
404  if ( scale.minSizeMMEnabled )
405  convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
406  if ( scale.maxSizeMMEnabled )
407  convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
408  }
409 
410  if ( isMapUnitHack )
411  {
412  // since we are arbitrarily treating map units as mm, we need to clamp to an (arbitrary!) reasonable range.
413  convertedSize = std::clamp( convertedSize, 10.0, 100.0 );
414  }
415  else
416  {
417  const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
418  convertedSize *= symbologyReferenceScaleFactor;
419  }
420 
422  {
423  // apply property based constraints in order to optimise symbol preview rendering
424  switch ( property )
425  {
427  break;
428 
430  // excessively large shadow offset in symbol preview icons is undesirable -- it pushes the shadow outside of view
431  convertedSize = std::min( convertedSize, 100.0 );
432  break;
434  // excessively large blur in symbol preview icons is too slow to calculate
435  convertedSize = std::min<double>( convertedSize, 30 );
436  break;
438  // excessively large glow spread in symbol preview icons is too slow to calculate
439  convertedSize = std::min<double>( convertedSize, 50 );
440  break;
441  }
442  }
443 
444  return convertedSize;
445 }
446 
447 double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale ) const
448 {
449  const double mup = mMapToPixel.mapUnitsPerPixel();
450 
451  const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
452 
453  switch ( unit )
454  {
456  {
457  size = convertMetersToMapUnits( size );
458  // Fall through to RenderMapUnits with values of meters converted to MapUnits
460  }
462  {
463  // check scale
464  double minSizeMU = std::numeric_limits<double>::lowest();
465  if ( scale.minSizeMMEnabled )
466  {
467  minSizeMU = scale.minSizeMM * mScaleFactor * mup;
468  }
469  if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
470  {
471  minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
472  }
473  size = std::max( size, minSizeMU );
474 
475  double maxSizeMU = std::numeric_limits<double>::max();
476  if ( scale.maxSizeMMEnabled )
477  {
478  maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
479  }
480  if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
481  {
482  maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
483  }
484  size = std::min( size, maxSizeMU );
485 
486  return size;
487  }
489  {
490  return size * mScaleFactor * mup / symbologyReferenceScaleFactor;
491  }
493  {
494  return size * mScaleFactor * mup / POINTS_TO_MM / symbologyReferenceScaleFactor;
495  }
497  {
498  return size * mScaleFactor * mup * INCH_TO_MM / symbologyReferenceScaleFactor;
499  }
501  {
502  return size * mup / symbologyReferenceScaleFactor;
503  }
504 
507  //no sensible value
508  return 0.0;
509  }
510  return 0.0;
511 }
512 
513 double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const
514 {
515  const double mup = mMapToPixel.mapUnitsPerPixel();
516  const double symbologyReferenceScaleFactor = mSymbologyReferenceScale > 0 ? mSymbologyReferenceScale / mRendererScale : 1;
517 
518  switch ( outputUnit )
519  {
521  {
522  return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
523  }
525  {
526  return sizeInMapUnits;
527  }
529  {
530  return sizeInMapUnits / ( mScaleFactor * mup ) * symbologyReferenceScaleFactor;
531  }
533  {
534  return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM ) * symbologyReferenceScaleFactor;
535  }
537  {
538  return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM ) * symbologyReferenceScaleFactor;
539  }
541  {
542  return sizeInMapUnits / mup * symbologyReferenceScaleFactor;
543  }
544 
547  //no sensible value
548  return 0.0;
549  }
550  return 0.0;
551 }
552 
553 double QgsRenderContext::convertMetersToMapUnits( double meters ) const
554 {
555  switch ( mDistanceArea.sourceCrs().mapUnits() )
556  {
558  return meters;
560  {
561  if ( mExtent.isNull() )
562  {
563  // we don't have an extent to calculate exactly -- so just use a very rough approximation
565  }
566 
567  QgsPointXY pointCenter = mExtent.center();
568  // The Extent is in the sourceCrs(), when different from destinationCrs()
569  // - the point must be transformed, since DistanceArea uses the destinationCrs()
570  // Note: the default QgsCoordinateTransform() : authid() will return an empty String
571  if ( !mCoordTransform.isShortCircuited() )
572  {
573  pointCenter = mCoordTransform.transform( pointCenter );
574  }
575  return mDistanceArea.measureLineProjected( pointCenter, meters );
576  }
585  return ( meters * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mDistanceArea.sourceCrs().mapUnits() ) );
586  }
587  return meters;
588 }
589 
590 QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
591 {
592  return mRenderedFeatureHandlers;
593 }
594 
595 QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
596 {
597  return mClippingRegions;
598 }
599 
601 {
602  return mFeatureClipGeometry;
603 }
604 
606 {
607  mFeatureClipGeometry = geometry;
608 }
609 
611 {
612  return mTextureOrigin;
613 }
614 
615 void QgsRenderContext::setTextureOrigin( const QPointF &origin )
616 {
617  mTextureOrigin = origin;
618 }
619 
621 {
622  return mZRange;
623 }
624 
626 {
627  mZRange = range;
628 }
629 
630 
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:63
RenderSubcomponentProperty
Rendering subcomponent properties.
Definition: qgis.h:976
@ Generic
Generic subcomponent property.
RenderContextFlag
Flags which affect rendering operations.
Definition: qgis.h:934
@ 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.
@ Render3DMap
Render is for a 3D map.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ 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.
@ Render3DMap
Render is for a 3D map.
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ 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.
Q_GADGET QgsUnitTypes::DistanceUnit mapUnits
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
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:124
The QgsMapSettings class contains configuration for rendering of the map.
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.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
double dpiTarget() const
Returns the target DPI (dots per inch) to be taken into consideration when rendering.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
const QgsMapToPixel & mapToPixel() const
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes 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.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
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.
void setShowSelection(bool showSelection)
Sets whether vector selections should be shown in the rendered map.
void setDrawEditingInformation(bool b)
Sets whether edit markers should be drawn during the render operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
double convertFromMapUnits(double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit) const
Converts a size from map units to the specified units.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale(), Qgis::RenderSubcomponentProperty property=Qgis::RenderSubcomponentProperty::Generic) const
Converts a size from the specified units to painter units (pixels).
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.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
bool 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...
void setDpiTarget(double dpi)
Sets the targeted dpi for rendering.
~QgsRenderContext() override
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setFeedback(QgsFeedback *feedback)
Attach a feedback object that can be queried regularly during rendering to check if rendering should ...
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
void setFlag(Qgis::RenderContextFlag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply during the render.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the context's coordinate transform context, which stores various information regarding which dat...
void 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...
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...
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
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.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsRenderContext & operator=(const QgsRenderContext &rh)
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
void setSelectionColor(const QColor &color)
Sets the color to use when rendering selected features.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
void setFeatureFilterProvider(const QgsFeatureFilterProvider *ffp)
Set a filter feature provider used for additional filtering of rendered features.
Base class for objects with an associated (optional) temporal range.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
@ DistanceMeters
Meters.
Definition: qgsunittypes.h:69
@ DistanceDegrees
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:75
@ DistanceKilometers
Kilometers.
Definition: qgsunittypes.h:70
@ DistanceMiles
Terrestrial miles.
Definition: qgsunittypes.h:74
@ DistanceUnknownUnit
Unknown distance unit.
Definition: qgsunittypes.h:78
@ DistanceMillimeters
Millimeters.
Definition: qgsunittypes.h:77
@ DistanceYards
Imperial yards.
Definition: qgsunittypes.h:73
@ DistanceFeet
Imperial feet.
Definition: qgsunittypes.h:71
@ DistanceNauticalMiles
Nautical miles.
Definition: qgsunittypes.h:72
@ DistanceCentimeters
Centimeters.
Definition: qgsunittypes.h:76
static Q_INVOKABLE double fromUnitToUnitFactor(QgsUnitTypes::DistanceUnit fromUnit, QgsUnitTypes::DistanceUnit toUnit)
Returns the conversion factor between the specified distance units.
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:175
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:176
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:172
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:173
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
@ RenderInches
Inches.
Definition: qgsunittypes.h:174
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:169
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:170
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
@ NoSimplification
No simplification can be applied.
#define FALLTHROUGH
Definition: qgis.h:1757
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:1234
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define INCH_TO_MM
#define POINTS_TO_MM