Skip to content
Permalink
Browse files

Fix tests

  • Loading branch information
nyalldawson committed Nov 15, 2017
1 parent 75885d7 commit 3734a0d677d372229d0bcbdd9ec1ba1f50457c0e
@@ -105,9 +105,10 @@ Sets the x and y value of the point
:rtype: QPointF
%End

QString toString( int precision = 12 ) const;
QString toString( int precision = -1 ) const;
%Docstring
Returns a string representation of the point (x, y) with a preset ``precision``.
If ``precision`` is -1, then a default precision will be used.
:rtype: str
%End

@@ -44,9 +44,20 @@ QPointF QgsPointXY::toQPointF() const

QString QgsPointXY::toString( int precision ) const
{
QString x = std::isfinite( mX ) ? QString::number( mX, 'f', precision ) : QObject::tr( "infinite" );
QString y = std::isfinite( mY ) ? QString::number( mY, 'f', precision ) : QObject::tr( "infinite" );
return QStringLiteral( "%1,%2" ).arg( x, y );
if ( precision < 0 )
{
QString rep;
QTextStream ot( &rep );
ot.setRealNumberPrecision( 12 );
ot << mX << ", " << mY;
return rep;
}
else
{
QString x = std::isfinite( mX ) ? QString::number( mX, 'f', precision ) : QObject::tr( "infinite" );
QString y = std::isfinite( mY ) ? QString::number( mY, 'f', precision ) : QObject::tr( "infinite" );
return QStringLiteral( "%1,%2" ).arg( x, y );
}
}

QString QgsPointXY::asWkt() const
@@ -149,8 +149,9 @@ class CORE_EXPORT QgsPointXY

/**
* Returns a string representation of the point (x, y) with a preset \a precision.
* If \a precision is -1, then a default precision will be used.
*/
QString toString( int precision = 12 ) const;
QString toString( int precision = -1 ) const;

/**
* Return the well known text representation for the point (e.g. "POINT(x y)").
@@ -23,7 +23,8 @@
QgsPointXY,
QgsRasterLayer,
QgsMultiBandColorRenderer,
QgsProject)
QgsProject,
QgsCoordinateFormatter)

from qgis.testing import start_app, unittest
from qgis.testing.mocked import get_iface
@@ -49,7 +50,7 @@ def testSubstitutionMap(self):
"""
# Create a point and convert it to text containing a degree symbol.
myPoint = QgsPointXY(12.3, -33.33)
myCoordinates = myPoint.toDegreesMinutesSeconds(2)
myCoordinates = QgsCoordinateFormatter.format(myPoint, QgsCoordinateFormatter.FormatDegreesMinutesSeconds, 2)
myTokens = myCoordinates.split(',')
myLongitude = myTokens[0]
myLatitude = myTokens[1]
@@ -13,11 +13,11 @@
__revision__ = '$Format:%H$'

import qgis
from utilities import unittest, TestCase
from qgis.testing import unittest
from qgis.core import QgsCoordinateFormatter


class TestQgsCoordinateFormatter(TestCase):
class TestQgsCoordinateFormatter(unittest.TestCase):

def testFormatXPair(self):
"""Test formatting x as pair"""
@@ -208,7 +208,7 @@ def testFormatXDegreesMinutes(self):
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")

# test with padding
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FormatDegreesMinutes | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
self.assertEqual(QgsCoordinateFormatter.formatX(80, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"80°00.00′E")
self.assertEqual(QgsCoordinateFormatter.formatX(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
self.assertEqual(QgsCoordinateFormatter.formatX(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
@@ -257,7 +257,7 @@ def testFormatYDegreesMinutes(self):
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 5, QgsCoordinateFormatter.FormatFlags()), u"-0°0.00006′")

# test with padding
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FormatDegreesMinutes | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
padding_and_suffix = QgsCoordinateFormatter.FormatFlags(QgsCoordinateFormatter.FlagDegreesPadMinutesSeconds | QgsCoordinateFormatter.FlagDegreesUseStringSuffix)
self.assertEqual(QgsCoordinateFormatter.formatY(20, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"20°00.00′N")
self.assertEqual(QgsCoordinateFormatter.formatY(0, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")
self.assertEqual(QgsCoordinateFormatter.formatY(-0.000001, QgsCoordinateFormatter.FormatDegreesMinutes, 2, padding_and_suffix), u"0°00.00′")

0 comments on commit 3734a0d

Please sign in to comment.
You can’t perform that action at this time.