QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
qgslayoutitemmapgrid.h
Go to the documentation of this file.
1/***************************************************************************
2 qgslayoutitemmapgrid.h
3 ----------------------
4 begin : October 2017
5 copyright : (C) 2017 by Marco Hugentobler, Nyall Dawson
6 email : marco dot hugentobler at sourcepole dot ch
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSLAYOUTITEMMAPGRID_H
19#define QGSLAYOUTITEMMAPGRID_H
20
21#include "qgis_core.h"
22#include "qgis_sip.h"
24#include "qgstextformat.h"
25#include <QPainter>
26#include <QVector2D>
27
31class QDomDocument;
32class QDomElement;
33class QPainter;
35class QgsLineSymbol;
36
46{
47 public:
48
53
62 void addGrid( QgsLayoutItemMapGrid *grid SIP_TRANSFER );
63
70 void removeGrid( const QString &gridId );
71
78 void moveGridUp( const QString &gridId );
79
86 void moveGridDown( const QString &gridId );
87
91 QgsLayoutItemMapGrid *grid( const QString &gridId ) const;
92
96 QgsLayoutItemMapGrid *grid( int index ) const;
97
102 QgsLayoutItemMapGrid &operator[]( int index );
103
107 QList< QgsLayoutItemMapGrid * > asList() const;
108
109 bool readXml( const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
110
116 double maxGridExtension() const;
117
124 void calculateMaxGridExtension( double &top, double &right, double &bottom, double &left ) const;
125};
126
127//
128// QgsLayoutItemMapGrid
129//
130
139{
140
141 Q_OBJECT
142
143 public:
144
149 {
154 };
155
160 {
161 Solid = 0,
164 FrameAnnotationsOnly
165 };
166
171 {
172 ShowAll = 0,
175 HideAll
176 };
177
182 {
183 InsideMapFrame = 0,
185 };
186
191 {
192 Horizontal = 0,
199 };
200
205 {
206 Decimal = 0,
214 CustomFormat
215 };
216
221 {
226 };
227
232 {
233 NoFrame = 0,
241 };
242
247 {
248 OrthogonalTicks = 0,
250 };
251
256 {
257 FrameLeft = 0x01,
258 FrameRight = 0x02,
259 FrameTop = 0x04,
260 FrameBottom = 0x08
261 };
262 Q_DECLARE_FLAGS( FrameSideFlags, FrameSideFlag )
263
264
268 {
269 Longitude = 0,
270 Latitude
271 };
272
278 QgsLayoutItemMapGrid( const QString &name, QgsLayoutItemMap *map );
280
281 void draw( QPainter *painter ) override;
282 bool writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
283 bool readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
284
289 void setCrs( const QgsCoordinateReferenceSystem &crs );
290
295 QgsCoordinateReferenceSystem crs() const { return mCRS; }
296
301 void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
302
307 QPainter::CompositionMode blendMode() const { return mBlendMode; }
308
309 bool usesAdvancedEffects() const override;
310
315 double maxExtension() const;
316
323 void calculateMaxExtension( double &top, double &right, double &bottom, double &left ) const;
324
325 void setEnabled( bool enabled ) override;
326
327 //
328 // GRID UNITS
329 //
330
336 void setUnits( GridUnit unit );
337
343 GridUnit units() const { return mGridUnit; }
344
351 void setIntervalX( double interval );
352
359 double intervalX() const { return mGridIntervalX; }
360
367 void setIntervalY( double interval );
368
375 double intervalY() const { return mGridIntervalY; }
376
383 void setOffsetX( double offset );
384
391 double offsetX() const { return mGridOffsetX; }
392
399 void setOffsetY( double offset );
400
407 double offsetY() const { return mGridOffsetY; }
408
418 double minimumIntervalWidth() const { return mMinimumIntervalWidth; }
419
429 void setMinimumIntervalWidth( double width );
430
440 double maximumIntervalWidth() const { return mMaximumIntervalWidth; }
441
451 void setMaximumIntervalWidth( double width );
452
453 //
454 // GRID APPEARANCE
455 //
456
462 void setStyle( GridStyle style );
463
469 GridStyle style() const { return mGridStyle; }
470
476 void setCrossLength( const double length );
477
483 double crossLength() const { return mCrossLength; }
484
492 void setGridLineWidth( double width );
493
501 void setGridLineColor( const QColor &color );
502
511 void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
512
521 const QgsLineSymbol *lineSymbol() const; SIP_SKIP
522
530 QgsLineSymbol *lineSymbol();
531
540 void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
541
550 const QgsMarkerSymbol *markerSymbol() const; SIP_SKIP
551
559 QgsMarkerSymbol *markerSymbol();
560
561 //
562 // ANNOTATIONS
563 //
564
569 void setAnnotationEnabled( const bool enabled ) { mShowGridAnnotation = enabled; }
570
575 bool annotationEnabled() const { return mShowGridAnnotation; }
576
583 void setAnnotationTextFormat( const QgsTextFormat &format ) { mAnnotationFormat = format; }
584
591 QgsTextFormat annotationTextFormat() const { return mAnnotationFormat; }
592
599 Q_DECL_DEPRECATED void setAnnotationFont( const QFont &font ) SIP_DEPRECATED;
600
607 Q_DECL_DEPRECATED QFont annotationFont() const SIP_DEPRECATED;
608
615 Q_DECL_DEPRECATED void setAnnotationFontColor( const QColor &color ) SIP_DEPRECATED;
616
623 Q_DECL_DEPRECATED QColor annotationFontColor() const SIP_DEPRECATED;
624
630 void setAnnotationPrecision( const int precision ) { mGridAnnotationPrecision = precision; }
631
637 int annotationPrecision() const { return mGridAnnotationPrecision; }
638
646 void setAnnotationDisplay( DisplayMode display, BorderSide border );
647
656 DisplayMode annotationDisplay( BorderSide border ) const;
657
663 void setAnnotationPosition( AnnotationPosition position, BorderSide side );
664
670 AnnotationPosition annotationPosition( BorderSide side ) const;
671
676 void setAnnotationFrameDistance( const double distance );
677
682 double annotationFrameDistance() const { return mAnnotationFrameDistance; }
683
688 void setAnnotationDirection( AnnotationDirection direction, BorderSide side );
689
694 void setAnnotationDirection( AnnotationDirection direction );
695
701 AnnotationDirection annotationDirection( BorderSide border ) const;
702
707 void setAnnotationFormat( const AnnotationFormat format ) { mGridAnnotationFormat = format; }
708
713 AnnotationFormat annotationFormat() const { return mGridAnnotationFormat; }
714
720 void setAnnotationExpression( const QString &expression );
721
727 QString annotationExpression() const { return mGridAnnotationExpressionString; }
728
729 //
730 // GRID FRAME
731 //
732
737 void setFrameStyle( const FrameStyle style ) { mGridFrameStyle = style; }
738
743 FrameStyle frameStyle() const { return mGridFrameStyle; }
744
749 void setFrameDivisions( DisplayMode divisions, BorderSide side );
750
755 DisplayMode frameDivisions( BorderSide side ) const;
756
764 void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
765
774 void setFrameSideFlag( QgsLayoutItemMapGrid::FrameSideFlag flag, bool on = true );
775
783 QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags() const;
784
794 bool testFrameSideFlag( FrameSideFlag flag ) const;
795
802 void setFrameWidth( const double width );
803
810 double frameWidth() const { return mGridFrameWidth; }
811
817 void setRotatedTicksEnabled( const bool state ) { mRotatedTicksEnabled = state; }
818
824 double rotatedTicksEnabled() const { return mRotatedTicksEnabled; }
825
831 void setRotatedTicksLengthMode( const TickLengthMode mode ) { mRotatedTicksLengthMode = mode; }
832
838 TickLengthMode rotatedTicksLengthMode() const { return mRotatedTicksLengthMode; }
839
845 void setRotatedTicksMinimumAngle( const double angle ) { mRotatedTicksMinimumAngle = angle; }
846
852 double rotatedTicksMinimumAngle() const { return mRotatedTicksMinimumAngle; }
853
859 void setRotatedTicksMarginToCorner( const double margin ) { mRotatedTicksMarginToCorner = margin; }
860
866 double rotatedTicksMarginToCorner() const { return mRotatedTicksMarginToCorner; }
867
873 void setRotatedAnnotationsEnabled( const bool state ) { mRotatedAnnotationsEnabled = state; }
874
880 double rotatedAnnotationsEnabled() const { return mRotatedAnnotationsEnabled; }
881
887 void setRotatedAnnotationsLengthMode( const TickLengthMode mode ) { mRotatedAnnotationsLengthMode = mode; }
888
894 TickLengthMode rotatedAnnotationsLengthMode() const { return mRotatedAnnotationsLengthMode; }
895
901 void setRotatedAnnotationsMinimumAngle( const double angle ) { mRotatedAnnotationsMinimumAngle = angle; }
902
908 double rotatedAnnotationsMinimumAngle() const { return mRotatedAnnotationsMinimumAngle; }
909
915 void setRotatedAnnotationsMarginToCorner( const double margin ) { mRotatedAnnotationsMarginToCorner = margin; }
916
922 double rotatedAnnotationsMarginToCorner() const { return mRotatedAnnotationsMarginToCorner; }
923
930 void setFrameMargin( const double margin );
931
938 double frameMargin() const { return mGridFrameMargin; }
939
945 void setFramePenSize( const double width );
946
952 double framePenSize() const { return mGridFramePenThickness; }
953
961 void setFramePenColor( const QColor &color ) { mGridFramePenColor = color; }
962
970 QColor framePenColor() const {return mGridFramePenColor;}
971
978 void setFrameFillColor1( const QColor &color ) { mGridFrameFillColor1 = color; }
979
986 QColor frameFillColor1() const { return mGridFrameFillColor1; }
987
994 void setFrameFillColor2( const QColor &color ) { mGridFrameFillColor2 = color; }
995
1002 QColor frameFillColor2() const { return mGridFrameFillColor2; }
1003
1004 QgsExpressionContext createExpressionContext() const override;
1005 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
1006 void refresh() override;
1007
1008 signals:
1009
1016
1017 private:
1018
1019 QgsLayoutItemMapGrid() = delete;
1020
1021 struct GridExtension
1022 {
1023 GridExtension() = default;
1024 double top = 0.0;
1025 double right = 0.0;
1026 double bottom = 0.0;
1027 double left = 0.0;
1028
1032 void UpdateBorder( BorderSide border, double value )
1033 {
1034 switch ( border )
1035 {
1037 left = std::max( left, value );
1038 break;
1040 right = std::max( right, value );
1041 break;
1043 top = std::max( top, value );
1044 break;
1046 bottom = std::max( bottom, value );
1047 break;
1048 }
1049 }
1050
1054 void UpdateAll( double value )
1055 {
1056 left = std::max( left, value );
1057 right = std::max( right, value );
1058 top = std::max( top, value );
1059 bottom = std::max( bottom, value );
1060 }
1061 };
1062
1063 struct GridLineAnnotation
1064 {
1065 BorderSide border = Left; // border on which the annotation is
1066 QVector2D position; // position on the frame
1067 QVector2D vector; // vector towards map center
1068 double angle = 0; // the (acute) angle formed between the vector and the border
1069 };
1070
1075 struct GridLine
1076 {
1077 QPolygonF line; // the actual line, can be straight with two points or curved if transformed
1078 double coordinate; // the coordinate value
1079 QgsLayoutItemMapGrid::AnnotationCoordinate coordinateType; // whether it's a latitude or longitude line
1080 GridLineAnnotation startAnnotation; // the annotation on the start point
1081 GridLineAnnotation endAnnotation; // the annotation on the end point
1082 };
1083 mutable QList< GridLine > mGridLines;
1084
1086 mutable bool mTransformDirty = true;
1087
1089 GridStyle mGridStyle = QgsLayoutItemMapGrid::Solid;
1091 double mGridIntervalX = 0.0;
1093 double mGridIntervalY = 0.0;
1095 double mGridOffsetX = 0.0;
1097 double mGridOffsetY = 0.0;
1098
1100 QgsTextFormat mAnnotationFormat;
1101
1103 int mGridAnnotationPrecision = 3;
1105 bool mShowGridAnnotation = false;
1106
1108 DisplayMode mLeftGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1110 DisplayMode mRightGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1112 DisplayMode mTopGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1114 DisplayMode mBottomGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1115
1117 AnnotationPosition mLeftGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1119 AnnotationPosition mRightGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1121 AnnotationPosition mTopGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1123 AnnotationPosition mBottomGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1124
1126 double mAnnotationFrameDistance = 1.0;
1127
1129 AnnotationDirection mLeftGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1131 AnnotationDirection mRightGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1133 AnnotationDirection mTopGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1135 AnnotationDirection mBottomGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1136 AnnotationFormat mGridAnnotationFormat = QgsLayoutItemMapGrid::Decimal;
1137
1138 QString mGridAnnotationExpressionString;
1139 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
1140
1141 FrameStyle mGridFrameStyle = QgsLayoutItemMapGrid::NoFrame;
1142
1143 FrameSideFlags mGridFrameSides;
1144 double mGridFrameWidth = 2.0;
1145 double mGridFramePenThickness = 0.3;
1146 QColor mGridFramePenColor = QColor( 0, 0, 0 );
1147 QColor mGridFrameFillColor1 = Qt::white;
1148 QColor mGridFrameFillColor2 = Qt::black;
1149 double mCrossLength = 3.0;
1150 double mGridFrameMargin = 0.0;
1151 bool mRotatedTicksEnabled = false;
1152 TickLengthMode mRotatedTicksLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
1153 double mRotatedTicksMinimumAngle = 0.0;
1154 double mRotatedTicksMarginToCorner = 0.0;
1155 bool mRotatedAnnotationsEnabled = false;
1156 TickLengthMode mRotatedAnnotationsLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
1157 double mRotatedAnnotationsMinimumAngle = 0.0;
1158 double mRotatedAnnotationsMarginToCorner = 0.0;
1159
1160 double mMinimumIntervalWidth = 50;
1161 double mMaximumIntervalWidth = 100;
1162
1164 DisplayMode mLeftFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1166 DisplayMode mRightFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1168 DisplayMode mTopFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1170 DisplayMode mBottomFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1171
1172 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
1173 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
1174
1176
1177 GridUnit mGridUnit = MapUnit;
1178
1179 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1180
1181 mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
1182 mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
1183 mutable QList< QgsPointXY > mTransformedIntersections;
1184 QRectF mPrevPaintRect;
1185 mutable QPolygonF mPrevMapPolygon;
1186
1187 bool mEvaluatedEnabled = true;
1188 double mEvaluatedIntervalX = 0;
1189 double mEvaluatedIntervalY = 0;
1190 double mEvaluatedOffsetX = 0;
1191 double mEvaluatedOffsetY = 0;
1192 double mEvaluatedGridFrameWidth = 0;
1193 double mEvaluatedGridFrameMargin = 0;
1194 double mEvaluatedAnnotationFrameDistance = 0;
1195 double mEvaluatedCrossLength = 0;
1196 double mEvaluatedGridFrameLineThickness = 0;
1197 DisplayMode mEvaluatedLeftGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1198 DisplayMode mEvaluatedRightGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1199 DisplayMode mEvaluatedTopGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1200 DisplayMode mEvaluatedBottomGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1201 DisplayMode mEvaluatedLeftFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1202 DisplayMode mEvaluatedRightFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1203 DisplayMode mEvaluatedTopFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1204 DisplayMode mEvaluatedBottomFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1205
1209 void updateGridLinesAnnotationsPositions() const;
1210
1215 void drawGridFrame( QPainter *p, GridExtension *extension = nullptr ) const;
1216
1224 void drawCoordinateAnnotations( QgsRenderContext &context, QgsExpressionContext &expressionContext, GridExtension *extension = nullptr ) const;
1225
1230 void drawCoordinateAnnotation( QgsRenderContext &context, GridLineAnnotation annot, const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension = nullptr ) const;
1231
1232 QString gridAnnotationString( double value, AnnotationCoordinate coord, QgsExpressionContext &expressionContext ) const;
1233
1238 int xGridLines() const;
1239
1244 int yGridLines() const;
1245
1246 int xGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
1247
1248 int yGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
1249
1250 void drawGridLine( const QLineF &line, QgsRenderContext &context ) const;
1251
1252 void drawGridLine( const QPolygonF &line, QgsRenderContext &context ) const;
1253
1258 void drawGridFrameBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
1259
1265 BorderSide borderForLineCoord( QPointF p, AnnotationCoordinate coordinateType ) const;
1266
1268 int crsGridParams( QgsRectangle &crsRect, QgsCoordinateTransform &inverseTransform ) const;
1269
1270 static QList<QPolygonF> trimLinesToMap( const QPolygonF &line, const QgsRectangle &rect );
1271
1272 QPolygonF scalePolygon( const QPolygonF &polygon, double scale ) const;
1273
1275 void drawGridCrsTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
1276
1277 void drawGridNoTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
1278
1279 void createDefaultGridLineSymbol();
1280
1281 void createDefaultGridMarkerSymbol();
1282
1283 void drawGridMarker( QPointF point, QgsRenderContext &context ) const;
1284
1285 void drawGridFrameZebra( QPainter *p, GridExtension *extension = nullptr ) const;
1286
1287 void drawGridFrameZebraBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
1288
1289 void drawGridFrameTicks( QPainter *p, GridExtension *extension = nullptr ) const;
1290
1291 void drawGridFrameLine( QPainter *p, GridExtension *extension = nullptr ) const;
1292
1293 void calculateCrsTransformLines() const;
1294
1295 bool shouldShowDivisionForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
1296 bool shouldShowAnnotationForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
1297 bool shouldShowForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode ) const;
1298 void refreshDataDefinedProperties();
1299
1301 double mapWidth() const;
1302
1303 friend class TestQgsLayoutMapGrid;
1304
1305 // Needs access to evaluated properties to compute frame bleed
1306 friend class QgsLayoutItemMap;
1307
1308};
1309
1311
1312#endif // QGSLAYOUTITEMMAPGRID_H
This class represents a coordinate reference system (CRS).
Class for doing transforms between two map coordinate systems.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
A collection of grids which is drawn above the map content in a QgsLayoutItemMap.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
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.
GridStyle
Grid drawing style.
@ Markers
Draw markers at intersections of grid lines.
@ Cross
Draw line crosses at intersections of grid lines.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
GridUnit
Unit for grid values.
@ CM
Grid units in centimeters.
@ MM
Grid units in millimeters.
@ DynamicPageSizeBased
Dynamically sized, based on a on-page size range.
@ MapUnit
Grid units follow map units.
GridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
double frameWidth() const
Gets the grid frame width in layout units.
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.
AnnotationFormat annotationFormat() const
Returns the format for drawing 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.
AnnotationPosition
Position for grid annotations.
@ OutsideMapFrame
Draw annotations outside the map frame.
TickLengthMode rotatedAnnotationsLengthMode() const
Returns the annotation length calculation mode.
double rotatedTicksMinimumAngle() const
Gets the minimum angle (in degrees) below which ticks are not drawn.
double offsetY() const
Returns the offset for grid lines in the y-direction.
AnnotationCoordinate
Annotation coordinate type.
double rotatedAnnotationsEnabled() const
Gets whether annotations rotation for rotated or reprojected grids is enabled.
void setRotatedTicksLengthMode(const TickLengthMode mode)
Sets the tick length calculation mode.
DisplayMode
Display settings for grid annotations and frames.
@ LongitudeOnly
Show longitude/x annotations/divisions only.
@ ShowAll
Show both latitude and longitude annotations/divisions.
@ LatitudeOnly
Show latitude/y annotations/divisions only.
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() 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.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
QFlags< FrameSideFlag > FrameSideFlags
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
FrameStyle frameStyle() const
Returns the grid frame style.
void setRotatedTicksMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
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.
void setRotatedAnnotationsLengthMode(const TickLengthMode mode)
Sets the annotation length calculation mode.
TickLengthMode
Tick length mode (useful for rotated grids)
@ OrthogonalTicks
Align ticks orthogonaly.
@ NormalizedTicks
Constant tick lengths.
double offsetX() const
Returns the offset for grid lines in the x-direction.
AnnotationFormat
Format for displaying grid annotations.
@ DegreeMinuteSecondNoSuffix
Degree/minutes/seconds, use - for S/W coordinates.
@ DegreeMinuteSecondPadded
Degree/minutes/seconds, with minutes using leading zeros where required.
@ DegreeMinuteSecond
Degree/minutes/seconds, use NSEW suffix.
@ DecimalWithSuffix
Decimal degrees, use NSEW suffix.
@ DegreeMinute
Degree/minutes, use NSEW suffix.
@ DegreeMinuteNoSuffix
Degree/minutes, use - for S/W coordinates.
@ Decimal
Decimal degrees, use - for S/W coordinates.
@ DegreeMinutePadded
Degree/minutes, with minutes using leading zeros where required.
AnnotationDirection
Direction of grid annotations.
@ OnTick
Draw annotations parallel to tick (on the line)
@ Horizontal
Draw annotations horizontally.
@ Vertical
Draw annotations vertically, ascending.
@ BoundaryDirection
Annotations follow the boundary direction.
@ AboveTick
Draw annotations parallel to tick (above the line)
@ UnderTick
Draw annotations parallel to tick (under the line)
@ VerticalDescending
Draw annotations vertically, descending.
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.
GridUnit units() const
Returns the units used for grid measurements such as the interval and offset for grid lines.
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.
FrameStyle
Style for grid frame.
@ Zebra
Black/white pattern.
@ InteriorTicks
Tick markers drawn inside map frame.
@ LineBorder
Simple solid line frame.
@ InteriorExteriorTicks
Tick markers drawn both inside and outside the map frame.
@ LineBorderNautical
Simple solid line frame, with nautical style diagonals on corners.
@ ExteriorTicks
Tick markers drawn outside map frame.
@ NoFrame
Disable grid frame.
@ ZebraNautical
Black/white pattern, with nautical style diagonals on corners.
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).
double rotatedTicksEnabled() const
Gets whether ticks rotation for rotated or reprojected grids is enabled.
BorderSide
Border sides for 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.
TickLengthMode rotatedTicksLengthMode() const
Returns the grid frame style.
double intervalX() const
Returns the interval between grid lines in the x-direction.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
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.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Layout graphical items for displaying a map.
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgslinesymbol.h:30
A marker symbol type, for rendering Point and MultiPoint geometries.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
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.
Definition: qgstextformat.h:41
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)
Definition: MathUtils.cpp:716
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition: qgis_sip.h:278
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
int precision