Skip to content
Permalink
Browse files

Save layer blend mode and opacity for additional layer types

  • Loading branch information
nyalldawson committed Nov 13, 2020
1 parent 0056bb1 commit 1936fa03133ebd7e0fbb0e7d8ff51061759fdcd7
@@ -20,6 +20,7 @@
#include "qgsannotationitemregistry.h"
#include "qgsapplication.h"
#include "qgslogger.h"
#include "qgspainting.h"
#include <QUuid>

QgsAnnotationLayer::QgsAnnotationLayer( const QString &name, const LayerOptions &options )
@@ -195,6 +196,16 @@ bool QgsAnnotationLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QStr
layerOpacityElem.appendChild( layerOpacityText );
node.appendChild( layerOpacityElem );
}

if ( categories.testFlag( Symbology ) )
{
// add the blend mode field
QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
QDomText blendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
blendModeElem.appendChild( blendModeText );
node.appendChild( blendModeElem );
}

return true;
}

@@ -209,5 +220,17 @@ bool QgsAnnotationLayer::readSymbology( const QDomNode &node, QString &, QgsRead
setOpacity( e.text().toDouble() );
}
}

if ( categories.testFlag( Symbology ) )
{
// get and set the blend mode if it exists
QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
}
}

return true;
}
@@ -1056,6 +1056,17 @@ bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,
setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
}

// get and set the layer transparency
if ( categories.testFlag( Rendering ) )
{
QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
if ( !layerOpacityNode.isNull() )
{
QDomElement e = layerOpacityNode.toElement();
setOpacity( e.text().toDouble() );
}
}

return true;
}

@@ -1081,6 +1092,15 @@ bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &e
blendModeElement.appendChild( blendModeText );
node.appendChild( blendModeElement );

// add the layer opacity
if ( categories.testFlag( Rendering ) )
{
QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
layerOpacityElem.appendChild( layerOpacityText );
node.appendChild( layerOpacityElem );
}

return true;
}

@@ -182,14 +182,12 @@ bool QgsPointCloudLayer::readStyle( const QDomNode &node, QString &, QgsReadWrit
// get and set the layer transparency and scale visibility if they exists
if ( categories.testFlag( Rendering ) )
{
#if 0 // TODO
QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
if ( !layerOpacityNode.isNull() )
{
QDomElement e = layerOpacityNode.toElement();
setOpacity( e.text().toDouble() );
}
#endif

const bool hasScaleBasedVisibiliy { node.attributes().namedItem( QStringLiteral( "hasScaleBasedVisibilityFlag" ) ).nodeValue() == '1' };
setScaleBasedVisibility( hasScaleBasedVisibiliy );
@@ -252,12 +250,11 @@ bool QgsPointCloudLayer::writeStyle( QDomNode &node, QDomDocument &doc, QString
// add the layer opacity and scale visibility
if ( categories.testFlag( Rendering ) )
{
#if 0 // TODO
QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
layerOpacityElem.appendChild( layerOpacityText );
node.appendChild( layerOpacityElem );
#endif

mapLayerNode.setAttribute( QStringLiteral( "hasScaleBasedVisibilityFlag" ), hasScaleBasedVisibility() ? 1 : 0 );
mapLayerNode.setAttribute( QStringLiteral( "maxScale" ), maximumScale() );
mapLayerNode.setAttribute( QStringLiteral( "minScale" ), minimumScale() );
@@ -30,6 +30,7 @@
#include "qgsblockingnetworkrequest.h"
#include "qgsmapboxglstyleconverter.h"
#include "qgsjsonutils.h"
#include "qgspainting.h"

QgsVectorTileLayer::QgsVectorTileLayer( const QString &uri, const QString &baseName )
: QgsMapLayer( QgsMapLayerType::VectorTileLayer, baseName )
@@ -265,6 +266,28 @@ bool QgsVectorTileLayer::readSymbology( const QDomNode &node, QString &errorMess
}
}

if ( categories.testFlag( Symbology ) )
{
// get and set the blend mode if it exists
QDomNode blendModeNode = node.namedItem( QStringLiteral( "blendMode" ) );
if ( !blendModeNode.isNull() )
{
QDomElement e = blendModeNode.toElement();
setBlendMode( QgsPainting::getCompositionMode( static_cast< QgsPainting::BlendMode >( e.text().toInt() ) ) );
}
}

// get and set the layer transparency
if ( categories.testFlag( Rendering ) )
{
QDomNode layerOpacityNode = node.namedItem( QStringLiteral( "layerOpacity" ) );
if ( !layerOpacityNode.isNull() )
{
QDomElement e = layerOpacityNode.toElement();
setOpacity( e.text().toDouble() );
}
}

return true;
}

@@ -294,6 +317,24 @@ bool QgsVectorTileLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QStr
elem.appendChild( elemLabeling );
}

if ( categories.testFlag( Symbology ) )
{
// add the blend mode field
QDomElement blendModeElem = doc.createElement( QStringLiteral( "blendMode" ) );
QDomText blendModeText = doc.createTextNode( QString::number( QgsPainting::getBlendModeEnum( blendMode() ) ) );
blendModeElem.appendChild( blendModeText );
node.appendChild( blendModeElem );
}

// add the layer opacity
if ( categories.testFlag( Rendering ) )
{
QDomElement layerOpacityElem = doc.createElement( QStringLiteral( "layerOpacity" ) );
QDomText layerOpacityText = doc.createTextNode( QString::number( opacity() ) );
layerOpacityElem.appendChild( layerOpacityText );
node.appendChild( layerOpacityElem );
}

return true;
}

0 comments on commit 1936fa0

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