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
qgeocameradata.cpp
Go to the documentation of this file.
1// Copyright (C) 2015 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 <QtCore/QVariant>
7#include <QtCore/QVariantAnimation>
8
9#include <QtPositioning/private/qgeocoordinate_p.h>
10#include <QtPositioning/private/qwebmercator_p.h>
11
12QT_BEGIN_NAMESPACE
13
14class QGeoCameraDataPrivate : public QSharedData
15{
16public:
17 bool operator==(const QGeoCameraDataPrivate &rhs) const noexcept;
18
19 QGeoCoordinate m_center = {0, 0};
20 double m_bearing = 0.0;
21 double m_tilt = 0.0;
22 double m_roll = 0.0;
23 double m_fieldOfView = 45.0;
24 double m_zoomLevel = 0.0;
25};
26
27QT_DEFINE_QSDP_SPECIALIZATION_DTOR(QGeoCameraDataPrivate)
28
29bool QGeoCameraDataPrivate::operator==(const QGeoCameraDataPrivate &rhs) const noexcept
30{
31 return ((m_center == rhs.m_center)
32 && (m_bearing == rhs.m_bearing)
33 && (m_tilt == rhs.m_tilt)
34 && (m_roll == rhs.m_roll)
35 && (m_fieldOfView == rhs.m_fieldOfView)
36 && (m_zoomLevel == rhs.m_zoomLevel));
37}
38
39QVariant cameraInterpolator(const QGeoCameraData &start,
40 const QGeoCameraData &end,
41 qreal progress)
42{
43 QGeoCameraData result = start;
44 QGeoCoordinate from = start.center();
45 QGeoCoordinate to = end.center();
46
47 if (from == to) {
48 if (progress < 0.5) {
49 result.setCenter(from);
50 } else {
51 result.setCenter(to);
52 }
53 }
54 else {
55 QGeoCoordinate coordinateResult = QWebMercator::coordinateInterpolation(from, to, progress);
56 result.setCenter(coordinateResult);
57 }
58
59 double sf = 1.0 - progress;
60 double ef = progress;
61
62 result.setBearing(sf * start.bearing() + ef * end.bearing());
63 result.setTilt(sf * start.tilt() + ef * end.tilt());
64 result.setRoll(sf * start.roll() + ef * end.roll());
65 result.setFieldOfView(sf * start.fieldOfView() + ef * end.fieldOfView());
66 result.setZoomLevel(sf * start.zoomLevel() + ef * end.zoomLevel());
67
68 return QVariant::fromValue(result);
69}
70
71QGeoCameraData::QGeoCameraData()
72 : d(new QGeoCameraDataPrivate())
73{
74 qRegisterMetaType<QGeoCameraData>();
75 qRegisterAnimationInterpolator<QGeoCameraData>(cameraInterpolator);
76}
77
78QGeoCameraData::QGeoCameraData(const QGeoCameraData &other) noexcept = default;
79
80QGeoCameraData::~QGeoCameraData() = default;
81
82QGeoCameraData &QGeoCameraData::operator=(const QGeoCameraData &other) noexcept
83{
84 if (this == &other)
85 return *this;
86
87 d = other.d;
88 return *this;
89}
90
91bool QGeoCameraData::isEqual(const QGeoCameraData &other) const
92{
93 return (*(d.constData()) == *(other.d.constData()));
94}
95
96void QGeoCameraData::setCenter(const QGeoCoordinate &center)
97{
98 d->m_center = center;
99}
100
101QGeoCoordinate QGeoCameraData::center() const
102{
103 return d->m_center;
104}
105
106void QGeoCameraData::setBearing(double bearing)
107{
108 d->m_bearing = bearing;
109}
110
111double QGeoCameraData::bearing() const
112{
113 return d->m_bearing;
114}
115
116void QGeoCameraData::setTilt(double tilt)
117{
118 d->m_tilt = tilt;
119}
120
121double QGeoCameraData::tilt() const
122{
123 return d->m_tilt;
124}
125
126void QGeoCameraData::setRoll(double roll)
127{
128 d->m_roll = roll;
129}
130
131double QGeoCameraData::roll() const
132{
133 return d->m_roll;
134}
135
136void QGeoCameraData::setFieldOfView(double fieldOfView)
137{
138 d->m_fieldOfView = fieldOfView;
139}
140
141double QGeoCameraData::fieldOfView() const
142{
143 return d->m_fieldOfView;
144}
145
146void QGeoCameraData::setZoomLevel(double zoomFactor)
147{
148 d->m_zoomLevel = zoomFactor;
149}
150
151double QGeoCameraData::zoomLevel() const
152{
153 return d->m_zoomLevel;
154}
155
156QT_END_NAMESPACE
QVariant cameraInterpolator(const QGeoCameraData &start, const QGeoCameraData &end, qreal progress)