41 b.
setId( element.attribute( QStringLiteral(
"id" ) ) );
42 b.
setName( element.attribute( QStringLiteral(
"name" ) ) );
43 b.
setGroup( element.attribute( QStringLiteral(
"group" ) ) );
53 QDomElement bookmarkElem = doc.createElement( QStringLiteral(
"Bookmark" ) );
54 bookmarkElem.setAttribute( QStringLiteral(
"id" ), mId );
55 bookmarkElem.setAttribute( QStringLiteral(
"name" ), mName );
56 bookmarkElem.setAttribute( QStringLiteral(
"group" ), mGroup );
57 bookmarkElem.setAttribute( QStringLiteral(
"extent" ), mExtent.
asWktPolygon() );
64 return mId == other.mId && mName == other.mName && mExtent == other.mExtent && mGroup == other.mGroup;
69 return !( *
this == other );
110 res->mProject = project;
131 if ( bookmark.
id().isEmpty() )
132 bookmark.
setId( QUuid::createUuid().toString() );
136 for (
const QgsBookmark &b : qgis::as_const( mBookmarks ) )
138 if ( b.
id() == bookmark.
id() )
149 mBookmarks << bookmark;
150 if ( !mGroups.contains( bookmark.group() ) )
151 mGroups << bookmark.group();
158 return bookmark.id();
169 for (
const QgsBookmark &b : qgis::as_const( mBookmarks ) )
184 mBookmarks.removeAt( pos );
186 mGroups.removeOne( group );
200 for (
const QgsBookmark &b : qgis::as_const( mBookmarks ) )
202 if ( b.id() == bookmark.
id() )
204 if ( mBookmarks[i].group() != bookmark.
group() )
207 mGroups.removeOne( mBookmarks[i].group() );
208 if ( !mGroups.contains( bookmark.
group() ) )
209 mGroups << bookmark.
group();
211 mBookmarks[i] = bookmark;
227 const QList< QgsBookmark >
bookmarks = mBookmarks;
241 for (
int i = 0; i < mBookmarks.count(); ++i )
243 if ( mBookmarks.at( i ).group() == oldName )
245 mBookmarks[ i ].setGroup( newName );
271 if ( b.group() == group )
281 QDomElement bookmarksElem = element;
282 if ( element.tagName() != QStringLiteral(
"Bookmarks" ) )
284 bookmarksElem = element.firstChildElement( QStringLiteral(
"Bookmarks" ) );
287 if ( mProject && bookmarksElem.isNull() )
290 const int count = mProject->
readNumEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/count" ) );
291 for (
int i = 0; i < count; ++i )
293 const double minX = mProject->
readDoubleEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/MinX" ).arg( i ) );
294 const double minY = mProject->
readDoubleEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/MinY" ).arg( i ) );
295 const double maxX = mProject->
readDoubleEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/MaxX" ).arg( i ) );
296 const double maxY = mProject->
readDoubleEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/MaxY" ).arg( i ) );
297 const long srid = mProject->
readNumEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/SRID" ).arg( i ) );
299 b.
setId( QStringLiteral(
"bookmark_%1" ).arg( i ) );
300 b.
setName( mProject->
readEntry( QStringLiteral(
"Bookmarks" ), QStringLiteral(
"/Row-%1/Name" ).arg( i ) ) );
305 result = added && result;
311 QDomNodeList bookmarkNodes = element.elementsByTagName( QStringLiteral(
"Bookmark" ) );
312 for (
int i = 0; i < bookmarkNodes.size(); ++i )
317 result = added && result;
325 QDomElement bookmarksElem = doc.createElement( QStringLiteral(
"Bookmarks" ) );
329 QDomElement bookmarkElem = b.writeXml( doc );
330 bookmarksElem.appendChild( bookmarkElem );
332 return bookmarksElem;
338 if ( b.
id().isEmpty() )
350 QDomDocument doc( QStringLiteral(
"qgis_bookmarks" ) );
351 QDomElement root = doc.createElement( QStringLiteral(
"qgis_bookmarks" ) );
352 doc.appendChild( root );
354 QList<QString> headerList;
356 << QStringLiteral(
"project" )
357 << QStringLiteral(
"xmin" )
358 << QStringLiteral(
"ymin" )
359 << QStringLiteral(
"xmax" )
360 << QStringLiteral(
"ymax" )
361 << QStringLiteral(
"sr_id" );
365 const QList< QgsBookmark >
bookmarks = manager->bookmarks();
368 if ( !group.isEmpty() && b.group() != group )
371 QDomElement bookmark = doc.createElement( QStringLiteral(
"bookmark" ) );
372 root.appendChild( bookmark );
374 QDomElement
id = doc.createElement( QStringLiteral(
"id" ) );
375 id.appendChild( doc.createTextNode( b.id() ) );
376 bookmark.appendChild(
id );
378 QDomElement name = doc.createElement( QStringLiteral(
"name" ) );
379 name.appendChild( doc.createTextNode( b.name() ) );
380 bookmark.appendChild( name );
382 QDomElement group = doc.createElement( QStringLiteral(
"project" ) );
383 group.appendChild( doc.createTextNode( b.group() ) );
384 bookmark.appendChild( group );
386 QDomElement xMin = doc.createElement( QStringLiteral(
"xmin" ) );
387 xMin.appendChild( doc.createTextNode(
qgsDoubleToString( b.extent().xMinimum() ) ) );
388 bookmark.appendChild( xMin );
389 QDomElement yMin = doc.createElement( QStringLiteral(
"ymin" ) );
390 yMin.appendChild( doc.createTextNode(
qgsDoubleToString( b.extent().yMinimum() ) ) );
391 bookmark.appendChild( yMin );
392 QDomElement xMax = doc.createElement( QStringLiteral(
"xmax" ) );
393 xMax.appendChild( doc.createTextNode(
qgsDoubleToString( b.extent().xMaximum() ) ) );
394 bookmark.appendChild( xMax );
395 QDomElement yMax = doc.createElement( QStringLiteral(
"ymax" ) );
396 yMax.appendChild( doc.createTextNode(
qgsDoubleToString( b.extent().yMaximum() ) ) );
397 bookmark.appendChild( yMax );
399 QDomElement
crs = doc.createElement( QStringLiteral(
"sr_id" ) );
400 crs.appendChild( doc.createTextNode( QString::number( b.extent().crs().srsid() ) ) );
401 bookmark.appendChild(
crs );
406 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
412 QTextStream out( &f );
413 out.setCodec(
"UTF-8" );
422 if ( path.isEmpty() )
428 if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) )
434 if ( !doc.setContent( &f ) )
440 QDomElement docElem = doc.documentElement();
441 QDomNodeList nodeList = docElem.elementsByTagName( QStringLiteral(
"bookmark" ) );
444 for (
int i = 0; i < nodeList.count(); i++ )
446 QDomNode bookmark = nodeList.at( i );
447 QDomElement name = bookmark.firstChildElement( QStringLiteral(
"name" ) );
448 QDomElement prjname = bookmark.firstChildElement( QStringLiteral(
"project" ) );
449 QDomElement xmin = bookmark.firstChildElement( QStringLiteral(
"xmin" ) );
450 QDomElement ymin = bookmark.firstChildElement( QStringLiteral(
"ymin" ) );
451 QDomElement xmax = bookmark.firstChildElement( QStringLiteral(
"xmax" ) );
452 QDomElement ymax = bookmark.firstChildElement( QStringLiteral(
"ymax" ) );
453 QDomElement srid = bookmark.firstChildElement( QStringLiteral(
"sr_id" ) );
462 ymin.text().toDouble(),
463 xmax.text().toDouble(),
464 ymax.text().toDouble() ),
crs ) );
472 void QgsBookmarkManager::store()
474 if ( !mFilePath.isEmpty() )
476 QFile f( mFilePath );
477 if ( !f.open( QFile::WriteOnly | QIODevice::Truncate ) )
485 doc.appendChild( elem );
487 QTextStream out( &f );
488 out.setCodec(
"UTF-8" );
499 mFilePath = filePath;
504 if ( !QFileInfo::exists( mFilePath ) )
509 if ( result != SQLITE_OK )
515 if ( result == SQLITE_OK )
517 while ( preparedStatement.
step() == SQLITE_ROW )
519 const QString name = preparedStatement.
columnAsText( 0 );
537 QFile f( mFilePath );
538 if ( !f.open( QIODevice::ReadOnly | QIODevice::Text ) )
544 if ( !doc.setContent( &f ) )
550 QDomElement elem = doc.documentElement();