@@ -979,26 +979,26 @@ void QgsComposerMapGrid::drawCoordinateAnnotations( QPainter* p, const QList< QP
979
979
for ( ; it != hLines.constEnd (); ++it )
980
980
{
981
981
currentAnnotationString = gridAnnotationString ( it->first , QgsComposerMapGrid::Latitude );
982
- drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString );
983
- drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString );
982
+ drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString, QgsComposerMapGrid::Latitude );
983
+ drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString, QgsComposerMapGrid::Latitude );
984
984
}
985
985
986
986
it = vLines.constBegin ();
987
987
for ( ; it != vLines.constEnd (); ++it )
988
988
{
989
989
currentAnnotationString = gridAnnotationString ( it->first , QgsComposerMapGrid::Longitude );
990
- drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString );
991
- drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString );
990
+ drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString, QgsComposerMapGrid::Longitude );
991
+ drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString, QgsComposerMapGrid::Longitude );
992
992
}
993
993
}
994
994
995
- void QgsComposerMapGrid::drawCoordinateAnnotation ( QPainter* p, const QPointF& pos, QString annotationString ) const
995
+ void QgsComposerMapGrid::drawCoordinateAnnotation ( QPainter* p, const QPointF& pos, QString annotationString, const AnnotationCoordinate coordinateType ) const
996
996
{
997
997
if ( !mComposerMap )
998
998
{
999
999
return ;
1000
1000
}
1001
- QgsComposerMapGrid::BorderSide frameBorder = borderForLineCoord ( pos );
1001
+ QgsComposerMapGrid::BorderSide frameBorder = borderForLineCoord ( pos, coordinateType );
1002
1002
double textWidth = QgsComposerUtils::textWidthMM ( mGridAnnotationFont , annotationString );
1003
1003
// relevant for annotations is the height of digits
1004
1004
double textHeight = QgsComposerUtils::fontHeightCharacterMM ( mGridAnnotationFont , QChar ( ' 0' ) );
@@ -1610,51 +1610,103 @@ int QgsComposerMapGrid::yGridLinesCRSTransform( const QgsRectangle& bbox, const
1610
1610
void QgsComposerMapGrid::sortGridLinesOnBorders ( const QList< QPair< double , QLineF > >& hLines, const QList< QPair< double , QLineF > >& vLines, QMap< double , double >& leftFrameEntries,
1611
1611
QMap< double , double >& rightFrameEntries, QMap< double , double >& topFrameEntries, QMap< double , double >& bottomFrameEntries ) const
1612
1612
{
1613
- QList< QPair< double , QPointF > > borderPositions;
1613
+ QList< QgsMapAnnotation > borderPositions;
1614
1614
QList< QPair< double , QLineF > >::const_iterator it = hLines.constBegin ();
1615
1615
for ( ; it != hLines.constEnd (); ++it )
1616
1616
{
1617
- borderPositions << qMakePair ( it->first , it->second .p1 () );
1618
- borderPositions << qMakePair ( it->first , it->second .p2 () );
1617
+ QgsMapAnnotation p1;
1618
+ p1.coordinate = it->first ;
1619
+ p1.itemPosition = it->second .p1 ();
1620
+ p1.coordinateType = QgsComposerMapGrid::Latitude;
1621
+ borderPositions << p1;
1622
+
1623
+ QgsMapAnnotation p2;
1624
+ p2.coordinate = it->first ;
1625
+ p2.itemPosition = it->second .p2 ();
1626
+ p2.coordinateType = QgsComposerMapGrid::Latitude;
1627
+ borderPositions << p2;
1619
1628
}
1620
1629
it = vLines.constBegin ();
1621
1630
for ( ; it != vLines.constEnd (); ++it )
1622
1631
{
1623
- borderPositions << qMakePair ( it->first , it->second .p1 () );
1624
- borderPositions << qMakePair ( it->first , it->second .p2 () );
1632
+ QgsMapAnnotation p1;
1633
+ p1.coordinate = it->first ;
1634
+ p1.itemPosition = it->second .p1 ();
1635
+ p1.coordinateType = QgsComposerMapGrid::Longitude;
1636
+ borderPositions << p1;
1637
+
1638
+ QgsMapAnnotation p2;
1639
+ p2.coordinate = it->first ;
1640
+ p2.itemPosition = it->second .p2 ();
1641
+ p2.coordinateType = QgsComposerMapGrid::Longitude;
1642
+ borderPositions << p2;
1625
1643
}
1626
1644
1627
- QList< QPair< double , QPointF > >::const_iterator bIt = borderPositions.constBegin ();
1645
+ QList< QgsMapAnnotation >::const_iterator bIt = borderPositions.constBegin ();
1628
1646
for ( ; bIt != borderPositions.constEnd (); ++bIt )
1629
1647
{
1630
- QgsComposerMapGrid::BorderSide frameBorder = borderForLineCoord ( bIt->second );
1648
+ QgsComposerMapGrid::BorderSide frameBorder = borderForLineCoord ( bIt->itemPosition , bIt-> coordinateType );
1631
1649
if ( frameBorder == QgsComposerMapGrid::Left )
1632
1650
{
1633
- leftFrameEntries.insert ( bIt->second .y (), bIt->first );
1651
+ leftFrameEntries.insert ( bIt->itemPosition .y (), bIt->coordinate );
1634
1652
}
1635
1653
else if ( frameBorder == QgsComposerMapGrid::Right )
1636
1654
{
1637
- rightFrameEntries.insert ( bIt->second .y (), bIt->first );
1655
+ rightFrameEntries.insert ( bIt->itemPosition .y (), bIt->coordinate );
1638
1656
}
1639
1657
else if ( frameBorder == QgsComposerMapGrid::Top )
1640
1658
{
1641
- topFrameEntries.insert ( bIt->second .x (), bIt->first );
1659
+ topFrameEntries.insert ( bIt->itemPosition .x (), bIt->coordinate );
1642
1660
}
1643
1661
else // Bottom
1644
1662
{
1645
- bottomFrameEntries.insert ( bIt->second .x (), bIt->first );
1663
+ bottomFrameEntries.insert ( bIt->itemPosition .x (), bIt->coordinate );
1646
1664
}
1647
1665
}
1648
1666
}
1649
1667
1650
- QgsComposerMapGrid::BorderSide QgsComposerMapGrid::borderForLineCoord ( const QPointF& p ) const
1668
+ QgsComposerMapGrid::BorderSide QgsComposerMapGrid::borderForLineCoord ( const QPointF& p , const AnnotationCoordinate coordinateType ) const
1651
1669
{
1652
1670
if ( !mComposerMap )
1653
1671
{
1654
1672
return QgsComposerMapGrid::Left;
1655
1673
}
1656
1674
1657
1675
double framePenWidth = mComposerMap ->hasFrame () ? mComposerMap ->pen ().widthF () : 0.000000001 ;
1676
+
1677
+ // check for corner coordinates
1678
+ if (( p.y () <= framePenWidth && p.x () <= framePenWidth ) // top left
1679
+ || ( p.y () <= framePenWidth && p.x () >= ( mComposerMap ->rect ().width () - framePenWidth ) ) // top right
1680
+ || ( p.y () >= ( mComposerMap ->rect ().height () - framePenWidth ) && p.x () <= framePenWidth ) // bottom left
1681
+ || ( p.y () >= ( mComposerMap ->rect ().height () - framePenWidth ) && p.x () >= ( mComposerMap ->rect ().width () - framePenWidth ) ) // bottom right
1682
+ )
1683
+ {
1684
+ // coordinate is in corner - fall back to preferred side for coordinate type
1685
+ if ( coordinateType == QgsComposerMapGrid::Latitude )
1686
+ {
1687
+ if ( p.x () <= framePenWidth )
1688
+ {
1689
+ return QgsComposerMapGrid::Left;
1690
+ }
1691
+ else
1692
+ {
1693
+ return QgsComposerMapGrid::Right;
1694
+ }
1695
+ }
1696
+ else
1697
+ {
1698
+ if ( p.y () <= framePenWidth )
1699
+ {
1700
+ return QgsComposerMapGrid::Top;
1701
+ }
1702
+ else
1703
+ {
1704
+ return QgsComposerMapGrid::Bottom;
1705
+ }
1706
+ }
1707
+ }
1708
+
1709
+ // otherwise, guess side based on point
1658
1710
if ( p.y () <= framePenWidth )
1659
1711
{
1660
1712
return QgsComposerMapGrid::Top;
0 commit comments