Class: QgsConditionalStyle¶
Conditional styling for a rule.
Methods
The background color for 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 |
|
The name of the style. |
|
Reads vector conditional style specific state from layer Dom node. |
|
Render a preview icon of the rule, at the specified size. |
|
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. |
Static Methods
Compress a list of styles into a single style. |
|
Find and return the matching style for the value and feature. |
|
Find and return the matching styles for the value and feature. |
- class qgis.core.QgsConditionalStyle[source]¶
Bases:
object
- backgroundColor(self) QColor [source]¶
The background color for style
- Return type:
QColor
- Returns:
QColor for background color
- static compressStyles(styles: Iterable[QgsConditionalStyle]) QgsConditionalStyle [source]¶
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 [source]¶
The name of the style.
- Return type:
str
- Returns:
The name of the style. Names are optional so might be empty.
- icon(self) QPixmap [source]¶
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 [source]¶
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 [source]¶
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
- static matchingConditionalStyle(styles: Iterable[QgsConditionalStyle], value: Any, context: QgsExpressionContext) QgsConditionalStyle [source]¶
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)
- static 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 [source]¶
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 [source]¶
Reads vector conditional style specific state from layer Dom node.
- Parameters:
node (QDomNode)
context (QgsReadWriteContext)
- Return type:
bool
- renderPreview(self, size: QSize = QSize()) QPixmap [source]¶
Render a preview icon of the rule, at the specified
size
.If
size
is not specified, a default size will be used.- Return type:
QPixmap
- Returns:
QPixmap preview of the style
- Parameters:
size (QSize = QSize())
- rule(self) str [source]¶
The condition rule set for the style. Rule may contain variable @value to represent the current value
- Return type:
str
- Returns:
string of the current set rule
- setBackgroundColor(self, value: QColor | Qt.GlobalColor)[source]¶
Set the background color for the style
- Parameters:
value (Union[QColor, Qt.GlobalColor]) – QColor for background color
- setFont(self, value: QFont)[source]¶
Set the font for the style
- Parameters:
value (QFont) – QFont to be used for text
- setName(self, value: str | None)[source]¶
Set the name of the style. Names are optional but handy for display
- Parameters:
value (Optional[str]) – The name given to the style
- setRule(self, value: str | None)[source]¶
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 (Optional[str]) – The
QgsExpression
style rule to use for this style
- setSymbol(self, value: QgsSymbol | None)[source]¶
Set the icon for the style. Icons are generated from symbols
- setTextColor(self, value: QColor | Qt.GlobalColor)[source]¶
Set the text color for the style
- Parameters:
value (Union[QColor, Qt.GlobalColor]) – QColor for text color
- textColor(self) QColor [source]¶
The text color set for style
- Return type:
QColor
- Returns:
QColor for text color
- validBackgroundColor(self) bool [source]¶
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 [source]¶
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 [source]¶
Write vector conditional style specific state from layer Dom node.
- Parameters:
node (QDomNode)
doc (QDomDocument)
context (QgsReadWriteContext)
- Return type:
bool