Skip to content
Permalink
Browse files

[rotated_ticks] prepare_commit and tests

  • Loading branch information
olivierdalang committed Sep 1, 2020
1 parent b80e252 commit 426c869aef96c972b6dfdad4aeee9d0c72df2ee9
@@ -899,6 +899,20 @@ Sets the ``minimum`` angle (in degrees) below which ticks are not drawn.
Gets the ``minimum`` angle (in degrees) below which ticks are not drawn.

.. seealso:: :py:func:`setRotatedTicksMinimumAngle`
%End

void setRotatedTicksMarginToCorner( const double margin );
%Docstring
Sets the ``margin`` to corners (in canvas units) below which outwards facing ticks are not drawn.

.. seealso:: :py:func:`rotatedTicksMarginToCorner`
%End

double rotatedTicksMarginToCorner() const;
%Docstring
Gets the ``margin`` to corners (in canvas units) below which outwards facing ticks are not drawn.

.. seealso:: :py:func:`setRotatedTicksMarginToCorner`
%End

void setRotatedAnnotationsEnabled( const bool state );
@@ -941,6 +955,20 @@ Sets the ``minimum`` angle (in degrees) below which annotated are not drawn.
Gets the ``minimum`` angle (in degrees) below which annotated are not drawn.

.. seealso:: :py:func:`setRotatedAnnotationsMinimumAngle`
%End

void setRotatedAnnotationsMarginToCorner( const double margin );
%Docstring
Sets the ``margin`` to corners (in canvas units) below which outwards facing ticks are not drawn.

.. seealso:: :py:func:`rotatedAnnotationsMarginToCorner`
%End

double rotatedAnnotationsMarginToCorner() const;
%Docstring
Gets the ``margin`` to corners (in canvas units) below which outwards facing ticks are not drawn.

.. seealso:: :py:func:`setRotatedAnnotationsMarginToCorner`
%End

void setFrameMargin( const double margin );
@@ -1040,16 +1040,16 @@ void QgsLayoutItemMapGrid::drawGridFrameTicks( QPainter *p, GridExtension *exten
}

if ( annot.border == BorderSide::Top && ( ( facingLeft && annot.position.x() < mRotatedTicksMarginToCorner ) ||
( facingRight && annot.position.x() > mMap->rect().width() - mRotatedTicksMarginToCorner ) ) )
( facingRight && annot.position.x() > mMap->rect().width() - mRotatedTicksMarginToCorner ) ) )
continue;
if ( annot.border == BorderSide::Bottom && ( ( facingLeft && annot.position.x() > mMap->rect().width() - mRotatedTicksMarginToCorner ) ||
( facingRight && annot.position.x() < mRotatedTicksMarginToCorner ) ) )
( facingRight && annot.position.x() < mRotatedTicksMarginToCorner ) ) )
continue;
if ( annot.border == BorderSide::Left && ( ( facingLeft && annot.position.y() > mMap->rect().height() - mRotatedTicksMarginToCorner ) ||
( facingRight && annot.position.y() < mRotatedTicksMarginToCorner ) ) )
( facingRight && annot.position.y() < mRotatedTicksMarginToCorner ) ) )
continue;
if ( annot.border == BorderSide::Right && ( ( facingLeft && annot.position.y() < mRotatedTicksMarginToCorner ) ||
( facingRight && annot.position.y() > mMap->rect().height() - mRotatedTicksMarginToCorner ) ) )
( facingRight && annot.position.y() > mMap->rect().height() - mRotatedTicksMarginToCorner ) ) )
continue;

QVector2D normalVector = borderToNormal2D( annot.border );
@@ -1349,16 +1349,16 @@ void QgsLayoutItemMapGrid::drawCoordinateAnnotation( QgsRenderContext &context,
facingRight = !facingRight;
}
if ( annot.border == BorderSide::Top && ( ( facingLeft && xpos < mRotatedAnnotationsMarginToCorner ) ||
( facingRight && xpos > mMap->rect().width() - mRotatedAnnotationsMarginToCorner ) ) )
( facingRight && xpos > mMap->rect().width() - mRotatedAnnotationsMarginToCorner ) ) )
return;
if ( annot.border == BorderSide::Bottom && ( ( facingLeft && xpos > mMap->rect().width() - mRotatedAnnotationsMarginToCorner ) ||
( facingRight && xpos < mRotatedAnnotationsMarginToCorner ) ) )
( facingRight && xpos < mRotatedAnnotationsMarginToCorner ) ) )
return;
if ( annot.border == BorderSide::Left && ( ( facingLeft && ypos > mMap->rect().height() - mRotatedAnnotationsMarginToCorner ) ||
( facingRight && ypos < mRotatedAnnotationsMarginToCorner ) ) )
( facingRight && ypos < mRotatedAnnotationsMarginToCorner ) ) )
return;
if ( annot.border == BorderSide::Right && ( ( facingLeft && ypos < mRotatedAnnotationsMarginToCorner ) ||
( facingRight && ypos > mMap->rect().height() - mRotatedAnnotationsMarginToCorner ) ) )
( facingRight && ypos > mMap->rect().height() - mRotatedAnnotationsMarginToCorner ) ) )
return;

QgsScopedQPainterState painterState( context.painter() );
@@ -418,6 +418,74 @@ def testAnnotationsVariationsRotated(self):
myTestResult, myMessage = checker.testLayout()
self.assertTrue(myTestResult, myMessage)

def testAnnotationsVariationsRotatedThresholds(self):
"""
Tests various rotated grid threshold settings
"""
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()

map_configs = [
(10, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, True, False),
(10, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, True, False),
(170, 30, QgsLayoutItemMapGrid.OutsideMapFrame, QgsLayoutItemMapGrid.InteriorTicks, False, True),
(170, 120, QgsLayoutItemMapGrid.InsideMapFrame, QgsLayoutItemMapGrid.ExteriorTicks, False, True),
]

for x, y, pos, style, limit_rot, limit_corners in map_configs:

map = QgsLayoutItemMap(layout)
layout.addLayoutItem(map)
map.attemptSetSceneRect(QRectF(x, y, 100, 50))
map.setExtent(QgsRectangle(5000000, 800000, 6000000, 1300000))
map.setBackgroundColor(QColor(200, 200, 200))
map.setMapRotation(0)
map.setFrameEnabled(True)
map.setCrs(QgsCoordinateReferenceSystem.fromEpsgId(2056))
map.grid().setCrs(QgsCoordinateReferenceSystem.fromEpsgId(4326))
map.grid().setFrameStyle(style)
map.grid().setFrameWidth(7)
map.grid().setFramePenSize(1)
map.grid().setFramePenColor(QColor(255, 0, 0))
map.grid().setEnabled(True)
map.grid().setIntervalX(2)
map.grid().setIntervalY(2)
map.grid().setAnnotationEnabled(True)
map.grid().setGridLineColor(QColor(0, 255, 0))
map.grid().setGridLineWidth(0.5)
map.grid().setRotatedTicksLengthMode(QgsLayoutItemMapGrid.NormalizedTicks)
map.grid().setAnnotationFont(getTestFont('Bold', 15))
map.grid().setAnnotationFontColor(QColor(0, 0, 255, 150))
map.grid().setAnnotationPrecision(0)
map.grid().setAnnotationFrameDistance(2.5)
map.grid().setRotatedTicksEnabled(True)
map.grid().setRotatedAnnotationsEnabled(True)

map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationPosition(pos, QgsLayoutItemMapGrid.Left)

map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick, QgsLayoutItemMapGrid.Top)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick, QgsLayoutItemMapGrid.Right)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick, QgsLayoutItemMapGrid.Bottom)
map.grid().setAnnotationDirection(QgsLayoutItemMapGrid.OnTick, QgsLayoutItemMapGrid.Left)

if limit_rot:
map.grid().setRotatedAnnotationsMinimumAngle(30)
map.grid().setRotatedTicksMinimumAngle(30)

if limit_corners:
map.grid().setRotatedAnnotationsMarginToCorner(10)
map.grid().setRotatedTicksMarginToCorner(10)

map.updateBoundingRect()

checker = QgsLayoutChecker('composermap_annotations_variations_rotated_thresholds', layout)
checker.setControlPathPrefix("composer_mapgrid")
myTestResult, myMessage = checker.testLayout()
self.assertTrue(myTestResult, myMessage)

def testExpressionContext(self):
layout = QgsLayout(QgsProject.instance())
layout.initializeDefaults()
Binary file not shown.

0 comments on commit 426c869

Please sign in to comment.
You can’t perform that action at this time.