Skip to content

Commit

Permalink
Use distance unit from QGis projekt in Stakeout panel
Browse files Browse the repository at this point in the history
  • Loading branch information
iiLubos committed Oct 3, 2023
1 parent ae5c2fc commit 9cf63a2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,18 @@ QString InputUtils::formatNumber( const double number, int precision )
return QString::number( number, 'f', precision );
}

QString InputUtils::formatDistanceInProjectUnit( InputMapSettings *mapSettings, const double distanceInMeters, int precision )
QString InputUtils::formatDistanceInProjectUnit( const double distanceInMeters, int precision )
{
QgsCoordinateReferenceSystem projectCrs = mapSettings->destinationCrs();
Qgis::DistanceUnit distUnit = QgsProject::instance()->distanceUnits();

if ( !projectCrs.isValid() || projectCrs.mapUnits() == Qgis::DistanceUnit::Unknown )
if ( distUnit == Qgis::DistanceUnit::Unknown )
{
return QString::number( distanceInMeters, 'f', precision );
}

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

return QString( "%1 %2" ).arg( QString::number( distance, 'f', precision ), abbreviation );
}
Expand Down
2 changes: 1 addition & 1 deletion app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +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( InputMapSettings *mapSettings, const double distanceInMeters, 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.formatDistanceInProjectUnit( root.mapCanvas.mapSettings, remainingDistance, 2 ) : "N/A"
text: remainingDistance >= 0 ?__inputUtils.formatDistanceInProjectUnit( remainingDistance, 2 ) : "N/A"

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

1 comment on commit 9cf63a2

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 23.10.462511 just submitted!

Please sign in to comment.