Class: QgsMapLayerStyleManager¶
- class qgis.core.QgsMapLayerStyleManager¶
Bases:
PyQt5.QtCore.QObject
Management of styles for use with one map layer
Stored styles are identified by their names. The manager always keep track of which style of the stored ones is currently active. When the current style is changed, the new style is applied to the associated layer.
The class takes care of updating itself when the layer’s current style configuration changes. When some of layer style’s properties change (e.g. opacity / colors), the style manager will record them in the currently active style without any extra effort required.
When an instance is created, it creates “default” style (with empty name) recorded from the associated map layer and it is set as the current style. The instance must always contain at least one style (which is the current).
The style which is marked as current has no style data stored in its entry. This is to avoid duplication of data as all data is stored in map layer and can be retrieved easily. Also when saving, the entry for the current style will be saved with no data because everything is already saved by the map layer itself.
The class also features support for temporary change of the layer’s style, ideal for short-term use of a custom style followed by restoration of the original style (for example, when rendering a map with a different than current style).
QgsMapLayerStyleManager(layer:
QgsMapLayer
) Construct a style manager associated with a map layer (must not beNone
). The style manager will be parented tolayer
.Methods
Add a style with given name and data
Add style by cloning the current one
Copies all styles from
other
.Returns name of the current style
Returns
True
if this is the default styleGets pointer to the associated map layer
Gets available styles for the associated map layer.
Read configuration (for project loading)
Remove a stored style
Rename a stored style to a different name
Reset the style manager to a basic state - with one default style which is set as current
Restore the original store after a call to
setOverrideStyle()
Set a different style as the current style - will apply it to the layer
Temporarily apply a different style to the layer.
Returns data of a stored style - accessed by its unique name
Returns list of all defined style names
Write configuration (for project saving)
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
- addStyle(self, name: str, style: QgsMapLayerStyle) bool ¶
Add a style with given name and data
- Return type:
bool
- Returns:
True
on success (name is unique and style is valid)- Parameters:
name (str) –
style (QgsMapLayerStyle) –
- addStyleFromLayer(self, name: str) bool ¶
Add style by cloning the current one
- Return type:
bool
- Returns:
True
on success- Parameters:
name (str) –
- childEvent(self, QChildEvent)¶
- connectNotify(self, QMetaMethod)¶
- copyStylesFrom(self, other: QgsMapLayerStyleManager)¶
Copies all styles from
other
. In case there is already a style with the same name it will be overwritten.New in version 3.14.
- Parameters:
other (QgsMapLayerStyleManager) –
- currentStyle(self) str ¶
Returns name of the current style
- Return type:
str
- currentStyleChanged¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- isDefault(styleName: str) bool ¶
Returns
True
if this is the default style- Parameters:
styleName (str) –
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- layer(self) QgsMapLayer ¶
Gets pointer to the associated map layer
- Return type:
- mapLayerStyles(self) Dict[str, QgsMapLayerStyle] ¶
Gets available styles for the associated map layer.
- Return type:
Dict[str, QgsMapLayerStyle]
- Returns:
A map of map layer style by style name
- readXml(self, mgrElement: QDomElement)¶
Read configuration (for project loading)
- Parameters:
mgrElement (QDomElement) –
- receivers(self, PYQT_SIGNAL) int ¶
- removeStyle(self, name: str) bool ¶
Remove a stored style
- Return type:
bool
- Returns:
True
on success (style exists and it is not the last one)- Parameters:
name (str) –
- renameStyle(self, name: str, newName: str) bool ¶
Rename a stored style to a different name
- Return type:
bool
- Returns:
True
on success (style exists and new name is unique)- Parameters:
name (str) –
newName (str) –
- reset(self)¶
Reset the style manager to a basic state - with one default style which is set as current
- restoreOverrideStyle(self) bool ¶
Restore the original store after a call to
setOverrideStyle()
- Return type:
bool
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setCurrentStyle(self, name: str) bool ¶
Set a different style as the current style - will apply it to the layer
- Return type:
bool
- Returns:
True
on success- Parameters:
name (str) –
- setOverrideStyle(self, styleDef: str) bool ¶
Temporarily apply a different style to the layer. The argument can be either a style name or a full QML style definition. Each call must be paired with
restoreOverrideStyle()
- Parameters:
styleDef (str) –
- Return type:
bool
- style(self, name: str) QgsMapLayerStyle ¶
Returns data of a stored style - accessed by its unique name
- Parameters:
name (str) –
- Return type:
- styleAdded¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- styleRemoved¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- styleRenamed¶
pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL
types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.
- Parameters:
name (str = ...) –
revision (int = ...) –
arguments (Sequence = ...) –
- Return type:
PYQT_SIGNAL
- styles(self) List[str] ¶
Returns list of all defined style names
- Return type:
List[str]
- timerEvent(self, QTimerEvent)¶
- writeXml(self, mgrElement: QDomElement)¶
Write configuration (for project saving)
- Parameters:
mgrElement (QDomElement) –