18 #ifndef QGSLAYOUTITEMMAPGRID_H
19 #define QGSLAYOUTITEMMAPGRID_H
21 #include "qgis_core.h"
71 void removeGrid(
const QString &gridId );
79 void moveGridUp(
const QString &gridId );
87 void moveGridDown(
const QString &gridId );
108 QList< QgsLayoutItemMapGrid * >
asList()
const;
117 double maxGridExtension()
const;
125 void calculateMaxGridExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
264 Q_DECLARE_FLAGS( FrameSideFlags, FrameSideFlag )
282 void draw( QPainter *painter )
override;
302 void setBlendMode(
const QPainter::CompositionMode mode ) { mBlendMode = mode; }
308 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
310 bool usesAdvancedEffects()
const override;
316 double maxExtension()
const;
324 void calculateMaxExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
326 void setEnabled(
bool enabled )
override;
337 void setUnits( GridUnit unit );
352 void setIntervalX(
double interval );
368 void setIntervalY(
double interval );
384 void setOffsetX(
double offset );
392 double offsetX()
const {
return mGridOffsetX; }
400 void setOffsetY(
double offset );
408 double offsetY()
const {
return mGridOffsetY; }
430 void setMinimumIntervalWidth(
double width );
452 void setMaximumIntervalWidth(
double width );
463 void setStyle( GridStyle style );
477 void setCrossLength(
const double length );
493 void setGridLineWidth(
double width );
502 void setGridLineColor(
const QColor &color );
600 Q_DECL_DEPRECATED
void setAnnotationFont(
const QFont &font )
SIP_DEPRECATED;
616 Q_DECL_DEPRECATED
void setAnnotationFontColor( const QColor &color )
SIP_DEPRECATED;
624 Q_DECL_DEPRECATED QColor annotationFontColor() const
SIP_DEPRECATED;
647 void setAnnotationDisplay( DisplayMode display, BorderSide border );
657 DisplayMode annotationDisplay( BorderSide border )
const;
664 void setAnnotationPosition( AnnotationPosition position, BorderSide side );
671 AnnotationPosition annotationPosition( BorderSide side )
const;
677 void setAnnotationFrameDistance(
const double distance );
689 void setAnnotationDirection( AnnotationDirection direction, BorderSide side );
695 void setAnnotationDirection( AnnotationDirection direction );
702 AnnotationDirection annotationDirection( BorderSide border )
const;
721 void setAnnotationExpression(
const QString &expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
750 void setFrameDivisions( DisplayMode divisions, BorderSide side );
756 DisplayMode frameDivisions( BorderSide side )
const;
765 void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
784 QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags()
const;
795 bool testFrameSideFlag( FrameSideFlag flag )
const;
803 void setFrameWidth(
const double width );
931 void setFrameMargin(
const double margin );
946 void setFramePenSize(
const double width );
1007 void refresh()
override;
1022 struct GridExtension
1024 GridExtension() =
default;
1027 double bottom = 0.0;
1033 void UpdateBorder(
BorderSide border,
double value )
1038 left = std::max( left, value );
1041 right = std::max( right, value );
1044 top = std::max( top, value );
1047 bottom = std::max( bottom, value );
1055 void UpdateAll(
double value )
1057 left = std::max( left, value );
1058 right = std::max( right, value );
1059 top = std::max( top, value );
1060 bottom = std::max( bottom, value );
1064 struct GridLineAnnotation
1066 BorderSide border = Left;
1081 GridLineAnnotation startAnnotation;
1082 GridLineAnnotation endAnnotation;
1084 mutable QList< GridLine > mGridLines;
1087 mutable bool mTransformDirty =
true;
1092 double mGridIntervalX = 0.0;
1094 double mGridIntervalY = 0.0;
1096 double mGridOffsetX = 0.0;
1098 double mGridOffsetY = 0.0;
1104 int mGridAnnotationPrecision = 3;
1106 bool mShowGridAnnotation =
false;
1127 double mAnnotationFrameDistance = 1.0;
1139 QString mGridAnnotationExpressionString;
1140 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
1144 FrameSideFlags mGridFrameSides;
1145 double mGridFrameWidth = 2.0;
1146 double mGridFramePenThickness = 0.3;
1147 QColor mGridFramePenColor = QColor( 0, 0, 0 );
1148 QColor mGridFrameFillColor1 = Qt::white;
1149 QColor mGridFrameFillColor2 = Qt::black;
1150 double mCrossLength = 3.0;
1151 double mGridFrameMargin = 0.0;
1152 bool mRotatedTicksEnabled =
false;
1154 double mRotatedTicksMinimumAngle = 0.0;
1155 double mRotatedTicksMarginToCorner = 0.0;
1156 bool mRotatedAnnotationsEnabled =
false;
1158 double mRotatedAnnotationsMinimumAngle = 0.0;
1159 double mRotatedAnnotationsMarginToCorner = 0.0;
1161 double mMinimumIntervalWidth = 50;
1162 double mMaximumIntervalWidth = 100;
1173 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
1174 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
1178 GridUnit mGridUnit = MapUnit;
1180 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
1182 mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
1183 mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
1184 mutable QList< QgsPointXY > mTransformedIntersections;
1185 QRectF mPrevPaintRect;
1186 mutable QPolygonF mPrevMapPolygon;
1188 bool mEvaluatedEnabled =
true;
1189 double mEvaluatedIntervalX = 0;
1190 double mEvaluatedIntervalY = 0;
1191 double mEvaluatedOffsetX = 0;
1192 double mEvaluatedOffsetY = 0;
1193 double mEvaluatedGridFrameWidth = 0;
1194 double mEvaluatedGridFrameMargin = 0;
1195 double mEvaluatedAnnotationFrameDistance = 0;
1196 double mEvaluatedCrossLength = 0;
1197 double mEvaluatedGridFrameLineThickness = 0;
1210 void updateGridLinesAnnotationsPositions()
const;
1216 void drawGridFrame( QPainter *p, GridExtension *extension =
nullptr )
const;
1231 void drawCoordinateAnnotation(
QgsRenderContext &context, GridLineAnnotation annot,
const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension =
nullptr )
const;
1233 QString gridAnnotationString(
double value, AnnotationCoordinate coord,
QgsExpressionContext &expressionContext )
const;
1239 int xGridLines()
const;
1245 int yGridLines()
const;
1253 void drawGridLine(
const QPolygonF &line,
QgsRenderContext &context )
const;
1259 void drawGridFrameBorder( QPainter *p, BorderSide border,
double *extension =
nullptr )
const;
1266 BorderSide borderForLineCoord( QPointF p, AnnotationCoordinate coordinateType )
const;
1271 static QList<QPolygonF> trimLinesToMap(
const QPolygonF &line,
const QgsRectangle &rect );
1273 QPolygonF scalePolygon(
const QPolygonF &polygon,
double scale )
const;
1276 void drawGridCrsTransform(
QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1278 void drawGridNoTransform(
QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1280 void createDefaultGridLineSymbol();
1282 void createDefaultGridMarkerSymbol();
1286 void drawGridFrameZebra( QPainter *p, GridExtension *extension =
nullptr )
const;
1288 void drawGridFrameZebraBorder( QPainter *p, BorderSide border,
double *extension =
nullptr )
const;
1290 void drawGridFrameTicks( QPainter *p, GridExtension *extension =
nullptr )
const;
1292 void drawGridFrameLine( QPainter *p, GridExtension *extension =
nullptr )
const;
1294 void calculateCrsTransformLines()
const;
1296 bool shouldShowDivisionForSide( AnnotationCoordinate coordinate, BorderSide side )
const;
1297 bool shouldShowAnnotationForSide( AnnotationCoordinate coordinate, BorderSide side )
const;
1298 bool shouldShowForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode )
const;
1299 void refreshDataDefinedProperties();
1302 double mapWidth()
const;
1304 friend class TestQgsLayoutMapGrid;
This class represents a coordinate reference system (CRS).
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 grid frame style.
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 annotated are not drawn.
double rotatedAnnotationsMinimumAngle() const
Gets the minimum angle (in degrees) below which annotated are not drawn.
void setAnnotationTextFormat(const QgsTextFormat &format)
Sets the text format to use when rendering grid annotations.
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.
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 ticks are not drawn.
double rotatedAnnotationsMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks 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.
void setAnnotationExpression(const QString &expression)
Sets the expression used for drawing grid annotations.
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.
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.
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)
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.
const QgsCoordinateReferenceSystem & crs