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