28
28
#include < qgis.h>
29
29
#include < qgsspatialrefsys.h>
30
30
#include < qgscoordinatetransform.h>
31
+ #include < qgsgenericprojectionselector.h>
31
32
32
33
#include " coordinatecapture.h"
33
34
#include " coordinatecapturegui.h"
@@ -79,7 +80,7 @@ CoordinateCapture::~CoordinateCapture()
79
80
*/
80
81
void CoordinateCapture::initGui ()
81
82
{
82
-
83
+ mEpsgId = GEOEPSG_ID;
83
84
// Create the action for tool
84
85
mQActionPointer = new QAction (QIcon (" :/coordinatecapture/coordinate_capture.png" ),tr (" Coordinate Capture" ), this );
85
86
// Set the what's this text
@@ -102,19 +103,20 @@ void CoordinateCapture::initGui()
102
103
mypLayout->setColumnMinimumWidth ( 0 , 36 );
103
104
mypWidget->setLayout (mypLayout);
104
105
105
- QLabel * mypGeoLabel = new QLabel (mypWidget);
106
- mypGeoLabel->setPixmap (QPixmap (" :/coordinatecapture/geographic.png" ));
106
+ QToolButton * mypUserCrsToolButton = new QToolButton (mypWidget);
107
+ mypUserCrsToolButton->setIcon (QIcon (" :/coordinatecapture/geographic.png" ));
108
+ connect (mypUserCrsToolButton , SIGNAL (clicked ()), this , SLOT (setCRS ()));
107
109
108
110
QLabel * mypCRSLabel = new QLabel (mypWidget);
109
111
mypCRSLabel->setPixmap (QPixmap (" :/coordinatecapture/transformed.png" ));
110
112
111
- mpGeoEdit = new QLineEdit (mypWidget);
112
- mpGeoEdit ->setReadOnly (true );
113
- mpGeoEdit ->setToolTip (tr (" Coordinate in lat/long WGS84 " ));
113
+ mpUserCrsEdit = new QLineEdit (mypWidget);
114
+ mpUserCrsEdit ->setReadOnly (true );
115
+ mpUserCrsEdit ->setToolTip (tr (" Coordinate in your selected CRS " ));
114
116
115
- mpTransformedEdit = new QLineEdit (mypWidget);
116
- mpTransformedEdit ->setReadOnly (true );
117
- mpTransformedEdit ->setToolTip (tr (" Coordinate in map canvas coordinate reference system" ));
117
+ mpCanvasEdit = new QLineEdit (mypWidget);
118
+ mpCanvasEdit ->setReadOnly (true );
119
+ mpCanvasEdit ->setToolTip (tr (" Coordinate in map canvas coordinate reference system" ));
118
120
119
121
QPushButton * mypCopyButton = new QPushButton (mypWidget);
120
122
mypCopyButton->setText (tr (" Copy to clipboard" ));
@@ -126,10 +128,10 @@ void CoordinateCapture::initGui()
126
128
mpTrackMouseButton->setChecked (false );
127
129
mpTrackMouseButton->setIcon (QIcon (" :/coordinatecapture/tracking.png" ));
128
130
129
- mypLayout->addWidget (mypGeoLabel , 0 ,0 );
130
- mypLayout->addWidget (mpGeoEdit , 0 ,1 );
131
+ mypLayout->addWidget (mypUserCrsToolButton , 0 ,0 );
132
+ mypLayout->addWidget (mpUserCrsEdit , 0 ,1 );
131
133
mypLayout->addWidget (mypCRSLabel, 1 ,0 );
132
- mypLayout->addWidget (mpTransformedEdit , 1 ,1 );
134
+ mypLayout->addWidget (mpCanvasEdit , 1 ,1 );
133
135
mypLayout->addWidget (mpTrackMouseButton, 2 ,0 );
134
136
mypLayout->addWidget (mypCopyButton, 2 ,1 );
135
137
@@ -150,6 +152,17 @@ void CoordinateCapture::help()
150
152
{
151
153
// implement me!
152
154
}
155
+
156
+ void CoordinateCapture::setCRS ()
157
+ {
158
+ QgsGenericProjectionSelector mySelector (mQGisIface ->getMainWindow ());
159
+ mySelector.setSelectedEpsg (mEpsgId );
160
+ if (mySelector.exec ())
161
+ {
162
+ mEpsgId = mySelector.getSelectedEpsg ();
163
+ }
164
+ }
165
+
153
166
void CoordinateCapture::mouseClicked (QgsPoint thePoint)
154
167
{
155
168
// clicking on the canvas will update the widgets and then disable
@@ -170,13 +183,13 @@ void CoordinateCapture::update(QgsPoint thePoint)
170
183
{
171
184
// this is the coordinate resolved back to lat / lon
172
185
QgsSpatialRefSys mySrs;
173
- mySrs.createFromEpsg (GEOEPSG_ID ); // geo lat lon
186
+ mySrs.createFromEpsg (mEpsgId ); // geo lat lon
174
187
QgsCoordinateTransform myTransform (mQGisIface ->getMapCanvas ()->mapRenderer ()->destinationSrs (),mySrs);
175
- QgsPoint myGeoPoint = myTransform.transform (thePoint);
176
- mpGeoEdit ->setText (QString::number ( myGeoPoint .x (),' f' ,3 ) + " ," +
177
- QString::number ( myGeoPoint .y (),' f' ,3 ));
188
+ QgsPoint myUserCrsPoint = myTransform.transform (thePoint);
189
+ mpUserCrsEdit ->setText (QString::number ( myUserCrsPoint .x (),' f' ,3 ) + " ," +
190
+ QString::number ( myUserCrsPoint .y (),' f' ,3 ));
178
191
// This is the coordinate space of the map canvas
179
- mpTransformedEdit ->setText (QString::number ( thePoint.x (),' f' ,3 ) + " ," +
192
+ mpCanvasEdit ->setText (QString::number ( thePoint.x (),' f' ,3 ) + " ," +
180
193
QString::number ( thePoint.y (),' f' ,3 ));
181
194
}
182
195
void CoordinateCapture::copy ()
@@ -185,14 +198,14 @@ void CoordinateCapture::copy()
185
198
// if we are on x11 system put text into selection ready for middle button pasting
186
199
if (myClipboard->supportsSelection ())
187
200
{
188
- myClipboard->setText (mpGeoEdit ->text () + " ," + mpTransformedEdit ->text (),QClipboard::Selection);
201
+ myClipboard->setText (mpUserCrsEdit ->text () + " ," + mpCanvasEdit ->text (),QClipboard::Selection);
189
202
// QString myMessage = tr("Clipboard contents set to: ");
190
203
// statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Selection));
191
204
}
192
205
else
193
206
{
194
207
// user has an inferior operating system....
195
- myClipboard->setText (mpGeoEdit ->text () + " ," + mpTransformedEdit ->text (),QClipboard::Clipboard );
208
+ myClipboard->setText (mpUserCrsEdit ->text () + " ," + mpCanvasEdit ->text (),QClipboard::Clipboard );
196
209
// QString myMessage = tr("Clipboard contents set to: ");
197
210
// statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Clipboard));
198
211
}
0 commit comments