@@ -278,9 +278,11 @@ bool QgsLayoutItemMapGrid::writeXml( QDomElement &elem, QDomDocument &doc, const
278
278
mapGridElem.setAttribute ( QStringLiteral ( " rotatedTicksLengthMode" ), mRotatedTicksLengthMode );
279
279
mapGridElem.setAttribute ( QStringLiteral ( " rotatedTicksEnabled" ), mRotatedTicksEnabled );
280
280
mapGridElem.setAttribute ( QStringLiteral ( " rotatedTicksMinimumAngle" ), QString::number ( mRotatedTicksMinimumAngle ) );
281
+ mapGridElem.setAttribute ( QStringLiteral ( " rotatedTicksMarginToCorner" ), QString::number ( mRotatedTicksMarginToCorner ) );
281
282
mapGridElem.setAttribute ( QStringLiteral ( " rotatedAnnotationsLengthMode" ), mRotatedAnnotationsLengthMode );
282
283
mapGridElem.setAttribute ( QStringLiteral ( " rotatedAnnotationsEnabled" ), mRotatedAnnotationsEnabled );
283
284
mapGridElem.setAttribute ( QStringLiteral ( " rotatedAnnotationsMinimumAngle" ), QString::number ( mRotatedAnnotationsMinimumAngle ) );
285
+ mapGridElem.setAttribute ( QStringLiteral ( " rotatedAnnotationsMarginToCorner" ), QString::number ( mRotatedAnnotationsMarginToCorner ) );
284
286
if ( mCRS .isValid () )
285
287
{
286
288
mCRS .writeXml ( mapGridElem, doc );
@@ -346,9 +348,11 @@ bool QgsLayoutItemMapGrid::readXml( const QDomElement &itemElem, const QDomDocum
346
348
mRotatedTicksLengthMode = TickLengthMode ( itemElem.attribute ( QStringLiteral ( " rotatedTicksLengthMode" ), QStringLiteral ( " 0" ) ).toInt () );
347
349
mRotatedTicksEnabled = itemElem.attribute ( QStringLiteral ( " rotatedTicksEnabled" ), QStringLiteral ( " 0" ) ) != QLatin1String ( " 0" );
348
350
mRotatedTicksMinimumAngle = itemElem.attribute ( QStringLiteral ( " rotatedTicksMinimumAngle" ), QStringLiteral ( " 0" ) ).toDouble ();
351
+ mRotatedTicksMarginToCorner = itemElem.attribute ( QStringLiteral ( " rotatedTicksMarginToCorner" ), QStringLiteral ( " 0" ) ).toDouble ();
349
352
mRotatedAnnotationsLengthMode = TickLengthMode ( itemElem.attribute ( QStringLiteral ( " rotatedAnnotationsLengthMode" ), QStringLiteral ( " 0" ) ).toInt () );
350
353
mRotatedAnnotationsEnabled = itemElem.attribute ( QStringLiteral ( " rotatedAnnotationsEnabled" ), QStringLiteral ( " 0" ) ) != QLatin1String ( " 0" );
351
354
mRotatedAnnotationsMinimumAngle = itemElem.attribute ( QStringLiteral ( " rotatedAnnotationsMinimumAngle" ), QStringLiteral ( " 0" ) ).toDouble ();
355
+ mRotatedAnnotationsMarginToCorner = itemElem.attribute ( QStringLiteral ( " rotatedAnnotationsMarginToCorner" ), QStringLiteral ( " 0" ) ).toDouble ();
352
356
353
357
QDomElement lineStyleElem = itemElem.firstChildElement ( QStringLiteral ( " lineStyle" ) );
354
358
if ( !lineStyleElem.isNull () )
@@ -666,9 +670,9 @@ void QgsLayoutItemMapGrid::updateGridLinesAnnotationsPositions() const
666
670
it->startAnnotation .vector = QVector2D ( it->line .at ( 1 ) - it->line .first () ).normalized ();
667
671
it->endAnnotation .vector = QVector2D ( it->line .at ( it->line .count () - 2 ) - it->line .last () ).normalized ();
668
672
QVector2D normS = borderToNormal2D ( it->startAnnotation .border );
669
- it->startAnnotation .angle = abs ( M_PI / 2.0 - acos ( QVector2D::dotProduct ( it->startAnnotation .vector , normS ) / ( it->startAnnotation .vector .length () * normS.length () ) ) );
673
+ it->startAnnotation .angle = atan2 ( it-> startAnnotation . vector . x () * normS. y () - it->startAnnotation .vector . y () * normS. x (), it->startAnnotation .vector .x () * normS.x () + it-> startAnnotation . vector . y () * normS. y ( ) );
670
674
QVector2D normE = borderToNormal2D ( it->endAnnotation .border );
671
- it->endAnnotation .angle = abs ( M_PI / 2.0 - acos ( QVector2D::dotProduct ( it->endAnnotation .vector , normE ) / ( it->endAnnotation .vector .length () * normE.length () ) ) );
675
+ it->endAnnotation .angle = atan2 ( it-> endAnnotation . vector . x () * normE. y () - it->endAnnotation .vector . y () * normE. x (), it->endAnnotation .vector .x () * normE.x () + it-> endAnnotation . vector . y () * normE. y ( ) );
672
676
}
673
677
}
674
678
@@ -1013,7 +1017,39 @@ void QgsLayoutItemMapGrid::drawGridFrameTicks( QPainter *p, GridExtension *exten
1013
1017
continue ;
1014
1018
1015
1019
// If the angle is below the threshold, we don't draw the annotation
1016
- if ( annot.angle < mRotatedTicksMinimumAngle * M_PI / 180.0 )
1020
+ if ( abs ( annot.angle ) / M_PI * 180.0 > 90.0 - mRotatedTicksMinimumAngle )
1021
+ continue ;
1022
+
1023
+ // Skip outwards facing annotations that are below mRotatedTicksMarginToCorner
1024
+ bool facingLeft;
1025
+ bool facingRight;
1026
+ if ( mGridFrameStyle == QgsLayoutItemMapGrid::InteriorExteriorTicks )
1027
+ {
1028
+ facingLeft = ( annot.angle != 0 );
1029
+ facingRight = ( annot.angle != 0 );
1030
+ }
1031
+ else if ( mGridFrameStyle == QgsLayoutItemMapGrid::ExteriorTicks )
1032
+ {
1033
+ facingLeft = ( annot.angle > 0 );
1034
+ facingRight = ( annot.angle < 0 );
1035
+ }
1036
+ else
1037
+ {
1038
+ facingLeft = ( annot.angle < 0 );
1039
+ facingRight = ( annot.angle > 0 );
1040
+ }
1041
+
1042
+ if ( annot.border == BorderSide::Top && ( ( facingLeft && annot.position .x () < mRotatedTicksMarginToCorner ) ||
1043
+ ( facingRight && annot.position .x () > mMap ->rect ().width () - mRotatedTicksMarginToCorner ) ) )
1044
+ continue ;
1045
+ if ( annot.border == BorderSide::Bottom && ( ( facingLeft && annot.position .x () > mMap ->rect ().width () - mRotatedTicksMarginToCorner ) ||
1046
+ ( facingRight && annot.position .x () < mRotatedTicksMarginToCorner ) ) )
1047
+ continue ;
1048
+ if ( annot.border == BorderSide::Left && ( ( facingLeft && annot.position .y () > mMap ->rect ().height () - mRotatedTicksMarginToCorner ) ||
1049
+ ( facingRight && annot.position .y () < mRotatedTicksMarginToCorner ) ) )
1050
+ continue ;
1051
+ if ( annot.border == BorderSide::Right && ( ( facingLeft && annot.position .y () < mRotatedTicksMarginToCorner ) ||
1052
+ ( facingRight && annot.position .y () > mMap ->rect ().height () - mRotatedTicksMarginToCorner ) ) )
1017
1053
continue ;
1018
1054
1019
1055
QVector2D normalVector = borderToNormal2D ( annot.border );
@@ -1179,9 +1215,8 @@ void QgsLayoutItemMapGrid::drawCoordinateAnnotation( QgsRenderContext &context,
1179
1215
AnnotationPosition anotPos = annotationPosition ( frameBorder );
1180
1216
AnnotationDirection anotDir = annotationDirection ( frameBorder );
1181
1217
1182
-
1183
1218
// If the angle is below the threshold, we don't draw the annotation
1184
- if ( annot.angle < mRotatedAnnotationsMinimumAngle * M_PI / 180.0 )
1219
+ if ( abs ( annot.angle ) / M_PI * 180.0 > 90.0 - mRotatedAnnotationsMinimumAngle )
1185
1220
return ;
1186
1221
1187
1222
QVector2D normalVector = borderToNormal2D ( annot.border );
@@ -1302,10 +1337,30 @@ void QgsLayoutItemMapGrid::drawCoordinateAnnotation( QgsRenderContext &context,
1302
1337
extension->UpdateAll ( textWidth / 2.0 );
1303
1338
}
1304
1339
1305
-
1306
1340
if ( extension || !context.painter () )
1307
1341
return ;
1308
1342
1343
+ // Skip outwards facing annotations that are below mRotatedAnnotationsMarginToCorner
1344
+ bool facingLeft = ( annot.angle < 0 );
1345
+ bool facingRight = ( annot.angle > 0 );
1346
+ if ( anotPos == QgsLayoutItemMapGrid::OutsideMapFrame )
1347
+ {
1348
+ facingLeft = !facingLeft;
1349
+ facingRight = !facingRight;
1350
+ }
1351
+ if ( annot.border == BorderSide::Top && ( ( facingLeft && xpos < mRotatedAnnotationsMarginToCorner ) ||
1352
+ ( facingRight && xpos > mMap ->rect ().width () - mRotatedAnnotationsMarginToCorner ) ) )
1353
+ return ;
1354
+ if ( annot.border == BorderSide::Bottom && ( ( facingLeft && xpos > mMap ->rect ().width () - mRotatedAnnotationsMarginToCorner ) ||
1355
+ ( facingRight && xpos < mRotatedAnnotationsMarginToCorner ) ) )
1356
+ return ;
1357
+ if ( annot.border == BorderSide::Left && ( ( facingLeft && ypos > mMap ->rect ().height () - mRotatedAnnotationsMarginToCorner ) ||
1358
+ ( facingRight && ypos < mRotatedAnnotationsMarginToCorner ) ) )
1359
+ return ;
1360
+ if ( annot.border == BorderSide::Right && ( ( facingLeft && ypos < mRotatedAnnotationsMarginToCorner ) ||
1361
+ ( facingRight && ypos > mMap ->rect ().height () - mRotatedAnnotationsMarginToCorner ) ) )
1362
+ return ;
1363
+
1309
1364
QgsScopedQPainterState painterState ( context.painter () );
1310
1365
context.painter ()->translate ( QPointF ( xpos, ypos ) );
1311
1366
context.painter ()->rotate ( rotation );
0 commit comments