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

Methods

addBookmark

Adds a bookmark to the manager.

bookmarkById

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

bookmarks

Returns a list of all bookmarks contained in the manager.

bookmarksByGroup

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

clear

Removes and deletes all bookmarks from the manager.

groups

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

importFromFile

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

initialize

Initializes the bookmark manager.

moveBookmark

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

readXml

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

removeBookmark

Removes the bookmark with matching id from the manager.

renameGroup

Renames an existing group from oldName to newName.

updateBookmark

Updates the definition of a bookmark in the manager.

writeXml

Returns a DOM element representing the state of the manager.

Static Methods

createProjectBasedManager

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

exportToFile

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

Signals

bookmarkAboutToBeAdded

Emitted when a bookmark is about to be added to the manager

bookmarkAboutToBeRemoved

Emitted when a bookmark is about to be removed from the manager

bookmarkAdded

Emitted when a bookmark has been added to the manager

bookmarkChanged

Emitted when a bookmark is changed

bookmarkRemoved

Emitted when a bookmark was removed from the manager

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(id: str)[source]

Emitted when a bookmark is about to be added to the manager

Parameters:

id (str)

signal bookmarkAboutToBeRemoved(id: str)[source]

Emitted when a bookmark is about to be removed from the manager

Parameters:

id (str)

signal bookmarkAdded(id: str)[source]

Emitted when a bookmark has been added to the manager

Parameters:

id (str)

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(id: str)[source]

Emitted when a bookmark is changed

Parameters:

id (str)

signal bookmarkRemoved(id: str)[source]

Emitted when a bookmark was removed from the manager

Parameters:

id (str)

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