Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
timlinux committed Jun 5, 2011
2 parents 48d82eb + 0e318b0 commit 6cb4248
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 249 deletions.
1 change: 1 addition & 0 deletions doc/CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Richard Duivenvoorde
Richard Kostecky
Robert Szczepanek
Stefanie Tellex
Steven Mizuno
Tom Russo
Tyler Mitchell
Vita Cizek
Expand Down
5 changes: 5 additions & 0 deletions resources/context_help/QgsBookmarks-en_US
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Spatial Bookmarks allow you to "bookmark" a geographic location and return to it
<a href="#working">Working with Bookmarks</a><br/>
<a href="#zooming">Zooming to a Bookmark</a><br/>
<a href="#deleting">Deleting a Bookmark</a><br/>
<a href="#updating">Updating a Bookmark</a><br/>

<a name="creating">
<h4>Creating a Bookmark</h4>
Expand All @@ -31,4 +32,8 @@ You can also zoom to a bookmark by double-clicking on it.
<h5>Deleting a Bookmark</h5>
</a>
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>.
<a name="updating">
<h5>Updating a Bookmark</h5>
</a>
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>.

1 change: 0 additions & 1 deletion src/app/qgisapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6338,7 +6338,6 @@ void QgisApp::showBookmarks()
{
bookmarks = new QgsBookmarks( this, Qt::WindowMinMaxButtonsHint );
}
bookmarks->restorePosition();
bookmarks->show();
bookmarks->raise();
bookmarks->setWindowState( bookmarks->windowState() & ~Qt::WindowMinimized );
Expand Down
63 changes: 28 additions & 35 deletions src/app/qgsbookmarkitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,41 @@ void QgsBookmarkItem::store()
int rc;
QgsDebugMsg( QString( "Opening user database: %1" ).arg( mUserDbPath ) );
rc = sqlite3_open( mUserDbPath.toUtf8().data(), &db );
if ( rc )
if ( SQLITE_OK == rc )
{
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 );
}
// prepare the sql statement
const char *pzTail;
sqlite3_stmt *ppStmt;
QString sql;
QTextStream sqlStream( &sql );
sqlStream << "insert into tbl_bookmarks values(null,'" <<
mName << "','" <<
mProjectTitle << "'," <<
mViewExtent.xMinimum() << "," <<
mViewExtent.yMinimum() << "," <<
mViewExtent.xMaximum() << "," <<
mViewExtent.yMaximum() << "," <<
mSrid << ")";
// 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 ) );
QgsDebugMsg( QString( "Storing bookmark using: %1" ).arg( sql ) );

QByteArray sqlData = sql.toUtf8();

rc = sqlite3_prepare( db, sqlData.constData(), sqlData.size(), &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
if ( sqlite3_step( ppStmt ) != SQLITE_DONE )
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( sqlite3_errmsg( db ) ) );
QgsDebugMsg( QString( "Failed to store bookmark: %1" ).arg( errmsg ) );
sqlite3_free( errmsg );
}
// close the statement
sqlite3_finalize( ppStmt );
// close the database
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 );
}
}
71 changes: 69 additions & 2 deletions src/app/qgsbookmarks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
mParent( parent )
{
setupUi( this );

restorePosition();

// user database is created at QGIS startup in QgisApp::createDB
// we just check whether there is our database [MD]
QFileInfo myFileInfo;
Expand All @@ -53,11 +56,15 @@ QgsBookmarks::QgsBookmarks( QWidget *parent, Qt::WFlags fl )
// 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" ) );
btnZoomTo->setDefault( true );
buttonBox->addButton( btnUpdate, 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
Expand Down Expand Up @@ -108,7 +115,7 @@ void QgsBookmarks::initialise()
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 );
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 ) ) );
}
Expand Down Expand Up @@ -144,6 +151,66 @@ void QgsBookmarks::saveWindowLocation()
settings.setValue( "/Windows/Bookmarks/geometry", saveGeometry() );
}

void QgsBookmarks::on_btnUpdate_clicked()
{
// 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 );
}
}
}
}

void QgsBookmarks::on_btnDelete_clicked()
{
// get the current item
Expand Down Expand Up @@ -186,7 +253,7 @@ void QgsBookmarks::on_btnZoomTo_clicked()
zoomToBookmark();
}

void QgsBookmarks::on_lstBookmarks_doubleClicked( QTreeWidgetItem *lvi )
void QgsBookmarks::on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem *lvi )
{
zoomToBookmark();
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/qgsbookmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ class QgsBookmarks : public QDialog, private Ui::QgsBookmarksBase
void restorePosition();
private slots:
void saveWindowLocation();
void on_btnUpdate_clicked();
void on_btnDelete_clicked();
void on_btnZoomTo_clicked();
void on_lstBookmarks_doubleClicked( QTreeWidgetItem * );
void on_lstBookmarks_itemDoubleClicked( QTreeWidgetItem * );
void refreshBookmarks();

void on_buttonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
Expand Down
35 changes: 12 additions & 23 deletions src/app/qgsmeasuredialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,21 @@ void QgsMeasureDialog::mouseMove( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
QgsDistanceArea myDa;
configureDistanceArea( myDa );

// show current distance/area while moving the point
// by creating a temporary copy of point array
// and adding moving point at the end
if ( mMeasureArea && mTool->points().size() > 1 )
{
QList<QgsPoint> tmpPoints = mTool->points();
tmpPoints.append( point );
double area = myDa.measurePolygon( tmpPoints );
double area = mDa.measurePolygon( tmpPoints );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && mTool->points().size() > 0 )
{
QgsPoint p1( mTool->points().last() ), p2( point );

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
// Ignore units
Expand All @@ -130,14 +126,10 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )
QSettings settings;
int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// Create QgsDistance Area for customization ProjectionEnabled setting
QgsDistanceArea myDa;
configureDistanceArea( myDa );

int numPoints = mTool->points().size();
if ( mMeasureArea && numPoints > 2 )
{
double area = myDa.measurePolygon( mTool->points() );
double area = mDa.measurePolygon( mTool->points() );
editTotal->setText( formatArea( area, decimalPlaces ) );
}
else if ( !mMeasureArea && numPoints > 1 )
Expand All @@ -146,7 +138,7 @@ void QgsMeasureDialog::addPoint( QgsPoint &point )

QgsPoint p1 = mTool->points()[last], p2 = mTool->points()[last+1];

double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );

mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
Expand Down Expand Up @@ -243,7 +235,7 @@ void QgsMeasureDialog::updateUi()
break;
case QGis::UnknownUnit:
mTable->setHeaderLabels( QStringList( tr( "Segments" ) ) );
};
}

if ( mMeasureArea )
{
Expand All @@ -256,6 +248,7 @@ void QgsMeasureDialog::updateUi()
editTotal->setText( formatDistance( 0, decimalPlaces ) );
}

configureDistanceArea();
}

void QgsMeasureDialog::convertMeasurement( double &measure, QGis::UnitType &u, bool isArea )
Expand Down Expand Up @@ -322,16 +315,12 @@ void QgsMeasureDialog::changeProjectionEnabledState()

int decimalPlaces = settings.value( "/qgis/measure/decimalplaces", "3" ).toInt();

// create DistanceArea
QgsDistanceArea myDa;
configureDistanceArea( myDa );

if ( mMeasureArea )
{
double area = 0.0;
if ( mTool->points().size() > 1 )
{
area = myDa.measurePolygon( mTool->points() );
area = mDa.measurePolygon( mTool->points() );
}
editTotal->setText( formatArea( area, decimalPlaces ) );
}
Expand All @@ -347,7 +336,7 @@ void QgsMeasureDialog::changeProjectionEnabledState()
p2 = *it;
if ( !b )
{
double d = myDa.measureLine( p1, p2 );
double d = mDa.measureLine( p1, p2 );
mTotal += d;
editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
QGis::UnitType myDisplayUnits;
Expand All @@ -367,11 +356,11 @@ void QgsMeasureDialog::changeProjectionEnabledState()
}
}

void QgsMeasureDialog::configureDistanceArea( QgsDistanceArea& da )
void QgsMeasureDialog::configureDistanceArea()
{
QSettings settings;
QString ellipsoidId = settings.value( "/qgis/measure/ellipsoid", "WGS84" ).toString();
da.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
da.setEllipsoid( ellipsoidId );
da.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
mDa.setSourceCrs( mTool->canvas()->mapRenderer()->destinationCrs().srsid() );
mDa.setEllipsoid( ellipsoidId );
mDa.setProjectionsEnabled( mcbProjectionEnabled->isChecked() );
}
4 changes: 3 additions & 1 deletion src/app/qgsmeasuredialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ class QgsMeasureDialog : public QDialog, private Ui::QgsMeasureBase
void convertMeasurement( double &measure, QGis::UnitType &u, bool isArea );

//! Configures distance area objects with ellipsoid / output crs
void configureDistanceArea( QgsDistanceArea& da );
void configureDistanceArea();

double mTotal;

//! indicates whether we're measuring distances or areas
bool mMeasureArea;

QgsDistanceArea mDa;

//! pointer to measure tool which owns this dialog
QgsMeasureTool* mTool;
};
Expand Down
Loading

0 comments on commit 6cb4248

Please sign in to comment.