Skip to content

Commit 9ae32d3

Browse files
Steven Mizunojef-n
authored andcommittedJun 2, 2011
applied #3863 (fixes #2774)
1 parent 94dc380 commit 9ae32d3

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
@@ -6338,7 +6338,6 @@ void QgisApp::showBookmarks()
63386338
{
63396339
bookmarks = new QgsBookmarks( this, Qt::WindowMinMaxButtonsHint );
63406340
}
6341-
bookmarks->restorePosition();
63426341
bookmarks->show();
63436342
bookmarks->raise();
63446343
bookmarks->setWindowState( bookmarks->windowState() & ~Qt::WindowMinimized );

‎src/app/qgsbookmarkitem.cpp

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

67-
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
62+
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );
6863

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

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

‎src/app/qgsbookmarks.cpp

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
3737
mParent( parent )
3838
{
3939
setupUi( this );
40+
41+
restorePosition();
42+
4043
// user database is created at QGIS startup in QgisApp::createDB
4144
// we just check whether there is our database [MD]
4245
QFileInfo myFileInfo;
@@ -53,11 +56,15 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
5356
// Create the zoomto and delete buttons and add them to the
5457
// toolbar
5558
//
59+
QPushButton * btnUpdate = new QPushButton( tr( "&Update" ) );
5660
QPushButton * btnDelete = new QPushButton( tr( "&Delete" ) );
5761
QPushButton * btnZoomTo = new QPushButton( tr( "&Zoom to" ) );
5862
btnZoomTo->setDefault( true );
63+
buttonBox->addButton( btnUpdate, QDialogButtonBox::ActionRole );
5964
buttonBox->addButton( btnDelete, QDialogButtonBox::ActionRole );
6065
buttonBox->addButton( btnZoomTo, QDialogButtonBox::ActionRole );
66+
// connect the slot up to catch when a bookmark is updated
67+
connect( btnUpdate, SIGNAL( clicked() ), this, SLOT( on_btnUpdate_clicked() ) );
6168
// connect the slot up to catch when a bookmark is deleted
6269
connect( btnDelete, SIGNAL( clicked() ), this, SLOT( on_btnDelete_clicked() ) );
6370
// connect the slot up to catch when a bookmark is zoomed to
@@ -108,7 +115,7 @@ void QgsBookmarks::initialise()
108115
QString xMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 5 ) );
109116
QString yMax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 6 ) );
110117
// set the extents
111-
item->setText( 2, xMin + ", " + yMin + ", " + xMax + ", " + yMax );
118+
item->setText( 2, xMin + ", " + yMin + " : " + xMax + ", " + yMax ); // use colon to separate ll from ur corners listed (be consistent with other displays of extent)
112119
// set the id
113120
item->setText( 3, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ) );
114121
}
@@ -144,6 +151,66 @@ void QgsBookmarks::saveWindowLocation()
144151
settings.setValue( "/Windows/Bookmarks/geometry", saveGeometry() );
145152
}
146153

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

189-
void QgsBookmarks::on_lstBookmarks_doubleClicked( QTreeWidgetItem *lvi )
256+
void QgsBookmarks::on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem *lvi )
190257
{
191258
zoomToBookmark();
192259
}

‎src/app/qgsbookmarks.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase
3434
void restorePosition();
3535
private slots:
3636
void saveWindowLocation();
37+
void on_btnUpdate_clicked();
3738
void on_btnDelete_clicked();
3839
void on_btnZoomTo_clicked();
39-
void on_lstBookmarks_doubleClicked( QTreeWidgetItem * );
40+
void on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem * );
4041
void refreshBookmarks();
4142

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

0 commit comments

Comments
 (0)
Please sign in to comment.