diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-03 18:21:26 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-13 19:20:14 +0200 |
commit | 22c3c1d155f817324ed535ba599633cad0e49b5e (patch) | |
tree | d8161d1c8ef554cad346fc335a5cd2518b3c89dc /src/location/declarativemaps/qdeclarativegeoroute.cpp | |
parent | 3af758a4cf133a1d8b465a23e4967d64f0e52237 (diff) | |
download | qtlocation-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>
Diffstat (limited to 'src/location/declarativemaps/qdeclarativegeoroute.cpp')
-rw-r--r-- | src/location/declarativemaps/qdeclarativegeoroute.cpp | 34 |
1 files changed, 2 insertions, 32 deletions
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(); } |