Class: QgsBookmarkManager

class qgis.core.QgsBookmarkManager(parent: QObject = None)

Bases: PyQt5.QtCore.QObject

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.

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

New in version 3.10.

Parameters

parent

addBookmark(self, bookmark: QgsBookmark) → Tuple[str, bool]

Adds a bookmark to the manager.

Parameters

bookmark (QgsBookmark) – the bookmark to add

Return type

Tuple[str, bool]

Returns

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

  • ok: will be set to 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()

bookmarkAboutToBeAdded

Emitted when a bookmark is about to be added to the manager [signal]

Parameters

id (str) –

bookmarkAboutToBeRemoved

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

Parameters

id (str) –

bookmarkAdded

Emitted when a bookmark has been added to the manager [signal]

Parameters

id (str) –

bookmarkById(self, id: str) → QgsBookmark

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

Parameters

id (str) –

Return type

QgsBookmark

bookmarkChanged

Emitted when a bookmark is changed [signal]

Parameters

id (str) –

bookmarkRemoved

Emitted when a bookmark was removed from the manager [signal]

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) → List[QgsBookmark]

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

Parameters

group (str) –

Return type

List[QgsBookmark]

childEvent()
clear(self)

Removes and deletes all bookmarks from the manager.

See also

removeBookmark()

connectNotify()
createProjectBasedManager(project: QgsProject) → QgsBookmarkManager

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 (QgsProject) –

Return type

QgsBookmarkManager

customEvent()
disconnectNotify()
exportToFile(path: str, managers: Iterable[QgsBookmarkManager], group: str = '') → bool

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]

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

Return type

List[str]

importFromFile(self, path: str) → bool

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

Returns True if the import was successful.

See also

exportToFile()

Parameters

path (str) –

Return type

bool

initialize(self, filePath: str)

initialize

Parameters

filePath (str) –

isSignalConnected()
moveBookmark(self, id: str, destination: QgsBookmarkManager) → bool

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

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

receivers()
removeBookmark(self, id: str) → bool

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 (str) –

Return type

bool

renameGroup(self, oldName: str, newName: str)

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

Parameters
  • oldName (str) –

  • newName (str) –

sender()
senderSignalIndex()
timerEvent()
updateBookmark(self, bookmark: QgsBookmark) → bool

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

Returns a DOM element representing the state of the manager.

See also

readXml()

Parameters

doc (QDomDocument) –

Return type

QDomElement