QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
103 static QgsBookmark fromXml( const QDomElement &element, const QDomDocument &doc );
104
109 QDomElement writeXml( QDomDocument &doc ) const;
110
111#ifdef SIP_RUN
112 SIP_PYOBJECT __repr__();
113 % MethodCode
114 QString str = QStringLiteral( "<QgsBookmark: '%1' (%2 - %3)>" ).arg( sipCpp->name(), sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() );
115 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
116 % End
117#endif
118
119 // TODO c++20 - replace with = default
120 bool operator==( const QgsBookmark &other ) const;
121 bool operator!=( const QgsBookmark &other ) const;
122
123 private:
124
125 QString mId;
126 QString mName;
127 QString mGroup;
129
130};
131
145class CORE_EXPORT QgsBookmarkManager : public QObject
146{
147 Q_OBJECT
148
149 public:
150
156 static QgsBookmarkManager *createProjectBasedManager( QgsProject *project );
157
164 explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
165
166 ~QgsBookmarkManager() override;
167
171 void initialize( const QString &filePath );
172
185 QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
186
198 bool removeBookmark( const QString &id );
199
211 bool updateBookmark( const QgsBookmark &bookmark );
212
217 void clear();
218
222 QStringList groups() const;
223
228 void renameGroup( const QString &oldName, const QString &newName );
229
233 QList< QgsBookmark > bookmarks() const;
234
239 QgsBookmark bookmarkById( const QString &id ) const;
240
245 QList< QgsBookmark > bookmarksByGroup( const QString &group );
246
252 bool readXml( const QDomElement &element, const QDomDocument &doc );
253
258 QDomElement writeXml( QDomDocument &doc ) const;
259
265 bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
266
276 static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
277
278
286 bool importFromFile( const QString &path );
287
288 signals:
289
291 void bookmarkAboutToBeAdded( const QString &id );
292
294 void bookmarkAdded( const QString &id );
295
297 void bookmarkRemoved( const QString &id );
298
300 void bookmarkAboutToBeRemoved( const QString &id );
301
303 void bookmarkChanged( const QString &id );
304
305 private:
306
307 QgsProject *mProject = nullptr;
308 QString mFilePath;
309 QList< QgsBookmark > mBookmarks;
310 QStringList mGroups;
311
312 void store();
313 bool mInitialized = false;
314
315};
316
317#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:105
A QgsRectangle with associated coordinate reference system.
#define str(x)
Definition: qgis.cpp:37
#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)