33 #include <QDomDocument>
35 #include <QMutexLocker>
37 #include <QListIterator>
40 #include <QCoreApplication>
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 )
175 if ( !myWidth || !myHeight )
186 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
189 double dxmin, dxmax, dymin, dymax, whitespace;
191 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
256 if ( !thePaintDevice )
295 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
296 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
297 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
298 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
305 double scaleFactor = 1.0;
308 if ( forceWidthScale )
310 scaleFactor = *forceWidthScale;
314 scaleFactor = sceneDpi / 25.4;
317 double rasterScaleFactor = ( thePaintDevice->
logicalDpiX() + thePaintDevice->
logicalDpiY() ) / 2.0 / sceneDpi;
357 QImage * mypFlattenedImage = 0;
361 QgsDebugMsg(
"Rendering at layer item " + layerId );
369 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
380 QgsDebugMsg(
QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
429 bool scaleRaster =
false;
444 bool flattenedLayer =
false;
448 if ((( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
452 flattenedLayer =
true;
455 if ( mypFlattenedImage->
isNull() )
462 mypFlattenedImage->
fill( 0 );
464 if ( mySettings.
value(
"/qgis/enable_anti_aliasing",
true ).
toBool() )
468 mypPainter->
scale( rasterScaleFactor, rasterScaleFactor );
538 if ( flattenedLayer )
543 mypContextPainter->
save();
544 mypContextPainter->
scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
545 mypContextPainter->
drawImage( 0, 0, *( mypFlattenedImage ) );
547 delete mypFlattenedImage;
548 mypFlattenedImage = 0;
555 QgsDebugMsg(
"Layer not rendered because it is not within the defined "
556 "visibility scale range" );
659 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
683 if ( refreshCoordinateTransformInfo )
740 static const double splitCoord = 180.0;
753 ll = transform->
transform( ll.x(), ll.y(),
755 ur = transform->
transform( ur.x(), ur.y(),
760 if ( ll.x() > ur.x() )
780 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
781 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
949 QgsDebugMsg(
QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
986 const double padFactor = 1e-8;
1022 tmpSettings.
readXML( theNode );
1026 if ( !layerCoordTransformInfoElem.
isNull() )
1030 for (
int i = 0; i < layerCoordinateTransformList.
size(); ++i )
1032 layerCoordTransformElem = layerCoordinateTransformList.
at( i ).
toElement();
1068 tmpSettings.
writeXML( theNode, theDoc );
1076 layerCoordTransformElem.
setAttribute(
"srcAuthId", coordIt->srcAuthId );
1077 layerCoordTransformElem.
setAttribute(
"destAuthId", coordIt->destAuthId );
1080 layerCoordTransformInfo.
appendChild( layerCoordTransformElem );
1108 && ctIt->srcAuthId == layer->
crs().
authid()
1121 || ctIt->srcAuthId == layer->
crs().
authid()
1135 switch ( blendMode )
1138 return QPainter::CompositionMode_SourceOver;
1140 return QPainter::CompositionMode_Lighten;
1142 return QPainter::CompositionMode_Screen;
1144 return QPainter::CompositionMode_ColorDodge;
1146 return QPainter::CompositionMode_Plus;
1148 return QPainter::CompositionMode_Darken;
1150 return QPainter::CompositionMode_Multiply;
1152 return QPainter::CompositionMode_ColorBurn;
1154 return QPainter::CompositionMode_Overlay;
1156 return QPainter::CompositionMode_SoftLight;
1158 return QPainter::CompositionMode_HardLight;
1160 return QPainter::CompositionMode_Difference;
1162 return QPainter::CompositionMode_Exclusion;
1164 return QPainter::CompositionMode_Source;
1166 return QPainter::CompositionMode_DestinationOver;
1168 return QPainter::CompositionMode_Clear;
1170 return QPainter::CompositionMode_Destination;
1172 return QPainter::CompositionMode_SourceIn;
1174 return QPainter::CompositionMode_DestinationIn;
1176 return QPainter::CompositionMode_SourceOut;
1178 return QPainter::CompositionMode_DestinationOut;
1180 return QPainter::CompositionMode_SourceAtop;
1182 return QPainter::CompositionMode_DestinationAtop;
1184 return QPainter::CompositionMode_Xor;
1187 return QPainter::CompositionMode_SourceOver;
1194 switch ( blendMode )
1196 case QPainter::CompositionMode_SourceOver:
1198 case QPainter::CompositionMode_Lighten:
1200 case QPainter::CompositionMode_Screen:
1202 case QPainter::CompositionMode_ColorDodge:
1204 case QPainter::CompositionMode_Plus:
1206 case QPainter::CompositionMode_Darken:
1208 case QPainter::CompositionMode_Multiply:
1210 case QPainter::CompositionMode_ColorBurn:
1212 case QPainter::CompositionMode_Overlay:
1214 case QPainter::CompositionMode_SoftLight:
1216 case QPainter::CompositionMode_HardLight:
1218 case QPainter::CompositionMode_Difference:
1220 case QPainter::CompositionMode_Exclusion:
1222 case QPainter::CompositionMode_Source:
1224 case QPainter::CompositionMode_DestinationOver:
1226 case QPainter::CompositionMode_Clear:
1228 case QPainter::CompositionMode_Destination:
1230 case QPainter::CompositionMode_SourceIn:
1232 case QPainter::CompositionMode_DestinationIn:
1234 case QPainter::CompositionMode_SourceOut:
1236 case QPainter::CompositionMode_DestinationOut:
1238 case QPainter::CompositionMode_SourceAtop:
1240 case QPainter::CompositionMode_DestinationAtop:
1242 case QPainter::CompositionMode_Xor:
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
QDomNodeList elementsByTagName(const QString &tagname) const
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.
iterator insert(const Key &key, const T &value)
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.
const Key key(const T &value) const
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setCompositionMode(CompositionMode mode)
void drawError(QgsMapLayer *)
emitted when layer's draw() returned false
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void setXMaximum(double x)
Set the maximum x value.
void readXML(QDomNode &theNode)
OutputUnits mOutputUnits
Output units.
QString attribute(const QString &name, const QString &defValue) const
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 scale(qreal sx, qreal sy)
void addLayerCoordinateTransform(const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
void setRendererScale(double scale)
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)
Set parameters for use in transforming coordinates.
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...
QString join(const QString &separator) const
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
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
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.
QDomElement toElement() const
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)
QString number(int n, int base)
int count(const T &value) const
void extentsChanged()
emitted when the current extent gets changed
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
void setScaleFactor(double factor)
QgsDistanceArea * mDistArea
tool for measuring
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
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
const_iterator constEnd() const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
void fill(uint pixelValue)
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 setAttribute(const QString &name, const QString &value)
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
int toInt(bool *ok, int base) const
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.
QPaintDevice * device() const
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
iterator find(const Key &key)
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
Returns the current transparency for the vector 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
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
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.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
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
QDomElement firstChildElement(const QString &tagName) const
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.
QDomElement createElement(const QString &tagName)
double width() const
Width of the rectangle.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
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
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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
QDomNode at(int index) const
QString toProj4() const
Get the Proj Proj4 string representation of this srs.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)