Skip to content

Commit 440125b

Browse files
author
timlinux
committed
Applied patch from ticket #1478 to trunk
git-svn-id: http://svn.osgeo.org/qgis/trunk@9940 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b092ae7 commit 440125b

File tree

2 files changed

+38
-17
lines changed

2 files changed

+38
-17
lines changed

src/plugins/coordinate_capture/coordinatecapture.cpp

+23-12
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,14 @@ CoordinateCapture::~CoordinateCapture()
8080
*/
8181
void CoordinateCapture::initGui()
8282
{
83-
mEpsgId = GEO_EPSG_CRS_ID;
83+
mCrs.createFromSrsId( GEOCRS_ID ); // initialize the CRS object
84+
85+
connect( mQGisIface->mapCanvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setSourceCrs() ) );
86+
87+
setSourceCrs(); //set up the source CRS
88+
mTransform.setDestCRS( mCrs ); // set the CRS in the transform
89+
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; // precision depends on CRS units
90+
8491
// Create the action for tool
8592
mQActionPointer = new QAction( QIcon( ":/coordinatecapture/coordinate_capture.png" ), tr( "Coordinate Capture" ), this );
8693
// Set the what's this text
@@ -158,14 +165,21 @@ void CoordinateCapture::help()
158165
void CoordinateCapture::setCRS()
159166
{
160167
QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() );
161-
mySelector.setSelectedEpsg( mEpsgId );
168+
mySelector.setSelectedCrsId( mCrs.srsid() );
162169
if ( mySelector.exec() )
163170
{
164-
mEpsgId = mySelector.selectedEpsg();
165-
mProj4Str = mySelector.selectedProj4String();
171+
mCrs.createFromSrsId( mySelector.selectedCrsId() );
172+
mTransform.setDestCRS( mCrs );
173+
mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3; //precision depends on CRS units
166174
}
167175
}
168176

177+
void CoordinateCapture::setSourceCrs()
178+
{
179+
mTransform.setSourceCrs( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs() );
180+
mCanvasDisplayPrecision = ( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs().mapUnits() == QGis::Degrees ) ? 8 : 3; // for the map canvas coordinate display
181+
}
182+
169183
void CoordinateCapture::mouseClicked( QgsPoint thePoint )
170184
{
171185
//clicking on the canvas will update the widgets and then disable
@@ -185,15 +199,12 @@ void CoordinateCapture::mouseMoved( QgsPoint thePoint )
185199
void CoordinateCapture::update( QgsPoint thePoint )
186200
{
187201
//this is the coordinate resolved back to lat / lon
188-
QgsCoordinateReferenceSystem mySrs;
189-
mySrs.createFromProj4( mProj4Str );
190-
QgsCoordinateTransform myTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), mySrs );
191-
QgsPoint myUserCrsPoint = myTransform.transform( thePoint );
192-
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', 3 ) + "," +
193-
QString::number( myUserCrsPoint.y(), 'f', 3 ) );
202+
QgsPoint myUserCrsPoint = mTransform.transform( thePoint );
203+
mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', mUserCrsDisplayPrecision ) + "," +
204+
QString::number( myUserCrsPoint.y(), 'f', mUserCrsDisplayPrecision ) );
194205
// This is the coordinate space of the map canvas
195-
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', 3 ) + "," +
196-
QString::number( thePoint.y(), 'f', 3 ) );
206+
mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', mCanvasDisplayPrecision ) + "," +
207+
QString::number( thePoint.y(), 'f', mCanvasDisplayPrecision ) );
197208
}
198209
void CoordinateCapture::copy()
199210
{

src/plugins/coordinate_capture/coordinatecapture.h

+15-5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
//QGIS includes
4444
#include "../qgisplugin.h"
4545
#include "coordinatecapturemaptool.h"
46+
#include <qgscoordinatereferencesystem.h>
47+
#include <qgscoordinatetransform.h>
4648

4749
//forward declarations
4850
class QAction;
@@ -99,7 +101,8 @@ class CoordinateCapture: public QObject, public QgisPlugin
99101
void update( QgsPoint thePoint );
100102
//! Called when user clicks the copy button
101103
void copy();
102-
104+
//! called when the project's CRS is changed
105+
void setSourceCrs();
103106

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

120-
//!epsg id for showin in geoedit box
121-
long mEpsgId;
122-
//!proj4 string for coordinate translation
123-
QString mProj4Str;
123+
//! transform object
124+
QgsCoordinateTransform mTransform;
125+
126+
//! map coordinate display precision
127+
int mCanvasDisplayPrecision;
128+
129+
//! user CRS object
130+
QgsCoordinateReferenceSystem mCrs;
131+
132+
//! user coordinate display precision
133+
int mUserCrsDisplayPrecision;
124134

125135
////////////////////////////////////////////////////////////////////
126136
//

0 commit comments

Comments
 (0)