43
43
#include < QLineEdit>
44
44
#include < QClipboard>
45
45
#include < QPushButton>
46
+ #include < QToolButton>
46
47
47
48
static const char * const sIdent = " $Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $" ;
48
49
static const QString sName = QObject::tr(" Coordinate Capture" );
@@ -91,7 +92,8 @@ void CoordinateCapture::initGui()
91
92
92
93
// create our map tool
93
94
mpMapTool = new CoordinateCaptureMapTool (mQGisIface ->getMapCanvas ());
94
- connect (mpMapTool, SIGNAL (pointCaptured (QgsPoint)), this , SLOT (update (QgsPoint)));
95
+ connect (mpMapTool, SIGNAL (mouseMoved (QgsPoint)), this , SLOT (mouseMoved (QgsPoint)));
96
+ connect (mpMapTool, SIGNAL (mouseClicked (QgsPoint)), this , SLOT (mouseClicked (QgsPoint)));
95
97
96
98
97
99
// create a little widget with x and y display to put into our dock widget
@@ -102,22 +104,33 @@ void CoordinateCapture::initGui()
102
104
103
105
QLabel * mypGeoLabel = new QLabel (mypWidget);
104
106
mypGeoLabel->setPixmap (QPixmap (" :/coordinatecapture/geographic.png" ));
105
- mypGeoLabel-> setToolTip ( tr ( " Coordinate in lat/long WGS84 " ));
107
+
106
108
QLabel * mypCRSLabel = new QLabel (mypWidget);
107
109
mypCRSLabel->setPixmap (QPixmap (" :/coordinatecapture/transformed.png" ));
108
- mypGeoLabel-> setToolTip ( tr ( " Coordinate in map canvas coordinate reference system " ));
110
+
109
111
mpGeoEdit = new QLineEdit (mypWidget);
110
112
mpGeoEdit->setReadOnly (true );
113
+ mpGeoEdit->setToolTip (tr (" Coordinate in lat/long WGS84" ));
114
+
111
115
mpTransformedEdit = new QLineEdit (mypWidget);
112
116
mpTransformedEdit->setReadOnly (true );
117
+ mpTransformedEdit->setToolTip (tr (" Coordinate in map canvas coordinate reference system" ));
118
+
113
119
QPushButton * mypCopyButton = new QPushButton (mypWidget);
114
120
mypCopyButton->setText (tr (" Copy to clipboard" ));
115
121
connect (mypCopyButton, SIGNAL (clicked ()), this , SLOT (copy ()));
116
122
123
+ mpTrackMouseButton = new QToolButton (mypWidget);
124
+ mpTrackMouseButton->setCheckable (true );
125
+ mpTrackMouseButton->setToolTip (tr (" Click to enable mouse tracking. Click the canvas to stop" ));
126
+ mpTrackMouseButton->setChecked (false );
127
+ mpTrackMouseButton->setIcon (QIcon (" :/coordinatecapture/tracking.png" ));
128
+
117
129
mypLayout->addWidget (mypGeoLabel, 0 ,0 );
118
130
mypLayout->addWidget (mpGeoEdit, 0 ,1 );
119
131
mypLayout->addWidget (mypCRSLabel, 1 ,0 );
120
132
mypLayout->addWidget (mpTransformedEdit, 1 ,1 );
133
+ mypLayout->addWidget (mpTrackMouseButton, 2 ,0 );
121
134
mypLayout->addWidget (mypCopyButton, 2 ,1 );
122
135
123
136
@@ -130,14 +143,29 @@ void CoordinateCapture::initGui()
130
143
// now add our custom widget to the dock - ownership of the widget is passed to the dock
131
144
mpDockWidget->setWidget (mypWidget);
132
145
133
-
134
146
}
147
+
135
148
// method defined in interface
136
149
void CoordinateCapture::help ()
137
150
{
138
151
// implement me!
139
152
}
140
-
153
+ void CoordinateCapture::mouseClicked (QgsPoint thePoint)
154
+ {
155
+ // clicking on the canvas will update the widgets and then disable
156
+ // tracking so the user can copy the click point coords
157
+ mpTrackMouseButton->setChecked (false );
158
+ update (thePoint);
159
+ }
160
+ void CoordinateCapture::mouseMoved (QgsPoint thePoint)
161
+ {
162
+ // mouse movements will only update the widgets if the
163
+ // tracking button is checked
164
+ if (mpTrackMouseButton->isChecked ())
165
+ {
166
+ update (thePoint);
167
+ }
168
+ }
141
169
void CoordinateCapture::update (QgsPoint thePoint)
142
170
{
143
171
// this is the coordinate resolved back to lat / lon
0 commit comments