Skip to content
Permalink
Browse files

fix travis and use qgscoordinateformatter

  • Loading branch information
PeterPetrik committed May 23, 2018
1 parent 32836da commit 3f5babddfa7aa60d7d053b4a953151cf0257067f
@@ -62,6 +62,8 @@ void QgsQuickPlugin::registerTypes( const char *uri )
qRegisterMetaType< QgsPointXY >( "QgsPointXY" );
qRegisterMetaType< QgsQuickFeatureLayerPair >( "QgsQuickFeatureLayerPair" );
qRegisterMetaType< QgsUnitTypes::DistanceUnit >( "QgsUnitTypes::DistanceUnit" );
qRegisterMetaType< QgsCoordinateFormatter::FormatFlags >( "QgsCoordinateFormatter::FormatFlags" );
qRegisterMetaType< QgsCoordinateFormatter::Format >( "QgsCoordinateFormatter::Format" );

qmlRegisterType< QgsProject >( uri, 0, 1, "Project" );
qmlRegisterType< QgsQuickFeatureHighlight >( uri, 0, 1, "FeatureHighlight" );
@@ -121,9 +121,6 @@ class QUICK_EXPORT QgsQuickPositionKit : public QObject
//! \copydoc QgsQuickPositionKit::position
bool hasPosition() const;

//! \copydoc QgsQuickPositionKit::positionLabel
QString positionLabel() const;

//! \copydoc QgsQuickPositionKit::position
QgsPoint position() const;

@@ -191,13 +188,10 @@ class QUICK_EXPORT QgsQuickPositionKit : public QObject
//! \copydoc QgsQuickPositionKit::position
void positionChanged();

//! \copydoc QgsQuickPositionKit::positionLabel
QString positionLabelChanged();

//! \copydoc QgsQuickPositionKit::projectedPosition
void projectedPositionChanged();

//! \copydoc QgsQuickPositionKit::screenPositionChanged
//! \copydoc QgsQuickPositionKit::screenPosition
void screenPositionChanged();

//! hasPosition changed
@@ -241,7 +235,6 @@ class QUICK_EXPORT QgsQuickPositionKit : public QObject
QGeoPositionInfoSource *gpsSource();
QGeoPositionInfoSource *simulatedSource( double longitude, double latitude, double radius );

QString mPositionLabel;
QgsPoint mPosition;
QgsPoint mProjectedPosition;
QPointF mScreenPosition;
@@ -100,12 +100,16 @@ QUrl QgsQuickUtils::getThemeIcon( const QString &name )
return QUrl( path );
}

QString QgsQuickUtils::qgsPointToString( const QgsPoint &point, int decimals )
QString QgsQuickUtils::formatPoint(
const QgsPoint &point,
QgsCoordinateFormatter::Format format,
int decimals,
QgsCoordinateFormatter::FormatFlags flags )
{
return QString( "%1, %2" ).arg( QString::number( point.x(), 'f', decimals ) ).arg( QString::number( point.y(), 'f', decimals ) );
return QgsCoordinateFormatter::format( point, format, decimals, flags );
}

QString QgsQuickUtils::distanceToString( double distance, QgsUnitTypes::DistanceUnit units, int decimals )
QString QgsQuickUtils::formatDistance( double distance, QgsUnitTypes::DistanceUnit units, int decimals )
{
double dist = distance * QgsUnitTypes::fromUnitToUnitFactor( units, QgsUnitTypes::DistanceMeters );

@@ -32,6 +32,7 @@
#include "qgsquickfeaturelayerpair.h"
#include "qgis_quick.h"
#include "qgsfeature.h"
#include "qgscoordinateformatter.h"

class QgsVectorLayer;
class QgsCoordinateReferenceSystem;
@@ -123,11 +124,12 @@ class QUICK_EXPORT QgsQuickUtils: public QObject
*/
Q_INVOKABLE const QUrl getThemeIcon( const QString &name );

/**
* Converts point to string with given decimals (default decimals = 3),
* e.g. -2.234521, 34.4444421 -> -2.234, 34.444
*/
Q_INVOKABLE static QString qgsPointToString( const QgsPoint &point, int decimals = 3 );
//! \copydoc QgsCoordinateFormatter::format()
Q_INVOKABLE static QString formatPoint(
const QgsPoint &point,
QgsCoordinateFormatter::Format format = QgsCoordinateFormatter::FormatPair,
int decimals = 3,
QgsCoordinateFormatter::FormatFlags flags = QgsCoordinateFormatter::FlagDegreesUseStringSuffix );

/**
* Converts distance in meters to human readable
@@ -140,7 +142,7 @@ class QUICK_EXPORT QgsQuickUtils: public QObject
* \param decimals decimal to use
* \returns string represetation of dist
*/
Q_INVOKABLE static QString distanceToString( double distance, QgsUnitTypes::DistanceUnit units, int decimals = 1 );
Q_INVOKABLE static QString formatDistance( double distance, QgsUnitTypes::DistanceUnit units, int decimals = 1 );

//! Returns a string with information about screen size and resolution - useful for debugging
QString dumpScreenInfo() const;
@@ -103,9 +103,9 @@ ApplicationWindow {
text: {
var label = "Signal Lost"
if ( positionKit.hasPosition )
label = QgsQuick.Utils.qgsPointToString( positionKit.position, 3 )
label = QgsQuick.Utils.formatPoint( positionKit.position )
if (positionKit.accuracy > 0)
label += " (" + QgsQuick.Utils.distanceToString( positionKit.accuracy, positionKit.accuracyUnits, 0 ) + ")"
label += " (" + QgsQuick.Utils.formatDistance( positionKit.accuracy, positionKit.accuracyUnits, 0 ) + ")"
label;
}
height: scaleBar.height
@@ -129,7 +129,7 @@ ApplicationWindow {
id: webPositionLabel
text: {
if ( positionKit.hasPosition )
QgsQuick.Utils.qgsPointToString( coordinateTransformer.projectedPosition, 3 ) + " (web mercator)"
QgsQuick.Utils.formatPoint( coordinateTransformer.projectedPosition ) + " (web mercator)"
}
height: scaleBar.height
x: window.width - width
@@ -38,8 +38,8 @@ class TestQgsQuickUtils: public QObject
void dump_screen_info();
void screenUnitsToMeters();
void transformedPoint();
void qgsPointToString();
void distanceToString();
void formatPoint();
void formatDistance();

private:
QgsQuickUtils utils;
@@ -73,12 +73,12 @@ void TestQgsQuickUtils::screenUnitsToMeters()
void TestQgsQuickUtils::transformedPoint()
{
QgsPointXY pointXY = utils.pointXYFactory( 49.9, 16.3 );
QVERIFY( pointXY.x() == 49.9 );
QVERIFY( pointXY.y() == 16.3 );
QGSCOMPARENEAR( pointXY.x(), 49.9, 1e-4 );
QGSCOMPARENEAR( pointXY.y(), 16.3, 1e-4 );

QgsPoint point = utils.pointFactory( 1.0, -1.0 );
QVERIFY( point.x() == 1.0 );
QVERIFY( point.y() == -1.0 );
QGSCOMPARENEAR( point.x(), 1.0, 1e-4 );
QGSCOMPARENEAR( point.y(), -1.0, 1e-4 );

QgsCoordinateReferenceSystem crs3857 = QgsCoordinateReferenceSystem::fromEpsgId( 3857 );
QVERIFY( crs3857.authid() == "EPSG:3857" );
@@ -90,47 +90,38 @@ void TestQgsQuickUtils::transformedPoint()
crs3857,
QgsCoordinateTransformContext(),
pointXY );
QVERIFY( fabs( transformedPoint.x() - 5554843 ) < 1.0 );
QVERIFY( fabs( transformedPoint.y() - 1839491 ) < 1.0 );
QGSCOMPARENEAR( transformedPoint.x(), 5554843, 1.0 );
QGSCOMPARENEAR( transformedPoint.y(), 1839491, 1.0 );
}

void TestQgsQuickUtils::qgsPointToString()
void TestQgsQuickUtils::formatPoint()
{
QgsPoint point( -2.234521, 34.4444421 );
QString point2str = utils.qgsPointToString( point, 3 );
QVERIFY( point2str == "-2.235, 34.444" );

point2str = utils.qgsPointToString( point, 2 );
QVERIFY( point2str == "-2.23, 34.44" );

point2str = utils.qgsPointToString( point, 1 );
QVERIFY( point2str == "-2.2, 34.4" );

point2str = utils.qgsPointToString( point, 0 );
QVERIFY( point2str == "-2, 34" );
QString point2str = utils.formatPoint( point );
QVERIFY( point2str == "-2.235,34.444" );
}

void TestQgsQuickUtils::distanceToString()
void TestQgsQuickUtils::formatDistance()
{
QString dist2str = utils.distanceToString( 1222.234, QgsUnitTypes::DistanceMeters, 2 );
QString dist2str = utils.formatDistance( 1222.234, QgsUnitTypes::DistanceMeters, 2 );
QVERIFY( dist2str == "1.22 km" );

dist2str = utils.distanceToString( 1222.234, QgsUnitTypes::DistanceMeters, 1 );
dist2str = utils.formatDistance( 1222.234, QgsUnitTypes::DistanceMeters, 1 );
QVERIFY( dist2str == "1.2 km" );

dist2str = utils.distanceToString( 1222.234, QgsUnitTypes::DistanceMeters, 0 );
dist2str = utils.formatDistance( 1222.234, QgsUnitTypes::DistanceMeters, 0 );
QVERIFY( dist2str == "1 km" );

dist2str = utils.distanceToString( 700.22, QgsUnitTypes::DistanceMeters, 1 );
dist2str = utils.formatDistance( 700.22, QgsUnitTypes::DistanceMeters, 1 );
QVERIFY( dist2str == "700.2 m" );

dist2str = utils.distanceToString( 0.22, QgsUnitTypes::DistanceMeters, 0 );
dist2str = utils.formatDistance( 0.22, QgsUnitTypes::DistanceMeters, 0 );
QVERIFY( dist2str == "220 mm" );

dist2str = utils.distanceToString( -0.22, QgsUnitTypes::DistanceMeters, 0 );
dist2str = utils.formatDistance( -0.22, QgsUnitTypes::DistanceMeters, 0 );
QVERIFY( dist2str == "0 m" );

dist2str = utils.distanceToString( 1.222234, QgsUnitTypes::DistanceKilometers, 2 );
dist2str = utils.formatDistance( 1.222234, QgsUnitTypes::DistanceKilometers, 2 );
QVERIFY( dist2str == "1.22 km" );
}

0 comments on commit 3f5babd

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