Class: QgsMapThemeCollection¶
- class qgis.core.QgsMapThemeCollection¶
Bases:
PyQt5.QtCore.QObject
Container class that allows storage of map themes consisting of visible map layers and layer styles.
New in version 2.12.
QgsMapThemeCollection(project:
QgsProject
= None) Create map theme collection that handles themes of the given project.Methods
Apply theme given by its name and modify layer tree, current style of layers and checked legend items of passed layer tree model.
Removes all map themes from the collection.
Static method to create theme from the current state of layer visibilities in layer tree, current style of layers and check state of legend items (from a layer tree model).
Returns whether a map theme with a matching name exists.
Inserts a new map theme to the collection.
Returns the recorded state of a map theme.
Gets layer style overrides (for
QgsMapSettings
) of the visible layers for given map theme.Returns the list of layer IDs that are visible for the specified map theme.
Returns the list of layers that are visible for the specified map theme.
Returns a list of existing map theme names.
Returns the master layer order (this will always match the project's
QgsProject.layerOrder()
).Returns the master list of visible layers.
The
QgsProject
on which this map theme collection works.Reads the map theme collection state from XML
Removes an existing map theme from collection.
Renames the existing map theme called
name
tonewName
.copydoc
project()
Updates a map theme within the collection.
Writes the map theme collection state to XML.
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
- class MapThemeLayerRecord¶
Bases:
sip.wrapper
Individual record of a visible layer in a map theme record.
New in version 3.0.
QgsMapThemeCollection.MapThemeLayerRecord(l:
QgsMapLayer
= None) Initialize layer record with a map layer - it will be stored as a weak pointerQgsMapThemeCollection.MapThemeLayerRecord(QgsMapThemeCollection.MapThemeLayerRecord)
- checkedLegendItems¶
- currentStyle¶
- expandedLayerNode¶
- expandedLegendItems¶
- isVisible¶
- layer(self) QgsMapLayer ¶
Returns map layer or
None
if the layer does not exist anymore- Return type:
- setLayer(self, layer: QgsMapLayer)¶
Sets the map layer for this record
- Parameters:
layer (QgsMapLayer) –
- usingCurrentStyle¶
- usingLegendItems¶
- class MapThemeRecord¶
Bases:
sip.wrapper
Individual map theme record of visible layers and styles.
New in version 3.0.
- addLayerRecord(self, record: QgsMapThemeCollection.MapThemeLayerRecord)¶
Add a new record for a layer.
- Parameters:
record (QgsMapThemeCollection.MapThemeLayerRecord) –
- checkedGroupNodes(self) Set[str] ¶
Returns a set of group identifiers for group nodes that should have checked state (other group nodes should be unchecked). The returned value is valid only when
hasCheckedStateInfo()
returnsTrue
. Group identifiers are built using group names, a sub-group name is prepended by parent group’s identifier and a forward slash, e.g. “level1/level2”New in version 3.10.1.
- Return type:
Set[str]
- expandedGroupNodes(self) Set[str] ¶
Returns a set of group identifiers for group nodes that should have expanded state (other group nodes should be collapsed). The returned value is valid only when
hasExpandedStateInfo()
returnsTrue
. Group identifiers are built using group names, a sub-group name is prepended by parent group’s identifier and a forward slash, e.g. “level1/level2”New in version 3.2.
- Return type:
Set[str]
- hasCheckedStateInfo(self) bool ¶
Returns whether information about checked/unchecked state of groups has been recorded and thus whether
checkedGroupNodes()
is valid.New in version 3.10.1.
- Return type:
bool
- hasExpandedStateInfo(self) bool ¶
Returns whether information about expanded/collapsed state of nodes has been recorded and thus whether
expandedGroupNodes()
and expandedLegendItems + expandedLayerNode from layer records are valid.New in version 3.2.
- Return type:
bool
- layerRecords(self) List[QgsMapThemeCollection.MapThemeLayerRecord] ¶
Returns a list of records for all visible layer belonging to the theme.
- Return type:
- removeLayerRecord(self, layer: QgsMapLayer)¶
Removes a record for
layer
if present.- Parameters:
layer (QgsMapLayer) –
- setCheckedGroupNodes(self, checkedGroupNodes: Iterable[str])¶
Sets a set of group identifiers for group nodes that should have checked state. See
checkedGroupNodes()
.New in version 3.10.1.
- Parameters:
checkedGroupNodes (Iterable[str]) –
- setExpandedGroupNodes(self, expandedGroupNodes: Iterable[str])¶
Sets a set of group identifiers for group nodes that should have expanded state. See
expandedGroupNodes()
.New in version 3.2.
- Parameters:
expandedGroupNodes (Iterable[str]) –
- setHasCheckedStateInfo(self, hasInfo: bool)¶
Sets whether the map theme contains valid checked/unchecked state of group nodes
New in version 3.10.1.
- Parameters:
hasInfo (bool) –
- setHasExpandedStateInfo(self, hasInfo: bool)¶
Sets whether the map theme contains valid expanded/collapsed state of nodes
New in version 3.2.
- Parameters:
hasInfo (bool) –
- setLayerRecords(self, records: Iterable[QgsMapThemeCollection.MapThemeLayerRecord])¶
Sets layer records for the theme.
- Parameters:
records (Iterable[QgsMapThemeCollection.MapThemeLayerRecord]) –
- applyTheme(self, name: str, root: QgsLayerTreeGroup, model: QgsLayerTreeModel)¶
Apply theme given by its name and modify layer tree, current style of layers and checked legend items of passed layer tree model.
New in version 3.0.
- Parameters:
name (str) –
root (QgsLayerTreeGroup) –
model (QgsLayerTreeModel) –
- childEvent(self, QChildEvent)¶
- clear(self)¶
Removes all map themes from the collection.
- connectNotify(self, QMetaMethod)¶
- createThemeFromCurrentState(root: QgsLayerTreeGroup, model: QgsLayerTreeModel) QgsMapThemeCollection.MapThemeRecord ¶
Static method to create theme from the current state of layer visibilities in layer tree, current style of layers and check state of legend items (from a layer tree model).
New in version 3.0.
- Parameters:
root (QgsLayerTreeGroup) –
model (QgsLayerTreeModel) –
- Return type:
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- hasMapTheme(self, name: str) bool ¶
Returns whether a map theme with a matching name exists.
New in version 3.0.
- Parameters:
name (str) –
- Return type:
bool
- insert(self, name: str, state: QgsMapThemeCollection.MapThemeRecord)¶
Inserts a new map theme to the collection.
See also
- Parameters:
name (str) –
state (QgsMapThemeCollection.MapThemeRecord) –
- isSignalConnected(self, QMetaMethod) bool ¶
- mapThemeChanged¶
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
- mapThemeRenamed¶
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
- mapThemeState(self, name: str) QgsMapThemeCollection.MapThemeRecord ¶
Returns the recorded state of a map theme.
New in version 3.0.
- Parameters:
name (str) –
- Return type:
- mapThemeStyleOverrides(self, name: str) Dict[str, str] ¶
Gets layer style overrides (for
QgsMapSettings
) of the visible layers for given map theme.New in version 3.0.
- Parameters:
name (str) –
- Return type:
Dict[str, str]
- mapThemeVisibleLayerIds(self, name: str) List[str] ¶
Returns the list of layer IDs that are visible for the specified map theme.
Note
The order of the returned list is not guaranteed to reflect the order of layers in the canvas.
New in version 3.0.
- Parameters:
name (str) –
- Return type:
List[str]
- mapThemeVisibleLayers(self, name: str) List[QgsMapLayer] ¶
Returns the list of layers that are visible for the specified map theme.
Note
The order of the returned list is not guaranteed to reflect the order of layers in the canvas.
New in version 3.0.
- Parameters:
name (str) –
- Return type:
List[QgsMapLayer]
- mapThemes(self) List[str] ¶
Returns a list of existing map theme names.
New in version 3.0.
- Return type:
List[str]
- mapThemesChanged¶
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
- masterLayerOrder(self) List[QgsMapLayer] ¶
Returns the master layer order (this will always match the project’s
QgsProject.layerOrder()
). All map themes will maintain the same layer order as the master layer order.See also
New in version 3.0.
- Return type:
List[QgsMapLayer]
- masterVisibleLayers(self) List[QgsMapLayer] ¶
Returns the master list of visible layers. The order of returned layers will always match those of
masterLayerOrder()
, but the returned layers are filtered to only include those visible in the project’s layer tree.See also
New in version 3.0.
- Return type:
List[QgsMapLayer]
- project(self) QgsProject ¶
The
QgsProject
on which this map theme collection works.New in version 3.0.
- Return type:
- projectChanged¶
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
- readXml(self, doc: QDomDocument)¶
Reads the map theme collection state from XML
- Parameters:
doc (QDomDocument) – DOM document
See also
- receivers(self, PYQT_SIGNAL) int ¶
- removeMapTheme(self, name: str)¶
Removes an existing map theme from collection.
New in version 3.0.
- Parameters:
name (str) –
- renameMapTheme(self, name: str, newName: str) bool ¶
Renames the existing map theme called
name
tonewName
. ReturnsTrue
if the rename was successful, orFalse
if it failed (e.g. due to a duplicate name fornewName
).New in version 3.14.
- Parameters:
name (str) –
newName (str) –
- Return type:
bool
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setProject(self, project: QgsProject)¶
copydoc
project()
New in version 3.0.
- Parameters:
project (QgsProject) –
- timerEvent(self, QTimerEvent)¶
- update(self, name: str, state: QgsMapThemeCollection.MapThemeRecord)¶
Updates a map theme within the collection.
- Parameters:
name (str) – name of map theme to update
state (QgsMapThemeCollection.MapThemeRecord) – map theme record to replace existing map theme
See also