33 #include <QDomDocument> 35 #include <QMutexLocker> 37 #include <QListIterator> 40 #include <QCoreApplication> 55 mSize = QSize( 0, 0 );
99 if ( extent.
width() > 0 &&
101 extent.
width() < 1 &&
106 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
107 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
109 double xRange = extent.
width() / xMean;
110 double yRange = extent.
height() / yMean;
112 static const double minProportion = 1e-12;
113 if ( xRange < minProportion || yRange < minProportion )
141 mSize = QSizeF( size.width(), size.height() );
160 return mSize.toSize();
170 double myHeight =
mSize.height();
171 double myWidth =
mSize.width();
175 if ( !myWidth || !myHeight )
186 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
189 double dxmin, dxmax, dymin, dymax, whitespace;
191 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
247 if (
mSize.width() == 1 &&
mSize.height() == 1 )
253 QPaintDevice* thePaintDevice = painter->device();
254 if ( !thePaintDevice )
263 QCoreApplication::processEvents();
293 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
294 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
295 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
296 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
303 double scaleFactor = 1.0;
306 if ( forceWidthScale )
308 scaleFactor = *forceWidthScale;
312 scaleFactor = sceneDpi / 25.4;
315 double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
344 while ( li.hasPrevious() )
355 QImage * mypFlattenedImage = 0;
357 QString layerId = li.previous();
359 QgsDebugMsg(
"Rendering at layer item " + layerId );
367 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
378 QgsDebugMsg( QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
391 mypContextPainter->setCompositionMode( ml->
blendMode() );
427 bool scaleRaster =
false;
436 QSettings mySettings;
442 bool flattenedLayer =
false;
446 if ((( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
450 flattenedLayer =
true;
453 if ( mypFlattenedImage->isNull() )
460 mypFlattenedImage->fill( 0 );
461 QPainter * mypPainter =
new QPainter( mypFlattenedImage );
462 if ( mySettings.value(
"/qgis/enable_anti_aliasing",
true ).toBool() )
464 mypPainter->setRenderHint( QPainter::Antialiasing );
466 mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
526 QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->
layerTransparency() / 100 ) );
534 if ( flattenedLayer )
539 mypContextPainter->save();
540 mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
541 mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
542 mypContextPainter->restore();
543 delete mypFlattenedImage;
544 mypFlattenedImage = 0;
551 QgsDebugMsg(
"Layer not rendered because it is not within the defined " 552 "visibility scale range" );
566 while ( li.hasPrevious() )
573 QString layerId = li.previous();
624 QgsDebugMsg(
"Rendering completed in (seconds): " + QString(
"%1" ).arg( renderTime.elapsed() / 1000.0 ) );
655 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
679 if ( refreshCoordinateTransformInfo )
693 QgsDebugMsg( QString(
"Transform error caught: %1" ).arg( e.
what() ) );
736 static const double splitCoord = 180.0;
749 ll = transform->
transform( ll.x(), ll.y(),
751 ur = transform->
transform( ur.x(), ur.y(),
756 if ( ll.x() > ur.x() )
776 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
777 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
938 QStringList::iterator it =
mLayerSet.begin();
945 QgsDebugMsg( QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
982 const double padFactor = 1e-8;
1004 QgsDebugMsg( QString(
"Entering: %1" ).arg( layers.join(
", " ) ) );
1018 tmpSettings.
readXML( theNode );
1021 QDomElement layerCoordTransformInfoElem = theNode.firstChildElement(
"layer_coordinate_transform_info" );
1022 if ( !layerCoordTransformInfoElem.isNull() )
1024 QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName(
"layer_coordinate_transform" );
1025 QDomElement layerCoordTransformElem;
1026 for (
int i = 0; i < layerCoordinateTransformList.size(); ++i )
1028 layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1029 QString layerId = layerCoordTransformElem.attribute(
"layerid" );
1030 if ( layerId.isEmpty() )
1036 lct.
srcAuthId = layerCoordTransformElem.attribute(
"srcAuthId" );
1037 lct.
destAuthId = layerCoordTransformElem.attribute(
"destAuthId" );
1038 lct.
srcDatumTransform = layerCoordTransformElem.attribute(
"srcDatumTransform",
"-1" ).toInt();
1039 lct.
destDatumTransform = layerCoordTransformElem.attribute(
"destDatumTransform",
"-1" ).toInt();
1064 tmpSettings.
writeXML( theNode, theDoc );
1066 QDomElement layerCoordTransformInfo = theDoc.createElement(
"layer_coordinate_transform_info" );
1070 QDomElement layerCoordTransformElem = theDoc.createElement(
"layer_coordinate_transform" );
1071 layerCoordTransformElem.setAttribute(
"layerid", coordIt.key() );
1072 layerCoordTransformElem.setAttribute(
"srcAuthId", coordIt->srcAuthId );
1073 layerCoordTransformElem.setAttribute(
"destAuthId", coordIt->destAuthId );
1074 layerCoordTransformElem.setAttribute(
"srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1075 layerCoordTransformElem.setAttribute(
"destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1076 layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1078 theNode.appendChild( layerCoordTransformInfo );
1104 && ctIt->srcAuthId == layer->
crs().
authid()
1117 || ctIt->srcAuthId == layer->
crs().
authid()
1131 switch ( blendMode )
1134 return QPainter::CompositionMode_SourceOver;
1136 return QPainter::CompositionMode_Lighten;
1138 return QPainter::CompositionMode_Screen;
1140 return QPainter::CompositionMode_ColorDodge;
1142 return QPainter::CompositionMode_Plus;
1144 return QPainter::CompositionMode_Darken;
1146 return QPainter::CompositionMode_Multiply;
1148 return QPainter::CompositionMode_ColorBurn;
1150 return QPainter::CompositionMode_Overlay;
1152 return QPainter::CompositionMode_SoftLight;
1154 return QPainter::CompositionMode_HardLight;
1156 return QPainter::CompositionMode_Difference;
1158 return QPainter::CompositionMode_Exclusion;
1160 return QPainter::CompositionMode_Source;
1162 return QPainter::CompositionMode_DestinationOver;
1164 return QPainter::CompositionMode_Clear;
1166 return QPainter::CompositionMode_Destination;
1168 return QPainter::CompositionMode_SourceIn;
1170 return QPainter::CompositionMode_DestinationIn;
1172 return QPainter::CompositionMode_SourceOut;
1174 return QPainter::CompositionMode_DestinationOut;
1176 return QPainter::CompositionMode_SourceAtop;
1178 return QPainter::CompositionMode_DestinationAtop;
1180 return QPainter::CompositionMode_Xor;
1182 QgsDebugMsg( QString(
"Blend mode %1 mapped to SourceOver" ).arg( blendMode ) );
1183 return QPainter::CompositionMode_SourceOver;
1190 switch ( blendMode )
1192 case QPainter::CompositionMode_SourceOver:
1194 case QPainter::CompositionMode_Lighten:
1196 case QPainter::CompositionMode_Screen:
1198 case QPainter::CompositionMode_ColorDodge:
1200 case QPainter::CompositionMode_Plus:
1202 case QPainter::CompositionMode_Darken:
1204 case QPainter::CompositionMode_Multiply:
1206 case QPainter::CompositionMode_ColorBurn:
1208 case QPainter::CompositionMode_Overlay:
1210 case QPainter::CompositionMode_SoftLight:
1212 case QPainter::CompositionMode_HardLight:
1214 case QPainter::CompositionMode_Difference:
1216 case QPainter::CompositionMode_Exclusion:
1218 case QPainter::CompositionMode_Source:
1220 case QPainter::CompositionMode_DestinationOver:
1222 case QPainter::CompositionMode_Clear:
1224 case QPainter::CompositionMode_Destination:
1226 case QPainter::CompositionMode_SourceIn:
1228 case QPainter::CompositionMode_DestinationIn:
1230 case QPainter::CompositionMode_SourceOut:
1232 case QPainter::CompositionMode_DestinationOut:
1234 case QPainter::CompositionMode_SourceAtop:
1236 case QPainter::CompositionMode_DestinationAtop:
1238 case QPainter::CompositionMode_Xor:
1241 QgsDebugMsg( QString(
"Composition mode %1 mapped to Normal" ).arg( blendMode ) );
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 rotationChanged(double)
emitted when the current rotation gets changed
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 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
void addLayerCoordinateTransform(const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
void setRendererScale(double scale)
static QgsMapLayerRegistry * instance()
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
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.
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
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
Q_DECL_DEPRECATED void setYMaximum(double yMax)
Set maximum y value.
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.
double mRotation
Map rotation.
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)
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
Returns whether scale based visibility is enabled for the layer.
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
Returns the maximum scale denominator at which the layer is visible.
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 rotation() const
returns current rotation in clockwise degrees
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.
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
void setRotation(double degrees)
sets rotation value in clockwise degrees
QString qgsDoubleToString(const double &a, const int &precision=17)
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.
#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...
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)
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.
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.
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)