Class: QgsProjectStorage

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

Added in version 3.2.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: listProjects(), readProject(), removeProject(), type(), writeProject()

Abstract Methods

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).

removeProject

Removes an existing project at the given URI.

type

Unique identifier of the project storage type.

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.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsProjectStorage. See the FAQ for more details.

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.

readProjectStorageMetadata

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

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).

visibleName

Returns human-readable name of the storage.

class qgis.core.QgsProjectStorage[source]

Bases: object

class Metadata[source]

Bases: object

Metadata associated with a project.

Added in version 3.2.

lastModified: QDateTime

Date and local time when the file was last modified.

name: str

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

virtual 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

virtual 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

abstract 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]

abstract 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

virtual 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)

abstract 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

virtual 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

virtual 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

virtual 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

abstract 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

virtual 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

abstract 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