QgsMapRenderer Class Reference
[QGIS core library]

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

#include <qgsmaprenderer.h>

Collaboration diagram for QgsMapRenderer:

Collaboration graph
[legend]

List of all members.

Public Types

enum  OutputUnits { Millimeters, Pixels }
 Output units for pen width and point marker width/height. More...

Public Slots

void onDrawingProgress (int current, int total)
 called by signal from layer current being drawn

Signals

void drawingProgress (int current, int total)
void hasCrsTransformEnabled (bool flag)
void destinationSrsChanged ()
void updateMap ()
void mapUnitsChanged ()
void drawError (QgsMapLayer *)
 emitted when layer's draw() returned false

Public Member Functions

 QgsMapRenderer ()
 constructor
 ~QgsMapRenderer ()
 destructor
void render (QPainter *painter)
 starts rendering
bool setExtent (const QgsRectangle &extent)
 sets extent and checks whether suitable (returns false if not)
QgsRectangle extent () const
 returns current extent
const QgsMapToPixelcoordinateTransform ()
double scale () const
void setScale (double scale)
 Sets scale for scale based visibility.
double mapUnitsPerPixel () const
int width () const
int height () const
void updateScale ()
 Recalculate the map scale.
QgsDistanceAreadistanceArea ()
 Return the measuring object.
QGis::UnitType mapUnits () const
void setMapUnits (QGis::UnitType u)
void enableOverviewMode (bool isOverview=true)
 sets whether map image will be for overview
void setOutputSize (QSize size, int dpi)
void setOutputSize (QSizeF size, double dpi)
double outputDpi ()
 accessor for output dpi
QSize outputSize ()
 accessor for output size
QSizeF outputSizeF ()
QgsRectangle layerExtentToOutputExtent (QgsMapLayer *theLayer, QgsRectangle extent)
 transform extent in layer's CRS to extent in output CRS
QgsPoint layerToMapCoordinates (QgsMapLayer *theLayer, QgsPoint point)
 transform coordinates from layer's CRS to output CRS
QgsPoint mapToLayerCoordinates (QgsMapLayer *theLayer, QgsPoint point)
 transform coordinates from output CRS to layer's CRS
QgsRectangle mapToLayerCoordinates (QgsMapLayer *theLayer, QgsRectangle rect)
 transform rect's coordinates from output CRS to layer's CRS
void setProjectionsEnabled (bool enabled)
 sets whether to use projections for this layer set
bool hasCrsTransformEnabled ()
 returns true if projections are enabled for this layer set
void setDestinationSrs (const QgsCoordinateReferenceSystem &srs)
 sets destination spatial reference system
const
QgsCoordinateReferenceSystem
destinationSrs ()
 returns CRS of destination spatial reference system
void setOutputUnits (OutputUnits u)
OutputUnits outputUnits () const
QgsRectangle fullExtent ()
 returns current extent of layer set
QStringList & layerSet ()
 returns current layer set
void setLayerSet (const QStringList &layers)
 change current layer set
void updateFullExtent ()
 updates extent of the layer set
bool readXML (QDomNode &theNode)
 read settings
bool writeXML (QDomNode &theNode, QDomDocument &theDoc)
 write settings
QgsRenderContextrendererContext ()
 Accessor for render context.
QgsLabelingEngineInterfacelabelingEngine ()
 Labeling engine (NULL if there's no custom engine).
void setLabelingEngine (QgsLabelingEngineInterface *iface)
 Set labeling engine.

Protected Member Functions

void adjustExtentToSize ()
 adjust extent to fit the pixmap size
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.
QgsOverlayObjectPositionManageroverlayManagerFromSettings ()
 Creates an overlay object position manager subclass according to the current settings.

Protected Attributes

bool mDrawing
 indicates drawing in progress
double mMapUnitsPerPixel
 map units per pixel
double mScale
 Map scale at its current zool level.
QgsScaleCalculatormScaleCalculator
 scale calculator
QgsRectangle mExtent
 current extent to be drawn
QgsRectangle mLastExtent
 Last extent to we drew so we know if we can used layer render caching or not.
bool mOverview
 indicates whether it's map image for overview
QSizeF mSize
bool mProjectionsEnabled
 detemines whether on the fly projection support is enabled
QgsCoordinateReferenceSystemmDestCRS
 destination spatial reference system of the projection
QStringList mLayerSet
 stores array of layers to be rendered (identified by string)
QgsRectangle mFullExtent
 full extent of the layer set
QgsDistanceAreamDistArea
 tool for measuring
QgsRenderContext mRenderContext
 Encapsulates context of rendering.
OutputUnits mOutputUnits
 Output units.
QgsLabelingEngineInterfacemLabelingEngine
 Labeling engine (NULL by default).


Detailed Description

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

Definition at line 73 of file qgsmaprenderer.h.


Member Enumeration Documentation

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

Enumerator:
Millimeters 
Pixels 

Definition at line 80 of file qgsmaprenderer.h.


Constructor & Destructor Documentation

QgsMapRenderer::QgsMapRenderer (  ) 

QgsMapRenderer::~QgsMapRenderer (  ) 

destructor

Definition at line 65 of file qgsmaprenderer.cpp.

References mDestCRS, mDistArea, mLabelingEngine, and mScaleCalculator.


Member Function Documentation

void QgsMapRenderer::render ( QPainter *  painter  ) 

starts rendering

Definition at line 217 of file qgsmaprenderer.cpp.

References QgsOverlayObjectPositionManager::addLayer(), QgsMapLayer::cacheImage(), QgsMapLayerRegistry::clearAllLayerCaches(), QgsScaleCalculator::dpi(), QgsMapLayer::draw(), drawError(), drawingProgress(), QgsLabelingEngineInterface::drawLabeling(), QgsMapLayer::drawLabels(), QgsLabelingEngineInterface::exit(), QgsMapLayer::extent(), QgsOverlayObjectPositionManager::findObjectPositions(), hasCrsTransformEnabled(), QgsMapLayer::hasScaleBasedVisibility(), QgsLabelingEngineInterface::init(), QgsMapLayerRegistry::instance(), QgsVectorLayer::isEditable(), QgsRectangle::isEmpty(), QgsRenderContext::labelingEngine(), QgsMapLayerRegistry::mapLayer(), QgsRenderContext::mapToPixel(), QgsScaleCalculator::mapUnits(), QgsMapToPixel::mapUnitsPerPixel(), QgsMapLayer::maximumScale(), mDestCRS, mDrawing, mExtent, Millimeters, QgsMapLayer::minimumScale(), mLabelingEngine, mLastExtent, mLayerSet, mOutputUnits, mOverview, mRenderContext, mScale, mScaleCalculator, mSize, QgsMapLayer::name(), onDrawingProgress(), overlayManagerFromSettings(), QgsRenderContext::painter(), QgsDebugMsg, QgsMapLayer::RasterLayer, QgsRenderContext::rasterScaleFactor(), QgsOverlayObjectPositionManager::removeLayers(), QgsRenderContext::rendererScale(), QgsRenderContext::renderingStopped(), QgsRenderContext::scaleFactor(), QgsMapLayer::setCacheImage(), QgsRenderContext::setCoordinateTransform(), QgsRenderContext::setDrawEditingInformation(), QgsRenderContext::setExtent(), QgsRenderContext::setLabelingEngine(), QgsRenderContext::setMapToPixel(), QgsMapToPixel::setMapUnitsPerPixel(), QgsRenderContext::setPainter(), QgsRenderContext::setRasterScaleFactor(), QgsRenderContext::setRendererScale(), QgsRenderContext::setRenderingStopped(), QgsRenderContext::setScaleFactor(), QgsMapToPixel::setYMaximum(), splitLayersExtent(), QgsMapLayer::srs(), QgsRectangle::toString(), QgsMapLayer::type(), QgsMapLayer::VectorLayer, QgsVectorLayer::vectorOverlays(), and QgsLabelingEngineInterface::willUseLayer().

Referenced by QgsComposerMap::draw(), QgsQuickPrint::printMap(), QgsMapOverviewCanvas::refresh(), QgsMapCanvasMap::render(), and QgsMapCanvas::saveAsImage().

bool QgsMapRenderer::setExtent ( const QgsRectangle extent  ) 

QgsRectangle QgsMapRenderer::extent (  )  const

const QgsMapToPixel* QgsMapRenderer::coordinateTransform (  )  [inline]

double QgsMapRenderer::scale (  )  const [inline]

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 107 of file qgsmaprenderer.h.

Referenced by QgsComposerMap::draw().

double QgsMapRenderer::mapUnitsPerPixel (  )  const [inline]

int QgsMapRenderer::width (  )  const [inline]

Definition at line 110 of file qgsmaprenderer.h.

int QgsMapRenderer::height (  )  const [inline]

Definition at line 111 of file qgsmaprenderer.h.

void QgsMapRenderer::updateScale (  ) 

Recalculate the map scale.

Definition at line 79 of file qgsmaprenderer.cpp.

References QgsScaleCalculator::calculate(), mExtent, mScale, mScaleCalculator, and mSize.

Referenced by adjustExtentToSize(), and setMapUnits().

QgsDistanceArea* QgsMapRenderer::distanceArea (  )  [inline]

Return the measuring object.

Definition at line 117 of file qgsmaprenderer.h.

QGis::UnitType QgsMapRenderer::mapUnits (  )  const

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

void QgsMapRenderer::enableOverviewMode ( bool  isOverview = true  )  [inline]

sets whether map image will be for overview

Definition at line 122 of file qgsmaprenderer.h.

Referenced by QgsMapOverviewCanvas::QgsMapOverviewCanvas().

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

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

double QgsMapRenderer::outputDpi (  ) 

accessor for output dpi

Definition at line 140 of file qgsmaprenderer.cpp.

References QgsScaleCalculator::dpi(), and mScaleCalculator.

Referenced by QgsQuickPrint::printMap(), and QgsMapCanvasItem::setRenderContextVariables().

QSize QgsMapRenderer::outputSize (  ) 

accessor for output size

Definition at line 145 of file qgsmaprenderer.cpp.

References mSize.

Referenced by QgsQuickPrint::printMap().

QSizeF QgsMapRenderer::outputSizeF (  ) 

Definition at line 150 of file qgsmaprenderer.cpp.

References mSize.

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

transform extent in layer's CRS to extent in output CRS

Definition at line 727 of file qgsmaprenderer.cpp.

References hasCrsTransformEnabled(), mDestCRS, QgsDebugMsg, QgsMapLayer::srs(), and QgsException::what().

Referenced by updateFullExtent(), and QgsMapCanvas::zoomToSelected().

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

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

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

transform rect's coordinates from output CRS to layer's CRS

Definition at line 794 of file qgsmaprenderer.cpp.

References hasCrsTransformEnabled(), mDestCRS, QgsDebugMsg, QgsCoordinateTransform::ReverseTransform, QgsMapLayer::srs(), and QgsException::what().

void QgsMapRenderer::setProjectionsEnabled ( bool  enabled  ) 

bool QgsMapRenderer::hasCrsTransformEnabled (  ) 

void QgsMapRenderer::setDestinationSrs ( const QgsCoordinateReferenceSystem srs  ) 

const QgsCoordinateReferenceSystem & QgsMapRenderer::destinationSrs (  ) 

void QgsMapRenderer::setOutputUnits ( OutputUnits  u  )  [inline]

Definition at line 157 of file qgsmaprenderer.h.

OutputUnits QgsMapRenderer::outputUnits (  )  const [inline]

Definition at line 159 of file qgsmaprenderer.h.

Referenced by QgsMapCanvasItem::setRenderContextVariables().

QgsRectangle QgsMapRenderer::fullExtent (  ) 

returns current extent of layer set

Definition at line 875 of file qgsmaprenderer.cpp.

References mFullExtent, and updateFullExtent().

Referenced by QgsMapCanvas::fullExtent().

QStringList & QgsMapRenderer::layerSet (  ) 

void QgsMapRenderer::setLayerSet ( const QStringList &  layers  ) 

change current layer set

Definition at line 881 of file qgsmaprenderer.cpp.

References mLayerSet, and updateFullExtent().

Referenced by QgsComposerMap::draw(), QgsMapOverviewCanvas::setLayerSet(), and QgsMapCanvas::setLayerSet().

void QgsMapRenderer::updateFullExtent (  ) 

bool QgsMapRenderer::readXML ( QDomNode &  theNode  ) 

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

QgsRenderContext* QgsMapRenderer::rendererContext (  )  [inline]

Accessor for render context.

Definition at line 180 of file qgsmaprenderer.h.

Referenced by QgsComposerMap::draw(), QgsMapCanvas::resizeEvent(), and QgsMapCanvas::setRenderFlag().

QgsLabelingEngineInterface* QgsMapRenderer::labelingEngine (  )  [inline]

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

Note:
Added in QGIS v1.4

Definition at line 184 of file qgsmaprenderer.h.

Referenced by QgsComposerMap::draw().

void QgsMapRenderer::setLabelingEngine ( QgsLabelingEngineInterface iface  ) 

Set labeling engine.

Previous engine (if any) is deleted. Takes ownership of the engine. Added in QGIS v1.4

Definition at line 1069 of file qgsmaprenderer.cpp.

References mLabelingEngine.

Referenced by QgsComposerMap::draw().

void QgsMapRenderer::drawingProgress ( int  current,
int  total 
) [signal]

Referenced by render().

void QgsMapRenderer::hasCrsTransformEnabled ( bool  flag  )  [signal]

void QgsMapRenderer::destinationSrsChanged (  )  [signal]

Referenced by setDestinationSrs().

void QgsMapRenderer::updateMap (  )  [signal]

Referenced by onDrawingProgress().

void QgsMapRenderer::mapUnitsChanged (  )  [signal]

Referenced by setMapUnits().

void QgsMapRenderer::drawError ( QgsMapLayer  )  [signal]

emitted when layer's draw() returned false

Referenced by render().

void QgsMapRenderer::onDrawingProgress ( int  current,
int  total 
) [slot]

called by signal from layer current being drawn

Definition at line 620 of file qgsmaprenderer.cpp.

References updateMap().

Referenced by render().

void QgsMapRenderer::adjustExtentToSize (  )  [protected]

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

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 669 of file qgsmaprenderer.cpp.

References hasCrsTransformEnabled(), mDestCRS, QgsDebugMsg, QgsCoordinateTransform::ReverseTransform, QgsRectangle::set(), QgsMapLayer::srs(), QgsPoint::x(), QgsRectangle::xMaximum(), QgsRectangle::xMinimum(), QgsPoint::y(), QgsRectangle::yMaximum(), and QgsRectangle::yMinimum().

Referenced by render().

QgsOverlayObjectPositionManager * QgsMapRenderer::overlayManagerFromSettings (  )  [protected]

Creates an overlay object position manager subclass according to the current settings.

Note:
this method was added in version 1.1

Definition at line 892 of file qgsmaprenderer.cpp.

References QgsPALObjectPositionManager::setPlacementAlgorithm().

Referenced by render().


Member Data Documentation

bool QgsMapRenderer::mDrawing [protected]

indicates drawing in progress

Definition at line 231 of file qgsmaprenderer.h.

Referenced by QgsMapRenderer(), and render().

map units per pixel

Definition at line 234 of file qgsmaprenderer.h.

Referenced by adjustExtentToSize().

double QgsMapRenderer::mScale [protected]

Map scale at its current zool level.

Definition at line 237 of file qgsmaprenderer.h.

Referenced by adjustExtentToSize(), render(), and updateScale().

scale calculator

Definition at line 240 of file qgsmaprenderer.h.

Referenced by mapUnits(), outputDpi(), QgsMapRenderer(), render(), setMapUnits(), setOutputSize(), updateScale(), and ~QgsMapRenderer().

current extent to be drawn

Definition at line 243 of file qgsmaprenderer.h.

Referenced by adjustExtentToSize(), extent(), render(), setExtent(), and updateScale().

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.

Note:
added in QGIS 1.4

Definition at line 250 of file qgsmaprenderer.h.

Referenced by render(), and setExtent().

bool QgsMapRenderer::mOverview [protected]

indicates whether it's map image for overview

Definition at line 253 of file qgsmaprenderer.h.

Referenced by QgsMapRenderer(), and render().

QSizeF QgsMapRenderer::mSize [protected]

detemines whether on the fly projection support is enabled

Definition at line 258 of file qgsmaprenderer.h.

Referenced by hasCrsTransformEnabled(), QgsMapRenderer(), and setProjectionsEnabled().

QStringList QgsMapRenderer::mLayerSet [protected]

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

Definition at line 264 of file qgsmaprenderer.h.

Referenced by layerSet(), render(), setLayerSet(), and updateFullExtent().

full extent of the layer set

Definition at line 267 of file qgsmaprenderer.h.

Referenced by fullExtent(), and updateFullExtent().

tool for measuring

Definition at line 270 of file qgsmaprenderer.h.

Referenced by QgsMapRenderer(), setDestinationSrs(), setProjectionsEnabled(), and ~QgsMapRenderer().

Encapsulates context of rendering.

Definition at line 273 of file qgsmaprenderer.h.

Referenced by adjustExtentToSize(), and render().

Output units.

Definition at line 276 of file qgsmaprenderer.h.

Referenced by QgsMapRenderer(), and render().

Labeling engine (NULL by default).

Definition at line 279 of file qgsmaprenderer.h.

Referenced by QgsMapRenderer(), render(), setLabelingEngine(), and ~QgsMapRenderer().


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

Generated on Sat Feb 4 19:17:39 2012 for Quantum GIS API Documentation by  doxygen 1.5.6