QGIS/python/core/qgsmapsettings.sip

249 lines
11 KiB
Plaintext
Raw Normal View History

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.
2016-05-18 14:36:02 +02:00
void setExtent( const QgsRectangle& rect, bool magnified = true );
2014-05-27 23:22:50 +02:00
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
void setOutputSize( QSize size );
2014-05-27 23:22:50 +02: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
2016-05-28 17:22:22 +02:00
double outputDpi() const;
2014-06-21 23:48:52 +07:00
//! Set DPI used for conversion between real world units (e.g. mm) and pixels
2016-05-28 17:22:22 +02:00
void setOutputDpi( double dpi );
/**
2016-05-29 08:10:23 +10:00
* Set the magnification factor.
* @param factor the factor of magnification
* @note added in 2.16
2016-05-29 08:10:23 +10:00
* @see magnificationFactor()
*/
2016-05-29 08:10:23 +10:00
void setMagnificationFactor( double factor );
2016-05-29 08:10:23 +10:00
//! Return the magnification factor.
2016-05-18 14:36:02 +02:00
//! @note added in 2.16
2016-05-29 08:10:23 +10:00
//! @see setMagnificationFactor()
double magnificationFactor() const;
2016-05-18 14:36:02 +02: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)
QStringList layerIds() const;
//! Get list of layers for map rendering
2014-06-21 23:48:52 +07:00
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
QList<QgsMapLayer*> layers();
//! Set list of layers for map rendering. The layers must be registered in QgsProject.
//! The layers are stored in the reverse order of how they are rendered (layer with index 0 will be on top)
void setLayers( const QList<QgsMapLayer*>& layers );
//! 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 );
/** Get custom rendering flags. Layers might honour these to alter their rendering.
* @returns custom flags strings, separated by ';'
* @note added in QGIS 2.16
* @see setCustomRenderFlags()
*/
QString customRenderFlags() const;
/** Sets the custom rendering flags. Layers might honour these to alter their rendering.
* @param customRenderFlags custom flags strings, separated by ';'
* @note added in QGIS 2.16
* @see customRenderFlags()
*/
void setCustomRenderFlags( const QString& customRenderFlags );
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
QgsCoordinateReferenceSystem destinationCrs() const;
2014-06-22 00:15:37 +07:00
//! Get units of map's geographical coordinates - used for scale calculation
QgsUnitTypes::DistanceUnit mapUnits() const;
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;
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
//! Enumeration of flags that adjust the way the map is rendered
2014-05-27 23:22:50 +02:00
enum Flag
{
Antialiasing, //!< Enable anti-aliasing for map rendering
2014-06-22 00:15:37 +07:00
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
2016-02-14 03:50:23 +01:00
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
DrawSymbolBounds, //!< Draw bounds of symbols (for debugging/testing)
2016-09-09 17:01:02 +08:00
RenderMapTile, //!< Draw map such that there are no problems between adjacent tiles
RenderPartialOutput, //!< Whether to make extra effort to update map image with partially rendered layers (better for interactive map canvas). Added in QGIS 3.0
2014-05-27 23:22:50 +02:00
};
typedef QFlags<QgsMapSettings::Flag> Flags;
2014-06-22 00:15:37 +07:00
//! Set combination of flags that will be used for rendering
void setFlags( 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;
//! 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;
//! 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;
/** 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;
2014-05-27 23:22:50 +02:00
// -- utility functions --
2016-02-14 03:50:23 +01:00
//! @note not available in python bindings
//const QgsDatumTransformStore& datumTransformStore() const;
QgsDatumTransformStore& datumTransformStore();
2014-05-27 23:22:50 +02:00
const QgsMapToPixel& mapToPixel() const;
2015-09-12 23:04:17 +02:00
/** Computes an *estimated* conversion factor between layer and map units: layerUnits * layerToMapUnits = mapUnits
* @param layer The layer
2015-09-12 23:04:17 +02:00
* @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
*/
double layerToMapUnits( const QgsMapLayer* layer, 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* layer, QgsRectangle rect ) if you want to transform a rectangle
2014-05-27 23:22:50 +02:00
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle layerExtentToOutputExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
2014-05-27 23:22:50 +02:00
/**
* @brief transform bounding box from output CRS to layer's CRS
* @see mapToLayerCoordinates( QgsMapLayer* layer,QgsRectangle rect ) if you want to transform a rectangle
2014-05-27 23:22:50 +02:00
* @return a bounding box (aligned rectangle) containing the transformed extent
*/
QgsRectangle outputExtentToLayerExtent( const QgsMapLayer* layer, QgsRectangle extent ) const;
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( const QgsMapLayer* layer, QgsPoint point ) const;
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( const QgsMapLayer* layer, QgsRectangle rect ) const;
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( const QgsMapLayer* layer, QgsPoint point ) const;
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( const QgsMapLayer* layer, QgsRectangle rect ) const;
/**
* @brief Return coordinate transform from layer's CRS to destination CRS
* @param layer
* @return transform - may be invalid if the transform is not needed
*/
QgsCoordinateTransform layerTransform( const QgsMapLayer *layer ) const;
2014-05-27 23:22:50 +02:00
//! returns current extent of layer set
QgsRectangle fullExtent() const;
2014-05-27 23:22:50 +02:00
/* serialization */
void readXml( QDomNode& node );
2014-05-27 23:22:50 +02:00
void writeXml( QDomNode& node, QDomDocument& doc );
/** Sets the segmentation tolerance applied when rendering curved geometries
@param tolerance the segmentation tolerance*/
void setSegmentationTolerance( double tolerance );
/** Gets the segmentation tolerance applied when rendering curved geometries*/
double segmentationTolerance() const;
/** Sets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)
@param type the segmentation tolerance typename*/
2016-08-06 11:01:42 +02:00
void setSegmentationToleranceType( QgsAbstractGeometry::SegmentationToleranceType type );
/** Gets segmentation tolerance type (maximum angle or maximum difference between curve and approximation)*/
2016-08-06 11:01:42 +02:00
QgsAbstractGeometry::SegmentationToleranceType segmentationToleranceType() const;
protected:
void updateDerived();
};
QFlags<QgsMapSettings::Flag> operator|(QgsMapSettings::Flag f1, QFlags<QgsMapSettings::Flag> f2);