Class: QgsBookmarkManager

Manages storage of a set of bookmarks.

QgsBookmarkManager handles the storage, serializing and deserializing of geographic bookmarks. Usually this class is not constructed directly, but rather accessed through a QgsProject via QgsProject.bookmarkManager(), or via the application-wide bookmark store at QgsApplication.bookmarkManager().

Added in version 3.10.

Class Hierarchy

Inheritance diagram of qgis.core.QgsBookmarkManager

Base classes

QObject

class qgis.core.QgsBookmarkManager[source]

Bases: QObject

__init__(parent: QObject | None = None)

Constructor for QgsBookmarkManager, with the specified parent object.

This constructor creates a bookmark manager which stores bookmarks in an XML file. A call to initialize() is required to initialize the manager and set the corresponding file path.

Parameters:

parent (Optional[QObject] = None)

addBookmark(self, bookmark: QgsBookmark)[source]

Adds a bookmark to the manager.

Parameters:

bookmark (QgsBookmark) -> (str) – the bookmark to add

Returns:

  • The bookmark’s ID (or newly generated ID, if no ID was originally set and one was automatically generated)

  • ok: True if the bookmark was successfully added, or False if the bookmark could not be added (eg as a result of a duplicate bookmark ID).

See also

removeBookmark()

See also

bookmarkAdded()

signal bookmarkAboutToBeAdded[source]

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.

signal bookmarkAboutToBeRemoved[source]

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.

signal bookmarkAdded[source]

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.

bookmarkById(self, id: str | None) QgsBookmark[source]

Returns the bookmark with a matching id, or an empty bookmark if no matching bookmarks were found.

Parameters:

id (Optional[str])

Return type:

QgsBookmark

signal bookmarkChanged[source]

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.

signal bookmarkRemoved[source]

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.

bookmarks(self) List[QgsBookmark]

Returns a list of all bookmarks contained in the manager.

Return type:

List[QgsBookmark]

bookmarksByGroup(self, group: str | None) List[QgsBookmark]

Returns a list of bookmark with a matching group, or an empty list if no matching bookmarks were found.

Parameters:

group (Optional[str])

Return type:

List[QgsBookmark]

clear(self)[source]

Removes and deletes all bookmarks from the manager.

See also

removeBookmark()

static createProjectBasedManager(project: QgsProject | None) QgsBookmarkManager | None[source]

Returns a newly created QgsBookmarkManager using a project-based bookmark store, linked to the specified project.

The returned object is parented to the project.

Parameters:

project (Optional[QgsProject])

Return type:

Optional[QgsBookmarkManager]

static exportToFile(path: str | None, managers: Iterable[QgsBookmarkManager], group: str | None = '') bool[source]

Exports all bookmarks from a list of managers to an xml file at the specified path.

If group is set then only bookmarks from the matching group will be exported.

Returns True if the export was successful.

See also

importFromFile()

Parameters:
Return type:

bool

groups(self) List[str][source]

Returns a list of all bookmark groups contained in the manager.

Return type:

List[str]

importFromFile(self, path: str | None) bool[source]

Imports the bookmarks from an xml file at the specified path.

Returns True if the import was successful.

See also

exportToFile()

Parameters:

path (Optional[str])

Return type:

bool

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

Initializes the bookmark manager.

Parameters:

filePath (Optional[str])

moveBookmark(self, id: str | None, destination: QgsBookmarkManager | None) bool[source]

Moves the bookmark with matching id from this manager to a destination manager.

Returns True if the bookmark was successfully moved.

Parameters:
Return type:

bool

readXml(self, element: QDomElement, doc: QDomDocument) bool[source]

Reads the manager’s state from a DOM element, restoring all bookmarks present in the XML document.

See also

writeXml()

Parameters:
  • element (QDomElement)

  • doc (QDomDocument)

Return type:

bool

removeBookmark(self, id: str | None) bool[source]

Removes the bookmark with matching id from the manager.

Returns True if the removal was successful, or False if the removal failed (eg as a result of removing a bookmark which is not contained in the manager).

See also

addBookmark()

See also

clear()

Parameters:

id (Optional[str])

Return type:

bool

renameGroup(self, oldName: str | None, newName: str | None)[source]

Renames an existing group from oldName to newName. This updates all existing bookmarks to reflect the new name.

Parameters:
  • oldName (Optional[str])

  • newName (Optional[str])

updateBookmark(self, bookmark: QgsBookmark) bool[source]

Updates the definition of a bookmark in the manager.

Replaces the current definition of the bookmark with matching ID in the manager with a new definition (new bookmark name or extent).

Returns True if the bookmark was successfully updated, or False if the bookmark could not be updated (eg bookmark is not stored in the manager).

Parameters:

bookmark (QgsBookmark)

Return type:

bool

writeXml(self, doc: QDomDocument) QDomElement[source]

Returns a DOM element representing the state of the manager.

See also

readXml()

Parameters:

doc (QDomDocument)

Return type:

QDomElement