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-13 19:20:14 +0200
commit22c3c1d155f817324ed535ba599633cad0e49b5e (patch)
treed8161d1c8ef554cad346fc335a5cd2518b3c89dc
parent3af758a4cf133a1d8b465a23e4967d64f0e52237 (diff)
downloadqtlocation-22c3c1d155f817324ed535ba599633cad0e49b5e.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. Pick-to: 6.2 Change-Id: Ie01cca3e5a7bd09a88be67225185b54e0f28e773 Reviewed-by: Ivan Solovev <ivan.solovev@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.cpp34
-rw-r--r--src/location/declarativemaps/qdeclarativepolygonmapitem.cpp2
4 files changed, 7 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 af6dc42b..d8db5793 100644
--- a/src/location/declarativemaps/qdeclarativegeoroute.cpp
+++ b/src/location/declarativemaps/qdeclarativegeoroute.cpp
@@ -43,9 +43,6 @@
#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
@@ -153,20 +150,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)
@@ -174,25 +158,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)