Class: QgsConditionalStyle¶
-
class
qgis.core.
QgsConditionalStyle
¶ Bases:
sip.wrapper
Conditional styling for a rule.
Methods
The background color for style
Compress a list of styles into a single style.
The name of the style.
The font for the style
The icon set for style generated from the set symbol
isValid Check if this rule is valid.
Check if the rule matches using the given value and feature
Find and return the matching style for the value and feature.
Find and return the matching styles for the value and feature.
The name of the style.
Reads vector conditional style specific state from layer Dom node.
Render a preview icon of the rule.
The condition rule set for the style.
Set the background color for the style
Set the font for the style
Set the name of the style.
Set the rule for the style.
Set the icon for the style.
Set the text color for the style
The symbol used to generate the icon for the style
The text color set for style
Check if the background color is valid for render.
Check if the text color is valid for render.
Write vector conditional style specific state from layer Dom node.
-
backgroundColor
(self) → QColor¶ The background color for style
- Return type
QColor
- Returns
QColor for background color
-
compressStyles
(styles: Iterable[QgsConditionalStyle]) → QgsConditionalStyle¶ Compress a list of styles into a single style. This can be used to stack the elements of the styles. The font of the last style is used in the output.
- Parameters
styles (Iterable[QgsConditionalStyle]) – The list of styles to compress down
- Return type
- Returns
A single style generated from joining each style property.
-
displayText
(self) → str¶ The name of the style.
- Return type
str
- Returns
The name of the style. Names are optional so might be empty.
-
font
(self) → QFont¶ The font for the style
- Return type
QFont
- Returns
QFont for the style
-
icon
(self) → QPixmap¶ The icon set for style generated from the set symbol
- Return type
QPixmap
- Returns
A QPixmap that was set for the icon using the symbol
-
isValid
(self) → bool¶ isValid Check if this rule is valid. A valid rule has one or more properties set.
- Return type
bool
- Returns
True if the rule is valid.
-
matches
(self, value: Any, context: QgsExpressionContext) → bool¶ Check if the rule matches using the given value and feature
- Parameters
value (Any) – The current value being checked. The “value” variable from the context is replaced with this value.
context (QgsExpressionContext) – Expression context for evaluating rule expression
- Return type
bool
- Returns
True of the rule matches against the given feature
-
matchingConditionalStyle
(styles: Iterable[QgsConditionalStyle], value: Any, context: QgsExpressionContext) → QgsConditionalStyle¶ Find and return the matching style for the value and feature. If no match is found a invalid
QgsConditionalStyle
is return.- Return type
- Returns
A conditional style that matches the value and feature. Check with
QgsConditionalStyle.isValid()
- Parameters
styles (Iterable[QgsConditionalStyle]) –
value (Any) –
context (QgsExpressionContext) –
-
matchingConditionalStyles
(styles: Iterable[QgsConditionalStyle], value: Any, context: QgsExpressionContext) → List[QgsConditionalStyle]¶ Find and return the matching styles for the value and feature. If no match is found a invalid
QgsConditionalStyle
is return.- Return type
List[QgsConditionalStyle]
- Returns
A conditional style that matches the value and feature. Check with
QgsConditionalStyle.isValid()
- Parameters
styles (Iterable[QgsConditionalStyle]) –
value (Any) –
context (QgsExpressionContext) –
-
name
(self) → str¶ The name of the style.
- Return type
str
- Returns
The name of the style. Names are optional so might be empty.
-
readXml
(self, node: QDomNode, context: QgsReadWriteContext) → bool¶ Reads vector conditional style specific state from layer Dom node.
- Parameters
node (QDomNode) –
context (QgsReadWriteContext) –
- Return type
bool
-
renderPreview
(self) → QPixmap¶ Render a preview icon of the rule.
- Return type
QPixmap
- Returns
QPixmap preview of the style
-
rule
(self) → str¶ The condition rule set for the style. Rule may contain variable @value to represent the current value
- Return type
str
- Returns
QString of the current set rule
-
setBackgroundColor
(self, value: Union[QColor, Qt.GlobalColor, QGradient])¶ Set the background color for the style
- Parameters
value (Union[QColor) – QColor for background color
-
setFont
(self, value: QFont)¶ Set the font for the style
- Parameters
value (QFont) – QFont to be used for text
-
setName
(self, value: str)¶ Set the name of the style. Names are optional but handy for display
- Parameters
value (str) – The name given to the style
-
setRule
(self, value: str)¶ Set the rule for the style. Rules should be of
QgsExpression
syntax. Special value of @value is replaced at run time with the check value- Parameters
value (str) – The
QgsExpression
style rule to use for this style
-
setSymbol
(self, value: QgsSymbol)¶ Set the icon for the style. Icons are generated from symbols
-
setTextColor
(self, value: Union[QColor, Qt.GlobalColor, QGradient])¶ Set the text color for the style
- Parameters
value (Union[QColor) – QColor for text color
-
symbol
(self) → QgsSymbol¶ The symbol used to generate the icon for the style
-
textColor
(self) → QColor¶ The text color set for style
- Return type
QColor
- Returns
QColor for text color
-
validBackgroundColor
(self) → bool¶ Check if the background color is valid for render. Valid colors are non invalid QColors and a color with a > 0 alpha
- Return type
bool
- Returns
True of the color set for background is valid.
-
validTextColor
(self) → bool¶ Check if the text color is valid for render. Valid colors are non invalid QColors and a color with a > 0 alpha
- Return type
bool
- Returns
True of the color set for text is valid.
-
writeXml
(self, node: QDomNode, doc: QDomDocument, context: QgsReadWriteContext) → bool¶ Write vector conditional style specific state from layer Dom node.
- Parameters
node (QDomNode) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
-