QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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( DrawEditingInfo | UseAdvancedEffects | DrawSelection | 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  , mScaleFactor( rh.mScaleFactor )
54  , mRendererScale( rh.mRendererScale )
55  , mLabelingEngine( rh.mLabelingEngine )
56  , mSelectionColor( rh.mSelectionColor )
57  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
58  , mExpressionContext( rh.mExpressionContext )
59  , mGeometry( rh.mGeometry )
60  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
61  , mSegmentationTolerance( rh.mSegmentationTolerance )
62  , mSegmentationToleranceType( rh.mSegmentationToleranceType )
63  , mTransformContext( rh.mTransformContext )
64  , mPathResolver( rh.mPathResolver )
65  , mTextRenderFormat( rh.mTextRenderFormat )
66  , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
67  , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
68  , mCustomRenderingFlags( rh.mCustomRenderingFlags )
69  , mDisabledSymbolLayers()
70  , mClippingRegions( rh.mClippingRegions )
71  , mFeatureClipGeometry( rh.mFeatureClipGeometry )
72  , mTextureOrigin( rh.mTextureOrigin )
73  , mZRange( rh.mZRange )
74 #ifdef QGISDEBUG
75  , mHasTransformContext( rh.mHasTransformContext )
76 #endif
77 {
78 }
79 
81 {
82  mFlags = rh.mFlags;
83  mPainter = rh.mPainter;
84  mMaskPainter = rh.mMaskPainter;
85  mCoordTransform = rh.mCoordTransform;
86  mExtent = rh.mExtent;
87  mOriginalMapExtent = rh.mOriginalMapExtent;
88  mMapToPixel = rh.mMapToPixel;
89  mRenderingStopped = rh.mRenderingStopped;
90  mScaleFactor = rh.mScaleFactor;
91  mRendererScale = rh.mRendererScale;
92  mLabelingEngine = rh.mLabelingEngine;
93  mSelectionColor = rh.mSelectionColor;
94  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
95  mExpressionContext = rh.mExpressionContext;
96  mGeometry = rh.mGeometry;
97  mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
98  mSegmentationTolerance = rh.mSegmentationTolerance;
99  mSegmentationToleranceType = rh.mSegmentationToleranceType;
100  mDistanceArea = rh.mDistanceArea;
101  mTransformContext = rh.mTransformContext;
102  mPathResolver = rh.mPathResolver;
103  mTextRenderFormat = rh.mTextRenderFormat;
104  mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
105  mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
106  mCustomRenderingFlags = rh.mCustomRenderingFlags;
107  mClippingRegions = rh.mClippingRegions;
108  mFeatureClipGeometry = rh.mFeatureClipGeometry;
109  mTextureOrigin = rh.mTextureOrigin;
110  mZRange = rh.mZRange;
111  setIsTemporal( rh.isTemporal() );
112  if ( isTemporal() )
114 #ifdef QGISDEBUG
115  mHasTransformContext = rh.mHasTransformContext;
116 #endif
117 
118  return *this;
119 }
120 
122 {
123  QgsRenderContext context;
124  context.setPainter( painter );
125  if ( painter && painter->device() )
126  {
127  context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
128  }
129  else
130  {
131  context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
132  }
133 
134  if ( painter && painter->renderHints() & QPainter::Antialiasing )
135  context.setFlag( QgsRenderContext::Antialiasing, true );
136 
137 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
138  if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
140 #endif
141 
142  return context;
143 }
144 
145 void QgsRenderContext::setPainterFlagsUsingContext( QPainter *painter ) const
146 {
147  if ( !painter )
148  painter = mPainter;
149 
150  if ( !painter )
151  return;
152 
153  painter->setRenderHint( QPainter::Antialiasing, mFlags & QgsRenderContext::Antialiasing );
154 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
155  painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & QgsRenderContext::LosslessImageRendering );
156 #endif
157 }
158 
160 {
161 #ifdef QGISDEBUG
162  if ( !mHasTransformContext )
163  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
164 #endif
165  return mTransformContext;
166 }
167 
169 {
170  mTransformContext = context;
171 #ifdef QGISDEBUG
172  mHasTransformContext = true;
173 #endif
174 }
175 
176 void QgsRenderContext::setFlags( QgsRenderContext::Flags flags )
177 {
178  mFlags = flags;
179 }
180 
182 {
183  if ( on )
184  mFlags |= flag;
185  else
186  mFlags &= ~flag;
187 }
188 
189 QgsRenderContext::Flags QgsRenderContext::flags() const
190 {
191  return mFlags;
192 }
193 
195 {
196  return mFlags.testFlag( flag );
197 }
198 
200 {
201  QgsRenderContext ctx;
202  QgsRectangle extent = mapSettings.visibleExtent();
203  extent.grow( mapSettings.extentBuffer() );
204  ctx.setMapToPixel( mapSettings.mapToPixel() );
205  ctx.setExtent( extent );
206  ctx.setMapExtent( mapSettings.visibleExtent() );
212  ctx.setSelectionColor( mapSettings.selectionColor() );
222  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
223  ctx.setRendererScale( mapSettings.scale() );
224  ctx.setExpressionContext( mapSettings.expressionContext() );
225  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
227  ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
228  ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
229  ctx.setTransformContext( mapSettings.transformContext() );
230  ctx.setPathResolver( mapSettings.pathResolver() );
231  ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
232  ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
233  ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
234  ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
235  //this flag is only for stopping during the current rendering progress,
236  //so must be false at every new render operation
237  ctx.setRenderingStopped( false );
238  ctx.mCustomRenderingFlags = mapSettings.customRenderingFlags();
239  ctx.setIsTemporal( mapSettings.isTemporal() );
240  if ( ctx.isTemporal() )
241  ctx.setTemporalRange( mapSettings.temporalRange() );
242 
243  ctx.setZRange( mapSettings.zRange() );
244 
245  ctx.mClippingRegions = mapSettings.clippingRegions();
246 
247  return ctx;
248 }
249 
251 {
252  return mFlags.testFlag( ForceVectorOutput );
253 }
254 
256 {
257  return mFlags.testFlag( UseAdvancedEffects );
258 }
259 
261 {
262  setFlag( UseAdvancedEffects, enabled );
263 }
264 
266 {
267  return mFlags.testFlag( DrawEditingInfo );
268 }
269 
271 {
272  return mFlags.testFlag( DrawSelection );
273 }
274 
276 {
277  mCoordTransform = t;
278 }
279 
281 {
282  setFlag( DrawEditingInfo, b );
283 }
284 
286 {
287  setFlag( ForceVectorOutput, force );
288 }
289 
290 void QgsRenderContext::setShowSelection( const bool showSelection )
291 {
293 }
294 
296 {
297  return mFlags.testFlag( UseRenderingOptimization );
298 }
299 
301 {
302  setFlag( UseRenderingOptimization, enabled );
303 }
304 
306 {
307  if ( ffp )
308  {
309  mFeatureFilterProvider.reset( ffp->clone() );
310  }
311  else
312  {
313  mFeatureFilterProvider.reset( nullptr );
314  }
315 }
316 
318 {
319  return mFeatureFilterProvider.get();
320 }
321 
323 {
324  double conversionFactor = 1.0;
325  switch ( unit )
326  {
328  conversionFactor = mScaleFactor;
329  break;
330 
332  conversionFactor = mScaleFactor / POINTS_TO_MM;
333  break;
334 
336  conversionFactor = mScaleFactor * INCH_TO_MM;
337  break;
338 
340  {
341  size = convertMetersToMapUnits( size );
343  // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
345  }
347  {
348  double mup = scale.computeMapUnitsPerPixel( *this );
349  if ( mup > 0 )
350  {
351  conversionFactor = 1.0 / mup;
352  }
353  else
354  {
355  conversionFactor = 1.0;
356  }
357  break;
358  }
360  conversionFactor = 1.0;
361  break;
362 
365  //no sensible value
366  conversionFactor = 1.0;
367  break;
368  }
369 
370  double convertedSize = size * conversionFactor;
371 
372  if ( unit == QgsUnitTypes::RenderMapUnits )
373  {
374  //check max/min size
375  if ( scale.minSizeMMEnabled )
376  convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
377  if ( scale.maxSizeMMEnabled )
378  convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
379  }
380 
381  return convertedSize;
382 }
383 
384 double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale ) const
385 {
386  double mup = mMapToPixel.mapUnitsPerPixel();
387 
388  switch ( unit )
389  {
391  {
392  size = convertMetersToMapUnits( size );
393  // Fall through to RenderMapUnits with values of meters converted to MapUnits
395  }
397  {
398  // check scale
399  double minSizeMU = std::numeric_limits<double>::lowest();
400  if ( scale.minSizeMMEnabled )
401  {
402  minSizeMU = scale.minSizeMM * mScaleFactor * mup;
403  }
404  if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
405  {
406  minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
407  }
408  size = std::max( size, minSizeMU );
409 
410  double maxSizeMU = std::numeric_limits<double>::max();
411  if ( scale.maxSizeMMEnabled )
412  {
413  maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
414  }
415  if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
416  {
417  maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
418  }
419  size = std::min( size, maxSizeMU );
420 
421  return size;
422  }
424  {
425  return size * mScaleFactor * mup;
426  }
428  {
429  return size * mScaleFactor * mup / POINTS_TO_MM;
430  }
432  {
433  return size * mScaleFactor * mup * INCH_TO_MM;
434  }
436  {
437  return size * mup;
438  }
439 
442  //no sensible value
443  return 0.0;
444  }
445  return 0.0;
446 }
447 
448 double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const
449 {
450  double mup = mMapToPixel.mapUnitsPerPixel();
451 
452  switch ( outputUnit )
453  {
455  {
456  return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
457  }
459  {
460  return sizeInMapUnits;
461  }
463  {
464  return sizeInMapUnits / ( mScaleFactor * mup );
465  }
467  {
468  return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM );
469  }
471  {
472  return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM );
473  }
475  {
476  return sizeInMapUnits / mup;
477  }
478 
481  //no sensible value
482  return 0.0;
483  }
484  return 0.0;
485 }
486 
487 double QgsRenderContext::convertMetersToMapUnits( double meters ) const
488 {
489  switch ( mDistanceArea.sourceCrs().mapUnits() )
490  {
492  return meters;
494  {
495  if ( mExtent.isNull() )
496  {
497  // we don't have an extent to calculate exactly -- so just use a very rough approximation
499  }
500 
501  QgsPointXY pointCenter = mExtent.center();
502  // The Extent is in the sourceCrs(), when different from destinationCrs()
503  // - the point must be transformed, since DistanceArea uses the destinationCrs()
504  // Note: the default QgsCoordinateTransform() : authid() will return an empty String
505  if ( !mCoordTransform.isShortCircuited() )
506  {
507  pointCenter = mCoordTransform.transform( pointCenter );
508  }
509  return mDistanceArea.measureLineProjected( pointCenter, meters );
510  }
519  return ( meters * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mDistanceArea.sourceCrs().mapUnits() ) );
520  }
521  return meters;
522 }
523 
524 QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
525 {
526  return mRenderedFeatureHandlers;
527 }
528 
529 QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
530 {
531  return mClippingRegions;
532 }
533 
535 {
536  return mFeatureClipGeometry;
537 }
538 
540 {
541  mFeatureClipGeometry = geometry;
542 }
543 
545 {
546  return mTextureOrigin;
547 }
548 
549 void QgsRenderContext::setTextureOrigin( const QPointF &origin )
550 {
551  mTextureOrigin = origin;
552 }
553 
555 {
556  return mZRange;
557 }
558 
560 {
561  mZRange = range;
562 }
563 
564 
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.
QgsPointXY transform(const QgsPointXY &point, TransformDirection direction=ForwardTransform) const SIP_THROW(QgsCsException)
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.
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.
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.
QgsRenderContext::TextRenderFormat textRenderFormat() const
Returns the text render format, which dictates how text is rendered (e.g.
double segmentationTolerance() const
Gets the segmentation tolerance applied when rendering curved geometries.
QgsDoubleRange zRange() const
Returns the range of z-values which will be visible in the map.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Antialiasing
Enable anti-aliasing for map rendering.
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ Render3DMap
Render is for a 3D map.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering the map settings.
const QgsExpressionContext & expressionContext() const
Gets the expression context.
const QgsPathResolver & pathResolver() const
Returns the path resolver for conversion between relative and absolute paths during rendering operati...
double extentBuffer() const
Returns the buffer in map units to use around the visible extent for rendering symbols whose correspo...
const QgsMapToPixel & mapToPixel() const
QColor selectionColor() const
Returns the color that is used for drawing of selected vector features.
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const
Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
const QgsVectorSimplifyMethod & simplifyMethod() const
Returns the simplification settings to use when rendering vector layers.
QgsRectangle visibleExtent() const
Returns the actual extent derived from requested extent that takes takes output image size into accou...
QVariantMap customRenderingFlags() const
Returns any custom rendering flags.
QString ellipsoid() const
Returns ellipsoid's acronym.
double outputDpi() const
Returns the DPI (dots per inch) used for conversion between real world units (e.g.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply to the map.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
double mapUnitsPerPixel() const
Returns current map units per pixel.
Struct for storing maximum and minimum scales for measurements in map units.
double computeMapUnitsPerPixel(const QgsRenderContext &c) const
Computes a map units per pixel scaling factor, respecting the minimum and maximum scales set for the ...
bool minSizeMMEnabled
Whether the minimum size in mm should be respected.
double maxScale
The maximum scale, or 0.0 if unset.
double minScale
The minimum scale, or 0.0 if unset.
double maxSizeMM
The maximum size in millimeters, or 0.0 if unset.
bool maxSizeMMEnabled
Whether the maximum size in mm should be respected.
double minSizeMM
The minimum size in millimeters, or 0.0 if unset.
A class to represent a 2D point.
Definition: qgspointxy.h:44
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:447
void grow(double delta)
Grows the rectangle in place by the specified amount.
Definition: qgsrectangle.h:275
QgsPointXY center() const SIP_HOLDGIL
Returns the center point of the rectangle.
Definition: qgsrectangle.h:230
Contains information about the context of a rendering operation.
void setForceVectorOutput(bool force)
Sets whether rendering operations should use vector operations instead of any faster raster shortcuts...
void setMapExtent(const QgsRectangle &extent)
Sets the original extent of the map being rendered.
void setTextureOrigin(const QPointF &origin)
Sets the texture origin, which should be used as a brush transform when rendering using QBrush object...
void setRenderingStopped(bool stopped)
Sets whether the rendering operation has been stopped and any ongoing rendering should be canceled im...
void setCoordinateTransform(const QgsCoordinateTransform &t)
Sets the current coordinate transform for the context.
void setShowSelection(bool showSelection)
Sets whether vector selections should be shown in the rendered map.
void setDrawEditingInformation(bool b)
Sets whether edit markers should be drawn during the render operation.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
void setScaleFactor(double factor)
Sets the scaling factor for the render to convert painter units to physical sizes.
void setSegmentationToleranceType(QgsAbstractGeometry::SegmentationToleranceType type)
Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation...
void setTextRenderFormat(TextRenderFormat format)
Sets the text render format, which dictates how text is rendered (e.g.
const QgsAbstractGeometry * geometry() const
Returns pointer to the unsegmentized geometry.
double convertFromMapUnits(double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit) const
Converts a size from map units to the specified units.
void setUseAdvancedEffects(bool enabled)
Used to enable or disable advanced effects such as blend modes.
QPainter * painter()
Returns the destination QPainter for the render operation.
void setPainterFlagsUsingContext(QPainter *painter=nullptr) const
Sets relevant flags on a destination painter, using the flags and settings currently defined for the ...
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
void setVectorSimplifyMethod(const QgsVectorSimplifyMethod &simplifyMethod)
Sets the simplification setting to use when rendering vector layers.
QgsCoordinateTransformContext transformContext() const
Returns the context's coordinate transform context, which stores various information regarding which ...
QgsGeometry featureClipGeometry() const
Returns the geometry to use to clip features at render time.
bool forceVectorOutput() const
Returns true if rendering operations should use vector operations instead of any faster raster shortc...
~QgsRenderContext() override
void setPathResolver(const QgsPathResolver &resolver)
Sets the path resolver for conversion between relative and absolute paths during rendering operations...
void setFeatureClipGeometry(const QgsGeometry &geometry)
Sets a geometry to use to clip features at render time.
const QgsFeatureFilterProvider * featureFilterProvider() const
Gets the filter feature provider used for additional filtering of rendered features.
QList< QgsRenderedFeatureHandlerInterface * > renderedFeatureHandlers() const
Returns the list of rendered feature handlers to use while rendering map layers.
bool showSelection() const
Returns true if vector selections should be shown in the rendered map.
QList< QgsMapClippingRegion > clippingRegions() const
Returns the list of clipping regions to apply during the render.
void setTransformContext(const QgsCoordinateTransformContext &context)
Sets the context's coordinate transform context, which stores various information regarding which dat...
void setExtent(const QgsRectangle &extent)
When rendering a map layer, calling this method sets the "clipping" extent for the layer (in the laye...
void setMapToPixel(const QgsMapToPixel &mtp)
Sets the context's map to pixel transform, which transforms between map coordinates and device coordi...
Flag
Enumeration of flags that affect rendering operations.
@ DrawSymbolBounds
Draw bounds of symbols (for debugging/testing)
@ DrawSelection
Whether vector selections should be shown in the rendered map.
@ RenderPreviewJob
Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.
@ ForceVectorOutput
Vector graphics should not be cached and drawn as raster images.
@ RenderMapTile
Draw map such that there are no problems between adjacent tiles.
@ Antialiasing
Use antialiasing while drawing.
@ DrawEditingInfo
Enable drawing of vertex markers for layers in editing mode.
@ RenderBlocking
Render and load remote sources in the same thread to ensure rendering remote sources (svg and images)...
@ UseAdvancedEffects
Enable layer opacity and blending effects.
@ UseRenderingOptimization
Enable vector simplification and other rendering optimizations.
@ RenderPartialOutput
Whether to make extra effort to update map image with partially rendered layers (better for interacti...
@ LosslessImageRendering
Render images losslessly whenever possible, instead of the default lossy jpeg rendering used for some...
@ Render3DMap
Render is for a 3D map.
Flags flags() const
Returns combination of flags used for rendering.
QPointF textureOrigin() const
Returns the texture origin, which should be used as a brush transform when rendering using QBrush obj...
double convertToMapUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to map units.
void setPainter(QPainter *p)
Sets the destination QPainter for the render operation.
QgsDoubleRange zRange() const
Returns the range of z-values which should be rendered.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
bool drawEditingInformation() const
Returns true if edit markers should be drawn during the render operation.
static QgsRenderContext fromQPainter(QPainter *painter)
Creates a default render context given a pixel based QPainter destination.
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
double convertToPainterUnits(double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
Converts a size from the specified units to painter units (pixels).
void setUseRenderingOptimization(bool enabled)
Sets whether the rendering optimization (geometry simplification) should be executed.
void setRendererScale(double scale)
Sets the renderer map scale.
void setZRange(const QgsDoubleRange &range)
Sets the range of z-values which should be rendered.
double convertMetersToMapUnits(double meters) const
Convert meter distances to active MapUnit values for QgsUnitTypes::RenderMetersInMapUnits.
bool testFlag(Flag flag) const
Check whether a particular flag is enabled.
const QgsRectangle & extent() const
When rendering a map layer, calling this method returns the "clipping" extent for the layer (in the l...
QgsRenderContext & operator=(const QgsRenderContext &rh)
void setFlags(QgsRenderContext::Flags flags)
Set combination of flags that will be used for rendering.
bool useRenderingOptimization() const
Returns true if the rendering optimization (geometry simplification) can be executed.
void setSelectionColor(const QColor &color)
Sets the color to use when rendering selected features.
void setSegmentationTolerance(double tolerance)
Sets the segmentation tolerance applied when rendering curved geometries.
void setFeatureFilterProvider(const QgsFeatureFilterProvider *ffp)
Set a filter feature provider used for additional filtering of rendered features.
Base class for objects with an associated (optional) temporal range.
const QgsDateTimeRange & temporalRange() const
Returns the datetime range for the object.
bool isTemporal() const
Returns true if the object's temporal range is enabled, and the object will be filtered when renderin...
void setIsTemporal(bool enabled)
Sets whether the temporal range is enabled (i.e.
void setTemporalRange(const QgsDateTimeRange &range)
Sets the temporal range for the object.
@ 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:167
@ RenderUnknownUnit
Mixed or unknown units.
Definition: qgsunittypes.h:174
@ RenderMetersInMapUnits
Meters value as Map units.
Definition: qgsunittypes.h:175
@ RenderPercentage
Percentage of another measurement (e.g., canvas size, feature size)
Definition: qgsunittypes.h:171
@ RenderPoints
Points (e.g., for font sizes)
Definition: qgsunittypes.h:172
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
@ RenderInches
Inches.
Definition: qgsunittypes.h:173
@ RenderMillimeters
Millimeters.
Definition: qgsunittypes.h:168
@ RenderMapUnits
Map units.
Definition: qgsunittypes.h:169
void setSimplifyHints(SimplifyHints simplifyHints)
Sets the simplification hints of the vector layer managed.
@ NoSimplification
No simplification can be applied.
#define FALLTHROUGH
Definition: qgis.h:829
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:316
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define INCH_TO_MM
#define POINTS_TO_MM