Skip to content

Commit c760a1c

Browse files
author
timlinux
committedAug 6, 2008

File tree

7 files changed

+249
-8
lines changed

7 files changed

+249
-8
lines changed
 

‎src/plugins/coordinate_capture/coordinatecapture.cpp

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <QLineEdit>
4444
#include <QClipboard>
4545
#include <QPushButton>
46+
#include <QToolButton>
4647

4748
static const char * const sIdent = "$Id: plugin.cpp 8053 2008-01-26 13:59:53Z timlinux $";
4849
static const QString sName = QObject::tr("Coordinate Capture");
@@ -91,7 +92,8 @@ void CoordinateCapture::initGui()
9192

9293
// create our map tool
9394
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)));
9597

9698

9799
// create a little widget with x and y display to put into our dock widget
@@ -102,22 +104,33 @@ void CoordinateCapture::initGui()
102104

103105
QLabel * mypGeoLabel = new QLabel(mypWidget);
104106
mypGeoLabel->setPixmap(QPixmap(":/coordinatecapture/geographic.png"));
105-
mypGeoLabel->setToolTip(tr("Coordinate in lat/long WGS84"));
107+
106108
QLabel * mypCRSLabel = new QLabel(mypWidget);
107109
mypCRSLabel->setPixmap(QPixmap(":/coordinatecapture/transformed.png"));
108-
mypGeoLabel->setToolTip(tr("Coordinate in map canvas coordinate reference system"));
110+
109111
mpGeoEdit = new QLineEdit(mypWidget);
110112
mpGeoEdit->setReadOnly(true);
113+
mpGeoEdit->setToolTip(tr("Coordinate in lat/long WGS84"));
114+
111115
mpTransformedEdit = new QLineEdit(mypWidget);
112116
mpTransformedEdit->setReadOnly(true);
117+
mpTransformedEdit->setToolTip(tr("Coordinate in map canvas coordinate reference system"));
118+
113119
QPushButton * mypCopyButton = new QPushButton(mypWidget);
114120
mypCopyButton->setText(tr("Copy to clipboard"));
115121
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));
116122

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+
117129
mypLayout->addWidget(mypGeoLabel, 0,0);
118130
mypLayout->addWidget(mpGeoEdit, 0,1);
119131
mypLayout->addWidget(mypCRSLabel, 1,0);
120132
mypLayout->addWidget(mpTransformedEdit, 1,1);
133+
mypLayout->addWidget(mpTrackMouseButton, 2,0);
121134
mypLayout->addWidget(mypCopyButton, 2,1);
122135

123136

@@ -130,14 +143,29 @@ void CoordinateCapture::initGui()
130143
// now add our custom widget to the dock - ownership of the widget is passed to the dock
131144
mpDockWidget->setWidget(mypWidget);
132145

133-
134146
}
147+
135148
//method defined in interface
136149
void CoordinateCapture::help()
137150
{
138151
//implement me!
139152
}
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+
}
141169
void CoordinateCapture::update(QgsPoint thePoint)
142170
{
143171
//this is the coordinate resolved back to lat / lon

‎src/plugins/coordinate_capture/coordinatecapture.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
//forward declarations
4848
class QAction;
4949
class QToolBar;
50+
class QToolButton;
5051
class QDockWidget;
5152
class QLineEdit;
5253

@@ -87,6 +88,11 @@ public slots:
8788
void unload();
8889
//! show the help document
8990
void help();
91+
//! Called when mouse clicks on the canvas. Will populate text box with coords.
92+
void mouseClicked(QgsPoint thePoint);
93+
/** Called when mouse moved over the canvas. If the tracking button is toggled,
94+
* the text box coords will be updated. */
95+
void mouseMoved(QgsPoint thePoint);
9096
//! Called when mouse is clicked on the canvas
9197
void update(QgsPoint thePoint);
9298
//! Called when user clicks the copy button
@@ -106,6 +112,9 @@ public slots:
106112
//!Our custom map tool to capture clicks
107113
CoordinateCaptureMapTool * mpMapTool;
108114

115+
//!A toolbutton to keep track whether mouse tracking is enabled
116+
QToolButton * mpTrackMouseButton;
117+
109118
////////////////////////////////////////////////////////////////////
110119
//
111120
// MANDATORY PLUGIN PROPERTY DECLARATIONS .....

‎src/plugins/coordinate_capture/coordinatecapture.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
<file>coordinate_capture.png</file>
44
<file>geographic.png</file>
55
<file>transformed.png</file>
6+
<file>tracking.png</file>
67
</qresource>
78
</RCC>

‎src/plugins/coordinate_capture/coordinatecapturemaptool.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ CoordinateCaptureMapTool::~CoordinateCaptureMapTool()
4545
delete mpRubberBand;
4646
}
4747

48-
void CoordinateCaptureMapTool::canvasMoveEvent(QMouseEvent * e)
48+
void CoordinateCaptureMapTool::canvasMoveEvent(QMouseEvent * thepEvent)
4949
{
50+
QgsPoint myOriginalPoint =
51+
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
52+
emit mouseMoved(myOriginalPoint);
5053
}
5154

5255
void CoordinateCaptureMapTool::canvasPressEvent(QMouseEvent * thepEvent)
@@ -62,7 +65,7 @@ void CoordinateCaptureMapTool::canvasReleaseEvent(QMouseEvent * thepEvent)
6265

6366
QgsPoint myOriginalPoint =
6467
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
65-
emit pointCaptured(myOriginalPoint);
68+
emit mouseClicked(myOriginalPoint);
6669

6770
//make a little box for display
6871

‎src/plugins/coordinate_capture/coordinatecapturemaptool.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class CoordinateCaptureMapTool : public QgsMapTool
5252
public slots:
5353

5454
signals:
55-
void pointCaptured(QgsPoint);
55+
void mouseMoved(QgsPoint);
56+
void mouseClicked(QgsPoint);
5657
private:
5758

5859
//! Rubber band for highlighting identified feature
2.11 KB
Loading
Lines changed: 199 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)
Please sign in to comment.