2013-12-05 18:27:45 +07:00
|
|
|
|
|
|
|
class QgsMapSettings
|
|
|
|
{
|
|
|
|
%TypeHeaderCode
|
|
|
|
#include <qgsmapsettings.h>
|
|
|
|
%End
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
public:
|
|
|
|
QgsMapSettings();
|
|
|
|
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Return geographical coordinates of the rectangle that should be rendered.
|
|
|
|
//! The actual visible extent used for rendering could be slightly different
|
|
|
|
//! since the given extent may be expanded in order to fit the aspect ratio
|
|
|
|
//! of output size. Use visibleExtent() to get the resulting extent.
|
2014-05-27 23:22:50 +02:00
|
|
|
QgsRectangle extent() const;
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Set coordinates of the rectangle which should be rendered.
|
|
|
|
//! The actual visible extent used for rendering could be slightly different
|
|
|
|
//! since the given extent may be expanded in order to fit the aspect ratio
|
|
|
|
//! of output size. Use visibleExtent() to get the resulting extent.
|
2014-05-27 23:22:50 +02:00
|
|
|
void setExtent( const QgsRectangle& rect );
|
|
|
|
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Return the size of the resulting map image
|
2014-05-27 23:22:50 +02:00
|
|
|
QSize outputSize() const;
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Set the size of the resulting map image
|
2014-05-27 23:22:50 +02:00
|
|
|
void setOutputSize( const QSize& size );
|
|
|
|
|
2014-12-09 09:53:56 +01:00
|
|
|
//! Return the rotation of the resulting map image
|
|
|
|
//! Units are clockwise degrees
|
|
|
|
//! @note added in 2.8
|
|
|
|
double rotation() const;
|
|
|
|
//! Set the rotation of the resulting map image
|
|
|
|
//! Units are clockwise degrees
|
|
|
|
//! @note added in 2.8
|
|
|
|
void setRotation( double degrees );
|
|
|
|
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Return DPI used for conversion between real world units (e.g. mm) and pixels
|
|
|
|
//! Default value is 96
|
2014-05-27 23:22:50 +02:00
|
|
|
int outputDpi() const;
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
|
2014-05-27 23:22:50 +02:00
|
|
|
void setOutputDpi( int dpi );
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Get list of layer IDs for map rendering
|
|
|
|
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
2014-05-27 23:22:50 +02:00
|
|
|
QStringList layers() const;
|
2014-06-21 23:48:52 +07:00
|
|
|
//! Set list of layer IDs for map rendering. The layers must be registered in QgsMapLayerRegistry.
|
|
|
|
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
|
2014-05-27 23:22:50 +02:00
|
|
|
void setLayers( const QStringList& layers );
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2015-01-09 21:41:50 +07:00
|
|
|
//! Get map of map layer style overrides (key: layer ID, value: style name) where a different style should be used instead of the current one
|
|
|
|
//! @note added in 2.8
|
|
|
|
QMap<QString, QString> layerStyleOverrides() const;
|
|
|
|
//! Set map of map layer style overrides (key: layer ID, value: style name) where a different style should be used instead of the current one
|
|
|
|
//! @note added in 2.8
|
|
|
|
void setLayerStyleOverrides( const QMap<QString, QString>& overrides );
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
//! sets whether to use projections for this layer set
|
|
|
|
void setCrsTransformEnabled( bool enabled );
|
|
|
|
//! returns true if projections are enabled for this layer set
|
|
|
|
bool hasCrsTransformEnabled() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
//! sets destination coordinate reference system
|
|
|
|
void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
|
|
|
|
//! returns CRS of destination coordinate reference system
|
|
|
|
const QgsCoordinateReferenceSystem& destinationCrs() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Get units of map's geographical coordinates - used for scale calculation
|
2014-05-27 23:22:50 +02:00
|
|
|
QGis::UnitType mapUnits() const;
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Set units of map's geographical coordinates - used for scale calculation
|
2014-05-27 23:22:50 +02:00
|
|
|
void setMapUnits( QGis::UnitType u );
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Set the background color of the map
|
2014-05-27 23:22:50 +02:00
|
|
|
void setBackgroundColor( const QColor& color );
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Get the background color of the map
|
2014-05-27 23:22:50 +02:00
|
|
|
QColor backgroundColor() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Set color that is used for drawing of selected vector features
|
2014-05-27 23:22:50 +02:00
|
|
|
void setSelectionColor( const QColor& color );
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Get color that is used for drawing of selected vector features
|
2014-05-27 23:22:50 +02:00
|
|
|
QColor selectionColor() const;
|
2014-06-02 21:00:51 +02:00
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Enumeration of flags that adjust the way how map is rendered
|
2014-05-27 23:22:50 +02:00
|
|
|
enum Flag
|
|
|
|
{
|
2014-06-22 00:15:37 +07:00
|
|
|
Antialiasing, //!< Enable anti-aliasin for map rendering
|
|
|
|
DrawEditingInfo, //!< Enable drawing of vertex markers for layers in editing mode
|
|
|
|
ForceVectorOutput, //!< Vector graphics should not be cached and drawn as raster images
|
|
|
|
UseAdvancedEffects, //!< Enable layer transparency and blending effects
|
|
|
|
DrawLabeling, //!< Enable drawing of labels on top of the map
|
|
|
|
UseRenderingOptimization, //!< Enable vector simplification and other rendering optimizations
|
2014-06-22 00:58:16 +07:00
|
|
|
DrawSelection, //!< Whether vector selections should be shown in the rendered map
|
2015-11-20 19:16:15 +11:00
|
|
|
DrawSymbolBounds, //!< Draw bounds of symbols (for debugging/testing)
|
2014-05-27 23:22:50 +02:00
|
|
|
// TODO: ignore scale-based visibility (overview)
|
|
|
|
};
|
|
|
|
typedef QFlags<QgsMapSettings::Flag> Flags;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Set combination of flags that will be used for rendering
|
2015-10-07 11:55:34 +11:00
|
|
|
void setFlags( const Flags& flags );
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Enable or disable a particular flag (other flags are not affected)
|
2014-05-27 23:22:50 +02:00
|
|
|
void setFlag( Flag flag, bool on = true );
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Return combination of flags used for rendering
|
2014-05-27 23:22:50 +02:00
|
|
|
Flags flags() const;
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Check whether a particular flag is enabled
|
2014-05-27 23:22:50 +02:00
|
|
|
bool testFlag( Flag flag ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-03-31 21:51:21 -06:00
|
|
|
//! sets format of internal QImage
|
|
|
|
void setOutputImageFormat( QImage::Format format );
|
|
|
|
//! format of internal QImage, default QImage::Format_ARGB32_Premultiplied
|
|
|
|
QImage::Format outputImageFormat() const;
|
|
|
|
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Check whether the map settings are valid and can be used for rendering
|
2014-05-27 23:22:50 +02:00
|
|
|
bool hasValidSettings() const;
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Return the actual extent derived from requested extent that takes takes output image size into account
|
2014-05-27 23:22:50 +02:00
|
|
|
QgsRectangle visibleExtent() const;
|
2015-02-07 15:05:00 +01:00
|
|
|
//! Return the visible area as a polygon (may be rotated)
|
|
|
|
//! @note added in 2.8
|
|
|
|
QPolygonF visiblePolygon() const;
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Return the distance in geographical coordinates that equals to one pixel in the map
|
2014-05-27 23:22:50 +02:00
|
|
|
double mapUnitsPerPixel() const;
|
2014-06-22 00:15:37 +07:00
|
|
|
//! Return the calculated scale of the map
|
2014-05-27 23:22:50 +02:00
|
|
|
double scale() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2015-08-13 10:10:26 +10:00
|
|
|
/** Sets the expression context. This context is used for all expression evaluation
|
|
|
|
* associated with this map settings.
|
|
|
|
* @see expressionContext()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
void setExpressionContext( const QgsExpressionContext& context );
|
|
|
|
|
|
|
|
/** Gets the expression context. This context should be used for all expression evaluation
|
|
|
|
* associated with this map settings.
|
|
|
|
* @see setExpressionContext()
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
|
|
|
const QgsExpressionContext& expressionContext() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
// -- utility functions --
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-05 20:23:34 +07:00
|
|
|
//const QgsDatumTransformStore& datumTransformStore() const;
|
|
|
|
QgsDatumTransformStore& datumTransformStore();
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
const QgsMapToPixel& mapToPixel() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2015-09-12 23:04:17 +02:00
|
|
|
/** Computes an *estimated* conversion factor between layer and map units: layerUnits * layerToMapUnits = mapUnits
|
|
|
|
* @param theLayer The layer
|
|
|
|
* @param referenceExtent A reference extent based on which to perform the computation. If not specified, the layer extent is used
|
|
|
|
* @note added in QGIS 2.12
|
|
|
|
*/
|
2015-09-09 17:45:31 +02:00
|
|
|
double layerToMapUnits( QgsMapLayer* theLayer, const QgsRectangle& referenceExtent = QgsRectangle() ) const;
|
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform bounding box from layer's CRS to output CRS
|
|
|
|
* @see layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) if you want to transform a rectangle
|
|
|
|
* @return a bounding box (aligned rectangle) containing the transformed extent
|
|
|
|
*/
|
|
|
|
QgsRectangle layerExtentToOutputExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform bounding box from output CRS to layer's CRS
|
|
|
|
* @see mapToLayerCoordinates( QgsMapLayer* theLayer,QgsRectangle rect ) if you want to transform a rectangle
|
|
|
|
* @return a bounding box (aligned rectangle) containing the transformed extent
|
|
|
|
*/
|
|
|
|
QgsRectangle outputExtentToLayerExtent( QgsMapLayer* theLayer, QgsRectangle extent ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform point coordinates from layer's CRS to output CRS
|
|
|
|
* @return the transformed point
|
|
|
|
*/
|
|
|
|
QgsPoint layerToMapCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform rectangle from layer's CRS to output CRS
|
|
|
|
* @see layerExtentToOutputExtent() if you want to transform a bounding box
|
|
|
|
* @return the transformed rectangle
|
|
|
|
*/
|
|
|
|
QgsRectangle layerToMapCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform point coordinates from output CRS to layer's CRS
|
|
|
|
* @return the transformed point
|
|
|
|
*/
|
|
|
|
QgsPoint mapToLayerCoordinates( QgsMapLayer* theLayer, QgsPoint point ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/**
|
|
|
|
* @brief transform rectangle from output CRS to layer's CRS
|
|
|
|
* @see outputExtentToLayerExtent() if you want to transform a bounding box
|
|
|
|
* @return the transformed rectangle
|
|
|
|
*/
|
|
|
|
QgsRectangle mapToLayerCoordinates( QgsMapLayer* theLayer, QgsRectangle rect ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-06-05 20:23:34 +07:00
|
|
|
/**
|
|
|
|
* @brief Return coordinate transform from layer's CRS to destination CRS
|
|
|
|
* @param layer
|
|
|
|
* @return transform - may be null if the transform is not needed
|
|
|
|
*/
|
2014-11-20 14:17:51 +01:00
|
|
|
const QgsCoordinateTransform* layerTransform( QgsMapLayer *layer ) const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
//! returns current extent of layer set
|
|
|
|
QgsRectangle fullExtent() const;
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
/* serialization */
|
2013-12-05 18:27:45 +07:00
|
|
|
|
2014-05-27 23:22:50 +02:00
|
|
|
void readXML( QDomNode& theNode );
|
|
|
|
|
|
|
|
void writeXML( QDomNode& theNode, QDomDocument& theDoc );
|
2013-12-05 18:27:45 +07:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QFlags<QgsMapSettings::Flag> operator|(QgsMapSettings::Flag f1, QFlags<QgsMapSettings::Flag> f2);
|