summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-06-01 16:24:43 +0300
committerBruno de Oliveira Abinader <brunoabinader@gmail.com>2018-06-06 08:36:04 +0000
commit29b3f1eb809fd1c84dfab53e99d7f99b7bfe36cc (patch)
tree0a635665192aafd80e4f11cc33996dd5fedf0d25 /src
parent9be1436afa3d6f7345cd761688726abff5721791 (diff)
downloadqtlocation-29b3f1eb809fd1c84dfab53e99d7f99b7bfe36cc.tar.gz
Support dynamic properties in QMapboxGLStyleChange
QMapboxGLStyleChange should iterate also over dynamic properties when generating the style change objects. These dynamic properties could come from generic QGeoMapParameter objects instantiated from C++ code. Task-number: QTBUG-68598 Change-Id: I01a3e0971615c61f74789446c03255185a373803 Reviewed-by: Paolo Angelelli <paolo.angelelli@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
index 964f94f5..6c47d3ee 100644
--- a/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
+++ b/src/plugins/geoservices/mapboxgl/qmapboxglstylechange.cpp
@@ -45,14 +45,14 @@
namespace {
-QString formatPropertyName(QString *name)
+QByteArray formatPropertyName(const QByteArray &name)
{
+ QString nameAsString = QString::fromLatin1(name);
static const QRegularExpression camelCaseRegex(QStringLiteral("([a-z0-9])([A-Z])"));
-
- return name->replace(camelCaseRegex, QStringLiteral("\\1-\\2")).toLower();
+ return nameAsString.replace(camelCaseRegex, QStringLiteral("\\1-\\2")).toLower().toLatin1();
}
-bool isImmutableProperty(const QString &name)
+bool isImmutableProperty(const QByteArray &name)
{
return name == QStringLiteral("type") || name == QStringLiteral("layer");
}
@@ -167,6 +167,16 @@ QMapbox::Feature featureFromMapItem(QDeclarativeGeoMapItemBase *item)
}
}
+QList<QByteArray> getAllPropertyNamesList(QObject *object)
+{
+ const QMetaObject *metaObject = object->metaObject();
+ QList<QByteArray> propertyNames(object->dynamicPropertyNames());
+ for (int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
+ propertyNames.append(metaObject->property(i).name());
+ }
+ return propertyNames;
+}
+
} // namespace
@@ -261,22 +271,20 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleSetLayoutProperty::fro
QList<QSharedPointer<QMapboxGLStyleChange>> changes;
- // Offset objectName and type properties.
- for (int i = 2; i < param->metaObject()->propertyCount(); ++i) {
- QString name = param->metaObject()->property(i).name();
-
- if (isImmutableProperty(name))
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
continue;
auto layout = new QMapboxGLStyleSetLayoutProperty();
- layout->m_value = param->property(name.toLatin1());
+ layout->m_value = param->property(propertyName);
if (layout->m_value.canConvert<QJSValue>()) {
layout->m_value = layout->m_value.value<QJSValue>().toVariant();
}
layout->m_layer = param->property("layer").toString();
- layout->m_property = formatPropertyName(&name);
+ layout->m_property = formatPropertyName(propertyName);
changes << QSharedPointer<QMapboxGLStyleChange>(layout);
}
@@ -340,22 +348,20 @@ QList<QSharedPointer<QMapboxGLStyleChange>> QMapboxGLStyleSetPaintProperty::from
QList<QSharedPointer<QMapboxGLStyleChange>> changes;
- // Offset objectName and type properties.
- for (int i = 2; i < param->metaObject()->propertyCount(); ++i) {
- QString name = param->metaObject()->property(i).name();
-
- if (isImmutableProperty(name))
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
continue;
auto paint = new QMapboxGLStyleSetPaintProperty();
- paint->m_value = param->property(name.toLatin1());
+ paint->m_value = param->property(propertyName);
if (paint->m_value.canConvert<QJSValue>()) {
paint->m_value = paint->m_value.value<QJSValue>().toVariant();
}
paint->m_layer = param->property("layer").toString();
- paint->m_property = formatPropertyName(&name);
+ paint->m_property = formatPropertyName(propertyName);
changes << QSharedPointer<QMapboxGLStyleChange>(paint);
}
@@ -464,14 +470,16 @@ QSharedPointer<QMapboxGLStyleChange> QMapboxGLStyleAddLayer::fromMapParameter(QG
static const QStringList layerProperties = QStringList()
<< QStringLiteral("name") << QStringLiteral("layerType") << QStringLiteral("before");
- // 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());
+ QList<QByteArray> propertyNames = getAllPropertyNamesList(param);
+ for (const QByteArray &propertyName : propertyNames) {
+ if (isImmutableProperty(propertyName))
+ continue;
+
+ const QVariant value = param->property(propertyName);
- switch (layerProperties.indexOf(name)) {
+ switch (layerProperties.indexOf(propertyName)) {
case -1:
- layer->m_params[formatPropertyName(&name)] = value;
+ layer->m_params[formatPropertyName(propertyName)] = value;
break;
case 0: // name
layer->m_params[QStringLiteral("id")] = value;