diff options
Diffstat (limited to 'platform/qt/src/qmapboxgl.cpp')
-rw-r--r-- | platform/qt/src/qmapboxgl.cpp | 155 |
1 files changed, 36 insertions, 119 deletions
diff --git a/platform/qt/src/qmapboxgl.cpp b/platform/qt/src/qmapboxgl.cpp index ce7e237afb..f094e2a0ec 100644 --- a/platform/qt/src/qmapboxgl.cpp +++ b/platform/qt/src/qmapboxgl.cpp @@ -9,6 +9,7 @@ #include <mbgl/map/map.hpp> #include <mbgl/map/backend_scope.hpp> #include <mbgl/math/minmax.hpp> +#include <mbgl/style/style.hpp> #include <mbgl/style/conversion.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/source.hpp> @@ -71,16 +72,6 @@ QThreadStorage<std::shared_ptr<mbgl::util::RunLoop>> loop; // Conversion helper functions. -auto fromQStringList(const QStringList &list) -{ - std::vector<std::string> strings; - strings.reserve(list.size()); - for (const QString &string : list) { - strings.push_back(string.toStdString()); - } - return strings; -} - mbgl::Size sanitizedSize(const QSize& size) { return mbgl::Size { mbgl::util::max(0u, static_cast<uint32_t>(size.width())), @@ -88,7 +79,7 @@ mbgl::Size sanitizedSize(const QSize& size) { }; }; -std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) { +std::unique_ptr<mbgl::style::Image> toStyleImage(const QString &id, const QImage &sprite) { const QImage swapped = sprite .rgbSwapped() .convertToFormat(QImage::Format_ARGB32_Premultiplied); @@ -97,6 +88,7 @@ std::unique_ptr<mbgl::style::Image> toStyleImage(const QImage &sprite) { memcpy(img.get(), swapped.constBits(), swapped.byteCount()); return std::make_unique<mbgl::style::Image>( + id.toStdString(), mbgl::PremultipliedImage( { static_cast<uint32_t>(swapped.width()), static_cast<uint32_t>(swapped.height()) }, std::move(img)), @@ -483,12 +475,12 @@ void QMapboxGL::cycleDebugOptions() */ QString QMapboxGL::styleJson() const { - return QString::fromStdString(d_ptr->mapObj->getStyleJSON()); + return QString::fromStdString(d_ptr->mapObj->getStyle().getJSON()); } void QMapboxGL::setStyleJson(const QString &style) { - d_ptr->mapObj->setStyleJSON(style.toStdString()); + d_ptr->mapObj->getStyle().loadJSON(style.toStdString()); } /*! @@ -508,12 +500,12 @@ void QMapboxGL::setStyleJson(const QString &style) */ QString QMapboxGL::styleUrl() const { - return QString::fromStdString(d_ptr->mapObj->getStyleURL()); + return QString::fromStdString(d_ptr->mapObj->getStyle().getURL()); } void QMapboxGL::setStyleUrl(const QString &url) { - d_ptr->mapObj->setStyleURL(url.toStdString()); + d_ptr->mapObj->getStyle().loadURL(url.toStdString()); } /*! @@ -752,81 +744,15 @@ void QMapboxGL::setGestureInProgress(bool progress) } /*! - Adds an \a className to the list of active classes. Layers tagged with a certain class - will only be active when the class is added. - - This was removed from the \l {https://www.mapbox.com/mapbox-gl-style-spec/#layer-paint.*} - {Mapbox style specification} and should no longer be used. - - \deprecated - \sa removeClass() -*/ -void QMapboxGL::addClass(const QString &className) -{ - d_ptr->mapObj->addClass(className.toStdString()); -} - -/*! - Removes a \a className. - - \deprecated - \sa addClass() -*/ -void QMapboxGL::removeClass(const QString &className) -{ - d_ptr->mapObj->removeClass(className.toStdString()); -} - -/*! - Returns true when \a className is active, false otherwise. - - \deprecated - \sa addClass() -*/ -bool QMapboxGL::hasClass(const QString &className) const -{ - return d_ptr->mapObj->hasClass(className.toStdString()); -} - -/*! - Bulk adds a list of \a classNames. - - \deprecated - \sa addClass() -*/ -void QMapboxGL::setClasses(const QStringList &classNames) -{ - d_ptr->mapObj->setClasses(fromQStringList(classNames)); -} - -/*! - Returns a list of active classes. - - \deprecated - \sa setClasses() -*/ -QStringList QMapboxGL::getClasses() const -{ - QStringList classNames; - for (const std::string &mbglClass : d_ptr->mapObj->getClasses()) { - classNames << QString::fromStdString(mbglClass); - } - return classNames; -} - -/*! - Sets the \a duration and \a delay of style class transitions. Style property - values transition to new values with animation when a new class is set. - - \deprecated - \sa addClass() + Sets the \a duration and \a delay of style transitions. Style paint property + values transition to new values with animation when they are updated. */ void QMapboxGL::setTransitionOptions(qint64 duration, qint64 delay) { static auto convert = [](qint64 value) -> mbgl::optional<mbgl::Duration> { return std::chrono::duration_cast<mbgl::Duration>(mbgl::Milliseconds(value)); }; - d_ptr->mapObj->setTransitionOptions(mbgl::style::TransitionOptions{ convert(duration), convert(delay) }); + d_ptr->mapObj->getStyle().setTransitionOptions(mbgl::style::TransitionOptions{ convert(duration), convert(delay) }); } mbgl::Annotation asMapboxGLAnnotation(const QMapbox::Annotation & annotation) { @@ -866,9 +792,6 @@ mbgl::Annotation asMapboxGLAnnotation(const QMapbox::Annotation & annotation) { } else { return mbgl::FillAnnotation { asMapboxGLGeometry(fillAnnotation.geometry), fillAnnotation.opacity, { *color }, {} }; } - } else if (annotation.canConvert<QMapbox::StyleSourcedAnnotation>()) { - QMapbox::StyleSourcedAnnotation styleSourcedAnnotation = annotation.value<QMapbox::StyleSourcedAnnotation>(); - return mbgl::StyleSourcedAnnotation { asMapboxGLGeometry(styleSourcedAnnotation.geometry), styleSourcedAnnotation.layerID.toStdString() }; } qWarning() << "Unable to convert annotation:" << annotation; @@ -944,7 +867,7 @@ void QMapboxGL::setLayoutProperty(const QString& layer, const QString& property, { using namespace mbgl::style; - Layer* layer_ = d_ptr->mapObj->getLayer(layer.toStdString()); + Layer* layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString()); if (!layer_) { qWarning() << "Layer not found:" << layer; return; @@ -961,9 +884,6 @@ void QMapboxGL::setLayoutProperty(const QString& layer, const QString& property, as defined by the \l {https://www.mapbox.com/mapbox-gl-style-spec/} {Mapbox style specification} for paint properties. - The argument \a styleClass is deprecated and is used for defining the style class for the paint - property. - For paint properties that take a color as \a value, such as \c fill-color, a string such as \c blue can be passed or a QColor. @@ -1009,22 +929,17 @@ void QMapboxGL::setLayoutProperty(const QString& layer, const QString& property, map->setPaintProperty("route","line-dasharray", lineDashArray); \endcode */ -void QMapboxGL::setPaintProperty(const QString& layer, const QString& property, const QVariant& value, const QString& styleClass) +void QMapboxGL::setPaintProperty(const QString& layer, const QString& property, const QVariant& value) { using namespace mbgl::style; - Layer* layer_ = d_ptr->mapObj->getLayer(layer.toStdString()); + Layer* layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString()); if (!layer_) { qWarning() << "Layer not found:" << layer; return; } - mbgl::optional<std::string> klass; - if (!styleClass.isEmpty()) { - klass = styleClass.toStdString(); - } - - if (conversion::setPaintProperty(*layer_, property.toStdString(), value, klass)) { + if (conversion::setPaintProperty(*layer_, property.toStdString(), value)) { qWarning() << "Error setting paint property:" << layer << "-" << property; return; } @@ -1114,7 +1029,7 @@ void QMapboxGL::addAnnotationIcon(const QString &name, const QImage &icon) { if (icon.isNull()) return; - d_ptr->mapObj->addAnnotationImage(name.toStdString(), toStyleImage(icon)); + d_ptr->mapObj->addAnnotationImage(toStyleImage(name, icon)); } /*! @@ -1267,7 +1182,7 @@ void QMapboxGL::addSource(const QString &id, const QVariantMap ¶ms) return; } - d_ptr->mapObj->addSource(std::move(*source)); + d_ptr->mapObj->getStyle().addSource(std::move(*source)); } /*! @@ -1275,7 +1190,7 @@ void QMapboxGL::addSource(const QString &id, const QVariantMap ¶ms) */ bool QMapboxGL::sourceExists(const QString& sourceID) { - return !!d_ptr->mapObj->getSource(sourceID.toStdString()); + return !!d_ptr->mapObj->getStyle().getSource(sourceID.toStdString()); } /*! @@ -1289,7 +1204,7 @@ void QMapboxGL::updateSource(const QString &id, const QVariantMap ¶ms) using namespace mbgl::style; using namespace mbgl::style::conversion; - auto source = d_ptr->mapObj->getSource(id.toStdString()); + auto source = d_ptr->mapObj->getStyle().getSource(id.toStdString()); if (!source) { addSource(id, params); return; @@ -1319,8 +1234,8 @@ void QMapboxGL::removeSource(const QString& id) { auto sourceIDStdString = id.toStdString(); - if (d_ptr->mapObj->getSource(sourceIDStdString)) { - d_ptr->mapObj->removeSource(sourceIDStdString); + if (d_ptr->mapObj->getStyle().getSource(sourceIDStdString)) { + d_ptr->mapObj->getStyle().removeSource(sourceIDStdString); } } @@ -1337,9 +1252,9 @@ void QMapboxGL::addCustomLayer(const QString &id, QMapbox::CustomLayerRenderFunction renderFn, QMapbox::CustomLayerDeinitializeFunction deinitFn, void *context, - char *before) + const QString& before) { - d_ptr->mapObj->addLayer(std::make_unique<mbgl::style::CustomLayer>( + d_ptr->mapObj->getStyle().addLayer(std::make_unique<mbgl::style::CustomLayer>( id.toStdString(), reinterpret_cast<mbgl::style::CustomLayerInitializeFunction>(initFn), // This cast is safe as long as both mbgl:: and QMapbox:: @@ -1347,13 +1262,14 @@ void QMapboxGL::addCustomLayer(const QString &id, (mbgl::style::CustomLayerRenderFunction)renderFn, reinterpret_cast<mbgl::style::CustomLayerDeinitializeFunction>(deinitFn), context), - before ? mbgl::optional<std::string>(before) : mbgl::optional<std::string>()); + before.isEmpty() ? mbgl::optional<std::string>() : mbgl::optional<std::string>(before.toStdString())); } /*! Adds a style layer to the map as specified by the \l {https://www.mapbox.com/mapbox-gl-style-spec/#root-layers}{Mapbox style specification} with - \a params. + \a params. The layer will be added under the layer specified by \a before, if specified. + Otherwise it will be added as the topmost layer. This example shows how to add a layer that will be used to show a route line on the map. Note that nothing will be drawn until we set paint properties using setPaintProperty(). @@ -1369,7 +1285,7 @@ void QMapboxGL::addCustomLayer(const QString &id, /note The source must exist prior to adding a layer. */ -void QMapboxGL::addLayer(const QVariantMap ¶ms) +void QMapboxGL::addLayer(const QVariantMap ¶ms, const QString& before) { using namespace mbgl::style; using namespace mbgl::style::conversion; @@ -1381,7 +1297,8 @@ void QMapboxGL::addLayer(const QVariantMap ¶ms) return; } - d_ptr->mapObj->addLayer(std::move(*layer)); + d_ptr->mapObj->getStyle().addLayer(std::move(*layer), + before.isEmpty() ? mbgl::optional<std::string>() : mbgl::optional<std::string>(before.toStdString())); } /*! @@ -1389,7 +1306,7 @@ void QMapboxGL::addLayer(const QVariantMap ¶ms) */ bool QMapboxGL::layerExists(const QString& id) { - return !!d_ptr->mapObj->getLayer(id.toStdString()); + return !!d_ptr->mapObj->getStyle().getLayer(id.toStdString()); } /*! @@ -1397,7 +1314,7 @@ bool QMapboxGL::layerExists(const QString& id) */ void QMapboxGL::removeLayer(const QString& id) { - d_ptr->mapObj->removeLayer(id.toStdString()); + d_ptr->mapObj->getStyle().removeLayer(id.toStdString()); } /*! @@ -1414,7 +1331,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image) { if (image.isNull()) return; - d_ptr->mapObj->addImage(id.toStdString(), toStyleImage(image)); + d_ptr->mapObj->getStyle().addImage(toStyleImage(id, image)); } /*! @@ -1422,7 +1339,7 @@ void QMapboxGL::addImage(const QString &id, const QImage &image) */ void QMapboxGL::removeImage(const QString &id) { - d_ptr->mapObj->removeImage(id.toStdString()); + d_ptr->mapObj->getStyle().removeImage(id.toStdString()); } /*! @@ -1450,7 +1367,7 @@ void QMapboxGL::setFilter(const QString& layer, const QVariant& filter) using namespace mbgl::style; using namespace mbgl::style::conversion; - Layer* layer_ = d_ptr->mapObj->getLayer(layer.toStdString()); + Layer* layer_ = d_ptr->mapObj->getStyle().getLayer(layer.toStdString()); if (!layer_) { qWarning() << "Layer not found:" << layer; return; @@ -1590,12 +1507,12 @@ mbgl::Size QMapboxGLPrivate::framebufferSize() const { void QMapboxGLPrivate::updateAssumedState() { assumeFramebufferBinding(fbObject); - assumeViewportSize(framebufferSize()); + assumeViewport(0, 0, framebufferSize()); } void QMapboxGLPrivate::bind() { setFramebufferBinding(fbObject); - setViewportSize(framebufferSize()); + setViewport(0, 0, framebufferSize()); } void QMapboxGLPrivate::invalidate() @@ -1680,7 +1597,7 @@ void QMapboxGLPrivate::onDidFinishLoadingStyle() void QMapboxGLPrivate::onSourceChanged(mbgl::style::Source&) { std::string attribution; - for (const auto& source : mapObj->getSources()) { + for (const auto& source : mapObj->getStyle().getSources()) { // Avoid duplicates by using the most complete attribution HTML snippet. if (source->getAttribution() && (attribution.size() < source->getAttribution()->size())) attribution = *source->getAttribution(); |