From cb2d9854615405ebe3b78a5ad4ba477d2f87ecaa Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 11 Aug 2017 16:22:49 +0300 Subject: Fix MapParameters not having effect on Mapbox GL if added dynamically The previous code was not handling the case of MapParameters changing the style appearance after the style is fully loaded, which happens when MapParameters are created dynamically at runtime. [ChangeLog][QtLocation][MapboxGL] Fixed MapParameter dynamic usage Task-number: QTBUG-61442 Change-Id: I64a8a1416dd5f7477297878f42760ad9008382a4 Reviewed-by: Paolo Angelelli --- src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp index 3b9026ce..1001ca31 100644 --- a/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp +++ b/src/plugins/geoservices/mapboxgl/qgeomapmapboxgl.cpp @@ -160,6 +160,11 @@ void QGeoMapMapboxGLPrivate::addParameter(QGeoMapParameter *param) QObject::connect(param, &QGeoMapParameter::propertyUpdated, q, &QGeoMapMapboxGL::onParameterPropertyUpdated); + + if (m_styleLoaded) { + m_styleChanges << QMapboxGLStyleChange::addMapParameter(param); + emit q->sgNodeChanged(); + } } void QGeoMapMapboxGLPrivate::removeParameter(QGeoMapParameter *param) -- cgit v1.2.1 From 47e2c461d517a6bb2fe663f752f3c7dd72c63357 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Tue, 22 Aug 2017 14:53:19 +0300 Subject: Bump Mapbox GL to v1.1.0 mapbox-gl-native @ bd15e273dce767458d335aeb1f50aa081390d593 Task-number: QTBUG-62454 Change-Id: I241ae47d8590a5de7da95f39ae056abeab9c172b Reviewed-by: Paolo Angelelli --- src/3rdparty/mapbox-gl-native | 2 +- src/plugins/geoservices/geoservices.pro | 2 +- .../geoservices/mapboxgl/qmapboxglstylechange.cpp | 34 +++++++++++++++------- .../geoservices/mapboxgl/qmapboxglstylechange_p.h | 1 - .../geoservices/mapboxgl/qsgmapboxglnode.cpp | 1 + 5 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/3rdparty/mapbox-gl-native b/src/3rdparty/mapbox-gl-native index 9ecbe364..1c633072 160000 --- a/src/3rdparty/mapbox-gl-native +++ b/src/3rdparty/mapbox-gl-native @@ -1 +1 @@ -Subproject commit 9ecbe3642fb4a53b558598239b59bf1d0224c25b +Subproject commit 1c633072fcea7ad153ab6f8ec40dd72d83541ead diff --git a/src/plugins/geoservices/geoservices.pro b/src/plugins/geoservices/geoservices.pro index 459897a8..07c34798 100644 --- a/src/plugins/geoservices/geoservices.pro +++ b/src/plugins/geoservices/geoservices.pro @@ -7,7 +7,7 @@ qtConfig(concurrent) { } qtConfig(opengl):qtConfig(c++14):!win32|mingw:!qnx { - !exists(../../3rdparty/mapbox-gl-native/CMakeLists.txt) { + !exists(../../3rdparty/mapbox-gl-native/mapbox-gl-native.pro) { warning("Submodule mapbox-gl-native does not exist. Run 'git submodule update --init' on qtlocation.") } else { SUBDIRS += mapboxgl ../../3rdparty/mapbox-gl-native diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp index c6972b07..f79f0a38 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp @@ -54,7 +54,7 @@ QString formatPropertyName(QString *name) bool isImmutableProperty(const QString &name) { - return name == QStringLiteral("type") || name == QStringLiteral("layer") || name == QStringLiteral("class"); + return name == QStringLiteral("type") || name == QStringLiteral("layer"); } QString getId(QDeclarativeGeoMapItemBase *mapItem) @@ -288,7 +288,7 @@ QMapboxGLStyleSetPaintProperty::QMapboxGLStyleSetPaintProperty(const QString& la void QMapboxGLStyleSetPaintProperty::apply(QMapboxGL *map) { - map->setPaintProperty(m_layer, m_property, m_value, m_class); + map->setPaintProperty(m_layer, m_property, m_value); } QList> QMapboxGLStyleSetPaintProperty::fromMapParameter(QGeoMapParameter *param) @@ -313,7 +313,6 @@ QList> QMapboxGLStyleSetPaintProperty::from paint->m_layer = param->property("layer").toString(); paint->m_property = formatPropertyName(&name); - paint->m_class = param->property("class").toString(); changes << QSharedPointer(paint); } @@ -399,15 +398,30 @@ QSharedPointer QMapboxGLStyleAddLayer::fromMapParameter(QG Q_ASSERT(param->type() == "layer"); auto layer = new QMapboxGLStyleAddLayer(); - layer->m_params[QStringLiteral("id")] = param->property("name"); - layer->m_params[QStringLiteral("source")] = param->property("source"); - layer->m_params[QStringLiteral("type")] = param->property("layerType"); - if (param->property("sourceLayer").isValid()) { - layer->m_params[QStringLiteral("source-layer")] = param->property("sourceLayer"); - } + static const QStringList layerProperties = QStringList() + << QStringLiteral("name") << QStringLiteral("layerType") << QStringLiteral("before"); - layer->m_before = param->property("before").toString(); + // Offset objectName and type properties. + for (int i = 2; i < param->metaObject()->propertyCount(); ++i) { + QString name = param->metaObject()->property(i).name(); + QVariant value = param->property(name.toLatin1()); + + switch (layerProperties.indexOf(name)) { + case -1: + layer->m_params[formatPropertyName(&name)] = value; + break; + case 0: // name + layer->m_params[QStringLiteral("id")] = value; + break; + case 1: // layerType + layer->m_params[QStringLiteral("type")] = value; + break; + case 2: // before + layer->m_before = value.toString(); + break; + } + } return QSharedPointer(layer); } diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h index 9164591a..aa81d89f 100644 --- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h +++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange_p.h @@ -102,7 +102,6 @@ private: QString m_layer; QString m_property; QVariant m_value; - QString m_class; }; class QMapboxGLStyleAddLayer : public QMapboxGLStyleChange diff --git a/src/plugins/geoservices/mapboxgl/qsgmapboxglnode.cpp b/src/plugins/geoservices/mapboxgl/qsgmapboxglnode.cpp index d338a51a..3f31997c 100644 --- a/src/plugins/geoservices/mapboxgl/qsgmapboxglnode.cpp +++ b/src/plugins/geoservices/mapboxgl/qsgmapboxglnode.cpp @@ -65,6 +65,7 @@ void QSGMapboxGLTextureNode::resize(const QSize &size, qreal pixelRatio) m_map->resize(minSize, fbSize); m_fbo.reset(new QOpenGLFramebufferObject(fbSize, QOpenGLFramebufferObject::CombinedDepthStencil)); + m_map->setFramebufferObject(m_fbo->handle()); QSGPlainTexture *fboTexture = static_cast(texture()); if (!fboTexture) -- cgit v1.2.1 From db8e4340d65eea4d82b49a67d525d33cdb0478fc Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Mon, 21 Aug 2017 14:38:29 +0200 Subject: Fix QDeclarativeGeoMap::populateMap duplicating items Since apparently children() and childItems() do not necessarily return disjoint sets, concatenating the two lists did, in some cases, cause duplicated items in the map. This patch resorts to uniting sets to remove the duplicates. Change-Id: I07ef19a2fdff65429eb65d92be278d7c02ac1999 Reviewed-by: BogDan Vatra --- src/location/declarativemaps/qdeclarativegeomap.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/location/declarativemaps/qdeclarativegeomap.cpp b/src/location/declarativemaps/qdeclarativegeomap.cpp index dedb590e..2ed482e3 100644 --- a/src/location/declarativemaps/qdeclarativegeomap.cpp +++ b/src/location/declarativemaps/qdeclarativegeomap.cpp @@ -539,26 +539,26 @@ QQuickGeoMapGestureArea *QDeclarativeGeoMap::gesture() */ void QDeclarativeGeoMap::populateMap() { - QObjectList kids = children(); - QList quickKids = childItems(); - for (int i=0; i < quickKids.count(); ++i) - kids.append(quickKids.at(i)); + QSet kids = children().toSet(); + const QList quickKids = childItems(); + for (QQuickItem *ite: quickKids) + kids.insert(ite); - for (int i = 0; i < kids.size(); ++i) { + for (QObject *k : qAsConst(kids)) { // dispatch items appropriately - QDeclarativeGeoMapItemView *mapView = qobject_cast(kids.at(i)); + QDeclarativeGeoMapItemView *mapView = qobject_cast(k); if (mapView) { m_mapViews.append(mapView); setupMapView(mapView); continue; } - QDeclarativeGeoMapItemBase *mapItem = qobject_cast(kids.at(i)); + QDeclarativeGeoMapItemBase *mapItem = qobject_cast(k); if (mapItem) { addMapItem(mapItem); continue; } // Allow to add to the map Map items contained inside a parent QQuickItem, but only those at one level of nesting. - QDeclarativeGeoMapItemGroup *itemGroup = qobject_cast(kids.at(i)); + QDeclarativeGeoMapItemGroup *itemGroup = qobject_cast(k); if (itemGroup) { addMapItemGroup(itemGroup); continue; -- cgit v1.2.1 From f61a0512cc56c0e86870a66fcca43e0a16e4e8e9 Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Mon, 21 Aug 2017 14:42:32 +0200 Subject: Fix GeocodeModel not autoUpdating if plugin attaches late This patch handles the case when the plugin attaches after QDeclarativeGeocodeModel::componentComplete() has been called. Change-Id: Ib9e4991ab3a4a34730da2d55fae20a492ac9d9f2 Reviewed-by: BogDan Vatra --- src/location/declarativemaps/qdeclarativegeocodemodel.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp index ee435a5a..3e2a1aea 100644 --- a/src/location/declarativemaps/qdeclarativegeocodemodel.cpp +++ b/src/location/declarativemaps/qdeclarativegeocodemodel.cpp @@ -319,6 +319,9 @@ void QDeclarativeGeocodeModel::pluginReady() this, SLOT(geocodeFinished(QGeoCodeReply*))); connect(geocodingManager, SIGNAL(error(QGeoCodeReply*,QGeoCodeReply::Error,QString)), this, SLOT(geocodeError(QGeoCodeReply*,QGeoCodeReply::Error,QString))); + + if (complete_ && autoUpdate_) + update(); } /*! -- cgit v1.2.1 From d22e6d09f1607e694694d2ae5b2f447605a8782e Mon Sep 17 00:00:00 2001 From: Paolo Angelelli Date: Mon, 21 Aug 2017 14:44:34 +0200 Subject: Fix PluginParameter not working with script as property values This patch introduces the undocumented QDeclarativeGeoServiceProviderParameter::initialized signal, to signal to the parent when a parameter becomes fully initialized, so that the parent QDeclarativeGeoServiceProvider can attach. Task-number: QTBUG-62075 Change-Id: Ie3615abf31d19f39587c5e54b202f8f2c4a711cc Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../qdeclarativegeoserviceprovider.cpp | 59 +++++++++++++++++++--- .../qdeclarativegeoserviceprovider_p.h | 5 ++ tests/auto/declarative_core/tst_plugin.qml | 7 ++- tests/auto/declarative_ui/tst_map.qml | 24 +++++++++ .../qgeotiledmappingmanagerengine_test.h | 6 +++ 5 files changed, 94 insertions(+), 7 deletions(-) diff --git a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp index 4b8b2d7c..9e4fee8a 100644 --- a/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp +++ b/src/location/declarativemaps/qdeclarativegeoserviceprovider.cpp @@ -113,12 +113,42 @@ void QDeclarativeGeoServiceProvider::setName(const QString &name) return; name_ = name; + + if (complete_) + tryAttach(); + + emit nameChanged(name_); +} + +/*! + \internal +*/ +bool QDeclarativeGeoServiceProvider::parametersReady() { + for (const QDeclarativeGeoServiceProviderParameter *p: qAsConst(parameters_)) { + if (!p->isInitialized()) + return false; + } + return true; +} + +/*! + \internal +*/ +void QDeclarativeGeoServiceProvider::tryAttach() +{ + if (!parametersReady()) + return; + delete sharedProvider_; + sharedProvider_ = nullptr; + + if (name_.isEmpty()) + return; + sharedProvider_ = new QGeoServiceProvider(name_, parameterMap()); sharedProvider_->setLocale(locales_.at(0)); sharedProvider_->setAllowExperimental(experimental_); - emit nameChanged(name_); emit attached(); } @@ -147,11 +177,17 @@ QStringList QDeclarativeGeoServiceProvider::availableServiceProviders() void QDeclarativeGeoServiceProvider::componentComplete() { complete_ = true; - if (!name_.isEmpty()) { - return; + + for (QDeclarativeGeoServiceProviderParameter *p: qAsConst(parameters_)) { + if (!p->isInitialized()) { + connect(p, &QDeclarativeGeoServiceProviderParameter::initialized, + this, &QDeclarativeGeoServiceProvider::tryAttach); + } } - if (!prefer_.isEmpty() + if (!name_.isEmpty()) { + tryAttach(); + } else if (!prefer_.isEmpty() || required_->mappingRequirements() != NoMappingFeatures || required_->routingRequirements() != NoRoutingFeatures || required_->geocodingRequirements() != NoGeocodingFeatures @@ -796,15 +832,18 @@ QDeclarativeGeoServiceProviderParameter::~QDeclarativeGeoServiceProviderParamete \qmlproperty string PluginParameter::name This property holds the name of the plugin parameter as a single formatted string. + This property is a write-once property. */ void QDeclarativeGeoServiceProviderParameter::setName(const QString &name) { - if (name_ == name) + if (!name_.isEmpty() || name.isEmpty()) return; name_ = name; emit nameChanged(name_); + if (value_.isValid()) + emit initialized(); } QString QDeclarativeGeoServiceProviderParameter::name() const @@ -816,15 +855,18 @@ QString QDeclarativeGeoServiceProviderParameter::name() const \qmlproperty QVariant PluginParameter::value This property holds the value of the plugin parameter which support different types of values (variant). + This property is a write-once property. */ void QDeclarativeGeoServiceProviderParameter::setValue(const QVariant &value) { - if (value_ == value) + if (value_.isValid() || !value.isValid() || value.isNull()) return; value_ = value; emit valueChanged(value_); + if (!name_.isEmpty()) + emit initialized(); } QVariant QDeclarativeGeoServiceProviderParameter::value() const @@ -832,6 +874,11 @@ QVariant QDeclarativeGeoServiceProviderParameter::value() const return value_; } +bool QDeclarativeGeoServiceProviderParameter::isInitialized() const +{ + return !name_.isEmpty() && value_.isValid(); +} + /******************************************************************************* *******************************************************************************/ diff --git a/src/location/declarativemaps/qdeclarativegeoserviceprovider_p.h b/src/location/declarativemaps/qdeclarativegeoserviceprovider_p.h index 426c6b4d..c1ad4987 100644 --- a/src/location/declarativemaps/qdeclarativegeoserviceprovider_p.h +++ b/src/location/declarativemaps/qdeclarativegeoserviceprovider_p.h @@ -78,9 +78,12 @@ public: void setValue(const QVariant &value); QVariant value() const; + bool isInitialized() const; + Q_SIGNALS: void nameChanged(const QString &name); void valueChanged(const QVariant &value); + void initialized(); private: QString name_; @@ -210,6 +213,8 @@ Q_SIGNALS: void allowExperimentalChanged(bool allow); private: + bool parametersReady(); + void tryAttach(); static void parameter_append(QQmlListProperty *prop, QDeclarativeGeoServiceProviderParameter *mapObject); static int parameter_count(QQmlListProperty *prop); static QDeclarativeGeoServiceProviderParameter *parameter_at(QQmlListProperty *prop, int index); diff --git a/tests/auto/declarative_core/tst_plugin.qml b/tests/auto/declarative_core/tst_plugin.qml index 3dabba07..7b880f1d 100644 --- a/tests/auto/declarative_core/tst_plugin.qml +++ b/tests/auto/declarative_core/tst_plugin.qml @@ -99,9 +99,14 @@ Item { verify(invalidPlugin.supportsRouting()) verify(invalidPlugin.supportsPlaces()) - invalidPlugin.name = '' + invalidPlugin.name = 'here' compare(invalidAttachedSpy.count, 2) + verify(invalidPlugin.supportsMapping(Plugin.OnlineMappingFeature)) + verify(invalidPlugin.supportsGeocoding(Plugin.OnlineGeocodingFeature)) + verify(invalidPlugin.supportsRouting(Plugin.OnlineRoutingFeature)) + invalidPlugin.name = '' + compare(invalidAttachedSpy.count, 2) verify(!invalidPlugin.supportsMapping()) verify(!invalidPlugin.supportsGeocoding()) verify(!invalidPlugin.supportsRouting()) diff --git a/tests/auto/declarative_ui/tst_map.qml b/tests/auto/declarative_ui/tst_map.qml index 408bf96e..5c9deca2 100644 --- a/tests/auto/declarative_ui/tst_map.qml +++ b/tests/auto/declarative_ui/tst_map.qml @@ -50,6 +50,20 @@ Item { } ] } + Plugin { + id: testPluginLazyParameter; + name: "qmlgeo.test.plugin" + allowExperimental: true + property string extraTypeName : undefined + PluginParameter { name: "supported"; value: true} + PluginParameter { name: "finishRequestImmediately"; value: true} + PluginParameter { name: "validateWellKnownValues"; value: true} + PluginParameter { name: "extraMapTypeName"; value: testPluginLazyParameter.extraTypeName} + + Component.onCompleted: { + extraTypeName = "SomeString" + } + } property variant coordinate1: QtPositioning.coordinate(10, 11) property variant coordinate2: QtPositioning.coordinate(12, 13) @@ -106,6 +120,11 @@ Item { Map {id: mapTiltBearingHere; plugin: herePlugin; center: coordinate1; width: 1000; height: 1000; zoomLevel: 4; bearing: 45.0; tilt: 25.0 } + Map { + id: mapWithLazyPlugin + plugin: testPluginLazyParameter + } + MapParameter { id: testParameter type: "cameraCenter_test" @@ -129,6 +148,11 @@ Item { mapCenterSpy.clear(); } + function test_lazy_parameter() { + compare(mapWithLazyPlugin.supportedMapTypes.length, 5) + compare(mapWithLazyPlugin.supportedMapTypes[4].name, "SomeString") + } + function test_map_center() { // coordinate is set at map element declaration compare(map.center.latitude, 10) diff --git a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h index 5f6f0116..2fcf654d 100644 --- a/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h +++ b/tests/auto/geotestplugin/qgeotiledmappingmanagerengine_test.h @@ -68,6 +68,12 @@ public: mapTypes << QGeoMapType(QGeoMapType::SatelliteMapDay, tr("SatelliteMapDay"), tr("SatelliteMapDay"), false, false, 2, pluginName); mapTypes << QGeoMapType(QGeoMapType::CycleMap, tr("CycleMap"), tr("CycleMap"), false, false, 3, pluginName); mapTypes << QGeoMapType(QGeoMapType::CustomMap, tr("AlternateCameraCapabilities"), tr("AlternateCameraCapabilities"), false, false, 4, pluginName); + + if (parameters.contains(QStringLiteral("extraMapTypeName"))) { + QString extraMapTypeName = parameters.value(QStringLiteral("extraMapTypeName")).toString(); + mapTypes << QGeoMapType(QGeoMapType::CustomMap, extraMapTypeName, extraMapTypeName, false, false, 5, pluginName); + } + setSupportedMapTypes(mapTypes); QGeoTileFetcherTest *fetcher = new QGeoTileFetcherTest(this); -- cgit v1.2.1