Skip to content

Commit 5c94f89

Browse files
committed
Save and load alpha of conditional style color
Alpha (saturation) will be saved and loaded for the conditional style color of text and background. Before there was not only the problem, that it was not saved - it was additional the issue, that background with no color had after reopening the project the alpha(saturation) of FF and the color black. This is fixed now.
1 parent 3183107 commit 5c94f89

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/core/qgsconditionalstyle.cpp

Lines changed: 14 additions & 2 deletions
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( "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( "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)