Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qplacecontent.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8QT_USE_NAMESPACE
9
10inline QPlaceContentPrivate *QPlaceContent::d_func()
11{
12 return d_ptr.data();
13}
14
15inline const QPlaceContentPrivate *QPlaceContent::d_func() const
16{
17 return d_ptr.constData();
18}
19
20bool QPlaceContentPrivate::compare(const QPlaceContentPrivate *other) const
21{
22 return data == other->data;
23}
24
25QT_DEFINE_QESDP_SPECIALIZATION_DTOR(QPlaceContentPrivate)
26
27/*!
28 \class QPlaceContent
29 \inmodule QtLocation
30 \ingroup QtLocation-places
31 \ingroup QtLocation-places-data
32 \since 5.6
33
34 \brief The QPlaceContent class holds content about places.
35
36 A QPlaceContent holds rich content such as images, reviews, or editorials, as well
37 as attributes about the content such as the user or supplier of the content. Content
38 objects might hold multiple data, e.g. an item holding a review typically includes
39 the user that wrote the review. Use type() to inspect the type of content a
40 QPlaceContent object represents, and dataTags() to see which data is held. Use value()
41 to get the individual data as a QVariant.
42
43 \b {Note:} Some providers may \e {require} that the attribution string be displayed
44 to the user whenever a piece of content is viewed.
45
46 The rich content of a place is typically made available as paginated items.
47
48 At present the QPlaceContent class is not extensible by 3rd parties.
49
50 Note: The Places API considers content objects to be 'retrieve-only' objects.
51 Submission of content to a provider is not a supported use case.
52*/
53
54/*!
55 \typedef QPlaceContent::Collection
56 Synonym for QMap<int, QPlaceContent>. The key of the map is an \c int representing the
57 index of the content. The value is the content object itself.
58
59 The \c {Collection} is intended to be a container where content items, that have been retrieved
60 as pages, can be stored. This enables a developer to skip pages, for example indexes 0-9 may be
61 stored in the collection, if the user skips to indexes 80-99, these can be stored in the
62 collection as well.
63*/
64
65/*!
66 \enum QPlaceContent::Type
67 Defines the type of content.
68 \value NoType
69 The content object is default constructed, any other content type may be assigned
70 to this content object
71 \value ImageType
72 The content object is an image
73 \value ReviewType
74 The content object is a review
75 \value EditorialType
76 The content object is an editorial
77 \value CustomType
78 The content object is of a custom type
79*/
80
81/*!
82 \enum QPlaceContent::DataTag
83
84 Defines the value entry of the content object
85
86 \value ContentSupplier
87 The supplier who contributed this content
88 \value ContentUser
89 The user who contributed this content
90 \value ContentAttribution
91 Returns a rich text attribution string
92 \note Some providers may require that the attribution
93 of a particular content item always be displayed
94 when the content item is shown.
95 \value ImageId
96 The image's identifier
97 \value ImageUrl
98 The image's url
99 \value ImageMimeType
100 The image's MIME type
101 \value EditorialTitle
102 The title of the editorial
103 \value EditorialText
104 A textual description of the place. Depending upon the provider, the
105 text could be either rich (HTML based) text or plain text.
106 \value EditorialLanguage
107 The language of the editorial. Typically this would be a language code
108 in the 2 letter ISO 639-1 format.
109 \value ReviewId
110 The identifier of the review
111 \value ReviewDateTime
112 The date and time that the review was submitted
113 \value ReviewTitle
114 The title of the review
115 \value ReviewText
116 The text of the review. Depending on the provider, the text could be
117 rich (HTML based) or plain text.
118 \value ReviewLanguage
119 The language of the review. Typically this would be a language code
120 in the 2 letter ISO 639-1 format.
121 \value ReviewRating
122 This review's rating of the place
123 \value CustomDataTag
124*/
125
126/*!
127 Constructs an content object for \a type.
128*/
129QPlaceContent::QPlaceContent(Type type)
130 : d_ptr(new QPlaceContentPrivate(type))
131{}
132
133/*!
134 Constructs a new copy of \a other.
135*/
136QPlaceContent::QPlaceContent(const QPlaceContent &other) noexcept = default;
137
138/*!
139 Assigns the \a other content object to this and returns a reference
140 to this content object.
141*/
142QPlaceContent &QPlaceContent::operator=(const QPlaceContent &other) noexcept = default;
143
144/*!
145 Destroys the content object.
146*/
147QPlaceContent::~QPlaceContent() = default;
148
149/*!
150 \internal
151*/
152void QPlaceContent::detach()
153{
154 d_ptr.detach();
155}
156
157/*!
158 Returns the content type.
159*/
160QPlaceContent::Type QPlaceContent::type() const
161{
162 if (!d_ptr)
163 return NoType;
164 return d_ptr->type();
165}
166
167/*!
168 Returns true if this content object is equivalent to \a other,
169 otherwise returns false.
170*/
171bool QPlaceContent::operator==(const QPlaceContent &other) const
172{
173 // An invalid content object is only equal to another invalid content object
174 if (!d_ptr)
175 return !other.d_ptr;
176
177 if (type() != other.type())
178 return false;
179
180 return d_ptr->compare(other.d_ptr.constData());
181}
182
183/*!
184 Returns true if this content object is not equivalent to \a other,
185 otherwise returns false.
186*/
187bool QPlaceContent::operator!=(const QPlaceContent &other) const
188{
189 return !(*this == other);
190}
191
192/*!
193 Returns the list of data tags for which values are stored in this
194 content objects.
195*/
196QList<QPlaceContent::DataTag> QPlaceContent::dataTags() const
197{
198 Q_D(const QPlaceContent);
199 return d->data.keys();
200}
201
202/*!
203 Returns the value stored for the data \a tag, or an invalid QVariant
204 if there is no data for that tag.
205*/
206QVariant QPlaceContent::value(QPlaceContent::DataTag tag) const
207{
208 Q_D(const QPlaceContent);
209 return d->data.value(tag);
210}
211
212/*!
213 Sets the value stored for the data \a tag to \a value.
214*/
215void QPlaceContent::setValue(QPlaceContent::DataTag tag, const QVariant &value)
216{
217 detach();
218 Q_D(QPlaceContent);
219 d->data[tag] = value;
220}