Skip to content
Permalink
Browse files

Fix #7723, bookmark names not saved

- Allow bookmarks database table to be edited
- Store project file name with new bookmark, if custom project title not set
  • Loading branch information
dakcarto committed Jun 2, 2013
1 parent c78a5d1 commit 8a712b4a02bef24b8f12fda6c3a616207181b2be
Showing with 18 additions and 1 deletion.
  1. +18 −1 src/app/qgsbookmarks.cpp
@@ -24,6 +24,7 @@

#include "qgslogger.h"

#include <QFileInfo>
#include <QMessageBox>
#include <QSettings>
#include <QPushButton>
@@ -73,9 +74,11 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
QSqlTableModel *model = new QSqlTableModel( this, db );
model->setTable( "tbl_bookmarks" );
model->setSort( 0, Qt::AscendingOrder );
model->setEditStrategy( QSqlTableModel::OnFieldChange );
model->select();

// set better headers then column names from table
model->setHeaderData( 0, Qt::Horizontal, tr( "ID" ) );
model->setHeaderData( 1, Qt::Horizontal, tr( "Name" ) );
model->setHeaderData( 2, Qt::Horizontal, tr( "Project" ) );
model->setHeaderData( 3, Qt::Horizontal, tr( "xMin" ) );
@@ -141,8 +144,22 @@ void QgsBookmarks::addClicked()
" VALUES (NULL,:name,:project_name,:xmin,:xmax,:ymin,:ymax,:projection_srid)",
model->database() );

QString projStr( "" );
if ( QgsProject::instance() )
{
if ( !QgsProject::instance()->title().isEmpty() )
{
projStr = QgsProject::instance()->title();
}
else if ( !QgsProject::instance()->fileName().isEmpty() )
{
QFileInfo fi( QgsProject::instance()->fileName() );
projStr = fi.exists() ? fi.fileName() : "";
}
}

query.bindValue( ":name", tr( "New bookmark" ) );
query.bindValue( ":project_name", QgsProject::instance()->title() );
query.bindValue( ":project_name", projStr );
query.bindValue( ":xmin", canvas->extent().xMinimum() );
query.bindValue( ":ymin", canvas->extent().yMinimum() );
query.bindValue( ":xmax", canvas->extent().xMaximum() );

0 comments on commit 8a712b4

Please sign in to comment.
You can’t perform that action at this time.