Skip to content
Permalink
Browse files

Fix missing transform context warnings on status bar coordinate display

(cherry-picked from 55814b8)
  • Loading branch information
nyalldawson committed Feb 27, 2018
1 parent 9ae1e93 commit 63d587c098839baeef3d71e9069f76a09eaf0cf3
@@ -226,7 +226,7 @@ void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )
return;
}

mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( p, mMapCanvas->mapSettings().destinationCrs(),
mLineEdit->setText( QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), p, mMapCanvas->mapSettings().destinationCrs(),
mMousePrecisionDecimalPlaces ) );

ensureCoordinatesVisible();
@@ -62,9 +62,12 @@ int QgsCoordinateUtils::calculateCoordinatePrecision( double mapUnitsPerPixel, c
return dp;
}

QString QgsCoordinateUtils::formatCoordinateForProject( const QgsPointXY &point, const QgsCoordinateReferenceSystem &destCrs, int precision )
QString QgsCoordinateUtils::formatCoordinateForProject( QgsProject *project, const QgsPointXY &point, const QgsCoordinateReferenceSystem &destCrs, int precision )
{
QString format = QgsProject::instance()->readEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DegreeFormat" ), QStringLiteral( "MU" ) );
if ( !project )
return QString();

QString format = project->readEntry( QStringLiteral( "PositionPrecision" ), QStringLiteral( "/DegreeFormat" ), QStringLiteral( "MU" ) );

QgsPointXY geo = point;
if ( format == QLatin1String( "DM" ) || format == QLatin1String( "DMS" ) || format == QLatin1String( "D" ) )
@@ -73,9 +76,7 @@ QString QgsCoordinateUtils::formatCoordinateForProject( const QgsPointXY &point,
if ( destCrs.isValid() && !destCrs.isGeographic() )
{
// need to transform to geographic coordinates
Q_NOWARN_DEPRECATED_PUSH
QgsCoordinateTransform ct( destCrs, QgsCoordinateReferenceSystem( GEOSRID ) );
Q_NOWARN_DEPRECATED_POP
QgsCoordinateTransform ct( destCrs, QgsCoordinateReferenceSystem( GEOSRID ), project );
try
{
geo = ct.transform( point );
@@ -26,6 +26,7 @@

class QgsPointXY;
class QgsCoordinateReferenceSystem;
class QgsProject;

//not stable api - I plan on reworking this when QgsCoordinateFormatter lands in 2.16
///@cond NOT_STABLE_API
@@ -53,7 +54,12 @@ class CORE_EXPORT QgsCoordinateUtils
*/
static int calculateCoordinatePrecision( double mapUnitsPerPixel, const QgsCoordinateReferenceSystem &mapCrs );

static QString formatCoordinateForProject( const QgsPointXY &point, const QgsCoordinateReferenceSystem &destCrs, int precision );
/**
* Formats a \a point coordinate for use with the specified \a project, respecting the project's
* coordinate display settings.
* \since QGIS 3.2
*/
static QString formatCoordinateForProject( QgsProject *project, const QgsPointXY &point, const QgsCoordinateReferenceSystem &destCrs, int precision );

};

@@ -325,7 +325,7 @@ void QgsMapToolIdentify::closestVertexAttributes( const QgsAbstractGeometry &geo

QString QgsMapToolIdentify::formatCoordinate( const QgsPointXY &canvasPoint ) const
{
return QgsCoordinateUtils::formatCoordinateForProject( canvasPoint, mCanvas->mapSettings().destinationCrs(),
return QgsCoordinateUtils::formatCoordinateForProject( QgsProject::instance(), canvasPoint, mCanvas->mapSettings().destinationCrs(),
mCoordinatePrecision );
}

0 comments on commit 63d587c

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