Skip to content
Permalink
Browse files

use flexibility of QVariant to save/load SVG parameters

  • Loading branch information
3nids committed Jan 6, 2021
1 parent 2e90da4 commit 98e0cd58560ea8efb732e93bf1e316a2854728b4
Showing with 21 additions and 10 deletions.
  1. +21 −10 src/core/symbology/qgsmarkersymbollayer.cpp
@@ -26,6 +26,7 @@
#include "qgslogger.h"
#include "qgssvgcache.h"
#include "qgsunittypes.h"
#include "qgsxmlutils.h"

#include <QPainter>
#include <QSvgRenderer>
@@ -1881,7 +1882,20 @@ QgsSymbolLayer *QgsSvgMarkerSymbolLayer::create( const QVariantMap &props )

m->updateDefaultAspectRatio();

m->setParameters( QgsSymbolLayerUtils::readSerializedProperties( props ) );
if ( props.contains( QStringLiteral( "parameters" ) ) )
{
const QVariantMap parameters = props[QStringLiteral( "parameters" )].toMap();
QMap<QString, QgsProperty> parametersProperties;
QVariantMap::const_iterator it = parameters.constBegin();
for ( ; it != parameters.constEnd(); ++it )
{
QgsProperty property;
if ( property.loadVariant( it.value() ) )
parametersProperties.insert( it.key(), property );
}

m->setParameters( parametersProperties );
}

return m;
}
@@ -2260,15 +2274,12 @@ QVariantMap QgsSvgMarkerSymbolLayer::properties() const
map[QStringLiteral( "outline_width_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mStrokeWidthMapUnitScale );
map[QStringLiteral( "horizontal_anchor_point" )] = QString::number( mHorizontalAnchorPoint );
map[QStringLiteral( "vertical_anchor_point" )] = QString::number( mVerticalAnchorPoint );
const QgsStringMap serializedParameters = QgsSymbolLayerUtils::serializeProperties( mParameters );
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
for ( QgsStringMap::const_iterator parameterIt = serializedParameters.constBegin(); parameterIt != serializedParameters.constEnd(); ++parameterIt )
{
map.insert( parameterIt.key(), parameterIt.value() );
}
#else
map.insert( serializedParameters );
#endif

QVariantMap parameters;
QMap<QString, QgsProperty>::const_iterator it = mParameters.constBegin();
for ( ; it != mParameters.constEnd(); ++it )
parameters.insert( it.key(), it.value().toVariant() );
map[QStringLiteral( "vertical_anchor_point" )] = parameters;

return map;
}

0 comments on commit 98e0cd5

Please sign in to comment.
You can’t perform that action at this time.