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