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 =
nullptr;
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 =
nullptr;
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 )
741 static const double splitCoord = 180.0;
754 ll = transform->
transform( ll.x(), ll.y(),
756 ur = transform->
transform( ur.x(), ur.y(),
761 if ( ll.x() > ur.x() )
781 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
782 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
949 QgsDebugMsg(
QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( layerId ) );
984 const double padFactor = 1e-8;
1020 tmpSettings.
readXML( theNode );
1024 if ( !layerCoordTransformInfoElem.
isNull() )
1028 for (
int i = 0; i < layerCoordinateTransformList.
size(); ++i )
1030 layerCoordTransformElem = layerCoordinateTransformList.
at( i ).
toElement();
1066 tmpSettings.
writeXML( theNode, theDoc );
1074 layerCoordTransformElem.
setAttribute(
"srcAuthId", coordIt->srcAuthId );
1075 layerCoordTransformElem.
setAttribute(
"destAuthId", coordIt->destAuthId );
1078 layerCoordTransformInfo.
appendChild( layerCoordTransformElem );
1106 && ctIt->srcAuthId == layer->
crs().
authid()
1119 || ctIt->srcAuthId == layer->
crs().
authid()
1133 switch ( blendMode )
1136 return QPainter::CompositionMode_SourceOver;
1138 return QPainter::CompositionMode_Lighten;
1140 return QPainter::CompositionMode_Screen;
1142 return QPainter::CompositionMode_ColorDodge;
1144 return QPainter::CompositionMode_Plus;
1146 return QPainter::CompositionMode_Darken;
1148 return QPainter::CompositionMode_Multiply;
1150 return QPainter::CompositionMode_ColorBurn;
1152 return QPainter::CompositionMode_Overlay;
1154 return QPainter::CompositionMode_SoftLight;
1156 return QPainter::CompositionMode_HardLight;
1158 return QPainter::CompositionMode_Difference;
1160 return QPainter::CompositionMode_Exclusion;
1162 return QPainter::CompositionMode_Source;
1164 return QPainter::CompositionMode_DestinationOver;
1166 return QPainter::CompositionMode_Clear;
1168 return QPainter::CompositionMode_Destination;
1170 return QPainter::CompositionMode_SourceIn;
1172 return QPainter::CompositionMode_DestinationIn;
1174 return QPainter::CompositionMode_SourceOut;
1176 return QPainter::CompositionMode_DestinationOut;
1178 return QPainter::CompositionMode_SourceAtop;
1180 return QPainter::CompositionMode_DestinationAtop;
1182 return QPainter::CompositionMode_Xor;
1185 return QPainter::CompositionMode_SourceOver;
1192 switch ( blendMode )
1194 case QPainter::CompositionMode_SourceOver:
1196 case QPainter::CompositionMode_Lighten:
1198 case QPainter::CompositionMode_Screen:
1200 case QPainter::CompositionMode_ColorDodge:
1202 case QPainter::CompositionMode_Plus:
1204 case QPainter::CompositionMode_Darken:
1206 case QPainter::CompositionMode_Multiply:
1208 case QPainter::CompositionMode_ColorBurn:
1210 case QPainter::CompositionMode_Overlay:
1212 case QPainter::CompositionMode_SoftLight:
1214 case QPainter::CompositionMode_HardLight:
1216 case QPainter::CompositionMode_Difference:
1218 case QPainter::CompositionMode_Exclusion:
1220 case QPainter::CompositionMode_Source:
1222 case QPainter::CompositionMode_DestinationOver:
1224 case QPainter::CompositionMode_Clear:
1226 case QPainter::CompositionMode_Destination:
1228 case QPainter::CompositionMode_SourceIn:
1230 case QPainter::CompositionMode_DestinationIn:
1232 case QPainter::CompositionMode_SourceOut:
1234 case QPainter::CompositionMode_DestinationOut:
1236 case QPainter::CompositionMode_SourceAtop:
1238 case QPainter::CompositionMode_DestinationAtop:
1240 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()
double rendererScale() const
void setLabelingEngine(QgsLabelingEngineInterface *iface)
Set labeling engine.
iterator insert(const Key &key, const T &value)
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
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)
QgsScaleCalculator * mScaleCalculator
scale calculator
void scale(qreal sx, qreal sy)
void addLayerCoordinateTransform(const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
const QgsCoordinateTransform * transformation(const QgsMapLayer *layer) const
void setRendererScale(double scale)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
#define Q_NOWARN_DEPRECATED_PUSH
void drawingProgress(int current, int total)
static QgsMapRenderer::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
QString toProj4() const
Returns a Proj4 string representation of this CRS.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
~QgsMapRenderer()
destructor
bool renderingStopped() const
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
Get units of map's geographical coordinates - used for scale calculation.
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
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)
QgsMapLayer::LayerType type() const
Get the type of the layer.
QString tr(const char *sourceText, const char *disambiguation, int n)
void setExtent(const QgsRectangle &extent)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
QgsRectangle mExtent
current extent to be drawn
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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.
QDomElement toElement() const
double mRotation
Map rotation.
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...
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
QMutex mRenderMutex
Locks rendering loop for concurrent draws.
Perform transforms between map coordinates and device coordinates.
float maximumScale() const
Returns the maximum scale denominator at which the layer is visible.
void setSelectionColor(const QColor &color)
QString number(int n, int base)
int count(const T &value) const
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
void extentsChanged()
emitted when the current extent gets changed
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
void setOutputSize(QSize size)
Set the size of the resulting map image.
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
void setScaleFactor(double factor)
QgsDistanceArea * mDistArea
tool for measuring
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
void adjustExtentToSize()
adjust extent to fit the pixmap size
const_iterator constEnd() const
void fill(uint pixelValue)
void hasCrsTransformEnabledChanged(bool flag)
This signal is emitted when CRS transformation is enabled/disabled.
#define QgsDebugMsgLevel(str, level)
bool isEmpty() const
test if rectangle is empty.
void setAttribute(const QString &name, const QString &value)
void setMapUnits(QGis::UnitType u)
Set units of map's geographical coordinates - used for scale calculation.
double width() const
Width of the rectangle.
int toInt(bool *ok, int base) const
QString qgsDoubleToString(double a, int precision=17)
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.
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QPaintDevice * device() const
void destinationSrsChanged()
void setPainter(QPainter *p)
Reads and writes project states.
bool mOverview
indicates whether it's map image for overview
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int layerTransparency() const
Returns the current transparency for the vector layer.
void setOutputSize(QSize size, int dpi)
double mapUnitsPerPixel() const
Return current map units per pixel.
static QPainter::CompositionMode getCompositionMode(BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
A class to represent a point.
QgsRectangle extent() const
returns current extent
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
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
bool isFinite() const
Returns true if the rectangle has finite boundaries.
void setRotation(double degrees)
sets rotation value in clockwise degrees
QGis::UnitType mapUnits() const
Returns current map units.
iterator find(const Key &key)
double dpi()
Accessor for dpi used in scale calculations.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc)
write settings
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
double xMaximum() const
Get the x maximum value (right side of rectangle)
#define Q_NOWARN_DEPRECATED_POP
General purpose distance and area calculator.
QgsRectangle fullExtent()
returns current extent of layer set
QGis::UnitType mapUnits() const
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
QString name() const
Get the display name of the layer.
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)
const QgsMapToPixel & mapToPixel() const
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
virtual void drawLabeling(QgsRenderContext &context)=0
called when the map is drawn and labels should be placed
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
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
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)
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
UnitType
Map units that qgis supports.
double xMinimum() const
Get the x minimum value (left side of rectangle)
double yMaximum() const
Get the y maximum value (top side of rectangle)
void updateScale()
Recalculate the map scale.
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
void setRasterScaleFactor(double factor)
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
Custom exception class for Coordinate Reference System related exceptions.
double mMapUnitsPerPixel
map units per pixel
Labeling engine interface.
double rasterScaleFactor() const
QgsRenderContext mRenderContext
Encapsulates context of rendering.
QDomElement createElement(const QString &tagName)
long srsid() const
Returns the SrsId, if available.
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.
double scaleFactor() const
Represents a vector layer which manages a vector based data sets.
QgsLabelingEngineInterface * mLabelingEngine
Labeling engine (nullptr by default)
bool readXML(QDomNode &theNode)
read settings
QStringList & layerSet()
returns current layer set
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void render(QPainter *painter, double *forceWidthScale=nullptr)
starts rendering
QgsRectangle mFullExtent
full extent of the layer set
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
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
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
double rotation() const
returns current rotation in clockwise degrees
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
bool geographicFlag() const
Returns whether the CRS is a geographic CRS.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)