Skip to content

Commit 98713a9

Browse files
committedFeb 23, 2016
Fix tests where locale-dependent formatting of numbers is used
1 parent b34105d commit 98713a9

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed
 

‎src/core/qgsdistancearea.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <sqlite3.h>
1818
#include <QDir>
1919
#include <QString>
20-
#include <QLocale>
2120
#include <QObject>
2221

2322
#include "qgis.h"
@@ -1094,7 +1093,7 @@ QString QgsDistanceArea::textUnit( double value, int decimals, QGis::UnitType u,
10941093
break;
10951094
}
10961095

1097-
return QLocale::system().toString( value, 'f', decimals ) + unitLabel;
1096+
return QString( "%L1%2" ).arg( value, 0, 'f', decimals ).arg( unitLabel );
10981097
}
10991098

11001099
QString QgsDistanceArea::formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit )
@@ -1229,7 +1228,7 @@ QString QgsDistanceArea::formatArea( double area, int decimals, QgsUnitTypes::Ar
12291228
}
12301229
}
12311230

1232-
return QLocale::system().toString( area, 'f', decimals ) + unitLabel;
1231+
return QString( "%L1%2" ).arg( area, 0, 'f', decimals ).arg( unitLabel );
12331232
}
12341233

12351234
void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const

‎src/core/qgsunittypes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#include "qgsunittypes.h"
1818
#include <QCoreApplication>
19-
#include <QLocale>
2019

2120
/***************************************************************************
2221
* This class is considered CRITICAL and any change MUST be accompanied with
@@ -938,7 +937,7 @@ QString QgsUnitTypes::formatAngle( double angle, int decimals, QgsUnitTypes::Ang
938937
break;
939938
}
940939

941-
return QLocale::system().toString( angle, 'f', decimals ) + unitLabel;
940+
return QString( "%L1%2" ).arg( angle, 0, 'f', decimals ).arg( unitLabel );
942941
}
943942

944943
// enable for QGIS 3.0

‎tests/src/app/testqgsmaptoolidentifyaction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ void TestQgsMapToolIdentifyAction::initTestCase()
5555
QCoreApplication::setApplicationName( "QGIS-TEST" );
5656

5757
QgsApplication::showSettings();
58+
59+
// enforce C locale because the tests expect it
60+
// (decimal separators / thousand separators)
61+
QLocale::setDefault( QLocale::c() );
5862
}
5963

6064
void TestQgsMapToolIdentifyAction::cleanupTestCase()

‎tests/src/app/testqgsmeasuretool.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ void TestQgsMeasureTool::initTestCase()
6969

7070
mQgisApp = new QgisApp();
7171
mCanvas = new QgsMapCanvas();
72+
73+
// enforce C locale because the tests expect it
74+
// (decimal separators / thousand separators)
75+
QLocale::setDefault( QLocale::c() );
7276
}
7377

7478
//runs after all tests

‎tests/src/python/test_qgsunittypes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
QGis,
2121
QgsSymbolV2
2222
)
23+
from PyQt4.QtCore import QLocale
24+
25+
# enforce C locale because the tests expect it
26+
# (decimal separators / thousand separators)
27+
QLocale.setDefault(QLocale.c())
2328

2429

2530
class TestQgsUnitTypes(unittest.TestCase):

0 commit comments

Comments
 (0)