18 #ifndef QGSLAYOUTITEMMAPGRID_H 19 #define QGSLAYOUTITEMMAPGRID_H 21 #include "qgis_core.h" 69 void removeGrid(
const QString &gridId );
77 void moveGridUp(
const QString &gridId );
85 void moveGridDown(
const QString &gridId );
106 QList< QgsLayoutItemMapGrid * >
asList()
const;
115 double maxGridExtension()
const;
123 void calculateMaxGridExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
268 void draw( QPainter *painter )
override;
288 void setBlendMode(
const QPainter::CompositionMode mode ) { mBlendMode = mode; }
294 QPainter::CompositionMode
blendMode()
const {
return mBlendMode; }
302 double maxExtension()
const;
310 void calculateMaxExtension(
double &top,
double &right,
double &bottom,
double &left )
const;
338 void setIntervalX(
double interval );
354 void setIntervalY(
double interval );
370 void setOffsetX(
double offset );
378 double offsetX()
const {
return mGridOffsetX; }
386 void setOffsetY(
double offset );
394 double offsetY()
const {
return mGridOffsetY; }
416 void setMinimumIntervalWidth(
double width );
438 void setMaximumIntervalWidth(
double width );
463 void setCrossLength(
const double length );
479 void setGridLineWidth(
double width );
488 void setGridLineColor(
const QColor &color );
639 void setAnnotationFrameDistance(
const double distance );
683 void setAnnotationExpression(
const QString &expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
727 void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
746 QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags()
const;
765 void setFrameWidth(
const double width );
781 void setFrameMargin(
const double margin );
796 void setFramePenSize(
const double width );
865 GridExtension() =
default;
873 mutable bool mTransformDirty =
true;
878 double mGridIntervalX = 0.0;
880 double mGridIntervalY = 0.0;
882 double mGridOffsetX = 0.0;
884 double mGridOffsetY = 0.0;
886 QFont mGridAnnotationFont;
888 QColor mGridAnnotationFontColor = Qt::black;
890 int mGridAnnotationPrecision = 3;
892 bool mShowGridAnnotation =
false;
913 double mAnnotationFrameDistance = 1.0;
925 QString mGridAnnotationExpressionString;
926 mutable std::unique_ptr< QgsExpression > mGridAnnotationExpression;
929 FrameSideFlags mGridFrameSides;
930 double mGridFrameWidth = 2.0;
931 double mGridFramePenThickness = 0.3;
932 QColor mGridFramePenColor = QColor( 0, 0, 0 );
933 QColor mGridFrameFillColor1 = Qt::white;
934 QColor mGridFrameFillColor2 = Qt::black;
935 double mCrossLength = 3.0;
936 double mGridFrameMargin = 0.0;
938 double mMinimumIntervalWidth = 50;
939 double mMaximumIntervalWidth = 100;
950 std::unique_ptr< QgsLineSymbol > mGridLineSymbol;
951 std::unique_ptr< QgsMarkerSymbol > mGridMarkerSymbol;
957 QPainter::CompositionMode mBlendMode = QPainter::CompositionMode_SourceOver;
959 mutable QList< QPair< double, QPolygonF > > mTransformedXLines;
960 mutable QList< QPair< double, QPolygonF > > mTransformedYLines;
961 mutable QList< QgsPointXY > mTransformedIntersections;
962 QRectF mPrevPaintRect;
963 mutable QPolygonF mPrevMapPolygon;
965 bool mEvaluatedEnabled =
true;
966 double mEvaluatedIntervalX = 0;
967 double mEvaluatedIntervalY = 0;
968 double mEvaluatedOffsetX = 0;
969 double mEvaluatedOffsetY = 0;
970 double mEvaluatedGridFrameWidth = 0;
971 double mEvaluatedGridFrameMargin = 0;
972 double mEvaluatedAnnotationFrameDistance = 0;
973 double mEvaluatedCrossLength = 0;
974 double mEvaluatedGridFrameLineThickness = 0;
976 class QgsMapAnnotation
980 QPointF itemPosition;
988 void drawGridFrame( QPainter *p,
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines, GridExtension *extension =
nullptr )
const;
999 void drawCoordinateAnnotations( QPainter *p,
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines,
QgsExpressionContext &expressionContext, GridExtension *extension =
nullptr )
const;
1005 void drawCoordinateAnnotation( QPainter *p, QPointF pos,
const QString &annotationString,
AnnotationCoordinate coordinateType, GridExtension *extension =
nullptr )
const;
1014 void drawAnnotation( QPainter *p, QPointF pos,
int rotation,
const QString &annotationText )
const;
1021 int xGridLines( QList< QPair< double, QLineF > > &lines )
const;
1026 int yGridLines( QList< QPair< double, QLineF > > &lines )
const;
1034 void drawGridLine(
const QPolygonF &line,
QgsRenderContext &context )
const;
1036 void sortGridLinesOnBorders(
const QList< QPair< double, QLineF > > &hLines,
const QList< QPair< double, QLineF > > &vLines, QMap< double, double > &leftFrameEntries,
1037 QMap< double, double > &rightFrameEntries, QMap< double, double > &topFrameEntries, QMap< double, double > &bottomFrameEntries )
const;
1043 void drawGridFrameBorder( QPainter *p,
const QMap< double, double > &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
1055 static QList<QPolygonF> trimLinesToMap(
const QPolygonF &line,
const QgsRectangle &rect );
1057 QPolygonF scalePolygon(
const QPolygonF &polygon,
double scale )
const;
1060 void drawGridCrsTransform(
QgsRenderContext &context,
double dotsPerMM, QList< QPair< double, QLineF > > &horizontalLines,
1061 QList< QPair< double, QLineF > > &verticalLines,
bool calculateLinesOnly =
false )
const;
1063 void drawGridNoTransform(
QgsRenderContext &context,
double dotsPerMM, QList<QPair<double, QLineF> > &horizontalLines, QList<QPair<double, QLineF> > &verticalLines,
bool calculateLinesOnly =
false )
const;
1065 void createDefaultGridLineSymbol();
1067 void createDefaultGridMarkerSymbol();
1071 void drawGridFrameZebraBorder( QPainter *p,
const QMap<double, double> &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
1073 void drawGridFrameTicks( QPainter *p,
const QMap<double, double> &borderPos,
BorderSide border,
double *extension =
nullptr )
const;
1075 void drawGridFrameLineBorder( QPainter *p,
BorderSide border,
double *extension =
nullptr )
const;
1077 void calculateCrsTransformLines()
const;
1081 void refreshDataDefinedProperties();
1084 double mapWidth()
const;
1086 friend class TestQgsLayoutMapGrid;
1090 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItemMapGrid::FrameSideFlags )
1092 #endif // QGSLAYOUTITEMMAPGRID_H void setAnnotationExpression(const QString &expression)
Sets the expression used for drawing grid annotations.
double offsetY() const
Returns the offset for grid lines in the y-direction.
The class is used as a container of context for various read/write operations on other objects...
A rectangle specified with double values.
double intervalX() const
Returns the interval between grid lines in the x-direction.
Degree/minutes/seconds, use NSEW suffix.
bool annotationEnabled() const
Returns whether annotations are shown for the grid.
void setAnnotationFontColor(const QColor &color)
Sets the font color used for drawing grid annotations.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
QColor framePenColor() const
Retrieves the color of the stroke drawn in the grid frame.
QColor annotationFontColor() const
Returns the font color used for drawing grid annotations.
double framePenSize() const
Retrieves the width of the stroke drawn in the grid frame.
FrameSideFlag
Flags for controlling which side of the map a frame is drawn on.
An item which is drawn inside a QgsLayoutItemMap, e.g., a grid or map overview.
Draw annotations vertically, ascending.
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.
double intervalY() const
Returns the interval between grid lines in the y-direction.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
double crossLength() const
Retrieves the length (in layout units) of the cross segments drawn for the grid.
Grid units in millimeters.
Degree/minutes, use - for S/W coordinates.
double offsetX() const
Returns the offset for grid lines in the x-direction.
double maximumIntervalWidth() const
Returns the maximum width (in millimeters) for grid segments.
QFont annotationFont() const
Returns the font used for drawing grid annotations.
double frameMargin() const
Sets the grid frame Margin (in layout units).
const QgsCoordinateReferenceSystem & crs
Degree/minutes, use NSEW suffix.
An interface for classes which can visit style entity (e.g.
int annotationPrecision() const
Returns the coordinate precision for grid annotations, which is the number of decimal places shown wh...
A marker symbol type, for rendering Point and MultiPoint geometries.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
A line symbol type, for rendering LineString and MultiLineString geometries.
void setAnnotationFont(const QFont &font)
Sets the font used for drawing grid annotations.
virtual bool usesAdvancedEffects() const
Returns true if the item is drawn using advanced effects, such as blend modes.
Draw line crosses at intersections of grid lines.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
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.
AnnotationFormat annotationFormat() const
Returns the format for drawing grid annotations.
Grid units in centimeters.
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...
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
QString annotationExpression() const
Returns the expression used for drawing grid annotations.
void setFramePenColor(const QColor &color)
Sets the color of the stroke drawn in the grid frame.
Decimal degrees, use NSEW suffix.
bool enabled() const
Returns whether the item will be drawn.
Show latitude/y annotations/divisions only.
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
Dynamically sized, based on a on-page size range.
virtual void draw(QPainter *painter)=0
Draws the item on to a destination painter.
AnnotationFormat
Format for displaying grid annotations.
double annotationFrameDistance() const
Returns the distance between the map frame and annotations.
QgsLayoutItemMapItem & operator[](int index)
Returns a reference to an item at the specified index within the stack.
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.
QList< QgsLayoutItemMapItem *> asList() const
Returns a list of QgsLayoutItemMapItems contained by the stack.
double minimumIntervalWidth() const
Returns the minimum width (in millimeters) for grid segments.
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
BorderSide
Border sides for annotations.
virtual bool accept(QgsStyleEntityVisitorInterface *visitor) const
Accepts the specified style entity visitor, causing it to visit all style entities associated with th...
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.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
Draw markers at intersections of grid lines.
FrameStyle frameStyle() const
Returns the grid frame style.
Black/white pattern, with nautical style diagonals on corners.
Degree/minutes, with minutes using leading zeros where required.
This class represents a coordinate reference system (CRS).
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...
GridStyle
Grid drawing style.
Simple solid line frame, with nautical style diagonals on corners.
Tick markers drawn both inside and outside the map frame.
virtual void refresh()
Refreshes the object, causing a recalculation of any property overrides.
virtual void setEnabled(bool enabled)
Controls whether the item will be drawn.
GridStyle style() const
Returns the grid's style, which controls how the grid is drawn over the map's contents.
Draw annotations outside the map frame.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
Grid units follow map units.
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...
QgsCoordinateReferenceSystem crs() const
Retrieves the CRS for the grid.
Degree/minutes/seconds, use - for S/W coordinates.
Tick markers drawn outside map frame.