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¶
Base classes¶
Methods
Adds a bookmark to the manager. |
|
Returns the bookmark with a matching id, or an empty bookmark if no matching bookmarks were found. |
|
Returns a list of all bookmarks contained in the manager. |
|
Returns a list of bookmark with a matching group, or an empty list if no matching bookmarks were found. |
|
Removes and deletes all bookmarks from the manager. |
|
Returns a list of all bookmark groups contained in the manager. |
|
Imports the bookmarks from an xml file at the specified path. |
|
Initializes the bookmark manager. |
|
Moves the bookmark with matching id from this manager to a destination manager. |
|
Reads the manager's state from a DOM element, restoring all bookmarks present in the XML document. |
|
Removes the bookmark with matching id from the manager. |
|
Renames an existing group from oldName to newName. |
|
Updates the definition of a bookmark in the manager. |
|
Returns a DOM element representing the state of the manager. |
Static Methods
Returns a newly created |
|
Exports all bookmarks from a list of managers to an xml file at the specified path. |
Signals
Emitted when a bookmark is about to be added to the manager |
|
Emitted when a bookmark is about to be removed from the manager |
|
Emitted when a bookmark has been added to the manager |
|
Emitted when a bookmark is changed |
|
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, orFalse
if the bookmark could not be added (eg as a result of a duplicate bookmark ID).
See also
See also
- 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:
- 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]
- static createProjectBasedManager(project: QgsProject | None) QgsBookmarkManager | None [source]¶
Returns a newly created
QgsBookmarkManager
using a project-based bookmark store, linked to the specifiedproject
.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 specifiedpath
.If
group
is set then only bookmarks from the matching group will be exported.Returns
True
if the export was successful.See also
- Parameters:
path (Optional[str])
managers (Iterable[QgsBookmarkManager])
group (Optional[str] = '')
- 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
- 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 adestination
manager.Returns
True
if the bookmark was successfully moved.- Parameters:
id (Optional[str])
destination (Optional[QgsBookmarkManager])
- 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
- 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, orFalse
if the removal failed (eg as a result of removing a bookmark which is not contained in the manager).See also
See also
See also
See also
- Parameters:
id (Optional[str])
- Return type:
bool
- renameGroup(self, oldName: str | None, newName: str | None)[source]¶
Renames an existing group from
oldName
tonewName
. 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, orFalse
if the bookmark could not be updated (eg bookmark is not stored in the manager).See also
- Parameters:
bookmark (QgsBookmark)
- Return type:
bool