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
qdeclarativegeolocation.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
5
7
8/*!
9 \qmltype Location
10 \inqmlmodule QtPositioning
11 \since 5.2
12
13 \brief The Location type holds location data.
14
15 Location types represent a geographic "location", in a human sense. This
16 consists of a specific \l {coordinate}, an \l {address} and a
17 \l {boundingShape}{bounding shape}.
18 The \l {boundingShape}{bounding shape} represents the recommended region
19 to display when viewing this location.
20
21 The Location type is most commonly seen as the contents of a search
22 model such as the GeocodeModel. When a GeocodeModel returns the list of
23 locations found for a given query, it represents these as Location objects.
24
25 \section2 Example Usage
26
27 The following example shows a simple Location object being declared:
28
29 \code
30 Location {
31 coordinate {
32 latitude: -27.3
33 longitude: 153.1
34 }
35 address: Address {
36 ...
37 }
38 }
39 \endcode
40*/
41
42/*!
43 \qmlproperty VariantMap QDeclarativeGeoLocation::extendedAttributes
44
45 This property holds the extended attributes for this Location.
46 Extended attributes are backend-dependent and can be location-dependent.
47
48 \since 5.13
49*/
50
51QDeclarativeGeoLocation::QDeclarativeGeoLocation(QObject *parent)
52: QObject(parent)
53
54{
55 setLocationInternal(QGeoLocation());
56}
57
58QDeclarativeGeoLocation::QDeclarativeGeoLocation(const QGeoLocation &src, QObject *parent)
59: QObject(parent)
60{
61 setLocationInternal(src);
62}
63
64QDeclarativeGeoLocation::~QDeclarativeGeoLocation()
65{
66}
67
68/*!
69 \internal
70
71 This method is supposed to be used in the constructors, when we know that
72 the properties have no bindings, and we do not want to introduce any.
73*/
74void QDeclarativeGeoLocation::setLocationInternal(const QGeoLocation &src)
75{
76 m_address.setValueBypassingBindings(new QDeclarativeGeoAddress(src.address(), this));
77 m_coordinate.setValueBypassingBindings(src.coordinate());
78 m_boundingShape.setValueBypassingBindings(src.boundingShape());
79 m_extendedAttributes.setValueBypassingBindings(src.extendedAttributes());
80}
81
82/*!
83 \qmlproperty QGeoLocation QtPositioning::Location::location
84
85 For details on how to use this property to interface between C++ and QML see
86 "\l {Location - QGeoLocation} {Interfaces between C++ and QML Code}".
87
88 \note This property updates the whole geo location information, so using it
89 will result in breaking of all the bindings for all other properties.
90*/
91void QDeclarativeGeoLocation::setLocation(const QGeoLocation &src)
92{
93 if (m_address && m_address->parent() == this) {
94 m_address->setAddress(src.address());
95 } else if (!m_address || m_address->parent() != this) {
96 m_address.setValue(new QDeclarativeGeoAddress(src.address(), this));
97 m_address.notify();
98 }
99
100 setCoordinate(src.coordinate());
101 setBoundingShape(src.boundingShape());
102 setExtendedAttributes(src.extendedAttributes());
103}
104
105QGeoLocation QDeclarativeGeoLocation::location() const
106{
107 QGeoLocation retValue;
108 retValue.setAddress(m_address ? m_address->address() : QGeoAddress());
109 retValue.setCoordinate(m_coordinate);
110 retValue.setBoundingShape(m_boundingShape);
111 retValue.setExtendedAttributes(m_extendedAttributes);
112 return retValue;
113}
114
115/*!
116 \qmlproperty Address QtPositioning::Location::address
117
118 This property holds the address of the location which can be use to retrieve address details of the location.
119*/
120void QDeclarativeGeoLocation::setAddress(QDeclarativeGeoAddress *address)
121{
122 m_address.removeBindingUnlessInWrapper();
123
124 const QDeclarativeGeoAddress *oldAddress = m_address.valueBypassingBindings();
125 if (oldAddress == address)
126 return;
127
128 // implicitly deleting m_address.value() will force the QML bindings to
129 // be reevaluated by the QML engine. So we defer the deletion of the old
130 // address until a new value is assigned to the m_address.
131 m_address.setValueBypassingBindings(address);
132 m_address.notify();
133 if (oldAddress && (oldAddress->parent() == this))
134 delete oldAddress;
135}
136
137QBindable<QDeclarativeGeoAddress *> QDeclarativeGeoLocation::bindableAddress()
138{
139 return QBindable<QDeclarativeGeoAddress *>(&m_address);
140}
141
142QDeclarativeGeoAddress *QDeclarativeGeoLocation::address() const
143{
144 return m_address;
145}
146
147/*!
148 \qmlproperty coordinate QtPositioning::Location::coordinate
149
150 This property holds the exact geographical coordinate of the location which can be used to retrieve the latitude, longitude and altitude of the location.
151
152 \note this property's changed() signal is currently emitted only if the
153 whole object changes, not if only the contents of the object change.
154*/
155void QDeclarativeGeoLocation::setCoordinate(const QGeoCoordinate coordinate)
156{
157 m_coordinate = coordinate;
158}
159
160QBindable<QGeoCoordinate> QDeclarativeGeoLocation::bindableCoordinate()
161{
162 return QBindable<QGeoCoordinate>(&m_coordinate);
163}
164
165QGeoCoordinate QDeclarativeGeoLocation::coordinate() const
166{
167 return m_coordinate;
168}
169
170/*!
171 \since QtPositioning 6.2
172
173 \qmlproperty geoshape QtPositioning::Location::boundingShape
174
175 This property holds the recommended region to use when displaying the location.
176 For example, a building's location may have a region centered around the building,
177 but the region is large enough to show it's immediate surrounding geographical
178 context.
179
180 \note This property's changed() signal is currently emitted only if the
181 whole object changes, not if only the contents of the object change.
182
183 \note This property was introduced in Qt6 instead of boundingBox property.
184 It returns a \l geoshape instead of a \l georectangle.
185 Use \l QGeoShape::boundingGeoRectangle() to obtain a bounding
186 \l georectangle for the shape.
187
188 If you need to convert the returned shape to a specific type, use the
189 \c type property of \l geoshape together with convenience
190 methods from \l [QML]{QtPositioning} like
191 \l {QtPositioning::shapeToRectangle}{QtPositioning.shapeToRectangle()}.
192*/
193void QDeclarativeGeoLocation::setBoundingShape(const QGeoShape &boundingShape)
194{
195 m_boundingShape = boundingShape;
196}
197
198QBindable<QGeoShape> QDeclarativeGeoLocation::bindableBoundingShape()
199{
200 return QBindable<QGeoShape>(&m_boundingShape);
201}
202
203QVariantMap QDeclarativeGeoLocation::extendedAttributes() const
204{
205 return m_extendedAttributes;
206}
207
208void QDeclarativeGeoLocation::setExtendedAttributes(const QVariantMap &attributes)
209{
210 m_extendedAttributes = attributes;
211}
212
213QBindable<QVariantMap> QDeclarativeGeoLocation::bindableExtendedAttributes()
214{
215 return QBindable<QVariantMap>(&m_extendedAttributes);
216}
217
218QGeoShape QDeclarativeGeoLocation::boundingShape() const
219{
220 return m_boundingShape;
221}
222
223QT_END_NAMESPACE
224
225#include "moc_qdeclarativegeolocation_p.cpp"
Combined button and popup list for selecting options.