diff --git a/doc/CONTRIBUTORS b/doc/CONTRIBUTORS
index e397d363f85..d29403c394c 100644
--- a/doc/CONTRIBUTORS
+++ b/doc/CONTRIBUTORS
@@ -48,6 +48,7 @@ Richard Duivenvoorde
Richard Kostecky
Robert Szczepanek
Stefanie Tellex
+Steven Mizuno
Tom Russo
Tyler Mitchell
Vita Cizek
diff --git a/resources/context_help/QgsBookmarks-en_US b/resources/context_help/QgsBookmarks-en_US
index d516a1dad55..8b89bf2d3aa 100644
--- a/resources/context_help/QgsBookmarks-en_US
+++ b/resources/context_help/QgsBookmarks-en_US
@@ -5,6 +5,7 @@ Spatial Bookmarks allow you to "bookmark" a geographic location and return to it
Working with Bookmarks
Zooming to a Bookmark
Deleting a Bookmark
+Updating a Bookmark
Creating a Bookmark
@@ -31,4 +32,8 @@ You can also zoom to a bookmark by double-clicking on it.
Deleting a Bookmark
To delete a bookmark from the Bookmarks dialog, click on it then click the Delete button. Confirm your choice by clicking OK or cancel the delete by clicking Cancel .
+
+Updating a Bookmark
+
+To update the extent of a bookmark, click on it then click the Update button. Confirm your choice by clicking OK or cancel the update by clicking Cancel .
diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp
index 684c993f0d8..8829ebbdcd3 100644
--- a/src/app/qgisapp.cpp
+++ b/src/app/qgisapp.cpp
@@ -6338,7 +6338,6 @@ void QgisApp::showBookmarks()
{
bookmarks = new QgsBookmarks( this, Qt::WindowMinMaxButtonsHint );
}
- bookmarks->restorePosition();
bookmarks->show();
bookmarks->raise();
bookmarks->setWindowState( bookmarks->windowState() & ~Qt::WindowMinimized );
diff --git a/src/app/qgsbookmarkitem.cpp b/src/app/qgsbookmarkitem.cpp
index 254a19d5edc..64e00d258ec 100644
--- a/src/app/qgsbookmarkitem.cpp
+++ b/src/app/qgsbookmarkitem.cpp
@@ -42,7 +42,36 @@ void QgsBookmarkItem::store()
int rc;
QgsDebugMsg( QString( "Opening user database: %1" ).arg( mUserDbPath ) );
rc = sqlite3_open( mUserDbPath.toUtf8().data(), &db );
- if ( rc )
+ if ( SQLITE_OK == rc )
+ {
+ // prepare the sql statement
+ QString sql;
+ QTextStream sqlStream( &sql );
+ // use '17 g' format; SmartNotation is default
+ sqlStream.setRealNumberPrecision( 17 );
+ sqlStream << "insert into tbl_bookmarks values(null,'" <<
+ // fix occurrences of single-quote
+ mName.replace( '\'', "''" ) << "','" <<
+ mProjectTitle.replace( '\'', "''" ) << "'," <<
+ mViewExtent.xMinimum() << "," <<
+ mViewExtent.yMinimum() << "," <<
+ mViewExtent.xMaximum() << "," <<
+ mViewExtent.yMaximum() << "," <<
+ mSrid << ")";
+
+ QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
+
+ char * errmsg = 0;
+ rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
+ if ( rc != SQLITE_OK )
+ {
+ // XXX query failed -- warn the user some how
+ QgsDebugMsg( QString( "Failed to store bookmark: %1" ).arg( errmsg ) );
+ sqlite3_free( errmsg );
+ }
+ sqlite3_close( db );
+ }
+ else
{
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );
@@ -50,40 +79,4 @@ void QgsBookmarkItem::store()
// database if it does not exist.
assert( rc == 0 );
}
- // prepare the sql statement
- const char *pzTail;
- sqlite3_stmt *ppStmt;
- QString sql;
- QTextStream sqlStream( &sql );
- sqlStream << "insert into tbl_bookmarks values(null,'" <<
- mName << "','" <<
- mProjectTitle << "'," <<
- mViewExtent.xMinimum() << "," <<
- mViewExtent.yMinimum() << "," <<
- mViewExtent.xMaximum() << "," <<
- mViewExtent.yMaximum() << "," <<
- mSrid << ")";
-
- QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
-
- QByteArray sqlData = sql.toUtf8();
-
- rc = sqlite3_prepare( db, sqlData.constData(), sqlData.size(), &ppStmt, &pzTail );
- // XXX Need to free memory from the error msg if one is set
- if ( rc == SQLITE_OK )
- {
- // get the first row of the result set
- if ( sqlite3_step( ppStmt ) != SQLITE_DONE )
- {
-
- // XXX query failed -- warn the user some how
- QgsDebugMsg( QString( "Failed to store bookmark: %1" ).arg( sqlite3_errmsg( db ) ) );
- }
- // close the statement
- sqlite3_finalize( ppStmt );
- // close the database
- sqlite3_close( db );
- }
-
-
}
diff --git a/src/app/qgsbookmarks.cpp b/src/app/qgsbookmarks.cpp
index 1552772816f..214fcbfc3c8 100644
--- a/src/app/qgsbookmarks.cpp
+++ b/src/app/qgsbookmarks.cpp
@@ -37,6 +37,9 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
mParent( parent )
{
setupUi( this );
+
+ restorePosition();
+
// user database is created at QGIS startup in QgisApp::createDB
// we just check whether there is our database [MD]
QFileInfo myFileInfo;
@@ -53,11 +56,15 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
// Create the zoomto and delete buttons and add them to the
// toolbar
//
+ QPushButton * btnUpdate = new QPushButton( tr( "&Update" ) );
QPushButton * btnDelete = new QPushButton( tr( "&Delete" ) );
QPushButton * btnZoomTo = new QPushButton( tr( "&Zoom to" ) );
btnZoomTo->setDefault( true );
+ buttonBox->addButton( btnUpdate, QDialogButtonBox::ActionRole );
buttonBox->addButton( btnDelete, QDialogButtonBox::ActionRole );
buttonBox->addButton( btnZoomTo, QDialogButtonBox::ActionRole );
+ // connect the slot up to catch when a bookmark is updated
+ connect( btnUpdate, SIGNAL( clicked() ), this, SLOT( on_btnUpdate_clicked() ) );
// connect the slot up to catch when a bookmark is deleted
connect( btnDelete, SIGNAL( clicked() ), this, SLOT( on_btnDelete_clicked() ) );
// connect the slot up to catch when a bookmark is zoomed to
@@ -108,7 +115,7 @@ void QgsBookmarks::initialise()
QString xMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 5 ) );
QString yMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 6 ) );
// set the extents
- item->setText( 2, xMin + ", " + yMin + ", " + xMax + ", " + yMax );
+ item->setText( 2, xMin + ", " + yMin + " : " + xMax + ", " + yMax ); // use colon to separate ll from ur corners listed (be consistent with other displays of extent)
// set the id
item->setText( 3, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
}
@@ -144,6 +151,66 @@ void QgsBookmarks::saveWindowLocation()
settings.setValue( "/Windows/Bookmarks/geometry", saveGeometry() );
}
+void QgsBookmarks::on_btnUpdate_clicked()
+{
+ // get the current item
+ QTreeWidgetItem *item = lstBookmarks->currentItem();
+ if ( item )
+ {
+ // make sure the user really wants to update this bookmark
+ if ( QMessageBox::Ok == QMessageBox::information( this, tr( "Really Update?" ),
+ tr( "Are you sure you want to update the %1 bookmark?" ).arg( item->text( 0 ) ),
+ QMessageBox::Ok | QMessageBox::Cancel ) )
+ {
+ // retrieve the current map extent
+ QgsRectangle viewExtent = QgisApp::instance()->mapCanvas()->extent();
+
+ int rc;
+ QgsDebugMsg( QString( "Opening user database: %1" ).arg( QgsApplication::qgisUserDbFilePath() ) );
+ rc = connectDb();
+ if ( SQLITE_OK == rc )
+ {
+ // prepare the sql statement
+ QString sql;
+ QTextStream sqlStream( &sql );
+ // use '17 g' format; SmartNotation is default
+ sqlStream.setRealNumberPrecision( 17 );
+ sqlStream << "update tbl_bookmarks set " <<
+ "xmin=" << viewExtent.xMinimum() << "," <<
+ "ymin=" << viewExtent.yMinimum() << "," <<
+ "xmax=" << viewExtent.xMaximum() << "," <<
+ "ymax=" << viewExtent.yMaximum() << " " <<
+ "where bookmark_id=" << item->text( 3 );
+ QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
+
+ char * errmsg;
+ rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
+ if ( rc != SQLITE_OK )
+ {
+ // XXX Provide popup message on failure?
+ QMessageBox::warning( this, tr( "Error updating bookmark" ),
+ tr( "Failed to update the %1 bookmark. The database said:\n%2" )
+ .arg( item->text( 0 ) ).arg( errmsg ) );
+ sqlite3_free( errmsg );
+ }
+ // close the database
+ sqlite3_close( db );
+
+ refreshBookmarks();
+
+ }
+ else
+ {
+ QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );
+
+ // XXX This will likely never happen since on open, sqlite creates the
+ // database if it does not exist.
+ assert( rc == 0 );
+ }
+ }
+ }
+}
+
void QgsBookmarks::on_btnDelete_clicked()
{
// get the current item
@@ -186,7 +253,7 @@ void QgsBookmarks::on_btnZoomTo_clicked()
zoomToBookmark();
}
-void QgsBookmarks::on_lstBookmarks_doubleClicked( QTreeWidgetItem *lvi )
+void QgsBookmarks::on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem *lvi )
{
zoomToBookmark();
}
diff --git a/src/app/qgsbookmarks.h b/src/app/qgsbookmarks.h
index 511dd5a0f5e..2e10216d768 100644
--- a/src/app/qgsbookmarks.h
+++ b/src/app/qgsbookmarks.h
@@ -34,9 +34,10 @@ class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase
void restorePosition();
private slots:
void saveWindowLocation();
+ void on_btnUpdate_clicked();
void on_btnDelete_clicked();
void on_btnZoomTo_clicked();
- void on_lstBookmarks_doubleClicked( QTreeWidgetItem * );
+ void on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem * );
void refreshBookmarks();
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }