From ec43d4172bf2d8243c546a737c3f930009559459 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 8 Nov 2021 17:30:12 +0100 Subject: Fix position handling in geoclue2 plugin The pre-existing code was incorrect due to the operation priority. The result of the comparison was assigned to the variables, so they were always initialized with 0 or 1 instead of real values. Also use std::numeric_limits::lowest(), because the altitude can have a negative value (when we are below sea level). This commit is a manual cherry-pick from qtpositioning.git dev branch Fixes: QTBUG-97722 Change-Id: I2d5beddfdf6d7b4fc626d6b09f4923c968016428 (cherry picked from commit 70b7818e1fc585f8bac43b721f3dd172b7489d07) Reviewed-by: Juha Vuolle --- .../position/geoclue2/qgeopositioninfosource_geoclue2.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp index 8e54a1ea..7f3eb5db 100644 --- a/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp +++ b/src/plugins/position/geoclue2/qgeopositioninfosource_geoclue2.cpp @@ -410,7 +410,8 @@ void QGeoPositionInfoSourceGeoclue2::handleNewLocation(const QDBusObjectPath &ol } else { QGeoCoordinate coordinate(location.latitude(), location.longitude()); - if (const auto altitude = location.altitude() > std::numeric_limits::min()) + const auto altitude = location.altitude(); + if (altitude > std::numeric_limits::lowest()) coordinate.setAltitude(altitude); const Timestamp ts = location.timestamp(); @@ -428,9 +429,11 @@ void QGeoPositionInfoSourceGeoclue2::handleNewLocation(const QDBusObjectPath &ol m_lastPositionFromSatellite = qFuzzyCompare(accuracy, 0.0); m_lastPosition.setAttribute(QGeoPositionInfo::HorizontalAccuracy, accuracy); - if (const auto speed = location.speed() >= 0.0) + const auto speed = location.speed(); + if (speed >= 0.0) m_lastPosition.setAttribute(QGeoPositionInfo::GroundSpeed, speed); - if (const auto heading = location.heading() >= 0.0) + const auto heading = location.heading(); + if (heading >= 0.0) m_lastPosition.setAttribute(QGeoPositionInfo::Direction, heading); emit positionUpdated(m_lastPosition); -- cgit v1.2.1