summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-29 12:49:07 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-30 13:02:41 +0200
commit7779e6a05cde72320e47cf4d5ebed78b9e049226 (patch)
tree811c072c622b8f1e9cad5c883dd44b993549a5f3
parent71a057951c6ae679c9133261e332983f4b630cbf (diff)
downloadqtlocation-7779e6a05cde72320e47cf4d5ebed78b9e049226.tar.gz
Declare value types as structured values, remove workarounds
Use QML's new support for initializing structured values, adjust tests, and remove the now unnecessary conversion functions. Change-Id: I7007c9acb50f4a9532a9eed847b1b4dd0928ba34 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/location/CMakeLists.txt1
-rw-r--r--src/location/maps/qgeomaneuver.h1
-rw-r--r--src/location/maps/qgeomaptype_p.h1
-rw-r--r--src/location/maps/qgeoroute.h3
-rw-r--r--src/location/maps/qgeoroutesegment.h1
-rw-r--r--src/location/places/qplaceattribute.h1
-rw-r--r--src/location/places/qplacecontactdetail.h1
-rw-r--r--src/location/places/qplaceicon.h2
-rw-r--r--src/location/places/qplaceratings.h2
-rw-r--r--src/location/places/qplacesupplier.h2
-rw-r--r--src/location/places/qplaceuser.h2
-rw-r--r--src/location/qlocation_quick.cpp127
-rw-r--r--tests/auto/qmlinterface/data/TestContactDetail.qml7
-rw-r--r--tests/auto/qmlinterface/data/TestPlaceAttribute.qml7
-rw-r--r--tests/auto/qmlinterface/data/TestRatings.qml9
-rw-r--r--tests/auto/qmlinterface/data/TestSupplier.qml11
-rw-r--r--tests/auto/qmlinterface/data/TestUser.qml7
17 files changed, 33 insertions, 152 deletions
diff --git a/src/location/CMakeLists.txt b/src/location/CMakeLists.txt
index 38f46485..eb26b79e 100644
--- a/src/location/CMakeLists.txt
+++ b/src/location/CMakeLists.txt
@@ -106,7 +106,6 @@ qt_internal_add_qml_module(Location
NO_PLUGIN_OPTIONAL
CLASS_NAME QtLocationDeclarativeModule
SOURCES
- qlocation_quick.cpp
# value types
maps/qgeomaptype_p.h
maps/qgeomaneuver.h
diff --git a/src/location/maps/qgeomaneuver.h b/src/location/maps/qgeomaneuver.h
index 97d3c86b..1f97ecb0 100644
--- a/src/location/maps/qgeomaneuver.h
+++ b/src/location/maps/qgeomaneuver.h
@@ -56,6 +56,7 @@ class Q_LOCATION_EXPORT QGeoManeuver
{
Q_GADGET
QML_VALUE_TYPE(routeManeuver)
+ QML_STRUCTURED_VALUE
Q_ENUMS(InstructionDirection)
Q_PROPERTY(bool valid READ isValid CONSTANT)
diff --git a/src/location/maps/qgeomaptype_p.h b/src/location/maps/qgeomaptype_p.h
index 4d1f12db..eacc1b48 100644
--- a/src/location/maps/qgeomaptype_p.h
+++ b/src/location/maps/qgeomaptype_p.h
@@ -68,6 +68,7 @@ class Q_LOCATION_PRIVATE_EXPORT QGeoMapType
{
Q_GADGET
QML_VALUE_TYPE(mapType)
+ QML_STRUCTURED_VALUE
Q_ENUMS(MapStyle)
Q_PROPERTY(MapStyle style READ style CONSTANT)
diff --git a/src/location/maps/qgeoroute.h b/src/location/maps/qgeoroute.h
index 3450af25..e9a9041a 100644
--- a/src/location/maps/qgeoroute.h
+++ b/src/location/maps/qgeoroute.h
@@ -59,7 +59,8 @@ QT_DECLARE_QESDP_SPECIALIZATION_DTOR_WITH_EXPORT(QGeoRoutePrivate, Q_LOCATION_EX
class Q_LOCATION_EXPORT QGeoRoute
{
Q_GADGET
- QML_NAMED_ELEMENT(route)
+ QML_VALUE_TYPE(route)
+ QML_STRUCTURED_VALUE
Q_PROPERTY(QGeoRectangle bounds READ bounds CONSTANT)
Q_PROPERTY(int travelTime READ travelTime CONSTANT)
diff --git a/src/location/maps/qgeoroutesegment.h b/src/location/maps/qgeoroutesegment.h
index 7ab8a771..cf969907 100644
--- a/src/location/maps/qgeoroutesegment.h
+++ b/src/location/maps/qgeoroutesegment.h
@@ -57,6 +57,7 @@ class Q_LOCATION_EXPORT QGeoRouteSegment
{
Q_GADGET
QML_VALUE_TYPE(routeSegment)
+ QML_STRUCTURED_VALUE
Q_PROPERTY(int travelTime READ travelTime CONSTANT)
Q_PROPERTY(qreal distance READ distance CONSTANT)
diff --git a/src/location/places/qplaceattribute.h b/src/location/places/qplaceattribute.h
index 5e628f26..6d8820d8 100644
--- a/src/location/places/qplaceattribute.h
+++ b/src/location/places/qplaceattribute.h
@@ -56,6 +56,7 @@ class Q_LOCATION_EXPORT QPlaceAttribute
{
Q_GADGET
QML_VALUE_TYPE(placeAttribute)
+ QML_STRUCTURED_VALUE
Q_PROPERTY(QString label READ label WRITE setLabel)
Q_PROPERTY(QString text READ text WRITE setText)
diff --git a/src/location/places/qplacecontactdetail.h b/src/location/places/qplacecontactdetail.h
index 5801a1f0..4467c1f4 100644
--- a/src/location/places/qplacecontactdetail.h
+++ b/src/location/places/qplacecontactdetail.h
@@ -56,6 +56,7 @@ class Q_LOCATION_EXPORT QPlaceContactDetail
{
Q_GADGET
QML_VALUE_TYPE(contactDetail)
+ QML_STRUCTURED_VALUE
Q_PROPERTY(QString label READ label WRITE setLabel)
Q_PROPERTY(QString value READ value WRITE setValue)
diff --git a/src/location/places/qplaceicon.h b/src/location/places/qplaceicon.h
index 2360553c..f39b5ea6 100644
--- a/src/location/places/qplaceicon.h
+++ b/src/location/places/qplaceicon.h
@@ -59,6 +59,8 @@ class Q_LOCATION_EXPORT QPlaceIcon
{
Q_GADGET
QML_VALUE_TYPE(icon)
+ QML_STRUCTURED_VALUE
+
Q_PROPERTY(QVariantMap parameters READ parameters WRITE setParameters)
Q_PROPERTY(QPlaceManager *manager READ manager WRITE setManager)
diff --git a/src/location/places/qplaceratings.h b/src/location/places/qplaceratings.h
index 6a73fb9a..396ac1b8 100644
--- a/src/location/places/qplaceratings.h
+++ b/src/location/places/qplaceratings.h
@@ -54,6 +54,8 @@ class Q_LOCATION_EXPORT QPlaceRatings
{
Q_GADGET
QML_VALUE_TYPE(ratings)
+ QML_STRUCTURED_VALUE
+
Q_PROPERTY(qreal average READ average WRITE setAverage)
Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum)
Q_PROPERTY(int count READ count WRITE setCount)
diff --git a/src/location/places/qplacesupplier.h b/src/location/places/qplacesupplier.h
index 81a4aff5..e9a942ec 100644
--- a/src/location/places/qplacesupplier.h
+++ b/src/location/places/qplacesupplier.h
@@ -56,6 +56,8 @@ class Q_LOCATION_EXPORT QPlaceSupplier
{
Q_GADGET
QML_VALUE_TYPE(supplier)
+ QML_STRUCTURED_VALUE
+
Q_PROPERTY(QString name READ name WRITE setName)
Q_PROPERTY(QString supplierId READ supplierId WRITE setSupplierId)
Q_PROPERTY(QUrl url READ url WRITE setUrl)
diff --git a/src/location/places/qplaceuser.h b/src/location/places/qplaceuser.h
index 6dcca89b..871ad95b 100644
--- a/src/location/places/qplaceuser.h
+++ b/src/location/places/qplaceuser.h
@@ -54,6 +54,8 @@ class Q_LOCATION_EXPORT QPlaceUser
{
Q_GADGET
QML_VALUE_TYPE(user)
+ QML_STRUCTURED_VALUE
+
Q_PROPERTY(QString userId READ userId WRITE setUserId)
Q_PROPERTY(QString name READ name WRITE setName)
diff --git a/src/location/qlocation_quick.cpp b/src/location/qlocation_quick.cpp
deleted file mode 100644
index 0ad82693..00000000
--- a/src/location/qlocation_quick.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2022 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtLocation module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtLocation/qplaceratings.h>
-#include <QtLocation/qplaceicon.h>
-#include <QtLocation/qplacesupplier.h>
-
-QT_BEGIN_NAMESPACE
-
-namespace {
-
-bool convertToGadget(const QMetaObject &metaObject, const QVariantMap &map, void *gadget)
-{
- for (auto &&[key, value] : map.asKeyValueRange()) {
- const int propIndex = metaObject.indexOfProperty(key.toUtf8());
- if (propIndex == -1) {
- qCritical("No property %s in %s", qPrintable(key), metaObject.className());
- return false;
- }
- const QMetaProperty prop = metaObject.property(propIndex);
- bool successfulWrite = false;
- if (value.metaType() != prop.metaType()) {
- QVariant coercedValue = value;
- if (!coercedValue.convert(prop.metaType())) {
- qCritical("Could not convert value from %s to %s for property %s::%s",
- value.typeName(), prop.typeName(), metaObject.className(), qPrintable(key));
- return false;
- }
- successfulWrite = prop.writeOnGadget(gadget, coercedValue);
- } else {
- successfulWrite = prop.writeOnGadget(gadget, value);
- }
- if (!successfulWrite) {
- qCritical("Could not set property %s on %s", qPrintable(key), metaObject.className());
- return false;
- }
- }
- return true;
-}
-
-template<typename SourceType, typename GadgetType>
-bool converterToGadget(const void *src, void *gadget)
-{
- const QMetaObject &metaObject = GadgetType::staticMetaObject;
- QVariantMap variantMap;
- if constexpr (std::is_same_v<SourceType, QJSValue>) {
- const QJSValue &jsValue = *static_cast<const QJSValue *>(src);
- const QVariant &variant = jsValue.toVariant();
- if (variant.metaType() != QMetaType::fromType<QVariantMap>())
- return false;
- variantMap = variant.toMap();
- } else {
- static_assert(std::is_same_v<SourceType, QVariantMap>);
- variantMap = *static_cast<const QVariantMap *>(src);
- }
- return convertToGadget(metaObject, variantMap, gadget);
-}
-
-template<typename GadgetType>
-bool registerConverterToGadget()
-{
- if (!QMetaType::registerConverterFunction(converterToGadget<QJSValue, GadgetType>,
- QMetaType::fromType<QJSValue>(), QMetaType::fromType<GadgetType>())) {
- qCritical("Failed to register conversion function from QJSValue to %s",
- GadgetType::staticMetaObject.className());
- return false;
- }
- if (!QMetaType::registerConverterFunction(converterToGadget<QVariantMap, GadgetType>,
- QMetaType::fromType<QVariantMap>(), QMetaType::fromType<GadgetType>())) {
- qCritical("Failed to register conversion function from QVariantMap to %s",
- GadgetType::staticMetaObject.className());
- return false;
- }
-
- return true;
-}
-
-} // anonymous namespace
-
-void registerConverters()
-{
- registerConverterToGadget<QPlaceRatings>();
- registerConverterToGadget<QPlaceIcon>();
- registerConverterToGadget<QPlaceSupplier>();
-}
-
-Q_CONSTRUCTOR_FUNCTION(registerConverters);
-
-
-
-QT_END_NAMESPACE
diff --git a/tests/auto/qmlinterface/data/TestContactDetail.qml b/tests/auto/qmlinterface/data/TestContactDetail.qml
index c8f82870..3bee3ebb 100644
--- a/tests/auto/qmlinterface/data/TestContactDetail.qml
+++ b/tests/auto/qmlinterface/data/TestContactDetail.qml
@@ -30,9 +30,8 @@ import QtLocation
import QtQuick
Item {
- property contactDetail contactDetail
- contactDetail {
- label: "Test Contact Detail"
+ property contactDetail contactDetail: ({
+ label: "Test Contact Detail",
value: "Test contact detail value"
- }
+ })
}
diff --git a/tests/auto/qmlinterface/data/TestPlaceAttribute.qml b/tests/auto/qmlinterface/data/TestPlaceAttribute.qml
index cab47537..c3879cea 100644
--- a/tests/auto/qmlinterface/data/TestPlaceAttribute.qml
+++ b/tests/auto/qmlinterface/data/TestPlaceAttribute.qml
@@ -30,9 +30,8 @@ import QtLocation
import QtQuick
Item {
- property placeAttribute attribute
- attribute {
- label: "Test Attribute"
+ property placeAttribute attribute: ({
+ label: "Test Attribute",
text: "Test attribute text"
- }
+ })
}
diff --git a/tests/auto/qmlinterface/data/TestRatings.qml b/tests/auto/qmlinterface/data/TestRatings.qml
index 17f7d4f5..77f63a3f 100644
--- a/tests/auto/qmlinterface/data/TestRatings.qml
+++ b/tests/auto/qmlinterface/data/TestRatings.qml
@@ -30,10 +30,9 @@ import QtLocation
import QtQuick
Item {
- property ratings ratings
- ratings {
- average: 3.5
- maximum: 5.0
+ property ratings ratings: ({
+ average: 3.5,
+ maximum: 5.0,
count: 10
- }
+ })
}
diff --git a/tests/auto/qmlinterface/data/TestSupplier.qml b/tests/auto/qmlinterface/data/TestSupplier.qml
index f94f7f7b..1c5ef92b 100644
--- a/tests/auto/qmlinterface/data/TestSupplier.qml
+++ b/tests/auto/qmlinterface/data/TestSupplier.qml
@@ -30,11 +30,10 @@ import QtLocation
import QtQuick
Item {
- property supplier supplier
- supplier {
- name: "Test supplier"
- supplierId: "test-supplier-id"
- url: "http://www.example.com/test-supplier"
+ property supplier supplier: ({
+ name: "Test supplier",
+ supplierId: "test-supplier-id",
+ url: "http://www.example.com/test-supplier",
icon: ({ parameters: { singleUrl: "http://www.example.com/test-icon.png" }})
- }
+ })
}
diff --git a/tests/auto/qmlinterface/data/TestUser.qml b/tests/auto/qmlinterface/data/TestUser.qml
index 137d87ed..48baad12 100644
--- a/tests/auto/qmlinterface/data/TestUser.qml
+++ b/tests/auto/qmlinterface/data/TestUser.qml
@@ -30,9 +30,8 @@ import QtQuick
import QtLocation
Item {
- property user user
- user {
- name: "Test User"
+ property user user: ({
+ name: "Test User",
userId: "test-user-id"
- }
+ })
}