|
54 | 54 |
|
55 | 55 | using namespace Qt::StringLiterals; |
56 | 56 |
|
| 57 | +#define MAX_GRID_LINES 1000 //maximum number of horizontal or vertical grid lines to draw |
| 58 | + |
57 | 59 | QgsLayoutItemMapGridStack::QgsLayoutItemMapGridStack( QgsLayoutItemMap *map ) |
58 | 60 | : QgsLayoutItemMapItemStack( map ) |
59 | 61 | {} |
@@ -1591,17 +1593,22 @@ void QgsLayoutItemMapGrid::drawCoordinateAnnotation( |
1591 | 1593 | facingLeft = !facingLeft; |
1592 | 1594 | facingRight = !facingRight; |
1593 | 1595 | } |
| 1596 | + const QRectF mapRect = mMap->rect(); |
1594 | 1597 | if ( annot.border == Qgis::MapGridBorderSide::Top |
1595 | | - && ( ( facingLeft && annot.position.x() < mRotatedAnnotationsMarginToCorner ) || ( facingRight && annot.position.x() > mMap->rect().width() - mRotatedAnnotationsMarginToCorner ) ) ) |
| 1598 | + && ( ( facingLeft && !qgsDoubleGreaterThanOrNear( annot.position.x(),mRotatedAnnotationsMarginToCorner,ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM) ) |
| 1599 | + || ( facingRight && !qgsDoubleLessThanOrNear( annot.position.x(), mapRect.width() - mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) ) ) |
1596 | 1600 | return; |
1597 | 1601 | if ( annot.border == Qgis::MapGridBorderSide::Bottom |
1598 | | - && ( ( facingLeft && annot.position.x() > mMap->rect().width() - mRotatedAnnotationsMarginToCorner ) || ( facingRight && annot.position.x() < mRotatedAnnotationsMarginToCorner ) ) ) |
| 1602 | + && ( ( facingLeft && !qgsDoubleLessThanOrNear( annot.position.x(), mapRect.width() - mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) |
| 1603 | + || ( facingRight && !qgsDoubleGreaterThanOrNear( annot.position.x(), mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) ) ) |
1599 | 1604 | return; |
1600 | 1605 | if ( annot.border == Qgis::MapGridBorderSide::Left |
1601 | | - && ( ( facingLeft && annot.position.y() > mMap->rect().height() - mRotatedAnnotationsMarginToCorner ) || ( facingRight && annot.position.y() < mRotatedAnnotationsMarginToCorner ) ) ) |
| 1606 | + && ( ( facingLeft && !qgsDoubleLessThanOrNear( annot.position.y(), mapRect.height() - mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) |
| 1607 | + || ( facingRight && !qgsDoubleGreaterThanOrNear( annot.position.y(), mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) ) ) |
1602 | 1608 | return; |
1603 | 1609 | if ( annot.border == Qgis::MapGridBorderSide::Right |
1604 | | - && ( ( facingLeft && annot.position.y() < mRotatedAnnotationsMarginToCorner ) || ( facingRight && annot.position.y() > mMap->rect().height() - mRotatedAnnotationsMarginToCorner ) ) ) |
| 1610 | + && ( ( facingLeft && !qgsDoubleGreaterThanOrNear( annot.position.y(), mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) |
| 1611 | + || ( facingRight && !qgsDoubleLessThanOrNear( annot.position.y(), mapRect.height() - mRotatedAnnotationsMarginToCorner, ANNOTATION_CLOSE_TO_EDGE_TOLERANCE_MM ) ) ) ) |
1605 | 1612 | return; |
1606 | 1613 |
|
1607 | 1614 | // adjust to account for text alignment -- for left/right borders the alignment |
@@ -1882,14 +1889,16 @@ void QgsLayoutItemMapGrid::calculateXGridLines() const |
1882 | 1889 | } |
1883 | 1890 |
|
1884 | 1891 | double currentLevel = static_cast< int >( ( mapBoundingRect.top() - gridOffsetY ) / gridIntervalY ) * gridIntervalY + gridOffsetY; |
| 1892 | + if ( !qgsDoubleGreaterThanOrNear( currentLevel, mapBoundingRect.top(), GRID_LINE_CLOSE_TO_EDGE_TOLERANCE_MAP_UNITS ) ) |
| 1893 | + currentLevel += gridIntervalY; |
1885 | 1894 |
|
1886 | 1895 | int gridLineCount = 0; |
1887 | 1896 | if ( qgsDoubleNear( mMap->mapRotation(), 0.0 ) || ( mGridUnit != Qgis::MapGridUnit::MapUnits && mGridUnit != Qgis::MapGridUnit::DynamicPageSizeBased ) ) |
1888 | 1897 | { |
1889 | 1898 | //no rotation. Do it 'the easy way' |
1890 | 1899 |
|
1891 | 1900 | double yCanvasCoord; |
1892 | | - while ( currentLevel <= mapBoundingRect.bottom() && gridLineCount < MAX_GRID_OBJECTS ) |
| 1901 | + while ( qgsDoubleLessThanOrNear( currentLevel, mapBoundingRect.bottom(), GRID_LINE_CLOSE_TO_EDGE_TOLERANCE_MAP_UNITS ) && gridLineCount < MAX_GRID_OBJECTS ) |
1893 | 1902 | { |
1894 | 1903 | yCanvasCoord = mMap->rect().height() * ( 1 - ( currentLevel - mapBoundingRect.top() ) / mapBoundingRect.height() ); |
1895 | 1904 | GridLine newLine; |
@@ -1978,13 +1987,15 @@ void QgsLayoutItemMapGrid::calculateYGridLines() const |
1978 | 1987 | } |
1979 | 1988 |
|
1980 | 1989 | double currentLevel = static_cast< int >( ( mapBoundingRect.left() - gridOffsetX ) / gridIntervalX ) * gridIntervalX + gridOffsetX; |
| 1990 | + if ( !qgsDoubleGreaterThanOrNear( currentLevel, mapBoundingRect.left(), GRID_LINE_CLOSE_TO_EDGE_TOLERANCE_MAP_UNITS ) ) |
| 1991 | + currentLevel += gridIntervalX; |
1981 | 1992 |
|
1982 | 1993 | int gridLineCount = 0; |
1983 | 1994 | if ( qgsDoubleNear( mMap->mapRotation(), 0.0 ) || ( mGridUnit != Qgis::MapGridUnit::MapUnits && mGridUnit != Qgis::MapGridUnit::DynamicPageSizeBased ) ) |
1984 | 1995 | { |
1985 | 1996 | //no rotation. Do it 'the easy way' |
1986 | 1997 | double xCanvasCoord; |
1987 | | - while ( currentLevel <= mapBoundingRect.right() && gridLineCount < MAX_GRID_OBJECTS ) |
| 1998 | + while ( qgsDoubleLessThanOrNear( currentLevel, mapBoundingRect.right(), GRID_LINE_CLOSE_TO_EDGE_TOLERANCE_MAP_UNITS ) && gridLineCount < MAX_GRID_OBJECTS ) |
1988 | 1999 | { |
1989 | 2000 | xCanvasCoord = mMap->rect().width() * ( currentLevel - mapBoundingRect.left() ) / mapBoundingRect.width(); |
1990 | 2001 |
|
|
0 commit comments