QgsConditionalStyle class

Conditional styling for a rule.

Public static functions

static auto compressStyles(const QList<QgsConditionalStyle>& styles) -> QgsConditionalStyle
Compress a list of styles into a single style.
static auto matchingConditionalStyle(const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context) -> QgsConditionalStyle
Find and return the matching style for the value and feature.
static auto matchingConditionalStyles(const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context) -> QList<QgsConditionalStyle>
Find and return the matching styles for the value and feature.

Public functions

auto backgroundColor() const -> QColor
The background color for style.
auto displayText() const -> QString
The name of the style.
auto font() const -> QFont
The font for the style.
auto icon() const -> QPixmap
The icon set for style generated from the set symbol.
auto isValid() const -> bool
isValid Check if this rule is valid.
auto matches(const QVariant& value, QgsExpressionContext& context) const -> bool
Check if the rule matches using the given value and feature.
auto name() const -> QString
The name of the style.
auto readXml(const QDomNode& node, const QgsReadWriteContext& context) -> bool
Reads vector conditional style specific state from layer Dom node.
auto renderPreview() const -> QPixmap
Render a preview icon of the rule.
auto rule() const -> QString
The condition rule set for the style.
void setBackgroundColor(const QColor& value)
Set the background color for the style.
void setFont(const QFont& value)
Set the font for the style.
void setName(const QString& value)
Set the name of the style.
void setRule(const QString& value)
Set the rule for the style.
void setSymbol(QgsSymbol* value)
Set the icon for the style.
void setTextColor(const QColor& value)
Set the text color for the style.
auto symbol() const -> QgsSymbol*
The symbol used to generate the icon for the style.
auto textColor() const -> QColor
The text color set for style.
auto validBackgroundColor() const -> bool
Check if the background color is valid for render.
auto validTextColor() const -> bool
Check if the text color is valid for render.
auto writeXml(QDomNode& node, QDomDocument& doc, const QgsReadWriteContext& context) const -> bool
Write vector conditional style specific state from layer Dom node.

Function documentation

static QgsConditionalStyle QgsConditionalStyle::compressStyles(const QList<QgsConditionalStyle>& styles)

Compress a list of styles into a single style.

Parameters
styles The list of styles to compress down
Returns A single style generated from joining each style property.

This can be used to stack the elements of the styles. The font of the last style is used in the output.

static QgsConditionalStyle QgsConditionalStyle::matchingConditionalStyle(const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context)

Find and return the matching style for the value and feature.

Returns A conditional style that matches the value and feature. Check with QgsConditionalStyle::isValid()

If no match is found a invalid QgsConditionalStyle is return.

static QList<QgsConditionalStyle> QgsConditionalStyle::matchingConditionalStyles(const QList<QgsConditionalStyle>& styles, const QVariant& value, QgsExpressionContext& context)

Find and return the matching styles for the value and feature.

Returns A conditional style that matches the value and feature. Check with QgsConditionalStyle::isValid()

If no match is found a invalid QgsConditionalStyle is return.

QColor QgsConditionalStyle::backgroundColor() const

The background color for style.

Returns QColor for background color

QString QgsConditionalStyle::displayText() const

The name of the style.

Returns The name of the style. Names are optional so might be empty.

QFont QgsConditionalStyle::font() const

The font for the style.

Returns QFont for the style

QPixmap QgsConditionalStyle::icon() const

The icon set for style generated from the set symbol.

Returns A QPixmap that was set for the icon using the symbol

bool QgsConditionalStyle::isValid() const

isValid Check if this rule is valid.

Returns True if the rule is valid.

A valid rule has one or more properties set.

bool QgsConditionalStyle::matches(const QVariant& value, QgsExpressionContext& context) const

Check if the rule matches using the given value and feature.

Parameters
value The current value being checked. The "value" variable from the context is replaced with this value.
context Expression context for evaluating rule expression
Returns True of the rule matches against the given feature

QString QgsConditionalStyle::name() const

The name of the style.

Returns The name of the style. Names are optional so might be empty.

QPixmap QgsConditionalStyle::renderPreview() const

Render a preview icon of the rule.

Returns QPixmap preview of the style

QString QgsConditionalStyle::rule() const

The condition rule set for the style.

Returns QString of the current set rule

Rule may contain variable @value to represent the current value

void QgsConditionalStyle::setBackgroundColor(const QColor& value)

Set the background color for the style.

Parameters
value QColor for background color

void QgsConditionalStyle::setFont(const QFont& value)

Set the font for the style.

Parameters
value QFont to be used for text

void QgsConditionalStyle::setName(const QString& value)

Set the name of the style.

Parameters
value The name given to the style

Names are optional but handy for display

void QgsConditionalStyle::setRule(const QString& value)

Set the rule for the style.

Parameters
value The QgsExpression style rule to use for this style

Rules should be of QgsExpression syntax. Special value of @value is replaced at run time with the check value

void QgsConditionalStyle::setSymbol(QgsSymbol* value)

Set the icon for the style.

Parameters
value QgsSymbol to be used when generating the icon

Icons are generated from symbols

void QgsConditionalStyle::setTextColor(const QColor& value)

Set the text color for the style.

Parameters
value QColor for text color

QgsSymbol* QgsConditionalStyle::symbol() const

The symbol used to generate the icon for the style.

Returns The QgsSymbol used for the icon

QColor QgsConditionalStyle::textColor() const

The text color set for style.

Returns QColor for text color

bool QgsConditionalStyle::validBackgroundColor() const

Check if the background color is valid for render.

Returns True of the color set for background is valid.

Valid colors are non invalid QColors and a color with a > 0 alpha

bool QgsConditionalStyle::validTextColor() const

Check if the text color is valid for render.

Returns True of the color set for text is valid.

Valid colors are non invalid QColors and a color with a > 0 alpha