QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsbookmarkmanager.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsbookmarkmanager.h
3 ------------------
4 Date : Septemeber 2019
5 Copyright : (C) 2019 Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSBOOKMARKMANAGER_H
17#define QGSBOOKMARKMANAGER_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
22
23#include <QObject>
24
25class QgsProject;
26
38class CORE_EXPORT QgsBookmark
39{
40
41 public:
42
46 QgsBookmark() = default;
47
52 QString id() const;
53
58 void setId( const QString &id );
59
65 QString name() const;
66
72 void setName( const QString &name );
73
79 QString group() const;
80
86 void setGroup( const QString &group );
87
93
99
100
107 double rotation() const;
108
115 void setRotation( double rotation );
116
121 static QgsBookmark fromXml( const QDomElement &element, const QDomDocument &doc );
122
127 QDomElement writeXml( QDomDocument &doc ) const;
128
129#ifdef SIP_RUN
130 SIP_PYOBJECT __repr__();
131 % MethodCode
132 QString str = QStringLiteral( "<QgsBookmark: '%1' (%2)>" )
133 .arg( sipCpp->name() )
134 .arg(
135 sipCpp->extent().isNull() ?
136 QStringLiteral( "EMPTY" ) :
137 QStringLiteral( "%1 - %2" )
138 .arg( sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() )
139 );
140 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
141 % End
142#endif
143
144 // TODO c++20 - replace with = default
145 bool operator==( const QgsBookmark &other ) const;
146 bool operator!=( const QgsBookmark &other ) const;
147
148 private:
149
150 QString mId;
151 QString mName;
152 QString mGroup;
154 double mRotation = 0;
155
156};
157
171class CORE_EXPORT QgsBookmarkManager : public QObject
172{
173 Q_OBJECT
174
175 public:
176
183
190 explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
191
192 ~QgsBookmarkManager() override;
193
197 void initialize( const QString &filePath );
198
211 QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
212
224 bool removeBookmark( const QString &id );
225
237 bool updateBookmark( const QgsBookmark &bookmark );
238
243 void clear();
244
248 QStringList groups() const;
249
254 void renameGroup( const QString &oldName, const QString &newName );
255
259 QList< QgsBookmark > bookmarks() const;
260
265 QgsBookmark bookmarkById( const QString &id ) const;
266
271 QList< QgsBookmark > bookmarksByGroup( const QString &group );
272
278 bool readXml( const QDomElement &element, const QDomDocument &doc );
279
284 QDomElement writeXml( QDomDocument &doc ) const;
285
291 bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
292
302 static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
303
304
312 bool importFromFile( const QString &path );
313
314 signals:
315
317 void bookmarkAboutToBeAdded( const QString &id );
318
320 void bookmarkAdded( const QString &id );
321
323 void bookmarkRemoved( const QString &id );
324
326 void bookmarkAboutToBeRemoved( const QString &id );
327
329 void bookmarkChanged( const QString &id );
330
331 private:
332
333 QgsProject *mProject = nullptr;
334 QString mFilePath;
335 QList< QgsBookmark > mBookmarks;
336 QStringList mGroups;
337
338 void store();
339 bool mInitialized = false;
340
341};
342
343#endif // QGSBOOKMARKMANAGER_H
void renameGroup(const QString &oldName, const QString &newName)
Renames an existing group from oldName to newName.
bool removeBookmark(const QString &id)
Removes the bookmark with matching id from the manager.
QList< QgsBookmark > bookmarksByGroup(const QString &group)
Returns a list of bookmark with a matching group, or an empty list if no matching bookmarks were foun...
void initialize(const QString &filePath)
Initializes the bookmark manager.
void bookmarkAboutToBeRemoved(const QString &id)
Emitted when a bookmark is about to be removed from the manager.
void bookmarkChanged(const QString &id)
Emitted when a bookmark is changed.
static QgsBookmarkManager * createProjectBasedManager(QgsProject *project)
Returns a newly created QgsBookmarkManager using a project-based bookmark store, linked to the specif...
bool readXml(const QDomElement &element, const QDomDocument &doc)
Reads the manager's state from a DOM element, restoring all bookmarks present in the XML document.
void clear()
Removes and deletes all bookmarks from the manager.
void bookmarkAdded(const QString &id)
Emitted when a bookmark has been added to the manager.
bool updateBookmark(const QgsBookmark &bookmark)
Updates the definition of a bookmark in the manager.
void bookmarkAboutToBeAdded(const QString &id)
Emitted when a bookmark is about to be added to the manager.
bool moveBookmark(const QString &id, QgsBookmarkManager *destination)
Moves the bookmark with matching id from this manager to a destination manager.
static bool exportToFile(const QString &path, const QList< const QgsBookmarkManager * > &managers, const QString &group=QString())
Exports all bookmarks from a list of managers to an xml file at the specified path.
QgsBookmark bookmarkById(const QString &id) const
Returns the bookmark with a matching id, or an empty bookmark if no matching bookmarks were found.
QStringList groups() const
Returns a list of all bookmark groups contained in the manager.
QString addBookmark(const QgsBookmark &bookmark, bool *ok=nullptr)
Adds a bookmark to the manager.
QDomElement writeXml(QDomDocument &doc) const
Returns a DOM element representing the state of the manager.
QgsBookmarkManager(QObject *parent=nullptr)
Constructor for QgsBookmarkManager, with the specified parent object.
QList< QgsBookmark > bookmarks() const
Returns a list of all bookmarks contained in the manager.
void bookmarkRemoved(const QString &id)
Emitted when a bookmark was removed from the manager.
bool importFromFile(const QString &path)
Imports the bookmarks from an xml file at the specified path.
Represents a spatial bookmark, with a name, CRS and extent.
static QgsBookmark fromXml(const QDomElement &element, const QDomDocument &doc)
Creates a bookmark using the properties from a DOM element.
void setGroup(const QString &group)
Sets the bookmark's group, which is a user-visible string identifying the bookmark's category.
void setRotation(double rotation)
Sets the bookmark's spatial map rotation.
QgsBookmark()=default
Default constructor, creates an empty bookmark.
QString id() const
Returns the bookmark's unique ID.
QgsReferencedRectangle extent() const
Returns the bookmark's spatial extent.
void setExtent(const QgsReferencedRectangle &extent)
Sets the bookmark's spatial extent.
double rotation() const
Returns the bookmark's map rotation.
void setId(const QString &id)
Sets the bookmark's unique id.
QDomElement writeXml(QDomDocument &doc) const
Returns a DOM element representing the bookmark's properties.
QString group() const
Returns the bookmark's group, which is a user-visible string identifying the bookmark's category.
void setName(const QString &name)
Sets the bookmark's name, which is a user-visible string identifying the bookmark.
QString name() const
Returns the bookmark's name, which is a user-visible string identifying the bookmark.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition qgsproject.h:109
A QgsRectangle with associated coordinate reference system.
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_OUT
Definition qgis_sip.h:58
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)