Skip to content
Permalink
Browse files

[ui] Format status bar coordinate widget's extent using project settings

  • Loading branch information
nirvn committed Jan 9, 2021
1 parent 24aa545 commit 760a436f4f52a02533140b3f24c0828f8fdbd071
Showing with 19 additions and 3 deletions.
  1. +2 −3 src/app/qgsstatusbarcoordinateswidget.cpp
  2. +9 −0 src/core/qgscoordinateutils.cpp
  3. +8 −0 src/core/qgscoordinateutils.h
@@ -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();
}
@@ -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 )
@@ -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-" ) );
@@ -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
@@ -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

0 comments on commit 760a436

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