QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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"
21 #include "qgsreferencedgeometry.h"
22 #include <QObject>
23 
24 class QgsProject;
25 
37 class 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  bool operator==( const QgsBookmark &other );
120  bool operator!=( const QgsBookmark &other );
121 
122  private:
123 
124  QString mId;
125  QString mName;
126  QString mGroup;
127  QgsReferencedRectangle mExtent;
128 
129 };
130 
144 class CORE_EXPORT QgsBookmarkManager : public QObject
145 {
146  Q_OBJECT
147 
148  public:
149 
155  static QgsBookmarkManager *createProjectBasedManager( QgsProject *project );
156 
163  explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
164 
165  ~QgsBookmarkManager() override;
166 
170  void initialize( const QString &filePath );
171 
184  QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
185 
197  bool removeBookmark( const QString &id );
198 
210  bool updateBookmark( const QgsBookmark &bookmark );
211 
216  void clear();
217 
221  QStringList groups() const;
222 
227  void renameGroup( const QString &oldName, const QString &newName );
228 
232  QList< QgsBookmark > bookmarks() const;
233 
238  QgsBookmark bookmarkById( const QString &id ) const;
239 
244  QList< QgsBookmark > bookmarksByGroup( const QString &group );
245 
251  bool readXml( const QDomElement &element, const QDomDocument &doc );
252 
257  QDomElement writeXml( QDomDocument &doc ) const;
258 
264  bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
265 
275  static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
276 
277 
285  bool importFromFile( const QString &path );
286 
287  signals:
288 
290  void bookmarkAboutToBeAdded( const QString &id );
291 
293  void bookmarkAdded( const QString &id );
294 
296  void bookmarkRemoved( const QString &id );
297 
299  void bookmarkAboutToBeRemoved( const QString &id );
300 
302  void bookmarkChanged( const QString &id );
303 
304  private:
305 
306  QgsProject *mProject = nullptr;
307  QString mFilePath;
308  QList< QgsBookmark > mBookmarks;
309  QStringList mGroups;
310 
311  void store();
312  bool mInitialized = false;
313 
314 };
315 
316 #endif // QGSBOOKMARKMANAGER_H
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:399
QgsReferencedRectangle
Definition: qgsreferencedgeometry.h:72
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsBookmarkManager
Manages storage of a set of bookmarks.
Definition: qgsbookmarkmanager.h:144
operator!=
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:404
QgsProject
Definition: qgsproject.h:92
QgsBookmark
Represents a spatial bookmark, with a name, CRS and extent.
Definition: qgsbookmarkmanager.h:37
qgis_sip.h
qgsreferencedgeometry.h
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53