Skip to content

Commit bc30e89

Browse files
Steven Mizunojef-n
authored andcommitted
applied #3863 (fixes #2774)
1 parent 445ef93 commit bc30e89

File tree

6 files changed

+105
-39
lines changed

6 files changed

+105
-39
lines changed

doc/CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Richard Duivenvoorde
4848
Richard Kostecky
4949
Robert Szczepanek
5050
Stefanie Tellex
51+
Steven Mizuno
5152
Tom Russo
5253
Tyler Mitchell
5354
Vita Cizek

resources/context_help/QgsBookmarks-en_US

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Spatial Bookmarks allow you to "bookmark" a geographic location and return to it
55
<a href="#working">Working with Bookmarks</a><br/>
66
<a href="#zooming">Zooming to a Bookmark</a><br/>
77
<a href="#deleting">Deleting a Bookmark</a><br/>
8+
<a href="#updating">Updating a Bookmark</a><br/>
89

910
<a name="creating">
1011
<h4>Creating a Bookmark</h4>
@@ -31,4 +32,8 @@ You can also zoom to a bookmark by double-clicking on it.
3132
<h5>Deleting a Bookmark</h5>
3233
</a>
3334
To delete a bookmark from the Bookmarks dialog, click on it then click the <label>Delete</label> button. Confirm your choice by clicking <label>OK</label> or cancel the delete by clicking <label>Cancel</label>.
35+
<a name="updating">
36+
<h5>Updating a Bookmark</h5>
37+
</a>
38+
To update the extent of a bookmark, click on it then click the <label>Update</label> button. Confirm your choice by clicking <label>OK</label> or cancel the update by clicking <label>Cancel</label>.
3439

src/app/qgisapp.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6518,7 +6518,6 @@ void QgisApp::showBookmarks()
65186518
{
65196519
bookmarks = new QgsBookmarks( this, Qt::WindowMinMaxButtonsHint );
65206520
}
6521-
bookmarks->restorePosition();
65226521
bookmarks->show();
65236522
bookmarks->raise();
65246523
bookmarks->setWindowState( bookmarks->windowState() & ~Qt::WindowMinimized );

src/app/qgsbookmarkitem.cpp

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,41 @@ void QgsBookmarkItem::store()
4343
int rc;
4444
QgsDebugMsg( QString( "Opening user database: %1" ).arg( mUserDbPath ) );
4545
rc = sqlite3_open( mUserDbPath.toUtf8().data(), &db );
46-
if ( rc )
46+
if ( SQLITE_OK == rc )
4747
{
48-
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );
49-
50-
// XXX This will likely never happen since on open, sqlite creates the
51-
// database if it does not exist.
52-
assert( rc == 0 );
53-
}
54-
// prepare the sql statement
55-
const char *pzTail;
56-
sqlite3_stmt *ppStmt;
57-
QString sql;
58-
QTextStream sqlStream( &sql );
59-
sqlStream << "insert into tbl_bookmarks values(null,'" <<
60-
mName << "','" <<
61-
mProjectTitle << "'," <<
62-
mViewExtent.xMinimum() << "," <<
63-
mViewExtent.yMinimum() << "," <<
64-
mViewExtent.xMaximum() << "," <<
65-
mViewExtent.yMaximum() << "," <<
66-
mSrid << ")";
48+
// prepare the sql statement
49+
QString sql;
50+
QTextStream sqlStream( &sql );
51+
// use '17 g' format; SmartNotation is default
52+
sqlStream.setRealNumberPrecision( 17 );
53+
sqlStream << "insert into tbl_bookmarks values(null,'" <<
54+
// fix occurrences of single-quote
55+
mName.replace( '\'', "''" ) << "','" <<
56+
mProjectTitle.replace( '\'', "''" ) << "'," <<
57+
mViewExtent.xMinimum() << "," <<
58+
mViewExtent.yMinimum() << "," <<
59+
mViewExtent.xMaximum() << "," <<
60+
mViewExtent.yMaximum() << "," <<
61+
mSrid << ")";
6762

68-
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
63+
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
6964

70-
QByteArray sqlData = sql.toUtf8();
71-
72-
rc = sqlite3_prepare( db, sqlData.constData(), sqlData.size(), &ppStmt, &pzTail );
73-
// XXX Need to free memory from the error msg if one is set
74-
if ( rc == SQLITE_OK )
75-
{
76-
// get the first row of the result set
77-
if ( sqlite3_step( ppStmt ) != SQLITE_DONE )
65+
char * errmsg = 0;
66+
rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
67+
if ( rc != SQLITE_OK )
7868
{
79-
8069
// XXX query failed -- warn the user some how
81-
QgsDebugMsg( QString( "Failed to store bookmark: %1" ).arg( sqlite3_errmsg( db ) ) );
70+
QgsDebugMsg( QString( "Failed to store bookmark: %1" ).arg( errmsg ) );
71+
sqlite3_free( errmsg );
8272
}
83-
// close the statement
84-
sqlite3_finalize( ppStmt );
85-
// close the database
8673
sqlite3_close( db );
8774
}
75+
else
76+
{
77+
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );
8878

89-
79+
// XXX This will likely never happen since on open, sqlite creates the
80+
// database if it does not exist.
81+
assert( rc == 0 );
82+
}
9083
}

src/app/qgsbookmarks.cpp

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
3838
mParent( parent )
3939
{
4040
setupUi( this );
41+
42+
restorePosition();
43+
4144
// user database is created at QGIS startup in QgisApp::createDB
4245
// we just check whether there is our database [MD]
4346
QFileInfo myFileInfo;
@@ -54,11 +57,15 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
5457
// Create the zoomto and delete buttons and add them to the
5558
// toolbar
5659
//
60+
QPushButton * btnUpdate = new QPushButton( tr( "&Update" ) );
5761
QPushButton * btnDelete = new QPushButton( tr( "&Delete" ) );
5862
QPushButton * btnZoomTo = new QPushButton( tr( "&Zoom to" ) );
5963
btnZoomTo->setDefault( true );
64+
buttonBox->addButton( btnUpdate, QDialogButtonBox::ActionRole );
6065
buttonBox->addButton( btnDelete, QDialogButtonBox::ActionRole );
6166
buttonBox->addButton( btnZoomTo, QDialogButtonBox::ActionRole );
67+
// connect the slot up to catch when a bookmark is updated
68+
connect( btnUpdate, SIGNAL( clicked() ), this, SLOT( on_btnUpdate_clicked() ) );
6269
// connect the slot up to catch when a bookmark is deleted
6370
connect( btnDelete, SIGNAL( clicked() ), this, SLOT( on_btnDelete_clicked() ) );
6471
// connect the slot up to catch when a bookmark is zoomed to
@@ -109,7 +116,7 @@ void QgsBookmarks::initialise()
109116
QString xMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 5 ) );
110117
QString yMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 6 ) );
111118
// set the extents
112-
item->setText( 2, xMin + ", " + yMin + ", " + xMax + ", " + yMax );
119+
item->setText( 2, xMin + ", " + yMin + " : " + xMax + ", " + yMax ); // use colon to separate ll from ur corners listed (be consistent with other displays of extent)
113120
// set the id
114121
item->setText( 3, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
115122
}
@@ -145,6 +152,66 @@ void QgsBookmarks::saveWindowLocation()
145152
settings.setValue( "/Windows/Bookmarks/geometry", saveGeometry() );
146153
}
147154

155+
void QgsBookmarks::on_btnUpdate_clicked()
156+
{
157+
// get the current item
158+
QTreeWidgetItem *item = lstBookmarks->currentItem();
159+
if ( item )
160+
{
161+
// make sure the user really wants to update this bookmark
162+
if ( QMessageBox::Ok == QMessageBox::information( this, tr( "Really Update?" ),
163+
tr( "Are you sure you want to update the %1 bookmark?" ).arg( item->text( 0 ) ),
164+
QMessageBox::Ok | QMessageBox::Cancel ) )
165+
{
166+
// retrieve the current map extent
167+
QgsRectangle viewExtent = QgisApp::instance()->mapCanvas()->extent();
168+
169+
int rc;
170+
QgsDebugMsg( QString( "Opening user database: %1" ).arg( QgsApplication::qgisUserDbFilePath() ) );
171+
rc = connectDb();
172+
if ( SQLITE_OK == rc )
173+
{
174+
// prepare the sql statement
175+
QString sql;
176+
QTextStream sqlStream( &sql );
177+
// use '17 g' format; SmartNotation is default
178+
sqlStream.setRealNumberPrecision( 17 );
179+
sqlStream << "update tbl_bookmarks set " <<
180+
"xmin=" << viewExtent.xMinimum() << "," <<
181+
"ymin=" << viewExtent.yMinimum() << "," <<
182+
"xmax=" << viewExtent.xMaximum() << "," <<
183+
"ymax=" << viewExtent.yMaximum() << " " <<
184+
"where bookmark_id=" << item->text( 3 );
185+
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
186+
187+
char * errmsg;
188+
rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg );
189+
if ( rc != SQLITE_OK )
190+
{
191+
// XXX Provide popup message on failure?
192+
QMessageBox::warning( this, tr( "Error updating bookmark" ),
193+
tr( "Failed to update the %1 bookmark. The database said:\n%2" )
194+
.arg( item->text( 0 ) ).arg( errmsg ) );
195+
sqlite3_free( errmsg );
196+
}
197+
// close the database
198+
sqlite3_close( db );
199+
200+
refreshBookmarks();
201+
202+
}
203+
else
204+
{
205+
QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) );
206+
207+
// XXX This will likely never happen since on open, sqlite creates the
208+
// database if it does not exist.
209+
assert( rc == 0 );
210+
}
211+
}
212+
}
213+
}
214+
148215
void QgsBookmarks::on_btnDelete_clicked()
149216
{
150217
// get the current item
@@ -187,7 +254,7 @@ void QgsBookmarks::on_btnZoomTo_clicked()
187254
zoomToBookmark();
188255
}
189256

190-
void QgsBookmarks::on_lstBookmarks_doubleClicked( QTreeWidgetItem *lvi )
257+
void QgsBookmarks::on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem *lvi )
191258
{
192259
zoomToBookmark();
193260
}

src/app/qgsbookmarks.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase
3535
void restorePosition();
3636
private slots:
3737
void saveWindowLocation();
38+
void on_btnUpdate_clicked();
3839
void on_btnDelete_clicked();
3940
void on_btnZoomTo_clicked();
40-
void on_lstBookmarks_doubleClicked( QTreeWidgetItem * );
41+
void on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem * );
4142
void refreshBookmarks();
4243

4344
void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }

0 commit comments

Comments
 (0)