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 "qplacecontentrequest_p.h"
38 #include "qplacecontentrequest.h"
39 #include "qgeocoordinate.h"
40 
41 QT_BEGIN_NAMESPACE
42 
QPlaceContentRequestPrivate()43 QPlaceContentRequestPrivate::QPlaceContentRequestPrivate()
44 :   QSharedData(), contentType(QPlaceContent::NoType), limit(-1)
45 {
46 }
47 
QPlaceContentRequestPrivate(const QPlaceContentRequestPrivate & other)48 QPlaceContentRequestPrivate::QPlaceContentRequestPrivate(const QPlaceContentRequestPrivate &other)
49 :   QSharedData(other), contentType(other.contentType), placeId(other.placeId),
50     contentContext(other.contentContext), limit(other.limit)
51 {
52 }
53 
~QPlaceContentRequestPrivate()54 QPlaceContentRequestPrivate::~QPlaceContentRequestPrivate()
55 {
56 }
57 
operator ==(const QPlaceContentRequestPrivate & other) const58 bool QPlaceContentRequestPrivate::operator==(const QPlaceContentRequestPrivate &other) const
59 {
60     return contentType == other.contentType
61             && limit == other.limit;
62 }
63 
clear()64 void QPlaceContentRequestPrivate::clear()
65 {
66     contentType = QPlaceContent::NoType;
67     limit = -1;
68 }
69 
70 /*!
71     \class QPlaceContentRequest
72     \inmodule QtLocation
73     \ingroup QtLocation-places
74     \ingroup QtLocation-places-requests
75     \since 5.6
76 
77     \brief The QPlaceContentRequest class represents the parameters of a content request.
78 
79     The QPlaceContentRequest class is used in conjunction with a QPlaceManager to
80     retrieve rich content like images and reviews in a paginated fashion.
81     The following code would request a set of 5 images from the 10th index:
82 
83     \snippet places/requesthandler.h Content request
84     \dots
85     \dots
86     \snippet places/requesthandler.h Content handler
87 
88     \sa QPlaceContentReply
89 */
90 
91 /*!
92     Constructs a new request object.
93 */
QPlaceContentRequest()94 QPlaceContentRequest::QPlaceContentRequest()
95     : d_ptr(new QPlaceContentRequestPrivate())
96 {
97 }
98 
99 /*!
100     Constructs a copy of \a other.
101 */
QPlaceContentRequest(const QPlaceContentRequest & other)102 QPlaceContentRequest::QPlaceContentRequest(const QPlaceContentRequest &other)
103     : d_ptr(other.d_ptr)
104 {
105 }
106 
107 /*!
108     Destroys the request object
109 */
~QPlaceContentRequest()110 QPlaceContentRequest::~QPlaceContentRequest()
111 {
112 }
113 
114 /*!
115     Assigns \a other to this content request and returns a reference
116     to this content request.
117 */
operator =(const QPlaceContentRequest & other)118 QPlaceContentRequest &QPlaceContentRequest::operator= (const QPlaceContentRequest & other)
119 {
120     if (this == &other)
121         return *this;
122 
123     d_ptr = other.d_ptr;
124     return *this;
125 }
126 
127 /*!
128     Returns true if \a other is equal to this content request,
129     otherwise returns false.
130 */
operator ==(const QPlaceContentRequest & other) const131 bool QPlaceContentRequest::operator== (const QPlaceContentRequest &other) const
132 {
133     Q_D(const QPlaceContentRequest);
134     return *d == *other.d_func();
135 }
136 
137 /*!
138     Returns true if \a other is not equal to this content request,
139     otherwise returns false.
140 */
operator !=(const QPlaceContentRequest & other) const141 bool QPlaceContentRequest::operator!= (const QPlaceContentRequest &other) const
142 {
143     Q_D(const QPlaceContentRequest);
144     return !(*d == *other.d_func());
145 }
146 
147 /*!
148     Returns the type of content to be requested, for example reviews or images
149 */
contentType() const150 QPlaceContent::Type QPlaceContentRequest::contentType() const
151 {
152     Q_D(const QPlaceContentRequest);
153     return d->contentType;
154 }
155 
156 /*!
157     Sets the \a type of content to be requested.
158 */
setContentType(QPlaceContent::Type type)159 void QPlaceContentRequest::setContentType(QPlaceContent::Type type)
160 {
161     Q_D(QPlaceContentRequest);
162     d->contentType = type;
163 }
164 
165 /*!
166     Returns the identifier of the place content is to be fetched for.
167 */
placeId() const168 QString QPlaceContentRequest::placeId() const
169 {
170     Q_D(const QPlaceContentRequest);
171     return d->placeId;
172 }
173 
174 /*!
175     Sets the identifier of the place to fetch content for to \a identifier.
176 */
setPlaceId(const QString & identifier)177 void QPlaceContentRequest::setPlaceId(const QString &identifier)
178 {
179     Q_D(QPlaceContentRequest);
180     d->placeId = identifier;
181 }
182 
183 /*!
184     Returns backend specific additional content context associated with this place content request.
185 */
contentContext() const186 QVariant QPlaceContentRequest::contentContext() const
187 {
188     Q_D(const QPlaceContentRequest);
189     return d->contentContext;
190 }
191 
192 /*!
193     Sets the content context to \a context.
194 
195     \note This method is intended to be used by geo service plugins when returning place content
196     results.
197 
198     The content context is used by backends to store additional content context related to the
199     content request. Other relevant fields should also be filled in. For example, if the content
200     request is for image content the content type should also be set with \l setContentType(). The
201     content context allows additional context to be kept which is not directly accessible via the
202     Qt Location API.
203 
204     The content context can be of any type storable in a QVariant. The value of the content context
205     is not intended to be used directly by applications.
206 */
setContentContext(const QVariant & context)207 void QPlaceContentRequest::setContentContext(const QVariant &context)
208 {
209     Q_D(QPlaceContentRequest);
210     d->contentContext = context;
211 }
212 
213 /*!
214     Returns the maximum number of content items to retrieve.
215 
216     A negative value for limit means that it is undefined.  It is left up to the backend
217     provider to choose an appropriate number of items to return.
218 
219     The default limit is -1.
220 */
limit() const221 int QPlaceContentRequest::limit() const
222 {
223     Q_D(const QPlaceContentRequest);
224     return d->limit;
225 }
226 
227 /*!
228     Set the maximum number of content items to retrieve to
229     \a limit.
230 */
setLimit(int limit)231 void QPlaceContentRequest::setLimit(int limit)
232 {
233     Q_D(QPlaceContentRequest);
234     d->limit = limit;
235 }
236 
237 /*!
238     Clears the content request.
239 */
clear()240 void QPlaceContentRequest::clear()
241 {
242     Q_D(QPlaceContentRequest);
243     d->clear();
244 }
245 
d_func()246 inline QPlaceContentRequestPrivate *QPlaceContentRequest::d_func()
247 {
248     return static_cast<QPlaceContentRequestPrivate *>(d_ptr.data());
249 }
250 
d_func() const251 inline const QPlaceContentRequestPrivate *QPlaceContentRequest::d_func() const
252 {
253     return static_cast<const QPlaceContentRequestPrivate *>(d_ptr.constData());
254 }
255 
256 QT_END_NAMESPACE
257