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
qgeolocation.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 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
5#include "qgeolocation.h"
7
9
10QT_IMPL_METATYPE_EXTERN(QGeoLocation)
11
12QGeoLocationPrivate::QGeoLocationPrivate()
13 : QSharedData()
14{
15}
16
17QGeoLocationPrivate::QGeoLocationPrivate(const QGeoLocationPrivate &other)
18 : QSharedData()
19{
20 this->address = other.address;
21 this->coordinate = other.coordinate;
22 this->viewport = other.viewport;
23 this->extendedAttributes = other.extendedAttributes;
24}
25
26QGeoLocationPrivate::~QGeoLocationPrivate()
27{
28}
29
30bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const
31{
32 return (this->address == other.address
33 && this->coordinate == other.coordinate
34 && this->viewport == other.viewport
35 && this->extendedAttributes == other.extendedAttributes);
36
37}
38
39bool QGeoLocationPrivate::isEmpty() const
40{
41 return (address.isEmpty()
42 && !coordinate.isValid()
43 && viewport.isEmpty()
44 && extendedAttributes.isEmpty());
45}
46
47/*!
48 \class QGeoLocation
49 \inmodule QtPositioning
50 \ingroup QtPositioning-positioning
51 \ingroup QtLocation-places
52 \ingroup QtLocation-places-data
53 \since 5.2
54
55 \brief The QGeoLocation class represents basic information about a location.
56
57 A QGeoLocation consists of a coordinate and corresponding address, along with an optional
58 bounding shape, which is the recommended region to be displayed when viewing the location.
59*/
60
61/*!
62 Constructs an new location object.
63*/
64QGeoLocation::QGeoLocation()
65 : d(new QGeoLocationPrivate)
66{
67}
68
69/*!
70 Constructs a copy of \a other
71*/
72QGeoLocation::QGeoLocation(const QGeoLocation &other)
73 :d(other.d)
74{
75}
76
77/*!
78 \fn QGeoLocation::QGeoLocation(QGeoLocation &&other)
79 \since 6.2
80
81 Constructs a geo location object by moving from \a other.
82
83 \note The moved-from QGeoLocation object can only be destroyed or
84 assigned to. The effect of calling other functions than the destructor
85 or one of the assignment operators is undefined.
86*/
87
88/*!
89 Destroys the location object.
90*/
91QGeoLocation::~QGeoLocation()
92{
93}
94
95QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoLocationPrivate)
96
97/*!
98 Assigns \a other to this location and returns a reference to this location.
99*/
100QGeoLocation &QGeoLocation::operator =(const QGeoLocation &other)
101{
102 if (this == &other)
103 return *this;
104
105 d = other.d;
106 return *this;
107}
108
109/*!
110 \fn QGeoLocation &QGeoLocation::operator=(QGeoLocation &&other)
111 \since 6.2
112
113 Move-assings \a other to this location and returns a reference to this
114 location.
115
116 \note The moved-from QGeoLocation object can only be destroyed or
117 assigned to. The effect of calling other functions than the destructor
118 or one of the assignment operators is undefined.
119*/
120
121/*!
122 \fn bool QGeoLocation::operator==(const QGeoLocation &lhs, const QGeoLocation &rhs)
123
124 Returns \c true if the \a lhs location is equal to \a rhs, otherwise
125 returns \c false.
126*/
127
128/*!
129 \fn bool QGeoLocation::operator!=(const QGeoLocation &lhs, const QGeoLocation &rhs)
130
131 Returns \c true if the \a lhs location is not equal to \a rhs, otherwise
132 returns \c false.
133*/
134
135/*!
136 \fn void QGeoLocation::swap(QGeoLocation &other)
137 \since 6.2
138 \memberswap{location}
139*/
140
141/*!
142 Returns the address of the location.
143*/
144QGeoAddress QGeoLocation::address() const
145{
146 return d->address;
147}
148
149/*!
150 Sets the \a address of the location.
151*/
152void QGeoLocation::setAddress(const QGeoAddress &address)
153{
154 d->address = address;
155}
156
157/*!
158 Returns the coordinate of the location.
159*/
160QGeoCoordinate QGeoLocation::coordinate() const
161{
162 return d->coordinate;
163}
164
165/*!
166 Sets the \a coordinate of the location.
167*/
168void QGeoLocation::setCoordinate(const QGeoCoordinate &coordinate)
169{
170 d->coordinate = coordinate;
171}
172
173/*!
174 \since 6.2
175
176 Returns a bounding shape which represents the recommended region
177 to display when viewing this location.
178
179 For example, a building's location may have a region centered around the
180 building, but the region is large enough to show it's immediate surrounding
181 geographical context.
182
183 \note This method was introduced in Qt6 instead of boundingBox() method.
184 It returns a QGeoShape instead of a QGeoRectangle.
185 Use \l QGeoShape::boundingGeoRectangle() to obtain a bounding QGeoRectangle
186 for the shape.
187*/
188QGeoShape QGeoLocation::boundingShape() const
189{
190 return d->viewport;
191}
192
193/*!
194 \since 6.2
195
196 Sets the \a boundingShape of the location.
197*/
198void QGeoLocation::setBoundingShape(const QGeoShape &boundingShape)
199{
200 d->viewport = boundingShape;
201}
202
203/*!
204 Returns the extended attributes associated to this location.
205 Extended attributes are backend-dependent and can be location-dependent.
206
207 \since 5.13
208*/
209QVariantMap QGeoLocation::extendedAttributes() const
210{
211 return d->extendedAttributes;
212}
213
214/*!
215 Sets the extended attributes of the location with the
216 parameters specified in \a data.
217
218 \since 5.13
219*/
220void QGeoLocation::setExtendedAttributes(const QVariantMap &data)
221{
222 d->extendedAttributes = data;
223}
224
225/*!
226 Returns \c true if the location coordinate is \l {QGeoCoordinate::isValid}
227 {invalid}, and all the other location fields are empty. Otherwise returns
228 \c false.
229*/
230bool QGeoLocation::isEmpty() const
231{
232 return d->isEmpty();
233}
234
235bool QGeoLocation::equals(const QGeoLocation &lhs, const QGeoLocation &rhs)
236{
237 return (*(lhs.d.constData()) == *(rhs.d.constData()));
238}
239
240/*!
241 \relates QGeoLocation
242
243 Returns the hash value for the \a location, using \a seed for the
244 calculation.
245
246 \note The hash does not take extended attributes into account. This means
247 that two geo location objects that differ only in the extended attributes
248 will provide similar hashes.
249*/
250size_t qHash(const QGeoLocation &location, size_t seed) noexcept
251{
252 return qHashMulti(seed, location.coordinate(), location.boundingShape(), location.address());
253}
254
255QT_END_NAMESPACE
Combined button and popup list for selecting options.
constexpr size_t qHash(const QSize &s, size_t seed=0) noexcept
Definition qsize.h:192