[Qt] Use QVariantMap in QQuickMapboxGLStyleProperty
This commit is contained in:
@@ -34,19 +34,6 @@ class Q_DECL_EXPORT QQuickMapboxGL : public QQuickFramebufferObject
|
||||
Q_PROPERTY(qreal pitch READ pitch WRITE setPitch NOTIFY pitchChanged)
|
||||
|
||||
public:
|
||||
struct LayoutPropertyChange {
|
||||
QString layer;
|
||||
QString property;
|
||||
QVariant value;
|
||||
};
|
||||
|
||||
struct PaintPropertyChange {
|
||||
QString layer;
|
||||
QString property;
|
||||
QVariant value;
|
||||
QString klass;
|
||||
};
|
||||
|
||||
QQuickMapboxGL(QQuickItem *parent = 0);
|
||||
virtual ~QQuickMapboxGL();
|
||||
|
||||
@@ -82,8 +69,8 @@ public:
|
||||
|
||||
Q_INVOKABLE void pan(int dx, int dy);
|
||||
|
||||
QList<LayoutPropertyChange>& layoutPropertyChanges() { return m_layoutChanges; }
|
||||
QList<PaintPropertyChange>& paintPropertyChanges() { return m_paintChanges; }
|
||||
QList<QVariantMap>& layoutPropertyChanges() { return m_layoutChanges; }
|
||||
QList<QVariantMap>& paintPropertyChanges() { return m_paintChanges; }
|
||||
|
||||
// MapboxGL QML Type interface.
|
||||
void setStyle(const QString &style);
|
||||
@@ -97,9 +84,6 @@ public:
|
||||
|
||||
QPointF swapPan();
|
||||
|
||||
void setLayoutProperty(const QString &layer, const QString &property, const QVariant &value);
|
||||
void setPaintProperty(const QString &layer, const QString &property, const QVariant &value, const QString &klass = QString());
|
||||
|
||||
enum SyncState {
|
||||
NothingNeedsSync = 0,
|
||||
ZoomNeedsSync = 1 << 0,
|
||||
@@ -142,8 +126,8 @@ private:
|
||||
QGeoCoordinate m_center;
|
||||
QGeoShape m_visibleRegion;
|
||||
QColor m_color;
|
||||
QList<LayoutPropertyChange> m_layoutChanges;
|
||||
QList<PaintPropertyChange> m_paintChanges;
|
||||
QList<QVariantMap> m_layoutChanges;
|
||||
QList<QVariantMap> m_paintChanges;
|
||||
|
||||
QString m_style;
|
||||
qreal m_bearing = 0;
|
||||
|
||||
@@ -35,9 +35,7 @@ protected:
|
||||
QQuickMapboxGLStyleProperty(QQuickItem *parent);
|
||||
virtual void updateParent() = 0;
|
||||
|
||||
QVariant m_layer;
|
||||
QVariant m_property;
|
||||
QVariant m_value;
|
||||
QVariantMap m_map;
|
||||
};
|
||||
|
||||
class Q_DECL_EXPORT QQuickMapboxGLLayoutStyleProperty : public QQuickMapboxGLStyleProperty
|
||||
@@ -67,9 +65,6 @@ signals:
|
||||
|
||||
protected:
|
||||
virtual void updateParent();
|
||||
|
||||
private:
|
||||
QVariant m_class;
|
||||
};
|
||||
|
||||
#endif // QQUICKMAPBOXGLSTYLEPROPERTY_H
|
||||
|
||||
@@ -156,7 +156,12 @@ void QQuickMapboxGL::setColor(const QColor &color)
|
||||
|
||||
m_color = color;
|
||||
|
||||
setPaintProperty("background", "background-color", color);
|
||||
QVariantMap paintProperty;
|
||||
paintProperty["type"] = QQuickMapboxGLLayoutStyleProperty::PaintType;
|
||||
paintProperty["layer"] = "background";
|
||||
paintProperty["property"] = "background-color";
|
||||
paintProperty["value"] = color;
|
||||
onStylePropertyUpdated(paintProperty);
|
||||
|
||||
emit colorChanged(m_color);
|
||||
}
|
||||
@@ -174,18 +179,6 @@ void QQuickMapboxGL::pan(int dx, int dy)
|
||||
update();
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setLayoutProperty(const QString &layer, const QString &property, const QVariant &value)
|
||||
{
|
||||
m_layoutChanges.append(LayoutPropertyChange { layer, property, value });
|
||||
update();
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setPaintProperty(const QString &layer, const QString &property, const QVariant &value, const QString &klass)
|
||||
{
|
||||
m_paintChanges.append(PaintPropertyChange { layer, property, value, klass });
|
||||
update();
|
||||
}
|
||||
|
||||
void QQuickMapboxGL::setStyle(const QString &styleUrl)
|
||||
{
|
||||
if (m_style == styleUrl) {
|
||||
|
||||
@@ -89,14 +89,14 @@ void QQuickMapboxGLRenderer::synchronize(QQuickFramebufferObject *item)
|
||||
if (m_styleLoaded) {
|
||||
if (!quickMap->layoutPropertyChanges().empty()) {
|
||||
for (const auto& change: quickMap->layoutPropertyChanges()) {
|
||||
m_map->setLayoutProperty(change.layer, change.property, change.value);
|
||||
m_map->setLayoutProperty(change.value("layer").toString(), change.value("property").toString(), change.value("value"));
|
||||
}
|
||||
quickMap->layoutPropertyChanges().clear();
|
||||
}
|
||||
|
||||
if (!quickMap->paintPropertyChanges().empty()) {
|
||||
for (const auto& change: quickMap->paintPropertyChanges()) {
|
||||
m_map->setPaintProperty(change.layer, change.property, change.value, change.klass);
|
||||
m_map->setPaintProperty(change.value("layer").toString(), change.value("property").toString(), change.value("value"), change.value("class").toString());
|
||||
}
|
||||
quickMap->paintPropertyChanges().clear();
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ QQuickMapboxGLPaintStyleProperty::QQuickMapboxGLPaintStyleProperty(QQuickItem *p
|
||||
|
||||
void QQuickMapboxGLLayoutStyleProperty::updateParent()
|
||||
{
|
||||
if (m_layer.isNull() || m_property.isNull() || m_value.isNull()) {
|
||||
if (m_map.value("layer").isNull() || m_map.value("property").isNull() || m_map.value("value").isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickMapboxGL *map = qobject_cast<QQuickMapboxGL *>(parentItem());
|
||||
if (map) {
|
||||
map->setLayoutProperty(layer(), property(), m_value);
|
||||
map->setLayoutProperty(layer(), property(), value());
|
||||
} else {
|
||||
qWarning() << "Style property requires QQuickMapboxGL as parent item.";
|
||||
}
|
||||
@@ -32,13 +32,13 @@ void QQuickMapboxGLLayoutStyleProperty::updateParent()
|
||||
|
||||
void QQuickMapboxGLPaintStyleProperty::updateParent()
|
||||
{
|
||||
if (m_layer.isNull() || m_property.isNull() || m_value.isNull()) {
|
||||
if (m_map.value("layer").isNull() || m_map.value("property").isNull() || m_map.value("value").isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QQuickMapboxGL *map = qobject_cast<QQuickMapboxGL *>(parentItem());
|
||||
if (map) {
|
||||
map->setPaintProperty(layer(), property(), m_value, styleClass());
|
||||
map->setPaintProperty(layer(), property(), value(), styleClass());
|
||||
} else {
|
||||
qWarning() << "Style property requires QQuickMapboxGL as parent item.";
|
||||
}
|
||||
@@ -55,64 +55,64 @@ void QQuickMapboxGLStyleProperty::itemChange(QQuickItem::ItemChange change, cons
|
||||
|
||||
void QQuickMapboxGLStyleProperty::setLayer(const QString &layer)
|
||||
{
|
||||
if (layer == m_layer.toString()) {
|
||||
if (m_map.value("layer").toString() == layer) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_layer = layer;
|
||||
m_map["layer"] = layer;
|
||||
emit layerChanged(layer);
|
||||
updateParent();
|
||||
}
|
||||
|
||||
QString QQuickMapboxGLStyleProperty::layer() const
|
||||
{
|
||||
return m_layer.toString();
|
||||
return m_map.value("layer").toString();
|
||||
}
|
||||
|
||||
void QQuickMapboxGLStyleProperty::setProperty(const QString &property)
|
||||
{
|
||||
if (property == m_property.toString()) {
|
||||
if (m_map.value("property").toString() == property) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_property = property;
|
||||
m_map["property"] = property;
|
||||
emit propertyChanged(property);
|
||||
updateParent();
|
||||
}
|
||||
|
||||
QString QQuickMapboxGLStyleProperty::property() const
|
||||
{
|
||||
return m_property.toString();
|
||||
return m_map.value("property").toString();
|
||||
}
|
||||
|
||||
void QQuickMapboxGLStyleProperty::setValue(const QVariant &value)
|
||||
{
|
||||
if (value == m_value) {
|
||||
if (m_map.value("value") == value) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_value = value;
|
||||
m_map["value"] = value;
|
||||
emit valueChanged(value);
|
||||
updateParent();
|
||||
}
|
||||
|
||||
QVariant QQuickMapboxGLStyleProperty::value() const
|
||||
{
|
||||
return m_value;
|
||||
return m_map.value("value");
|
||||
}
|
||||
|
||||
void QQuickMapboxGLPaintStyleProperty::setStyleClass(const QString &styleClass)
|
||||
{
|
||||
if (styleClass == m_class.toString()) {
|
||||
if (m_map.value("class").toString() == styleClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_class = styleClass;
|
||||
m_map["class"] = styleClass;
|
||||
emit classChanged(styleClass);
|
||||
updateParent();
|
||||
}
|
||||
|
||||
QString QQuickMapboxGLPaintStyleProperty::styleClass() const
|
||||
{
|
||||
return m_class.toString();
|
||||
return m_map.value("class").toString();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user