summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-03 18:21:26 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-14 17:17:57 +0200
commit1bfca1751534f83fcd6ad06257c9c5c35a9a0f20 (patch)
tree0b7c5a2ff3e87037196e41a3a2f68ef7b3b4d659
parentcfce084e080ba1e3f6d4000e084a5ecbce91612b (diff)
downloadqtlocation-1bfca1751534f83fcd6ad06257c9c5c35a9a0f20.tar.gz
Refactor: remove duplicated code
Use the existing helper implementation to convert QJSValue to QList<QGeoCoordinate>. Remove parseCircle helper function that is not used anywhere, and unexport the helper function that is only used by another helper. Change-Id: Ie01cca3e5a7bd09a88be67225185b54e0f28e773 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> (cherry picked from commit 22c3c1d155f817324ed535ba599633cad0e49b5e) Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/location/declarativemaps/locationvaluetypehelper.cpp23
-rw-r--r--src/location/declarativemaps/locationvaluetypehelper_p.h2
-rw-r--r--src/location/declarativemaps/qdeclarativegeoroute.cpp37
-rw-r--r--src/location/declarativemaps/qdeclarativepolygonmapitem.cpp2
4 files changed, 10 insertions, 54 deletions
diff --git a/src/location/declarativemaps/locationvaluetypehelper.cpp b/src/location/declarativemaps/locationvaluetypehelper.cpp
index f2029aa1..f5a3a556 100644
--- a/src/location/declarativemaps/locationvaluetypehelper.cpp
+++ b/src/location/declarativemaps/locationvaluetypehelper.cpp
@@ -53,6 +53,8 @@
QT_BEGIN_NAMESPACE
+namespace {
+
QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok)
{
QGeoCoordinate c;
@@ -74,6 +76,8 @@ QGeoCoordinate parseCoordinate(const QJSValue &value, bool *ok)
return c;
}
+} // anonymous namespace
+
QGeoCoordinate parseCoordinate(const QVariant &value, bool *ok)
{
QGeoCoordinate c;
@@ -142,25 +146,6 @@ QGeoRectangle parseRectangle(const QJSValue &value, bool *ok)
return r;
}
-QGeoCircle parseCircle(const QJSValue &value, bool *ok)
-{
- QGeoCircle c;
-
- *ok = false;
-
- if (value.isObject()) {
- if (value.hasProperty(QStringLiteral("center"))) {
- QGeoCoordinate coord = parseCoordinate(value.property(QStringLiteral("center")), ok);
- if (*ok)
- c.setCenter(coord);
- }
- if (value.hasProperty(QStringLiteral("radius")))
- c.setRadius(value.property(QStringLiteral("radius")).toNumber());
- }
-
- return c;
-}
-
QJSValue fromList(const QObject *object, const QList<QGeoCoordinate> &list)
{
QQmlContext *context = QQmlEngine::contextForObject(object);
diff --git a/src/location/declarativemaps/locationvaluetypehelper_p.h b/src/location/declarativemaps/locationvaluetypehelper_p.h
index ec593f3d..54d04f90 100644
--- a/src/location/declarativemaps/locationvaluetypehelper_p.h
+++ b/src/location/declarativemaps/locationvaluetypehelper_p.h
@@ -64,10 +64,8 @@ class QGeoCoordinate;
class QGeoRectangle;
class QGeoCircle;
-QGeoCoordinate Q_LOCATION_PRIVATE_EXPORT parseCoordinate(const QJSValue &value, bool *ok = nullptr);
QGeoCoordinate Q_LOCATION_PRIVATE_EXPORT parseCoordinate(const QVariant &value, bool *ok = nullptr);
QGeoRectangle Q_LOCATION_PRIVATE_EXPORT parseRectangle(const QJSValue &value, bool *ok);
-QGeoCircle Q_LOCATION_PRIVATE_EXPORT parseCircle(const QJSValue &value, bool *ok);
QJSValue Q_LOCATION_PRIVATE_EXPORT fromList(const QObject *object, const QList<QGeoCoordinate> &list);
QList<QGeoCoordinate> Q_LOCATION_PRIVATE_EXPORT toList(const QObject *object, const QJSValue &value);
diff --git a/src/location/declarativemaps/qdeclarativegeoroute.cpp b/src/location/declarativemaps/qdeclarativegeoroute.cpp
index 82406556..723d408f 100644
--- a/src/location/declarativemaps/qdeclarativegeoroute.cpp
+++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp
@@ -39,13 +39,13 @@
#include "qdeclarativegeoroute_p.h"
#include "locationvaluetypehelper_p.h"
+
+#include <QtQml/QQmlEngine>
+
#include <QtLocation/private/qgeomap_p.h>
#include <QtLocation/private/qgeoroute_p.h>
#include <QtLocation/private/qdeclarativegeoroutemodel_p.h>
-#include <QtQml/QQmlEngine>
-#include <QtQml/qqmlinfo.h>
-#include <QtQml/private/qqmlengine_p.h>
#include <QtPositioning/QGeoRectangle>
QT_BEGIN_NAMESPACE
@@ -180,20 +180,7 @@ qreal QDeclarativeGeoRoute::distance() const
QJSValue QDeclarativeGeoRoute::path() const
{
- QQmlContext *context = QQmlEngine::contextForObject(parent());
- QQmlEngine *engine = context->engine();
- QV4::ExecutionEngine *v4 = QQmlEnginePrivate::getV4Engine(engine);
-
- QV4::Scope scope(v4);
- QV4::Scoped<QV4::ArrayObject> pathArray(scope, v4->newArrayObject(route_.path().length()));
- for (int i = 0; i < route_.path().length(); ++i) {
- const QGeoCoordinate &c = route_.path().at(i);
-
- QV4::ScopedValue cv(scope, v4->fromVariant(QVariant::fromValue(c)));
- pathArray->put(i, cv);
- }
-
- return QJSValuePrivate::fromReturnedValue(pathArray.asReturnedValue());
+ return fromList(parent(), route_.path());
}
void QDeclarativeGeoRoute::setPath(const QJSValue &value)
@@ -201,25 +188,11 @@ void QDeclarativeGeoRoute::setPath(const QJSValue &value)
if (!value.isArray())
return;
- QList<QGeoCoordinate> pathList;
- quint32 length = value.property(QStringLiteral("length")).toUInt();
- for (quint32 i = 0; i < length; ++i) {
- bool ok;
- QGeoCoordinate c = parseCoordinate(value.property(i), &ok);
-
- if (!ok || !c.isValid()) {
- qmlWarning(this) << "Unsupported path type";
- return;
- }
-
- pathList.append(c);
- }
-
+ const QList<QGeoCoordinate> pathList = toList(this, value);
if (route_.path() == pathList)
return;
route_.setPath(pathList);
-
emit pathChanged();
}
diff --git a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp
index 5c44ffff..2888ca81 100644
--- a/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp
+++ b/src/location/declarativemaps/qdeclarativepolygonmapitem.cpp
@@ -724,7 +724,7 @@ void QDeclarativePolygonMapItem::setPath(const QJSValue &value)
if (!value.isArray())
return;
- QList<QGeoCoordinate> pathList = toList(this, value);
+ const QList<QGeoCoordinate> pathList = toList(this, value);
// Equivalent to QDeclarativePolylineMapItem::setPathFromGeoList
if (m_geopoly.perimeter() == pathList)