@@ -74,6 +74,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int w
74
74
setSceneRect ( QRectF ( x, y, width, height ) );
75
75
setToolTip ( tr ( " Map %1" ).arg ( mId ) );
76
76
mGridPen .setCapStyle ( Qt::FlatCap );
77
+
78
+ initGridAnnotationFormatFromProject ();
77
79
}
78
80
79
81
QgsComposerMap::QgsComposerMap ( QgsComposition *composition )
@@ -101,6 +103,8 @@ QgsComposerMap::QgsComposerMap( QgsComposition *composition )
101
103
102
104
setToolTip ( tr ( " Map %1" ).arg ( mId ) );
103
105
mGridPen .setCapStyle ( Qt::FlatCap );
106
+
107
+ initGridAnnotationFormatFromProject ();
104
108
}
105
109
106
110
QgsComposerMap::~QgsComposerMap ()
@@ -1071,15 +1075,15 @@ void QgsComposerMap::drawCoordinateAnnotations( QPainter* p, const QList< QPair<
1071
1075
QList< QPair< double , QLineF > >::const_iterator it = hLines.constBegin ();
1072
1076
for ( ; it != hLines.constEnd (); ++it )
1073
1077
{
1074
- currentAnnotationString = QString::number ( it->first , ' f ' , mGridAnnotationPrecision );
1078
+ currentAnnotationString = gridAnnotationString ( it->first , Latitude );
1075
1079
drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString );
1076
1080
drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString );
1077
1081
}
1078
1082
1079
1083
it = vLines.constBegin ();
1080
1084
for ( ; it != vLines.constEnd (); ++it )
1081
1085
{
1082
- currentAnnotationString = QString::number ( it->first , ' f ' , mGridAnnotationPrecision );
1086
+ currentAnnotationString = gridAnnotationString ( it->first , Longitude );
1083
1087
drawCoordinateAnnotation ( p, it->second .p1 (), currentAnnotationString );
1084
1088
drawCoordinateAnnotation ( p, it->second .p2 (), currentAnnotationString );
1085
1089
}
@@ -1253,6 +1257,42 @@ void QgsComposerMap::drawAnnotation( QPainter* p, const QPointF& pos, int rotati
1253
1257
p->restore ();
1254
1258
}
1255
1259
1260
+ QString QgsComposerMap::gridAnnotationString ( double value, AnnotationCoordinate coord ) const
1261
+ {
1262
+ if ( mGridAnnotationFormat == Decimal )
1263
+ {
1264
+ return QString::number ( value, ' f' , mGridAnnotationPrecision );
1265
+ }
1266
+
1267
+ QgsPoint p;
1268
+ p.setX ( coord == Longitude ? value : 0 );
1269
+ p.setY ( coord == Longitude ? 0 : value );
1270
+
1271
+ QString annotationString;
1272
+ if ( mGridAnnotationFormat == DegreeMinute )
1273
+ {
1274
+ annotationString = p.toDegreesMinutes ( mGridAnnotationPrecision );
1275
+ }
1276
+ else // DegreeMinuteSecond
1277
+ {
1278
+ annotationString = p.toDegreesMinutesSeconds ( mGridAnnotationPrecision );
1279
+ }
1280
+
1281
+ QStringList split = annotationString.split ( " ," );
1282
+ if ( coord == Longitude )
1283
+ {
1284
+ return split.at ( 0 );
1285
+ }
1286
+ else
1287
+ {
1288
+ if ( split.size () < 2 )
1289
+ {
1290
+ return " " ;
1291
+ }
1292
+ return split.at ( 1 );
1293
+ }
1294
+ }
1295
+
1256
1296
int QgsComposerMap::xGridLines ( QList< QPair< double , QLineF > >& lines ) const
1257
1297
{
1258
1298
lines.clear ();
@@ -1454,12 +1494,10 @@ double QgsComposerMap::maxExtension() const
1454
1494
QList< QPair< double , QLineF > > xLines;
1455
1495
QList< QPair< double , QLineF > > yLines;
1456
1496
1457
- if ( xGridLines ( xLines ) != 0 )
1458
- {
1459
- return 0 ;
1460
- }
1497
+ int xGridReturn = xGridLines ( xLines );
1498
+ int yGridReturn = yGridLines ( yLines );
1461
1499
1462
- if ( yGridLines ( yLines ) != 0 )
1500
+ if ( xGridReturn != 0 && yGridReturn != 0 )
1463
1501
{
1464
1502
return 0 ;
1465
1503
}
@@ -1471,15 +1509,15 @@ double QgsComposerMap::maxExtension() const
1471
1509
QList< QPair< double , QLineF > >::const_iterator it = xLines.constBegin ();
1472
1510
for ( ; it != xLines.constEnd (); ++it )
1473
1511
{
1474
- currentAnnotationString = QString::number ( it->first , ' f ' , mGridAnnotationPrecision );
1512
+ currentAnnotationString = gridAnnotationString ( it->first , Latitude );
1475
1513
currentExtension = qMax ( textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString ), fontAscentMillimeters ( mGridAnnotationFont ) );
1476
1514
maxExtension = qMax ( maxExtension, currentExtension );
1477
1515
}
1478
1516
1479
1517
it = yLines.constBegin ();
1480
1518
for ( ; it != yLines.constEnd (); ++it )
1481
1519
{
1482
- currentAnnotationString = QString::number ( it->first , ' f ' , mGridAnnotationPrecision );
1520
+ currentAnnotationString = gridAnnotationString ( it->first , Longitude );
1483
1521
currentExtension = qMax ( textWidthMillimeters ( mGridAnnotationFont , currentAnnotationString ), fontAscentMillimeters ( mGridAnnotationFont ) );
1484
1522
maxExtension = qMax ( maxExtension, currentExtension );
1485
1523
}
@@ -1948,6 +1986,23 @@ void QgsComposerMap::createDefaultOverviewFrameSymbol()
1948
1986
mOverviewFrameMapSymbol ->setAlpha ( 0.3 );
1949
1987
}
1950
1988
1989
+ void QgsComposerMap::initGridAnnotationFormatFromProject ()
1990
+ {
1991
+ QString format = QgsProject::instance ()->readEntry ( " PositionPrecision" , " /DegreeFormat" , " D" );
1992
+ if ( format == " DM" )
1993
+ {
1994
+ mGridAnnotationFormat = DegreeMinute;
1995
+ }
1996
+ else if ( format == " DMS" )
1997
+ {
1998
+ mGridAnnotationFormat = DegreeMinuteSecond;
1999
+ }
2000
+ else
2001
+ {
2002
+ mGridAnnotationFormat = Decimal;
2003
+ }
2004
+ }
2005
+
1951
2006
void QgsComposerMap::assignFreeId ()
1952
2007
{
1953
2008
if ( !mComposition )
0 commit comments