Skip to content

Commit

Permalink
Measurement Tool (#3574)
Browse files Browse the repository at this point in the history
  • Loading branch information
VitorVieiraZ authored Oct 22, 2024
1 parent af1a10e commit 237bd52
Show file tree
Hide file tree
Showing 32 changed files with 1,246 additions and 54 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ jobs:
-S ../ \
-B ./
- name: build APK
- name: Build APK
env:
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
ANDROID_NDK_HOST: darwin-x86_64
Expand All @@ -271,7 +271,7 @@ jobs:
path: ${{ github.workspace }}/merginmaps-${{ env.INPUT_VERSION_CODE }}.apk
name: Mergin Maps ${{ env.INPUT_VERSION_CODE }} APK [v7 + v8a]

- name: build AAB
- name: Build AAB
if: ${{ github.ref_name == 'master' || github.ref_type == 'tag' }}
env:
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
Expand All @@ -298,4 +298,3 @@ jobs:
with:
path: ${{ github.workspace }}/merginmaps-${{ env.INPUT_VERSION_CODE }}.aab
name: Mergin Maps ${{ env.INPUT_VERSION_CODE }} AAB

2 changes: 2 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ set(MM_SRCS
maptools/abstractmaptool.cpp
maptools/recordingmaptool.cpp
maptools/splittingmaptool.cpp
maptools/measurementmaptool.cpp
ios/iosimagepicker.cpp
ios/iosutils.cpp
position/providers/abstractpositionprovider.cpp
Expand Down Expand Up @@ -109,6 +110,7 @@ set(MM_HDRS
maptools/abstractmaptool.h
maptools/recordingmaptool.h
maptools/splittingmaptool.h
maptools/measurementmaptool.h
ios/iosimagepicker.h
ios/iosutils.h
position/providers/abstractpositionprovider.h
Expand Down
7 changes: 7 additions & 0 deletions app/icons/CloseShape.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions app/icons/Measure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions app/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,7 @@
<file>ZoomToProject.svg</file>
<file>StakeOut.svg</file>
<file>Student.svg</file>
<file>Measure.svg</file>
<file>CloseShape.svg</file>
</qresource>
</RCC>
23 changes: 23 additions & 0 deletions app/images/NeutralMMSymbol.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<file>ExternalGpsGreen.svg</file>
<file>NegativeMMSymbol.svg</file>
<file>PositiveMMSymbol.svg</file>
<file>NeutralMMSymbol.svg</file>
<file>CloseAccount.svg</file>
<file>Attention.svg</file>
<file>Bubble.svg</file>
Expand Down
48 changes: 38 additions & 10 deletions app/inpututils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,48 @@ QString InputUtils::formatNumber( const double number, int precision )
return QString::number( number, 'f', precision );
}

QString InputUtils::formatDistanceInProjectUnit( const double distanceInMeters, int precision, Qgis::DistanceUnit destUnit )
QString InputUtils::formatDistanceInProjectUnit( const double distanceInMeters, int precision, QgsProject *project )
{
Qgis::DistanceUnit distUnit = destUnit;
if ( !project )
return QString();

return InputUtils::formatDistanceHelper( distanceInMeters, precision, project->distanceUnits() );
}

if ( distUnit == Qgis::DistanceUnit::Unknown )
QString InputUtils::formatDistanceHelper( const double distanceInMeters, int precision, Qgis::DistanceUnit destUnit )
{
if ( destUnit == Qgis::DistanceUnit::Unknown )
{
distUnit = QgsProject::instance()->distanceUnits();
destUnit = Qgis::DistanceUnit::Meters;
}

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

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

QString InputUtils::formatAreaInProjectUnit( const double areaInSquareMeters, int precision, QgsProject *project )
{
if ( !project )
return QString();

return InputUtils::formatAreaHelper( areaInSquareMeters, precision, project->areaUnits() );
}

QString InputUtils::formatAreaHelper( const double areaInSquareMeters, int precision, Qgis::AreaUnit destUnit )
{
if ( destUnit == Qgis::AreaUnit::Unknown )
{
return QString::number( distanceInMeters, 'f', precision );
destUnit = Qgis::AreaUnit::SquareMeters;
}

double factor = QgsUnitTypes::fromUnitToUnitFactor( Qgis::DistanceUnit::Meters, distUnit );
double distance = distanceInMeters * factor;
QString abbreviation = QgsUnitTypes::toAbbreviatedString( distUnit );
const double factor = QgsUnitTypes::fromUnitToUnitFactor( Qgis::AreaUnit::SquareMeters, destUnit );
const double area = areaInSquareMeters * factor;
const QString abbreviation = QgsUnitTypes::toAbbreviatedString( destUnit );

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

QString InputUtils::formatDateTimeDiff( const QDateTime &tMin, const QDateTime &tMax )
Expand Down Expand Up @@ -2194,3 +2217,8 @@ bool InputUtils::openLink( const QString &homePath, const QString &link )

return true;
}

double InputUtils::pixelDistanceBetween( const QPointF &p1, const QPointF &p2 )
{
return std::hypot( p1.x() - p2.x(), p1.y() - p2.y() );
}
12 changes: 11 additions & 1 deletion app/inpututils.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ 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, Qgis::DistanceUnit destUnit = Qgis::DistanceUnit::Unknown );
Q_INVOKABLE QString formatDistanceInProjectUnit( const double distanceInMeters, int precision, QgsProject *project );
Q_INVOKABLE QString formatAreaInProjectUnit( const double areaInSquareMeters, int precision, QgsProject *project );

static QString formatDistanceHelper( const double distanceInMeters, int precision, Qgis::DistanceUnit destUnit );
static QString formatAreaHelper( const double areaInSquareMeters, int precision, Qgis::AreaUnit destUnit );

Q_INVOKABLE void setExtentToFeature( const FeatureLayerPair &pair, InputMapSettings *mapSettings );

/**
Expand Down Expand Up @@ -579,6 +584,11 @@ class InputUtils: public QObject
*/
static QVector<QString> qgisProfilerLog();

/**
* Calculates the Euclidean distance between two pixel points
*/
static double pixelDistanceBetween( const QPointF &p1, const QPointF &p2 );

public slots:
void onQgsLogMessageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level );

Expand Down
2 changes: 2 additions & 0 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
#include "maptools/abstractmaptool.h"
#include "maptools/recordingmaptool.h"
#include "maptools/splittingmaptool.h"
#include "maptools/measurementmaptool.h"

#include "layer/layertreemodel.h"
#include "layer/layertreemodelpixmapprovider.h"
Expand Down Expand Up @@ -348,6 +349,7 @@ void initDeclarative()
qmlRegisterUncreatableType< AbstractMapTool >( "mm", 1, 0, "AbstractMapTool", "Instantiate one of child map tools instead" );
qmlRegisterType< RecordingMapTool >( "mm", 1, 0, "RecordingMapTool" );
qmlRegisterType< SplittingMapTool >( "mm", 1, 0, "SplittingMapTool" );
qmlRegisterType< MeasurementMapTool >( "mm", 1, 0, "MeasurementMapTool" );
}

void addQmlImportPath( QQmlEngine &engine )
Expand Down
4 changes: 4 additions & 0 deletions app/maptools/abstractmaptool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ void AbstractMapTool::setMapSettings( InputMapSettings *newMapSettings )
{
if ( mMapSettings == newMapSettings )
return;

emit onAboutToChangeMapSettings();

mMapSettings = newMapSettings;

emit mapSettingsChanged( mMapSettings );
}
3 changes: 1 addition & 2 deletions app/maptools/abstractmaptool.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ class AbstractMapTool : public QObject
void setMapSettings( InputMapSettings *newMapSettings );

signals:

void onAboutToChangeMapSettings();
void mapSettingsChanged( InputMapSettings *mapSettings );

private:

InputMapSettings *mMapSettings = nullptr;
};

Expand Down
Loading

0 comments on commit 237bd52

Please sign in to comment.