diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-08 17:26:52 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2022-09-14 13:19:51 +0200 |
commit | 1732bdf40518194d0ee5e0f009de3409dce6280d (patch) | |
tree | 0a724a0c9d340ab28796d5b3bd39f78d5b119ffb | |
parent | 734799d9f88c2383be87806d4931799b6f6a843a (diff) | |
download | qtlocation-1732bdf40518194d0ee5e0f009de3409dce6280d.tar.gz |
Register QPlaceUser as a QML value type
Make QPlaceUser a gadget, and register it as a value type with the QML
engine. Remove declarative wrapper, and consolidate the documentation.
Adjust the tests, remove tests that test that the type is not a value.
Use grouped properties initialization syntax in QML for now.
Change-Id: I0c840911316590b7ba103e26fa99d824bb9e39c5
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | src/imports/location/location.cpp | 3 | ||||
-rw-r--r-- | src/imports/location/location.h | 8 | ||||
-rw-r--r-- | src/location/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp | 23 | ||||
-rw-r--r-- | src/location/declarativeplaces/qdeclarativeplacecontentmodel_p.h | 3 | ||||
-rw-r--r-- | src/location/declarativeplaces/qdeclarativeplaceuser.cpp | 142 | ||||
-rw-r--r-- | src/location/declarativeplaces/qdeclarativeplaceuser_p.h | 95 | ||||
-rw-r--r-- | src/location/places/qplaceuser.cpp | 54 | ||||
-rw-r--r-- | src/location/places/qplaceuser.h | 4 | ||||
-rw-r--r-- | tests/auto/declarative_location_core/tst_user.qml | 23 | ||||
-rw-r--r-- | tests/auto/qmlinterface/data/TestUser.qml | 10 |
11 files changed, 75 insertions, 292 deletions
diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp index 39c8046f..a11a7aac 100644 --- a/src/imports/location/location.cpp +++ b/src/imports/location/location.cpp @@ -64,7 +64,6 @@ #include <QtLocation/private/qdeclarativeplaceicon_p.h> #include <QtLocation/private/qdeclarativeratings_p.h> #include <QtLocation/private/qdeclarativesupplier_p.h> -#include <QtLocation/private/qdeclarativeplaceuser_p.h> #include <QtLocation/private/qdeclarativecontactdetail_p.h> #include <QtLocation/private/qdeclarativesupportedcategoriesmodel_p.h> @@ -195,7 +194,6 @@ public: qmlRegisterType<QDeclarativeRatings >(uri, major, minor, "Ratings"); qmlRegisterType<QDeclarativeReviewModel >(uri, major, minor, "ReviewModel"); qmlRegisterType<QDeclarativeSupplier >(uri, major, minor, "Supplier"); - qmlRegisterType<QDeclarativePlaceUser >(uri, major, minor, "User"); qmlRegisterType<QDeclarativeRectangleMapItem >(uri, major, minor, "MapRectangle"); qmlRegisterType<QDeclarativeCircleMapItem >(uri, major, minor, "MapCircle"); qmlRegisterAnonymousType<QDeclarativeMapLineProperties >(uri, major); @@ -279,7 +277,6 @@ public: qRegisterMetaType<QPlaceIcon>(); qRegisterMetaType<QPlaceRatings>(); qRegisterMetaType<QPlaceSupplier>(); - qRegisterMetaType<QPlaceUser>(); qRegisterMetaType<QPlaceAttribute>(); qRegisterMetaType<QPlaceContactDetail>(); } else { diff --git a/src/imports/location/location.h b/src/imports/location/location.h index cc5ed5ab..6ccfd01e 100644 --- a/src/imports/location/location.h +++ b/src/imports/location/location.h @@ -53,6 +53,7 @@ #include <QGeoManeuver> #include <QGeoRouteSegment> +#include <QPlaceUser> #include <QtLocation/private/qgeomaptype_p.h> @@ -95,6 +96,13 @@ namespace QGeoMapTypeForeignNamespace QML_NAMED_ELEMENT(MapType) }; +struct QPlaceUserForeign +{ + Q_GADGET + QML_FOREIGN(QPlaceUser) + QML_NAMED_ELEMENT(user) +}; + QT_END_NAMESPACE #endif // QTLOCATION_QMLTYPES_H diff --git a/src/location/CMakeLists.txt b/src/location/CMakeLists.txt index 81026c54..fff82c07 100644 --- a/src/location/CMakeLists.txt +++ b/src/location/CMakeLists.txt @@ -144,8 +144,6 @@ qt_internal_add_module(Location declarativeplaces/qdeclarativeplaceimagemodel.cpp declarativeplaces/qdeclarativeplaceimagemodel_p.h declarativeplaces/qdeclarativeplace_p.h - declarativeplaces/qdeclarativeplaceuser.cpp - declarativeplaces/qdeclarativeplaceuser_p.h declarativeplaces/qdeclarativeratings.cpp declarativeplaces/qdeclarativeratings_p.h declarativeplaces/qdeclarativereviewmodel.cpp diff --git a/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp b/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp index fe7111d6..3a567927 100644 --- a/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp +++ b/src/location/declarativeplaces/qdeclarativeplacecontentmodel.cpp @@ -40,13 +40,13 @@ #include "qdeclarativeplacecontentmodel_p.h" #include "qdeclarativeplace_p.h" #include "qdeclarativegeoserviceprovider_p.h" -#include "qdeclarativeplaceuser_p.h" #include "error_messages_p.h" #include <QtQml/QQmlInfo> #include <QtLocation/QGeoServiceProvider> #include <QtLocation/QPlaceManager> #include <QtLocation/QPlaceContentRequest> +#include <QtLocation/QPlaceUser> QT_BEGIN_NAMESPACE @@ -122,7 +122,6 @@ int QDeclarativePlaceContentModel::totalCount() const */ void QDeclarativePlaceContentModel::clearData() { - qDeleteAll(m_users); m_users.clear(); qDeleteAll(m_suppliers); @@ -161,10 +160,8 @@ void QDeclarativePlaceContentModel::initializeCollection(int totalCount, const Q m_suppliers.insert(content.supplier().supplierId(), new QDeclarativeSupplier(content.supplier(), m_place->plugin(), this)); } - if (!m_users.contains(content.user().userId())) { - m_users.insert(content.user().userId(), - new QDeclarativePlaceUser(content.user(), this)); - } + if (!m_users.contains(content.user().userId())) + m_users.insert(content.user().userId(), content.user()); } m_contentCount = totalCount; @@ -203,7 +200,7 @@ QVariant QDeclarativePlaceContentModel::data(const QModelIndex &index, int role) case SupplierRole: return QVariant::fromValue(static_cast<QObject *>(m_suppliers.value(content.supplier().supplierId()))); case PlaceUserRole: - return QVariant::fromValue(static_cast<QObject *>(m_users.value(content.user().userId()))); + return QVariant::fromValue(m_users.value(content.user().userId())); case AttributionRole: return content.attribution(); default: @@ -345,10 +342,8 @@ void QDeclarativePlaceContentModel::fetchFinished() m_suppliers.insert(content.supplier().supplierId(), new QDeclarativeSupplier(content.supplier(), m_place->plugin(), this)); } - if (!m_users.contains(content.user().userId())) { - m_users.insert(content.user().userId(), - new QDeclarativePlaceUser(content.user(), this)); - } + if (!m_users.contains(content.user().userId())) + m_users.insert(content.user().userId(), content.user()); } endInsertRows(); startIndex = -1; @@ -372,10 +367,8 @@ void QDeclarativePlaceContentModel::fetchFinished() m_suppliers.insert(content.supplier().supplierId(), new QDeclarativeSupplier(content.supplier(), m_place->plugin(), this)); } - if (!m_users.contains(content.user().userId())) { - m_users.insert(content.user().userId(), - new QDeclarativePlaceUser(content.user(), this)); - } + if (!m_users.contains(content.user().userId())) + m_users.insert(content.user().userId(), content.user()); } emit dataChanged(index(startIndex),index(currentIndex)); startIndex = -1; diff --git a/src/location/declarativeplaces/qdeclarativeplacecontentmodel_p.h b/src/location/declarativeplaces/qdeclarativeplacecontentmodel_p.h index 0b48039c..7beed04b 100644 --- a/src/location/declarativeplaces/qdeclarativeplacecontentmodel_p.h +++ b/src/location/declarativeplaces/qdeclarativeplacecontentmodel_p.h @@ -66,7 +66,6 @@ class QDeclarativePlace; class QDeclarativeGeoServiceProvider; class QGeoServiceProvider; class QDeclarativeSupplier; -class QDeclarativePlaceUser; class Q_LOCATION_PRIVATE_EXPORT QDeclarativePlaceContentModel : public QAbstractListModel, public QQmlParserStatus { @@ -124,7 +123,7 @@ private Q_SLOTS: protected: QPlaceContent::Collection m_content; QMap<QString, QDeclarativeSupplier *> m_suppliers; - QMap<QString, QDeclarativePlaceUser *>m_users; + QMap<QString, QPlaceUser>m_users; private: QDeclarativePlace *m_place = nullptr; diff --git a/src/location/declarativeplaces/qdeclarativeplaceuser.cpp b/src/location/declarativeplaces/qdeclarativeplaceuser.cpp deleted file mode 100644 index f946bf4a..00000000 --- a/src/location/declarativeplaces/qdeclarativeplaceuser.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 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 "qdeclarativeplaceuser_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmltype User - \instantiates QDeclarativePlaceUser - \inqmlmodule QtLocation - \ingroup qml-QtLocation5-places - \ingroup qml-QtLocation5-places-data - \since QtLocation 5.5 - - \brief The User type identifies a user who contributed a particular \l Place content item. - - Each \l Place content item has an associated user who contributed the content. This type - provides information about that user. - - \sa ImageModel, ReviewModel, EditorialModel - - \section1 Example - - The following example shows how to display information about the user who - submitted an editorial: - - \snippet declarative/places.qml QtQuick import - \snippet declarative/maps.qml QtLocation import - \codeline - \snippet declarative/places.qml EditorialModel -*/ - -QDeclarativePlaceUser::QDeclarativePlaceUser(QObject *parent) - : QObject(parent) {} - -QDeclarativePlaceUser::QDeclarativePlaceUser(const QPlaceUser &user, - QObject *parent) - : QObject(parent), - m_user(user) {} - -QDeclarativePlaceUser::~QDeclarativePlaceUser() {} - -/*! - \qmlproperty QPlaceUser QtLocation::User::user - - For details on how to use this property to interface between C++ and QML see - "\l {User - QPlaceUser} {Interfaces between C++ and QML Code}". -*/ -void QDeclarativePlaceUser::setUser(const QPlaceUser &user) -{ - QPlaceUser previousUser = m_user; - m_user = user; - - if (m_user.userId() != previousUser.userId()) - emit userIdChanged(); - - if (m_user.name() != previousUser.name()) - emit nameChanged(); -} - -QPlaceUser QDeclarativePlaceUser::user() const -{ - return m_user; -} - -/*! - \qmlproperty string QtLocation::User::userId - - This property holds the unique identifier of the user. -*/ - -void QDeclarativePlaceUser::setUserId(const QString &id) -{ - if (m_user.userId() == id) - return; - - m_user.setUserId(id); - emit userIdChanged(); -} - -QString QDeclarativePlaceUser::userId() const -{ - return m_user.userId(); -} - -/*! - \qmlproperty string QtLocation::User::name - - This property holds the name of a user. -*/ -void QDeclarativePlaceUser::setName(const QString &name) -{ - if (m_user.name() == name) - return; - - m_user.setName(name); - emit nameChanged(); -} - -QString QDeclarativePlaceUser::name() const -{ - return m_user.name(); -} - -QT_END_NAMESPACE diff --git a/src/location/declarativeplaces/qdeclarativeplaceuser_p.h b/src/location/declarativeplaces/qdeclarativeplaceuser_p.h deleted file mode 100644 index 69f85167..00000000 --- a/src/location/declarativeplaces/qdeclarativeplaceuser_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 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$ -** -****************************************************************************/ - -#ifndef QDECLARATIVEPLACEUSER_P_H -#define QDECLARATIVEPLACEUSER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtLocation/private/qlocationglobal_p.h> -#include <QtCore/QObject> -#include <QtQml/qqml.h> -#include <QtLocation/QPlaceUser> - -QT_BEGIN_NAMESPACE - -class Q_LOCATION_PRIVATE_EXPORT QDeclarativePlaceUser : public QObject -{ - Q_OBJECT - - Q_PROPERTY(QPlaceUser user READ user WRITE setUser) - Q_PROPERTY(QString userId READ userId WRITE setUserId NOTIFY userIdChanged) - Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) - -public: - explicit QDeclarativePlaceUser(QObject *parent = 0); - explicit QDeclarativePlaceUser(const QPlaceUser &src, QObject *parent = 0); - ~QDeclarativePlaceUser(); - - QPlaceUser user() const; - void setUser(const QPlaceUser &src); - - QString userId() const; - void setUserId(const QString &id); - - QString name() const; - void setName(const QString &name); - -Q_SIGNALS: - void userIdChanged(); - void nameChanged(); - -private: - QPlaceUser m_user; -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPE(QDeclarativePlaceUser) - -#endif diff --git a/src/location/places/qplaceuser.cpp b/src/location/places/qplaceuser.cpp index 48241e7a..6815e68f 100644 --- a/src/location/places/qplaceuser.cpp +++ b/src/location/places/qplaceuser.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2015 The Qt Company Ltd. +** 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. @@ -60,6 +60,31 @@ bool QPlaceUserPrivate::operator==(const QPlaceUserPrivate &other) const */ /*! + \qmlvaluetype user + \inqmlmodule QtLocation + \ingroup qml-QtLocation5-places + \ingroup qml-QtLocation5-places-data + \since QtLocation 5.5 + + \brief The user type identifies a user who contributed a particular \l Place content item. + + Each \l Place content item has an associated user who contributed the content. This type + provides information about that user. + + \sa ImageModel, ReviewModel, EditorialModel + + \section1 Example + + The following example shows how to display information about the user who + submitted an editorial: + + \snippet declarative/places.qml QtQuick import + \snippet declarative/maps.qml QtLocation import + \codeline + \snippet declarative/places.qml EditorialModel +*/ + +/*! Constructs a new user object. */ QPlaceUser::QPlaceUser() @@ -107,34 +132,43 @@ bool QPlaceUser::isEqual(const QPlaceUser &other) const noexcept } /*! - Returns the identifier of the user. + \qmlproperty string QtLocation::user::userId + + This property holds the unique identifier of the user. +*/ + +/*! + \property QPlaceUser::userId + \brief the identifier of the user. */ QString QPlaceUser::userId() const { return d->userId; } -/*! - Sets the \a identifier of the user. -*/ void QPlaceUser::setUserId(const QString &identifier) { d->userId = identifier; } /*! - Returns the name of the user. + \qmlproperty string QtLocation::User::name + + This property holds the name of a user. +*/ + +/*! + \property QPlaceUser::name + \brief the name of the user. */ QString QPlaceUser::name() const { return d->name; } -/*! - Sets the \a name of the user. -*/ - void QPlaceUser::setName(const QString &name) { d->name = name; } + +#include "moc_qplaceuser.cpp" diff --git a/src/location/places/qplaceuser.h b/src/location/places/qplaceuser.h index e5d333a1..b4c2f915 100644 --- a/src/location/places/qplaceuser.h +++ b/src/location/places/qplaceuser.h @@ -51,6 +51,10 @@ QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlaceUserPrivate, Q_LOCATION_EX class Q_LOCATION_EXPORT QPlaceUser { + Q_GADGET + Q_PROPERTY(QString userId READ userId WRITE setUserId) + Q_PROPERTY(QString name READ name WRITE setName) + public: QPlaceUser(); QPlaceUser(const QPlaceUser &other) noexcept; diff --git a/tests/auto/declarative_location_core/tst_user.qml b/tests/auto/declarative_location_core/tst_user.qml index abfad1b4..6ca12f7b 100644 --- a/tests/auto/declarative_location_core/tst_user.qml +++ b/tests/auto/declarative_location_core/tst_user.qml @@ -28,23 +28,21 @@ import QtTest import QtLocation -import "utils.js" as Utils TestCase { id: testCase name: "User" - User { id: emptyUser } + property user emptyUser function test_empty() { compare(emptyUser.userId, ""); compare(emptyUser.name, ""); } - User { - id: qmlUser - + property user qmlUser + qmlUser { userId: "testuser" name: "Test User" } @@ -53,19 +51,4 @@ TestCase { compare(qmlUser.userId, "testuser"); compare(qmlUser.name, "Test User"); } - - User { - id: testUser - } - - function test_setAndGet_data() { - return [ - { tag: "userId", property: "userId", signal: "userIdChanged", value: "testuser", reset: "" }, - { tag: "name", property: "name", signal: "nameChanged", value: "Test User", reset: "" }, - ]; - } - - function test_setAndGet(data) { - Utils.testObjectProperties(testCase, testUser, data); - } } diff --git a/tests/auto/qmlinterface/data/TestUser.qml b/tests/auto/qmlinterface/data/TestUser.qml index a02f4f1f..137d87ed 100644 --- a/tests/auto/qmlinterface/data/TestUser.qml +++ b/tests/auto/qmlinterface/data/TestUser.qml @@ -26,9 +26,13 @@ ** ****************************************************************************/ +import QtQuick import QtLocation -User { - name: "Test User" - userId: "test-user-id" +Item { + property user user + user { + name: "Test User" + userId: "test-user-id" + } } |