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 "qplacecontent.h"
38#include "qplacecontent_p.h"
39
40#include <QtCore/QUrl>
41
42QT_USE_NAMESPACE
43
44template<> QPlaceContentPrivate *QSharedDataPointer<QPlaceContentPrivate>::clone()
45{
46 return d->clone();
47}
48
49inline QPlaceContentPrivate *QPlaceContent::d_func()
50{
51 return static_cast<QPlaceContentPrivate *>(d_ptr.data());
52}
53
54inline const QPlaceContentPrivate *QPlaceContent::d_func() const
55{
56 return static_cast<const QPlaceContentPrivate *>(d_ptr.constData());
57}
58
59bool QPlaceContentPrivate::compare(const QPlaceContentPrivate *other) const
60{
61 return supplier == other->supplier
62 && user == other->user
63 && attribution == other->attribution;
64}
65
66/*!
67 \class QPlaceContent
68 \inmodule QtLocation
69 \ingroup QtLocation-places
70 \ingroup QtLocation-places-data
71 \since 5.6
72
73 \brief The QPlaceContent class serves as the base class for rich content types.
74
75 Rich content such as \l {QPlaceImage}{images}, \l {QPlaceReview}{reviews}
76 and \l {QPlaceEditorial}{editorials} inherit
77 from the QPlaceContent class which contains common properties such as
78 an attribution string and content contributor, which may take the form of a
79 \l {QPlaceUser}{user} and/or \l {QPlaceSupplier}{supplier}. It is possible that
80 a user from a supplier is contributing content, hence both fields could
81 be filled in simultaneously.
82
83 \b {Note:} Some providers may \e {require} that the attribution string be displayed
84 to the user whenever a piece of content is viewed.
85
86 Conversion between QPlaceContent and it's subclasses can be easily performed without
87 casting. Due to the way it has been implemented, object slicing is not an issue,
88 the following code is valid:
89 \snippet places/requesthandler.h Content conversion
90
91 The rich content of a place is typically made available as paginated items. The ability
92 to convert between QPlaceContent and it's subclasses means that code which handles
93 the mechanics of paging can be easily shared for each of the sub types.
94
95 At present the QPlaceContent class is not extensible by 3rd parties.
96
97 Note: The Places API considers content objects to be 'retrieve-only' objects.
98 Submission of content to a provider is not a supported use case.
99 \sa QPlaceImage, QPlaceReview, QPlaceEditorial
100*/
101
102/*!
103 \typedef QPlaceContent::Collection
104 Synonym for QMap<int, QPlaceContent>. The key of the map is an \c int representing the
105 index of the content. The value is the content object itself.
106
107 The \c {Collection} is intended to be a container where content items, that have been retrieved
108 as pages, can be stored. This enables a developer to skip pages, for example indexes 0-9 may be
109 stored in the collection, if the user skips to indexes 80-99, these can be stored in the
110 collection as well.
111*/
112
113/*!
114 \enum QPlaceContent::Type
115 Defines the type of content.
116 \value NoType
117 The content object is default constructed, any other content type may be assigned
118 to this content object
119 \value ImageType
120 The content object is an image
121 \value ReviewType
122 The content object is a review
123 \value EditorialType
124 The content object is an editorial
125 \value CustomType
126 The content object is of a custom type
127*/
128
129/*!
130 Constructs an default content object which has no type.
131*/
132QPlaceContent::QPlaceContent()
133 :d_ptr(0)
134{
135}
136
137/*!
138 Constructs a new copy of \a other.
139*/
140QPlaceContent::QPlaceContent(const QPlaceContent &other)
141 :d_ptr(other.d_ptr)
142{
143}
144
145/*!
146 Assigns the \a other content object to this and returns a reference
147 to this content object.
148*/
149QPlaceContent &QPlaceContent::operator=(const QPlaceContent &other)
150{
151 if (this == &other)
152 return *this;
153
154 d_ptr = other.d_ptr;
155 return *this;
156}
157
158/*!
159 Destroys the content object.
160*/
161QPlaceContent::~QPlaceContent()
162{
163}
164
165/*!
166 Returns the content type.
167*/
168QPlaceContent::Type QPlaceContent::type() const
169{
170 if (!d_ptr)
171 return NoType;
172 return d_ptr->type();
173}
174
175/*!
176 Returns true if this content object is equivalent to \a other,
177 otherwise returns false.
178*/
179bool QPlaceContent::operator==(const QPlaceContent &other) const
180{
181 // An invalid content object is only equal to another invalid content object
182 if (!d_ptr)
183 return !other.d_ptr;
184
185 if (type() != other.type())
186 return false;
187
188 return d_ptr->compare(other: other.d_ptr);
189}
190
191/*!
192 Returns true if this content object is not equivalent to \a other,
193 otherwise returns false.
194*/
195bool QPlaceContent::operator!=(const QPlaceContent &other) const
196{
197 return !(*this == other);
198}
199
200/*!
201 Returns the supplier who contributed this content.
202*/
203QPlaceSupplier QPlaceContent::supplier() const
204{
205 Q_D(const QPlaceContent);
206
207 return d->supplier;
208}
209
210/*!
211 Sets the \a supplier of the content.
212*/
213void QPlaceContent::setSupplier(const QPlaceSupplier &supplier)
214{
215 Q_D(QPlaceContent);
216
217 d->supplier = supplier;
218}
219
220/*!
221 Returns the user who contributed this content.
222*/
223QPlaceUser QPlaceContent::user() const
224{
225 Q_D(const QPlaceContent);
226 return d->user;
227}
228
229/*!
230 Sets the \a user who contributed this content.
231*/
232void QPlaceContent::setUser(const QPlaceUser &user)
233{
234 Q_D(QPlaceContent);
235 d->user = user;
236}
237
238/*!
239 Returns a rich text attribution string.
240
241 \b {Note}: Some providers may require that the attribution
242 of a particular content item always be displayed
243 when the content item is shown.
244*/
245QString QPlaceContent::attribution() const
246{
247 Q_D(const QPlaceContent);
248 return d->attribution;
249}
250
251/*!
252 Sets a rich text \a attribution string for this content item.
253*/
254void QPlaceContent::setAttribution(const QString &attribution)
255{
256 Q_D(QPlaceContent);
257 d->attribution = attribution;
258}
259
260/*!
261 \internal
262 Constructs a new content object from the given pointer \a d.
263*/
264QPlaceContent::QPlaceContent(QPlaceContentPrivate *d)
265 :d_ptr(d)
266{
267}
268

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