1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtLocation module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qdeclarativeratings_p.h"
38
39QT_BEGIN_NAMESPACE
40
41/*!
42 \qmltype Ratings
43 \instantiates QDeclarativeRatings
44 \inqmlmodule QtLocation
45 \ingroup qml-QtLocation5-places
46 \ingroup qml-QtLocation5-places-data
47 \since QtLocation 5.5
48
49 \brief The Ratings type holds place rating information.
50
51 Rating information is used to describe how \e good a place is conceived to be. Typically this
52 information is visualized as a number of stars. The \l average property gives an aggregated
53 ratings value out of a possible maximum as given by the \l maximum property.
54
55 \snippet declarative/places.qml QtQuick import
56 \snippet declarative/maps.qml QtLocation import
57 \codeline
58 \snippet declarative/places.qml Ratings
59*/
60
61QDeclarativeRatings::QDeclarativeRatings(QObject *parent)
62 : QObject(parent) {}
63
64QDeclarativeRatings::QDeclarativeRatings(const QPlaceRatings &rating,
65 QObject *parent)
66 : QObject(parent),
67 m_ratings(rating) {}
68
69QDeclarativeRatings::~QDeclarativeRatings() {}
70
71/*!
72 \qmlproperty QPlaceRatings Ratings::ratings
73
74 For details on how to use this property to interface between C++ and QML see
75 "\l {Ratings - QPlaceRatings} {Interfaces between C++ and QML Code}".
76*/
77void QDeclarativeRatings::setRatings(const QPlaceRatings &ratings)
78{
79 QPlaceRatings previous = m_ratings;
80 m_ratings = ratings;
81
82 if (ratings.average() != previous.average()) {
83 emit averageChanged();
84 }
85 if (ratings.count() != previous.count()) {
86 emit countChanged();
87 }
88}
89
90QPlaceRatings QDeclarativeRatings::ratings() const
91{
92 return m_ratings;
93}
94
95/*!
96 \qmlproperty real Ratings::average
97
98 This property holds the average of the individual ratings.
99
100 \sa maximum
101*/
102void QDeclarativeRatings::setAverage(qreal average)
103{
104 if (m_ratings.average() != average) {
105 m_ratings.setAverage(average);
106 emit averageChanged();
107 }
108}
109
110qreal QDeclarativeRatings::average() const
111{
112 return m_ratings.average();
113}
114
115/*!
116 \qmlproperty real Ratings::maximum
117
118 This property holds the maximum rating value.
119*/
120void QDeclarativeRatings::setMaximum(qreal max)
121{
122 if (m_ratings.maximum() == max)
123 return;
124
125 m_ratings.setMaximum(max);
126 emit maximumChanged();
127}
128
129qreal QDeclarativeRatings::maximum() const
130{
131 return m_ratings.maximum();
132}
133
134/*!
135 \qmlproperty int Ratings::count
136
137 This property holds the total number of individual user ratings
138 used in determining the overall ratings \l average.
139*/
140void QDeclarativeRatings::setCount(int count)
141{
142 if (m_ratings.count() != count) {
143 m_ratings.setCount(count);
144 emit countChanged();
145 }
146}
147
148int QDeclarativeRatings::count() const
149{
150 return m_ratings.count();
151}
152
153QT_END_NAMESPACE
154

source code of qtlocation/src/location/declarativeplaces/qdeclarativeratings.cpp