Skip to content

Commit e516e7c

Browse files
authored
Merge pull request #6786 from signedav/fix_condformat_alpha_BP
Backport to 3.0 Save and load alpha of conditional style color
2 parents 27fa062 + 79256b0 commit e516e7c

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/core/qgsconditionalstyle.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ bool QgsConditionalStyle::writeXml( QDomNode &node, QDomDocument &doc, const Qgs
273273
stylesel.setAttribute( QStringLiteral( "rule" ), mRule );
274274
stylesel.setAttribute( QStringLiteral( "name" ), mName );
275275
stylesel.setAttribute( QStringLiteral( "background_color" ), mBackColor.name() );
276+
stylesel.setAttribute( QStringLiteral( "background_color_alpha" ), mBackColor.alpha() );
276277
stylesel.setAttribute( QStringLiteral( "text_color" ), mTextColor.name() );
278+
stylesel.setAttribute( QStringLiteral( "text_color_alpha" ), mTextColor.alpha() );
277279
QDomElement labelFontElem = QgsFontUtils::toXmlElement( mFont, doc, QStringLiteral( "font" ) );
278280
stylesel.appendChild( labelFontElem );
279281
if ( mSymbol )
@@ -290,8 +292,18 @@ bool QgsConditionalStyle::readXml( const QDomNode &node, const QgsReadWriteConte
290292
QDomElement styleElm = node.toElement();
291293
setRule( styleElm.attribute( QStringLiteral( "rule" ) ) );
292294
setName( styleElm.attribute( QStringLiteral( "name" ) ) );
293-
setBackgroundColor( QColor( styleElm.attribute( QStringLiteral( "background_color" ) ) ) );
294-
setTextColor( QColor( styleElm.attribute( QStringLiteral( "text_color" ) ) ) );
295+
QColor bColor = QColor( styleElm.attribute( QStringLiteral( "background_color" ) ) );
296+
if ( styleElm.hasAttribute( QStringLiteral( "background_color_alpha" ) ) )
297+
{
298+
bColor.setAlpha( styleElm.attribute( QStringLiteral( "background_color_alpha" ) ).toInt() );
299+
}
300+
setBackgroundColor( bColor );
301+
QColor tColor = QColor( styleElm.attribute( QStringLiteral( "text_color" ) ) );
302+
if ( styleElm.hasAttribute( QStringLiteral( "text_color_alpha" ) ) )
303+
{
304+
tColor.setAlpha( styleElm.attribute( QStringLiteral( "text_color_alpha" ) ).toInt() );
305+
}
306+
setTextColor( tColor );
295307
QgsFontUtils::setFromXmlChildNode( mFont, styleElm, QStringLiteral( "font" ) );
296308
QDomElement symbolElm = styleElm.firstChildElement( QStringLiteral( "symbol" ) );
297309
if ( !symbolElm.isNull() )

0 commit comments

Comments
 (0)