Skip to content

Commit

Permalink
Fix missing transform context warnings on status bar coordinate display
Browse files Browse the repository at this point in the history
(cherry-picked from 55814b8)
  • Loading branch information
nyalldawson committed Mar 6, 2018
1 parent 9ae1e93 commit 63d587c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/app/qgsstatusbarcoordinateswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 6 additions & 5 deletions src/core/qgscoordinateutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) )
Expand All @@ -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 );
Expand Down
8 changes: 7 additions & 1 deletion src/core/qgscoordinateutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 );

};

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down

0 comments on commit 63d587c

Please sign in to comment.