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 "qplaceratings.h"
38#include "qplaceratings_p.h"
39
40QT_USE_NAMESPACE
41
42QPlaceRatingsPrivate::QPlaceRatingsPrivate()
43 : QSharedData(), average(0), maximum(0), count(0)
44{
45}
46
47QPlaceRatingsPrivate::QPlaceRatingsPrivate(const QPlaceRatingsPrivate &other)
48: QSharedData(), average(0), maximum(other.maximum), count(other.count)
49{
50}
51
52QPlaceRatingsPrivate::~QPlaceRatingsPrivate()
53{
54}
55
56bool QPlaceRatingsPrivate::operator==(const QPlaceRatingsPrivate &other) const
57{
58 return average == other.average && maximum == other.maximum && count == other.count;
59}
60
61bool QPlaceRatingsPrivate::isEmpty() const
62{
63 return count == 0 && average == 0 && maximum == 0;
64}
65
66/*!
67 \class QPlaceRatings
68 \inmodule QtLocation
69 \ingroup QtLocation-places
70 \ingroup QtLocation-places-data
71 \since 5.6
72
73 \brief The QPlaceRatings class holds rating information about a place.
74
75 Rating information is used to describe how good a place is conceived to be.
76 Typically this information is visualized as a number of stars.
77 The average() function returns an aggregated ratings value out of a possible
78 maximum as given by the maximum() function.
79
80 \snippet places/requesthandler.h Ratings
81*/
82
83/*!
84 Constructs a new ratings object.
85*/
86QPlaceRatings::QPlaceRatings()
87 : d(new QPlaceRatingsPrivate)
88{
89}
90
91/*!
92 Constructs a copy of \a other.
93*/
94QPlaceRatings::QPlaceRatings(const QPlaceRatings &other)
95 :d(other.d)
96{
97}
98
99/*!
100 Destroys the ratings object.
101*/
102QPlaceRatings::~QPlaceRatings()
103{
104}
105
106/*!
107 Assigns \a other to this ratings object and returns
108 a reference to this ratings object.
109*/
110QPlaceRatings &QPlaceRatings::operator=(const QPlaceRatings &other)
111{
112 if (this == &other)
113 return *this;
114
115 d = other.d;
116 return *this;
117}
118
119/*!
120 Returns true if \a other is equal to this ratings object,
121 otherwise returns false.
122*/
123bool QPlaceRatings::operator==(const QPlaceRatings &other) const
124{
125 return (*(d.constData()) == *(other.d.constData()));
126}
127
128/*!
129 \fn bool QPlaceRatings::operator!=(const QPlaceRatings &other) const
130
131 Returns true if \a other is not equal to this ratings object,
132 otherwise returns false.
133*/
134
135/*!
136 Returns the average value of individual ratings.
137*/
138qreal QPlaceRatings::average() const
139{
140 return d->average;
141}
142
143/*!
144 Sets the \a average value of the ratings.
145*/
146void QPlaceRatings::setAverage(qreal average)
147{
148 d->average = average;
149}
150
151/*!
152 Returns the maximum possible rating value.
153*/
154qreal QPlaceRatings::maximum() const
155{
156 return d->maximum;
157}
158
159/*!
160 Sets the maximum possible rating value to \a max.
161*/
162void QPlaceRatings::setMaximum(qreal max)
163{
164 d->maximum = max;
165}
166
167/*!
168 Returns the total number of individual ratings.
169*/
170int QPlaceRatings::count() const
171{
172 return d->count;
173}
174
175/*!
176 Sets the total number of individual ratings to \a count.
177*/
178void QPlaceRatings::setCount(int count)
179{
180 d->count = count;
181}
182
183/*!
184 Returns true if all fields of the place ratings are 0; otherwise returns false.
185*/
186bool QPlaceRatings::isEmpty() const
187{
188 return d->isEmpty();
189}
190

source code of qtlocation/src/location/places/qplaceratings.cpp