33 #include <QDomDocument> 35 #include <QMutexLocker> 37 #include <QListIterator> 40 #include <QCoreApplication> 64 readDefaultDatumTransformations();
103 if ( extent.
width() > 0 &&
105 extent.
width() < 1 &&
110 double xMean = ( qAbs( extent.
xMinimum() ) + qAbs( extent.
xMaximum() ) ) * 0.5;
111 double yMean = ( qAbs( extent.
yMinimum() ) + qAbs( extent.
yMaximum() ) ) * 0.5;
113 double xRange = extent.
width() / xMean;
114 double yRange = extent.
height() / yMean;
116 static const double minProportion = 1e-12;
117 if ( xRange < minProportion || yRange < minProportion )
179 if ( !myWidth || !myHeight )
190 mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
193 double dxmin, dxmax, dymin, dymax, whitespace;
195 if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
260 if ( !thePaintDevice )
299 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
300 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
301 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
302 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
309 double scaleFactor = 1.0;
312 if ( forceWidthScale )
314 scaleFactor = *forceWidthScale;
318 scaleFactor = sceneDpi / 25.4;
321 double rasterScaleFactor = ( thePaintDevice->
logicalDpiX() + thePaintDevice->
logicalDpiY() ) / 2.0 / sceneDpi;
363 QImage * mypFlattenedImage =
nullptr;
367 QgsDebugMsg(
"Rendering at layer item " + layerId );
375 QgsDebugMsg(
"If there is a QPaintEngine error here, it is caused by an emit call" );
386 QgsDebugMsg(
QString(
"layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
435 bool scaleRaster =
false;
450 bool flattenedLayer =
false;
454 if ((( vl->
blendMode() != QPainter::CompositionMode_SourceOver )
458 flattenedLayer =
true;
461 if ( mypFlattenedImage->
isNull() )
468 mypFlattenedImage->
fill( 0 );
470 if ( mySettings.
value(
"/qgis/enable_anti_aliasing",
true ).
toBool() )
474 mypPainter->
scale( rasterScaleFactor, rasterScaleFactor );
544 if ( flattenedLayer )
549 mypContextPainter->
save();
550 mypContextPainter->
scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
551 mypContextPainter->
drawImage( 0, 0, *( mypFlattenedImage ) );
553 delete mypFlattenedImage;
554 mypFlattenedImage =
nullptr;
561 QgsDebugMsg(
"Layer not rendered because it is not within the defined " 562 "visibility scale range" );
665 QgsDebugMsg(
"Adjusting DistArea projection on/off" );
689 if ( refreshCoordinateTransformInfo )
747 static const double splitCoord = 180.0;
760 ll = transform->
transform( ll.x(), ll.y(),
762 ur = transform->
transform( ur.x(), ur.y(),
767 if ( ll.x() > ur.x() )
787 extent =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
788 r2 =
QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
959 QgsDebugMsg(
QString(
"WARNING: layer '%1' not found in map layer registry!" ).arg( layerId ) );
994 const double padFactor = 1e-8;
1025 tmpSettings.
readXML( theNode );
1029 if ( !layerCoordTransformInfoElem.
isNull() )
1033 for (
int i = 0; i < layerCoordinateTransformList.
size(); ++i )
1035 layerCoordTransformElem = layerCoordinateTransformList.
at( i ).
toElement();
1071 tmpSettings.
writeXML( theNode, theDoc );
1079 layerCoordTransformElem.
setAttribute(
"srcAuthId", coordIt->srcAuthId );
1080 layerCoordTransformElem.
setAttribute(
"destAuthId", coordIt->destAuthId );
1083 layerCoordTransformInfo.
appendChild( layerCoordTransformElem );
1111 && ctIt->srcAuthId == layer->
crs().
authid()
1130 || ctIt->srcAuthId == layer->
crs().
authid()
1144 switch ( blendMode )
1147 return QPainter::CompositionMode_SourceOver;
1149 return QPainter::CompositionMode_Lighten;
1151 return QPainter::CompositionMode_Screen;
1153 return QPainter::CompositionMode_ColorDodge;
1155 return QPainter::CompositionMode_Plus;
1157 return QPainter::CompositionMode_Darken;
1159 return QPainter::CompositionMode_Multiply;
1161 return QPainter::CompositionMode_ColorBurn;
1163 return QPainter::CompositionMode_Overlay;
1165 return QPainter::CompositionMode_SoftLight;
1167 return QPainter::CompositionMode_HardLight;
1169 return QPainter::CompositionMode_Difference;
1171 return QPainter::CompositionMode_Exclusion;
1173 return QPainter::CompositionMode_Source;
1175 return QPainter::CompositionMode_DestinationOver;
1177 return QPainter::CompositionMode_Clear;
1179 return QPainter::CompositionMode_Destination;
1181 return QPainter::CompositionMode_SourceIn;
1183 return QPainter::CompositionMode_DestinationIn;
1185 return QPainter::CompositionMode_SourceOut;
1187 return QPainter::CompositionMode_DestinationOut;
1189 return QPainter::CompositionMode_SourceAtop;
1191 return QPainter::CompositionMode_DestinationAtop;
1193 return QPainter::CompositionMode_Xor;
1196 return QPainter::CompositionMode_SourceOver;
1203 switch ( blendMode )
1205 case QPainter::CompositionMode_SourceOver:
1207 case QPainter::CompositionMode_Lighten:
1209 case QPainter::CompositionMode_Screen:
1211 case QPainter::CompositionMode_ColorDodge:
1213 case QPainter::CompositionMode_Plus:
1215 case QPainter::CompositionMode_Darken:
1217 case QPainter::CompositionMode_Multiply:
1219 case QPainter::CompositionMode_ColorBurn:
1221 case QPainter::CompositionMode_Overlay:
1223 case QPainter::CompositionMode_SoftLight:
1225 case QPainter::CompositionMode_HardLight:
1227 case QPainter::CompositionMode_Difference:
1229 case QPainter::CompositionMode_Exclusion:
1231 case QPainter::CompositionMode_Source:
1233 case QPainter::CompositionMode_DestinationOver:
1235 case QPainter::CompositionMode_Clear:
1237 case QPainter::CompositionMode_Destination:
1239 case QPainter::CompositionMode_SourceIn:
1241 case QPainter::CompositionMode_DestinationIn:
1243 case QPainter::CompositionMode_SourceOut:
1245 case QPainter::CompositionMode_DestinationOut:
1247 case QPainter::CompositionMode_SourceAtop:
1249 case QPainter::CompositionMode_DestinationAtop:
1251 case QPainter::CompositionMode_Xor:
1274 int myRed = prj->
readNumEntry(
"Gui",
"/SelectionColorRedPart", 255 );
1275 int myGreen = prj->
readNumEntry(
"Gui",
"/SelectionColorGreenPart", 255 );
1276 int myBlue = prj->
readNumEntry(
"Gui",
"/SelectionColorBluePart", 0 );
1277 int myAlpha = prj->
readNumEntry(
"Gui",
"/SelectionColorAlphaPart", 255 );
1298 void QgsMapRenderer::readDefaultDatumTransformations()
1300 const char* envChar = getenv(
"DEFAULT_DATUM_TRANSFORM" );
1305 for (
int i = 0; i < transformSplit.
size(); ++i )
1307 QStringList slashSplit = transformSplit.
at( i ).split(
"/" );
1308 if ( slashSplit.
size() < 4 )
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 setExtent(const QgsRectangle &rect, bool magnified=true)
Set coordinates of the rectangle which should be rendered.
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.
QSizeF outputSizeF() const
Returns the size which the map will be rendered at.
QString attribute(const QString &name, const QString &defValue) const
bool mProjectionsEnabled
detemines whether on the fly projection support is enabled
QgsMapLayer * mapLayer(const QString &theLayerId) const
Retrieve a pointer to a registered layer by layer ID.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
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 T & at(int i) const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
void setOutputDpi(double dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
#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.
bool isInScaleRange(double scale) const
Tests whether the layer should be visible at the specified scale.
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
QHash< QPair< QString, QString >, QPair< int, int > > mDefaultDatumTransformations
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)
Compare two doubles (but allow some difference)
QSize outputSize() const
Returns the size which the map will be rendered at.
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
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.
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.
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.
bool mTileRenderMode
Tell the render system we are rendering a map tile.
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)
Returns a string representation of a double.
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.
double minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
double mapUnitsPerPixel() const
Return current map units per pixel.
double maximumScale() const
Returns the maximum scale denominator at which the layer is visible.
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 various methods to retrieve match...
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.
const T value(const Key &key) const
void setOutputSize(QSize size, double dpi)
Sets the desired size of the rendered map image.
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
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
void setSelectionColor(const QColor &color)
Set color that is used for drawing of selected vector features.
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()
Returns the QgsProject singleton instance.
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
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)
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
double yMaximum() const
Get the y maximum value (top side of rectangle)
QString name
Read property of QString layerName.
void updateScale()
Recalculate the map scale.
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
void setRasterScaleFactor(double factor)
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.
Draw map such that there are no problems between adjacent tiles.
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
static QgsCRSCache * instance()
Returns a pointer to the QgsCRSCache singleton.
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)