Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use distance unit from project's CRS for Stakeout panel #2826

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,22 @@ QString InputUtils::formatNumber( const double number, int precision )
return QString::number( number, 'f', precision );
}

QString InputUtils::formatDistanceInProjectUnit( const double distanceInMeters, int precision )
{
Qgis::DistanceUnit distUnit = QgsProject::instance()->distanceUnits();

if ( distUnit == Qgis::DistanceUnit::Unknown )
{
return QString::number( distanceInMeters, 'f', precision );
}

double factor = QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, distUnit );
double distance = distanceInMeters * factor;
QString abbreviation = QgsUnitTypes::toAbbreviatedString( distUnit );

return QString( "%1 %2" ).arg( QString::number( distance, 'f', precision ), abbreviation );
}

QString InputUtils::formatDateTimeDiff( const QDateTime &tMin, const QDateTime &tMax )
{
qint64 daysDiff = tMin.daysTo( tMax );
Expand Down
1 change: 1 addition & 0 deletions app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class InputUtils: public QObject
Q_INVOKABLE QString getFileName( const QString &filePath );
Q_INVOKABLE QString formatProjectName( const QString &fullProjectName );
Q_INVOKABLE QString formatNumber( const double number, int precision = 1 );
Q_INVOKABLE QString formatDistanceInProjectUnit( const double distanceInMeters, int precision = 1 );
Q_INVOKABLE void setExtentToFeature( const FeatureLayerPair &pair, InputMapSettings *mapSettings, double panelOffsetRatio );

// utility functions to extract information from map settings
Expand Down
2 changes: 1 addition & 1 deletion app/qml/StakeoutPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ Item {
width: parent.width / 2

titleText: qsTr( "Distance" )
text: remainingDistance >= 0 ?__inputUtils.formatNumber( remainingDistance, 2 ) + " m" : "N/A m"
text: remainingDistance >= 0 ?__inputUtils.formatDistanceInProjectUnit( remainingDistance, 2 ) : "N/A"

titleComponent.wrapMode: Text.NoWrap
titleComponent.elide: Text.ElideRight
Expand Down
Loading