Skip to content

Commit 0b798dc

Browse files
Withaliongabriel-bolbotina
authored andcommitted
Cherry pick some GNSS improvements (#4251)
1 parent a297c38 commit 0b798dc

File tree

6 files changed

+102
-1
lines changed

6 files changed

+102
-1
lines changed

app/position/positionkit.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ void PositionKit::parsePositionUpdate( const GeoPosition &newPosition )
212212
hasAnythingChanged = true;
213213
}
214214

215+
if ( !qgsDoubleNear( newPosition.elevation_diff, mPosition.elevation_diff ) )
216+
{
217+
mPosition.elevation_diff = newPosition.elevation_diff;
218+
emit geoidSeparationChanged( mPosition.elevation_diff );
219+
hasAnythingChanged = true;
220+
}
221+
215222
if ( newPosition.hasValidPosition() != mHasPosition )
216223
{
217224
mHasPosition = newPosition.hasValidPosition();
@@ -349,6 +356,11 @@ double PositionKit::altitude() const
349356
return mPosition.elevation;
350357
}
351358

359+
double PositionKit::geoidSeparation() const
360+
{
361+
return mPosition.elevation_diff;
362+
}
363+
352364
QgsPoint PositionKit::positionCoordinate() const
353365
{
354366
if ( mPosition.hasValidPosition() )

app/position/positionkit.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ class PositionKit : public QObject
3030

3131
Q_PROPERTY( double latitude READ latitude NOTIFY latitudeChanged )
3232
Q_PROPERTY( double longitude READ longitude NOTIFY longitudeChanged )
33+
3334
Q_PROPERTY( double altitude READ altitude NOTIFY altitudeChanged )
35+
Q_PROPERTY( double geoidSeparation READ geoidSeparation NOTIFY geoidSeparationChanged )
3436

3537
// auxiliary property providing QgsPoint for lat/long/alt instead of separate properties
3638
Q_PROPERTY( QgsPoint positionCoordinate READ positionCoordinate NOTIFY positionCoordinateChanged )
@@ -84,6 +86,7 @@ class PositionKit : public QObject
8486
double latitude() const;
8587
double longitude() const;
8688
double altitude() const;
89+
double geoidSeparation() const;
8790
QgsPoint positionCoordinate() const;
8891
bool hasPosition() const;
8992

@@ -127,6 +130,7 @@ class PositionKit : public QObject
127130
void latitudeChanged( double );
128131
void longitudeChanged( double );
129132
void altitudeChanged( double );
133+
void geoidSeparationChanged( double );
130134
void positionCoordinateChanged( QgsPoint );
131135
void hasPositionChanged( bool );
132136

app/qml/gps/MMGpsDataDrawer.qml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,21 @@ MMComponents.MMDrawer {
316316

317317
alignmentRight: Positioner.index % 2 === 1
318318
}
319+
320+
MMGpsComponents.MMGpsDataText {
321+
width: parent.width / 2
322+
323+
title: qsTr( "Geoid separation" )
324+
value: {
325+
if ( !__positionKit.hasPosition || Number.isNaN( __positionKit.geoidSeparation ) ) {
326+
return qsTr( "N/A" )
327+
}
328+
__inputUtils.formatNumber( __positionKit.geoidSeparation, 2 ) + " m"
329+
}
330+
visible: __positionKit.positionProvider && __positionKit.positionProvider.type() === "external"
331+
332+
alignmentRight: Positioner.index % 2 === 1
333+
}
319334
}
320335
}
321336

app/variablesmanager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ QgsExpressionContextScope *VariablesManager::positionScope()
7272
addPositionVariable( scope, QStringLiteral( "longitude" ), position.longitude );
7373
addPositionVariable( scope, QStringLiteral( "latitude" ), position.latitude );
7474
addPositionVariable( scope, QStringLiteral( "altitude" ), position.elevation );
75+
addPositionVariable( scope, QStringLiteral( "geoid_separation" ), position.elevation_diff );
7576
addPositionVariable( scope, QStringLiteral( "horizontal_accuracy" ), getGeoPositionAttribute( position.hacc ) );
7677
addPositionVariable( scope, QStringLiteral( "vertical_accuracy" ), getGeoPositionAttribute( position.vacc ) );
7778
addPositionVariable( scope, QStringLiteral( "ground_speed" ), getGeoPositionAttribute( position.speed ) );
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
diff --git a/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java b/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java
2+
index e4163b09..afb2889e 100644
3+
--- a/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java
4+
+++ b/src/plugins/position/android/jar/src/org/qtproject/qt/android/positioning/QtPositioning.java
5+
@@ -112,6 +112,8 @@ class QtPositioning implements LocationListener
6+
static private void addMslAltitude(Location location)
7+
{
8+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
9+
+ if (location.hasMslAltitude()) // Nothing to be done
10+
+ return;
11+
if (altitudeConverter == null)
12+
altitudeConverter = new AltitudeConverter();
13+
try {
14+
diff --git a/src/plugins/position/android/src/jnipositioning.cpp b/src/plugins/position/android/src/jnipositioning.cpp
15+
index 2b2919fa..0abc2cad 100644
16+
--- a/src/plugins/position/android/src/jnipositioning.cpp
17+
+++ b/src/plugins/position/android/src/jnipositioning.cpp
18+
@@ -220,7 +220,7 @@ namespace AndroidPositioning {
19+
return ret;
20+
}
21+
22+
- QGeoPositionInfo positionInfoFromJavaLocation(const jobject &location)
23+
+ QGeoPositionInfo positionInfoFromJavaLocation(const jobject &location, bool useAltConverter)
24+
{
25+
QGeoPositionInfo info;
26+
27+
@@ -241,8 +241,11 @@ namespace AndroidPositioning {
28+
coordinate.setAltitude(value);
29+
}
30+
// MSL altitude, available in API Level 34+.
31+
- // It will be available only if we requested it when starting updates.
32+
- if (QNativeInterface::QAndroidApplication::sdkVersion() >= 34) {
33+
+ // In API Level 34 it was available only if we manually added it.
34+
+ // In API Level 35 (and potentially later), it's automatically added
35+
+ // to the location object, so we need to use it *only* when the user
36+
+ // set the relevant plugin parameter.
37+
+ if (useAltConverter && QNativeInterface::QAndroidApplication::sdkVersion() >= 34) {
38+
attributeExists = jniObject.callMethod<jboolean>("hasMslAltitude");
39+
if (attributeExists) {
40+
const jdouble value = jniObject.callMethod<jdouble>("getMslAltitudeMeters");
41+
@@ -451,7 +454,7 @@ namespace AndroidPositioning {
42+
if (location == nullptr)
43+
return QGeoPositionInfo();
44+
45+
- const QGeoPositionInfo info = positionInfoFromJavaLocation(location);
46+
+ const QGeoPositionInfo info = positionInfoFromJavaLocation(location, useAltitudeConverter);
47+
48+
return info;
49+
}
50+
@@ -615,7 +618,6 @@ static void positionUpdated(JNIEnv *env, jobject thiz, QtJniTypes::Location loca
51+
{
52+
Q_UNUSED(env);
53+
Q_UNUSED(thiz);
54+
- QGeoPositionInfo info = AndroidPositioning::positionInfoFromJavaLocation(location.object());
55+
56+
QGeoPositionInfoSourceAndroid *source = AndroidPositioning::idToPosSource()->value(androidClassKey);
57+
if (!source) {
58+
@@ -623,6 +625,10 @@ static void positionUpdated(JNIEnv *env, jobject thiz, QtJniTypes::Location loca
59+
return;
60+
}
61+
62+
+ const bool useAltitudeConverter = source->useAltitudeConverter();
63+
+ QGeoPositionInfo info =
64+
+ AndroidPositioning::positionInfoFromJavaLocation(location.object(), useAltitudeConverter);
65+
+
66+
//we need to invoke indirectly as the Looper thread is likely to be not the same thread
67+
if (!isSingleUpdate)
68+
QMetaObject::invokeMethod(source, "processPositionUpdate", Qt::AutoConnection,

vcpkg/ports/qtpositioning/portfile.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ include("${SCRIPT_PATH}/qt_install_submodule.cmake")
33

44
set(${PORT}_PATCHES
55
devendor-poly2tri.patch
6-
foregroundservice.patch)
6+
foregroundservice.patch
7+
android15_altitude_fix.patch)
78

89
vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
910
FEATURES

0 commit comments

Comments
 (0)