From 15f06eca6a5085ce14d2eb0b743c5a06365068ea Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 29 Jul 2021 11:34:16 +0200 Subject: QGeoCoordinate: fix toString() conversion Applying qRound() to check if the minutes/seconds should overflow was not the right solution in some cases. It could lead to incorrect overflows, and so - to wrong conversion results. The actual logic of overflow is related to the behavior of QString::number. This patch fixes the logic and also introduces some minor optimizations. After overflow, the minutes or seconds value is always 0.0, because the actual minutes/seconds value is always in range [0; 60). This allows us to get rid of some checks. Fixes: QTBUG-95221 Pick-to: 6.2 5.15 Change-Id: Ie3dcb6cef226b04c43dd973c09c4ae297c583f3b Reviewed-by: Alex Blasche Reviewed-by: Qt CI Bot --- tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp index 820d904d..828b2ef4 100644 --- a/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp +++ b/tests/auto/qgeocoordinate/tst_qgeocoordinate.cpp @@ -875,13 +875,29 @@ private slots: << QString( "2%1 0.000', 2%1 0.000'").arg(DEGREES_SYMB); QTest::newRow("Wrap seconds to minutes to Degrees DM -> above valid long/lat values") - << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds + << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutesSeconds << QString( "90%1 0' 0.0\", 180%1 0' 0.0\"").arg(DEGREES_SYMB); + QTest::newRow("Seconds and minutes near valid long/lat values border") + << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutesSeconds + << QString("89%1 59' 59.6\", 179%1 59' 59.6\"").arg(DEGREES_SYMB); + QTest::newRow("Wrap minutes to Degrees DM ->above valid long/lat values") - << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes + << QGeoCoordinate(89.999999, 179.999999) << QGeoCoordinate::DegreesMinutes << QString( "90%1 0.000', 180%1 0.000'").arg(DEGREES_SYMB); + QTest::newRow("Minutes near valid long/lat values border") + << QGeoCoordinate(89.9999, 179.9999) << QGeoCoordinate::DegreesMinutes + << QString("89%1 59.994', 179%1 59.994'").arg(DEGREES_SYMB); + + QTest::newRow("Fix incorrect wrap minutes to degrees") + << QGeoCoordinate(0.995833, 0.995833) << QGeoCoordinate::DegreesMinutes + << QString("0%1 59.750', 0%1 59.750'").arg(DEGREES_SYMB); + + QTest::newRow("Fix incorrect wrap seconds to minutes") + << QGeoCoordinate(0.9832222, 0.9832222) << QGeoCoordinate::DegreesMinutesSeconds + << QString("0%1 58' 59.6\", 0%1 58' 59.6\"").arg(DEGREES_SYMB); + } void datastream() -- cgit v1.2.1