patch_for_1478.txt

patch CoordinateCapture - Steven Mizuno, 2009-01-06 08:09 PM

Download (4.67 KB)

 
1
Index: src/plugins/coordinate_capture/coordinatecapture.cpp
2
===================================================================
3
--- src/plugins/coordinate_capture/coordinatecapture.cpp	(revision 9913)
4
+++ src/plugins/coordinate_capture/coordinatecapture.cpp	(working copy)
5
@@ -80,7 +80,14 @@
6
  */
7
 void CoordinateCapture::initGui()
8
 {
9
-  mEpsgId = GEO_EPSG_CRS_ID;
10
+  mCrs.createFromSrsId( GEOCRS_ID );	// initialize the CRS object
11
+
12
+  connect( mQGisIface->mapCanvas()->mapRenderer(), SIGNAL( destinationSrsChanged() ), this, SLOT( setSourceCrs() ) );
13
+
14
+  setSourceCrs();	//set up the source CRS 
15
+  mTransform.setDestCRS( mCrs );	// set the CRS in the transform
16
+  mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3;	// precision depends on CRS units
17
+
18
   // Create the action for tool
19
   mQActionPointer = new QAction( QIcon( ":/coordinatecapture/coordinate_capture.png" ), tr( "Coordinate Capture" ), this );
20
   // Set the what's this text
21
@@ -158,14 +165,21 @@
22
 void CoordinateCapture::setCRS()
23
 {
24
   QgsGenericProjectionSelector mySelector( mQGisIface->mainWindow() );
25
-  mySelector.setSelectedEpsg( mEpsgId );
26
+  mySelector.setSelectedCrsId( mCrs.srsid() );
27
   if ( mySelector.exec() )
28
   {
29
-    mEpsgId = mySelector.selectedEpsg();
30
-    mProj4Str =  mySelector.selectedProj4String();
31
+    mCrs.createFromSrsId( mySelector.selectedCrsId() );
32
+    mTransform.setDestCRS( mCrs );
33
+    mUserCrsDisplayPrecision = ( mCrs.mapUnits() == QGis::Degrees ) ? 8 : 3;	//precision depends on CRS units
34
   }
35
 }
36
 
37
+void CoordinateCapture::setSourceCrs()
38
+{
39
+  mTransform.setSourceCrs( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs() );
40
+  mCanvasDisplayPrecision = ( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs().mapUnits() == QGis::Degrees ) ? 8 : 3;	// for the map canvas coordinate display
41
+}
42
+
43
 void CoordinateCapture::mouseClicked( QgsPoint thePoint )
44
 {
45
   //clicking on the canvas will update the widgets and then disable
46
@@ -185,15 +199,12 @@
47
 void CoordinateCapture::update( QgsPoint thePoint )
48
 {
49
   //this is the coordinate resolved back to lat / lon
50
-  QgsCoordinateReferenceSystem mySrs;
51
-  mySrs.createFromProj4( mProj4Str );
52
-  QgsCoordinateTransform myTransform( mQGisIface->mapCanvas()->mapRenderer()->destinationSrs(), mySrs );
53
-  QgsPoint myUserCrsPoint = myTransform.transform( thePoint );
54
-  mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', 3 ) + "," +
55
-                          QString::number( myUserCrsPoint.y(), 'f', 3 ) );
56
+  QgsPoint myUserCrsPoint = mTransform.transform( thePoint );
57
+  mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', mUserCrsDisplayPrecision ) + "," +
58
+                          QString::number( myUserCrsPoint.y(), 'f', mUserCrsDisplayPrecision ) );
59
   // This is the coordinate space of the map canvas
60
-  mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', 3 ) + "," +
61
-                         QString::number( thePoint.y(), 'f', 3 ) );
62
+  mpCanvasEdit->setText( QString::number( thePoint.x(), 'f', mCanvasDisplayPrecision ) + "," +
63
+                         QString::number( thePoint.y(), 'f', mCanvasDisplayPrecision ) );
64
 }
65
 void CoordinateCapture::copy()
66
 {
67
Index: src/plugins/coordinate_capture/coordinatecapture.h
68
===================================================================
69
--- src/plugins/coordinate_capture/coordinatecapture.h	(revision 9913)
70
+++ src/plugins/coordinate_capture/coordinatecapture.h	(working copy)
71
@@ -43,6 +43,8 @@
72
 //QGIS includes
73
 #include "../qgisplugin.h"
74
 #include "coordinatecapturemaptool.h"
75
+#include <qgscoordinatereferencesystem.h>
76
+#include <qgscoordinatetransform.h>
77
 
78
 //forward declarations
79
 class QAction;
80
@@ -99,8 +101,9 @@
81
     void update( QgsPoint thePoint );
82
     //! Called when user clicks the copy button
83
     void copy();
84
+    //! called when the project's CRS is changed
85
+    void setSourceCrs();
86
 
87
-
88
   private:
89
     //! Container for the coordinate info
90
     QPointer<QDockWidget> mpDockWidget;
91
@@ -117,11 +120,18 @@
92
     //!A toolbutton to keep track whether mouse tracking is enabled
93
     QToolButton * mpTrackMouseButton;
94
 
95
-    //!epsg id for showin in geoedit box
96
-    long mEpsgId;
97
-    //!proj4 string for coordinate translation
98
-    QString mProj4Str;
99
+    //! transform object
100
+    QgsCoordinateTransform mTransform;
101
 
102
+    //! map coordinate display precision
103
+    int mCanvasDisplayPrecision;
104
+
105
+    //! user CRS object
106
+    QgsCoordinateReferenceSystem mCrs;
107
+
108
+    //! user coordinate display precision
109
+    int mUserCrsDisplayPrecision;
110
+
111
     ////////////////////////////////////////////////////////////////////
112
     //
113
     // MANDATORY PLUGIN PROPERTY DECLARATIONS  .....