1
1
/* **************************************************************************
2
- qgscoordinateformatter.cpp
3
- --------------------------
4
- begin : Decemeber 2015
5
- copyright : (C) 2015 by Nyall Dawson
6
- email : nyall dot dawson at gmail dot com
7
- ***************************************************************************/
2
+ qgscoordinateformatter.cpp
3
+ --------------------------
4
+ begin : Decemeber 2015
5
+ copyright : (C) 2015 by Nyall Dawson
6
+ email : nyall dot dawson at gmail dot com
7
+ ***************************************************************************/
8
8
9
9
/* **************************************************************************
10
10
* *
@@ -24,16 +24,16 @@ QString QgsCoordinateFormatter::formatX( double x, QgsCoordinateFormatter::Forma
24
24
{
25
25
switch ( format )
26
26
{
27
- case Pair :
27
+ case FormatPair :
28
28
return formatAsPair ( x, precision );
29
29
30
- case DegreesMinutesSeconds :
30
+ case FormatDegreesMinutesSeconds :
31
31
return formatXAsDegreesMinutesSeconds ( x, precision, flags );
32
32
33
- case DegreesMinutes :
33
+ case FormatDegreesMinutes :
34
34
return formatXAsDegreesMinutes ( x, precision, flags );
35
35
36
- case DecimalDegrees :
36
+ case FormatDecimalDegrees :
37
37
return formatXAsDegrees ( x, precision, flags );
38
38
}
39
39
return QString (); // avoid warnings
@@ -43,16 +43,16 @@ QString QgsCoordinateFormatter::formatY( double y, QgsCoordinateFormatter::Forma
43
43
{
44
44
switch ( format )
45
45
{
46
- case Pair :
46
+ case FormatPair :
47
47
return formatAsPair ( y, precision );
48
48
49
- case DegreesMinutesSeconds :
49
+ case FormatDegreesMinutesSeconds :
50
50
return formatYAsDegreesMinutesSeconds ( y, precision, flags );
51
51
52
- case DegreesMinutes :
52
+ case FormatDegreesMinutes :
53
53
return formatYAsDegreesMinutes ( y, precision, flags );
54
54
55
- case DecimalDegrees :
55
+ case FormatDecimalDegrees :
56
56
return formatYAsDegrees ( y, precision, flags );
57
57
}
58
58
return QString (); // avoid warnings
@@ -68,13 +68,13 @@ QString QgsCoordinateFormatter::asPair( double x, double y, int precision )
68
68
69
69
QString QgsCoordinateFormatter::formatAsPair ( double val, int precision )
70
70
{
71
- return qIsFinite ( val ) ? QString::number ( val, ' f' , precision ) : QObject::tr ( " infinite" );
71
+ return std::isfinite ( val ) ? QString::number ( val, ' f' , precision ) : QObject::tr ( " infinite" );
72
72
}
73
73
74
74
QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds ( double val, int precision, FormatFlags flags )
75
75
{
76
76
// first, limit longitude to -360 to 360 degree range
77
- double wrappedX = fmod ( val, 360.0 );
77
+ double wrappedX = std:: fmod ( val, 360.0 );
78
78
// next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W"
79
79
if ( wrappedX > 180.0 )
80
80
{
@@ -85,17 +85,17 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int
85
85
wrappedX = wrappedX + 360.0 ;
86
86
}
87
87
88
- int precisionMultiplier = pow ( 10.0 , precision );
88
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
89
89
90
- int degreesX = int ( qAbs ( wrappedX ) );
91
- double floatMinutesX = ( qAbs ( wrappedX ) - degreesX ) * 60.0 ;
90
+ int degreesX = int ( std::fabs ( wrappedX ) );
91
+ double floatMinutesX = ( std::fabs ( wrappedX ) - degreesX ) * 60.0 ;
92
92
int intMinutesX = int ( floatMinutesX );
93
93
double secondsX = ( floatMinutesX - intMinutesX ) * 60.0 ;
94
94
95
95
// make sure rounding to specified precision doesn't create seconds >= 60
96
- if ( qRound ( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier )
96
+ if ( std::round ( secondsX * precisionMultiplier ) >= 60 * precisionMultiplier )
97
97
{
98
- secondsX = qMax ( secondsX - 60 , 0.0 );
98
+ secondsX = std::max ( secondsX - 60 , 0.0 );
99
99
intMinutesX++;
100
100
if ( intMinutesX >= 60 )
101
101
{
@@ -106,7 +106,7 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int
106
106
107
107
QString hemisphere;
108
108
QString sign;
109
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
109
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
110
110
{
111
111
hemisphere = wrappedX < 0 ? QObject::tr ( " W" ) : QObject::tr ( " E" );
112
112
}
@@ -119,14 +119,14 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int
119
119
}
120
120
// check if coordinate is all zeros for the specified precision, and if so,
121
121
// remove the sign and hemisphere strings
122
- if ( degreesX == 0 && intMinutesX == 0 && qRound ( secondsX * precisionMultiplier ) == 0 )
122
+ if ( degreesX == 0 && intMinutesX == 0 && std::round ( secondsX * precisionMultiplier ) == 0 )
123
123
{
124
124
sign.clear ();
125
125
hemisphere.clear ();
126
126
}
127
127
128
128
// also remove directional prefix from 180 degree longitudes
129
- if ( degreesX == 180 && intMinutesX == 0 && qRound ( secondsX * precisionMultiplier ) == 0 )
129
+ if ( degreesX == 180 && intMinutesX == 0 && std::round ( secondsX * precisionMultiplier ) == 0 )
130
130
{
131
131
hemisphere.clear ();
132
132
}
@@ -135,7 +135,7 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int
135
135
QString strSecondsX;
136
136
137
137
// pad with leading digits if required
138
- if ( flags.testFlag ( DegreesPadMinutesSeconds ) )
138
+ if ( flags.testFlag ( FlagDegreesPadMinutesSeconds ) )
139
139
{
140
140
minutesX = QString ( " %1" ).arg ( intMinutesX, 2 , 10 , QChar ( ' 0' ) );
141
141
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); // 1 for decimal place if required
@@ -156,7 +156,7 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutesSeconds( double val, int
156
156
QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds ( double val, int precision, FormatFlags flags )
157
157
{
158
158
// first, limit latitude to -180 to 180 degree range
159
- double wrappedY = fmod ( val, 180.0 );
159
+ double wrappedY = std:: fmod ( val, 180.0 );
160
160
// next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N"
161
161
if ( wrappedY > 90.0 )
162
162
{
@@ -167,17 +167,17 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int
167
167
wrappedY = wrappedY + 180.0 ;
168
168
}
169
169
170
- int precisionMultiplier = pow ( 10.0 , precision );
170
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
171
171
172
- int degreesY = int ( qAbs ( wrappedY ) );
173
- double floatMinutesY = ( qAbs ( wrappedY ) - degreesY ) * 60.0 ;
172
+ int degreesY = int ( std::fabs ( wrappedY ) );
173
+ double floatMinutesY = ( std::fabs ( wrappedY ) - degreesY ) * 60.0 ;
174
174
int intMinutesY = int ( floatMinutesY );
175
175
double secondsY = ( floatMinutesY - intMinutesY ) * 60.0 ;
176
176
177
177
// make sure rounding to specified precision doesn't create seconds >= 60
178
- if ( qRound ( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier )
178
+ if ( std::round ( secondsY * precisionMultiplier ) >= 60 * precisionMultiplier )
179
179
{
180
- secondsY = qMax ( secondsY - 60 , 0.0 );
180
+ secondsY = std::max ( secondsY - 60 , 0.0 );
181
181
intMinutesY++;
182
182
if ( intMinutesY >= 60 )
183
183
{
@@ -188,7 +188,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int
188
188
189
189
QString hemisphere;
190
190
QString sign;
191
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
191
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
192
192
{
193
193
hemisphere = wrappedY < 0 ? QObject::tr ( " S" ) : QObject::tr ( " N" );
194
194
}
@@ -201,7 +201,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int
201
201
}
202
202
// check if coordinate is all zeros for the specified precision, and if so,
203
203
// remove the sign and hemisphere strings
204
- if ( degreesY == 0 && intMinutesY == 0 && qRound ( secondsY * precisionMultiplier ) == 0 )
204
+ if ( degreesY == 0 && intMinutesY == 0 && std::round ( secondsY * precisionMultiplier ) == 0 )
205
205
{
206
206
sign = QString ();
207
207
hemisphere.clear ();
@@ -211,7 +211,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int
211
211
QString strSecondsY;
212
212
213
213
// pad with leading digits if required
214
- if ( flags.testFlag ( DegreesPadMinutesSeconds ) )
214
+ if ( flags.testFlag ( FlagDegreesPadMinutesSeconds ) )
215
215
{
216
216
strMinutesY = QString ( " %1" ).arg ( intMinutesY, 2 , 10 , QChar ( ' 0' ) );
217
217
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); // 1 for decimal place if required
@@ -232,7 +232,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutesSeconds( double val, int
232
232
QString QgsCoordinateFormatter::formatXAsDegreesMinutes ( double val, int precision, FormatFlags flags )
233
233
{
234
234
// first, limit longitude to -360 to 360 degree range
235
- double wrappedX = fmod ( val, 360.0 );
235
+ double wrappedX = std:: fmod ( val, 360.0 );
236
236
// next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W"
237
237
if ( wrappedX > 180.0 )
238
238
{
@@ -243,21 +243,21 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutes( double val, int precisi
243
243
wrappedX = wrappedX + 360.0 ;
244
244
}
245
245
246
- int degreesX = int ( qAbs ( wrappedX ) );
247
- double floatMinutesX = ( qAbs ( wrappedX ) - degreesX ) * 60.0 ;
246
+ int degreesX = int ( std::fabs ( wrappedX ) );
247
+ double floatMinutesX = ( std::fabs ( wrappedX ) - degreesX ) * 60.0 ;
248
248
249
- int precisionMultiplier = pow ( 10.0 , precision );
249
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
250
250
251
251
// make sure rounding to specified precision doesn't create minutes >= 60
252
- if ( qRound ( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier )
252
+ if ( std::round ( floatMinutesX * precisionMultiplier ) >= 60 * precisionMultiplier )
253
253
{
254
- floatMinutesX = qMax ( floatMinutesX - 60 , 0.0 );
254
+ floatMinutesX = std::max ( floatMinutesX - 60 , 0.0 );
255
255
degreesX++;
256
256
}
257
257
258
258
QString hemisphere;
259
259
QString sign;
260
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
260
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
261
261
{
262
262
hemisphere = wrappedX < 0 ? QObject::tr ( " W" ) : QObject::tr ( " E" );
263
263
}
@@ -270,21 +270,21 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutes( double val, int precisi
270
270
}
271
271
// check if coordinate is all zeros for the specified precision, and if so,
272
272
// remove the sign and hemisphere strings
273
- if ( degreesX == 0 && qRound ( floatMinutesX * precisionMultiplier ) == 0 )
273
+ if ( degreesX == 0 && std::round ( floatMinutesX * precisionMultiplier ) == 0 )
274
274
{
275
275
sign.clear ();
276
276
hemisphere.clear ();
277
277
}
278
278
279
279
// also remove directional prefix from 180 degree longitudes
280
- if ( degreesX == 180 && qRound ( floatMinutesX * precisionMultiplier ) == 0 )
280
+ if ( degreesX == 180 && std::round ( floatMinutesX * precisionMultiplier ) == 0 )
281
281
{
282
282
hemisphere.clear ();
283
283
}
284
284
285
285
// pad minutes with leading digits if required
286
286
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); // 1 for decimal place if required
287
- QString strMinutesX = flags.testFlag ( DegreesPadMinutesSeconds ) ? QString ( " %1" ).arg ( floatMinutesX, digits, ' f' , precision, QChar ( ' 0' ) )
287
+ QString strMinutesX = flags.testFlag ( FlagDegreesPadMinutesSeconds ) ? QString ( " %1" ).arg ( floatMinutesX, digits, ' f' , precision, QChar ( ' 0' ) )
288
288
: QString::number ( floatMinutesX, ' f' , precision );
289
289
290
290
return sign + QString::number ( degreesX ) + QChar ( 176 ) +
@@ -295,7 +295,7 @@ QString QgsCoordinateFormatter::formatXAsDegreesMinutes( double val, int precisi
295
295
QString QgsCoordinateFormatter::formatYAsDegreesMinutes ( double val, int precision, FormatFlags flags )
296
296
{
297
297
// first, limit latitude to -180 to 180 degree range
298
- double wrappedY = fmod ( val, 180.0 );
298
+ double wrappedY = std:: fmod ( val, 180.0 );
299
299
// next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N"
300
300
if ( wrappedY > 90.0 )
301
301
{
@@ -306,21 +306,21 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutes( double val, int precisi
306
306
wrappedY = wrappedY + 180.0 ;
307
307
}
308
308
309
- int degreesY = int ( qAbs ( wrappedY ) );
310
- double floatMinutesY = ( qAbs ( wrappedY ) - degreesY ) * 60.0 ;
309
+ int degreesY = int ( std::fabs ( wrappedY ) );
310
+ double floatMinutesY = ( std::fabs ( wrappedY ) - degreesY ) * 60.0 ;
311
311
312
- int precisionMultiplier = pow ( 10.0 , precision );
312
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
313
313
314
314
// make sure rounding to specified precision doesn't create minutes >= 60
315
- if ( qRound ( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier )
315
+ if ( std::round ( floatMinutesY * precisionMultiplier ) >= 60 * precisionMultiplier )
316
316
{
317
- floatMinutesY = qMax ( floatMinutesY - 60 , 0.0 );
317
+ floatMinutesY = std::max ( floatMinutesY - 60 , 0.0 );
318
318
degreesY++;
319
319
}
320
320
321
321
QString hemisphere;
322
322
QString sign;
323
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
323
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
324
324
{
325
325
hemisphere = wrappedY < 0 ? QObject::tr ( " S" ) : QObject::tr ( " N" );
326
326
}
@@ -333,7 +333,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutes( double val, int precisi
333
333
}
334
334
// check if coordinate is all zeros for the specified precision, and if so,
335
335
// remove the sign and hemisphere strings
336
- if ( degreesY == 0 && qRound ( floatMinutesY * precisionMultiplier ) == 0 )
336
+ if ( degreesY == 0 && std::round ( floatMinutesY * precisionMultiplier ) == 0 )
337
337
{
338
338
sign.clear ();
339
339
hemisphere.clear ();
@@ -342,7 +342,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutes( double val, int precisi
342
342
343
343
// pad minutes with leading digits if required
344
344
int digits = 2 + ( precision == 0 ? 0 : 1 + precision ); // 1 for decimal place if required
345
- QString strMinutesY = flags.testFlag ( DegreesPadMinutesSeconds ) ? QString ( " %1" ).arg ( floatMinutesY, digits, ' f' , precision, QChar ( ' 0' ) )
345
+ QString strMinutesY = flags.testFlag ( FlagDegreesPadMinutesSeconds ) ? QString ( " %1" ).arg ( floatMinutesY, digits, ' f' , precision, QChar ( ' 0' ) )
346
346
: QString::number ( floatMinutesY, ' f' , precision );
347
347
348
348
return sign + QString::number ( degreesY ) + QChar ( 176 ) +
@@ -353,7 +353,7 @@ QString QgsCoordinateFormatter::formatYAsDegreesMinutes( double val, int precisi
353
353
QString QgsCoordinateFormatter::formatXAsDegrees ( double val, int precision, FormatFlags flags )
354
354
{
355
355
// first, limit longitude to -360 to 360 degree range
356
- double wrappedX = fmod ( val, 360.0 );
356
+ double wrappedX = std:: fmod ( val, 360.0 );
357
357
// next, wrap around longitudes > 180 or < -180 degrees, so that eg "190E" -> "170W"
358
358
if ( wrappedX > 180.0 )
359
359
{
@@ -364,13 +364,13 @@ QString QgsCoordinateFormatter::formatXAsDegrees( double val, int precision, For
364
364
wrappedX = wrappedX + 360.0 ;
365
365
}
366
366
367
- double absX = qAbs ( wrappedX );
367
+ double absX = std::fabs ( wrappedX );
368
368
369
- int precisionMultiplier = pow ( 10.0 , precision );
369
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
370
370
371
371
QString hemisphere;
372
372
QString sign;
373
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
373
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
374
374
{
375
375
hemisphere = wrappedX < 0 ? QObject::tr ( " W" ) : QObject::tr ( " E" );
376
376
}
@@ -383,14 +383,14 @@ QString QgsCoordinateFormatter::formatXAsDegrees( double val, int precision, For
383
383
}
384
384
// check if coordinate is all zeros for the specified precision, and if so,
385
385
// remove the sign and hemisphere strings
386
- if ( qRound ( absX * precisionMultiplier ) == 0 )
386
+ if ( std::round ( absX * precisionMultiplier ) == 0 )
387
387
{
388
388
sign.clear ();
389
389
hemisphere.clear ();
390
390
}
391
391
392
392
// also remove directional prefix from 180 degree longitudes
393
- if ( qRound ( absX * precisionMultiplier ) == 180 * precisionMultiplier )
393
+ if ( std::round ( absX * precisionMultiplier ) == 180 * precisionMultiplier )
394
394
{
395
395
sign.clear ();
396
396
hemisphere.clear ();
@@ -402,7 +402,7 @@ QString QgsCoordinateFormatter::formatXAsDegrees( double val, int precision, For
402
402
QString QgsCoordinateFormatter::formatYAsDegrees ( double val, int precision, FormatFlags flags )
403
403
{
404
404
// first, limit latitude to -180 to 180 degree range
405
- double wrappedY = fmod ( val, 180.0 );
405
+ double wrappedY = std:: fmod ( val, 180.0 );
406
406
// next, wrap around latitudes > 90 or < -90 degrees, so that eg "110S" -> "70N"
407
407
if ( wrappedY > 90.0 )
408
408
{
@@ -413,13 +413,13 @@ QString QgsCoordinateFormatter::formatYAsDegrees( double val, int precision, For
413
413
wrappedY = wrappedY + 180.0 ;
414
414
}
415
415
416
- double absY = qAbs ( wrappedY );
416
+ double absY = std::fabs ( wrappedY );
417
417
418
- int precisionMultiplier = pow ( 10.0 , precision );
418
+ int precisionMultiplier = std:: pow ( 10.0 , precision );
419
419
420
420
QString hemisphere;
421
421
QString sign;
422
- if ( flags.testFlag ( DegreesUseStringSuffix ) )
422
+ if ( flags.testFlag ( FlagDegreesUseStringSuffix ) )
423
423
{
424
424
hemisphere = wrappedY < 0 ? QObject::tr ( " S" ) : QObject::tr ( " N" );
425
425
}
@@ -432,7 +432,7 @@ QString QgsCoordinateFormatter::formatYAsDegrees( double val, int precision, For
432
432
}
433
433
// check if coordinate is all zeros for the specified precision, and if so,
434
434
// remove the sign and hemisphere strings
435
- if ( qRound ( absY * precisionMultiplier ) == 0 )
435
+ if ( std::round ( absY * precisionMultiplier ) == 0 )
436
436
{
437
437
sign.clear ();
438
438
hemisphere.clear ();
0 commit comments