diff options
Diffstat (limited to 'platform/qt/src/qmapboxgl.cpp')
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 98 |
1 files changed, 66 insertions, 32 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index edda1f9599..ae4c028eed 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -13,6 +13,7 @@ #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/source.hpp> #include <mbgl/style/layers/custom_layer.hpp> +#include <mbgl/style/sources/geojson_source.hpp> #include <mbgl/style/transition_options.hpp> #include <mbgl/sprite/sprite_image.hpp> #include <mbgl/storage/network_status.hpp> @@ -25,6 +26,7 @@ #include <QGuiApplication> #include <QWindow> #include <QOpenGLFramebufferObject> +#include <QOpenGLContext> #else #include <QCoreApplication> #endif @@ -122,8 +124,9 @@ std::unique_ptr<const mbgl::SpriteImage> toSpriteImage(const QImage &sprite) { memcpy(img.get(), swapped.constBits(), swapped.byteCount()); return std::make_unique<mbgl::SpriteImage>( - mbgl::PremultipliedImage{ static_cast<uint16_t>(swapped.width()), - static_cast<uint16_t>(swapped.height()), std::move(img) }, + mbgl::PremultipliedImage( + { static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) }, + std::move(img)), 1.0); } @@ -611,7 +614,8 @@ void QMapboxGL::resize(const QSize& size, const QSize& framebufferSize) d_ptr->size = size; d_ptr->fbSize = framebufferSize; - d_ptr->mapObj->setSize({{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }}); + d_ptr->mapObj->setSize( + { static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) }); } void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &sprite) @@ -700,9 +704,38 @@ void QMapboxGL::addSource(const QString &sourceID, const QVariantMap ¶ms) d_ptr->mapObj->addSource(std::move(*source)); } +void QMapboxGL::updateSource(const QString &sourceID, const QVariantMap ¶ms) +{ + using namespace mbgl::style; + using namespace mbgl::style::conversion; + + auto source = d_ptr->mapObj->getSource(sourceID.toStdString()); + if (!source) { + addSource(sourceID, params); + return; + } + + auto sourceGeoJSON = source->as<GeoJSONSource>(); + if (!sourceGeoJSON) { + qWarning() << "Unable to update source: only GeoJSON sources are mutable."; + return; + } + + if (params.contains("data")) { + auto result = convertGeoJSON(params["data"]); + if (result) { + sourceGeoJSON->setGeoJSON(*result); + } + } +} + void QMapboxGL::removeSource(const QString& sourceID) { - d_ptr->mapObj->removeSource(sourceID.toStdString()); + auto sourceIDStdString = sourceID.toStdString(); + + if (d_ptr->mapObj->getSource(sourceIDStdString)) { + d_ptr->mapObj->removeSource(sourceIDStdString); + } } void QMapboxGL::addCustomLayer(const QString &id, @@ -798,12 +831,20 @@ void QMapboxGL::setFilter(const QString& layer_, const QVariant& filter_) void QMapboxGL::render(QOpenGLFramebufferObject *fbo) { d_ptr->dirty = false; - d_ptr->updateFramebufferBinding(fbo); + d_ptr->fbo = fbo; d_ptr->mapObj->render(*d_ptr); } #else void QMapboxGL::render() { +#if defined(__APPLE__) + // FIXME Qt 4.x provides an incomplete FBO at start. + // See https://bugreports.qt.io/browse/QTBUG-36802 for details. + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { + return; + } +#endif + d_ptr->dirty = false; d_ptr->mapObj->render(*d_ptr); } @@ -824,7 +865,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin settings.cacheDatabaseMaximumSize())) , threadPool(4) , mapObj(std::make_unique<mbgl::Map>( - *this, std::array<uint16_t, 2>{{ static_cast<uint16_t>(size.width()), static_cast<uint16_t>(size.height()) }}, + *this, mbgl::Size{ static_cast<uint32_t>(size.width()), static_cast<uint32_t>(size.height()) }, pixelRatio, *fileSourceObj, threadPool, static_cast<mbgl::MapMode>(settings.mapMode()), static_cast<mbgl::GLContextMode>(settings.contextMode()), @@ -836,6 +877,7 @@ QMapboxGLPrivate::QMapboxGLPrivate(QMapboxGL *q, const QMapboxGLSettings &settin fileSourceObj->setAccessToken(settings.accessToken().toStdString()); connect(this, SIGNAL(needsRendering()), q_ptr, SIGNAL(needsRendering()), Qt::QueuedConnection); connect(this, SIGNAL(mapChanged(QMapbox::MapChange)), q_ptr, SIGNAL(mapChanged(QMapbox::MapChange)), Qt::QueuedConnection); + connect(this, SIGNAL(copyrightsChanged(QString)), q_ptr, SIGNAL(copyrightsChanged(QString)), Qt::QueuedConnection); } QMapboxGLPrivate::~QMapboxGLPrivate() @@ -843,39 +885,21 @@ QMapboxGLPrivate::~QMapboxGLPrivate() } #if QT_VERSION >= 0x050000 -void QMapboxGLPrivate::updateFramebufferBinding(QOpenGLFramebufferObject *fbo_) -{ - fbo = fbo_; - if (fbo) { - getContext().bindFramebuffer.setDirty(); - getContext().viewport.setCurrentValue( - { 0, 0, static_cast<uint16_t>(fbo->width()), static_cast<uint16_t>(fbo->height()) }); - } else { - getContext().bindFramebuffer.setCurrentValue(0); - getContext().viewport.setCurrentValue({ 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }); - } -} - -void QMapboxGLPrivate::bind() -{ +void QMapboxGLPrivate::bind() { if (fbo) { fbo->bind(); getContext().bindFramebuffer.setDirty(); - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbo->width()), - static_cast<uint16_t>(fbo->height()) }; - } else { - getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }; + getContext().viewport = { + 0, 0, { static_cast<uint32_t>(fbo->width()), static_cast<uint32_t>(fbo->height()) } + }; } } #else -void QMapboxGLPrivate::bind() -{ +void QMapboxGLPrivate::bind() { getContext().bindFramebuffer = 0; - getContext().viewport = { 0, 0, static_cast<uint16_t>(fbSize.width()), - static_cast<uint16_t>(fbSize.height()) }; + getContext().viewport = { + 0, 0, { static_cast<uint32_t>(fbSize.width()), static_cast<uint32_t>(fbSize.height()) } + }; } #endif @@ -889,6 +913,16 @@ void QMapboxGLPrivate::invalidate() void QMapboxGLPrivate::notifyMapChange(mbgl::MapChange change) { + if (change == mbgl::MapChangeSourceDidChange) { + std::string attribution; + for (const auto& source : mapObj->getSources()) { + // Avoid duplicates by using the most complete attribution HTML snippet. + if (source->getAttribution() && (attribution.size() < source->getAttribution()->size())) + attribution = *source->getAttribution(); + } + emit copyrightsChanged(QString::fromStdString(attribution)); + } + emit mapChanged(static_cast<QMapbox::MapChange>(change)); } |