18 #ifndef QGSLAYOUTITEMMAPGRID_H 19 #define QGSLAYOUTITEMMAPGRID_H 21 #include "qgis_core.h" 70 void removeGrid(
const QString &gridId );
78 void moveGridUp(
const QString &gridId );
86 void moveGridDown(
const QString &gridId );
107 QList< QgsLayoutItemMapGrid * >
asList()
const;
116 double maxGridExtension()
const;
124 void calculateMaxGridExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
266 void draw( QPainter *painter )
override;
286 void setBlendMode(
const QPainter::CompositionMode mode ) { mBlendMode = mode; }
292 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
300 double maxExtension()
const;
308 void calculateMaxExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
334 void setIntervalX(
double interval );
350 void setIntervalY(
double interval );
366 void setOffsetX(
double offset );
374 double offsetX()
const {
return mGridOffsetX; }
382 void setOffsetY(
double offset );
390 double offsetY()
const {
return mGridOffsetY; }
431 void setGridLineWidth(
double width );
440 void setGridLineColor(
const QColor &color );
635 void setAnnotationExpression(
const QString &expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
679 void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
698 QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags()
const;
799 GridExtension() =
default;
807 mutable bool mTransformDirty =
true;
812 double mGridIntervalX = 0.0;
814 double mGridIntervalY = 0.0;
816 double mGridOffsetX = 0.0;
818 double mGridOffsetY = 0.0;
820 QFont mGridAnnotationFont;
822 QColor mGridAnnotationFontColor = Qt::black;
824 int mGridAnnotationPrecision = 3;
826 bool mShowGridAnnotation =
false;
847 double mAnnotationFrameDistance = 1.0;
859 QString mGridAnnotationExpressionString;
860 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
863 FrameSideFlags mGridFrameSides;
864 double mGridFrameWidth = 2.0;
865 double mGridFramePenThickness = 0.3;
866 QColor mGridFramePenColor = QColor( 0, 0, 0 );
867 QColor mGridFrameFillColor1 = Qt::white;
868 QColor mGridFrameFillColor2 = Qt::black;
869 double mCrossLength = 3.0;
880 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
881 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
887 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
889 mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
890 mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
891 mutable QList< QgsPointXY > mTransformedIntersections;
892 QRectF mPrevPaintRect;
893 mutable QPolygonF mPrevMapPolygon;
895 class QgsMapAnnotation
899 QPointF itemPosition;
907 void drawGridFrame( QPainter *p,
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines, GridExtension *extension =
nullptr )
const;
918 void drawCoordinateAnnotations( QPainter *p,
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines,
QgsExpressionContext &expressionContext, GridExtension *extension =
nullptr )
const;
924 void drawCoordinateAnnotation( QPainter *p, QPointF pos,
const QString &annotationString,
AnnotationCoordinate coordinateType, GridExtension *extension =
nullptr )
const;
933 void drawAnnotation( QPainter *p, QPointF pos,
int rotation,
const QString &annotationText )
const;
940 int xGridLines( QList< QPair< double, QLineF > > &lines )
const;
945 int yGridLines( QList< QPair< double, QLineF > > &lines )
const;
953 void drawGridLine(
const QPolygonF &line,
QgsRenderContext &context )
const;
955 void sortGridLinesOnBorders(
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines, QMap< double, double > &leftFrameEntries,
956 QMap< double, double > &rightFrameEntries, QMap< double, double > &topFrameEntries, QMap< double, double > &bottomFrameEntries )
const;
962 void drawGridFrameBorder( QPainter *p,
const QMap< double, double > &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
974 static QList<QPolygonF> trimLinesToMap(
const QPolygonF &line,
const QgsRectangle &rect );
976 QPolygonF scalePolygon(
const QPolygonF &polygon,
double scale )
const;
979 void drawGridCrsTransform(
QgsRenderContext &context,
double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
980 QList< QPair< double, QLineF > > &verticalLines,
bool calculateLinesOnly =
false )
const;
982 void drawGridNoTransform(
QgsRenderContext &context,
double dotsPerMM, QList<QPair<double, QLineF> > &horizontalLines, QList<QPair<double, QLineF> > &verticalLines,
bool calculateLinesOnly =
false )
const;
984 void createDefaultGridLineSymbol();
986 void createDefaultGridMarkerSymbol();
990 void drawGridFrameZebraBorder( QPainter *p,
const QMap<double, double> &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
992 void drawGridFrameTicks( QPainter *p,
const QMap<double, double> &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
994 void drawGridFrameLineBorder( QPainter *p,
BorderSide border,
double *extension =
nullptr )
const;
996 void calculateCrsTransformLines()
const;
1001 friend class TestQgsLayoutMapGrid;
1005 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItemMapGrid::FrameSideFlags )
1007 #endif // QGSLAYOUTITEMMAPGRID_H double offsetX() const
Returns the offset for grid lines in the x-direction.
void setAnnotationExpression(const QString &expression)
Sets the expression used for drawing grid annotations.
void setFramePenSize(const double width)
Sets the width of the stroke drawn in the grid frame.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
QgsExpressionContext createExpressionContext() const override
Creates an expression context relating to the objects' current state.
Degree/minutes/seconds, use NSEW suffix.
QString annotationExpression() const
Returns the expression used for drawing grid annotations.
void setAnnotationFontColor(const QColor &color)
Sets the font color used for drawing grid annotations.
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
int annotationPrecision() const
Returns the coordinate precision for grid annotations, which is the number of decimal places shown wh...
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
double frameWidth() const
Gets the grid frame width in layout units.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Draw annotations vertically, ascending.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
A collection of map items which are drawn above the map content in a QgsLayoutItemMap.
FrameStyle
Style for grid frame.
DisplayMode
Display settings for grid annotations and frames.
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
double framePenSize() const
Retrieves the width of the stroke drawn in the grid frame.
Grid units in millimeters.
Degree/minutes, use - for S/W coordinates.
const QgsCoordinateReferenceSystem & crs
Degree/minutes, use NSEW suffix.
QList< QgsLayoutItemMapItem * > asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
virtual bool usesAdvancedEffects() const
Returns true if the item is drawn using advanced effects, such as blend modes.
A marker symbol type, for rendering Point and MultiPoint geometries.
A line symbol type, for rendering LineString and MultiLineString geometries.
QFont annotationFont() const
Returns the font used for drawing grid annotations.
void setFrameWidth(const double width)
Sets the grid frame width (in layout units).
void setAnnotationFont(const QFont &font)
Sets the font used for drawing grid annotations.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
Draw line crosses at intersections of grid lines.
QColor annotationFontColor() const
Returns the font color used for drawing grid annotations.
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...
Tick markers drawn inside map frame.
Layout graphical items for displaying a map.
A collection of grids which is drawn above the map content in a QgsLayoutItemMap. ...
Draw annotations horizontally.
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
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...
Decimal degrees, use - for S/W coordinates.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
Decimal degrees, use NSEW suffix.
Show latitude/y annotations/divisions only.
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
GridUnit units() const
Returns the units used for grid measurements such as the interval and offset for grid lines...
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
AnnotationFormat
Format for displaying grid annotations.
double crossLength() const
Retrieves the length (in layout units) of the cross segments drawn for the grid.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
double intervalX() const
Returns the interval between grid lines in the x-direction.
An individual grid which is drawn above the map content in a QgsLayoutItemMap.
AnnotationDirection
Direction of grid annotations.
GridUnit
Unit for grid values.
Show both latitude and longitude annotations/divisions.
AnnotationPosition
Position for grid annotations.
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...
AnnotationCoordinate
Annotation coordinate type.
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
BorderSide
Border sides for annotations.
FrameStyle frameStyle() const
Returns the grid frame style.
Contains information about the context of a rendering operation.
Degree/minutes/seconds, with minutes using leading zeros where required.
Draw annotations vertically, descending.
Show longitude/x annotations/divisions only.
AnnotationFormat annotationFormat() const
Returns the format for drawing grid annotations.
void setCrossLength(const double length)
Sets the length (in layout units) of the cross segments drawn for the grid.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
Draw markers at intersections of grid lines.
Degree/minutes, with minutes using leading zeros where required.
This class represents a coordinate reference system (CRS).
double intervalY() const
Returns the interval between grid lines in the y-direction.
void setAnnotationFrameDistance(const double distance)
Sets the distance between the map frame and annotations.
GridStyle
Grid drawing style.
Tick markers drawn both inside and outside the map frame.
GridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
double annotationFrameDistance() const
Returns the distance between the map frame and annotations.
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
Draw annotations outside the map frame.
Grid units follow map units.
bool enabled() const
Returns whether the item will be drawn.
double offsetY() const
Returns the offset for grid lines in the y-direction.
Degree/minutes/seconds, use - for S/W coordinates.
bool annotationEnabled() const
Returns whether annotations are shown for the grid.
Tick markers drawn outside map frame.