[Qt] Expose center and zoom properties
This commit is contained in:
@@ -115,6 +115,8 @@ matrix:
|
||||
compiler: ": linux-gcc49-release"
|
||||
env: FLAVOR=qt5 BUILDTYPE=Release _CXX=g++-4.9 _CC=gcc-4.9
|
||||
addons: *qt5
|
||||
before_install:
|
||||
- sudo apt-get install -y qtpositioning5-dev
|
||||
script:
|
||||
- make qt-app qt-qml-app
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef QQUICKMAPBOXGL_H
|
||||
#define QQUICKMAPBOXGL_H
|
||||
|
||||
#include <QGeoCoordinate>
|
||||
#include <QGeoShape>
|
||||
#include <QQuickFramebufferObject>
|
||||
|
||||
class QQuickItem;
|
||||
@@ -9,12 +11,57 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(qreal minimumZoomLevel READ minimumZoomLevel WRITE setMinimumZoomLevel NOTIFY minimumZoomLevelChanged)
|
||||
Q_PROPERTY(qreal maximumZoomLevel READ maximumZoomLevel WRITE setMaximumZoomLevel NOTIFY maximumZoomLevelChanged)
|
||||
Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
|
||||
Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
|
||||
Q_PROPERTY(QGeoShape visibleRegion READ visibleRegion WRITE setVisibleRegion)
|
||||
|
||||
public:
|
||||
QQuickMapboxGL(QQuickItem *parent = 0);
|
||||
virtual ~QQuickMapboxGL();
|
||||
|
||||
// Called from render thread.
|
||||
// QQuickFramebufferObject implementation.
|
||||
virtual Renderer *createRenderer() const Q_DECL_FINAL;
|
||||
|
||||
void setMinimumZoomLevel(qreal minimumZoomLevel);
|
||||
qreal minimumZoomLevel() const;
|
||||
|
||||
void setMaximumZoomLevel(qreal maximumZoomLevel);
|
||||
qreal maximumZoomLevel() const;
|
||||
|
||||
void setZoomLevel(qreal zoomLevel);
|
||||
qreal zoomLevel() const;
|
||||
|
||||
void setCenter(const QGeoCoordinate ¢er);
|
||||
QGeoCoordinate center() const;
|
||||
|
||||
void setVisibleRegion(const QGeoShape &shape);
|
||||
QGeoShape visibleRegion() const;
|
||||
|
||||
enum SyncState {
|
||||
NothingNeedsSync = 0x00,
|
||||
ZoomNeedsSync = 0x01,
|
||||
CenterNeedsSync = 0x02,
|
||||
};
|
||||
|
||||
int swapSyncState();
|
||||
|
||||
signals:
|
||||
void minimumZoomLevelChanged();
|
||||
void maximumZoomLevelChanged();
|
||||
void zoomLevelChanged(qreal zoomLevel);
|
||||
void centerChanged(const QGeoCoordinate &coordinate);
|
||||
|
||||
private:
|
||||
qreal m_minimumZoomLevel = 0;
|
||||
qreal m_maximumZoomLevel = 20;
|
||||
qreal m_zoomLevel = 20;
|
||||
|
||||
QGeoCoordinate m_center;
|
||||
QGeoShape m_visibleRegion;
|
||||
|
||||
int m_syncState = NothingNeedsSync;
|
||||
};
|
||||
|
||||
#endif // QQUICKMAPBOXGL_H
|
||||
|
||||
@@ -118,9 +118,11 @@
|
||||
['<(qt_version_major) == 5', {
|
||||
'variables': {
|
||||
'cflags': [
|
||||
'<@(qt_positioning_cflags)',
|
||||
'<@(qt_quick_cflags)',
|
||||
],
|
||||
'ldflags': [
|
||||
'<@(qt_positioning_ldflags)',
|
||||
'<@(qt_quick_ldflags)',
|
||||
],
|
||||
},
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
'<@(opengl_cflags)',
|
||||
'<@(qt_core_cflags)',
|
||||
'<@(qt_gui_cflags)',
|
||||
'<@(qt_positioning_cflags)',
|
||||
'<@(qt_qml_cflags)',
|
||||
'<@(qt_quick_cflags)',
|
||||
'-fPIC',
|
||||
@@ -35,6 +36,7 @@
|
||||
'<@(opengl_ldflags)',
|
||||
'<@(qt_core_ldflags)',
|
||||
'<@(qt_gui_ldflags)',
|
||||
'<@(qt_positioning_ldflags)',
|
||||
'<@(qt_qml_ldflags)',
|
||||
'<@(qt_quick_ldflags)',
|
||||
],
|
||||
|
||||
@@ -47,9 +47,11 @@ function print_qt_flags {
|
||||
if [ ${QT_VERSION_MAJOR} -gt 4 ]; then
|
||||
CONFIG+=" 'qt_qml_cflags%': $(quote_flags $(mason cflags Qt system "QtQml")), "$LN
|
||||
CONFIG+=" 'qt_quick_cflags%': $(quote_flags $(mason cflags Qt system "QtQuick")), "$LN
|
||||
CONFIG+=" 'qt_positioning_cflags%': $(quote_flags $(mason cflags Qt system "QtPositioning")),"$LN
|
||||
|
||||
CONFIG+=" 'qt_qml_ldflags%': $(quote_flags $(mason ldflags Qt system "QtQml")), "$LN
|
||||
CONFIG+=" 'qt_quick_ldflags%': $(quote_flags $(mason ldflags Qt system "QtQuick")), "$LN
|
||||
CONFIG+=" 'qt_positioning_ldflags%': $(quote_flags $(mason ldflags Qt system "QtPositioning")),"$LN
|
||||
fi
|
||||
|
||||
if hash moc 2>/dev/null && hash rcc 2>/dev/null; then
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <QQuickMapboxGL>
|
||||
|
||||
#include <QQuickItem>
|
||||
#include <QtGlobal>
|
||||
|
||||
QQuickMapboxGL::QQuickMapboxGL(QQuickItem *parent_)
|
||||
: QQuickFramebufferObject(parent_)
|
||||
@@ -21,3 +22,102 @@ QQuickFramebufferObject::Renderer *QQuickMapboxGL::createRenderer() const
|
||||
{
|
||||
return new QQuickMapboxGLRenderer();
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setMinimumZoomLevel(qreal zoom)
|
||||
{
|
||||
zoom = qMax(0., zoom);
|
||||
zoom = qMin(m_maximumZoomLevel, zoom);
|
||||
|
||||
if (m_minimumZoomLevel == zoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_minimumZoomLevel = zoom;
|
||||
|
||||
emit minimumZoomLevelChanged();
|
||||
}
|
||||
|
||||
qreal QQuickMapboxGL::minimumZoomLevel() const
|
||||
{
|
||||
return m_minimumZoomLevel;
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setMaximumZoomLevel(qreal zoom)
|
||||
{
|
||||
zoom = qMin(20., zoom);
|
||||
zoom = qMax(m_minimumZoomLevel, zoom);
|
||||
|
||||
if (m_maximumZoomLevel == zoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_maximumZoomLevel = zoom;
|
||||
|
||||
emit maximumZoomLevelChanged();
|
||||
}
|
||||
|
||||
qreal QQuickMapboxGL::maximumZoomLevel() const
|
||||
{
|
||||
return m_maximumZoomLevel;
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setZoomLevel(qreal zoom)
|
||||
{
|
||||
zoom = qMin(m_maximumZoomLevel, zoom);
|
||||
zoom = qMax(m_minimumZoomLevel, zoom);
|
||||
|
||||
if (m_zoomLevel == zoom) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_zoomLevel = zoom;
|
||||
|
||||
m_syncState |= ZoomNeedsSync;
|
||||
update();
|
||||
|
||||
emit zoomLevelChanged(m_zoomLevel);
|
||||
}
|
||||
|
||||
qreal QQuickMapboxGL::zoomLevel() const
|
||||
{
|
||||
return m_zoomLevel;
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setCenter(const QGeoCoordinate &coordinate)
|
||||
{
|
||||
if (m_center == coordinate) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_center = coordinate;
|
||||
|
||||
m_syncState |= CenterNeedsSync;
|
||||
update();
|
||||
|
||||
emit centerChanged(m_center);
|
||||
}
|
||||
|
||||
QGeoCoordinate QQuickMapboxGL::center() const
|
||||
{
|
||||
return m_center;
|
||||
}
|
||||
|
||||
|
||||
void QQuickMapboxGL::setVisibleRegion(const QGeoShape &shape)
|
||||
{
|
||||
m_visibleRegion = shape;
|
||||
}
|
||||
|
||||
QGeoShape QQuickMapboxGL::visibleRegion() const
|
||||
{
|
||||
return m_visibleRegion;
|
||||
}
|
||||
|
||||
int QQuickMapboxGL::swapSyncState()
|
||||
{
|
||||
int oldState = m_syncState;
|
||||
|
||||
m_syncState = NothingNeedsSync;
|
||||
|
||||
return oldState;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "qquickmapboxglrenderer.hpp"
|
||||
|
||||
#include <QMapboxGL>
|
||||
#include <QQuickMapboxGL>
|
||||
|
||||
#include <QSize>
|
||||
#include <QOpenGLFramebufferObject>
|
||||
@@ -43,4 +44,16 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
|
||||
QObject::connect(m_map.data(), SIGNAL(needsRendering()), item, SLOT(update()));
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
auto quickMap = static_cast<QQuickMapboxGL*>(item);
|
||||
auto syncStatus = quickMap->swapSyncState();
|
||||
|
||||
if (syncStatus & QQuickMapboxGL::ZoomNeedsSync) {
|
||||
m_map->setZoom(quickMap->zoomLevel());
|
||||
}
|
||||
|
||||
if (syncStatus & QQuickMapboxGL::CenterNeedsSync) {
|
||||
const auto& center = quickMap->center();
|
||||
m_map->setCoordinate(QMapbox::Coordinate(center.latitude(), center.longitude()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user