Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 8a712b4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/app/qgsbookmarks.cpp
Expand Up @@ -24,6 +24,7 @@

#include "qgslogger.h"

#include <QFileInfo>
#include <QMessageBox>
#include <QSettings>
#include <QPushButton>
Expand Down Expand Up @@ -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" ) );
Expand Down Expand Up @@ -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() );
Expand Down

0 comments on commit 8a712b4

Please sign in to comment.