Skip to content

Commit 495246f

Browse files
committed
fix transparency saving on QML file (follow 74ba70a):
do not store the same transparency value twice (for both SimpleFill symbol and its layers)
1 parent 1dfb3b3 commit 495246f

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/core/qgsmaplayer.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "qgscoordinatereferencesystem.h"
3838
#include "qgsapplication.h"
3939
#include "qgsproject.h"
40+
#include "qgsprojectfiletransform.h"
4041
#include "qgsdatasourceuri.h"
4142
#include "qgsvectorlayer.h"
4243

@@ -778,6 +779,26 @@ QString QgsMapLayer::loadNamedStyle( const QString theURI, bool &theResultFlag )
778779
return myErrorMessage;
779780
}
780781

782+
// get style file version string, if any
783+
QgsProjectVersion fileVersion( myDocument.firstChildElement( "qgis" ).attribute( "version" ) );
784+
QgsProjectVersion thisVersion( QGis::QGIS_VERSION );
785+
786+
if ( thisVersion > fileVersion )
787+
{
788+
QgsLogger::warning( "Loading a style file that was saved with an older "
789+
"version of qgis (saved in " + fileVersion.text() +
790+
", loaded in " + QGis::QGIS_VERSION +
791+
"). Problems may occur." );
792+
793+
QgsProjectFileTransform styleFile( myDocument, fileVersion );
794+
795+
styleFile.dump();
796+
797+
styleFile.updateRevision( thisVersion );
798+
799+
styleFile.dump();
800+
}
801+
781802
// now get the layer node out and pass it over to the layer
782803
// to deserialise...
783804
QDomElement myRoot = myDocument.firstChildElement( "qgis" );

src/core/qgsprojectfiletransform.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,31 @@ void QgsProjectFileTransform::transform1800to1900()
531531
}
532532
}
533533

534+
// SimpleFill symbol layer v2: avoid double transparency
535+
// replacing alpha value of symbol layer's color with 255 (the
536+
// transparency value is already stored as symbol transparency).
537+
QDomNodeList rendererList = mDom.elementsByTagName( "renderer-v2" );
538+
for ( int i = 0; i < rendererList.size(); ++i )
539+
{
540+
QDomNodeList layerList = rendererList.at( i ).toElement().elementsByTagName( "layer" );
541+
for ( int j = 0; j < layerList.size(); ++j )
542+
{
543+
QDomElement layerElem = layerList.at( j ).toElement();
544+
if ( layerElem.attribute( "class" ) == "SimpleFill" )
545+
{
546+
QDomNodeList propList = layerElem.elementsByTagName( "prop" );
547+
for ( int k = 0; k < propList.size(); ++k )
548+
{
549+
QDomElement propElem = propList.at( k ).toElement();
550+
if ( propElem.attribute( "k" ) == "color" || propElem.attribute( "k" ) == "color_border" )
551+
{
552+
propElem.setAttribute( "v", propElem.attribute( "v" ).section( ",", 0, 2 ) + ",255" );
553+
}
554+
}
555+
}
556+
}
557+
}
558+
534559
QgsDebugMsg( mDom.toString() );
535560
}
536561

0 commit comments

Comments
 (0)