Skip to content

Commit

Permalink
Fix tests where locale-dependent formatting of numbers is used
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Feb 23, 2016
1 parent b34105d commit 98713a9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/core/qgsdistancearea.cpp
Expand Up @@ -17,7 +17,6 @@
#include <sqlite3.h>
#include <QDir>
#include <QString>
#include <QLocale>
#include <QObject>

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

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

QString QgsDistanceArea::formatArea( double area, int decimals, QgsUnitTypes::AreaUnit unit, bool keepBaseUnit )
Expand Down Expand Up @@ -1229,7 +1228,7 @@ QString QgsDistanceArea::formatArea( double area, int decimals, QgsUnitTypes::Ar
}
}

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

void QgsDistanceArea::convertMeasurement( double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea ) const
Expand Down
3 changes: 1 addition & 2 deletions src/core/qgsunittypes.cpp
Expand Up @@ -16,7 +16,6 @@

#include "qgsunittypes.h"
#include <QCoreApplication>
#include <QLocale>

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

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

// enable for QGIS 3.0
Expand Down
4 changes: 4 additions & 0 deletions tests/src/app/testqgsmaptoolidentifyaction.cpp
Expand Up @@ -55,6 +55,10 @@ void TestQgsMapToolIdentifyAction::initTestCase()
QCoreApplication::setApplicationName( "QGIS-TEST" );

QgsApplication::showSettings();

// enforce C locale because the tests expect it
// (decimal separators / thousand separators)
QLocale::setDefault( QLocale::c() );
}

void TestQgsMapToolIdentifyAction::cleanupTestCase()
Expand Down
4 changes: 4 additions & 0 deletions tests/src/app/testqgsmeasuretool.cpp
Expand Up @@ -69,6 +69,10 @@ void TestQgsMeasureTool::initTestCase()

mQgisApp = new QgisApp();
mCanvas = new QgsMapCanvas();

// enforce C locale because the tests expect it
// (decimal separators / thousand separators)
QLocale::setDefault( QLocale::c() );
}

//runs after all tests
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsunittypes.py
Expand Up @@ -20,6 +20,11 @@
QGis,
QgsSymbolV2
)
from PyQt4.QtCore import QLocale

# enforce C locale because the tests expect it
# (decimal separators / thousand separators)
QLocale.setDefault(QLocale.c())


class TestQgsUnitTypes(unittest.TestCase):
Expand Down

0 comments on commit 98713a9

Please sign in to comment.