QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
QgsMapRenderer Class Reference

A non GUI class for rendering a map layer set onto a QPainter. More...

#include <qgsmaprenderer.h>

Public Types

enum  BlendMode {
  BlendNormal, BlendLighten, BlendScreen, BlendDodge,
  BlendAddition, BlendDarken, BlendMultiply, BlendBurn,
  BlendOverlay, BlendSoftLight, BlendHardLight, BlendDifference,
  BlendSubtract, BlendSource, BlendDestinationOver, BlendClear,
  BlendDestination, BlendSourceIn, BlendDestinationIn, BlendSourceOut,
  BlendDestinationOut, BlendSourceAtop, BlendDestinationAtop, BlendXor
}
 Blending modes enum defining the available composition modes that can be used when rendering a layer. More...
enum  OutputUnits { Millimeters, Pixels }
 Output units for pen width and point marker width/height. More...

Public Slots

Q_DECL_DEPRECATED void onDrawingProgress (int current, int total)

Signals

void datumTransformInfoRequested (const QgsMapLayer *ml, const QString &srcAuthId, const QString &destAuthId) const
 Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTransformInfo for that layer.
void destinationSrsChanged ()
void drawError (QgsMapLayer *)
 emitted when layer's draw() returned false
void drawingProgress (int current, int total)
void extentsChanged ()
 emitted when the current extent gets changed
Q_DECL_DEPRECATED void hasCrsTransformEnabled (bool flag)
 This signal is emitted when CRS transformation is enabled/disabled.
void hasCrsTransformEnabledChanged (bool flag)
 This signal is emitted when CRS transformation is enabled/disabled.
void mapUnitsChanged ()
void rotationChanged (double)
 emitted when the current rotation gets changed
void updateMap ()

Public Member Functions

 QgsMapRenderer ()
 constructor
 ~QgsMapRenderer ()
 destructor
void addLayerCoordinateTransform (const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
void clearLayerCoordinateTransforms ()
const QgsMapToPixelcoordinateTransform ()
const
QgsCoordinateReferenceSystem
destinationCrs () const
 returns CRS of destination coordinate reference system
void enableOverviewMode (bool isOverview=true)
 sets whether map image will be for overview
QgsRectangle extent () const
 returns current extent
QgsRectangle fullExtent ()
 returns current extent of layer set
bool hasCrsTransformEnabled () const
 returns true if projections are enabled for this layer set
int height () const
QgsLabelingEngineInterfacelabelingEngine ()
 Labeling engine (NULL if there's no custom engine)
QgsRectangle layerExtentToOutputExtent (QgsMapLayer *theLayer, QgsRectangle extent)
 transform bounding box from layer's CRS to output CRS
QStringList & layerSet ()
 returns current layer set
QgsPoint layerToMapCoordinates (QgsMapLayer *theLayer, QgsPoint point)
 transform point coordinates from layer's CRS to output CRS
QgsRectangle layerToMapCoordinates (QgsMapLayer *theLayer, QgsRectangle rect)
 transform rectangle from layer's CRS to output CRS
const QgsMapSettingsmapSettings ()
 bridge to QgsMapSettings
QgsPoint mapToLayerCoordinates (QgsMapLayer *theLayer, QgsPoint point)
 transform point coordinates from output CRS to layer's CRS
QgsRectangle mapToLayerCoordinates (QgsMapLayer *theLayer, QgsRectangle rect)
 transform rectangle from output CRS to layer's CRS
QGis::UnitType mapUnits () const
double mapUnitsPerPixel () const
double outputDpi ()
 accessor for output dpi
QgsRectangle outputExtentToLayerExtent (QgsMapLayer *theLayer, QgsRectangle extent)
 transform bounding box from output CRS to layer's CRS
QSize outputSize ()
 accessor for output size
QSizeF outputSizeF ()
OutputUnits outputUnits () const
bool readXML (QDomNode &theNode)
 read settings
void render (QPainter *painter, double *forceWidthScale=0)
 starts rendering
QgsRenderContextrendererContext ()
 Accessor for render context.
double rotation () const
 returns current rotation in clockwise degrees
double scale () const
 Scale denominator.
void setDestinationCrs (const QgsCoordinateReferenceSystem &crs, bool refreshCoordinateTransformInfo=true, bool transformExtent=true)
 sets destination coordinate reference system
bool setExtent (const QgsRectangle &extent)
 sets extent and checks whether suitable (returns false if not)
void setLabelingEngine (QgsLabelingEngineInterface *iface)
 Set labeling engine.
void setLayerSet (const QStringList &layers)
 change current layer set
void setMapUnits (QGis::UnitType u)
void setOutputSize (QSize size, int dpi)
void setOutputSize (QSizeF size, double dpi)
void setOutputUnits (OutputUnits u)
void setProjectionsEnabled (bool enabled)
 sets whether to use projections for this layer set
void setRotation (double degrees)
 sets rotation value in clockwise degrees
void setScale (double scale)
 Sets scale for scale based visibility.
bool splitLayersExtent (QgsMapLayer *layer, QgsRectangle &extent, QgsRectangle &r2)
 Convenience function to project an extent into the layer source CRS, but also split it into two extents if it crosses the +/- 180 degree line.
const QgsCoordinateTransformtransformation (const QgsMapLayer *layer) const
void updateFullExtent ()
 updates extent of the layer set
void updateScale ()
 Recalculate the map scale.
int width () const
bool writeXML (QDomNode &theNode, QDomDocument &theDoc)
 write settings

Static Public Member Functions

static QgsMapRenderer::BlendMode getBlendModeEnum (const QPainter::CompositionMode &blendMode)
 Returns a BlendMode corresponding to a QPainter::CompositionMode.
static QPainter::CompositionMode getCompositionMode (const QgsMapRenderer::BlendMode &blendMode)
 Returns a QPainter::CompositionMode corresponding to a BlendMode.

Protected Member Functions

void adjustExtentToSize ()
 adjust extent to fit the pixmap size

Protected Attributes

QgsCoordinateReferenceSystemmDestCRS
 destination spatial reference system of the projection
QgsDistanceAreamDistArea
 tool for measuring
QgsRectangle mExtent
 current extent to be drawn
QgsRectangle mFullExtent
 full extent of the layer set
QgsLabelingEngineInterfacemLabelingEngine
 Labeling engine (NULL by default)
QgsRectangle mLastExtent
 Last extent to we drew so we know if we can used layer render caching or not.
QHash< QString,
QgsLayerCoordinateTransform
mLayerCoordinateTransformInfo
QStringList mLayerSet
 stores array of layers to be rendered (identified by string)
QgsMapSettings mMapSettings
 map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings
double mMapUnitsPerPixel
 map units per pixel
OutputUnits mOutputUnits
 Output units.
bool mOverview
 indicates whether it's map image for overview
bool mProjectionsEnabled
 detemines whether on the fly projection support is enabled
QgsRenderContext mRenderContext
 Encapsulates context of rendering.
QMutex mRenderMutex
 Locks rendering loop for concurrent draws.
double mRotation
 Map rotation.
double mScale
 Map scale denominator at its current zoom level.
QgsScaleCalculatormScaleCalculator
 scale calculator
QSizeF mSize

Static Protected Attributes

static bool mDrawing = false
 indicates drawing in progress

Detailed Description

A non GUI class for rendering a map layer set onto a QPainter.

Definition at line 125 of file qgsmaprenderer.h.

Member Enumeration Documentation

Blending modes enum defining the available composition modes that can be used when rendering a layer.

Enumerator:
BlendNormal 
BlendLighten 
BlendScreen 
BlendDodge 
BlendAddition 
BlendDarken 
BlendMultiply 
BlendBurn 
BlendOverlay 
BlendSoftLight 
BlendHardLight 
BlendDifference 
BlendSubtract 
BlendSource 
BlendDestinationOver 
BlendClear 
BlendDestination 
BlendSourceIn 
BlendDestinationIn 
BlendSourceOut 
BlendDestinationOut 
BlendSourceAtop 
BlendDestinationAtop 
BlendXor 

Definition at line 142 of file qgsmaprenderer.h.

Output units for pen width and point marker width/height.

Enumerator:
Millimeters 
Pixels 

Definition at line 132 of file qgsmaprenderer.h.

Constructor & Destructor Documentation

QgsMapRenderer::QgsMapRenderer ( )

constructor

Definition at line 42 of file qgsmaprenderer.cpp.

QgsMapRenderer::~QgsMapRenderer ( )

destructor

Definition at line 65 of file qgsmaprenderer.cpp.

Member Function Documentation

void QgsMapRenderer::addLayerCoordinateTransform ( const QString &  layerId,
const QString &  srcAuthId,
const QString &  destAuthId,
int  srcDatumTransform = -1,
int  destDatumTransform = -1 
)

Definition at line 1261 of file qgsmaprenderer.cpp.

void QgsMapRenderer::adjustExtentToSize ( )
protected

adjust extent to fit the pixmap size

Definition at line 168 of file qgsmaprenderer.cpp.

void QgsMapRenderer::clearLayerCoordinateTransforms ( )

Definition at line 1271 of file qgsmaprenderer.cpp.

const QgsMapToPixel* QgsMapRenderer::coordinateTransform ( )
inline

Definition at line 196 of file qgsmaprenderer.h.

void QgsMapRenderer::datumTransformInfoRequested ( const QgsMapLayer ml,
const QString &  srcAuthId,
const QString &  destAuthId 
) const
signal

Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTransformInfo for that layer.

const QgsCoordinateReferenceSystem & QgsMapRenderer::destinationCrs ( ) const

returns CRS of destination coordinate reference system

Definition at line 711 of file qgsmaprenderer.cpp.

void QgsMapRenderer::destinationSrsChanged ( )
signal
void QgsMapRenderer::drawError ( QgsMapLayer )
signal

emitted when layer's draw() returned false

void QgsMapRenderer::drawingProgress ( int  current,
int  total 
)
signal
Deprecated:
in 2.4 - not emitted anymore
void QgsMapRenderer::enableOverviewMode ( bool  isOverview = true)
inline

sets whether map image will be for overview

Definition at line 215 of file qgsmaprenderer.h.

QgsRectangle QgsMapRenderer::extent ( ) const

returns current extent

Definition at line 73 of file qgsmaprenderer.cpp.

void QgsMapRenderer::extentsChanged ( )
signal

emitted when the current extent gets changed

Note
added in 2.4
QgsRectangle QgsMapRenderer::fullExtent ( )

returns current extent of layer set

Definition at line 996 of file qgsmaprenderer.cpp.

QgsMapRenderer::BlendMode QgsMapRenderer::getBlendModeEnum ( const QPainter::CompositionMode &  blendMode)
static

Returns a BlendMode corresponding to a QPainter::CompositionMode.

Definition at line 1187 of file qgsmaprenderer.cpp.

QPainter::CompositionMode QgsMapRenderer::getCompositionMode ( const QgsMapRenderer::BlendMode blendMode)
static

Returns a QPainter::CompositionMode corresponding to a BlendMode.

Returns a QPainter::CompositionMode corresponding to a QgsMapRenderer::BlendMode.

Definition at line 1128 of file qgsmaprenderer.cpp.

bool QgsMapRenderer::hasCrsTransformEnabled ( ) const

returns true if projections are enabled for this layer set

Definition at line 668 of file qgsmaprenderer.cpp.

Q_DECL_DEPRECATED void QgsMapRenderer::hasCrsTransformEnabled ( bool  flag)
signal

This signal is emitted when CRS transformation is enabled/disabled.

Parameters
flagtrue if transformation is enabled.
Deprecated:
Use hasCrsTransformEnabledChanged( bool flag ) to avoid conflict with method of the same name).
void QgsMapRenderer::hasCrsTransformEnabledChanged ( bool  flag)
signal

This signal is emitted when CRS transformation is enabled/disabled.

Parameters
flagtrue if transformation is enabled.
Note
Added in 2.4
int QgsMapRenderer::height ( ) const
inline

Definition at line 206 of file qgsmaprenderer.h.

QgsLabelingEngineInterface* QgsMapRenderer::labelingEngine ( )
inline

Labeling engine (NULL if there's no custom engine)

Definition at line 304 of file qgsmaprenderer.h.

QgsRectangle QgsMapRenderer::layerExtentToOutputExtent ( QgsMapLayer theLayer,
QgsRectangle  extent 
)

transform bounding box from layer's CRS to output CRS

See Also
layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) if you want to transform a rectangle
Returns
a bounding box (aligned rectangle) containing the transformed extent

Definition at line 783 of file qgsmaprenderer.cpp.

QStringList & QgsMapRenderer::layerSet ( )

returns current layer set

Definition at line 1009 of file qgsmaprenderer.cpp.

QgsPoint QgsMapRenderer::layerToMapCoordinates ( QgsMapLayer theLayer,
QgsPoint  point 
)

transform point coordinates from layer's CRS to output CRS

Returns
the transformed point

Definition at line 838 of file qgsmaprenderer.cpp.

QgsRectangle QgsMapRenderer::layerToMapCoordinates ( QgsMapLayer theLayer,
QgsRectangle  rect 
)

transform rectangle from layer's CRS to output CRS

See Also
layerExtentToOutputExtent() if you want to transform a bounding box
Returns
the transformed rectangle

Definition at line 862 of file qgsmaprenderer.cpp.

const QgsMapSettings & QgsMapRenderer::mapSettings ( )

bridge to QgsMapSettings

Note
added in 2.4

Definition at line 1248 of file qgsmaprenderer.cpp.

QgsPoint QgsMapRenderer::mapToLayerCoordinates ( QgsMapLayer theLayer,
QgsPoint  point 
)

transform point coordinates from output CRS to layer's CRS

Returns
the transformed point

Definition at line 886 of file qgsmaprenderer.cpp.

QgsRectangle QgsMapRenderer::mapToLayerCoordinates ( QgsMapLayer theLayer,
QgsRectangle  rect 
)

transform rectangle from output CRS to layer's CRS

See Also
outputExtentToLayerExtent() if you want to transform a bounding box
Returns
the transformed rectangle

Definition at line 908 of file qgsmaprenderer.cpp.

QGis::UnitType QgsMapRenderer::mapUnits ( ) const

Definition at line 639 of file qgsmaprenderer.cpp.

void QgsMapRenderer::mapUnitsChanged ( )
signal
double QgsMapRenderer::mapUnitsPerPixel ( ) const
inline

Definition at line 203 of file qgsmaprenderer.h.

void QgsMapRenderer::onDrawingProgress ( int  current,
int  total 
)
slot
Deprecated:
in 2.4 - does nothing

Definition at line 644 of file qgsmaprenderer.cpp.

double QgsMapRenderer::outputDpi ( )

accessor for output dpi

Definition at line 153 of file qgsmaprenderer.cpp.

QgsRectangle QgsMapRenderer::outputExtentToLayerExtent ( QgsMapLayer theLayer,
QgsRectangle  extent 
)

transform bounding box from output CRS to layer's CRS

See Also
mapToLayerCoordinates( QgsMapLayer* theLayer,QgsRectangle rect ) if you want to transform a rectangle
Returns
a bounding box (aligned rectangle) containing the transformed extent

Definition at line 809 of file qgsmaprenderer.cpp.

QSize QgsMapRenderer::outputSize ( )

accessor for output size

Definition at line 158 of file qgsmaprenderer.cpp.

QSizeF QgsMapRenderer::outputSizeF ( )

Definition at line 163 of file qgsmaprenderer.cpp.

OutputUnits QgsMapRenderer::outputUnits ( ) const
inline

Definition at line 280 of file qgsmaprenderer.h.

bool QgsMapRenderer::readXML ( QDomNode &  theNode)

read settings

Definition at line 1015 of file qgsmaprenderer.cpp.

void QgsMapRenderer::render ( QPainter *  painter,
double *  forceWidthScale = 0 
)

starts rendering

Parameters
painterpainter to render to
forceWidthScaleForce a specific scale factor for line widths and marker sizes. Automatically calculated from output device DPI if 0

Definition at line 234 of file qgsmaprenderer.cpp.

QgsRenderContext* QgsMapRenderer::rendererContext ( )
inline

Accessor for render context.

Definition at line 301 of file qgsmaprenderer.h.

double QgsMapRenderer::rotation ( ) const

returns current rotation in clockwise degrees

Note
added in 2.8

Definition at line 133 of file qgsmaprenderer.cpp.

void QgsMapRenderer::rotationChanged ( double  )
signal

emitted when the current rotation gets changed

Note
added in 2.8
double QgsMapRenderer::scale ( ) const
inline

Scale denominator.

Definition at line 199 of file qgsmaprenderer.h.

void QgsMapRenderer::setDestinationCrs ( const QgsCoordinateReferenceSystem crs,
bool  refreshCoordinateTransformInfo = true,
bool  transformExtent = true 
)

sets destination coordinate reference system

Definition at line 673 of file qgsmaprenderer.cpp.

bool QgsMapRenderer::setExtent ( const QgsRectangle extent)

sets extent and checks whether suitable (returns false if not)

Definition at line 83 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setLabelingEngine ( QgsLabelingEngineInterface iface)

Set labeling engine.

Previous engine (if any) is deleted. Takes ownership of the engine.

Definition at line 1082 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setLayerSet ( const QStringList &  layers)

change current layer set

Definition at line 1002 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setMapUnits ( QGis::UnitType  u)

Definition at line 629 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setOutputSize ( QSize  size,
int  dpi 
)

Definition at line 139 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setOutputSize ( QSizeF  size,
double  dpi 
)

Definition at line 146 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setOutputUnits ( OutputUnits  u)
inline

Definition at line 278 of file qgsmaprenderer.h.

void QgsMapRenderer::setProjectionsEnabled ( bool  enabled)

sets whether to use projections for this layer set

Definition at line 650 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setRotation ( double  degrees)

sets rotation value in clockwise degrees

Note
added in 2.8

Definition at line 125 of file qgsmaprenderer.cpp.

void QgsMapRenderer::setScale ( double  scale)
inline

Sets scale for scale based visibility.

Normally, the scale is calculated automatically. This function is only used to force a preview scale (e.g. for print composer)

Definition at line 202 of file qgsmaprenderer.h.

bool QgsMapRenderer::splitLayersExtent ( QgsMapLayer layer,
QgsRectangle extent,
QgsRectangle r2 
)

Convenience function to project an extent into the layer source CRS, but also split it into two extents if it crosses the +/- 180 degree line.

Modifies the given extent to be in the source CRS coordinates, and if it was split, returns true, and also sets the contents of the r2 parameter

Definition at line 720 of file qgsmaprenderer.cpp.

const QgsCoordinateTransform * QgsMapRenderer::transformation ( const QgsMapLayer layer) const

Definition at line 1090 of file qgsmaprenderer.cpp.

void QgsMapRenderer::updateFullExtent ( )

updates extent of the layer set

Definition at line 927 of file qgsmaprenderer.cpp.

void QgsMapRenderer::updateMap ( )
signal
Deprecated:
in 2.4 - not emitted anymore
void QgsMapRenderer::updateScale ( )

Recalculate the map scale.

Definition at line 78 of file qgsmaprenderer.cpp.

int QgsMapRenderer::width ( ) const
inline

Definition at line 205 of file qgsmaprenderer.h.

bool QgsMapRenderer::writeXML ( QDomNode &  theNode,
QDomDocument &  theDoc 
)

write settings

Definition at line 1054 of file qgsmaprenderer.cpp.

Member Data Documentation

QgsCoordinateReferenceSystem* QgsMapRenderer::mDestCRS
protected

destination spatial reference system of the projection

Definition at line 416 of file qgsmaprenderer.h.

QgsDistanceArea* QgsMapRenderer::mDistArea
protected

tool for measuring

Definition at line 425 of file qgsmaprenderer.h.

bool QgsMapRenderer::mDrawing = false
staticprotected

indicates drawing in progress

Definition at line 384 of file qgsmaprenderer.h.

QgsRectangle QgsMapRenderer::mExtent
protected

current extent to be drawn

Definition at line 399 of file qgsmaprenderer.h.

QgsRectangle QgsMapRenderer::mFullExtent
protected

full extent of the layer set

Definition at line 422 of file qgsmaprenderer.h.

QgsLabelingEngineInterface* QgsMapRenderer::mLabelingEngine
protected

Labeling engine (NULL by default)

Definition at line 434 of file qgsmaprenderer.h.

QgsRectangle QgsMapRenderer::mLastExtent
protected

Last extent to we drew so we know if we can used layer render caching or not.

Note there are no accessors for this as it is intended to internal use only.

Definition at line 405 of file qgsmaprenderer.h.

QHash< QString, QgsLayerCoordinateTransform > QgsMapRenderer::mLayerCoordinateTransformInfo
protected

Definition at line 442 of file qgsmaprenderer.h.

QStringList QgsMapRenderer::mLayerSet
protected

stores array of layers to be rendered (identified by string)

Definition at line 419 of file qgsmaprenderer.h.

QgsMapSettings QgsMapRenderer::mMapSettings
protected

map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings

Definition at line 440 of file qgsmaprenderer.h.

double QgsMapRenderer::mMapUnitsPerPixel
protected

map units per pixel

Definition at line 387 of file qgsmaprenderer.h.

OutputUnits QgsMapRenderer::mOutputUnits
protected

Output units.

Definition at line 431 of file qgsmaprenderer.h.

bool QgsMapRenderer::mOverview
protected

indicates whether it's map image for overview

Definition at line 408 of file qgsmaprenderer.h.

bool QgsMapRenderer::mProjectionsEnabled
protected

detemines whether on the fly projection support is enabled

Definition at line 413 of file qgsmaprenderer.h.

QgsRenderContext QgsMapRenderer::mRenderContext
protected

Encapsulates context of rendering.

Definition at line 428 of file qgsmaprenderer.h.

QMutex QgsMapRenderer::mRenderMutex
protected

Locks rendering loop for concurrent draws.

Definition at line 437 of file qgsmaprenderer.h.

double QgsMapRenderer::mRotation
protected

Map rotation.

Definition at line 393 of file qgsmaprenderer.h.

double QgsMapRenderer::mScale
protected

Map scale denominator at its current zoom level.

Definition at line 390 of file qgsmaprenderer.h.

QgsScaleCalculator* QgsMapRenderer::mScaleCalculator
protected

scale calculator

Definition at line 396 of file qgsmaprenderer.h.

QSizeF QgsMapRenderer::mSize
protected

Definition at line 410 of file qgsmaprenderer.h.


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