QGIS API Documentation
3.16.0-Hannover (43b64b13f3)
|
Go to the documentation of this file.
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; }
316 double maxExtension()
const;
324 void calculateMaxExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
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 );
1013 struct GridExtension
1015 GridExtension() =
default;
1018 double bottom = 0.0;
1024 void UpdateBorder( BorderSide border,
double value )
1029 left = std::max( left, value );
1032 right = std::max( right, value );
1035 top = std::max( top, value );
1038 bottom = std::max( bottom, value );
1046 void UpdateAll(
double value )
1048 left = std::max( left, value );
1049 right = std::max( right, value );
1050 top = std::max( top, value );
1051 bottom = std::max( bottom, value );
1055 struct GridLineAnnotation
1072 GridLineAnnotation startAnnotation;
1073 GridLineAnnotation endAnnotation;
1075 mutable QList< GridLine > mGridLines;
1078 mutable bool mTransformDirty =
true;
1083 double mGridIntervalX = 0.0;
1085 double mGridIntervalY = 0.0;
1087 double mGridOffsetX = 0.0;
1089 double mGridOffsetY = 0.0;
1095 int mGridAnnotationPrecision = 3;
1097 bool mShowGridAnnotation =
false;
1118 double mAnnotationFrameDistance = 1.0;
1130 QString mGridAnnotationExpressionString;
1131 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
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;
1145 double mRotatedTicksMinimumAngle = 0.0;
1146 double mRotatedTicksMarginToCorner = 0.0;
1147 bool mRotatedAnnotationsEnabled =
false;
1149 double mRotatedAnnotationsMinimumAngle = 0.0;
1150 double mRotatedAnnotationsMarginToCorner = 0.0;
1152 double mMinimumIntervalWidth = 50;
1153 double mMaximumIntervalWidth = 100;
1164 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
1165 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
1169 GridUnit mGridUnit = MapUnit;
1171 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
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;
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;
1201 void updateGridLinesAnnotationsPositions()
const;
1207 void drawGridFrame( QPainter *p, GridExtension *extension =
nullptr )
const;
1222 void drawCoordinateAnnotation(
QgsRenderContext &context, GridLineAnnotation annot,
const QString &annotationString, AnnotationCoordinate coordinateType, GridExtension *extension =
nullptr )
const;
1224 QString gridAnnotationString(
double value, AnnotationCoordinate coord,
QgsExpressionContext &expressionContext )
const;
1230 int xGridLines()
const;
1236 int yGridLines()
const;
1244 void drawGridLine(
const QPolygonF &line,
QgsRenderContext &context )
const;
1250 void drawGridFrameBorder( QPainter *p, BorderSide border,
double *extension =
nullptr )
const;
1257 BorderSide borderForLineCoord( QPointF p, AnnotationCoordinate coordinateType )
const;
1262 static QList<QPolygonF> trimLinesToMap(
const QPolygonF &line,
const QgsRectangle &rect );
1264 QPolygonF scalePolygon(
const QPolygonF &polygon,
double scale )
const;
1267 void drawGridCrsTransform(
QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1269 void drawGridNoTransform(
QgsRenderContext &context,
double dotsPerMM,
bool calculateLinesOnly =
false )
const;
1271 void createDefaultGridLineSymbol();
1273 void createDefaultGridMarkerSymbol();
1277 void drawGridFrameZebra( QPainter *p, GridExtension *extension =
nullptr )
const;
1279 void drawGridFrameZebraBorder( QPainter *p, BorderSide border,
double *extension =
nullptr )
const;
1281 void drawGridFrameTicks( QPainter *p, GridExtension *extension =
nullptr )
const;
1283 void drawGridFrameLine( QPainter *p, GridExtension *extension =
nullptr )
const;
1285 void calculateCrsTransformLines()
const;
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();
1293 double mapWidth()
const;
1295 friend class TestQgsLayoutMapGrid;
1301 #endif // QGSLAYOUTITEMMAPGRID_H
TickLengthMode rotatedAnnotationsLengthMode() const
Returns the grid frame style.
TickLengthMode
Tick length mode (useful for rotated grids)
double intervalX() const
Returns the interval between grid lines in the x-direction.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual void setEnabled(bool enabled)
Controls whether the item will be drawn.
@ Zebra
Black/white pattern.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
@ InteriorTicks
Tick markers drawn inside map frame.
@ VerticalDescending
Draw annotations vertically, descending.
@ LongitudeOnly
Show longitude/x annotations/divisions only.
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...
GridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
@ DynamicPageSizeBased
Dynamically sized, based on a on-page size range.
void setRotatedTicksEnabled(const bool state)
Enable/disable ticks rotation for rotated or reprojected grids.
The class is used as a container of context for various read/write operations on other objects.
QString annotationExpression() const
Returns the expression used for drawing grid annotations.
double rotatedAnnotationsMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
@ OutsideMapFrame
Draw annotations outside the map frame.
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
const QgsCoordinateReferenceSystem & crs
@ ExteriorTicks
Tick markers drawn outside map frame.
@ ShowAll
Show both latitude and longitude annotations/divisions.
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
TickLengthMode rotatedTicksLengthMode() const
Returns the grid frame style.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
GridStyle
Grid drawing style.
double maximumIntervalWidth() const
Returns the maximum width (in millimeters) for grid segments.
Contains information about the context of a rendering operation.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
An interface for classes which can visit style entity (e.g.
AnnotationFormat annotationFormat() const
Returns the format for drawing grid annotations.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
@ ZebraNautical
Black/white pattern, with nautical style diagonals on corners.
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
@ DegreeMinutePadded
Degree/minutes, with minutes using leading zeros where required.
double intervalY() const
Returns the interval between grid lines in the y-direction.
void setRotatedTicksMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
@ CM
Grid units in centimeters.
double rotatedAnnotationsMinimumAngle() const
Gets the minimum angle (in degrees) below which annotated are not drawn.
int annotationPrecision() const
Returns the coordinate precision for grid annotations, which is the number of decimal places shown wh...
DisplayMode
Display settings for grid annotations and frames.
double offsetX() const
Returns the offset for grid lines in the x-direction.
A rectangle specified with double values.
@ BoundaryDirection
Annotations follow the boundary direction.
@ InteriorExteriorTicks
Tick markers drawn both inside and outside the map frame.
void setRotatedTicksLengthMode(const TickLengthMode mode)
Sets the tick length calculation mode.
void setRotatedAnnotationsMarginToCorner(const double margin)
Sets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
@ LatitudeOnly
Show latitude/y annotations/divisions only.
double rotatedTicksMarginToCorner() const
Gets the margin to corners (in canvas units) below which outwards facing ticks are not drawn.
@ NormalizedTicks
Constant tick lengths.
void setRotatedAnnotationsLengthMode(const TickLengthMode mode)
Sets the annotation length calculation mode.
Container for all settings relating to text rendering.
void setAnnotationExpression(const QString &expression)
Sets the expression used for drawing grid annotations.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
void setRotatedAnnotationsEnabled(const bool state)
Enable/disable annotations rotation for rotated or reprojected grids.
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
double rotatedAnnotationsEnabled() const
Gets whether annotations rotation for rotated or reprojected grids is enabled.
GridUnit
Unit for grid values.
A marker symbol type, for rendering Point and MultiPoint geometries.
AnnotationDirection
Direction of grid annotations.
void setRotatedTicksMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which ticks are not drawn.
@ MapUnit
Grid units follow map units.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
@ LineBorderNautical
Simple solid line frame, with nautical style diagonals on corners.
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.
@ DegreeMinuteSecondPadded
Degree/minutes/seconds, with minutes using leading zeros where required.
A line symbol type, for rendering LineString and MultiLineString geometries.
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...
double annotationFrameDistance() const
Returns the distance between the map frame and annotations.
AnnotationPosition
Position for grid annotations.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
virtual bool usesAdvancedEffects() const
Returns true if the item is drawn using advanced effects, such as blend modes.
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
BorderSide
Border sides for annotations.
double crossLength() const
Retrieves the length (in layout units) of the cross segments drawn for the grid.
This class represents a coordinate reference system (CRS).
QList< QgsLayoutItemMapItem * > asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
double rotatedTicksEnabled() const
Gets whether ticks rotation for rotated or reprojected grids is enabled.
@ Cross
Draw line crosses at intersections of grid lines.
Layout graphical items for displaying a map.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
void setAnnotationTextFormat(const QgsTextFormat &format)
Sets the text format to use when rendering grid annotations.
double frameWidth() const
Gets the grid frame width in layout units.
GridUnit units() const
Returns the units used for grid measurements such as the interval and offset for grid lines.
@ Horizontal
Draw annotations horizontally.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
double rotatedTicksMinimumAngle() const
Gets the minimum angle (in degrees) below which ticks are not drawn.
@ Vertical
Draw annotations vertically, ascending.
@ DegreeMinute
Degree/minutes, use NSEW suffix.
@ DecimalWithSuffix
Decimal degrees, use NSEW suffix.
@ DegreeMinuteNoSuffix
Degree/minutes, use - for S/W coordinates.
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...
void setRotatedAnnotationsMinimumAngle(const double angle)
Sets the minimum angle (in degrees) below which annotated are not drawn.
@ DegreeMinuteSecond
Degree/minutes/seconds, use NSEW suffix.
@ NoFrame
Disable grid frame.
AnnotationFormat
Format for displaying grid annotations.
@ DegreeMinuteSecondNoSuffix
Degree/minutes/seconds, use - for S/W coordinates.
@ AboveTick
Draw annotations parallel to tick (above the line)
@ Decimal
Decimal degrees, use - for S/W coordinates.
double frameMargin() const
Sets the grid frame Margin (in layout units).
QgsTextFormat annotationTextFormat() const
Returns the text format used when rendering grid annotations.
FrameStyle frameStyle() const
Returns the grid frame style.
@ OrthogonalTicks
Align ticks orthogonaly.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
@ Markers
Draw markers at intersections of grid lines.
bool annotationEnabled() const
Returns whether annotations are shown for the grid.
A collection of grids which is drawn above the map content in a QgsLayoutItemMap.
double offsetY() const
Returns the offset for grid lines in the y-direction.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
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)
@ LineBorder
Simple solid line frame.
AnnotationCoordinate
Annotation coordinate type.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
@ UnderTick
Draw annotations parallel to tick (under the line)
double minimumIntervalWidth() const
Returns the minimum width (in millimeters) for grid segments.
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
bool enabled() const
Returns whether the item will be drawn.
FrameStyle
Style for grid frame.
@ OnTick
Draw annotations parallel to tick (on the line)
double framePenSize() const
Retrieves the width of the stroke drawn in the grid frame.
@ MM
Grid units in millimeters.