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
qgeocameracapabilities.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
5
6#include <QSharedData>
7#include <cmath>
8
9static double zoomLevelTo256(double zoomLevelForTileSize, double tileSize)
10{
11 return std::log(std::pow(2.0, zoomLevelForTileSize) * tileSize / 256.0) * (1.0 / std::log(2.0));
12}
13
14QT_BEGIN_NAMESPACE
15
16class QGeoCameraCapabilitiesPrivate : public QSharedData
17{
18public:
19 bool operator==(const QGeoCameraCapabilitiesPrivate &rhs) const noexcept;
20
21 bool supportsBearing_ = false;
22 bool supportsRolling_ = false;
23 bool supportsTilting_ = false;
24
25 // this is mutable so that it can be set from accessor functions that are const
26 // TODO: remove the mutable here
27 mutable bool valid_ = false;
28
29 double minZoom_ = 0.0;
30 double maxZoom_ = 0.0;
31 double minTilt_ = 0.0;
32 double maxTilt_ = 0.0;
33 int tileSize_ = 256;
34 double minimumFieldOfView_ = 45.0; // Defaulting to a fixed FOV of 45 degrees.
35 double maximumFieldOfView_ = 45.0; // Too large FOVs cause the loading of too many tiles.
36 bool overzoomEnabled_ = false;
37};
38
39QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoCameraCapabilitiesPrivate)
40
41bool QGeoCameraCapabilitiesPrivate::operator==(const QGeoCameraCapabilitiesPrivate &rhs) const noexcept
42{
43 return ((supportsBearing_ == rhs.supportsBearing_)
44 && (supportsRolling_ == rhs.supportsRolling_)
45 && (supportsTilting_ == rhs.supportsTilting_)
46 && (valid_ == rhs.valid_)
47 && (minZoom_ == rhs.minZoom_)
48 && (maxZoom_ == rhs.maxZoom_)
49 && (minTilt_ == rhs.minTilt_)
50 && (maxTilt_ == rhs.maxTilt_)
51 && (tileSize_ == rhs.tileSize_)
52 && (minimumFieldOfView_ == rhs.minimumFieldOfView_)
53 && (maximumFieldOfView_ == rhs.maximumFieldOfView_)
54 && (overzoomEnabled_ == rhs.overzoomEnabled_));
55}
56
57/*!
58 \class QGeoCameraCapabilities
59 \inmodule QtLocation
60 \ingroup QtLocation-impl
61 \since 5.6
62 \internal
63
64 \brief The QGeoCameraCapabilities class describes the limitations on camera settings imposed by a mapping plugin.
65
66 Different mapping plugins will support different ranges of zoom levels, and not all mapping plugins will
67 be able to support, bearing, tilting and rolling of the camera.
68
69 This class describes what the plugin supports, and is used to restrict changes to the camera information
70 associated with a \l QGeoMap such that the camera information stays within these limits.
71*/
72
73/*!
74 \qmlvaluetype cameraCapabilities
75 \inqmlmodule QtLocation
76 \ingroup qml-QtLocation5-maps
77 \since QtLocation 5.10
78
79 \brief The cameraCapabilities type holds information about the camera capabilities for a specific map type.
80
81 This includes the map minimum and maximum zoom level, minimum and maximum tilt angle and
82 minimum and maximum field of view.
83*/
84
85/*!
86 Constructs a camera capabilities object.
87*/
88QGeoCameraCapabilities::QGeoCameraCapabilities()
89 : d(new QGeoCameraCapabilitiesPrivate()) {}
90
91/*!
92 Constructs a camera capabilities object from the contents of \a other.
93*/
94QGeoCameraCapabilities::QGeoCameraCapabilities(const QGeoCameraCapabilities &other) noexcept = default;
95
96/*!
97 Destroys this camera capabilities object.
98*/
99QGeoCameraCapabilities::~QGeoCameraCapabilities() = default;
100
101/*!
102 Assigns the contents of \a other to this camera capabilities object and
103 returns a reference to this camera capabilities object.
104*/
105QGeoCameraCapabilities &QGeoCameraCapabilities::operator=(const QGeoCameraCapabilities &other) noexcept
106{
107 if (this == &other)
108 return *this;
109
110 d = other.d;
111 return *this;
112}
113
114bool QGeoCameraCapabilities::isEqual(const QGeoCameraCapabilities &other) const
115{
116 return (*(d.constData()) == *(other.d.constData()));
117}
118
119void QGeoCameraCapabilities::setTileSize(int tileSize)
120{
121 if (tileSize < 1)
122 return;
123 d->tileSize_ = tileSize;
124}
125
126int QGeoCameraCapabilities::tileSize() const
127{
128 return d->tileSize_;
129}
130
131/*!
132 Returns whether this instance of the class is considered "valid". To be
133 valid, the instance must have had at least one capability set (to either
134 true or false) using a set method, or copied from another instance
135 (such as by the assignment operator).
136*/
137bool QGeoCameraCapabilities::isValid() const
138{
139 return d->valid_;
140}
141
142/*!
143 \qmlproperty real cameraCapabilities::minimumZoomLevel
144
145 This read-only property holds the minimum available zoom level with this map type.
146*/
147
148/*!
149 \property QGeoCameraCapabilities::minimumZoomLevel
150 \brief the minimum zoom level supported by the associated plugin.
151
152 Larger values of the zoom level correspond to more detailed views of the
153 map.
154*/
155void QGeoCameraCapabilities::setMinimumZoomLevel(double minimumZoomLevel)
156{
157 d->minZoom_ = minimumZoomLevel;
158 d->valid_ = true;
159}
160
161double QGeoCameraCapabilities::minimumZoomLevel() const
162{
163 return d->minZoom_;
164}
165
166double QGeoCameraCapabilities::minimumZoomLevelAt256() const
167{
168 if (d->tileSize_ == 256)
169 return d->minZoom_;
170 return qMax<double>(0, zoomLevelTo256(d->minZoom_, d->tileSize_));
171}
172
173/*!
174 \qmlproperty real cameraCapabilities::maximumZoomLevel
175
176 This read-only property holds the maximum available zoom level with this map type.
177*/
178
179/*!
180 \property QGeoCameraCapabilities::maximumZoomLevel
181 \brief the maximum zoom level supported by the associated plugin.
182
183 Larger values of the zoom level correspond to more detailed views of the
184 map.
185*/
186void QGeoCameraCapabilities::setMaximumZoomLevel(double maximumZoomLevel)
187{
188 d->maxZoom_ = maximumZoomLevel;
189 d->valid_ = true;
190}
191
192double QGeoCameraCapabilities::maximumZoomLevel() const
193{
194 return d->maxZoom_;
195}
196
197double QGeoCameraCapabilities::maximumZoomLevelAt256() const
198{
199 if (d->tileSize_ == 256)
200 return d->maxZoom_;
201 return qMax<double>(0, zoomLevelTo256(d->maxZoom_, d->tileSize_));
202}
203
204/*!
205 Sets whether the associated plugin can render a map when the camera
206 has an arbitrary bearing to \a supportsBearing.
207*/
208void QGeoCameraCapabilities::setSupportsBearing(bool supportsBearing)
209{
210 d->supportsBearing_ = supportsBearing;
211 d->valid_ = true;
212}
213
214/*!
215 Returns whether the associated plugin can render a map when the camera
216 has an arbitrary bearing.
217*/
218bool QGeoCameraCapabilities::supportsBearing() const
219{
220 return d->supportsBearing_;
221}
222
223/*!
224 Sets whether the associated plugin can render a map when the
225 camera is rolled to \a supportsRolling.
226*/
227void QGeoCameraCapabilities::setSupportsRolling(bool supportsRolling)
228{
229 d->supportsRolling_ = supportsRolling;
230 d->valid_ = true;
231}
232
233/*!
234 Returns whether the associated plugin can render a map when the
235 camera is rolled.
236*/
237bool QGeoCameraCapabilities::supportsRolling() const
238{
239 return d->supportsRolling_;
240}
241
242/*!
243 Sets whether the associated plugin can render a map when the
244 camera is tilted to \a supportsTilting.
245*/
246void QGeoCameraCapabilities::setSupportsTilting(bool supportsTilting)
247{
248 d->supportsTilting_ = supportsTilting;
249 d->valid_ = true;
250}
251
252/*!
253 Returns whether the associated plugin can render a map when the
254 camera is tilted.
255*/
256bool QGeoCameraCapabilities::supportsTilting() const
257{
258 return d->supportsTilting_;
259}
260
261/*!
262 \qmlproperty real cameraCapabilities::minimumTilt
263
264 This read-only property holds the minimum available tilt with this map type.
265*/
266
267/*!
268 \property QGeoCameraCapabilities::minimumTilt
269 \brief the minimum tilt supported by the associated plugin.
270
271 The value is in degrees where 0 is equivalent to 90 degrees between
272 the line of view and earth's surface, that is, looking straight down to earth.
273*/
274void QGeoCameraCapabilities::setMinimumTilt(double minimumTilt)
275{
276 d->minTilt_ = minimumTilt;
277 d->valid_ = true;
278}
279
280double QGeoCameraCapabilities::minimumTilt() const
281{
282 return d->minTilt_;
283}
284
285/*!
286 \qmlproperty real cameraCapabilities::maximumTilt
287
288 This read-only property holds the maximum available tilt with this map type.
289*/
290
291/*!
292 \property QGeoCameraCapabilities::maximumTilt
293 \brief the maximum tilt supported by the associated plugin.
294
295 The value is in degrees where 0 is equivalent to 90 degrees between
296 the line of view and earth's surface, that is, looking straight down to earth.
297*/
298void QGeoCameraCapabilities::setMaximumTilt(double maximumTilt)
299{
300 d->maxTilt_ = maximumTilt;
301 d->valid_ = true;
302}
303
304double QGeoCameraCapabilities::maximumTilt() const
305{
306 return d->maxTilt_;
307}
308
309/*!
310 \qmlproperty real cameraCapabilities::minimumFieldOfView
311
312 This read-only property holds the minimum available field of view with this map type.
313*/
314
315/*!
316 \property QGeoCameraCapabilities::minimumFieldOfView
317 \brief the minimum field of view supported by the associated plugin.
318
319 The value is in degrees and is clamped against a [1, 179] range.
320
321 \since 5.9
322*/
323void QGeoCameraCapabilities::setMinimumFieldOfView(double minimumFieldOfView)
324{
325 d->minimumFieldOfView_ = qBound(1.0, minimumFieldOfView, 179.0);
326 d->valid_ = true;
327}
328
329double QGeoCameraCapabilities::minimumFieldOfView() const
330{
331 return d->minimumFieldOfView_;
332}
333
334/*!
335 \qmlproperty real cameraCapabilities::maximumFieldOfView
336
337 This read-only property holds the maximum available field of view with this map type.
338*/
339
340/*!
341 \property QGeoCameraCapabilities::maximumFieldOfView
342 \brief the maximum field of view supported by the associated plugin.
343
344 The value is in degrees and is clamped against a [1, 179] range.
345
346 \since 5.9
347*/
348void QGeoCameraCapabilities::setMaximumFieldOfView(double maximumFieldOfView)
349{
350 d->maximumFieldOfView_ = qBound(1.0, maximumFieldOfView, 179.0);
351 d->valid_ = true;
352}
353
354double QGeoCameraCapabilities::maximumFieldOfView() const
355{
356 return d->maximumFieldOfView_;
357}
358
359/*!
360 Sets whether overzooming is supported by the associated plugin.
361
362 Overzooming means that zoom levels outside the [minimumZL, maximumZL] range can be set,
363 and if tiles aren't available for those zoom levels, either tiles from other zoom levels
364 will be used, or nothing will be shown.
365
366 Set this value to false if the plugin is not capable of that. For example if using
367 a mapping engine that always clamp the zoomLevel value, which may cause misalignment in case
368 of stacked map elements.
369
370 \since 5.9
371*/
372void QGeoCameraCapabilities::setOverzoomEnabled(bool overzoomEnabled)
373{
374 d->overzoomEnabled_ = overzoomEnabled;
375 d->valid_ = true;
376}
377
378/*!
379 Returns whether overzooming is supported by the associated plugin.
380
381 \since 5.9
382*/
383bool QGeoCameraCapabilities::overzoomEnabled() const
384{
385 return d->overzoomEnabled_;
386}
387
388
389QT_END_NAMESPACE
390
391#include "moc_qgeocameracapabilities_p.cpp"
static double zoomLevelTo256(double zoomLevelForTileSize, double tileSize)