QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
23 #include "qgslayoutitemmapitem.h"
24 #include "qgssymbol.h"
25 #include "qgstextformat.h"
26 #include <QPainter>
27 #include <QVector2D>
28 
31 class QgsLayoutItemMap;
32 class QDomDocument;
33 class QDomElement;
34 class QPainter;
35 class QgsRenderContext;
36 
47 {
48  public:
49 
54 
63  void addGrid( QgsLayoutItemMapGrid *grid SIP_TRANSFER );
64 
71  void removeGrid( const QString &gridId );
72 
79  void moveGridUp( const QString &gridId );
80 
87  void moveGridDown( const QString &gridId );
88 
92  QgsLayoutItemMapGrid *grid( const QString &gridId ) const;
93 
97  QgsLayoutItemMapGrid *grid( int index ) const;
98 
103  QgsLayoutItemMapGrid &operator[]( int index );
104 
108  QList< QgsLayoutItemMapGrid * > asList() const;
109 
110  bool readXml( const QDomElement &elem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
111 
117  double maxGridExtension() const;
118 
125  void calculateMaxGridExtension( double &top, double &right, double &bottom, double &left ) const;
126 };
127 
128 //
129 // QgsLayoutItemMapGrid
130 //
131 
140 class CORE_EXPORT QgsLayoutItemMapGrid : public QgsLayoutItemMapItem
141 {
142 
143  Q_OBJECT
144 
145  public:
146 
150  enum GridUnit
151  {
153  MM,
154  CM,
156  };
157 
162  {
163  Solid = 0,
166  FrameAnnotationsOnly
167  };
168 
173  {
174  ShowAll = 0,
177  HideAll
178  };
179 
184  {
185  InsideMapFrame = 0,
187  };
188 
193  {
194  Horizontal = 0,
201  };
202 
207  {
208  Decimal = 0,
216  CustomFormat
217  };
218 
223  {
227  Top,
228  };
229 
234  {
235  NoFrame = 0,
243  };
244 
249  {
250  OrthogonalTicks = 0,
252  };
253 
258  {
259  FrameLeft = 0x01,
260  FrameRight = 0x02,
261  FrameTop = 0x04,
262  FrameBottom = 0x08
263  };
264  Q_DECLARE_FLAGS( FrameSideFlags, FrameSideFlag )
265 
266 
270  {
271  Longitude = 0,
272  Latitude
273  };
274 
280  QgsLayoutItemMapGrid( const QString &name, QgsLayoutItemMap *map );
281 
282  void draw( QPainter *painter ) override;
283  bool writeXml( QDomElement &elem, QDomDocument &doc, const QgsReadWriteContext &context ) const override;
284  bool readXml( const QDomElement &itemElem, const QDomDocument &doc, const QgsReadWriteContext &context ) override;
285 
290  void setCrs( const QgsCoordinateReferenceSystem &crs );
291 
296  QgsCoordinateReferenceSystem crs() const { return mCRS; }
297 
302  void setBlendMode( const QPainter::CompositionMode mode ) { mBlendMode = mode; }
303 
308  QPainter::CompositionMode blendMode() const { return mBlendMode; }
309 
310  bool usesAdvancedEffects() const override;
311 
316  double maxExtension() const;
317 
324  void calculateMaxExtension( double &top, double &right, double &bottom, double &left ) const;
325 
326  void setEnabled( bool enabled ) override;
327 
328  //
329  // GRID UNITS
330  //
331 
337  void setUnits( GridUnit unit );
338 
344  GridUnit units() const { return mGridUnit; }
345 
352  void setIntervalX( double interval );
353 
360  double intervalX() const { return mGridIntervalX; }
361 
368  void setIntervalY( double interval );
369 
376  double intervalY() const { return mGridIntervalY; }
377 
384  void setOffsetX( double offset );
385 
392  double offsetX() const { return mGridOffsetX; }
393 
400  void setOffsetY( double offset );
401 
408  double offsetY() const { return mGridOffsetY; }
409 
419  double minimumIntervalWidth() const { return mMinimumIntervalWidth; }
420 
430  void setMinimumIntervalWidth( double width );
431 
441  double maximumIntervalWidth() const { return mMaximumIntervalWidth; }
442 
452  void setMaximumIntervalWidth( double width );
453 
454  //
455  // GRID APPEARANCE
456  //
457 
463  void setStyle( GridStyle style );
464 
470  GridStyle style() const { return mGridStyle; }
471 
477  void setCrossLength( const double length );
478 
484  double crossLength() const { return mCrossLength; }
485 
493  void setGridLineWidth( double width );
494 
502  void setGridLineColor( const QColor &color );
503 
512  void setLineSymbol( QgsLineSymbol *symbol SIP_TRANSFER );
513 
522  const QgsLineSymbol *lineSymbol() const; SIP_SKIP
523 
531  QgsLineSymbol *lineSymbol();
532 
541  void setMarkerSymbol( QgsMarkerSymbol *symbol SIP_TRANSFER );
542 
551  const QgsMarkerSymbol *markerSymbol() const; SIP_SKIP
552 
560  QgsMarkerSymbol *markerSymbol();
561 
562  //
563  // ANNOTATIONS
564  //
565 
570  void setAnnotationEnabled( const bool enabled ) { mShowGridAnnotation = enabled; }
571 
576  bool annotationEnabled() const { return mShowGridAnnotation; }
577 
584  void setAnnotationTextFormat( const QgsTextFormat &format ) { mAnnotationFormat = format; }
585 
592  QgsTextFormat annotationTextFormat() const { return mAnnotationFormat; }
593 
600  Q_DECL_DEPRECATED void setAnnotationFont( const QFont &font ) SIP_DEPRECATED;
601 
608  Q_DECL_DEPRECATED QFont annotationFont() const SIP_DEPRECATED;
609 
616  Q_DECL_DEPRECATED void setAnnotationFontColor( const QColor &color ) SIP_DEPRECATED;
617 
624  Q_DECL_DEPRECATED QColor annotationFontColor() const SIP_DEPRECATED;
625 
631  void setAnnotationPrecision( const int precision ) { mGridAnnotationPrecision = precision; }
632 
638  int annotationPrecision() const { return mGridAnnotationPrecision; }
639 
647  void setAnnotationDisplay( DisplayMode display, BorderSide border );
648 
657  DisplayMode annotationDisplay( BorderSide border ) const;
658 
664  void setAnnotationPosition( AnnotationPosition position, BorderSide side );
665 
671  AnnotationPosition annotationPosition( BorderSide side ) const;
672 
677  void setAnnotationFrameDistance( const double distance );
678 
683  double annotationFrameDistance() const { return mAnnotationFrameDistance; }
684 
689  void setAnnotationDirection( AnnotationDirection direction, BorderSide side );
690 
695  void setAnnotationDirection( AnnotationDirection direction );
696 
702  AnnotationDirection annotationDirection( BorderSide border ) const;
703 
708  void setAnnotationFormat( const AnnotationFormat format ) { mGridAnnotationFormat = format; }
709 
714  AnnotationFormat annotationFormat() const { return mGridAnnotationFormat; }
715 
721  void setAnnotationExpression( const QString &expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
722 
728  QString annotationExpression() const { return mGridAnnotationExpressionString; }
729 
730  //
731  // GRID FRAME
732  //
733 
738  void setFrameStyle( const FrameStyle style ) { mGridFrameStyle = style; }
739 
744  FrameStyle frameStyle() const { return mGridFrameStyle; }
745 
750  void setFrameDivisions( DisplayMode divisions, BorderSide side );
751 
756  DisplayMode frameDivisions( BorderSide side ) const;
757 
765  void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
766 
775  void setFrameSideFlag( QgsLayoutItemMapGrid::FrameSideFlag flag, bool on = true );
776 
784  QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags() const;
785 
795  bool testFrameSideFlag( FrameSideFlag flag ) const;
796 
803  void setFrameWidth( const double width );
804 
811  double frameWidth() const { return mGridFrameWidth; }
812 
818  void setRotatedTicksEnabled( const bool state ) { mRotatedTicksEnabled = state; }
819 
825  double rotatedTicksEnabled() const { return mRotatedTicksEnabled; }
826 
832  void setRotatedTicksLengthMode( const TickLengthMode mode ) { mRotatedTicksLengthMode = mode; }
833 
839  TickLengthMode rotatedTicksLengthMode() const { return mRotatedTicksLengthMode; }
840 
846  void setRotatedTicksMinimumAngle( const double angle ) { mRotatedTicksMinimumAngle = angle; }
847 
853  double rotatedTicksMinimumAngle() const { return mRotatedTicksMinimumAngle; }
854 
860  void setRotatedTicksMarginToCorner( const double margin ) { mRotatedTicksMarginToCorner = margin; }
861 
867  double rotatedTicksMarginToCorner() const { return mRotatedTicksMarginToCorner; }
868 
874  void setRotatedAnnotationsEnabled( const bool state ) { mRotatedAnnotationsEnabled = state; }
875 
881  double rotatedAnnotationsEnabled() const { return mRotatedAnnotationsEnabled; }
882 
888  void setRotatedAnnotationsLengthMode( const TickLengthMode mode ) { mRotatedAnnotationsLengthMode = mode; }
889 
895  TickLengthMode rotatedAnnotationsLengthMode() const { return mRotatedAnnotationsLengthMode; }
896 
902  void setRotatedAnnotationsMinimumAngle( const double angle ) { mRotatedAnnotationsMinimumAngle = angle; }
903 
909  double rotatedAnnotationsMinimumAngle() const { return mRotatedAnnotationsMinimumAngle; }
910 
916  void setRotatedAnnotationsMarginToCorner( const double margin ) { mRotatedAnnotationsMarginToCorner = margin; }
917 
923  double rotatedAnnotationsMarginToCorner() const { return mRotatedAnnotationsMarginToCorner; }
924 
931  void setFrameMargin( const double margin );
932 
939  double frameMargin() const { return mGridFrameMargin; }
940 
946  void setFramePenSize( const double width );
947 
953  double framePenSize() const { return mGridFramePenThickness; }
954 
962  void setFramePenColor( const QColor &color ) { mGridFramePenColor = color; }
963 
971  QColor framePenColor() const {return mGridFramePenColor;}
972 
979  void setFrameFillColor1( const QColor &color ) { mGridFrameFillColor1 = color; }
980 
987  QColor frameFillColor1() const { return mGridFrameFillColor1; }
988 
995  void setFrameFillColor2( const QColor &color ) { mGridFrameFillColor2 = color; }
996 
1003  QColor frameFillColor2() const { return mGridFrameFillColor2; }
1004 
1006  bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
1007  void refresh() override;
1008 
1009  private:
1010 
1011  QgsLayoutItemMapGrid() = delete;
1012 
1013  struct GridExtension
1014  {
1015  GridExtension() = default;
1016  double top = 0.0;
1017  double right = 0.0;
1018  double bottom = 0.0;
1019  double left = 0.0;
1020 
1024  void UpdateBorder( BorderSide border, double value )
1025  {
1026  switch ( border )
1027  {
1029  left = std::max( left, value );
1030  break;
1032  right = std::max( right, value );
1033  break;
1035  top = std::max( top, value );
1036  break;
1038  bottom = std::max( bottom, value );
1039  break;
1040  }
1041  }
1042 
1046  void UpdateAll( double value )
1047  {
1048  left = std::max( left, value );
1049  right = std::max( right, value );
1050  top = std::max( top, value );
1051  bottom = std::max( bottom, value );
1052  }
1053  };
1054 
1055  struct GridLineAnnotation
1056  {
1057  BorderSide border; // border on which the annotation is
1058  QVector2D position; // position on the frame
1059  QVector2D vector; // vector towards map center
1060  double angle; // the (acute) angle formed between the vector and the border
1061  };
1062 
1067  struct GridLine
1068  {
1069  QPolygonF line; // the actual line, can be straight with two points or curved if transformed
1070  double coordinate; // the coordinate value
1071  QgsLayoutItemMapGrid::AnnotationCoordinate coordinateType; // whether it's a latitude or longitude line
1072  GridLineAnnotation startAnnotation; // the annotation on the start point
1073  GridLineAnnotation endAnnotation; // the annotation on the end point
1074  };
1075  mutable QList< GridLine > mGridLines;
1076 
1078  mutable bool mTransformDirty = true;
1079 
1081  GridStyle mGridStyle = QgsLayoutItemMapGrid::Solid;
1083  double mGridIntervalX = 0.0;
1085  double mGridIntervalY = 0.0;
1087  double mGridOffsetX = 0.0;
1089  double mGridOffsetY = 0.0;
1090 
1092  QgsTextFormat mAnnotationFormat;
1093 
1095  int mGridAnnotationPrecision = 3;
1097  bool mShowGridAnnotation = false;
1098 
1100  DisplayMode mLeftGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1102  DisplayMode mRightGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1104  DisplayMode mTopGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1106  DisplayMode mBottomGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1107 
1109  AnnotationPosition mLeftGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1111  AnnotationPosition mRightGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1113  AnnotationPosition mTopGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1115  AnnotationPosition mBottomGridAnnotationPosition = QgsLayoutItemMapGrid::OutsideMapFrame;
1116 
1118  double mAnnotationFrameDistance = 1.0;
1119 
1121  AnnotationDirection mLeftGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1123  AnnotationDirection mRightGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1125  AnnotationDirection mTopGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1127  AnnotationDirection mBottomGridAnnotationDirection = QgsLayoutItemMapGrid::Horizontal;
1128  AnnotationFormat mGridAnnotationFormat = QgsLayoutItemMapGrid::Decimal;
1129 
1130  QString mGridAnnotationExpressionString;
1131  mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
1132 
1133  FrameStyle mGridFrameStyle = QgsLayoutItemMapGrid::NoFrame;
1134 
1135  FrameSideFlags mGridFrameSides;
1136  double mGridFrameWidth = 2.0;
1137  double mGridFramePenThickness = 0.3;
1138  QColor mGridFramePenColor = QColor( 0, 0, 0 );
1139  QColor mGridFrameFillColor1 = Qt::white;
1140  QColor mGridFrameFillColor2 = Qt::black;
1141  double mCrossLength = 3.0;
1142  double mGridFrameMargin = 0.0;
1143  bool mRotatedTicksEnabled = false;
1144  TickLengthMode mRotatedTicksLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
1145  double mRotatedTicksMinimumAngle = 0.0;
1146  double mRotatedTicksMarginToCorner = 0.0;
1147  bool mRotatedAnnotationsEnabled = false;
1148  TickLengthMode mRotatedAnnotationsLengthMode = QgsLayoutItemMapGrid::OrthogonalTicks;
1149  double mRotatedAnnotationsMinimumAngle = 0.0;
1150  double mRotatedAnnotationsMarginToCorner = 0.0;
1151 
1152  double mMinimumIntervalWidth = 50;
1153  double mMaximumIntervalWidth = 100;
1154 
1156  DisplayMode mLeftFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1158  DisplayMode mRightFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1160  DisplayMode mTopFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1162  DisplayMode mBottomFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1163 
1164  std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
1165  std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
1166 
1168 
1169  GridUnit mGridUnit = MapUnit;
1170 
1171  QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1172 
1173  mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
1174  mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
1175  mutable QList< QgsPointXY > mTransformedIntersections;
1176  QRectF mPrevPaintRect;
1177  mutable QPolygonF mPrevMapPolygon;
1178 
1179  bool mEvaluatedEnabled = true;
1180  double mEvaluatedIntervalX = 0;
1181  double mEvaluatedIntervalY = 0;
1182  double mEvaluatedOffsetX = 0;
1183  double mEvaluatedOffsetY = 0;
1184  double mEvaluatedGridFrameWidth = 0;
1185  double mEvaluatedGridFrameMargin = 0;
1186  double mEvaluatedAnnotationFrameDistance = 0;
1187  double mEvaluatedCrossLength = 0;
1188  double mEvaluatedGridFrameLineThickness = 0;
1189  DisplayMode mEvaluatedLeftGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1190  DisplayMode mEvaluatedRightGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1191  DisplayMode mEvaluatedTopGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1192  DisplayMode mEvaluatedBottomGridAnnotationDisplay = QgsLayoutItemMapGrid::ShowAll;
1193  DisplayMode mEvaluatedLeftFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1194  DisplayMode mEvaluatedRightFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1195  DisplayMode mEvaluatedTopFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1196  DisplayMode mEvaluatedBottomFrameDivisions = QgsLayoutItemMapGrid::ShowAll;
1197 
1201  void updateGridLinesAnnotationsPositions() const;
1202 
1207  void drawGridFrame( QPainter *p, GridExtension *extension = nullptr ) const;
1208 
1216  void drawCoordinateAnnotations( QgsRenderContext &context, QgsExpressionContext &expressionContext, GridExtension *extension = nullptr ) const;
1217 
1222  void drawCoordinateAnnotation( QgsRenderContext &context, GridLineAnnotation annot, const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension = nullptr ) const;
1223 
1224  QString gridAnnotationString( double value, AnnotationCoordinate coord, QgsExpressionContext &expressionContext ) const;
1225 
1230  int xGridLines() const;
1231 
1236  int yGridLines() const;
1237 
1238  int xGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
1239 
1240  int yGridLinesCrsTransform( const QgsRectangle &bbox, const QgsCoordinateTransform &t ) const;
1241 
1242  void drawGridLine( const QLineF &line, QgsRenderContext &context ) const;
1243 
1244  void drawGridLine( const QPolygonF &line, QgsRenderContext &context ) const;
1245 
1250  void drawGridFrameBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
1251 
1257  BorderSide borderForLineCoord( QPointF p, AnnotationCoordinate coordinateType ) const;
1258 
1260  int crsGridParams( QgsRectangle &crsRect, QgsCoordinateTransform &inverseTransform ) const;
1261 
1262  static QList<QPolygonF> trimLinesToMap( const QPolygonF &line, const QgsRectangle &rect );
1263 
1264  QPolygonF scalePolygon( const QPolygonF &polygon, double scale ) const;
1265 
1267  void drawGridCrsTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
1268 
1269  void drawGridNoTransform( QgsRenderContext &context, double dotsPerMM, bool calculateLinesOnly = false ) const;
1270 
1271  void createDefaultGridLineSymbol();
1272 
1273  void createDefaultGridMarkerSymbol();
1274 
1275  void drawGridMarker( QPointF point, QgsRenderContext &context ) const;
1276 
1277  void drawGridFrameZebra( QPainter *p, GridExtension *extension = nullptr ) const;
1278 
1279  void drawGridFrameZebraBorder( QPainter *p, BorderSide border, double *extension = nullptr ) const;
1280 
1281  void drawGridFrameTicks( QPainter *p, GridExtension *extension = nullptr ) const;
1282 
1283  void drawGridFrameLine( QPainter *p, GridExtension *extension = nullptr ) const;
1284 
1285  void calculateCrsTransformLines() const;
1286 
1287  bool shouldShowDivisionForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
1288  bool shouldShowAnnotationForSide( AnnotationCoordinate coordinate, BorderSide side ) const;
1289  bool shouldShowForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode ) const;
1290  void refreshDataDefinedProperties();
1291 
1293  double mapWidth() const;
1294 
1295  friend class TestQgsLayoutMapGrid;
1296 
1297 };
1298 
1299 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItemMapGrid::FrameSideFlags )
1300 
1301 #endif // QGSLAYOUTITEMMAPGRID_H
QgsLayoutItemMapGrid::rotatedAnnotationsLengthMode
TickLengthMode rotatedAnnotationsLengthMode() const
Returns the grid frame style.
Definition: qgslayoutitemmapgrid.h:895
QgsLayoutItemMapGrid::TickLengthMode
TickLengthMode
Tick length mode (useful for rotated grids)
Definition: qgslayoutitemmapgrid.h:249
QgsLayoutItemMapGrid::intervalX
double intervalX() const
Returns the interval between grid lines in the x-direction.
Definition: qgslayoutitemmapgrid.h:360
QgsExpressionContext
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Definition: qgsexpressioncontext.h:370
QgsLayoutItemMapItem::setEnabled
virtual void setEnabled(bool enabled)
Controls whether the item will be drawn.
Definition: qgslayoutitemmapitem.cpp:99
QgsLayoutItemMapGrid::Zebra
@ Zebra
Black/white pattern.
Definition: qgslayoutitemmapgrid.h:236
QgsLayoutItemMapGrid
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapgrid.h:141
QgsLayoutItemMapGrid::InteriorTicks
@ InteriorTicks
Tick markers drawn inside map frame.
Definition: qgslayoutitemmapgrid.h:237
QgsLayoutItemMapGrid::VerticalDescending
@ VerticalDescending
Draw annotations vertically, descending.
Definition: qgslayoutitemmapgrid.h:196
QgsLayoutItemMapGrid::LongitudeOnly
@ LongitudeOnly
Show longitude/x annotations/divisions only.
Definition: qgslayoutitemmapgrid.h:176
QgsLayoutItemMapItemStack::readXml
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...
QgsLayoutItemMapGrid::style
GridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
Definition: qgslayoutitemmapgrid.h:470
QgsLayoutObject::refresh
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
Definition: qgslayoutobject.h:312
QgsLayoutItemMapGrid::DynamicPageSizeBased
@ DynamicPageSizeBased
Dynamically sized, based on a on-page size range.
Definition: qgslayoutitemmapgrid.h:155
QgsLayoutItemMapGrid::setRotatedTicksEnabled
void setRotatedTicksEnabled(const bool state)
Enable/disable ticks rotation for rotated or reprojected grids.
Definition: qgslayoutitemmapgrid.h:818
QgsReadWriteContext
The class is used as a container of context for various read/write operations on other objects.
Definition: qgsreadwritecontext.h:35
QgsLayoutItemMapGrid::annotationExpression
QString annotationExpression() const
Returns the expression used for drawing grid annotations.
Definition: qgslayoutitemmapgrid.h:728
QgsLayoutItemMapGrid::rotatedAnnotationsMarginToCorner
double rotatedAnnotationsMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:923
QgsLayoutItemMapGrid::OutsideMapFrame
@ OutsideMapFrame
Draw annotations outside the map frame.
Definition: qgslayoutitemmapgrid.h:186
QgsLayoutItemMapItem::draw
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
QgsLayoutItemMapItem::createExpressionContext
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
Definition: qgslayoutitemmapitem.cpp:124
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsLayoutItemMapGrid::ExteriorTicks
@ ExteriorTicks
Tick markers drawn outside map frame.
Definition: qgslayoutitemmapgrid.h:238
QgsLayoutItemMapGrid::ShowAll
@ ShowAll
Show both latitude and longitude annotations/divisions.
Definition: qgslayoutitemmapgrid.h:174
QgsLayoutItemMapGrid::framePenColor
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
Definition: qgslayoutitemmapgrid.h:971
QgsLayoutItemMapGrid::rotatedTicksLengthMode
TickLengthMode rotatedTicksLengthMode() const
Returns the grid frame style.
Definition: qgslayoutitemmapgrid.h:839
QgsLayoutItemMapGrid::setBlendMode
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
Definition: qgslayoutitemmapgrid.h:302
QgsLayoutItemMapGrid::FrameSideFlag
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
Definition: qgslayoutitemmapgrid.h:258
QgsLayoutItemMapGrid::GridStyle
GridStyle
Grid drawing style.
Definition: qgslayoutitemmapgrid.h:162
QgsLayoutItemMapGrid::maximumIntervalWidth
double maximumIntervalWidth() const
Returns the maximum width (in millimeters) for grid segments.
Definition: qgslayoutitemmapgrid.h:441
QgsRenderContext
Contains information about the context of a rendering operation.
Definition: qgsrendercontext.h:58
QgsLayoutItemMapItem
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Definition: qgslayoutitemmapitem.h:34
QgsStyleEntityVisitorInterface
An interface for classes which can visit style entity (e.g.
Definition: qgsstyleentityvisitor.h:34
QgsLayoutItemMapGrid::annotationFormat
AnnotationFormat annotationFormat() const
Returns the format for drawing grid annotations.
Definition: qgslayoutitemmapgrid.h:714
QgsLayoutItemMapItemStack
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapitem.h:231
QgsLayoutItemMapGrid::ZebraNautical
@ ZebraNautical
Black/white pattern, with nautical style diagonals on corners.
Definition: qgslayoutitemmapgrid.h:242
QgsLayoutItemMapGrid::setFramePenColor
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
Definition: qgslayoutitemmapgrid.h:962
QgsLayoutItemMapGrid::DegreeMinutePadded
@ DegreeMinutePadded
Degree/minutes, with minutes using leading zeros where required.
Definition: qgslayoutitemmapgrid.h:213
QgsLayoutItemMapGrid::intervalY
double intervalY() const
Returns the interval between grid lines in the y-direction.
Definition: qgslayoutitemmapgrid.h:376
QgsLayoutItemMapGrid::setRotatedTicksMarginToCorner
void setRotatedTicksMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:860
QgsLayoutItemMapGrid::CM
@ CM
Grid units in centimeters.
Definition: qgslayoutitemmapgrid.h:154
QgsLayoutItemMapGrid::rotatedAnnotationsMinimumAngle
double rotatedAnnotationsMinimumAngle() const
Gets the minimum angle (in degrees) below which annotated are not drawn.
Definition: qgslayoutitemmapgrid.h:909
QgsLayoutItemMapGrid::annotationPrecision
int annotationPrecision() const
Returns the coordinate precision for grid annotations, which is the number of decimal places shown wh...
Definition: qgslayoutitemmapgrid.h:638
QgsLayoutItemMapGrid::DisplayMode
DisplayMode
Display settings for grid annotations and frames.
Definition: qgslayoutitemmapgrid.h:173
QgsLayoutItemMapGrid::offsetX
double offsetX() const
Returns the offset for grid lines in the x-direction.
Definition: qgslayoutitemmapgrid.h:392
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsLayoutItemMapGrid::BoundaryDirection
@ BoundaryDirection
Annotations follow the boundary direction.
Definition: qgslayoutitemmapgrid.h:197
QgsLayoutItemMapGrid::InteriorExteriorTicks
@ InteriorExteriorTicks
Tick markers drawn both inside and outside the map frame.
Definition: qgslayoutitemmapgrid.h:239
QgsLayoutItemMapGrid::setRotatedTicksLengthMode
void setRotatedTicksLengthMode(const TickLengthMode mode)
Sets the tick length calculation mode.
Definition: qgslayoutitemmapgrid.h:832
QgsLayoutItemMapGrid::setRotatedAnnotationsMarginToCorner
void setRotatedAnnotationsMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:916
QgsLayoutItemMapGrid::LatitudeOnly
@ LatitudeOnly
Show latitude/y annotations/divisions only.
Definition: qgslayoutitemmapgrid.h:175
QgsLayoutItemMapGrid::rotatedTicksMarginToCorner
double rotatedTicksMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:867
QgsLayoutItemMapGrid::NormalizedTicks
@ NormalizedTicks
Constant tick lengths.
Definition: qgslayoutitemmapgrid.h:251
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsLayoutItemMapGrid::setRotatedAnnotationsLengthMode
void setRotatedAnnotationsLengthMode(const TickLengthMode mode)
Sets the annotation length calculation mode.
Definition: qgslayoutitemmapgrid.h:888
QgsTextFormat
Container for all settings relating to text rendering.
Definition: qgstextformat.h:40
QgsLayoutItemMapGrid::setAnnotationExpression
void setAnnotationExpression(const QString &expression)
Sets the expression used for drawing grid annotations.
Definition: qgslayoutitemmapgrid.h:721
precision
int precision
Definition: qgswfsgetfeature.cpp:49
QgsLayoutItemMapItemStack::operator[]
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
Definition: qgslayoutitemmapitem.cpp:237
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsLayoutItemMapGrid::setRotatedAnnotationsEnabled
void setRotatedAnnotationsEnabled(const bool state)
Enable/disable annotations rotation for rotated or reprojected grids.
Definition: qgslayoutitemmapgrid.h:874
QgsLayoutItemMapGrid::crs
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
Definition: qgslayoutitemmapgrid.h:296
QgsLayoutItemMapGrid::rotatedAnnotationsEnabled
double rotatedAnnotationsEnabled() const
Gets whether annotations rotation for rotated or reprojected grids is enabled.
Definition: qgslayoutitemmapgrid.h:881
QgsLayoutItemMapGrid::GridUnit
GridUnit
Unit for grid values.
Definition: qgslayoutitemmapgrid.h:151
QgsMarkerSymbol
A marker symbol type, for rendering Point and MultiPoint geometries.
Definition: qgssymbol.h:931
QgsLayoutItemMapGrid::AnnotationDirection
AnnotationDirection
Direction of grid annotations.
Definition: qgslayoutitemmapgrid.h:193
QgsLayoutItemMapGrid::setRotatedTicksMinimumAngle
void setRotatedTicksMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:846
QgsLayoutItemMapGrid::MapUnit
@ MapUnit
Grid units follow map units.
Definition: qgslayoutitemmapgrid.h:152
qgis_sip.h
QgsLayoutItemMapGrid::setFrameFillColor1
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
Definition: qgslayoutitemmapgrid.h:979
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsLayoutItemMapGrid::LineBorderNautical
@ LineBorderNautical
Simple solid line frame, with nautical style diagonals on corners.
Definition: qgslayoutitemmapgrid.h:241
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsLayoutItemMapGrid::DegreeMinuteSecondPadded
@ DegreeMinuteSecondPadded
Degree/minutes/seconds, with minutes using leading zeros where required.
Definition: qgslayoutitemmapgrid.h:215
QgsLineSymbol
A line symbol type, for rendering LineString and MultiLineString geometries.
Definition: qgssymbol.h:1131
QgsLayoutItemMapGrid::Right
@ Right
Right border.
Definition: qgslayoutitemmapgrid.h:225
QgsLayoutItemMapItem::readXml
virtual bool readXml(const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context)
Sets the map item state from a DOM document, where element is the DOM node corresponding to a 'Layout...
Definition: qgslayoutitemmapitem.cpp:55
QgsLayoutItemMapGrid::annotationFrameDistance
double annotationFrameDistance() const
Returns the distance between the map frame and annotations.
Definition: qgslayoutitemmapgrid.h:683
QgsLayoutItemMapGrid::AnnotationPosition
AnnotationPosition
Position for grid annotations.
Definition: qgslayoutitemmapgrid.h:184
QgsLayoutItemMapGrid::setAnnotationFormat
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
Definition: qgslayoutitemmapgrid.h:708
QgsLayoutItemMapItem::usesAdvancedEffects
virtual bool usesAdvancedEffects() const
Returns true if the item is drawn using advanced effects, such as blend modes.
Definition: qgslayoutitemmapitem.cpp:109
QgsLayoutItemMapGrid::frameFillColor1
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
Definition: qgslayoutitemmapgrid.h:987
QgsLayoutItemMapGrid::BorderSide
BorderSide
Border sides for annotations.
Definition: qgslayoutitemmapgrid.h:223
QgsLayoutItemMapGrid::crossLength
double crossLength() const
Retrieves the length (in layout units) of the cross segments drawn for the grid.
Definition: qgslayoutitemmapgrid.h:484
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsLayoutItemMapItemStack::asList
QList< QgsLayoutItemMapItem * > asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
Definition: qgslayoutitemmapitem.cpp:242
QgsLayoutItemMapGrid::Solid
@ Solid
Definition: qgslayoutitemmapgrid.h:163
QgsLayoutItemMapGrid::rotatedTicksEnabled
double rotatedTicksEnabled() const
Gets whether ticks rotation for rotated or reprojected grids is enabled.
Definition: qgslayoutitemmapgrid.h:825
QgsLayoutItemMapGrid::Bottom
@ Bottom
Bottom border.
Definition: qgslayoutitemmapgrid.h:226
QgsLayoutItemMapGrid::Cross
@ Cross
Draw line crosses at intersections of grid lines.
Definition: qgslayoutitemmapgrid.h:164
QgsLayoutItemMap
Layout graphical items for displaying a map.
Definition: qgslayoutitemmap.h:318
QgsLayoutItemMapGrid::setFrameStyle
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
Definition: qgslayoutitemmapgrid.h:738
QgsLayoutItemMapGrid::setAnnotationTextFormat
void setAnnotationTextFormat(const QgsTextFormat &format)
Sets the text format to use when rendering grid annotations.
Definition: qgslayoutitemmapgrid.h:584
QgsLayoutItemMapGrid::frameWidth
double frameWidth() const
Gets the grid frame width in layout units.
Definition: qgslayoutitemmapgrid.h:811
QgsLayoutItemMapGrid::units
GridUnit units() const
Returns the units used for grid measurements such as the interval and offset for grid lines.
Definition: qgslayoutitemmapgrid.h:344
QgsLayoutItemMapGrid::Horizontal
@ Horizontal
Draw annotations horizontally.
Definition: qgslayoutitemmapgrid.h:194
QgsLayoutItemMapGrid::frameFillColor2
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
Definition: qgslayoutitemmapgrid.h:1003
QgsLayoutItemMapGrid::rotatedTicksMinimumAngle
double rotatedTicksMinimumAngle() const
Gets the minimum angle (in degrees) below which ticks are not drawn.
Definition: qgslayoutitemmapgrid.h:853
QgsLayoutItemMapGrid::Vertical
@ Vertical
Draw annotations vertically, ascending.
Definition: qgslayoutitemmapgrid.h:195
QgsLayoutItemMapGrid::DegreeMinute
@ DegreeMinute
Degree/minutes, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:209
QgsLayoutItemMapGrid::DecimalWithSuffix
@ DecimalWithSuffix
Decimal degrees, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:211
QgsLayoutItemMapGrid::DegreeMinuteNoSuffix
@ DegreeMinuteNoSuffix
Degree/minutes, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:212
QgsLayoutItemMapItem::writeXml
virtual bool writeXml(QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context) const
Stores map item state in a DOM element, where element is the DOM element corresponding to a 'LayoutMa...
Definition: qgslayoutitemmapitem.cpp:33
QgsLayoutItemMapGrid::setRotatedAnnotationsMinimumAngle
void setRotatedAnnotationsMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which annotated are not drawn.
Definition: qgslayoutitemmapgrid.h:902
qgslayoutitemmapitem.h
QgsLayoutItemMapGrid::DegreeMinuteSecond
@ DegreeMinuteSecond
Degree/minutes/seconds, use NSEW suffix.
Definition: qgslayoutitemmapgrid.h:210
QgsLayoutItemMapGrid::NoFrame
@ NoFrame
Disable grid frame.
Definition: qgslayoutitemmapgrid.h:235
QgsLayoutItemMapGrid::Top
@ Top
Top border.
Definition: qgslayoutitemmapgrid.h:227
QgsLayoutItemMapGrid::AnnotationFormat
AnnotationFormat
Format for displaying grid annotations.
Definition: qgslayoutitemmapgrid.h:207
QgsLayoutItemMapGrid::DegreeMinuteSecondNoSuffix
@ DegreeMinuteSecondNoSuffix
Degree/minutes/seconds, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:214
QgsLayoutItemMapGrid::AboveTick
@ AboveTick
Draw annotations parallel to tick (above the line)
Definition: qgslayoutitemmapgrid.h:198
QgsLayoutItemMapGrid::Decimal
@ Decimal
Decimal degrees, use - for S/W coordinates.
Definition: qgslayoutitemmapgrid.h:208
QgsLayoutItemMapGrid::frameMargin
double frameMargin() const
Sets the grid frame Margin (in layout units).
Definition: qgslayoutitemmapgrid.h:939
QgsLayoutItemMapGrid::annotationTextFormat
QgsTextFormat annotationTextFormat() const
Returns the text format used when rendering grid annotations.
Definition: qgslayoutitemmapgrid.h:592
qgstextformat.h
QgsLayoutItemMapGrid::frameStyle
FrameStyle frameStyle() const
Returns the grid frame style.
Definition: qgslayoutitemmapgrid.h:744
QgsLayoutItemMapGrid::OrthogonalTicks
@ OrthogonalTicks
Align ticks orthogonaly.
Definition: qgslayoutitemmapgrid.h:250
QgsLayoutItemMapGrid::setFrameFillColor2
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
Definition: qgslayoutitemmapgrid.h:995
QgsLayoutItemMapGrid::Markers
@ Markers
Draw markers at intersections of grid lines.
Definition: qgslayoutitemmapgrid.h:165
QgsCoordinateTransform
Class for doing transforms between two map coordinate systems.
Definition: qgscoordinatetransform.h:53
QgsLayoutItemMapGrid::annotationEnabled
bool annotationEnabled() const
Returns whether annotations are shown for the grid.
Definition: qgslayoutitemmapgrid.h:576
QgsLayoutItemMapGridStack
A collection of grids which is drawn above the map content in a QgsLayoutItemMap.
Definition: qgslayoutitemmapgrid.h:47
QgsLayoutItemMapGrid::offsetY
double offsetY() const
Returns the offset for grid lines in the y-direction.
Definition: qgslayoutitemmapgrid.h:408
QgsLayoutItemMapItem::accept
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
Definition: qgslayoutitemmapitem.cpp:132
MathUtils::angle
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:786
QgsLayoutItemMapGrid::LineBorder
@ LineBorder
Simple solid line frame.
Definition: qgslayoutitemmapgrid.h:240
qgssymbol.h
QgsLayoutItemMapGrid::AnnotationCoordinate
AnnotationCoordinate
Annotation coordinate type.
Definition: qgslayoutitemmapgrid.h:270
QgsLayoutItemMapGrid::blendMode
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
Definition: qgslayoutitemmapgrid.h:308
QgsLayoutItemMapGrid::UnderTick
@ UnderTick
Draw annotations parallel to tick (under the line)
Definition: qgslayoutitemmapgrid.h:200
QgsLayoutItemMapGrid::minimumIntervalWidth
double minimumIntervalWidth() const
Returns the minimum width (in millimeters) for grid segments.
Definition: qgslayoutitemmapgrid.h:419
QgsLayoutItemMapGrid::setAnnotationEnabled
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
Definition: qgslayoutitemmapgrid.h:570
QgsLayoutItemMapItem::enabled
bool enabled() const
Returns whether the item will be drawn.
Definition: qgslayoutitemmapitem.cpp:104
QgsLayoutItemMapGrid::FrameStyle
FrameStyle
Style for grid frame.
Definition: qgslayoutitemmapgrid.h:234
QgsLayoutItemMapGrid::OnTick
@ OnTick
Draw annotations parallel to tick (on the line)
Definition: qgslayoutitemmapgrid.h:199
QgsLayoutItemMapGrid::framePenSize
double framePenSize() const
Retrieves the width of the stroke drawn in the grid frame.
Definition: qgslayoutitemmapgrid.h:953
QgsLayoutItemMapGrid::Left
@ Left
Left border.
Definition: qgslayoutitemmapgrid.h:224
QgsLayoutItemMapGrid::MM
@ MM
Grid units in millimeters.
Definition: qgslayoutitemmapgrid.h:153