QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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#include <QObject>
23
24class QgsProject;
25
37class CORE_EXPORT QgsBookmark
38{
39
40 public:
41
45 QgsBookmark() = default;
46
51 QString id() const;
52
57 void setId( const QString &id );
58
64 QString name() const;
65
71 void setName( const QString &name );
72
78 QString group() const;
79
85 void setGroup( const QString &group );
86
91 QgsReferencedRectangle extent() const;
92
97 void setExtent( const QgsReferencedRectangle &extent );
98
99
106 double rotation() const;
107
114 void setRotation( double rotation );
115
120 static QgsBookmark fromXml( const QDomElement &element, const QDomDocument &doc );
121
126 QDomElement writeXml( QDomDocument &doc ) const;
127
128#ifdef SIP_RUN
129 SIP_PYOBJECT __repr__();
130 % MethodCode
131 QString str = QStringLiteral( "<QgsBookmark: '%1' (%2 - %3)>" ).arg( sipCpp->name(), sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() );
132 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
133 % End
134#endif
135
136 // TODO c++20 - replace with = default
137 bool operator==( const QgsBookmark &other ) const;
138 bool operator!=( const QgsBookmark &other ) const;
139
140 private:
141
142 QString mId;
143 QString mName;
144 QString mGroup;
146 double mRotation = 0;
147
148};
149
163class CORE_EXPORT QgsBookmarkManager : public QObject
164{
165 Q_OBJECT
166
167 public:
168
174 static QgsBookmarkManager *createProjectBasedManager( QgsProject *project );
175
182 explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
183
184 ~QgsBookmarkManager() override;
185
189 void initialize( const QString &filePath );
190
203 QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
204
216 bool removeBookmark( const QString &id );
217
229 bool updateBookmark( const QgsBookmark &bookmark );
230
235 void clear();
236
240 QStringList groups() const;
241
246 void renameGroup( const QString &oldName, const QString &newName );
247
251 QList< QgsBookmark > bookmarks() const;
252
257 QgsBookmark bookmarkById( const QString &id ) const;
258
263 QList< QgsBookmark > bookmarksByGroup( const QString &group );
264
270 bool readXml( const QDomElement &element, const QDomDocument &doc );
271
276 QDomElement writeXml( QDomDocument &doc ) const;
277
283 bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
284
294 static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
295
296
304 bool importFromFile( const QString &path );
305
306 signals:
307
309 void bookmarkAboutToBeAdded( const QString &id );
310
312 void bookmarkAdded( const QString &id );
313
315 void bookmarkRemoved( const QString &id );
316
318 void bookmarkAboutToBeRemoved( const QString &id );
319
321 void bookmarkChanged( const QString &id );
322
323 private:
324
325 QgsProject *mProject = nullptr;
326 QString mFilePath;
327 QList< QgsBookmark > mBookmarks;
328 QStringList mGroups;
329
330 void store();
331 bool mInitialized = false;
332
333};
334
335#endif // QGSBOOKMARKMANAGER_H
Manages storage of a set of bookmarks.
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.
void bookmarkAdded(const QString &id)
Emitted when a bookmark has been added to the manager.
void bookmarkAboutToBeAdded(const QString &id)
Emitted when a bookmark is about to be added to the manager.
void bookmarkRemoved(const QString &id)
Emitted when a bookmark was removed from the manager.
Represents a spatial bookmark, with a name, CRS and extent.
QgsBookmark()=default
Default constructor, creates an empty bookmark.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:107
A QgsRectangle with associated coordinate reference system.
#define str(x)
Definition: qgis.cpp:38
#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)