QGIS API Documentation 3.38.0-Grenoble (exported)
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#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)>" )
132 .arg( sipCpp->name() )
133 .arg(
134 sipCpp->extent().isNull() ?
135 QStringLiteral( "EMPTY" ) :
136 QStringLiteral( "%1 - %2" )
137 .arg( sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() )
138 );
139 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
140 % End
141#endif
142
143 // TODO c++20 - replace with = default
144 bool operator==( const QgsBookmark &other ) const;
145 bool operator!=( const QgsBookmark &other ) const;
146
147 private:
148
149 QString mId;
150 QString mName;
151 QString mGroup;
153 double mRotation = 0;
154
155};
156
170class CORE_EXPORT QgsBookmarkManager : public QObject
171{
172 Q_OBJECT
173
174 public:
175
181 static QgsBookmarkManager *createProjectBasedManager( QgsProject *project );
182
189 explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
190
191 ~QgsBookmarkManager() override;
192
196 void initialize( const QString &filePath );
197
210 QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
211
223 bool removeBookmark( const QString &id );
224
236 bool updateBookmark( const QgsBookmark &bookmark );
237
242 void clear();
243
247 QStringList groups() const;
248
253 void renameGroup( const QString &oldName, const QString &newName );
254
258 QList< QgsBookmark > bookmarks() const;
259
264 QgsBookmark bookmarkById( const QString &id ) const;
265
270 QList< QgsBookmark > bookmarksByGroup( const QString &group );
271
277 bool readXml( const QDomElement &element, const QDomDocument &doc );
278
283 QDomElement writeXml( QDomDocument &doc ) const;
284
290 bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
291
301 static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
302
303
311 bool importFromFile( const QString &path );
312
313 signals:
314
316 void bookmarkAboutToBeAdded( const QString &id );
317
319 void bookmarkAdded( const QString &id );
320
322 void bookmarkRemoved( const QString &id );
323
325 void bookmarkAboutToBeRemoved( const QString &id );
326
328 void bookmarkChanged( const QString &id );
329
330 private:
331
332 QgsProject *mProject = nullptr;
333 QString mFilePath;
334 QList< QgsBookmark > mBookmarks;
335 QStringList mGroups;
336
337 void store();
338 bool mInitialized = false;
339
340};
341
342#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)
const QgsCoordinateReferenceSystem & crs