Class: QgsProjectUtils

class qgis.core.QgsProjectUtils

Bases: sip.wrapper

Contains utility functions for working with QGIS projects.

New in version 3.22:

Methods

layerIsContainedInGroupLayer

Returns True if the specified layer is a child layer from any QgsGroupLayer in the given project.

layersMatchingPath

Returns a list of all layers in the specified project which match the given path.

updateLayerPath

Updates a project, replacing the data source for all layers which match the given oldPath with sources which point to newPath.

layerIsContainedInGroupLayer(project: QgsProject, layer: QgsMapLayer) bool

Returns True if the specified layer is a child layer from any QgsGroupLayer in the given project.

New in version 3.24.

Parameters:
Return type:

bool

layersMatchingPath(project: QgsProject, path: str) List[QgsMapLayer]

Returns a list of all layers in the specified project which match the given path.

This method can be used to retrieve a list of layers in a project associated with a file path.

Parameters:
Return type:

List[QgsMapLayer]

updateLayerPath(project: QgsProject, oldPath: str, newPath: str) bool

Updates a project, replacing the data source for all layers which match the given oldPath with sources which point to newPath.

Returns True if any layers were updated as a result.

Parameters:
  • project (QgsProject) –

  • oldPath (str) –

  • newPath (str) –

Return type:

bool