QGIS API Documentation  3.0.2-Girona (307d082)
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsRenderContext Class Reference

Contains information about the context of a rendering operation. More...

#include <qgsrendercontext.h>

Public Types

enum  Flag {
  DrawEditingInfo = 0x01, ForceVectorOutput = 0x02, UseAdvancedEffects = 0x04, UseRenderingOptimization = 0x08,
  DrawSelection = 0x10, DrawSymbolBounds = 0x20, RenderMapTile = 0x40, Antialiasing = 0x80,
  RenderPartialOutput = 0x100, RenderPreviewJob = 0x200
}
 Enumeration of flags that affect rendering operations. More...
 

Public Member Functions

 QgsRenderContext ()
 
 QgsRenderContext (const QgsRenderContext &rh)
 
double convertFromMapUnits (double sizeInMapUnits, QgsUnitTypes::RenderUnit outputUnit) const
 Converts a size from map units to the specified units. More...
 
double convertMetersToMapUnits (double meters) const
 Convert meter distances to active MapUnit values for QgsUnitTypes::RenderMetersInMapUnits. More...
 
double convertToMapUnits (double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
 Converts a size from the specified units to map units. More...
 
double convertToPainterUnits (double size, QgsUnitTypes::RenderUnit unit, const QgsMapUnitScale &scale=QgsMapUnitScale()) const
 Converts a size from the specified units to painter units (pixels). More...
 
QgsCoordinateTransform coordinateTransform () const
 Returns the current coordinate transform for the context, or an invalid transform is no coordinate transformation is required. More...
 
const QgsDistanceAreadistanceArea () const
 A general purpose distance and area calculator, capable of performing ellipsoid based calculations. More...
 
bool drawEditingInformation () const
 
QgsExpressionContextexpressionContext ()
 Gets the expression context. More...
 
const QgsExpressionContextexpressionContext () const
 Gets the expression context (const version). More...
 
const QgsRectangleextent () const
 
const QgsFeatureFilterProviderfeatureFilterProvider () const
 Get the filter feature provider used for additional filtering of rendered features. More...
 
Flags flags () const
 Return combination of flags used for rendering. More...
 
bool forceVectorOutput () const
 
const QgsAbstractGeometrygeometry () const
 Returns pointer to the unsegmentized geometry. More...
 
QgsLabelingEnginelabelingEngine () const
 Get access to new labeling engine (may be nullptr) More...
 
const QgsMapToPixelmapToPixel () const
 
QgsRenderContextoperator= (const QgsRenderContext &rh)
 
QPainter * painter ()
 Returns the destination QPainter for the render operation. More...
 
const QgsPathResolverpathResolver () const
 Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g. More...
 
double rendererScale () const
 Returns the renderer map scale. More...
 
bool renderingStopped () const
 
double scaleFactor () const
 Returns the scaling factor for the render to convert painter units to physical sizes. More...
 
double segmentationTolerance () const
 Gets the segmentation tolerance applied when rendering curved geometries. More...
 
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType () const
 Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation) More...
 
QColor selectionColor () const
 
void setCoordinateTransform (const QgsCoordinateTransform &t)
 Sets coordinate transformation. More...
 
void setDistanceArea (const QgsDistanceArea &distanceArea)
 A general purpose distance and area calculator, capable of performing ellipsoid based calculations. More...
 
void setDrawEditingInformation (bool b)
 
void setExpressionContext (const QgsExpressionContext &context)
 Sets the expression context. More...
 
void setExtent (const QgsRectangle &extent)
 
void setFeatureFilterProvider (const QgsFeatureFilterProvider *ffp)
 Set a filter feature provider used for additional filtering of rendered features. More...
 
void setFlag (Flag flag, bool on=true)
 Enable or disable a particular flag (other flags are not affected) More...
 
void setFlags (QgsRenderContext::Flags flags)
 Set combination of flags that will be used for rendering. More...
 
void setForceVectorOutput (bool force)
 
void setGeometry (const QgsAbstractGeometry *geometry)
 Sets pointer to original (unsegmentized) geometry. More...
 
void setLabelingEngine (QgsLabelingEngine *engine2)
 Assign new labeling engine. More...
 
void setMapToPixel (const QgsMapToPixel &mtp)
 
void setPainter (QPainter *p)
 Sets the destination QPainter for the render operation. More...
 
void setPathResolver (const QgsPathResolver &resolver)
 Sets the path resolver for conversion between relative and absolute paths during rendering operations, e.g. More...
 
void setRendererScale (double scale)
 Sets the renderer map scale. More...
 
void setRenderingStopped (bool stopped)
 
void setScaleFactor (double factor)
 Sets the scaling factor for the render to convert painter units to physical sizes. More...
 
void setSegmentationTolerance (double tolerance)
 Sets the segmentation tolerance applied when rendering curved geometries. More...
 
void setSegmentationToleranceType (QgsAbstractGeometry::SegmentationToleranceType type)
 Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation) More...
 
void setSelectionColor (const QColor &color)
 
void setShowSelection (const bool showSelection)
 Sets whether vector selections should be shown in the rendered map. More...
 
void setTransformContext (const QgsCoordinateTransformContext &context)
 Sets the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system. More...
 
void setUseAdvancedEffects (bool enabled)
 Used to enable or disable advanced effects such as blend modes. More...
 
void setUseRenderingOptimization (bool enabled)
 
void setVectorSimplifyMethod (const QgsVectorSimplifyMethod &simplifyMethod)
 
bool showSelection () const
 Returns true if vector selections should be shown in the rendered map. More...
 
bool testFlag (Flag flag) const
 Check whether a particular flag is enabled. More...
 
QgsCoordinateTransformContext transformContext () const
 Returns the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system. More...
 
bool useAdvancedEffects () const
 Returns true if advanced effects such as blend modes such be used. More...
 
bool useRenderingOptimization () const
 Returns true if the rendering optimization (geometry simplification) can be executed. More...
 
const QgsVectorSimplifyMethodvectorSimplifyMethod () const
 Added in QGIS v2.4. More...
 

Static Public Member Functions

static QgsRenderContext fromMapSettings (const QgsMapSettings &mapSettings)
 create initialized QgsRenderContext instance from given QgsMapSettings More...
 
static QgsRenderContext fromQPainter (QPainter *painter)
 Creates a default render context given a pixel based QPainter destination. More...
 

Detailed Description

Contains information about the context of a rendering operation.

The context of a rendering operation defines properties such as the conversion ratio between screen and map units, the extents to be rendered etc.

Definition at line 51 of file qgsrendercontext.h.

Member Enumeration Documentation

◆ Flag

Enumeration of flags that affect rendering operations.

Since
QGIS 2.14
Enumerator
DrawEditingInfo 

Enable drawing of vertex markers for layers in editing mode.

ForceVectorOutput 

Vector graphics should not be cached and drawn as raster images.

UseAdvancedEffects 

Enable layer opacity and blending effects.

UseRenderingOptimization 

Enable vector simplification and other rendering optimizations.

DrawSelection 

Whether vector selections should be shown in the rendered map.

DrawSymbolBounds 

Draw bounds of symbols (for debugging/testing)

RenderMapTile 

Draw map such that there are no problems between adjacent tiles.

Antialiasing 

Use antialiasing while drawing.

RenderPartialOutput 

Whether to make extra effort to update map image with partially rendered layers (better for interactive map canvas). Added in QGIS 3.0.

RenderPreviewJob 

Render is a 'canvas preview' render, and shortcuts should be taken to ensure fast rendering.

Definition at line 63 of file qgsrendercontext.h.

Constructor & Destructor Documentation

◆ QgsRenderContext() [1/2]

QgsRenderContext::QgsRenderContext ( )

Definition at line 31 of file qgsrendercontext.cpp.

◆ QgsRenderContext() [2/2]

QgsRenderContext::QgsRenderContext ( const QgsRenderContext rh)

Definition at line 40 of file qgsrendercontext.cpp.

Member Function Documentation

◆ convertFromMapUnits()

double QgsRenderContext::convertFromMapUnits ( double  sizeInMapUnits,
QgsUnitTypes::RenderUnit  outputUnit 
) const

Converts a size from map units to the specified units.

Since
QGIS 3.0
See also
convertToMapUnits()

Definition at line 380 of file qgsrendercontext.cpp.

◆ convertMetersToMapUnits()

double QgsRenderContext::convertMetersToMapUnits ( double  meters) const

Convert meter distances to active MapUnit values for QgsUnitTypes::RenderMetersInMapUnits.

Note
When the sourceCrs() is geographic, the center of the Extent will be used
Since
QGIS 3.0

Definition at line 419 of file qgsrendercontext.cpp.

◆ convertToMapUnits()

double QgsRenderContext::convertToMapUnits ( double  size,
QgsUnitTypes::RenderUnit  unit,
const QgsMapUnitScale scale = QgsMapUnitScale() 
) const

Converts a size from the specified units to map units.

The conversion respects the limits specified by the optional scale parameter.

Since
QGIS 3.0
See also
convertToPainterUnits()

Definition at line 316 of file qgsrendercontext.cpp.

◆ convertToPainterUnits()

double QgsRenderContext::convertToPainterUnits ( double  size,
QgsUnitTypes::RenderUnit  unit,
const QgsMapUnitScale scale = QgsMapUnitScale() 
) const

Converts a size from the specified units to painter units (pixels).

The conversion respects the limits specified by the optional scale parameter.

Since
QGIS 3.0
See also
convertToMapUnits()

Definition at line 254 of file qgsrendercontext.cpp.

◆ coordinateTransform()

QgsCoordinateTransform QgsRenderContext::coordinateTransform ( ) const
inline

Returns the current coordinate transform for the context, or an invalid transform is no coordinate transformation is required.

Definition at line 128 of file qgsrendercontext.h.

◆ distanceArea()

const QgsDistanceArea& QgsRenderContext::distanceArea ( ) const
inline

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

Since
QGIS 3.0

Definition at line 134 of file qgsrendercontext.h.

◆ drawEditingInformation()

bool QgsRenderContext::drawEditingInformation ( ) const

Definition at line 197 of file qgsrendercontext.cpp.

◆ expressionContext() [1/2]

QgsExpressionContext& QgsRenderContext::expressionContext ( )
inline

Gets the expression context.

This context should be used for all expression evaluation associated with this render context.

See also
setExpressionContext()
Since
QGIS 2.12

Definition at line 310 of file qgsrendercontext.h.

◆ expressionContext() [2/2]

const QgsExpressionContext& QgsRenderContext::expressionContext ( ) const
inline

Gets the expression context (const version).

This context should be used for all expression evaluation associated with this render context.

See also
setExpressionContext()
Since
QGIS 2.12
Note
not available in Python bindings

Definition at line 319 of file qgsrendercontext.h.

◆ extent()

const QgsRectangle& QgsRenderContext::extent ( ) const
inline

Definition at line 174 of file qgsrendercontext.h.

◆ featureFilterProvider()

const QgsFeatureFilterProvider * QgsRenderContext::featureFilterProvider ( ) const

Get the filter feature provider used for additional filtering of rendered features.

Returns
the filter feature provider
Since
QGIS 2.14
See also
setFeatureFilterProvider()

Definition at line 249 of file qgsrendercontext.cpp.

◆ flags()

QgsRenderContext::Flags QgsRenderContext::flags ( ) const

Return combination of flags used for rendering.

Since
QGIS 2.14

Definition at line 139 of file qgsrendercontext.cpp.

◆ forceVectorOutput()

bool QgsRenderContext::forceVectorOutput ( ) const

Definition at line 182 of file qgsrendercontext.cpp.

◆ fromMapSettings()

QgsRenderContext QgsRenderContext::fromMapSettings ( const QgsMapSettings mapSettings)
static

create initialized QgsRenderContext instance from given QgsMapSettings

Since
QGIS 2.4

Definition at line 149 of file qgsrendercontext.cpp.

◆ fromQPainter()

QgsRenderContext QgsRenderContext::fromQPainter ( QPainter *  painter)
static

Creates a default render context given a pixel based QPainter destination.

If no painter is specified or the painter has no device, then a default DPI of 88 will be assumed.

Since
QGIS 3.0

Definition at line 94 of file qgsrendercontext.cpp.

◆ geometry()

const QgsAbstractGeometry* QgsRenderContext::geometry ( ) const
inline

Returns pointer to the unsegmentized geometry.

Definition at line 322 of file qgsrendercontext.h.

◆ labelingEngine()

QgsLabelingEngine* QgsRenderContext::labelingEngine ( ) const
inline

Get access to new labeling engine (may be nullptr)

Note
not available in Python bindings

Definition at line 213 of file qgsrendercontext.h.

◆ mapToPixel()

const QgsMapToPixel& QgsRenderContext::mapToPixel ( ) const
inline

Definition at line 176 of file qgsrendercontext.h.

◆ operator=()

QgsRenderContext & QgsRenderContext::operator= ( const QgsRenderContext rh)

Definition at line 66 of file qgsrendercontext.cpp.

◆ painter()

QPainter* QgsRenderContext::painter ( )
inline

Returns the destination QPainter for the render operation.

See also
setPainter()

Definition at line 122 of file qgsrendercontext.h.

◆ pathResolver()

const QgsPathResolver& QgsRenderContext::pathResolver ( ) const
inline

Returns the path resolver for conversion between relative and absolute paths during rendering operations, e.g.

for resolving relative symbol paths.

Since
QGIS 3.0
See also
setPathResolver()

Definition at line 163 of file qgsrendercontext.h.

◆ rendererScale()

double QgsRenderContext::rendererScale ( ) const
inline

Returns the renderer map scale.

This will match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.

See also
setRendererScale()

Definition at line 207 of file qgsrendercontext.h.

◆ renderingStopped()

bool QgsRenderContext::renderingStopped ( ) const
inline

Definition at line 186 of file qgsrendercontext.h.

◆ scaleFactor()

double QgsRenderContext::scaleFactor ( ) const
inline

Returns the scaling factor for the render to convert painter units to physical sizes.

This is usually equal to the number of pixels per millimeter.

See also
setScaleFactor()

Definition at line 184 of file qgsrendercontext.h.

◆ segmentationTolerance()

double QgsRenderContext::segmentationTolerance ( ) const
inline

Gets the segmentation tolerance applied when rendering curved geometries.

Definition at line 347 of file qgsrendercontext.h.

◆ segmentationToleranceType()

QgsAbstractGeometry::SegmentationToleranceType QgsRenderContext::segmentationToleranceType ( ) const
inline

Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

Definition at line 354 of file qgsrendercontext.h.

◆ selectionColor()

QColor QgsRenderContext::selectionColor ( ) const
inline

Definition at line 215 of file qgsrendercontext.h.

◆ setCoordinateTransform()

void QgsRenderContext::setCoordinateTransform ( const QgsCoordinateTransform t)

Sets coordinate transformation.

Definition at line 207 of file qgsrendercontext.cpp.

◆ setDistanceArea()

void QgsRenderContext::setDistanceArea ( const QgsDistanceArea distanceArea)
inline

A general purpose distance and area calculator, capable of performing ellipsoid based calculations.

Will be used to convert meter distances to active MapUnit values for QgsUnitTypes::RenderMetersInMapUnits

Since
QGIS 3.0

Definition at line 242 of file qgsrendercontext.h.

◆ setDrawEditingInformation()

void QgsRenderContext::setDrawEditingInformation ( bool  b)

Definition at line 212 of file qgsrendercontext.cpp.

◆ setExpressionContext()

void QgsRenderContext::setExpressionContext ( const QgsExpressionContext context)
inline

Sets the expression context.

This context is used for all expression evaluation associated with this render context.

See also
expressionContext()
Since
QGIS 2.12

Definition at line 302 of file qgsrendercontext.h.

◆ setExtent()

void QgsRenderContext::setExtent ( const QgsRectangle extent)
inline

Definition at line 231 of file qgsrendercontext.h.

◆ setFeatureFilterProvider()

void QgsRenderContext::setFeatureFilterProvider ( const QgsFeatureFilterProvider ffp)

Set a filter feature provider used for additional filtering of rendered features.

Parameters
ffpthe filter feature provider
Since
QGIS 2.14
See also
featureFilterProvider()

Definition at line 237 of file qgsrendercontext.cpp.

◆ setFlag()

void QgsRenderContext::setFlag ( QgsRenderContext::Flag  flag,
bool  on = true 
)

Enable or disable a particular flag (other flags are not affected)

Since
QGIS 2.14

Definition at line 131 of file qgsrendercontext.cpp.

◆ setFlags()

void QgsRenderContext::setFlags ( QgsRenderContext::Flags  flags)

Set combination of flags that will be used for rendering.

Since
QGIS 2.14

Definition at line 126 of file qgsrendercontext.cpp.

◆ setForceVectorOutput()

void QgsRenderContext::setForceVectorOutput ( bool  force)

Definition at line 217 of file qgsrendercontext.cpp.

◆ setGeometry()

void QgsRenderContext::setGeometry ( const QgsAbstractGeometry geometry)
inline

Sets pointer to original (unsegmentized) geometry.

Definition at line 324 of file qgsrendercontext.h.

◆ setLabelingEngine()

void QgsRenderContext::setLabelingEngine ( QgsLabelingEngine engine2)
inline

Assign new labeling engine.

Note
not available in Python bindings

Definition at line 273 of file qgsrendercontext.h.

◆ setMapToPixel()

void QgsRenderContext::setMapToPixel ( const QgsMapToPixel mtp)
inline

Definition at line 230 of file qgsrendercontext.h.

◆ setPainter()

void QgsRenderContext::setPainter ( QPainter *  p)
inline

Sets the destination QPainter for the render operation.

Ownership of the painter is not transferred and the QPainter destination must stay alive for the duration of any rendering operations.

See also
painter()

Definition at line 265 of file qgsrendercontext.h.

◆ setPathResolver()

void QgsRenderContext::setPathResolver ( const QgsPathResolver resolver)
inline

Sets the path resolver for conversion between relative and absolute paths during rendering operations, e.g.

for resolving relative symbol paths.

Since
QGIS 3.0
See also
pathResolver()

Definition at line 172 of file qgsrendercontext.h.

◆ setRendererScale()

void QgsRenderContext::setRendererScale ( double  scale)
inline

Sets the renderer map scale.

This should match the desired scale denominator for the rendered map, eg 1000.0 for a 1:1000 map render.

See also
rendererScale()

Definition at line 257 of file qgsrendercontext.h.

◆ setRenderingStopped()

void QgsRenderContext::setRenderingStopped ( bool  stopped)
inline

Definition at line 235 of file qgsrendercontext.h.

◆ setScaleFactor()

void QgsRenderContext::setScaleFactor ( double  factor)
inline

Sets the scaling factor for the render to convert painter units to physical sizes.

This should usually be equal to the number of pixels per millimeter.

See also
scaleFactor()

Definition at line 250 of file qgsrendercontext.h.

◆ setSegmentationTolerance()

void QgsRenderContext::setSegmentationTolerance ( double  tolerance)
inline

Sets the segmentation tolerance applied when rendering curved geometries.

Parameters
tolerancethe segmentation tolerance

Definition at line 345 of file qgsrendercontext.h.

◆ setSegmentationToleranceType()

void QgsRenderContext::setSegmentationToleranceType ( QgsAbstractGeometry::SegmentationToleranceType  type)
inline

Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)

Parameters
typethe segmentation tolerance typename

Definition at line 352 of file qgsrendercontext.h.

◆ setSelectionColor()

void QgsRenderContext::setSelectionColor ( const QColor &  color)
inline

Definition at line 274 of file qgsrendercontext.h.

◆ setShowSelection()

void QgsRenderContext::setShowSelection ( const bool  showSelection)

Sets whether vector selections should be shown in the rendered map.

Parameters
showSelectionset to true if selections should be shown
See also
showSelection
setSelectionColor
Since
QGIS v2.4

Definition at line 222 of file qgsrendercontext.cpp.

◆ setTransformContext()

void QgsRenderContext::setTransformContext ( const QgsCoordinateTransformContext context)

Sets the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

Since
QGIS 3.0
See also
transformContext()

Definition at line 118 of file qgsrendercontext.cpp.

◆ setUseAdvancedEffects()

void QgsRenderContext::setUseAdvancedEffects ( bool  enabled)

Used to enable or disable advanced effects such as blend modes.

Definition at line 192 of file qgsrendercontext.cpp.

◆ setUseRenderingOptimization()

void QgsRenderContext::setUseRenderingOptimization ( bool  enabled)

Definition at line 232 of file qgsrendercontext.cpp.

◆ setVectorSimplifyMethod()

void QgsRenderContext::setVectorSimplifyMethod ( const QgsVectorSimplifyMethod simplifyMethod)
inline

Definition at line 294 of file qgsrendercontext.h.

◆ showSelection()

bool QgsRenderContext::showSelection ( ) const

Returns true if vector selections should be shown in the rendered map.

Returns
true if selections should be shown
See also
setShowSelection
selectionColor
Since
QGIS v2.4

Definition at line 202 of file qgsrendercontext.cpp.

◆ testFlag()

bool QgsRenderContext::testFlag ( QgsRenderContext::Flag  flag) const

Check whether a particular flag is enabled.

Since
QGIS 2.14

Definition at line 144 of file qgsrendercontext.cpp.

◆ transformContext()

QgsCoordinateTransformContext QgsRenderContext::transformContext ( ) const

Returns the context's coordinate transform context, which stores various information regarding which datum transforms should be used when transforming points from a source to destination coordinate reference system.

Since
QGIS 3.0
See also
setTransformContext()

Definition at line 109 of file qgsrendercontext.cpp.

◆ useAdvancedEffects()

bool QgsRenderContext::useAdvancedEffects ( ) const

Returns true if advanced effects such as blend modes such be used.

Definition at line 187 of file qgsrendercontext.cpp.

◆ useRenderingOptimization()

bool QgsRenderContext::useRenderingOptimization ( ) const

Returns true if the rendering optimization (geometry simplification) can be executed.

Definition at line 227 of file qgsrendercontext.cpp.

◆ vectorSimplifyMethod()

const QgsVectorSimplifyMethod& QgsRenderContext::vectorSimplifyMethod ( ) const
inline

Added in QGIS v2.4.

Definition at line 293 of file qgsrendercontext.h.


The documentation for this class was generated from the following files: