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