24
24
#include < qgisgui.h>
25
25
#include < qgspoint.h>
26
26
#include < qgsmapcanvas.h>
27
+ #include < qgsmaprenderer.h>
28
+ #include < qgis.h>
29
+ #include < qgsspatialrefsys.h>
30
+ #include < qgscoordinatetransform.h>
27
31
28
32
#include " coordinatecapture.h"
29
33
#include " coordinatecapturegui.h"
@@ -100,16 +104,16 @@ void CoordinateCapture::initGui()
100
104
mypGeoLabel->setPixmap (QPixmap (" :/coordinatecapture/geographic.png" ));
101
105
QLabel * mypCRSLabel = new QLabel (mypWidget);
102
106
mypCRSLabel->setPixmap (QPixmap (" :/coordinatecapture/transformed.png" ));
103
- mpXEdit = new QLineEdit (mypWidget);
104
- mpYEdit = new QLineEdit (mypWidget);
107
+ mpGeoEdit = new QLineEdit (mypWidget);
108
+ mpTransformedEdit = new QLineEdit (mypWidget);
105
109
QPushButton * mypCopyButton = new QPushButton (mypWidget);
106
110
mypCopyButton->setText (tr (" Copy to clipboard" ));
107
111
connect (mypCopyButton, SIGNAL (clicked ()), this , SLOT (copy ()));
108
112
109
113
mypLayout->addWidget (mypGeoLabel, 0 ,0 );
110
- mypLayout->addWidget (mpXEdit , 0 ,1 );
114
+ mypLayout->addWidget (mpGeoEdit , 0 ,1 );
111
115
mypLayout->addWidget (mypCRSLabel, 1 ,0 );
112
- mypLayout->addWidget (mpYEdit , 1 ,1 );
116
+ mypLayout->addWidget (mpTransformedEdit , 1 ,1 );
113
117
mypLayout->addWidget (mypCopyButton, 2 ,1 );
114
118
115
119
@@ -132,23 +136,31 @@ void CoordinateCapture::help()
132
136
133
137
void CoordinateCapture::update (QgsPoint thePoint)
134
138
{
135
- mpXEdit->setText (QString::number ( thePoint.x (),' f' ));
136
- mpYEdit->setText (QString::number ( thePoint.y (),' f' ));
139
+ // this is the coordinate resolved back to lat / lon
140
+ QgsSpatialRefSys mySrs;
141
+ mySrs.createFromEpsg (GEOEPSG_ID); // geo lat lon
142
+ QgsCoordinateTransform myTransform (mQGisIface ->getMapCanvas ()->mapRenderer ()->destinationSrs (),mySrs);
143
+ QgsPoint myGeoPoint = myTransform.transform (thePoint);
144
+ mpGeoEdit->setText (QString::number ( myGeoPoint.x (),' f' ,3 ) + " ," +
145
+ QString::number ( myGeoPoint.y (),' f' ,3 ));
146
+ // This is the coordinate space of the map canvas
147
+ mpTransformedEdit->setText (QString::number ( thePoint.x (),' f' ,3 ) + " ," +
148
+ QString::number ( thePoint.y (),' f' ,3 ));
137
149
}
138
150
void CoordinateCapture::copy ()
139
151
{
140
152
QClipboard *myClipboard = QApplication::clipboard ();
141
153
// if we are on x11 system put text into selection ready for middle button pasting
142
154
if (myClipboard->supportsSelection ())
143
155
{
144
- myClipboard->setText (mpXEdit ->text () + " ," + mpYEdit ->text (),QClipboard::Selection);
156
+ myClipboard->setText (mpGeoEdit ->text () + " ," + mpTransformedEdit ->text (),QClipboard::Selection);
145
157
// QString myMessage = tr("Clipboard contents set to: ");
146
158
// statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Selection));
147
159
}
148
160
else
149
161
{
150
162
// user has an inferior operating system....
151
- myClipboard->setText (mpXEdit ->text () + " ," + mpYEdit ->text (),QClipboard::Clipboard );
163
+ myClipboard->setText (mpGeoEdit ->text () + " ," + mpTransformedEdit ->text (),QClipboard::Clipboard );
152
164
// QString myMessage = tr("Clipboard contents set to: ");
153
165
// statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Clipboard));
154
166
}
0 commit comments