summaryrefslogtreecommitdiff
path: root/platform/qt/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2016-08-05 16:32:31 +0300
committerBruno de Oliveira Abinader <bruno@mapbox.com>2016-08-17 15:21:52 +0300
commit8843bebee259dfebfde07b0b18ceb9d5109eba9b (patch)
tree61e1183b2dbbc4f154383ab07f52ea1c8cbb5036 /platform/qt/src
parent45da1abbe1fa6237c793efb7e59332770d936053 (diff)
downloadqtlocation-mapboxgl-8843bebee259dfebfde07b0b18ceb9d5109eba9b.tar.gz
[Qt] Added QQuickMapboxGLStyle
A QQuickMapboxGLStyleProperty being a child of QQuickMapboxGLStyle assures that only properties associated with that particular style will reflect on the map - and that happens only when the style is the current set via style property.
Diffstat (limited to 'platform/qt/src')
-rw-r--r--platform/qt/src/qquickmapboxgl.cpp24
-rw-r--r--platform/qt/src/qquickmapboxglrenderer.cpp5
-rw-r--r--platform/qt/src/qquickmapboxglstyle.cpp59
3 files changed, 82 insertions, 6 deletions
diff --git a/platform/qt/src/qquickmapboxgl.cpp b/platform/qt/src/qquickmapboxgl.cpp
index b80b343d35..73241460cc 100644
--- a/platform/qt/src/qquickmapboxgl.cpp
+++ b/platform/qt/src/qquickmapboxgl.cpp
@@ -182,13 +182,21 @@ void QQuickMapboxGL::pan(int dx, int dy)
update();
}
-void QQuickMapboxGL::setStyle(const QString &styleUrl)
+void QQuickMapboxGL::setStyle(QQuickMapboxGLStyle *style)
{
- if (m_style == styleUrl) {
+ if (style == m_style) {
return;
}
- m_style = styleUrl;
+ 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;
update();
@@ -196,7 +204,7 @@ void QQuickMapboxGL::setStyle(const QString &styleUrl)
emit styleChanged();
}
-QString QQuickMapboxGL::style() const
+QQuickMapboxGLStyle *QQuickMapboxGL::style() const
{
return m_style;
}
@@ -295,3 +303,11 @@ void QQuickMapboxGL::onStylePropertyUpdated(const QVariantMap &params)
update();
}
+
+void QQuickMapboxGL::onStyleChanged()
+{
+ m_syncState |= StyleNeedsSync;
+ update();
+
+ emit styleChanged();
+}
diff --git a/platform/qt/src/qquickmapboxglrenderer.cpp b/platform/qt/src/qquickmapboxglrenderer.cpp
index 1b9a983d54..54ea251b06 100644
--- a/platform/qt/src/qquickmapboxglrenderer.cpp
+++ b/platform/qt/src/qquickmapboxglrenderer.cpp
@@ -2,6 +2,7 @@
#include <QMapboxGL>
#include <QQuickMapboxGL>
+#include <QQuickMapboxGLStyle>
#include <QSize>
#include <QOpenGLFramebufferObject>
@@ -83,8 +84,8 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
m_map->setCoordinateZoom({ center.latitude(), center.longitude() }, quickMap->zoomLevel());
}
- if (syncStatus & QQuickMapboxGL::StyleNeedsSync) {
- m_map->setStyleURL(quickMap->style());
+ if (syncStatus & QQuickMapboxGL::StyleNeedsSync && quickMap->style()) {
+ m_map->setStyleURL(quickMap->style()->url());
m_styleLoaded = false;
}
diff --git a/platform/qt/src/qquickmapboxglstyle.cpp b/platform/qt/src/qquickmapboxglstyle.cpp
new file mode 100644
index 0000000000..1a8640928b
--- /dev/null
+++ b/platform/qt/src/qquickmapboxglstyle.cpp
@@ -0,0 +1,59 @@
+#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;
+}