Class: QgsProjectStorage

Abstract interface for project storage - to be implemented by various backends and registered in QgsProjectStorageRegistry.

Added in version 3.2.

Methods

filePath

Extracts and returns the file path from a storage backend uri, filesystem-based storage backends should implement this method in order to support relative paths storage.

isSupportedUri

Returns True if the specified uri is supported by the storage provider.

listProjects

Returns list of all projects for given URI (specific to each storage backend)

readProject

Reads project file content stored in the backend at the specified URI to the given device (could be e.g. a temporary file or a memory buffer).

readProjectStorageMetadata

Reads project metadata (e.g. last modified time) if this is supported by the storage implementation.

removeProject

Removes an existing project at the given URI.

renameProject

Rename an existing project at the given URI to a different URI.

showLoadGui

Opens GUI to allow user to select a project to be loaded (GUI specific to this storage type).

showSaveGui

Opens GUI to allow user to select where a project should be saved (GUI specific to this storage type).

type

Unique identifier of the project storage type.

visibleName

Returns human-readable name of the storage.

writeProject

Writes project file content stored in given device (could be e.g. a temporary file or a memory buffer) using the backend to the specified URI.

class qgis.core.QgsProjectStorage[source]

Bases: object

class Metadata[source]

Bases: object

Metadata associated with a project

Added in version 3.2.

lastModified

Date and local time when the file was last modified.

name

Name of the project - equivalent to a file’s base name (i.e. without path and extension).

filePath(self, uri: str | None) str[source]

Extracts and returns the file path from a storage backend uri, filesystem-based storage backends should implement this method in order to support relative paths storage. The default implementation returns an empty string.

Added in version 3.8.1.

Parameters:

uri (Optional[str])

Return type:

str

isSupportedUri(self, uri: str | None) bool[source]

Returns True if the specified uri is supported by the storage provider.

Note

This method does not actually test whether the uri contains projects, but rather it is a quick test to determine if it is possible that the uri may contain projects.

Added in version 3.22.

Parameters:

uri (Optional[str])

Return type:

bool

listProjects(self, uri: str | None) List[str][source]

Returns list of all projects for given URI (specific to each storage backend)

Parameters:

uri (Optional[str])

Return type:

List[str]

readProject(self, uri: str | None, device: QIODevice | None, context: QgsReadWriteContext) bool[source]

Reads project file content stored in the backend at the specified URI to the given device (could be e.g. a temporary file or a memory buffer). The device is expected to be empty when passed to readProject() so that the method can write all data to it and then rewind it using seek(0) to make it ready for reading in QgsProject.

Parameters:
Return type:

bool

readProjectStorageMetadata(self, uri: str | None)[source]

Reads project metadata (e.g. last modified time) if this is supported by the storage implementation. Returns True if the metadata were read with success.

Parameters:

uri (Optional[str]) -> (bool)

removeProject(self, uri: str | None) bool[source]

Removes an existing project at the given URI. Returns True if the removal was successful.

Parameters:

uri (Optional[str])

Return type:

bool

renameProject(self, uri: str | None, uriNew: str | None) bool[source]

Rename an existing project at the given URI to a different URI. Returns True if renaming was successful.

Parameters:
  • uri (Optional[str])

  • uriNew (Optional[str])

Return type:

bool

showLoadGui(self) str[source]

Opens GUI to allow user to select a project to be loaded (GUI specific to this storage type). Returns project URI if user has picked a project or empty string if the GUI was canceled.

Deprecated since version 3.10: Use QgsProjectStorageGuiProvider for GUI-related project storage functionality.

Return type:

str

showSaveGui(self) str[source]

Opens GUI to allow user to select where a project should be saved (GUI specific to this storage type). Returns project URI if user has picked a destination or empty string if the GUI was canceled.

Deprecated since version 3.10: Use QgsProjectStorageGuiProvider for GUI-related project storage functionality.

Return type:

str

type(self) str[source]

Unique identifier of the project storage type. If type() returns “memory”, all project file names starting with “memory:” will have read/write redirected through that storage implementation.

Return type:

str

visibleName(self) str[source]

Returns human-readable name of the storage. Used as the menu item text in QGIS. Empty name indicates that the storage does not implement GUI support (showLoadGui() and showSaveGui()). The name may be translatable and ideally unique as well.

Deprecated since version 3.10: Use QgsProjectStorageGuiProvider for GUI-related project storage functionality.

Return type:

str

writeProject(self, uri: str | None, device: QIODevice | None, context: QgsReadWriteContext) bool[source]

Writes project file content stored in given device (could be e.g. a temporary file or a memory buffer) using the backend to the specified URI. The device is expected to contain all project file data and having position at the start of the content when passed to writeProject() so that the method can read all data from it until it reaches its end.

Parameters:
Return type:

bool