42  b.
setId( element.attribute( QStringLiteral( 
"id" ) ) );
 
   43  b.
setName( element.attribute( QStringLiteral( 
"name" ) ) );
 
   44  b.
setGroup( element.attribute( QStringLiteral( 
"group" ) ) );
 
   54  QDomElement bookmarkElem = doc.createElement( QStringLiteral( 
"Bookmark" ) );
 
   55  bookmarkElem.setAttribute( QStringLiteral( 
"id" ), mId );
 
   56  bookmarkElem.setAttribute( QStringLiteral( 
"name" ), mName );
 
   57  bookmarkElem.setAttribute( QStringLiteral( 
"group" ), mGroup );
 
   58  bookmarkElem.setAttribute( QStringLiteral( 
"extent" ), mExtent.
asWktPolygon() );
 
   65  return mId == other.mId && mName == other.mName && mExtent == other.mExtent && mGroup == other.mGroup;
 
   70  return !( *
this == other );
 
  111  res->mProject = project;
 
  132  if ( bookmark.
id().isEmpty() )
 
  133    bookmark.
setId( QUuid::createUuid().toString() );
 
  137    for ( 
const QgsBookmark &b : std::as_const( mBookmarks ) )
 
  139      if ( b.
id() == bookmark.
id() )
 
  150  mBookmarks << bookmark;
 
  151  if ( !mGroups.contains( bookmark.
group() ) )
 
  152    mGroups << bookmark.
group();
 
  159  return bookmark.
id();
 
  170  for ( 
const QgsBookmark &b : std::as_const( mBookmarks ) )
 
  185  mBookmarks.removeAt( pos );
 
  187    mGroups.removeOne( group );
 
  201  for ( 
const QgsBookmark &b : std::as_const( mBookmarks ) )
 
  203    if ( b.id() == bookmark.
id() )
 
  205      if ( mBookmarks[i].group() != bookmark.
group() )
 
  208          mGroups.removeOne( mBookmarks[i].group() );
 
  209        if ( !mGroups.contains( bookmark.
group() ) )
 
  210          mGroups << bookmark.
group();
 
  212      mBookmarks[i] = bookmark;
 
  228  const QList< QgsBookmark > 
bookmarks = mBookmarks;
 
  242  for ( 
int i = 0; i < mBookmarks.count(); ++i )
 
  244    if ( mBookmarks.at( i ).group() == oldName )
 
  246      mBookmarks[ i ].setGroup( newName );
 
  272    if ( b.group() == group )
 
  282  QDomElement bookmarksElem = element;
 
  283  if ( element.tagName() != QLatin1String( 
"Bookmarks" ) )
 
  285    bookmarksElem = element.firstChildElement( QStringLiteral( 
"Bookmarks" ) );
 
  288  if ( mProject && bookmarksElem.isNull() )
 
  291    const int count = mProject->
readNumEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/count" ) );
 
  292    for ( 
int i = 0; i < count; ++i )
 
  294      const double minX = mProject->
readDoubleEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/MinX" ).arg( i ) );
 
  295      const double minY = mProject->
readDoubleEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/MinY" ).arg( i ) );
 
  296      const double maxX = mProject->
readDoubleEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/MaxX" ).arg( i ) );
 
  297      const double maxY = mProject->
readDoubleEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/MaxY" ).arg( i ) );
 
  298      const long srid = mProject->
readNumEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/SRID" ).arg( i ) );
 
  300      b.
setId( QStringLiteral( 
"bookmark_%1" ).arg( i ) );
 
  301      b.
setName( mProject->
readEntry( QStringLiteral( 
"Bookmarks" ), QStringLiteral( 
"/Row-%1/Name" ).arg( i ) ) );
 
  306      result = added && result;
 
  312  QDomNodeList bookmarkNodes = element.elementsByTagName( QStringLiteral( 
"Bookmark" ) );
 
  313  for ( 
int i = 0; i < bookmarkNodes.size(); ++i )
 
  318    result = added && result;
 
  326  QDomElement bookmarksElem = doc.createElement( QStringLiteral( 
"Bookmarks" ) );
 
  330    QDomElement bookmarkElem = b.writeXml( doc );
 
  331    bookmarksElem.appendChild( bookmarkElem );
 
  333  return bookmarksElem;
 
  339  if ( b.
id().isEmpty() )
 
  351  QDomDocument doc( QStringLiteral( 
"qgis_bookmarks" ) );
 
  352  QDomElement root = doc.createElement( QStringLiteral( 
"qgis_bookmarks" ) );
 
  353  doc.appendChild( root );
 
  355  QList<QString> headerList;
 
  357      << QStringLiteral( 
"project" )
 
  358      << QStringLiteral( 
"xmin" )
 
  359      << QStringLiteral( 
"ymin" )
 
  360      << QStringLiteral( 
"xmax" )
 
  361      << QStringLiteral( 
"ymax" )
 
  362      << QStringLiteral( 
"sr_id" );
 
  366    const QList< QgsBookmark > 
bookmarks = manager->bookmarks();
 
  369      if ( !group.isEmpty() && b.group() != group )
 
  372      QDomElement bookmark = doc.createElement( QStringLiteral( 
"bookmark" ) );
 
  373      root.appendChild( bookmark );
 
  375      QDomElement 
id = doc.createElement( QStringLiteral( 
"id" ) );
 
  376      id.appendChild( doc.createTextNode( b.id() ) );
 
  377      bookmark.appendChild( 
id );
 
  379      QDomElement name = doc.createElement( QStringLiteral( 
"name" ) );
 
  380      name.appendChild( doc.createTextNode( b.name() ) );
 
  381      bookmark.appendChild( name );
 
  383      QDomElement group = doc.createElement( QStringLiteral( 
"project" ) );
 
  384      group.appendChild( doc.createTextNode( b.group() ) );
 
  385      bookmark.appendChild( group );
 
  387      QDomElement xMin = doc.createElement( QStringLiteral( 
"xmin" ) );
 
  388      xMin.appendChild( doc.createTextNode( 
qgsDoubleToString( b.extent().xMinimum() ) ) );
 
  389      bookmark.appendChild( xMin );
 
  390      QDomElement yMin = doc.createElement( QStringLiteral( 
"ymin" ) );
 
  391      yMin.appendChild( doc.createTextNode( 
qgsDoubleToString( b.extent().yMinimum() ) ) );
 
  392      bookmark.appendChild( yMin );
 
  393      QDomElement xMax = doc.createElement( QStringLiteral( 
"xmax" ) );
 
  394      xMax.appendChild( doc.createTextNode( 
qgsDoubleToString( b.extent().xMaximum() ) ) );
 
  395      bookmark.appendChild( xMax );
 
  396      QDomElement yMax = doc.createElement( QStringLiteral( 
"ymax" ) );
 
  397      yMax.appendChild( doc.createTextNode( 
qgsDoubleToString( b.extent().yMaximum() ) ) );
 
  398      bookmark.appendChild( yMax );
 
  400      QDomElement 
crs = doc.createElement( QStringLiteral( 
"sr_id" ) );
 
  401      crs.appendChild( doc.createTextNode( QString::number( b.extent().crs().srsid() ) ) );
 
  402      bookmark.appendChild( 
crs );
 
  407  if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
 
  413  QTextStream out( &f );
 
  414#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 
  415  out.setCodec( 
"UTF-8" );
 
  425  if ( path.isEmpty() )
 
  431  if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) )
 
  437  if ( !doc.setContent( &f ) )
 
  443  QDomElement docElem = doc.documentElement();
 
  444  QDomNodeList nodeList = docElem.elementsByTagName( QStringLiteral( 
"bookmark" ) );
 
  447  for ( 
int i = 0; i < nodeList.count(); i++ )
 
  449    QDomNode bookmark = nodeList.at( i );
 
  450    QDomElement name = bookmark.firstChildElement( QStringLiteral( 
"name" ) );
 
  451    QDomElement prjname = bookmark.firstChildElement( QStringLiteral( 
"project" ) );
 
  452    QDomElement xmin = bookmark.firstChildElement( QStringLiteral( 
"xmin" ) );
 
  453    QDomElement ymin = bookmark.firstChildElement( QStringLiteral( 
"ymin" ) );
 
  454    QDomElement xmax = bookmark.firstChildElement( QStringLiteral( 
"xmax" ) );
 
  455    QDomElement ymax = bookmark.firstChildElement( QStringLiteral( 
"ymax" ) );
 
  456    QDomElement srid = bookmark.firstChildElement( QStringLiteral( 
"sr_id" ) );
 
  465                                         ymin.text().toDouble(),
 
  466                                         xmax.text().toDouble(),
 
  467                                         ymax.text().toDouble() ), 
crs ) );
 
  475void QgsBookmarkManager::store()
 
  477  if ( !mFilePath.isEmpty() )
 
  479    QFile f( mFilePath );
 
  480    if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
 
  488    doc.appendChild( elem );
 
  490    QTextStream out( &f );
 
  491#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 
  492    out.setCodec( 
"UTF-8" );
 
  504  mFilePath = filePath;
 
  509  if ( !QFileInfo::exists( mFilePath ) )
 
  514    if ( result != SQLITE_OK )
 
  520    if ( result == SQLITE_OK )
 
  522      while ( preparedStatement.
step() == SQLITE_ROW )
 
  524        const QString name = preparedStatement.
columnAsText( 0 );
 
  542    QFile f( mFilePath );
 
  543    if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) )
 
  549    if ( !doc.setContent( &f ) )
 
  555    QDomElement elem = doc.documentElement();
 
static QString qgisUserDatabaseFilePath()
Returns the path to the user qgis.db file.
 
Manages storage of a set of bookmarks.
 
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.
 
~QgsBookmarkManager() override
 
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.
 
bool operator!=(const QgsBookmark &other) const
 
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.
 
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.
 
bool operator==(const QgsBookmark &other) const
 
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.
 
This class represents a coordinate reference system (CRS).
 
bool readXml(const QDomNode &node)
Restores state from the given DOM node.
 
bool createFromSrsId(long srsId)
Sets this CRS by lookup of internal QGIS CRS ID in the CRS database.
 
bool writeXml(QDomNode &node, QDomDocument &doc) const
Stores state to the given Dom node in the given document.
 
static QgsCoordinateReferenceSystem fromSrsId(long srsId)
Creates a CRS from a specified QGIS SRS ID.
 
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
 
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
Reads an integer from the specified scope and key.
 
QString readEntry(const QString &scope, const QString &key, const QString &def=QString(), bool *ok=nullptr) const
Reads a string from the specified scope and key.
 
double readDoubleEntry(const QString &scope, const QString &key, double def=0, bool *ok=nullptr) const
Reads a double from the specified scope and key.
 
void setDirty(bool b=true)
Flag the project as dirty (modified).
 
A rectangle specified with double values.
 
static QgsRectangle fromWkt(const QString &wkt)
Creates a new rectangle from a wkt string.
 
QString asWktPolygon() const
Returns a string representation of the rectangle as a WKT Polygon.
 
QgsCoordinateReferenceSystem crs() const
Returns the associated coordinate reference system, or an invalid CRS if no reference system is set.
 
A QgsRectangle with associated coordinate reference system.
 
Unique pointer for sqlite3 databases, which automatically closes the database when the pointer goes o...
 
sqlite3_statement_unique_ptr prepare(const QString &sql, int &resultCode) const
Prepares a sql statement, returning the result.
 
int open(const QString &path)
Opens the database at the specified file path.
 
Unique pointer for sqlite3 prepared statements, which automatically finalizes the statement when the ...
 
QString columnAsText(int column) const
Returns the column value from the current statement row as a string.
 
double columnAsDouble(int column) const
Gets column value from the current statement row as a double.
 
int step()
Steps to the next record in the statement, returning the sqlite3 result code.
 
qlonglong columnAsInt64(int column) const
Gets column value from the current statement row as a long long integer (64 bits).
 
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
 
const QgsCoordinateReferenceSystem & crs