[Qt] Add pitch property to QML MapboxGL Type
This commit is contained in:
@@ -30,6 +30,7 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
|
||||
// MapboxGL QML Type interface.
|
||||
Q_PROPERTY(QString style READ style WRITE setStyle NOTIFY styleChanged)
|
||||
Q_PROPERTY(qreal bearing READ bearing WRITE setBearing NOTIFY bearingChanged)
|
||||
Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
|
||||
|
||||
public:
|
||||
QQuickMapboxGL(QQuickItem *parent = 0);
|
||||
@@ -74,15 +75,19 @@ public:
|
||||
void setBearing(qreal bearing);
|
||||
qreal bearing() const;
|
||||
|
||||
void setPitch(qreal pitch);
|
||||
qreal pitch() const;
|
||||
|
||||
QPointF swapPan();
|
||||
|
||||
enum SyncState {
|
||||
NothingNeedsSync = 0x00,
|
||||
ZoomNeedsSync = 0x01,
|
||||
CenterNeedsSync = 0x02,
|
||||
StyleNeedsSync = 0x04,
|
||||
PanNeedsSync = 0x08,
|
||||
BearingNeedsSync = 0x16,
|
||||
NothingNeedsSync = 0,
|
||||
ZoomNeedsSync = 1 << 0,
|
||||
CenterNeedsSync = 1 << 1,
|
||||
StyleNeedsSync = 1 << 2,
|
||||
PanNeedsSync = 1 << 3,
|
||||
BearingNeedsSync = 1 << 4,
|
||||
PitchNeedsSync = 1 << 5,
|
||||
};
|
||||
|
||||
int swapSyncState();
|
||||
@@ -102,6 +107,7 @@ signals:
|
||||
|
||||
void styleChanged();
|
||||
void bearingChanged(qreal angle);
|
||||
void pitchChanged(qreal angle);
|
||||
|
||||
public slots:
|
||||
void setCenter(const QGeoCoordinate ¢er);
|
||||
@@ -118,6 +124,7 @@ private:
|
||||
|
||||
QString m_style;
|
||||
qreal m_bearing = 0;
|
||||
qreal m_pitch = 0;
|
||||
|
||||
int m_syncState = NothingNeedsSync;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "qquickmapboxglrenderer.hpp"
|
||||
|
||||
#include <mbgl/util/constants.hpp>
|
||||
|
||||
#include <QQuickMapboxGL>
|
||||
|
||||
#include <QQuickItem>
|
||||
@@ -209,6 +211,27 @@ qreal QQuickMapboxGL::bearing() const
|
||||
return m_bearing;
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setPitch(qreal angle)
|
||||
{
|
||||
angle = qMin(qMax(0., angle), mbgl::util::PITCH_MAX * mbgl::util::RAD2DEG);
|
||||
|
||||
if (m_pitch == angle) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pitch = angle;
|
||||
|
||||
m_syncState |= PitchNeedsSync;
|
||||
update();
|
||||
|
||||
emit pitchChanged(m_pitch);
|
||||
}
|
||||
|
||||
qreal QQuickMapboxGL::pitch() const
|
||||
{
|
||||
return m_pitch;
|
||||
}
|
||||
|
||||
QPointF QQuickMapboxGL::swapPan()
|
||||
{
|
||||
QPointF oldPan = m_pan;
|
||||
|
||||
@@ -74,4 +74,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
|
||||
if (syncStatus & QQuickMapboxGL::BearingNeedsSync) {
|
||||
m_map->setBearing(quickMap->bearing());
|
||||
}
|
||||
|
||||
if (syncStatus & QQuickMapboxGL::PitchNeedsSync) {
|
||||
m_map->setPitch(quickMap->pitch());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user