Skip to content

Commit

Permalink
Applied patch from ticket #1478 to trunk
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@9940 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Jan 7, 2009
1 parent b092ae7 commit 440125b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
35 changes: 23 additions & 12 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Expand Up @@ -80,7 +80,14 @@ CoordinateCapture::~CoordinateCapture()
*/
void CoordinateCapture::initGui()
{
mEpsgId = GEO_EPSG_CRS_ID;
mCrs.createFromSrsId( GEOCRS_ID ); // initialize the CRS object

connect( mQGisIface->mapCanvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setSourceCrs() ) );

setSourceCrs(); //set up the source CRS
mTransform.setDestCRS( mCrs ); // set the CRS in the transform
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; // precision depends on CRS units

// Create the action for tool
mQActionPointer = new QAction( QIcon( ":/coordinatecapture/coordinate_capture.png" ), tr( "Coordinate Capture" ), this );
// Set the what's this text
Expand Down Expand Up @@ -158,14 +165,21 @@ void CoordinateCapture::help()
void CoordinateCapture::setCRS()
{
QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() );
mySelector.setSelectedEpsg( mEpsgId );
mySelector.setSelectedCrsId( mCrs.srsid() );
if ( mySelector.exec() )
{
mEpsgId = mySelector.selectedEpsg();
mProj4Str = mySelector.selectedProj4String();
mCrs.createFromSrsId( mySelector.selectedCrsId() );
mTransform.setDestCRS( mCrs );
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; //precision depends on CRS units
}
}

void CoordinateCapture::setSourceCrs()
{
mTransform.setSourceCrs( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs() );
mCanvasDisplayPrecision = ( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs().mapUnits() == QGis::Degrees ) ? 8 : 3; // for the map canvas coordinate display
}

void CoordinateCapture::mouseClicked( QgsPoint thePoint )
{
//clicking on the canvas will update the widgets and then disable
Expand All @@ -185,15 +199,12 @@ void CoordinateCapture::mouseMoved( QgsPoint thePoint )
void CoordinateCapture::update( QgsPoint thePoint )
{
//this is the coordinate resolved back to lat / lon
QgsCoordinateReferenceSystem mySrs;
mySrs.createFromProj4( mProj4Str );
QgsCoordinateTransform myTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), mySrs );
QgsPoint myUserCrsPoint = myTransform.transform( thePoint );
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', 3 ) + "," +
QString::number( myUserCrsPoint.y(), 'f', 3 ) );
QgsPoint myUserCrsPoint = mTransform.transform( thePoint );
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', mUserCrsDisplayPrecision ) + "," +
QString::number( myUserCrsPoint.y(), 'f', mUserCrsDisplayPrecision ) );
// This is the coordinate space of the map canvas
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', 3 ) + "," +
QString::number( thePoint.y(), 'f', 3 ) );
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', mCanvasDisplayPrecision ) + "," +
QString::number( thePoint.y(), 'f', mCanvasDisplayPrecision ) );
}
void CoordinateCapture::copy()
{
Expand Down
20 changes: 15 additions & 5 deletions src/plugins/coordinate_capture/coordinatecapture.h
Expand Up @@ -43,6 +43,8 @@
//QGIS includes
#include "../qgisplugin.h"
#include "coordinatecapturemaptool.h"
#include <qgscoordinatereferencesystem.h>
#include <qgscoordinatetransform.h>

//forward declarations
class QAction;
Expand Down Expand Up @@ -99,7 +101,8 @@ class CoordinateCapture: public QObject, public QgisPlugin
void update( QgsPoint thePoint );
//! Called when user clicks the copy button
void copy();

//! called when the project's CRS is changed
void setSourceCrs();

private:
//! Container for the coordinate info
Expand All @@ -117,10 +120,17 @@ class CoordinateCapture: public QObject, public QgisPlugin
//!A toolbutton to keep track whether mouse tracking is enabled
QToolButton * mpTrackMouseButton;

//!epsg id for showin in geoedit box
long mEpsgId;
//!proj4 string for coordinate translation
QString mProj4Str;
//! transform object
QgsCoordinateTransform mTransform;

//! map coordinate display precision
int mCanvasDisplayPrecision;

//! user CRS object
QgsCoordinateReferenceSystem mCrs;

//! user coordinate display precision
int mUserCrsDisplayPrecision;

////////////////////////////////////////////////////////////////////
//
Expand Down

0 comments on commit 440125b

Please sign in to comment.