QGIS API Documentation  3.20.0-Odense (decaadbb31)
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  , mDpiTarget( rh.mDpiTarget )
55  , mRendererScale( rh.mRendererScale )
56  , mLabelingEngine( rh.mLabelingEngine )
57  , mSelectionColor( rh.mSelectionColor )
58  , mVectorSimplifyMethod( rh.mVectorSimplifyMethod )
59  , mExpressionContext( rh.mExpressionContext )
60  , mGeometry( rh.mGeometry )
61  , mFeatureFilterProvider( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr )
62  , mSegmentationTolerance( rh.mSegmentationTolerance )
63  , mSegmentationToleranceType( rh.mSegmentationToleranceType )
64  , mTransformContext( rh.mTransformContext )
65  , mPathResolver( rh.mPathResolver )
66  , mTextRenderFormat( rh.mTextRenderFormat )
67  , mRenderedFeatureHandlers( rh.mRenderedFeatureHandlers )
68  , mHasRenderedFeatureHandlers( rh.mHasRenderedFeatureHandlers )
69  , mCustomRenderingFlags( rh.mCustomRenderingFlags )
70  , mDisabledSymbolLayers()
71  , mClippingRegions( rh.mClippingRegions )
72  , mFeatureClipGeometry( rh.mFeatureClipGeometry )
73  , mTextureOrigin( rh.mTextureOrigin )
74  , mZRange( rh.mZRange )
75 #ifdef QGISDEBUG
76  , mHasTransformContext( rh.mHasTransformContext )
77 #endif
78 {
79 }
80 
82 {
83  mFlags = rh.mFlags;
84  mPainter = rh.mPainter;
85  mMaskPainter = rh.mMaskPainter;
86  mCoordTransform = rh.mCoordTransform;
87  mExtent = rh.mExtent;
88  mOriginalMapExtent = rh.mOriginalMapExtent;
89  mMapToPixel = rh.mMapToPixel;
90  mRenderingStopped = rh.mRenderingStopped;
91  mScaleFactor = rh.mScaleFactor;
92  mDpiTarget = rh.mDpiTarget;
93  mRendererScale = rh.mRendererScale;
94  mLabelingEngine = rh.mLabelingEngine;
95  mSelectionColor = rh.mSelectionColor;
96  mVectorSimplifyMethod = rh.mVectorSimplifyMethod;
97  mExpressionContext = rh.mExpressionContext;
98  mGeometry = rh.mGeometry;
99  mFeatureFilterProvider.reset( rh.mFeatureFilterProvider ? rh.mFeatureFilterProvider->clone() : nullptr );
100  mSegmentationTolerance = rh.mSegmentationTolerance;
101  mSegmentationToleranceType = rh.mSegmentationToleranceType;
102  mDistanceArea = rh.mDistanceArea;
103  mTransformContext = rh.mTransformContext;
104  mPathResolver = rh.mPathResolver;
105  mTextRenderFormat = rh.mTextRenderFormat;
106  mRenderedFeatureHandlers = rh.mRenderedFeatureHandlers;
107  mHasRenderedFeatureHandlers = rh.mHasRenderedFeatureHandlers;
108  mCustomRenderingFlags = rh.mCustomRenderingFlags;
109  mClippingRegions = rh.mClippingRegions;
110  mFeatureClipGeometry = rh.mFeatureClipGeometry;
111  mTextureOrigin = rh.mTextureOrigin;
112  mZRange = rh.mZRange;
113  setIsTemporal( rh.isTemporal() );
114  if ( isTemporal() )
116 #ifdef QGISDEBUG
117  mHasTransformContext = rh.mHasTransformContext;
118 #endif
119 
120  return *this;
121 }
122 
124 {
125  QgsRenderContext context;
126  context.setPainter( painter );
127  if ( painter && painter->device() )
128  {
129  context.setScaleFactor( painter->device()->logicalDpiX() / 25.4 );
130  }
131  else
132  {
133  context.setScaleFactor( 3.465 ); //assume 88 dpi as standard value
134  }
135 
136  if ( painter && painter->renderHints() & QPainter::Antialiasing )
137  context.setFlag( QgsRenderContext::Antialiasing, true );
138 
139 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
140  if ( painter && painter->renderHints() & QPainter::LosslessImageRendering )
142 #endif
143 
144  return context;
145 }
146 
147 void QgsRenderContext::setPainterFlagsUsingContext( QPainter *painter ) const
148 {
149  if ( !painter )
150  painter = mPainter;
151 
152  if ( !painter )
153  return;
154 
155  painter->setRenderHint( QPainter::Antialiasing, mFlags & QgsRenderContext::Antialiasing );
156 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
157  painter->setRenderHint( QPainter::LosslessImageRendering, mFlags & QgsRenderContext::LosslessImageRendering );
158 #endif
159 }
160 
162 {
163 #ifdef QGISDEBUG
164  if ( !mHasTransformContext )
165  QgsDebugMsgLevel( QStringLiteral( "No QgsCoordinateTransformContext context set for transform" ), 4 );
166 #endif
167  return mTransformContext;
168 }
169 
171 {
172  mTransformContext = context;
173 #ifdef QGISDEBUG
174  mHasTransformContext = true;
175 #endif
176 }
177 
178 void QgsRenderContext::setFlags( QgsRenderContext::Flags flags )
179 {
180  mFlags = flags;
181 }
182 
184 {
185  if ( on )
186  mFlags |= flag;
187  else
188  mFlags &= ~flag;
189 }
190 
191 QgsRenderContext::Flags QgsRenderContext::flags() const
192 {
193  return mFlags;
194 }
195 
197 {
198  return mFlags.testFlag( flag );
199 }
200 
202 {
203  QgsRenderContext ctx;
204  QgsRectangle extent = mapSettings.visibleExtent();
205  extent.grow( mapSettings.extentBuffer() );
206  ctx.setMapToPixel( mapSettings.mapToPixel() );
207  ctx.setExtent( extent );
208  ctx.setMapExtent( mapSettings.visibleExtent() );
214  ctx.setSelectionColor( mapSettings.selectionColor() );
224  ctx.setScaleFactor( mapSettings.outputDpi() / 25.4 ); // = pixels per mm
225  ctx.setDpiTarget( mapSettings.dpiTarget() >= 0.0 ? mapSettings.dpiTarget() : -1.0 );
226  ctx.setRendererScale( mapSettings.scale() );
227  ctx.setExpressionContext( mapSettings.expressionContext() );
228  ctx.setSegmentationTolerance( mapSettings.segmentationTolerance() );
230  ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
231  ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
232  ctx.setTransformContext( mapSettings.transformContext() );
233  ctx.setPathResolver( mapSettings.pathResolver() );
234  ctx.setTextRenderFormat( mapSettings.textRenderFormat() );
235  ctx.setVectorSimplifyMethod( mapSettings.simplifyMethod() );
236  ctx.mRenderedFeatureHandlers = mapSettings.renderedFeatureHandlers();
237  ctx.mHasRenderedFeatureHandlers = !mapSettings.renderedFeatureHandlers().isEmpty();
238  //this flag is only for stopping during the current rendering progress,
239  //so must be false at every new render operation
240  ctx.setRenderingStopped( false );
241  ctx.mCustomRenderingFlags = mapSettings.customRenderingFlags();
242  ctx.setIsTemporal( mapSettings.isTemporal() );
243  if ( ctx.isTemporal() )
244  ctx.setTemporalRange( mapSettings.temporalRange() );
245 
246  ctx.setZRange( mapSettings.zRange() );
247 
248  ctx.mClippingRegions = mapSettings.clippingRegions();
249 
250  return ctx;
251 }
252 
254 {
255  return mFlags.testFlag( ForceVectorOutput );
256 }
257 
259 {
260  return mFlags.testFlag( UseAdvancedEffects );
261 }
262 
264 {
265  setFlag( UseAdvancedEffects, enabled );
266 }
267 
269 {
270  return mFlags.testFlag( DrawEditingInfo );
271 }
272 
274 {
275  return mFlags.testFlag( DrawSelection );
276 }
277 
279 {
280  mCoordTransform = t;
281 }
282 
284 {
285  setFlag( DrawEditingInfo, b );
286 }
287 
289 {
290  setFlag( ForceVectorOutput, force );
291 }
292 
293 void QgsRenderContext::setShowSelection( const bool showSelection )
294 {
296 }
297 
299 {
300  return mFlags.testFlag( UseRenderingOptimization );
301 }
302 
304 {
305  setFlag( UseRenderingOptimization, enabled );
306 }
307 
309 {
310  if ( ffp )
311  {
312  mFeatureFilterProvider.reset( ffp->clone() );
313  }
314  else
315  {
316  mFeatureFilterProvider.reset( nullptr );
317  }
318 }
319 
321 {
322  return mFeatureFilterProvider.get();
323 }
324 
326 {
327  double conversionFactor = 1.0;
328  switch ( unit )
329  {
331  conversionFactor = mScaleFactor;
332  break;
333 
335  conversionFactor = mScaleFactor / POINTS_TO_MM;
336  break;
337 
339  conversionFactor = mScaleFactor * INCH_TO_MM;
340  break;
341 
343  {
344  size = convertMetersToMapUnits( size );
346  // Fall through to RenderMapUnits with size in meters converted to size in MapUnits
348  }
350  {
351  double mup = scale.computeMapUnitsPerPixel( *this );
352  if ( mup > 0 )
353  {
354  conversionFactor = 1.0 / mup;
355  }
356  else
357  {
358  conversionFactor = 1.0;
359  }
360  break;
361  }
363  conversionFactor = 1.0;
364  break;
365 
368  //no sensible value
369  conversionFactor = 1.0;
370  break;
371  }
372 
373  double convertedSize = size * conversionFactor;
374 
375  if ( unit == QgsUnitTypes::RenderMapUnits )
376  {
377  //check max/min size
378  if ( scale.minSizeMMEnabled )
379  convertedSize = std::max( convertedSize, scale.minSizeMM * mScaleFactor );
380  if ( scale.maxSizeMMEnabled )
381  convertedSize = std::min( convertedSize, scale.maxSizeMM * mScaleFactor );
382  }
383 
384  return convertedSize;
385 }
386 
387 double QgsRenderContext::convertToMapUnits( double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale ) const
388 {
389  double mup = mMapToPixel.mapUnitsPerPixel();
390 
391  switch ( unit )
392  {
394  {
395  size = convertMetersToMapUnits( size );
396  // Fall through to RenderMapUnits with values of meters converted to MapUnits
398  }
400  {
401  // check scale
402  double minSizeMU = std::numeric_limits<double>::lowest();
403  if ( scale.minSizeMMEnabled )
404  {
405  minSizeMU = scale.minSizeMM * mScaleFactor * mup;
406  }
407  if ( !qgsDoubleNear( scale.minScale, 0.0 ) )
408  {
409  minSizeMU = std::max( minSizeMU, size * ( mRendererScale / scale.minScale ) );
410  }
411  size = std::max( size, minSizeMU );
412 
413  double maxSizeMU = std::numeric_limits<double>::max();
414  if ( scale.maxSizeMMEnabled )
415  {
416  maxSizeMU = scale.maxSizeMM * mScaleFactor * mup;
417  }
418  if ( !qgsDoubleNear( scale.maxScale, 0.0 ) )
419  {
420  maxSizeMU = std::min( maxSizeMU, size * ( mRendererScale / scale.maxScale ) );
421  }
422  size = std::min( size, maxSizeMU );
423 
424  return size;
425  }
427  {
428  return size * mScaleFactor * mup;
429  }
431  {
432  return size * mScaleFactor * mup / POINTS_TO_MM;
433  }
435  {
436  return size * mScaleFactor * mup * INCH_TO_MM;
437  }
439  {
440  return size * mup;
441  }
442 
445  //no sensible value
446  return 0.0;
447  }
448  return 0.0;
449 }
450 
451 double QgsRenderContext::convertFromMapUnits( double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit ) const
452 {
453  double mup = mMapToPixel.mapUnitsPerPixel();
454 
455  switch ( outputUnit )
456  {
458  {
459  return sizeInMapUnits / convertMetersToMapUnits( 1.0 );
460  }
462  {
463  return sizeInMapUnits;
464  }
466  {
467  return sizeInMapUnits / ( mScaleFactor * mup );
468  }
470  {
471  return sizeInMapUnits / ( mScaleFactor * mup / POINTS_TO_MM );
472  }
474  {
475  return sizeInMapUnits / ( mScaleFactor * mup * INCH_TO_MM );
476  }
478  {
479  return sizeInMapUnits / mup;
480  }
481 
484  //no sensible value
485  return 0.0;
486  }
487  return 0.0;
488 }
489 
490 double QgsRenderContext::convertMetersToMapUnits( double meters ) const
491 {
492  switch ( mDistanceArea.sourceCrs().mapUnits() )
493  {
495  return meters;
497  {
498  if ( mExtent.isNull() )
499  {
500  // we don't have an extent to calculate exactly -- so just use a very rough approximation
502  }
503 
504  QgsPointXY pointCenter = mExtent.center();
505  // The Extent is in the sourceCrs(), when different from destinationCrs()
506  // - the point must be transformed, since DistanceArea uses the destinationCrs()
507  // Note: the default QgsCoordinateTransform() : authid() will return an empty String
508  if ( !mCoordTransform.isShortCircuited() )
509  {
510  pointCenter = mCoordTransform.transform( pointCenter );
511  }
512  return mDistanceArea.measureLineProjected( pointCenter, meters );
513  }
522  return ( meters * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceMeters, mDistanceArea.sourceCrs().mapUnits() ) );
523  }
524  return meters;
525 }
526 
527 QList<QgsRenderedFeatureHandlerInterface *> QgsRenderContext::renderedFeatureHandlers() const
528 {
529  return mRenderedFeatureHandlers;
530 }
531 
532 QList<QgsMapClippingRegion> QgsRenderContext::clippingRegions() const
533 {
534  return mClippingRegions;
535 }
536 
538 {
539  return mFeatureClipGeometry;
540 }
541 
543 {
544  mFeatureClipGeometry = geometry;
545 }
546 
548 {
549  return mTextureOrigin;
550 }
551 
552 void QgsRenderContext::setTextureOrigin( const QPointF &origin )
553 {
554  mTextureOrigin = origin;
555 }
556 
558 {
559  return mZRange;
560 }
561 
563 {
564  mZRange = range;
565 }
566 
567 
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.
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 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: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...
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...
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 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: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:1111
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:598
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define INCH_TO_MM
#define POINTS_TO_MM