33 #include <QDomDocument>
35 #include <QMutexLocker>
37 #include <QListIterator>
40 #include <QCoreApplication>
54 mSize = QSize( 0, 0 );
98 if ( extent.
width() > 0 &&
100 extent.
width() < 1 &&
105 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
106 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
108 double xRange = extent.
width() / xMean;
109 double yRange = extent.
height() / yMean;
111 static const double minProportion = 1e-12;
112 if ( xRange < minProportion || yRange < minProportion )
128 mSize = QSizeF( size.width(), size.height() );
147 return mSize.toSize();
157 double myHeight =
mSize.height();
158 double myWidth =
mSize.width();
162 if ( !myWidth || !myHeight )
173 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
176 double dxmin, dxmax, dymin, dymax, whitespace;
178 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
234 if (
mSize.width() == 1 &&
mSize.height() == 1 )
240 QPaintDevice* thePaintDevice = painter->device();
241 if ( !thePaintDevice )
250 QCoreApplication::processEvents();
280 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
281 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
282 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
283 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
290 double scaleFactor = 1.0;
293 if ( forceWidthScale )
295 scaleFactor = *forceWidthScale;
299 scaleFactor = sceneDpi / 25.4;
302 double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
331 while ( li.hasPrevious() )
342 QImage * mypFlattenedImage = 0;
344 QString layerId = li.previous();
346 QgsDebugMsg(
"Rendering at layer item " + layerId );
354 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
365 QgsDebugMsg( QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
378 mypContextPainter->setCompositionMode( ml->
blendMode() );
414 bool scaleRaster =
false;
423 QSettings mySettings;
429 bool flattenedLayer =
false;
433 if ((( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
437 flattenedLayer =
true;
440 if ( mypFlattenedImage->isNull() )
447 mypFlattenedImage->fill( 0 );
448 QPainter * mypPainter =
new QPainter( mypFlattenedImage );
449 if ( mySettings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
451 mypPainter->setRenderHint( QPainter::Antialiasing );
453 mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
513 QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->
layerTransparency() / 100 ) );
521 if ( flattenedLayer )
526 mypContextPainter->save();
527 mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
528 mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
529 mypContextPainter->restore();
530 delete mypFlattenedImage;
531 mypFlattenedImage = 0;
538 QgsDebugMsg(
"Layer not rendered because it is not within the defined "
539 "visibility scale range" );
553 while ( li.hasPrevious() )
560 QString layerId = li.previous();
611 QgsDebugMsg(
"Rendering completed in (seconds): " + QString(
"%1" ).arg( renderTime.elapsed() / 1000.0 ) );
642 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
666 if ( refreshCoordinateTransformInfo )
716 static const double splitCoord = 180.0;
729 ll = transform->
transform( ll.x(), ll.y(),
731 ur = transform->
transform( ur.x(), ur.y(),
736 if ( ll.x() > ur.x() )
756 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
757 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
918 QStringList::iterator it =
mLayerSet.begin();
925 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
962 const double padFactor = 1e-8;
984 QgsDebugMsg( QString(
"Entering: %1" ).arg( layers.join(
", " ) ) );
998 tmpSettings.
readXML( theNode );
1001 QDomElement layerCoordTransformInfoElem = theNode.firstChildElement(
"layer_coordinate_transform_info" );
1002 if ( !layerCoordTransformInfoElem.isNull() )
1004 QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName(
"layer_coordinate_transform" );
1005 QDomElement layerCoordTransformElem;
1006 for (
int i = 0; i < layerCoordinateTransformList.size(); ++i )
1008 layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1009 QString layerId = layerCoordTransformElem.attribute(
"layerid" );
1010 if ( layerId.isEmpty() )
1016 lct.
srcAuthId = layerCoordTransformElem.attribute(
"srcAuthId" );
1017 lct.
destAuthId = layerCoordTransformElem.attribute(
"destAuthId" );
1018 lct.
srcDatumTransform = layerCoordTransformElem.attribute(
"srcDatumTransform",
"-1" ).toInt();
1019 lct.
destDatumTransform = layerCoordTransformElem.attribute(
"destDatumTransform",
"-1" ).toInt();
1044 tmpSettings.
writeXML( theNode, theDoc );
1046 QDomElement layerCoordTransformInfo = theDoc.createElement(
"layer_coordinate_transform_info" );
1050 QDomElement layerCoordTransformElem = theDoc.createElement(
"layer_coordinate_transform" );
1051 layerCoordTransformElem.setAttribute(
"layerid", coordIt.key() );
1052 layerCoordTransformElem.setAttribute(
"srcAuthId", coordIt->srcAuthId );
1053 layerCoordTransformElem.setAttribute(
"destAuthId", coordIt->destAuthId );
1054 layerCoordTransformElem.setAttribute(
"srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1055 layerCoordTransformElem.setAttribute(
"destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1056 layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1058 theNode.appendChild( layerCoordTransformInfo );
1084 && ctIt->srcAuthId == layer->
crs().
authid()
1097 || ctIt->srcAuthId == layer->
crs().
authid()
1111 switch ( blendMode )
1114 return QPainter::CompositionMode_SourceOver;
1116 return QPainter::CompositionMode_Lighten;
1118 return QPainter::CompositionMode_Screen;
1120 return QPainter::CompositionMode_ColorDodge;
1122 return QPainter::CompositionMode_Plus;
1124 return QPainter::CompositionMode_Darken;
1126 return QPainter::CompositionMode_Multiply;
1128 return QPainter::CompositionMode_ColorBurn;
1130 return QPainter::CompositionMode_Overlay;
1132 return QPainter::CompositionMode_SoftLight;
1134 return QPainter::CompositionMode_HardLight;
1136 return QPainter::CompositionMode_Difference;
1138 return QPainter::CompositionMode_Exclusion;
1140 return QPainter::CompositionMode_SourceOver;
1147 switch ( blendMode )
1149 case QPainter::CompositionMode_SourceOver:
1151 case QPainter::CompositionMode_Lighten:
1153 case QPainter::CompositionMode_Screen:
1155 case QPainter::CompositionMode_ColorDodge:
1157 case QPainter::CompositionMode_Plus:
1159 case QPainter::CompositionMode_Darken:
1161 case QPainter::CompositionMode_Multiply:
1163 case QPainter::CompositionMode_ColorBurn:
1165 case QPainter::CompositionMode_Overlay:
1167 case QPainter::CompositionMode_SoftLight:
1169 case QPainter::CompositionMode_HardLight:
1171 case QPainter::CompositionMode_Difference:
1173 case QPainter::CompositionMode_Exclusion:
const QgsMapSettings & mapSettings()
bridge to QgsMapSettings
virtual void exit()=0
called when we're done with rendering
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
void unionRect(const QgsRectangle &rect)
updates rectangle to include passed argument
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
virtual Q_DECL_DEPRECATED void init(QgsMapRenderer *mp)=0
called when we're going to start with rendering
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Base class for all map layer types.
void clearLayerCoordinateTransforms()
void render(QPainter *painter, double *forceWidthScale=0)
starts rendering
void setLabelingEngine(QgsLabelingEngineInterface *iface)
Set labeling engine.
bool isEmpty() const
test if rectangle is empty.
QgsMapLayer::LayerType type() const
Get the type of the layer.
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
virtual void drawLabels(QgsRenderContext &rendererContext)
Draw labels.
void setYMaximum(double ymax)
Set maximum y value.
void drawError(QgsMapLayer *)
emitted when layer's draw() returned false
void setXMaximum(double x)
Set the maximum x value.
void readXML(QDomNode &theNode)
OutputUnits mOutputUnits
Output units.
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMaximum() const
Get the y maximum value (top side of rectangle)
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
bool mProjectionsEnabled
detemines whether on the fly projection support is enabled
QgsRectangle mLastExtent
Last extent to we drew so we know if we can used layer render caching or not.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
double rendererScale() const
QgsScaleCalculator * mScaleCalculator
scale calculator
QgsRectangle extent() const
returns current extent
QString qgsDoubleToString(const double &a)
void addLayerCoordinateTransform(const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
void setRendererScale(double scale)
float minimumScale() const
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
#define Q_NOWARN_DEPRECATED_PUSH
void drawingProgress(int current, int total)
~QgsMapRenderer()
destructor
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
QGis::UnitType mapUnits() const
Returns current map units.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void setProjectionsEnabled(bool enabled)
sets whether to use projections for this layer set
static bool mDrawing
indicates drawing in progress
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 exten...
double scaleFactor() const
void setLayerSet(const QStringList &layers)
change current layer set
double outputDpi()
accessor for output dpi
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point)
transform point coordinates from output CRS to layer's CRS
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent)
transform bounding box from output CRS to layer's CRS
void setExtent(const QgsRectangle &extent)
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
const QgsCoordinateTransform * transformation(const QgsMapLayer *layer) const
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
QgsRectangle mExtent
current extent to be drawn
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QgsMapRenderer()
constructor
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point)
transform point coordinates from layer's CRS to output CRS
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
The QgsMapSettings class contains configuration for rendering of the map.
void setCoordinateTransform(const QgsCoordinateTransform *t)
Sets coordinate transformation.
QSize outputSize()
accessor for output size
virtual bool draw(QgsRenderContext &rendererContext)
This is the method that does the actual work of drawing the layer onto a paint device.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
const QString & name() const
Get the display name of the layer.
QMutex mRenderMutex
Locks rendering loop for concurrent draws.
Perform transforms between map coordinates and device coordinates.
void setSelectionColor(const QColor &color)
Added in QGIS v2.0.
void extentsChanged()
emitted when the current extent gets changed
QPainter::CompositionMode blendMode() const
Read blend mode for layer.
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
void setScaleFactor(double factor)
QgsDistanceArea * mDistArea
tool for measuring
QPainter::CompositionMode featureBlendMode() const
Read blend mode for layer.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
bool hasScaleBasedVisibility() const
void adjustExtentToSize()
adjust extent to fit the pixmap size
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
double xMaximum() const
Get the x maximum value (right side of rectangle)
void hasCrsTransformEnabledChanged(bool flag)
This signal is emitted when CRS transformation is enabled/disabled.
#define QgsDebugMsgLevel(str, level)
bool renderingStopped() const
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void setMapUnits(QGis::UnitType u)
Set units of map's geographical coordinates - used for scale calculation.
float maximumScale() const
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setYMinimum(double y)
Set the minimum y value.
void setDrawEditingInformation(bool b)
bool setExtent(const QgsRectangle &extent)
sets extent and checks whether suitable (returns false if not)
Q_GUI_EXPORT int qt_defaultDpiX()
void setMapUnits(QGis::UnitType u)
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
void destinationSrsChanged()
void setPainter(QPainter *p)
double rasterScaleFactor() const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Reads and writes project states.
bool mOverview
indicates whether it's map image for overview
double mapUnitsPerPixel() const
Return current map units per pixel.
QGis::UnitType mapUnits() const
Get units of map's geographical coordinates - used for scale calculation.
void setOutputSize(QSize size, int dpi)
A class to represent a point geometry.
void updateFullExtent()
updates extent of the layer set
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs, bool refreshCoordinateTransformInfo=true, bool transformExtent=true)
sets destination coordinate reference system
double dpi()
Accessor for dpi used in scale calculations.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc)
write settings
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
int layerTransparency() const
Read transparency for layer.
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
#define Q_NOWARN_DEPRECATED_POP
General purpose distance and area calculator.
QgsRectangle fullExtent()
returns current extent of layer set
QgsMapSettings mMapSettings
map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
virtual void drawLabeling(QgsRenderContext &context)=0
called when the map is drawn and labels should be placed
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
void setYMaximum(double y)
Set the maximum y value.
Q_DECL_DEPRECATED void onDrawingProgress(int current, int total)
void setLabelingEngine(QgsLabelingEngineInterface *iface)
Added in QGIS v1.4.
double mScale
Map scale denominator at its current zoom level.
QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo
static QgsProject * instance()
access to canonical QgsProject instance
Class for storing a coordinate reference system (CRS)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
void setMapToPixel(const QgsMapToPixel &mtp)
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
UnitType
Map units that qgis supports.
const QgsMapToPixel & mapToPixel() const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double ymax)
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
void updateScale()
Recalculate the map scale.
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode Added in 1.9.
void setRasterScaleFactor(double factor)
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 QgsLayerCoordinateTrans...
Custom exception class for Coordinate Reference System related exceptions.
double mMapUnitsPerPixel
map units per pixel
Labeling engine interface.
QgsRenderContext mRenderContext
Encapsulates context of rendering.
double width() const
Width of the rectangle.
void setMapUnitsPerPixel(double mapUnitsPerPixel)
virtual QgsRectangle extent()
Return the extent of the layer.
QGis::UnitType mapUnits() const
Represents a vector layer which manages a vector based data sets.
QgsLabelingEngineInterface * mLabelingEngine
Labeling engine (NULL by default)
bool geographicFlag() const
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
bool readXML(QDomNode &theNode)
read settings
double xMinimum() const
Get the x minimum value (left side of rectangle)
QStringList & layerSet()
returns current layer set
QgsRectangle mFullExtent
full extent of the layer set
void setXMinimum(double x)
Set the minimum x value.
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
QgsRectangle layerExtentToOutputExtent(QgsMapLayer *theLayer, QgsRectangle extent)
transform bounding box from layer's CRS to output CRS
double height() const
Height of the rectangle.
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
QString toProj4() const
Get the Proj Proj4 string representation of this srs.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)