Skip to content

Commit

Permalink
[ui] Format status bar coordinate widget's extent using project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jan 9, 2021
1 parent 24aa545 commit 760a436
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/app/qgsstatusbarcoordinateswidget.cpp
Expand Up @@ -345,10 +345,9 @@ void QgsStatusBarCoordinatesWidget::showExtent()
return;
}

// update the statusbar with the current extents.
QgsRectangle myExtents = mMapCanvas->extent();
mLabel->setText( tr( "Extents" ) );
mLineEdit->setText( myExtents.toString( true ) );
mLineEdit->setText( QgsCoordinateUtils::formatExtentForProject( QgsProject::instance(), mMapCanvas->extent(), mMapCanvas->mapSettings().destinationCrs(),
mMousePrecisionDecimalPlaces ) );

ensureCoordinatesVisible();
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/qgscoordinateutils.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgis.h"
#include "qgsexception.h"
#include "qgscoordinateformatter.h"
#include "qgsrectangle.h"
///@cond NOT_STABLE_API

int QgsCoordinateUtils::calculateCoordinatePrecision( double mapUnitsPerPixel, const QgsCoordinateReferenceSystem &mapCrs, QgsProject *project )
Expand Down Expand Up @@ -131,6 +132,14 @@ QString QgsCoordinateUtils::formatCoordinateForProject( QgsProject *project, con
}
}

QString QgsCoordinateUtils::formatExtentForProject( QgsProject *project, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &destCrs, int precision )
{
const QgsPointXY p1( extent.xMinimum(), extent.yMinimum() );
const QgsPointXY p2( extent.xMaximum(), extent.yMaximum() );
return QStringLiteral( "%1 : %2" ).arg( QgsCoordinateUtils::formatCoordinateForProject( project, p1, destCrs, precision ),
QgsCoordinateUtils::formatCoordinateForProject( project, p2, destCrs, precision ) );
}

double QgsCoordinateUtils::dmsToDecimal( const QString &string, bool *ok, bool *isEasting )
{
const QString negative( QStringLiteral( "swSW-" ) );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgscoordinateutils.h
Expand Up @@ -28,6 +28,7 @@
class QgsPointXY;
class QgsCoordinateReferenceSystem;
class QgsProject;
class QgsRectangle;

//not stable api - I plan on reworking this when QgsCoordinateFormatter lands in 2.16
///@cond NOT_STABLE_API
Expand Down Expand Up @@ -76,6 +77,13 @@ class CORE_EXPORT QgsCoordinateUtils
*/
Q_INVOKABLE static QString formatCoordinateForProject( QgsProject *project, const QgsPointXY &point, const QgsCoordinateReferenceSystem &destCrs, int precision );

/**
* Formats an \a extent for use with the specified \a project, respecting the project's
* coordinate display settings.
* \since QGIS 3.18
*/
Q_INVOKABLE static QString formatExtentForProject( QgsProject *project, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &destCrs, int precision );

/**
* Converts a degree minute second coordinate string to its decimal equivalent.
* \param string degree minute second string to convert
Expand Down

0 comments on commit 760a436

Please sign in to comment.