summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-09 12:30:18 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-09-14 13:20:00 +0200
commite96f4fc0957d936385a086cf9b0882b62bcebad3 (patch)
tree6f8360e5b94842558ec768cb81abd4a313a2f78c
parent1732bdf40518194d0ee5e0f009de3409dce6280d (diff)
downloadqtlocation-e96f4fc0957d936385a086cf9b0882b62bcebad3.tar.gz
Register QPlaceRatings as a value type
Make QPlaceUser a gadget, and register it as a value type with the QML engine. Remove declarative wrapper, and consolidate the documentation. To support QML tests setting ratings properties from literal values, register a converter from QJSValue. That is temporary and will become obsolete once the QML engine can property-initialize, and perhaps even instantiate, value types. Adjust the tests and remove tests that verify that the type behaves like an object. This is not entirely complete (some tests still compare Place.ratings with `null`, but those tests pass for now, and will be changed in later commits when more types get converted in this way. Task-number: QTBUG-106482 Change-Id: I3694df414bb87adcfda3dc4b88e5206d4272bb82 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r--src/imports/location/location.cpp5
-rw-r--r--src/imports/location/location.h8
-rw-r--r--src/location/CMakeLists.txt2
-rw-r--r--src/location/declarativeplaces/qdeclarativeplace.cpp16
-rw-r--r--src/location/declarativeplaces/qdeclarativeplace_p.h10
-rw-r--r--src/location/declarativeplaces/qdeclarativeratings.cpp156
-rw-r--r--src/location/declarativeplaces/qdeclarativeratings_p.h101
-rw-r--r--src/location/places/qplaceratings.cpp60
-rw-r--r--src/location/places/qplaceratings.h5
-rw-r--r--tests/auto/declarative_location_core/tst_place.qml33
-rw-r--r--tests/auto/declarative_location_core/tst_ratings.qml26
-rw-r--r--tests/auto/qmlinterface/data/TestPlace.qml2
-rw-r--r--tests/auto/qmlinterface/data/TestRatings.qml12
13 files changed, 93 insertions, 343 deletions
diff --git a/src/imports/location/location.cpp b/src/imports/location/location.cpp
index a11a7aac..91680661 100644
--- a/src/imports/location/location.cpp
+++ b/src/imports/location/location.cpp
@@ -62,7 +62,6 @@
#include <QtLocation/private/qdeclarativeplace_p.h>
#include <QtLocation/private/qdeclarativeplaceattribute_p.h>
#include <QtLocation/private/qdeclarativeplaceicon_p.h>
-#include <QtLocation/private/qdeclarativeratings_p.h>
#include <QtLocation/private/qdeclarativesupplier_p.h>
#include <QtLocation/private/qdeclarativecontactdetail_p.h>
@@ -191,7 +190,6 @@ public:
qmlRegisterType<QDeclarativePlaceImageModel >(uri, major, minor, "ImageModel");
qmlRegisterType<QDeclarativePlace >(uri, major, minor, "Place");
qmlRegisterType<QDeclarativePlaceIcon >(uri, major, minor, "Icon");
- qmlRegisterType<QDeclarativeRatings >(uri, major, minor, "Ratings");
qmlRegisterType<QDeclarativeReviewModel >(uri, major, minor, "ReviewModel");
qmlRegisterType<QDeclarativeSupplier >(uri, major, minor, "Supplier");
qmlRegisterType<QDeclarativeRectangleMapItem >(uri, major, minor, "MapRectangle");
@@ -275,10 +273,11 @@ public:
qRegisterMetaType<QPlaceCategory>();
qRegisterMetaType<QPlace>();
qRegisterMetaType<QPlaceIcon>();
- qRegisterMetaType<QPlaceRatings>();
qRegisterMetaType<QPlaceSupplier>();
qRegisterMetaType<QPlaceAttribute>();
qRegisterMetaType<QPlaceContactDetail>();
+
+ registerConverterToGadget<QPlaceRatings>();
} else {
qDebug() << "Unsupported URI given to load location QML plugin: " << QLatin1String(uri);
}
diff --git a/src/imports/location/location.h b/src/imports/location/location.h
index 6ccfd01e..f9f6d310 100644
--- a/src/imports/location/location.h
+++ b/src/imports/location/location.h
@@ -54,6 +54,7 @@
#include <QGeoManeuver>
#include <QGeoRouteSegment>
#include <QPlaceUser>
+#include <QPlaceRatings>
#include <QtLocation/private/qgeomaptype_p.h>
@@ -103,6 +104,13 @@ struct QPlaceUserForeign
QML_NAMED_ELEMENT(user)
};
+struct QPlaceRatingsForeign
+{
+ Q_GADGET
+ QML_FOREIGN(QPlaceRatings)
+ QML_NAMED_ELEMENT(ratings)
+};
+
QT_END_NAMESPACE
#endif // QTLOCATION_QMLTYPES_H
diff --git a/src/location/CMakeLists.txt b/src/location/CMakeLists.txt
index fff82c07..d94e7f5c 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/qdeclarativeratings.cpp
- declarativeplaces/qdeclarativeratings_p.h
declarativeplaces/qdeclarativereviewmodel.cpp
declarativeplaces/qdeclarativereviewmodel_p.h
declarativeplaces/qdeclarativesearchmodelbase.cpp
diff --git a/src/location/declarativeplaces/qdeclarativeplace.cpp b/src/location/declarativeplaces/qdeclarativeplace.cpp
index 06fa7c9a..c75a8856 100644
--- a/src/location/declarativeplaces/qdeclarativeplace.cpp
+++ b/src/location/declarativeplaces/qdeclarativeplace.cpp
@@ -325,12 +325,7 @@ void QDeclarativePlace::setPlace(const QPlace &src)
emit locationChanged();
}
- if (m_ratings && m_ratings->parent() == this) {
- m_ratings->setRatings(m_src.ratings());
- } else if (!m_ratings || m_ratings->parent() != this) {
- m_ratings = new QDeclarativeRatings(m_src.ratings(), this);
- emit ratingsChanged();
- }
+ setRatings(m_src.ratings());
if (m_supplier && m_supplier->parent() == this) {
m_supplier->setSupplier(m_src.supplier(), m_plugin);
@@ -406,7 +401,7 @@ QPlace QDeclarativePlace::place() const
result.setLocation(m_location ? m_location->location() : QGeoLocation());
// Rating
- result.setRatings(m_ratings ? m_ratings->ratings() : QPlaceRatings());
+ result.setRatings(m_ratings);
// Supplier
result.setSupplier(m_supplier ? m_supplier->supplier() : QPlaceSupplier());
@@ -465,19 +460,16 @@ QDeclarativeGeoLocation *QDeclarativePlace::location() const
This property holds ratings of the place. The ratings provide an indication of the quality of a
place.
*/
-void QDeclarativePlace::setRatings(QDeclarativeRatings *rating)
+void QDeclarativePlace::setRatings(const QPlaceRatings &rating)
{
if (m_ratings == rating)
return;
- if (m_ratings && m_ratings->parent() == this)
- delete m_ratings;
-
m_ratings = rating;
emit ratingsChanged();
}
-QDeclarativeRatings *QDeclarativePlace::ratings() const
+QPlaceRatings QDeclarativePlace::ratings() const
{
return m_ratings;
diff --git a/src/location/declarativeplaces/qdeclarativeplace_p.h b/src/location/declarativeplaces/qdeclarativeplace_p.h
index c54e3ddf..e69d3d7e 100644
--- a/src/location/declarativeplaces/qdeclarativeplace_p.h
+++ b/src/location/declarativeplaces/qdeclarativeplace_p.h
@@ -57,12 +57,12 @@
#include <QtQml/QQmlParserStatus>
#include <QtQml/QQmlPropertyMap>
#include <QtLocation/QPlace>
+#include <QtLocation/QPlaceRatings>
#include <QtPositioningQuick/private/qdeclarativegeolocation_p.h>
#include <QtLocation/private/qdeclarativecategory_p.h>
#include <QtLocation/private/qdeclarativecontactdetail_p.h>
#include <QtLocation/private/qdeclarativesupplier_p.h>
-#include <QtLocation/private/qdeclarativeratings_p.h>
#include <QtLocation/private/qdeclarativereviewmodel_p.h>
#include <QtLocation/private/qdeclarativeplaceimagemodel_p.h>
#include <QtLocation/private/qdeclarativeplaceeditorialmodel_p.h>
@@ -84,7 +84,7 @@ class Q_LOCATION_PRIVATE_EXPORT QDeclarativePlace : public QObject, public QQmlP
Q_PROPERTY(QDeclarativeGeoServiceProvider *plugin READ plugin WRITE setPlugin NOTIFY pluginChanged)
Q_PROPERTY(QQmlListProperty<QDeclarativeCategory> categories READ categories NOTIFY categoriesChanged)
Q_PROPERTY(QDeclarativeGeoLocation *location READ location WRITE setLocation NOTIFY locationChanged)
- Q_PROPERTY(QDeclarativeRatings *ratings READ ratings WRITE setRatings NOTIFY ratingsChanged)
+ Q_PROPERTY(QPlaceRatings ratings READ ratings WRITE setRatings NOTIFY ratingsChanged)
Q_PROPERTY(QDeclarativeSupplier *supplier READ supplier WRITE setSupplier NOTIFY supplierChanged)
Q_PROPERTY(QDeclarativePlaceIcon *icon READ icon WRITE setIcon NOTIFY iconChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
@@ -146,8 +146,8 @@ public:
QDeclarativeGeoLocation *location() const;
void setLocation(QDeclarativeGeoLocation *location);
- QDeclarativeRatings *ratings() const;
- void setRatings(QDeclarativeRatings *ratings);
+ QPlaceRatings ratings() const;
+ void setRatings(const QPlaceRatings &ratings);
QDeclarativeSupplier *supplier() const;
void setSupplier(QDeclarativeSupplier *supplier);
QDeclarativePlaceIcon *icon() const;
@@ -229,7 +229,7 @@ private:
QList<QDeclarativeCategory *> m_categories;
QDeclarativeGeoLocation *m_location = nullptr;
- QDeclarativeRatings *m_ratings = nullptr;
+ QPlaceRatings m_ratings;
QDeclarativeSupplier *m_supplier = nullptr;
QDeclarativePlaceIcon *m_icon = nullptr;
QDeclarativeReviewModel *m_reviewModel = nullptr;
diff --git a/src/location/declarativeplaces/qdeclarativeratings.cpp b/src/location/declarativeplaces/qdeclarativeratings.cpp
deleted file mode 100644
index c7b6926b..00000000
--- a/src/location/declarativeplaces/qdeclarativeratings.cpp
+++ /dev/null
@@ -1,156 +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 "qdeclarativeratings_p.h"
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \qmltype Ratings
- \instantiates QDeclarativeRatings
- \inqmlmodule QtLocation
- \ingroup qml-QtLocation5-places
- \ingroup qml-QtLocation5-places-data
- \since QtLocation 5.5
-
- \brief The Ratings type holds place rating information.
-
- Rating information is used to describe how \e good a place is conceived to be. Typically this
- information is visualized as a number of stars. The \l average property gives an aggregated
- ratings value out of a possible maximum as given by the \l maximum property.
-
- \snippet declarative/places.qml QtQuick import
- \snippet declarative/maps.qml QtLocation import
- \codeline
- \snippet declarative/places.qml Ratings
-*/
-
-QDeclarativeRatings::QDeclarativeRatings(QObject *parent)
- : QObject(parent) {}
-
-QDeclarativeRatings::QDeclarativeRatings(const QPlaceRatings &rating,
- QObject *parent)
- : QObject(parent),
- m_ratings(rating) {}
-
-QDeclarativeRatings::~QDeclarativeRatings() {}
-
-/*!
- \qmlproperty QPlaceRatings Ratings::ratings
-
- For details on how to use this property to interface between C++ and QML see
- "\l {Ratings - QPlaceRatings} {Interfaces between C++ and QML Code}".
-*/
-void QDeclarativeRatings::setRatings(const QPlaceRatings &ratings)
-{
- QPlaceRatings previous = m_ratings;
- m_ratings = ratings;
-
- if (ratings.average() != previous.average()) {
- emit averageChanged();
- }
- if (ratings.count() != previous.count()) {
- emit countChanged();
- }
-}
-
-QPlaceRatings QDeclarativeRatings::ratings() const
-{
- return m_ratings;
-}
-
-/*!
- \qmlproperty real Ratings::average
-
- This property holds the average of the individual ratings.
-
- \sa maximum
-*/
-void QDeclarativeRatings::setAverage(qreal average)
-{
- if (m_ratings.average() != average) {
- m_ratings.setAverage(average);
- emit averageChanged();
- }
-}
-
-qreal QDeclarativeRatings::average() const
-{
- return m_ratings.average();
-}
-
-/*!
- \qmlproperty real Ratings::maximum
-
- This property holds the maximum rating value.
-*/
-void QDeclarativeRatings::setMaximum(qreal max)
-{
- if (m_ratings.maximum() == max)
- return;
-
- m_ratings.setMaximum(max);
- emit maximumChanged();
-}
-
-qreal QDeclarativeRatings::maximum() const
-{
- return m_ratings.maximum();
-}
-
-/*!
- \qmlproperty int Ratings::count
-
- This property holds the total number of individual user ratings
- used in determining the overall ratings \l average.
-*/
-void QDeclarativeRatings::setCount(int count)
-{
- if (m_ratings.count() != count) {
- m_ratings.setCount(count);
- emit countChanged();
- }
-}
-
-int QDeclarativeRatings::count() const
-{
- return m_ratings.count();
-}
-
-QT_END_NAMESPACE
diff --git a/src/location/declarativeplaces/qdeclarativeratings_p.h b/src/location/declarativeplaces/qdeclarativeratings_p.h
deleted file mode 100644
index b31aa83d..00000000
--- a/src/location/declarativeplaces/qdeclarativeratings_p.h
+++ /dev/null
@@ -1,101 +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 QDECLARATIVERATINGS_P_H
-#define QDECLARATIVERATINGS_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 <QtLocation/qplaceratings.h>
-#include <QtQml/qqml.h>
-
-#include <QObject>
-
-QT_BEGIN_NAMESPACE
-
-class Q_LOCATION_PRIVATE_EXPORT QDeclarativeRatings : public QObject
-{
- Q_OBJECT
-
- Q_PROPERTY(QPlaceRatings ratings READ ratings WRITE setRatings)
- Q_PROPERTY(qreal average READ average WRITE setAverage NOTIFY averageChanged)
- Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
- Q_PROPERTY(int count READ count WRITE setCount NOTIFY countChanged)
-
-public:
- explicit QDeclarativeRatings(QObject *parent = 0);
- explicit QDeclarativeRatings(const QPlaceRatings &src, QObject *parent = 0);
- ~QDeclarativeRatings();
-
- QPlaceRatings ratings() const;
- void setRatings(const QPlaceRatings &src);
-
- qreal average() const;
- void setAverage(qreal average);
-
- qreal maximum() const;
- void setMaximum(qreal max);
-
- int count() const;
- void setCount(int count);
-
-Q_SIGNALS:
- void averageChanged();
- void maximumChanged();
- void countChanged();
-
-private:
- QPlaceRatings m_ratings;
-};
-
-QT_END_NAMESPACE
-
-QML_DECLARE_TYPE(QDeclarativeRatings)
-
-#endif // QDECLARATIVERATING_P_H
diff --git a/src/location/places/qplaceratings.cpp b/src/location/places/qplaceratings.cpp
index ba4389ef..81c342d5 100644
--- a/src/location/places/qplaceratings.cpp
+++ b/src/location/places/qplaceratings.cpp
@@ -72,6 +72,25 @@ bool QPlaceRatingsPrivate::isEmpty() const
*/
/*!
+ \qmlvaluetype ratings
+ \inqmlmodule QtLocation
+ \ingroup qml-QtLocation5-places
+ \ingroup qml-QtLocation5-places-data
+ \since QtLocation 5.5
+
+ \brief The ratings type holds place rating information.
+
+ Rating information is used to describe how \e good a place is conceived to be. Typically this
+ information is visualized as a number of stars. The \l average property gives an aggregated
+ ratings value out of a possible maximum as given by the \l maximum property.
+
+ \snippet declarative/places.qml QtQuick import
+ \snippet declarative/maps.qml QtLocation import
+ \codeline
+ \snippet declarative/places.qml ratings
+*/
+
+/*!
Constructs a new ratings object.
*/
QPlaceRatings::QPlaceRatings()
@@ -120,48 +139,63 @@ bool QPlaceRatings::isEqual(const QPlaceRatings &other) const noexcept
}
/*!
- Returns the average value of individual ratings.
+ \qmlproperty real ratings::average
+
+ This property holds the average of the individual ratings.
+
+ \sa maximum
+*/
+
+/*!
+ \property QPlaceRatings::average
+ \brief the average value of individual ratings.
*/
qreal QPlaceRatings::average() const
{
return d->average;
}
-/*!
- Sets the \a average value of the ratings.
-*/
void QPlaceRatings::setAverage(qreal average)
{
d->average = average;
}
/*!
- Returns the maximum possible rating value.
+ \qmlproperty real ratings::maximum
+
+ This property holds the maximum rating value.
+*/
+
+/*!
+ \property QPlaceRatings::maximum
+ \brief the maximum possible rating value.
*/
qreal QPlaceRatings::maximum() const
{
return d->maximum;
}
-/*!
- Sets the maximum possible rating value to \a max.
-*/
void QPlaceRatings::setMaximum(qreal max)
{
d->maximum = max;
}
/*!
- Returns the total number of individual ratings.
+ \qmlproperty int ratings::count
+
+ This property holds the total number of individual user ratings
+ used in determining the overall ratings \l average.
+*/
+
+/*!
+ \property QPlaceRatings::count
+ \brief the total number of individual ratings.
*/
int QPlaceRatings::count() const
{
return d->count;
}
-/*!
- Sets the total number of individual ratings to \a count.
-*/
void QPlaceRatings::setCount(int count)
{
d->count = count;
@@ -174,3 +208,5 @@ bool QPlaceRatings::isEmpty() const
{
return d->isEmpty();
}
+
+#include "moc_qplaceratings.cpp"
diff --git a/src/location/places/qplaceratings.h b/src/location/places/qplaceratings.h
index d506aa20..019c20b1 100644
--- a/src/location/places/qplaceratings.h
+++ b/src/location/places/qplaceratings.h
@@ -51,6 +51,11 @@ QT_DECLARE_QSDP_SPECIALIZATION_DTOR_WITH_EXPORT(QPlaceRatingsPrivate, Q_LOCATION
class Q_LOCATION_EXPORT QPlaceRatings
{
+ Q_GADGET
+ Q_PROPERTY(qreal average READ average WRITE setAverage)
+ Q_PROPERTY(qreal maximum READ maximum WRITE setMaximum)
+ Q_PROPERTY(int count READ count WRITE setCount)
+
public:
QPlaceRatings();
QPlaceRatings(const QPlaceRatings &other) noexcept;
diff --git a/tests/auto/declarative_location_core/tst_place.qml b/tests/auto/declarative_location_core/tst_place.qml
index cc2ed44f..8f60f8c0 100644
--- a/tests/auto/declarative_location_core/tst_place.qml
+++ b/tests/auto/declarative_location_core/tst_place.qml
@@ -82,10 +82,7 @@ TestCase {
boundingShape: QtPositioning.rectangle(QtPositioning.coordinate(10, 10, 100), 100, 100)
}
- ratings: Ratings {
- average: 3.5
- count: 10
- }
+ ratings: ({ average: 3.5, count: 10 })
supplier: Supplier {
name: "Supplier 1"
@@ -183,15 +180,8 @@ TestCase {
}
// check ratings
- if (place1. ratings === null && place2.ratings !== null)
- return false;
- if (place1.ratings !== null && place2.ratings === null)
+ if (place1.ratings !== place2.ratings) {
return false;
- if (place1.ratings !== null && place2.ratings !== null) {
- if (place1.ratings.average !== place2.ratings.average)
- return false;
- if (place1.ratings.count !== place2.ratings.count)
- return false;
}
// check location
@@ -405,27 +395,24 @@ TestCase {
}
function test_ratings() {
- var ratings = Qt.createQmlObject('import QtLocation 5.3; Ratings { average: 3; count: 100 }', testCase, "Rating1");
+ var ratings1 = emptyPlace.ratings
+ var ratings2 = savePlace.ratings
var signalSpy = Qt.createQmlObject('import QtTest 1.0; SignalSpy {}', testCase, "SignalSpy");
signalSpy.target = testPlace;
signalSpy.signalName = "ratingsChanged";
- testPlace.ratings = ratings;
- compare(testPlace.ratings.average, 3);
- compare(testPlace.ratings.count, 100);
- compare(signalSpy.count, 1);
+ testPlace.ratings = ratings1;
+ compare(signalSpy.count, 0);
- testPlace.ratings = ratings;
- compare(testPlace.ratings.average, 3);
- compare(testPlace.ratings.count, 100);
+ testPlace.ratings = ratings2;
+ compare(testPlace.ratings.count, ratings2.count);
compare(signalSpy.count, 1);
- testPlace.ratings = null;
- compare(testPlace.ratings, null);
+ testPlace.ratings = ratings1;
+ compare(testPlace.ratings.count, ratings1.count);
compare(signalSpy.count, 2);
- ratings.destroy();
signalSpy.destroy();
}
diff --git a/tests/auto/declarative_location_core/tst_ratings.qml b/tests/auto/declarative_location_core/tst_ratings.qml
index d372d815..e1d76539 100644
--- a/tests/auto/declarative_location_core/tst_ratings.qml
+++ b/tests/auto/declarative_location_core/tst_ratings.qml
@@ -35,7 +35,7 @@ TestCase {
name: "Ratings"
- Ratings { id: emptyRatings }
+ property ratings emptyRatings
function test_empty() {
compare(emptyRatings.average, 0.0);
@@ -43,33 +43,11 @@ TestCase {
compare(emptyRatings.count, 0);
}
- Ratings {
- id: qmlRatings
-
- average: 3.5
- maximum: 5.0
- count: 7
- }
+ property ratings qmlRatings: ({ average: 3.5, maximum: 5.0, count: 7 })
function test_qmlConstructedRatings() {
compare(qmlRatings.average, 3.5);
compare(qmlRatings.maximum, 5.0);
compare(qmlRatings.count, 7);
}
-
- Ratings {
- id: testRatings
- }
-
- function test_setAndGet_data() {
- return [
- { tag: "average", property: "average", signal: "averageChanged", value: 4.5, reset: 0.0 },
- { tag: "maximum", property: "maximum", signal: "maximumChanged", value: 5.0, reset: 0.0 },
- { tag: "count", property: "count", signal: "countChanged", value: 10, reset: 0 },
- ];
- }
-
- function test_setAndGet(data) {
- Utils.testObjectProperties(testCase, testRatings, data);
- }
}
diff --git a/tests/auto/qmlinterface/data/TestPlace.qml b/tests/auto/qmlinterface/data/TestPlace.qml
index 4a0adc78..1cce22af 100644
--- a/tests/auto/qmlinterface/data/TestPlace.qml
+++ b/tests/auto/qmlinterface/data/TestPlace.qml
@@ -43,7 +43,7 @@ Place {
}
]
location: TestLocation { }
- ratings: TestRatings { }
+ ratings: ({ average: 3.5, maximum: 5.0, count: 10 })
icon: TestIcon { }
supplier: TestSupplier { }
visibility: Place.PrivateVisibility
diff --git a/tests/auto/qmlinterface/data/TestRatings.qml b/tests/auto/qmlinterface/data/TestRatings.qml
index 67e26cc3..17f7d4f5 100644
--- a/tests/auto/qmlinterface/data/TestRatings.qml
+++ b/tests/auto/qmlinterface/data/TestRatings.qml
@@ -27,9 +27,13 @@
****************************************************************************/
import QtLocation
+import QtQuick
-Ratings {
- average: 3.5
- maximum: 5.0
- count: 10
+Item {
+ property ratings ratings
+ ratings {
+ average: 3.5
+ maximum: 5.0
+ count: 10
+ }
}