1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtPositioning module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #include "qgeolocation.h"
41 #include "qgeolocation_p.h"
42 
43 QT_USE_NAMESPACE
44 
QGeoLocationPrivate()45 QGeoLocationPrivate::QGeoLocationPrivate()
46     : QSharedData()
47 {
48 }
49 
QGeoLocationPrivate(const QGeoLocationPrivate & other)50 QGeoLocationPrivate::QGeoLocationPrivate(const QGeoLocationPrivate &other)
51     : QSharedData()
52 {
53     this->address = other.address;
54     this->coordinate = other.coordinate;
55     this->viewport = other.viewport;
56     this->extendedAttributes = other.extendedAttributes;
57 }
58 
~QGeoLocationPrivate()59 QGeoLocationPrivate::~QGeoLocationPrivate()
60 {
61 }
62 
operator ==(const QGeoLocationPrivate & other) const63 bool QGeoLocationPrivate::operator==(const QGeoLocationPrivate &other) const
64 {
65     return  (this->address == other.address
66             && this->coordinate == other.coordinate
67             && this->viewport == other.viewport
68             && this->extendedAttributes == other.extendedAttributes);
69 
70 }
71 
isEmpty() const72 bool QGeoLocationPrivate::isEmpty() const
73 {
74     return (address.isEmpty()
75             && !coordinate.isValid()
76             && viewport.isEmpty()
77             && extendedAttributes.isEmpty());
78 }
79 
80 /*!
81     \class QGeoLocation
82     \inmodule QtPositioning
83     \ingroup QtPositioning-positioning
84     \ingroup QtLocation-places
85     \ingroup QtLocation-places-data
86     \since 5.2
87 
88     \brief The QGeoLocation class represents basic information about a location.
89 
90     A QGeoLocation consists of a coordinate and corresponding address, along with an optional
91     bounding box which is the recommended region to be displayed when viewing the location.
92 */
93 
94 /*!
95     \fn bool QGeoLocation::operator!=(const QGeoLocation &other) const
96 
97     Returns true if this location is not equal to \a other, otherwise returns false.
98 */
99 
100 /*!
101     Constructs an new location object.
102 */
QGeoLocation()103 QGeoLocation::QGeoLocation()
104     : d(new QGeoLocationPrivate)
105 {
106 }
107 
108 /*!
109     Constructs a copy of \a other
110 */
QGeoLocation(const QGeoLocation & other)111 QGeoLocation::QGeoLocation(const QGeoLocation &other)
112     :d(other.d)
113 {
114 }
115 
116 /*!
117     Destroys the location object.
118 */
~QGeoLocation()119 QGeoLocation::~QGeoLocation()
120 {
121 }
122 
123 /*!
124     Assigns \a other to this location and returns a reference to this location.
125 */
operator =(const QGeoLocation & other)126 QGeoLocation &QGeoLocation::operator =(const QGeoLocation &other)
127 {
128     if (this == &other)
129         return *this;
130 
131     d = other.d;
132     return *this;
133 }
134 
135 /*!
136     Returns true if this location is equal to \a other,
137     otherwise returns false.
138 */
operator ==(const QGeoLocation & other) const139 bool QGeoLocation::operator==(const QGeoLocation &other) const
140 {
141     return (*(d.constData()) == *(other.d.constData()));
142 }
143 
144 /*!
145     Returns the address of the location.
146 */
address() const147 QGeoAddress QGeoLocation::address() const
148 {
149     return d->address;
150 }
151 
152 /*!
153     Sets the \a address of the location.
154 */
setAddress(const QGeoAddress & address)155 void QGeoLocation::setAddress(const QGeoAddress &address)
156 {
157     d->address = address;
158 }
159 
160 /*!
161     Returns the coordinate of the location.
162 */
coordinate() const163 QGeoCoordinate QGeoLocation::coordinate() const
164 {
165     return d->coordinate;
166 }
167 
168 /*!
169     Sets the \a coordinate of the location.
170 */
setCoordinate(const QGeoCoordinate & coordinate)171 void QGeoLocation::setCoordinate(const QGeoCoordinate &coordinate)
172 {
173     d->coordinate = coordinate;
174 }
175 
176 /*!
177     Returns a bounding box which represents the recommended region
178     to display when viewing this location.
179 
180     For example, a building's location may have a region centered around the building,
181     but the region is large enough to show it's immediate surrounding geographical
182     context.
183 */
boundingBox() const184 QGeoRectangle QGeoLocation::boundingBox() const
185 {
186     return d->viewport;
187 }
188 
189 /*!
190     Sets the \a boundingBox of the location.
191 */
setBoundingBox(const QGeoRectangle & boundingBox)192 void QGeoLocation::setBoundingBox(const QGeoRectangle &boundingBox)
193 {
194     d->viewport = boundingBox;
195 }
196 
197 /*!
198     Returns the extended attributes associated to this location.
199     Extended attributes are backend-dependent and can be location-dependent.
200 
201     \since 5.13
202 */
extendedAttributes() const203 QVariantMap QGeoLocation::extendedAttributes() const
204 {
205     return d->extendedAttributes;
206 }
207 
208 /*!
209     Sets the extended attributes of the location with the
210     parameters specified in \a data.
211 
212     \since 5.13
213 */
setExtendedAttributes(const QVariantMap & data)214 void QGeoLocation::setExtendedAttributes(const QVariantMap &data)
215 {
216     d->extendedAttributes = data;
217 }
218 
219 /*!
220     Returns true if all fields of the location are 0; otherwise returns false.
221 */
isEmpty() const222 bool QGeoLocation::isEmpty() const
223 {
224     return d->isEmpty();
225 }
226