QGIS API Documentation 3.99.0-Master (d270888f95f)
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#include <QString>
25
26using namespace Qt::StringLiterals;
27
28class QgsProject;
29
41class CORE_EXPORT QgsBookmark
42{
43
44 public:
45
49 QgsBookmark() = default;
50
55 QString id() const;
56
61 void setId( const QString &id );
62
68 QString name() const;
69
75 void setName( const QString &name );
76
82 QString group() const;
83
89 void setGroup( const QString &group );
90
96
102
103
110 double rotation() const;
111
118 void setRotation( double rotation );
119
124 static QgsBookmark fromXml( const QDomElement &element, const QDomDocument &doc );
125
130 QDomElement writeXml( QDomDocument &doc ) const;
131
132#ifdef SIP_RUN
133 SIP_PYOBJECT __repr__();
134 % MethodCode
135 QString str = u"<QgsBookmark: '%1' (%2)>"_s
136 .arg( sipCpp->name() )
137 .arg(
138 sipCpp->extent().isNull() ?
139 u"EMPTY"_s :
140 u"%1 - %2"_s
141 .arg( sipCpp->extent().asWktCoordinates(), sipCpp->extent().crs().authid() )
142 );
143 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
144 % End
145#endif
146
147 // TODO c++20 - replace with = default
148 bool operator==( const QgsBookmark &other ) const;
149 bool operator!=( const QgsBookmark &other ) const;
150
151 private:
152
153 QString mId;
154 QString mName;
155 QString mGroup;
157 double mRotation = 0;
158
159};
160
174class CORE_EXPORT QgsBookmarkManager : public QObject
175{
176 Q_OBJECT
177
178 public:
179
186
193 explicit QgsBookmarkManager( QObject *parent SIP_TRANSFERTHIS = nullptr );
194
195 ~QgsBookmarkManager() override;
196
200 void initialize( const QString &filePath );
201
214 QString addBookmark( const QgsBookmark &bookmark, bool *ok SIP_OUT = nullptr );
215
227 bool removeBookmark( const QString &id );
228
240 bool updateBookmark( const QgsBookmark &bookmark );
241
246 void clear();
247
251 QStringList groups() const;
252
257 void renameGroup( const QString &oldName, const QString &newName );
258
262 QList< QgsBookmark > bookmarks() const;
263
268 QgsBookmark bookmarkById( const QString &id ) const;
269
274 QList< QgsBookmark > bookmarksByGroup( const QString &group );
275
281 bool readXml( const QDomElement &element, const QDomDocument &doc );
282
287 QDomElement writeXml( QDomDocument &doc ) const;
288
294 bool moveBookmark( const QString &id, QgsBookmarkManager *destination );
295
305 static bool exportToFile( const QString &path, const QList<const QgsBookmarkManager *> &managers, const QString &group = QString() );
306
307
315 bool importFromFile( const QString &path );
316
317 signals:
318
320 void bookmarkAboutToBeAdded( const QString &id );
321
323 void bookmarkAdded( const QString &id );
324
326 void bookmarkRemoved( const QString &id );
327
329 void bookmarkAboutToBeRemoved( const QString &id );
330
332 void bookmarkChanged( const QString &id );
333
334 private:
335
336 QgsProject *mProject = nullptr;
337 QString mFilePath;
338 QList< QgsBookmark > mBookmarks;
339 QStringList mGroups;
340
341 void store();
342 bool mInitialized = false;
343
344};
345
346#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:112
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)