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;
250 Q_DECLARE_FLAGS( FrameSideFlags, FrameSideFlag )
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;
323 void setUnits( GridUnit unit );
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 );
449 void setStyle( GridStyle style );
463 void setCrossLength(
const double length );
479 void setGridLineWidth(
double width );
488 void setGridLineColor(
const QColor &color );
609 void setAnnotationDisplay( DisplayMode display, BorderSide border );
619 DisplayMode annotationDisplay( BorderSide border )
const;
626 void setAnnotationPosition( AnnotationPosition position, BorderSide side );
633 AnnotationPosition annotationPosition( BorderSide side )
const;
639 void setAnnotationFrameDistance(
const double distance );
651 void setAnnotationDirection( AnnotationDirection direction, BorderSide side );
657 void setAnnotationDirection( AnnotationDirection direction );
664 AnnotationDirection annotationDirection( BorderSide border )
const;
683 void setAnnotationExpression(
const QString &expression ) { mGridAnnotationExpressionString = expression; mGridAnnotationExpression.reset(); }
712 void setFrameDivisions( DisplayMode divisions, BorderSide side );
718 DisplayMode frameDivisions( BorderSide side )
const;
727 void setFrameSideFlags( QgsLayoutItemMapGrid::FrameSideFlags flags );
746 QgsLayoutItemMapGrid::FrameSideFlags frameSideFlags()
const;
757 bool testFrameSideFlag( FrameSideFlag flag )
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;
955 GridUnit mGridUnit = MapUnit;
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;
1016 QString gridAnnotationString(
double value, AnnotationCoordinate coord,
QgsExpressionContext &expressionContext )
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;
1050 BorderSide borderForLineCoord( QPointF p, AnnotationCoordinate coordinateType )
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;
1079 bool shouldShowDivisionForSide( AnnotationCoordinate coordinate, BorderSide side )
const;
1080 bool shouldShowDivisionForDisplayMode( AnnotationCoordinate coordinate, DisplayMode mode )
const;
1081 void refreshDataDefinedProperties();
1084 double mapWidth()
const;
1086 friend class TestQgsLayoutMapGrid;
1090 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsLayoutItemMapGrid::FrameSideFlags )
1092 #endif // QGSLAYOUTITEMMAPGRID_H