[Qt] s/QQuickMapboxGL{Style,StyleProperty}/QQuickMapboxGLMapParameter

This commit is contained in:
Bruno de Oliveira Abinader
2016-09-22 18:36:52 +03:00
parent 478241a90f
commit 3e42a0de9f
17 changed files with 541 additions and 406 deletions

View File

@@ -1 +0,0 @@
#include "qquickmapboxglstyle.hpp"

View File

@@ -1 +0,0 @@
#include "qquickmapboxglstyleproperty.hpp"

View File

@@ -10,7 +10,6 @@
#include <QQmlListProperty>
#include <QMapbox>
#include <QQuickMapboxGLStyle>
#include <QQuickMapboxGLMapParameter>
class QDeclarativeGeoServiceProvider;
@@ -35,7 +34,6 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
// MapboxGL QML Type interface.
Q_PROPERTY(QQuickMapboxGLStyle *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)
@@ -80,9 +78,6 @@ public:
Q_INVOKABLE void pan(int dx, int dy);
// MapboxGL QML Type interface.
void setStyle(QQuickMapboxGLStyle *);
QQuickMapboxGLStyle* style() const;
void setBearing(qreal bearing);
qreal bearing() const;
@@ -93,8 +88,8 @@ public:
QQmlListProperty<QQuickMapboxGLMapParameter> parameters();
protected:
// QQuickItem implementation.
virtual void itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
// QQmlParserStatus implementation
void componentComplete() override;
signals:
// Map QML Type signals.
@@ -111,7 +106,6 @@ signals:
void copyrightsVisibleChanged(bool visible);
// Mapbox-specific signals.
void styleChanged();
void bearingChanged(qreal angle);
void pitchChanged(qreal angle);
@@ -120,8 +114,7 @@ public slots:
private slots:
void onMapChanged(QMapbox::MapChange);
void onStyleChanged();
void onStylePropertyUpdated(const QVariantMap &params);
void onParameterPropertyUpdated(const QString &name);
private:
static void appendParameter(QQmlListProperty<QQuickMapboxGLMapParameter> *prop, QQuickMapboxGLMapParameter *mapObject);
@@ -139,6 +132,26 @@ private:
PitchNeedsSync = 1 << 5,
};
struct StyleProperty {
enum Type {
Paint = 0,
Layout
};
Type type;
QString layer;
QString property;
QVariant value;
QString klass;
};
void processMapParameter(QQuickMapboxGLMapParameter *);
bool parseStyle(QQuickMapboxGLMapParameter *);
bool parseStyleProperty(QQuickMapboxGLMapParameter *, const QString &name);
bool parseStyleLayer(QQuickMapboxGLMapParameter *);
bool parseStyleSource(QQuickMapboxGLMapParameter *);
bool parseStyleFilter(QQuickMapboxGLMapParameter *);
qreal m_minimumZoomLevel = 0;
qreal m_maximumZoomLevel = 20;
qreal m_zoomLevel = 20;
@@ -148,11 +161,13 @@ private:
QGeoCoordinate m_center;
QGeoShape m_visibleRegion;
QColor m_color;
QList<QVariantMap> m_layoutChanges;
QList<QVariantMap> m_paintChanges;
QString m_styleUrl;
QList<StyleProperty> m_stylePropertyChanges;
QList<QVariantMap> m_layerChanges;
QList<QVariantMap> m_sourceChanges;
QList<QVariantMap> m_filterChanges;
QList<QQuickMapboxGLMapParameter*> m_parameters;
QQuickMapboxGLStyle *m_style = 0;
qreal m_bearing = 0;
qreal m_pitch = 0;

View File

@@ -18,7 +18,6 @@ public:
int propertyOffset() const { return m_metaPropertyOffset; }
signals:
void propertiesReady();
void propertyUpdated(const QString &name);
protected:

View File

@@ -1,39 +0,0 @@
#ifndef QQUICKMAPBOXGLSTYLE_H
#define QQUICKMAPBOXGLSTYLE_H
#include <QQuickItem>
class Q_DECL_EXPORT QQuickMapboxGLStyle : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QString url READ url WRITE setUrl NOTIFY urlChanged)
Q_PROPERTY(QString styleClass READ styleClass WRITE setStyleClass NOTIFY classChanged)
public:
QQuickMapboxGLStyle(QQuickItem *parent = Q_NULLPTR);
virtual ~QQuickMapboxGLStyle() {}
// QQuickItem implementation
virtual void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &);
void setUrl(const QString &);
QString url() const;
void setStyleClass(const QString &);
QString styleClass() const;
signals:
void urlChanged(const QString &);
void classChanged(const QString &);
void propertyUpdated(const QVariantMap &);
private:
QString m_url;
QString m_class;
};
QML_DECLARE_TYPE(QQuickMapboxGLStyle)
#endif // QQUICKMAPBOXGLSTYLE_H

View File

@@ -1,69 +0,0 @@
#ifndef QQUICKMAPBOXGLSTYLEPROPERTY_H
#define QQUICKMAPBOXGLSTYLEPROPERTY_H
#include <QQuickItem>
class Q_DECL_EXPORT QQuickMapboxGLStyleProperty : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QString layer READ layer WRITE setLayer NOTIFY layerChanged)
Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY propertyChanged)
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
public:
enum Type {
LayoutType = 0,
PaintType,
};
virtual ~QQuickMapboxGLStyleProperty() {}
void setLayer(const QString &);
QString layer() const;
void setProperty(const QString &);
QString property() const;
void setValue(const QVariant &);
QVariant value() const;
public slots:
void checkUpdated();
signals:
void layerChanged(const QString &);
void propertyChanged(const QString &);
void valueChanged(const QVariant &);
void updated(const QVariantMap& params);
protected:
QQuickMapboxGLStyleProperty(QQuickItem *parent, Type);
QVariantMap m_map;
};
class Q_DECL_EXPORT QQuickMapboxGLLayoutStyleProperty : public QQuickMapboxGLStyleProperty
{
public:
QQuickMapboxGLLayoutStyleProperty(QQuickItem *parent = 0);
virtual ~QQuickMapboxGLLayoutStyleProperty() {}
};
class Q_DECL_EXPORT QQuickMapboxGLPaintStyleProperty : public QQuickMapboxGLStyleProperty
{
Q_OBJECT
Q_PROPERTY(QString styleClass READ styleClass WRITE setStyleClass NOTIFY classChanged)
public:
QQuickMapboxGLPaintStyleProperty(QQuickItem *parent = 0);
virtual ~QQuickMapboxGLPaintStyleProperty() {}
void setStyleClass(const QString &);
QString styleClass() const;
signals:
void classChanged(const QString &);
};
#endif // QQUICKMAPBOXGLSTYLEPROPERTY_H

View File

@@ -4,8 +4,7 @@
#include <qqml.h>
#include <QQuickMapboxGL>
#include <QQuickMapboxGLStyle>
#include <QQuickMapboxGLStyleProperty>
#include <QQuickMapboxGLMapParameter>
int main(int argc, char *argv[])
{
@@ -16,9 +15,7 @@ int main(int argc, char *argv[])
#endif
qmlRegisterType<QQuickMapboxGL>("QQuickMapboxGL", 1, 0, "MapboxMap");
qmlRegisterType<QQuickMapboxGLStyle>("QQuickMapboxGL", 1, 0, "MapboxStyle");
qmlRegisterType<QQuickMapboxGLLayoutStyleProperty>("QQuickMapboxGL", 1, 0, "MapboxLayoutStyleProperty");
qmlRegisterType<QQuickMapboxGLPaintStyleProperty>("QQuickMapboxGL", 1, 0, "MapboxPaintStyleProperty");
qmlRegisterType<QQuickMapboxGLMapParameter>("QQuickMapboxGL", 1, 0, "MapParameter");
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

View File

@@ -16,34 +16,13 @@ ApplicationWindow {
ColorDialog {
id: landColorDialog
title: "Land color"
onCurrentColorChanged: { mapFront.color = currentColor }
color: "#e0ded8"
}
ColorDialog {
id: waterColorDialog
title: "Water color"
onCurrentColorChanged: { waterColor.value = currentColor }
}
MapboxLayoutStyleProperty {
parent: styleStreets
layer: "road-label-large"
property: "visibility"
value: roadLabel.checked ? "visible" : "none"
}
MapboxLayoutStyleProperty {
parent: styleStreets
layer: "road-label-medium"
property: "visibility"
value: roadLabel.checked ? "visible" : "none"
}
MapboxLayoutStyleProperty {
parent: styleStreets
layer: "road-label-small"
property: "visibility"
value: roadLabel.checked ? "visible" : "none"
color: "#63c5ee"
}
RowLayout {
@@ -75,10 +54,55 @@ ApplicationWindow {
anchors.fill: parent
visible: false
style: MapboxStyle {
id: styleStreets
url: "mapbox://styles/mapbox/streets-v9"
}
parameters: [
MapParameter {
id: styleStreets
property var type: "style"
property var url: "mapbox://styles/mapbox/streets-v9"
},
MapParameter {
property var type: "source"
property var id: "testSource"
property var sourceType: "geojson"
property var data: ":source.geojson"
},
MapParameter {
property var type: "layer"
property var id: "testLayer"
property var layerType: "fill"
property var source: "testSource"
},
MapParameter {
property var type: "paint"
property var layer: "testLayer"
property var fillColor: Qt.rgba(0, 0, 1, 1)
},
MapParameter {
property var type: "paint"
property var layer: "water"
property var fillColor: waterColorDialog.color
},
MapParameter {
property var type: "layout"
property var layer: "road-label-large"
property var visibility: roadLabel.checked ? "visible" : "none"
},
MapParameter {
property var type: "layout"
property var layer: "road-label-medium"
property var visibility: roadLabel.checked ? "visible" : "none"
},
MapParameter {
property var type: "layout"
property var layer: "road-label-small"
property var visibility: roadLabel.checked ? "visible" : "none"
},
MapParameter {
property var type: "filter"
property var layer: "road-label-small"
property var filter: [ "==", "$type", "Point" ]
}
]
center: QtPositioning.coordinate(60.170448, 24.942046) // Helsinki
zoomLevel: 14
@@ -91,12 +115,6 @@ ApplicationWindow {
color: landColorDialog.color
copyrightsVisible: true
MapboxPaintStyleProperty {
id: waterColor
layer: "water"
property: "fill-color"
}
Image {
id: logo
@@ -162,10 +180,12 @@ ApplicationWindow {
anchors.fill: parent
visible: false
style: MapboxStyle {
id: styleSatellite
url: "mapbox://styles/mapbox/satellite-streets-v9"
}
parameters: [
MapParameter {
property var type: "style"
property var url: "mapbox://styles/mapbox/satellite-streets-v9"
}
]
center: mapFront.center
zoomLevel: mapFront.zoomLevel

View File

@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>source.geojson</file>
</qresource>
</RCC>

View File

@@ -0,0 +1,253 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
69.2578125,
-40.17887331434695
],
[
69.2578125,
-10.141931686131018
],
[
110.74218749999999,
-10.141931686131018
],
[
110.74218749999999,
-40.17887331434695
],
[
69.2578125,
-40.17887331434695
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-71.71875,
-33.43144133557529
],
[
-71.71875,
20.3034175184893
],
[
-0.703125,
20.3034175184893
],
[
-0.703125,
-33.43144133557529
],
[
-71.71875,
-33.43144133557529
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
97.3828125,
38.548165423046584
],
[
97.3828125,
65.2198939361321
],
[
155.0390625,
65.2198939361321
],
[
155.0390625,
38.548165423046584
],
[
97.3828125,
38.548165423046584
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.93617534637451,
60.17058143435276
],
[
24.93617534637451,
60.17149933938796
],
[
24.93808507919311,
60.17149933938796
],
[
24.93808507919311,
60.17058143435276
],
[
24.93617534637451,
60.17058143435276
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.94398593902588,
60.170346617317186
],
[
24.94398593902588,
60.171456646699184
],
[
24.947032928466797,
60.171456646699184
],
[
24.947032928466797,
60.170346617317186
],
[
24.94398593902588,
60.170346617317186
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.938321113586426,
60.16800902895082
],
[
24.938321113586426,
60.169204528711674
],
[
24.941797256469727,
60.169204528711674
],
[
24.941797256469727,
60.16800902895082
],
[
24.938321113586426,
60.16800902895082
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.939115047454834,
60.17280143974311
],
[
24.939115047454834,
60.17387936902026
],
[
24.94175434112549,
60.17387936902026
],
[
24.94175434112549,
60.17280143974311
],
[
24.939115047454834,
60.17280143974311
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
24.944372177124023,
60.16034398818875
],
[
24.944372177124023,
60.16837195311943
],
[
24.963769912719727,
60.16837195311943
],
[
24.963769912719727,
60.16034398818875
],
[
24.944372177124023,
60.16034398818875
]
]
]
}
}
]
}

View File

@@ -18,14 +18,10 @@ set(MBGL_QT_LIBRARIES
add_library(qmapboxgl SHARED
platform/qt/include/qquickmapboxgl.hpp
platform/qt/include/qquickmapboxglmapparameter.hpp
platform/qt/include/qquickmapboxglstyle.hpp
platform/qt/include/qquickmapboxglstyleproperty.hpp
platform/qt/src/qquickmapboxgl.cpp
platform/qt/src/qquickmapboxglmapparameter.cpp
platform/qt/src/qquickmapboxglrenderer.cpp
platform/qt/src/qquickmapboxglrenderer.hpp
platform/qt/src/qquickmapboxglstyle.cpp
platform/qt/src/qquickmapboxglstyleproperty.cpp
)
target_link_libraries(qmapboxgl

View File

@@ -4,7 +4,6 @@
#include <QMapbox>
#include <QQuickMapboxGL>
#include <QQuickMapboxGLStyleProperty>
#include <QQuickMapboxGLMapParameter>
#include <QDebug>
@@ -13,8 +12,15 @@
#include <QString>
#include <QtGlobal>
#include <QQmlListProperty>
#include <QJSValue>
#include <cmath>
namespace {
static const QRegularExpression s_camelCase {"([a-z0-9])([A-Z])"};
static const QStringList s_parameterTypes = QStringList() << "style" << "paint" << "layout" << "layer" << "source" << "filter";
} // namespace
QQuickMapboxGL::QQuickMapboxGL(QQuickItem *parent_)
: QQuickFramebufferObject(parent_)
@@ -41,6 +47,15 @@ QDeclarativeGeoServiceProvider *QQuickMapboxGL::plugin() const
return nullptr;
}
void QQuickMapboxGL::componentComplete()
{
QQuickFramebufferObject::componentComplete();
for (const auto& param : m_parameters) {
processMapParameter(param);
}
}
void QQuickMapboxGL::setMinimumZoomLevel(qreal zoom)
{
zoom = qMax(mbgl::util::MIN_ZOOM, zoom);
@@ -161,12 +176,14 @@ void QQuickMapboxGL::setColor(const QColor &color)
m_color = color;
QVariantMap paintProperty;
paintProperty["type"] = QQuickMapboxGLLayoutStyleProperty::PaintType;
paintProperty["layer"] = "background";
paintProperty["property"] = "background-color";
paintProperty["value"] = color;
onStylePropertyUpdated(paintProperty);
StyleProperty change;
change.type = StyleProperty::Paint;
change.layer = "background";
change.property = "background-color";
change.value = color;
m_stylePropertyChanges << change;
update();
emit colorChanged(m_color);
}
@@ -184,34 +201,6 @@ void QQuickMapboxGL::pan(int dx, int dy)
update();
}
void QQuickMapboxGL::setStyle(QQuickMapboxGLStyle *style)
{
if (style == m_style) {
return;
}
disconnect(style, SIGNAL(urlChanged(QString)), this, SLOT(onStyleChanged()));
disconnect(style, SIGNAL(propertyUpdated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
delete m_style;
m_style = style;
if (style) {
style->setParentItem(this);
connect(style, SIGNAL(urlChanged(QString)), this, SLOT(onStyleChanged()));
connect(style, SIGNAL(propertyUpdated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
}
m_syncState |= StyleNeedsSync;
m_styleLoaded = false;
update();
emit styleChanged();
}
QQuickMapboxGLStyle *QQuickMapboxGL::style() const
{
return m_style;
}
void QQuickMapboxGL::setBearing(qreal angle)
{
angle = std::fmod(angle, 360.);
@@ -254,27 +243,6 @@ qreal QQuickMapboxGL::pitch() const
return m_pitch;
}
void QQuickMapboxGL::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
{
QQuickFramebufferObject::itemChange(change, value);
switch (change) {
case QQuickItem::ItemChildAddedChange:
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
connect(property, SIGNAL(updated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
connect(this, SIGNAL(styleChanged()), property, SLOT(checkUpdated()));
}
break;
case QQuickItem::ItemChildRemovedChange:
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
disconnect(property, SIGNAL(updated(QVariantMap)), this, SLOT(onStylePropertyUpdated(QVariantMap)));
disconnect(this, SIGNAL(styleChanged()), property, SLOT(checkUpdated()));
}
default:
break;
}
}
void QQuickMapboxGL::onMapChanged(QMapbox::MapChange change)
{
if (change == QMapbox::MapChangeDidFinishLoadingStyle) {
@@ -283,32 +251,169 @@ void QQuickMapboxGL::onMapChanged(QMapbox::MapChange change)
}
}
void QQuickMapboxGL::onStylePropertyUpdated(const QVariantMap &params)
bool QQuickMapboxGL::parseStyle(QQuickMapboxGLMapParameter *param)
{
switch (params.value("type").toInt()) {
case QQuickMapboxGLStyleProperty::LayoutType:
m_layoutChanges << params;
break;
case QQuickMapboxGLStyleProperty::PaintType:
m_paintChanges << params;
break;
QString url = param->property("url").toString();
if (m_styleUrl == url) {
return false;
}
update();
// Reload parameters if switching style URLs.
if (!m_styleUrl.isEmpty()) {
for (const auto& param_ : m_parameters) {
if (param_->property("type").toString() == "style") continue;
processMapParameter(param_);
}
}
m_styleUrl = url;
m_styleLoaded = false;
m_syncState |= StyleNeedsSync;
return true;
}
void QQuickMapboxGL::onStyleChanged()
bool QQuickMapboxGL::parseStyleProperty(QQuickMapboxGLMapParameter *param, const QString &name)
{
m_syncState |= StyleNeedsSync;
update();
// Ignore meta-properties "type", "layer" and "class".
if (name == "type" || name == "layer" || name == "class") {
return false;
}
emit styleChanged();
QString formattedName(name);
formattedName = formattedName.replace(s_camelCase, "\\1-\\2").toLower();
QVariant value = param->property(name.toLatin1());
if (value.canConvert<QJSValue>()) {
value = value.value<QJSValue>().toVariant();
}
m_stylePropertyChanges << QQuickMapboxGL::StyleProperty {
param->property("type").toString().at(0) == 'p' ? StyleProperty::Paint : StyleProperty::Layout,
param->property("layer").toString(),
formattedName,
value,
param->property("class").toString()
};
return true;
}
bool QQuickMapboxGL::parseStyleLayer(QQuickMapboxGLMapParameter *param)
{
QVariantMap layer;
layer["id"] = param->property("name");
layer["source"] = param->property("source");
layer["type"] = param->property("layerType");
if (param->property("sourceLayer").isValid()) {
layer["source-layer"] = param->property("sourceLayer");
}
m_layerChanges << layer;
return true;
}
bool QQuickMapboxGL::parseStyleSource(QQuickMapboxGLMapParameter *param)
{
QString sourceType = param->property("sourceType").toString();
QVariantMap source;
source["id"] = param->property("name");
source["type"] = sourceType;
if (sourceType == "vector" || sourceType == "raster") {
source["url"] = param->property("url");
m_sourceChanges << source;
} else if (sourceType == "geojson") {
QFile geojson(param->property("data").toString());
geojson.open(QIODevice::ReadOnly);
source["data"] = geojson.readAll();
m_sourceChanges << source;
} else {
qWarning() << "Error: Unsupported source type '" << sourceType << "'.";
return false;
}
return true;
}
bool QQuickMapboxGL::parseStyleFilter(QQuickMapboxGLMapParameter *param)
{
QVariantMap filter;
filter["layer"] = param->property("layer");
filter["filter"] = param->property("filter");
m_filterChanges << filter;
return true;
}
void QQuickMapboxGL::processMapParameter(QQuickMapboxGLMapParameter *param)
{
bool needsUpdate = false;
switch (s_parameterTypes.indexOf(param->property("type").toString())) {
case -1:
qWarning() << "Error: Invalid value for property 'type'.";
break;
case 0: // style
needsUpdate |= parseStyle(param);
break;
case 1: // paint
case 2: // layout
for (int i = param->propertyOffset(); i < param->metaObject()->propertyCount(); ++i) {
needsUpdate |= parseStyleProperty(param, QString(param->metaObject()->property(i).name()));
}
break;
case 3: // layer
needsUpdate |= parseStyleLayer(param);
break;
case 4: // source
needsUpdate |= parseStyleSource(param);
break;
case 5: // filter
needsUpdate |= parseStyleFilter(param);
break;
}
if (needsUpdate) update();
}
void QQuickMapboxGL::onParameterPropertyUpdated(const QString &propertyName)
{
QQuickMapboxGLMapParameter *param = qobject_cast<QQuickMapboxGLMapParameter *>(sender());
if (!param) {
qWarning() << "Warning: Sender for QQuickMapboxGL::onParameterPropertyUpdated is not a QQuickMapboxGLMapParameter.";
return;
}
if (propertyName == "type") {
qWarning() << "Error: Cannot modify property 'type'.";
return;
}
bool needsUpdate = false;
switch (s_parameterTypes.indexOf(param->property("type").toString())) {
case -1:
qWarning() << "Error: Invalid value for property 'type'.";
break;
case 0: // style
needsUpdate |= parseStyle(param);
break;
case 1: // paint
case 2: // layout
needsUpdate |= parseStyleProperty(param, propertyName);
break;
case 3: // layer
needsUpdate |= parseStyleLayer(param);
break;
case 4: // source
needsUpdate |= parseStyleSource(param);
break;
case 5: // filter
needsUpdate |= parseStyleFilter(param);
break;
}
if (needsUpdate) update();
}
void QQuickMapboxGL::appendParameter(QQmlListProperty<QQuickMapboxGLMapParameter> *prop, QQuickMapboxGLMapParameter *param)
{
QQuickMapboxGL *map = static_cast<QQuickMapboxGL *>(prop->object);
map->m_parameters.append(param);
QObject::connect(param, SIGNAL(propertyUpdated(QString)), map, SLOT(onParameterPropertyUpdated(QString)));
}
int QQuickMapboxGL::countParameters(QQmlListProperty<QQuickMapboxGLMapParameter> *prop)
@@ -327,6 +432,7 @@ void QQuickMapboxGL::clearParameter(QQmlListProperty<QQuickMapboxGLMapParameter>
{
QQuickMapboxGL *map = static_cast<QQuickMapboxGL *>(prop->object);
for (auto param : map->m_parameters) {
QObject::disconnect(param, SIGNAL(propertyUpdated(QString)), map, SLOT(onParameterPropertyUpdated(QString)));
}
map->m_parameters.clear();
}

View File

@@ -28,7 +28,6 @@ void QQuickMapboxGLMapParameter::componentComplete()
QObject::connect(this, signalName, mapper, SLOT(map()));
QObject::connect(mapper, SIGNAL(mapped(int)), this, SLOT(onPropertyUpdated(int)));
}
emit propertiesReady();
}
void QQuickMapboxGLMapParameter::onPropertyUpdated(int index)

View File

@@ -2,12 +2,12 @@
#include <QMapboxGL>
#include <QQuickMapboxGL>
#include <QQuickMapboxGLStyle>
#include <QSize>
#include <QOpenGLFramebufferObject>
#include <QOpenGLFramebufferObjectFormat>
#include <QQuickWindow>
#include <QThread>
QQuickMapboxGLRenderer::QQuickMapboxGLRenderer()
{
@@ -59,8 +59,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
m_map->setCoordinateZoom({ center.latitude(), center.longitude() }, quickMap->zoomLevel());
}
if (syncStatus & QQuickMapboxGL::StyleNeedsSync && quickMap->style()) {
m_map->setStyleUrl(quickMap->style()->url());
if (syncStatus & QQuickMapboxGL::StyleNeedsSync && !quickMap->m_styleUrl.isEmpty()) {
m_map->setStyleUrl(quickMap->m_styleUrl);
}
if (syncStatus & QQuickMapboxGL::PanNeedsSync) {
@@ -81,13 +81,27 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
return;
}
for (const auto& change: quickMap->m_layoutChanges) {
m_map->setLayoutProperty(change.value("layer").toString(), change.value("property").toString(), change.value("value"));
for (const auto& change : quickMap->m_sourceChanges) {
m_map->addSource(change.value("id").toString(), change);
}
quickMap->m_layoutChanges.clear();
quickMap->m_sourceChanges.clear();
for (const auto& change: quickMap->m_paintChanges) {
m_map->setPaintProperty(change.value("layer").toString(), change.value("property").toString(), change.value("value"), change.value("class").toString());
for (const auto& change : quickMap->m_layerChanges) {
m_map->addLayer(change);
}
quickMap->m_paintChanges.clear();
quickMap->m_layerChanges.clear();
for (const auto& change : quickMap->m_filterChanges) {
m_map->setFilter(change.value("layer").toString(), change.value("filter"));
}
quickMap->m_filterChanges.clear();
for (const auto& change : quickMap->m_stylePropertyChanges) {
if (change.type == QQuickMapboxGL::StyleProperty::Paint) {
m_map->setPaintProperty(change.layer, change.property, change.value, change.klass);
} else {
m_map->setLayoutProperty(change.layer, change.property, change.value);
}
}
quickMap->m_stylePropertyChanges.clear();
}

View File

@@ -4,6 +4,7 @@
#include <QQuickFramebufferObject>
#include <QScopedPointer>
#include <QMapbox>
#include <QMapboxGL>
class QGeoCoordinate;

View File

@@ -1,59 +0,0 @@
#include <QQuickMapboxGLStyle>
#include <QQuickMapboxGLStyleProperty>
QQuickMapboxGLStyle::QQuickMapboxGLStyle(QQuickItem *parent)
: QQuickItem(parent)
{
}
void QQuickMapboxGLStyle::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value)
{
QQuickItem::itemChange(change, value);
switch (change) {
case QQuickItem::ItemChildAddedChange:
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
connect(property, SIGNAL(updated(QVariantMap)), this, SIGNAL(propertyUpdated(QVariantMap)));
connect(this, SIGNAL(urlChanged(QString)), property, SLOT(checkUpdated()));
}
break;
case QQuickItem::ItemChildRemovedChange:
if (QQuickMapboxGLStyleProperty *property = qobject_cast<QQuickMapboxGLStyleProperty *>(value.item)) {
disconnect(property, SIGNAL(updated(QVariantMap)), this, SIGNAL(propertyUpdated(QVariantMap)));
disconnect(this, SIGNAL(urlChanged(QString)), property, SLOT(checkUpdated()));
}
break;
default:
break;
}
}
void QQuickMapboxGLStyle::setUrl(const QString &url)
{
if (url == m_url) {
return;
}
m_url = url;
emit urlChanged(url);
}
QString QQuickMapboxGLStyle::url() const
{
return m_url;
}
void QQuickMapboxGLStyle::setStyleClass(const QString &styleClass)
{
if (styleClass == m_class) {
return;
}
m_class = styleClass;
emit classChanged(styleClass);
}
QString QQuickMapboxGLStyle::styleClass() const
{
return m_class;
}

View File

@@ -1,97 +0,0 @@
#include <QQuickMapboxGLStyleProperty>
// QQuickMapboxGLStyleProperty
QQuickMapboxGLStyleProperty::QQuickMapboxGLStyleProperty(QQuickItem *parent_, Type type)
: QQuickItem(parent_)
{
m_map["type"] = type;
}
void QQuickMapboxGLStyleProperty::checkUpdated()
{
if (m_map.value("type").isValid()
&& m_map.value("layer").isValid()
&& m_map.value("property").isValid()
&& m_map.value("value").isValid()) {
emit updated(m_map);
}
}
void QQuickMapboxGLStyleProperty::setLayer(const QString &layer)
{
if (m_map.value("layer").toString() == layer) {
return;
}
m_map["layer"] = layer;
emit layerChanged(layer);
checkUpdated();
}
QString QQuickMapboxGLStyleProperty::layer() const
{
return m_map.value("layer").toString();
}
void QQuickMapboxGLStyleProperty::setProperty(const QString &property)
{
if (m_map.value("property").toString() == property) {
return;
}
m_map["property"] = property;
emit propertyChanged(property);
checkUpdated();
}
QString QQuickMapboxGLStyleProperty::property() const
{
return m_map.value("property").toString();
}
void QQuickMapboxGLStyleProperty::setValue(const QVariant &value)
{
if (m_map.value("value") == value) {
return;
}
m_map["value"] = value;
emit valueChanged(value);
checkUpdated();
}
QVariant QQuickMapboxGLStyleProperty::value() const
{
return m_map.value("value");
}
void QQuickMapboxGLPaintStyleProperty::setStyleClass(const QString &styleClass)
{
if (m_map.value("class").toString() == styleClass) {
return;
}
m_map["class"] = styleClass;
emit classChanged(styleClass);
checkUpdated();
}
QString QQuickMapboxGLPaintStyleProperty::styleClass() const
{
return m_map.value("class").toString();
}
// QQuickMapboxGLLayoutStyleProperty
QQuickMapboxGLLayoutStyleProperty::QQuickMapboxGLLayoutStyleProperty(QQuickItem *parent_)
: QQuickMapboxGLStyleProperty(parent_, LayoutType)
{
}
// QQuickMapboxGLPaintStyleProperty
QQuickMapboxGLPaintStyleProperty::QQuickMapboxGLPaintStyleProperty(QQuickItem *parent_)
: QQuickMapboxGLStyleProperty(parent_, PaintType)
{
}