diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 0f7ea3f35484..0354dbd05756 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -12,7 +12,6 @@ SET(QGIS_APP_SRCS qgsattributetypedialog.cpp qgsattributetypeloaddialog.cpp qgsattributetabledialog.cpp - qgsbookmarkitem.cpp qgsbookmarks.cpp qgsbrowserdockwidget.cpp qgsclipboard.cpp diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 4111a9a47254..b2749840a0e5 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -101,7 +101,6 @@ #include "qgsapplication.h" #include "qgsattributeaction.h" #include "qgsattributetabledialog.h" -#include "qgsbookmarkitem.h" #include "qgsbookmarks.h" #include "qgsbrowserdockwidget.h" #include "qgsclipboard.h" @@ -6751,48 +6750,15 @@ void QgisApp::customProjection() myDialog->setAttribute( Qt::WA_DeleteOnClose ); myDialog->show(); } -void QgisApp::showBookmarks() -{ - // Create or show the single instance of the Bookmarks modeless dialog. - // Closing a QWidget only hides it so it can be shown again later. - static QgsBookmarks *bookmarks = NULL; - if ( bookmarks == NULL ) - { - bookmarks = new QgsBookmarks( this, Qt::WindowMinMaxButtonsHint ); - } - bookmarks->show(); - bookmarks->raise(); - bookmarks->setWindowState( bookmarks->windowState() & ~Qt::WindowMinimized ); - bookmarks->activateWindow(); -} void QgisApp::newBookmark() { - // Get the name for the bookmark. Everything else we fetch from - // the mapcanvas + QgsBookmarks::newBookmark(); +} - bool ok; - QString bookmarkName = QInputDialog::getText( this, tr( "New Bookmark" ), - tr( "Enter a name for the new bookmark:" ), QLineEdit::Normal, - QString::null, &ok ); - if ( ok && !bookmarkName.isEmpty() ) - { - if ( createDB() ) - { - // create the bookmark - QgsBookmarkItem *bmi = new QgsBookmarkItem( bookmarkName, - QgsProject::instance()->title(), mMapCanvas->extent(), -1, - QgsApplication::qgisUserDbFilePath() ); - bmi->store(); - delete bmi; - // emit a signal to indicate that the bookmark was added - emit bookmarkAdded(); - } - else - { - QMessageBox::warning( this, tr( "Error" ), tr( "Unable to create the bookmark. Your user database may be missing or corrupted" ) ); - } - } +void QgisApp::showBookmarks() +{ + QgsBookmarks::showBookmarks(); } // Slot that gets called when the project file was saved with an older diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 1f2ccfacab64..def82216fa2e 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -856,9 +856,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow */ void newProject(); - //! emitted when a new bookmark is added - void bookmarkAdded(); - /** Signal emitted when the current theme is changed so plugins * can change there tool button icons. * @note This was added in QGIS 1.1 diff --git a/src/app/qgsbookmarkitem.cpp b/src/app/qgsbookmarkitem.cpp deleted file mode 100644 index 64e00d258ec0..000000000000 --- a/src/app/qgsbookmarkitem.cpp +++ /dev/null @@ -1,82 +0,0 @@ - -/*************************************************************************** - QgsBookmarkItem.h - Spatial Bookmark Item - ------------------- - begin : 2005-04-23 - copyright : (C) 2005 Gary Sherman - email : sherman at mrcc dot com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ -#include -#include - -#include - -#include "qgsrectangle.h" -#include "qgsbookmarkitem.h" -#include "qgslogger.h" - -QgsBookmarkItem::QgsBookmarkItem( QString name, QString projectTitle, - QgsRectangle viewExtent, int srid, QString dbPath ) - : mName( name ), mProjectTitle( projectTitle ), mViewExtent( viewExtent ), - mSrid( srid ), mUserDbPath( dbPath ) -{ -} -QgsBookmarkItem::~QgsBookmarkItem() -{ -} -void QgsBookmarkItem::store() -{ - // To store the bookmark we have to open the database and insert - // the record using the parameters set in the constructor - - sqlite3 *db; - int rc; - QgsDebugMsg( QString( "Opening user database: %1" ).arg( mUserDbPath ) ); - rc = sqlite3_open( mUserDbPath.toUtf8().data(), &db ); - 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 ) ) ); - - // XXX This will likely never happen since on open, sqlite creates the - // database if it does not exist. - assert( rc == 0 ); - } -} diff --git a/src/app/qgsbookmarkitem.h b/src/app/qgsbookmarkitem.h deleted file mode 100644 index 119d5e19027f..000000000000 --- a/src/app/qgsbookmarkitem.h +++ /dev/null @@ -1,54 +0,0 @@ - -/*************************************************************************** - QgsBookmarkItem.h - Spatial Bookmark Item - ------------------- - begin : 2005-04-23 - copyright : (C) 2005 Gary Sherman - email : sherman at mrcc dot com - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ -#ifndef QGSBOOKMARKITEM_H -#define QGSBOOKMARKITEM_H - -#include -#include "qgsrectangle.h" - -/*! - * \class QgsBookmarkItem - * \brief A spatial bookmark record that is stored in a sqlite3 - * database. - */ -class QgsBookmarkItem -{ - public: - //! Constructs a bookmark item - QgsBookmarkItem( QString name, QString projectTitle, - QgsRectangle viewExtent, int srid, QString databasePath ); - //! Default destructor - ~QgsBookmarkItem(); - //! Store the bookmark in the database - void store(); - private: - //! Name of the bookmark - QString mName; - //! Project that this bookmark was created from - QString mProjectTitle; - //! Extent of the view for the bookmark - QgsRectangle mViewExtent; - //! SRID of the canvas coordinate system when the bookmark was created - int mSrid; - //! Full path to the user database - QString mUserDbPath; - -}; - -#endif // QGSBOOKMARKITEM_H - diff --git a/src/app/qgsbookmarks.cpp b/src/app/qgsbookmarks.cpp index 6658a4bcffff..f8f6f0ebc96f 100644 --- a/src/app/qgsbookmarks.cpp +++ b/src/app/qgsbookmarks.cpp @@ -19,124 +19,82 @@ #include "qgsapplication.h" #include "qgscontexthelp.h" #include "qgsmapcanvas.h" +#include "qgsmaprenderer.h" +#include "qgsproject.h" + #include "qgslogger.h" -#include -#include #include #include #include +#include +#include +#include -//standard includes -#include -#include -#include +QgsBookmarks *QgsBookmarks::sInstance = 0; QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl ) - : QDialog( parent, fl ), - mParent( parent ) + : QDialog( parent, fl ) { setupUi( this ); - restorePosition(); - // user database is created at QGIS startup in QgisApp::createDB - // we just check whether there is our database [MD] - QFileInfo myFileInfo; - myFileInfo.setFile( QgsApplication::qgisSettingsDirPath() ); - if ( !myFileInfo.exists( ) ) - { - QgsDebugMsg( "The qgis.db does not exist" ); - } - - // Note proper queens english on next line - initialise(); - // // 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" ) ); + QPushButton *btnAdd = new QPushButton( tr( "&Add" ) ); + QPushButton *btnDelete = new QPushButton( tr( "&Delete" ) ); + QPushButton *btnZoomTo = new QPushButton( tr( "&Zoom to" ) ); btnZoomTo->setDefault( true ); - buttonBox->addButton( btnUpdate, QDialogButtonBox::ActionRole ); + buttonBox->addButton( btnAdd, 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 - connect( btnZoomTo, SIGNAL( clicked() ), this, SLOT( on_btnZoomTo_clicked() ) ); - // connect the slot up to catch when a new bookmark is added - connect( mParent, SIGNAL( bookmarkAdded() ), this, SLOT( refreshBookmarks() ) ); + + connect( btnAdd, SIGNAL( clicked() ), this, SLOT( addClicked() ) ); + connect( btnDelete, SIGNAL( clicked() ), this, SLOT( deleteClicked() ) ); + connect( btnZoomTo, SIGNAL( clicked() ), this, SLOT( zoomToBookmark() ) ); + + // open the database + QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE", "bookmarks" ); + db.setDatabaseName( QgsApplication::qgisUserDbFilePath() ); + if ( !db.open() ) + { + QMessageBox::warning( this, tr( "Error" ), + tr( "Unable to open bookmarks database.\nDatabase: %1\nDriver: %2\nDatabase: %3" ) + .arg( QgsApplication::qgisUserDbFilePath() ) + .arg( db.lastError().driverText() ) + .arg( db.lastError().databaseText() ) + ); + deleteLater(); + return; + } + + QSqlTableModel *model = new QSqlTableModel( this, db ); + model->setTable( "tbl_bookmarks" ); + model->setSort( 0, Qt::AscendingOrder ); + model->select(); + + // set better headers then column names from table + model->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) ); + model->setHeaderData( 2, Qt::Horizontal, tr( "Project" ) ); + model->setHeaderData( 3, Qt::Horizontal, tr( "xMin" ) ); + model->setHeaderData( 4, Qt::Horizontal, tr( "yMin" ) ); + model->setHeaderData( 5, Qt::Horizontal, tr( "xMax" ) ); + model->setHeaderData( 6, Qt::Horizontal, tr( "yMax" ) ); + model->setHeaderData( 7, Qt::Horizontal, tr( "SRID" ) ); + + lstBookmarks->setModel( model ); + +#ifndef QGISDEBUG + lstBookmarks->setColumnHidden( 0, true ); +#endif } -// Destructor QgsBookmarks::~QgsBookmarks() { saveWindowLocation(); -} - -void QgsBookmarks::refreshBookmarks() -{ - lstBookmarks->clear(); - initialise(); -} -// Initialise the bookmark tree from the database -void QgsBookmarks::initialise() -{ - int rc = connectDb(); - if ( rc == SQLITE_OK ) - { - // prepare the sql statement - const char *pzTail; - sqlite3_stmt *ppStmt; - QString sql = "select * from tbl_bookmarks"; - - rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &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 - while ( sqlite3_step( ppStmt ) == SQLITE_ROW ) - { - QTreeWidgetItem *item = new QTreeWidgetItem( lstBookmarks ); - QString name = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) ); - // sqlite3_bind_parameter_index(ppStmt, "name")); - //QgsDebugMsg("Bookmark name: " + name.toLocal8Bit().data()); - item->setText( 0, name ); - // set the project name - item->setText( 1, QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 2 ) ) ); - // get the extents - QString xMin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 3 ) ); - QString yMin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 4 ) ); - 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 ); // 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 ) ) ); - } - for ( int col = 0; col < 4; col++ ) - { - lstBookmarks->resizeColumnToContents( col ); - } - lstBookmarks->sortByColumn( 0, Qt::AscendingOrder ); - } - else - { - // XXX query failed -- warn the user some how - QgsDebugMsg( QString( "Failed to get bookmarks: %1" ).arg( sqlite3_errmsg( db ) ) ); - } - // close the statement - sqlite3_finalize( ppStmt ); - // close the database - sqlite3_close( db ); - // return the srs wkt - - } + sInstance = 0; } void QgsBookmarks::restorePosition() @@ -151,172 +109,124 @@ void QgsBookmarks::saveWindowLocation() settings.setValue( "/Windows/Bookmarks/geometry", saveGeometry() ); } -void QgsBookmarks::on_btnUpdate_clicked() +void QgsBookmarks::newBookmark() { - // 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 ); - } - } - } + showBookmarks(); + sInstance->addClicked(); } -void QgsBookmarks::on_btnDelete_clicked() +void QgsBookmarks::showBookmarks() { - // get the current item - QTreeWidgetItem *item = lstBookmarks->currentItem(); - if ( item ) + if ( !sInstance ) { - // make sure the user really wants to delete this bookmark - if ( QMessageBox::Ok == QMessageBox::information( this, tr( "Really Delete?" ), - tr( "Are you sure you want to delete the %1 bookmark?" ).arg( item->text( 0 ) ), - QMessageBox::Ok | QMessageBox::Cancel ) ) - { - // remove it from the listview - item = lstBookmarks->takeTopLevelItem( lstBookmarks->indexOfTopLevelItem( item ) ); - // delete it from the database - int rc = connectDb(); - if ( rc == SQLITE_OK ) - { - char *errmsg; - // build the sql statement - QString sql = "delete from tbl_bookmarks where bookmark_id = " + item->text( 3 ); - rc = sqlite3_exec( db, sql.toUtf8(), NULL, NULL, &errmsg ); - if ( rc != SQLITE_OK ) - { - // XXX Provide popup message on failure? - QMessageBox::warning( this, tr( "Error deleting bookmark" ), - tr( "Failed to delete the %1 bookmark from the database. The database said:\n%2" ) - .arg( item->text( 0 ) ).arg( errmsg ) ); - sqlite3_free( errmsg ); - } - // close the database - sqlite3_close( db ); - } - delete item; - } + sInstance = new QgsBookmarks( QgisApp::instance() ); + sInstance->setAttribute( Qt::WA_DeleteOnClose ); } -} -void QgsBookmarks::on_btnZoomTo_clicked() -{ - zoomToBookmark(); + sInstance->show(); + sInstance->raise(); + sInstance->setWindowState( sInstance->windowState() & ~Qt::WindowMinimized ); + sInstance->activateWindow(); } -void QgsBookmarks::on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem *lvi ) +void QgsBookmarks::addClicked() { - Q_UNUSED( lvi ); - zoomToBookmark(); + QSqlTableModel *model = qobject_cast( lstBookmarks->model() ); + Q_ASSERT( model ); + + QgsMapCanvas *canvas = QgisApp::instance()->mapCanvas(); + Q_ASSERT( canvas ); + + QSqlQuery query( "INSERT INTO tbl_bookmarks(bookmark_id,name,project_name,xmin,ymin,xmax,ymax,projection_srid)" + " VALUES (NULL,:name,:project_name,:xmin,:xmax,:ymin,:ymax,:projection_srid)", + model->database() ); + + query.bindValue( ":name", tr( "New bookmark" ) ); + query.bindValue( ":project_name", QgsProject::instance()->title() ); + query.bindValue( ":xmin", canvas->extent().xMinimum() ); + query.bindValue( ":ymin", canvas->extent().yMinimum() ); + query.bindValue( ":xmax", canvas->extent().xMaximum() ); + query.bindValue( ":ymax", canvas->extent().yMaximum() ); + query.bindValue( ":projection_srid", QVariant::fromValue( canvas->mapRenderer()->destinationCrs().srsid() ) ); + if ( query.exec() ) + { + model->setSort( 0, Qt::AscendingOrder ); + model->select(); + lstBookmarks->scrollToBottom(); + lstBookmarks->setCurrentIndex( model->index( model->rowCount() - 1, 1 ) ); + lstBookmarks->edit( model->index( model->rowCount() - 1, 1 ) ); + } + else + { + QMessageBox::warning( this, tr( "Error" ), tr( "Unable to create the bookmark.\nDriver:%1\nDatabase:%2" ) + .arg( query.lastError().driverText() ) + .arg( query.lastError().databaseText() ) ); + } } -void QgsBookmarks::zoomToBookmark() +void QgsBookmarks::deleteClicked() { - // Need to fetch the extent for the selected bookmark and then redraw - // the map - // get the current item - QTreeWidgetItem *item = lstBookmarks->currentItem(); - if ( !item ) - { - return; - } - // get the extent from the database - int rc = connectDb(); - if ( rc == SQLITE_OK ) + QList rows; + foreach( const QModelIndex &idx, lstBookmarks->selectionModel()->selectedIndexes() ) { - sqlite3_stmt *ppStmt; - const char *pzTail; - // build the sql statement - QString sql = "select xmin, ymin, xmax, ymax from tbl_bookmarks where bookmark_id = " + item->text( 3 ); - rc = sqlite3_prepare( db, sql.toUtf8(), sql.toUtf8().length(), &ppStmt, &pzTail ); - if ( rc == SQLITE_OK ) + if ( idx.column() == 1 ) { - if ( sqlite3_step( ppStmt ) == SQLITE_ROW ) - { - // get the extents from the resultset - QString xmin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 0 ) ); - QString ymin = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 1 ) ); - QString xmax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 2 ) ); - QString ymax = QString::fromUtf8(( const char * )sqlite3_column_text( ppStmt, 3 ) ); - // set the extent to the bookmark - QgisApp::instance()->setExtent( QgsRectangle( xmin.toDouble(), - ymin.toDouble(), - xmax.toDouble(), - ymax.toDouble() ) ); - // redraw the map - QgisApp::instance()->mapCanvas()->refresh(); - } + rows << idx.row(); } + } + + if( rows.size() == 0 ) + return; - // close the statement - sqlite3_finalize( ppStmt ); - // close the database - sqlite3_close( db ); + // make sure the user really wants to delete these bookmarks + if ( QMessageBox::Cancel == QMessageBox::information( this, tr( "Really Delete?" ), + tr( "Are you sure you want to delete %n bookmark(s)?", "number of rows", rows.size() ), + QMessageBox::Ok | QMessageBox::Cancel ) ) + return; + + int i=0; + foreach( int row, rows ) + { + lstBookmarks->model()->removeRow( row-i ); + i++; } +} +void QgsBookmarks::on_lstBookmarks_doubleClicked( const QModelIndex & index ) +{ + Q_UNUSED( index ); + zoomToBookmark(); } -int QgsBookmarks::connectDb() +void QgsBookmarks::zoomToBookmark() { + QModelIndex index = lstBookmarks->currentIndex(); + if ( !index.isValid() ) + return; - int rc; - rc = sqlite3_open( QgsApplication::qgisUserDbFilePath().toUtf8().data(), &db ); - if ( rc != SQLITE_OK ) - { - QgsDebugMsg( QString( "Can't open database: %1" ).arg( sqlite3_errmsg( db ) ) ); + double xmin = index.sibling( index.row(), 3 ).data().toDouble(); + double ymin = index.sibling( index.row(), 4 ).data().toDouble(); + double xmax = index.sibling( index.row(), 5 ).data().toDouble(); + double ymax = index.sibling( index.row(), 6 ).data().toDouble(); + int srid = index.sibling( index.row(), 7 ).data().toInt(); - // XXX This will likely never happen since on open, sqlite creates the - // database if it does not exist. - assert( rc == 0 ); + QgsRectangle rect = QgsRectangle( xmin, ymin, xmax, ymax ); + + // backwards compatibility, older version had -1 in the srid column + if ( srid > 0 && + srid != QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs().srsid() ) + { + QgsCoordinateTransform ct( QgsCoordinateReferenceSystem( srid, QgsCoordinateReferenceSystem::InternalCrsId ), + QgisApp::instance()->mapCanvas()->mapRenderer()->destinationCrs() ); + rect = ct.transform( rect ); + if( rect.isEmpty() ) + { + QMessageBox::warning( this, tr( "Empty extent" ), tr( "Reprojected extent is empty." ) ); + return; + } } - return rc; + + // set the extent to the bookmark and refresh + QgisApp::instance()->setExtent( rect ); + QgisApp::instance()->mapCanvas()->refresh(); } diff --git a/src/app/qgsbookmarks.h b/src/app/qgsbookmarks.h index 2e10216d768b..81c9145a34e6 100644 --- a/src/app/qgsbookmarks.h +++ b/src/app/qgsbookmarks.h @@ -17,37 +17,36 @@ #ifndef QGSBOOKMARKS_H #define QGSBOOKMARKS_H #include "ui_qgsbookmarksbase.h" -#include #include "qgscontexthelp.h" -class QString; -class QWidget; -class QTreeWidgetItem; -struct sqlite3; +#include + class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase { Q_OBJECT public: - QgsBookmarks( QWidget *parent = 0, Qt::WFlags fl = 0 ); - ~QgsBookmarks(); - void restorePosition(); + static void showBookmarks(); + static void newBookmark(); + private slots: - void saveWindowLocation(); - void on_btnUpdate_clicked(); - void on_btnDelete_clicked(); - void on_btnZoomTo_clicked(); - void on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem * ); - void refreshBookmarks(); + void addClicked(); + void deleteClicked(); + void zoomToBookmark(); + void on_lstBookmarks_doubleClicked( const QModelIndex & ); void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); } private: - QWidget *mParent; - void initialise(); - int connectDb(); - void zoomToBookmark(); - sqlite3 *db; + QgsBookmarks( QWidget *parent = 0, Qt::WFlags fl = 0 ); + ~QgsBookmarks(); + + void saveWindowLocation(); + void restorePosition(); + + static QgsBookmarks *sInstance; }; + + #endif // QGSBOOKMARKS_H diff --git a/src/ui/qgsbookmarksbase.ui b/src/ui/qgsbookmarksbase.ui index 38908751f2c9..8938506bc1b3 100644 --- a/src/ui/qgsbookmarksbase.ui +++ b/src/ui/qgsbookmarksbase.ui @@ -1,7 +1,8 @@ - + + QgsBookmarksBase - - + + 0 0 @@ -9,53 +10,33 @@ 370 - + Geospatial Bookmarks - - - - - false - - - true - - - 4 + + + + + QDialogButtonBox::Close|QDialogButtonBox::Help - - - Name - - - - - Project - - - - - Extent - - - - - Id - - - - - - QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::NoButton + + + + QAbstractItemView::ExtendedSelection + + + false + + + true - + lstBookmarks buttonBox @@ -68,11 +49,11 @@ QgsBookmarksBase reject() - + 211 342 - + 274 256