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
qplaceattribute.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
10QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QPlaceAttributePrivate)
11
12bool QPlaceAttributePrivate::operator== (const QPlaceAttributePrivate &other) const
13{
14 return label == other.label
15 && text == other.text;
16}
17
18bool QPlaceAttributePrivate::isEmpty() const
19{
20 return label.isEmpty()
21 && text.isEmpty();
22}
23
24
25/*!
26 \class QPlaceAttribute
27 \inmodule QtLocation
28 \ingroup QtLocation-places
29 \ingroup QtLocation-places-data
30 \since 5.6
31
32 \brief The QPlaceAttribute class represents generic attribute information about a place.
33
34 A QPlaceAttribute instance stores an additional piece of information about a place that is not
35 otherwise exposed through the QPlace class. A QPlaceAttribute encapsulates a
36 localized label which describes the attribute and rich text string representing the attribute's value.
37 Generally, both are intended to be displayed to the end-user as is.
38
39 Some plugins may not support attributes at all, others may only support a
40 certain set, others still may support a dynamically changing set of attributes
41 over time or even allow attributes to be arbitrarily defined by the client
42 application. The attributes could also vary on a place by place basis,
43 for example one place may have opening hours while another does not.
44 Consult the \l {Plugin References and Parameters}{plugin
45 references} for details.
46
47 \section2 Attribute Types
48 The QPlaceAttribute class defines some constant strings which characterize standard \e {attribute types}.
49 \list
50 \li QPlaceAttribute::OpeningHours
51 \li QPlaceAttribute::Payment
52 \li QPlaceAttribute::Provider
53 \endlist
54
55 There is a class of attribute types of the format x_id_<provider> for example x_id_here.
56 This class of attributes is a set of alternative identifiers of the place, from the specified provider's
57 perspective.
58
59 The above types are used to access and modify attributes in QPlace via:
60 \list
61 \li QPlace::extendedAttribute()
62 \li QPlace::setExtendedAttribute()
63 \li QPlace::removeExtendedAttribute()
64 \li QPlace::removeExtendedAttribute()
65 \endlist
66
67 The \e {attribute type} is a string type so that providers are able to introduce
68 new attributes as necessary. Custom attribute types should always be prefixed
69 by a qualifier in order to avoid conflicts.
70
71 \section3 User Readable and Non-User Readable Attributes
72 Some attributes may not be intended to be readable by end users, the label field
73 of such attributes are empty to indicate this fact.
74*/
75
76/*!
77 \qmltype ExtendedAttributes
78 \nativetype QQmlPropertyMap
79 \inqmlmodule QtLocation
80 \ingroup qml-QtLocation5-places
81 \ingroup qml-QtLocation5-places-data
82 \since QtLocation 5.5
83
84 \brief The ExtendedAttributes type holds additional data about a \l Place.
85
86 The ExtendedAttributes type is a map of \l {placeAttribute}{placeAttributes}. To access
87 attributes in the map use the \l keys() method to get the list of keys stored in the map and
88 use the \c {[]} operator to access the \l placeAttribute items.
89
90 The following are standard keys that are defined by the API. \l Plugin
91 implementations are free to define additional keys. Custom keys should
92 be qualified by a unique prefix to avoid clashes.
93 \table
94 \header
95 \li key
96 \li description
97 \row
98 \li openingHours
99 \li The trading hours of the place
100 \row
101 \li payment
102 \li The types of payment the place accepts, for example visa, mastercard.
103 \row
104 \li x_provider
105 \li The name of the provider that a place is sourced from
106 \row
107 \li x_id_<provider> (for example x_id_here)
108 \li An alternative identifier which identifies the place from the
109 perspective of the specified provider.
110 \endtable
111
112 Some plugins may not support attributes at all, others may only support a
113 certain set, others still may support a dynamically changing set of attributes
114 over time or even allow attributes to be arbitrarily defined by the client
115 application. The attributes could also vary on a place by place basis,
116 for example one place may have opening hours while another does not.
117 Consult the \l {Plugin References and Parameters}{plugin
118 references} for details.
119
120 Some attributes may not be intended to be readable by end users, the label field
121 of such attributes is empty to indicate this fact.
122
123 \note ExtendedAttributes instances are only ever used in the context of \l {Place}s. It is not
124 possible to create an ExtendedAttributes instance directly or re-assign a \l {Place}'s
125 ExtendedAttributes property. Modification of ExtendedAttributes can only be accomplished
126 via Javascript.
127
128 The following example shows how to access all \l {placeAttribute}{placeAttributes} and print
129 them to the console:
130
131 \snippet declarative/maps.qml QtLocation import
132 \codeline
133 \snippet declarative/places.qml ExtendedAttributes read
134
135 The following example shows how to assign and modify an attribute:
136 \snippet declarative/places.qml ExtendedAttributes write
137
138 \sa placeAttribute, QQmlPropertyMap
139*/
140
141/*!
142 \qmlmethod variant ExtendedAttributes::keys()
143
144 Returns an array of place attribute keys currently stored in the map.
145*/
146
147/*!
148 \qmlsignal void ExtendedAttributes::valueChanged(string key, variant value)
149
150 This signal is emitted when the set of attributes changes. \a key is the key
151 corresponding to the \a value that was changed.
152
153 The corresponding handler is \c onValueChanged.
154*/
155
156/*!
157 \qmlvaluetype placeAttribute
158 \inqmlmodule QtLocation
159 \ingroup qml-QtLocation5-places
160 \ingroup qml-QtLocation5-places-data
161 \since QtLocation 5.5
162
163 \brief The placeAttribute type holds generic place attribute information.
164
165 A place attribute stores an additional piece of information about a \l Place that is not
166 otherwise exposed through the \l Place type. A placeAttribute is a textual piece of data,
167 accessible through the \l {placeAttribute::}{text} property, and a \l {placeAttribute::}{label}.
168 Both the l {placeAttribute::}{text} and \l {placeAttribute::}{label} properties are intended
169 to be displayed to the user. placeAttributes are stored in an \l ExtendedAttributes map with
170 a unique key.
171
172 The following example shows how to display all attributes in a list:
173
174 \snippet declarative/places.qml QtQuick import
175 \snippet declarative/maps.qml QtLocation import
176 \codeline
177 \snippet declarative/places.qml ExtendedAttributes
178
179 The following example shows how to assign and modify an attribute:
180 \snippet declarative/places.qml ExtendedAttributes write
181*/
182
183/*!
184 \variable QPlaceAttribute::OpeningHours
185 Specifies the opening hours.
186*/
187const QString QPlaceAttribute::OpeningHours(QLatin1String("openingHours"));
188
189/*!
190 \variable QPlaceAttribute::Payment
191 The constant to specify an attribute that defines the methods of payment.
192*/
193const QString QPlaceAttribute::Payment(QLatin1String("payment"));
194
195/*!
196 \variable QPlaceAttribute::Provider
197 The constant to specify an attribute that defines which
198 provider the place came from.
199*/
200const QString QPlaceAttribute::Provider(QLatin1String("x_provider"));
201
202/*!
203 Constructs an attribute.
204*/
205QPlaceAttribute::QPlaceAttribute()
206 : d_ptr(new QPlaceAttributePrivate)
207{
208}
209
210/*!
211 Destroys the attribute.
212*/
213QPlaceAttribute::~QPlaceAttribute() = default;
214
215/*!
216 Creates a copy of \a other.
217*/
218QPlaceAttribute::QPlaceAttribute(const QPlaceAttribute &other) noexcept = default;
219
220/*!
221 Assigns \a other to this attribute and returns a reference to this
222 attribute.
223*/
224QPlaceAttribute &QPlaceAttribute::operator=(const QPlaceAttribute &other) noexcept
225{
226 if (this == &other)
227 return *this;
228
229 d_ptr = other.d_ptr;
230 return *this;
231}
232
233/*!
234 \fn bool QPlaceAttribute::operator==(const QPlaceAttribute &lhs, const QPlaceAttribute &rhs) noexcept
235
236 Returns true if \a lhs is equal to \a rhs, otherwise
237 returns false.
238*/
239
240/*!
241 \fn bool QPlaceAttribute::operator!=(const QPlaceAttribute &lhs, const QPlaceAttribute &rhs) noexcept
242
243 Returns true if \a lhs is not equal to \a rhs,
244 otherwise returns false.
245*/
246
247bool QPlaceAttribute::isEqual(const QPlaceAttribute &other) const noexcept
248{
249 if (d_ptr == other.d_ptr)
250 return true;
251 return ( *(d_ptr.constData()) == *(other.d_ptr.constData()));
252}
253
254/*!
255 \qmlproperty string placeAttribute::label
256
257 This property holds the attribute label which is a user visible string
258 describing the attribute.
259*/
260
261/*!
262 \property QPlaceAttribute::label
263 \brief a localized label describing the attribute.
264*/
265QString QPlaceAttribute::label() const
266{
267 return d_ptr->label;
268}
269
270void QPlaceAttribute::setLabel(const QString &label)
271{
272 d_ptr->label = label;
273}
274
275/*!
276 \qmlproperty string placeAttribute::text
277
278 This property holds the attribute text which can be used to show additional information about the place.
279*/
280
281/*!
282 \property QPlaceAttribute::text
283 \brief a piece of rich text representing the attribute value.
284*/
285QString QPlaceAttribute::text() const
286{
287 return d_ptr->text;
288}
289
290void QPlaceAttribute::setText(const QString &text)
291{
292 d_ptr->text = text;
293}
294
295/*!
296 Returns a boolean indicating whether the all the fields of the place attribute
297 are empty or not.
298*/
299bool QPlaceAttribute::isEmpty() const
300{
301 return d_ptr->isEmpty();
302}
303
304#include "moc_qplaceattribute.cpp"