18#ifndef QGSLAYOUTITEMMAPGRID_H
19#define QGSLAYOUTITEMMAPGRID_H
108 QList< QgsLayoutItemMapGrid * >
asList()
const;
154 void draw( QPainter *painter )
override;
174 void setBlendMode(
const QPainter::CompositionMode mode ) { mBlendMode = mode; }
180 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
182 bool usesAdvancedEffects()
const override;
188 double maxExtension()
const;
196 void calculateMaxExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
198 void setEnabled(
bool enabled )
override;
224 void setIntervalX(
double interval );
240 void setIntervalY(
double interval );
256 void setOffsetX(
double offset );
264 double offsetX()
const {
return mGridOffsetX; }
272 void setOffsetY(
double offset );
280 double offsetY()
const {
return mGridOffsetY; }
302 void setMinimumIntervalWidth(
double width );
324 void setMaximumIntervalWidth(
double width );
349 void setCrossLength(
const double length );
365 void setGridLineWidth(
double width );
374 void setGridLineColor(
const QColor &color );
472 Q_DECL_DEPRECATED
void setAnnotationFont(
const QFont &font )
SIP_DEPRECATED;
488 Q_DECL_DEPRECATED
void setAnnotationFontColor( const QColor &color )
SIP_DEPRECATED;
496 Q_DECL_DEPRECATED QColor annotationFontColor() const
SIP_DEPRECATED;
549 void setAnnotationFrameDistance(
const double distance );
593 void setAnnotationExpression(
const QString &expression );
675 void setFrameWidth(
const double width );
803 void setFrameMargin(
const double margin );
818 void setFramePenSize(
const double width );
895 void refresh()
override;
919 GridExtension() =
default;
933 left = std::max( left, value );
936 right = std::max( right, value );
939 top = std::max( top, value );
942 bottom = std::max( bottom, value );
950 void UpdateAll(
double value )
952 left = std::max( left, value );
953 right = std::max( right, value );
954 top = std::max( top, value );
955 bottom = std::max( bottom, value );
959 struct GridLineAnnotation
976 GridLineAnnotation startAnnotation;
977 GridLineAnnotation endAnnotation;
979 mutable QList< GridLine > mGridLines;
982 mutable bool mTransformDirty =
true;
987 double mGridIntervalX = 0.0;
989 double mGridIntervalY = 0.0;
991 double mGridOffsetX = 0.0;
993 double mGridOffsetY = 0.0;
996 QgsTextFormat mAnnotationFormat;
999 int mGridAnnotationPrecision = 3;
1001 bool mShowGridAnnotation =
false;
1024 double mAnnotationFrameDistance = 1.0;
1036 QString mGridAnnotationExpressionString;
1037 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
1042 double mGridFrameWidth = 2.0;
1043 double mGridFramePenThickness = 0.3;
1044 QColor mGridFramePenColor = QColor( 0, 0, 0 );
1045 QColor mGridFrameFillColor1 = Qt::white;
1046 QColor mGridFrameFillColor2 = Qt::black;
1047 double mCrossLength = 3.0;
1048 double mGridFrameMargin = 0.0;
1049 bool mRotatedTicksEnabled =
false;
1051 double mRotatedTicksMinimumAngle = 0.0;
1052 double mRotatedTicksMarginToCorner = 0.0;
1053 bool mRotatedAnnotationsEnabled =
false;
1055 double mRotatedAnnotationsMinimumAngle = 0.0;
1056 double mRotatedAnnotationsMarginToCorner = 0.0;
1058 double mMinimumIntervalWidth = 50;
1059 double mMaximumIntervalWidth = 100;
1070 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
1071 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
1073 QgsCoordinateReferenceSystem mCRS;
1077 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1079 mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
1080 mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
1081 mutable QList< QgsPointXY > mTransformedIntersections;
1082 QRectF mPrevPaintRect;
1083 mutable QPolygonF mPrevMapPolygon;
1085 bool mEvaluatedEnabled =
true;
1086 double mEvaluatedIntervalX = 0;
1087 double mEvaluatedIntervalY = 0;
1088 double mEvaluatedOffsetX = 0;
1089 double mEvaluatedOffsetY = 0;
1090 double mEvaluatedGridFrameWidth = 0;
1091 double mEvaluatedGridFrameMargin = 0;
1092 double mEvaluatedAnnotationFrameDistance = 0;
1093 double mEvaluatedCrossLength = 0;
1094 double mEvaluatedGridFrameLineThickness = 0;
1095 std::unique_ptr< QgsProperty > mDrawAnnotationProperty;
1108 void updateGridLinesAnnotationsPositions()
const;
1114 void drawGridFrame( QPainter *p, GridExtension *extension =
nullptr )
const;
1123 void drawCoordinateAnnotations( QgsRenderContext &context, QgsExpressionContext &expressionContext, GridExtension *extension =
nullptr )
const;
1129 void drawCoordinateAnnotation( QgsRenderContext &context, GridLineAnnotation annot,
const QString &annotationString,
Qgis::MapGridAnnotationType coordinateType, GridExtension *extension =
nullptr )
const;
1131 QString gridAnnotationString(
double value,
Qgis::MapGridAnnotationType coord, QgsExpressionContext &expressionContext,
bool isGeographic )
const;
1137 int xGridLines()
const;
1143 int yGridLines()
const;
1145 int xGridLinesCrsTransform(
const QgsRectangle &bbox,
const QgsCoordinateTransform &t )
const;
1147 int yGridLinesCrsTransform(
const QgsRectangle &bbox,
const QgsCoordinateTransform &t )
const;
1149 void drawGridLine(
const QLineF &line, QgsRenderContext &context )
const;
1151 void drawGridLine(
const QPolygonF &line, QgsRenderContext &context )
const;
1167 int crsGridParams( QgsRectangle &crsRect, QgsCoordinateTransform &inverseTransform )
const;
1169 static QList<QPolygonF> trimLinesToMap(
const QPolygonF &line,
const QgsRectangle &rect );
1171 QPolygonF scalePolygon(
const QPolygonF &polygon,
double scale )
const;
1174 void drawGridCrsTransform( QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1176 void drawGridNoTransform( QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1178 void createDefaultGridLineSymbol();
1180 void createDefaultGridMarkerSymbol();
1182 void drawGridMarker( QPointF point, QgsRenderContext &context )
const;
1184 void drawGridFrameZebra( QPainter *p, GridExtension *extension =
nullptr )
const;
1186 void drawGridFrameZebraBorder( QPainter *p,
Qgis::MapGridBorderSide border,
double *extension =
nullptr )
const;
1188 void drawGridFrameTicks( QPainter *p, GridExtension *extension =
nullptr )
const;
1190 void drawGridFrameLine( QPainter *p, GridExtension *extension =
nullptr )
const;
1192 void calculateCrsTransformLines()
const;
1197 void refreshDataDefinedProperties();
1200 double mapWidth()
const;
MapGridTickLengthMode
Map grid tick length mode (useful for rotated grids).
@ OrthogonalTicks
Align ticks orthogonaly.
QFlags< MapGridFrameSideFlag > MapGridFrameSideFlags
Flags for controlling which side of the map a frame is drawn on.
MapGridAnnotationPosition
Position for map grid annotations.
@ OutsideMapFrame
Draw annotations outside the map frame.
MapGridUnit
Units for map grid values.
@ MapUnits
Grid units follow map units.
MapGridBorderSide
Border sides for map grid annotations.
MapGridFrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
MapGridComponentVisibility
Visibility display settings for map grid annotations and frames.
@ ShowAll
Show both latitude and longitude annotations/divisions.
MapGridStyle
Map grid drawing styles.
@ Lines
Draw lines for grid.
MapGridAnnotationType
Annotation coordinate type.
MapGridFrameStyle
Style for map grid frames.
@ NoFrame
Disable grid frame.
MapGridAnnotationDirection
Direction of grid annotations.
@ Horizontal
Draw annotations horizontally.
TextHorizontalAlignment
Text horizontal alignment.
MapGridAnnotationFormat
Format for displaying map grid annotations.
@ Decimal
Decimal degrees, use - for S/W coordinates.
Represents a coordinate reference system (CRS).
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void calculateMaxGridExtension(double &top, double &right, double &bottom, double &left) const
Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect...
void removeGrid(const QString &gridId)
Removes a grid with matching gridId from the stack and deletes the corresponding QgsLayoutItemMapGrid...
double maxGridExtension() const
Calculates the maximum distance grids within the stack extend beyond the QgsLayoutItemMap's item rect...
void addGrid(QgsLayoutItemMapGrid *grid)
Adds a new map grid to the stack and takes ownership of the grid.
QgsLayoutItemMapGrid * grid(const QString &gridId) const
Returns a reference to a grid with matching gridId within the stack.
void moveGridUp(const QString &gridId)
Moves a grid with matching gridId up the stack, causing it to be rendered above other grids.
void moveGridDown(const QString &gridId)
Moves a grid with matching gridId down the stack, causing it to be rendered below other grids.
QgsLayoutItemMapGridStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapGridStack, attached to the specified map.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
void setRotatedTicksLengthMode(const Qgis::MapGridTickLengthMode mode)
Sets the tick length calculation mode.
bool rotatedAnnotationsEnabled() const
Gets whether annotations rotation for rotated or reprojected grids is enabled.
QString annotationExpression() const
Returns the expression used for drawing grid annotations.
double rotatedTicksMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
void setFrameStyle(const Qgis::MapGridFrameStyle style)
Sets the grid frame style.
double frameWidth() const
Gets the grid frame width in layout units.
void draw(QPainter *painter) override
Draws the item on to a destination painter.
double crossLength() const
Retrieves the length (in layout units) of the cross segments drawn for the grid.
void setRotatedTicksMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which ticks are not drawn.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
QgsTextFormat annotationTextFormat() const
Returns the text format used when rendering grid annotations.
double framePenSize() const
Retrieves the width of the stroke drawn in the grid frame.
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
void setRotatedTicksEnabled(const bool state)
Enable/disable ticks rotation for rotated or reprojected grids.
Qgis::MapGridUnit units() const
Returns the units used for grid measurements such as the interval and offset for grid lines.
Qgis::MapGridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
double rotatedTicksMinimumAngle() const
Gets the minimum angle (in degrees) below which ticks are not drawn.
Qgis::MapGridTickLengthMode rotatedAnnotationsLengthMode() const
Returns the annotation length calculation mode.
Qgis::MapGridFrameStyle frameStyle() const
Returns the grid frame style.
friend class QgsLayoutItemMap
double offsetY() const
Returns the offset for grid lines in the y-direction.
void crsChanged()
Emitted whenever the grid's CRS is changed.
void setRotatedAnnotationsMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which annotations are not drawn.
double rotatedAnnotationsMinimumAngle() const
Gets the minimum angle (in degrees) below which annotations are not drawn.
void setAnnotationTextFormat(const QgsTextFormat &format)
Sets the text format to use when rendering grid annotations.
QgsLayoutItemMapGrid(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapGrid.
Qgis::MapGridTickLengthMode rotatedTicksLengthMode() const
Returns the grid frame style.
~QgsLayoutItemMapGrid() override
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
bool annotationEnabled() const
Returns whether annotations are shown for the grid.
friend class TestQgsLayoutMapGrid
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
void setRotatedTicksMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
void setRotatedAnnotationsLengthMode(const Qgis::MapGridTickLengthMode mode)
Sets the annotation length calculation mode.
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
void setRotatedAnnotationsMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing annotations are not drawn.
double rotatedAnnotationsMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing annotations are not drawn.
double offsetX() const
Returns the offset for grid lines in the x-direction.
bool rotatedTicksEnabled() const
Gets whether ticks rotation for rotated or reprojected grids is enabled.
double annotationFrameDistance() const
Returns the distance between the map frame and annotations.
double intervalY() const
Returns the interval between grid lines in the y-direction.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the crs for the grid.
double minimumIntervalWidth() const
Returns the minimum width (in millimeters) for grid segments.
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
void setRotatedAnnotationsEnabled(const bool state)
Enable/disable annotations rotation for rotated or reprojected grids.
void setAnnotationFormat(const Qgis::MapGridAnnotationFormat format)
Sets the format for drawing grid annotations.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
double frameMargin() const
Sets the grid frame Margin (in layout units).
Qgis::MapGridAnnotationFormat annotationFormat() const
Returns the format for drawing grid annotations.
int annotationPrecision() const
Returns the coordinate precision for grid annotations, which is the number of decimal places shown wh...
double maximumIntervalWidth() const
Returns the maximum width (in millimeters) for grid segments.
double intervalX() const
Returns the interval between grid lines in the x-direction.
virtual bool writeXml(QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context) const
Stores the state of the item stack in a DOM node, where element is the DOM element corresponding to a...
virtual bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)=0
Sets the item stack's state from a DOM document, where element is a DOM node corresponding to a 'Layo...
QList< QgsLayoutItemMapItem * > asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
QgsLayoutItemMapItemStack(QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItemStack, attached to the specified map.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
QString name() const
Returns the friendly display name for the item.
QgsLayoutItemMapItem(const QString &name, QgsLayoutItemMap *map)
Constructor for QgsLayoutItemMapItem, attached to the specified map.
bool enabled() const
Returns whether the item will be drawn.
const QgsLayoutItemMap * map() const
Returns the layout item map for the item.
Layout graphical items for displaying a map.
A line symbol type, for rendering LineString and MultiLineString geometries.
A marker symbol type, for rendering Point and MultiPoint geometries.
A container for the context for various read/write operations on objects.
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
Container for all settings relating to text rendering.
double ANALYSIS_EXPORT angle(QgsPoint *p1, QgsPoint *p2, QgsPoint *p3, QgsPoint *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored).