35 if ( styles == mRowStyles )
44 if ( mFieldStyles.value( fieldName ) == styles )
47 mFieldStyles.insert( fieldName, styles );
53 return mFieldStyles.value( fieldName );
58 QDomElement stylesel = doc.createElement( QStringLiteral(
"conditionalstyles" ) );
59 QDomElement rowel = doc.createElement( QStringLiteral(
"rowstyles" ) );
60 const auto constMRowStyles = mRowStyles;
63 style.writeXml( rowel, doc, context );
66 stylesel.appendChild( rowel );
68 QDomElement fieldsel = doc.createElement( QStringLiteral(
"fieldstyles" ) );
69 QHash<QString, QgsConditionalStyles>::const_iterator it = mFieldStyles.constBegin();
70 for ( ; it != mFieldStyles.constEnd(); ++it )
72 QDomElement fieldel = doc.createElement( QStringLiteral(
"fieldstyle" ) );
73 fieldel.setAttribute( QStringLiteral(
"fieldname" ), it.key() );
75 const auto constStyles = styles;
78 style.writeXml( fieldel, doc, context );
80 fieldsel.appendChild( fieldel );
83 stylesel.appendChild( fieldsel );
85 node.appendChild( stylesel );
103 const QDomElement condel = node.firstChildElement( QStringLiteral(
"conditionalstyles" ) );
105 mFieldStyles.clear();
106 const QDomElement rowstylesel = condel.firstChildElement( QStringLiteral(
"rowstyles" ) );
107 QDomNodeList nodelist = rowstylesel.toElement().elementsByTagName( QStringLiteral(
"style" ) );
108 for (
int i = 0; i < nodelist.count(); i++ )
110 const QDomElement styleElm = nodelist.at( i ).toElement();
112 style.
readXml( styleElm, context );
113 mRowStyles.append( style );
116 const QDomElement fieldstylesel = condel.firstChildElement( QStringLiteral(
"fieldstyles" ) );
117 nodelist = fieldstylesel.toElement().elementsByTagName( QStringLiteral(
"fieldstyle" ) );
118 QList<QgsConditionalStyle> styles;
119 for (
int i = 0; i < nodelist.count(); i++ )
122 const QDomElement fieldel = nodelist.at( i ).toElement();
123 const QString fieldName = fieldel.attribute( QStringLiteral(
"fieldname" ) );
124 const QDomNodeList stylenodelist = fieldel.toElement().elementsByTagName( QStringLiteral(
"style" ) );
125 styles.reserve( stylenodelist.count() );
126 for (
int j = 0; j < stylenodelist.count(); j++ )
128 const QDomElement styleElm = stylenodelist.at( j ).toElement();
130 style.
readXml( styleElm, context );
131 styles.append( style );
133 mFieldStyles.insert( fieldName, styles );
150 : mValid( other.mValid )
151 , mName( other.mName )
152 , mRule( other.mRule )
153 , mFont( other.mFont )
154 , mBackColor( other.mBackColor )
155 , mTextColor( other.mTextColor )
156 , mIcon( other.mIcon )
159 mSymbol.reset( other.mSymbol->clone() );
164 mValid = other.mValid;
167 mBackColor = other.mBackColor;
168 mTextColor = other.mTextColor;
173 mSymbol.reset( other.mSymbol->clone() );
184 if (
name().isEmpty() )
187 return QStringLiteral(
"%1 \n%2" ).arg(
name(),
rule() );
195 mSymbol.reset( value->
clone() );
208 return exp.
evaluate( &context ).toBool();
213 QPixmap pixmap( size.isValid() ? size.width() : 64, size.isValid() ? size.height() : 32 );
214 pixmap.fill( Qt::transparent );
216 QPainter painter( &pixmap );
219 painter.setBrush( mBackColor );
221 QRect rect = QRect( 0, 0, pixmap.width(), pixmap.height() );
222 painter.setPen( Qt::NoPen );
223 painter.drawRect( rect );
224 const QPixmap symbolIcon =
icon();
225 if ( !symbolIcon.isNull() )
227 painter.drawPixmap( ( pixmap.width() / 3 - symbolIcon.width() ) / 2, ( pixmap.height() - symbolIcon.height() ) / 2, symbolIcon );
231 painter.setPen( mTextColor );
233 painter.setPen( Qt::black );
235 painter.setRenderHint( QPainter::Antialiasing );
236 painter.setFont(
font() );
237 rect = QRect( pixmap.width() / 3, 0, 2 * pixmap.width() / 3, pixmap.height() );
238 painter.drawText( rect, Qt::AlignCenter, QStringLiteral(
"abc\n123" ) );
255 QList<QgsConditionalStyle> matchingstyles;
256 const auto constStyles = styles;
259 if ( style.matches( value, context ) )
260 matchingstyles.append( style );
262 return matchingstyles;
267 const auto constStyles = styles;
270 if ( style.matches( value, context ) )
285 if ( s.backgroundColor().isValid() && s.backgroundColor().alpha() != 0 )
287 if ( s.textColor().isValid() && s.textColor().alpha() != 0 )
289 if (
auto *lSymbol = s.symbol() )
297 QDomElement stylesel = doc.createElement( QStringLiteral(
"style" ) );
298 stylesel.setAttribute( QStringLiteral(
"rule" ), mRule );
299 stylesel.setAttribute( QStringLiteral(
"name" ), mName );
300 if ( mBackColor.isValid() )
302 stylesel.setAttribute( QStringLiteral(
"background_color" ), mBackColor.name() );
303 stylesel.setAttribute( QStringLiteral(
"background_color_alpha" ), mBackColor.alpha() );
305 if ( mTextColor.isValid() )
307 stylesel.setAttribute( QStringLiteral(
"text_color" ), mTextColor.name() );
308 stylesel.setAttribute( QStringLiteral(
"text_color_alpha" ), mTextColor.alpha() );
311 stylesel.appendChild( labelFontElem );
315 stylesel.appendChild( symbolElm );
317 node.appendChild( stylesel );
323 return mValid == other.mValid
324 && mName == other.mName
325 && mRule == other.mRule
326 && mFont == other.mFont
327 && mBackColor == other.mBackColor
328 && mTextColor == other.mTextColor
329 &&
static_cast< bool >( mSymbol ) ==
static_cast< bool >( other.mSymbol )
335 return !( *
this == other );
340 const QDomElement styleElm = node.toElement();
341 setRule( styleElm.attribute( QStringLiteral(
"rule" ) ) );
342 setName( styleElm.attribute( QStringLiteral(
"name" ) ) );
343 if ( styleElm.hasAttribute( QStringLiteral(
"background_color" ) ) )
345 QColor bColor = QColor( styleElm.attribute( QStringLiteral(
"background_color" ) ) );
346 if ( styleElm.hasAttribute( QStringLiteral(
"background_color_alpha" ) ) )
348 bColor.setAlpha( styleElm.attribute( QStringLiteral(
"background_color_alpha" ) ).toInt() );
350 if ( bColor.alpha() == 0 )
359 if ( styleElm.hasAttribute( QStringLiteral(
"text_color" ) ) )
361 QColor tColor = QColor( styleElm.attribute( QStringLiteral(
"text_color" ) ) );
362 if ( styleElm.hasAttribute( QStringLiteral(
"text_color_alpha" ) ) )
364 tColor.setAlpha( styleElm.attribute( QStringLiteral(
"text_color_alpha" ) ).toInt() );
366 if ( tColor.alpha() == 0 )
376 const QDomElement symbolElm = styleElm.firstChildElement( QStringLiteral(
"symbol" ) );
377 if ( !symbolElm.isNull() )
379 QgsSymbol *
symbol = QgsSymbolLayerUtils::loadSymbol<QgsMarkerSymbol>( symbolElm, context );