mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Fix tests
This commit is contained in:
parent
75885d70d5
commit
3734a0d677
@ -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 @@ from qgis.core import (QgsComposition,
|
||||
QgsPointXY,
|
||||
QgsRasterLayer,
|
||||
QgsMultiBandColorRenderer,
|
||||
QgsProject)
|
||||
QgsProject,
|
||||
QgsCoordinateFormatter)
|
||||
|
||||
from qgis.testing import start_app, unittest
|
||||
from qgis.testing.mocked import get_iface
|
||||
@ -49,7 +50,7 @@ class TestQgsComposition(unittest.TestCase):
|
||||
"""
|
||||
# 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 @@ __copyright__ = 'Copyright 2015, The QGIS Project'
|
||||
__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 @@ class TestQgsCoordinateFormatter(TestCase):
|
||||
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 @@ class TestQgsCoordinateFormatter(TestCase):
|
||||
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′")
|
||||
|
Loading…
x
Reference in New Issue
Block a user