Skip to content


Browse files Browse the repository at this point in the history
Added tracking button and logic for live mouse tracking.
git-svn-id: c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 6, 2008
1 parent 177516b commit 4f015a3
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 8 deletions.
38 changes: 33 additions & 5 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Expand Up @@ -43,6 +43,7 @@
#include <QLineEdit>
#include <QClipboard>
#include <QPushButton>
#include <QToolButton>

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

// create our map tool
mpMapTool = new CoordinateCaptureMapTool(mQGisIface->getMapCanvas());
connect(mpMapTool, SIGNAL(pointCaptured(QgsPoint)), this, SLOT(update(QgsPoint)));
connect(mpMapTool, SIGNAL(mouseMoved(QgsPoint)), this, SLOT(mouseMoved(QgsPoint)));
connect(mpMapTool, SIGNAL(mouseClicked(QgsPoint)), this, SLOT(mouseClicked(QgsPoint)));

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

QLabel * mypGeoLabel = new QLabel(mypWidget);
mypGeoLabel->setToolTip(tr("Coordinate in lat/long WGS84"));

QLabel * mypCRSLabel = new QLabel(mypWidget);
mypGeoLabel->setToolTip(tr("Coordinate in map canvas coordinate reference system"));

mpGeoEdit = new QLineEdit(mypWidget);
mpGeoEdit->setToolTip(tr("Coordinate in lat/long WGS84"));

mpTransformedEdit = new QLineEdit(mypWidget);
mpTransformedEdit->setToolTip(tr("Coordinate in map canvas coordinate reference system"));

QPushButton * mypCopyButton = new QPushButton(mypWidget);
mypCopyButton->setText(tr("Copy to clipboard"));
connect(mypCopyButton, SIGNAL(clicked()), this, SLOT(copy()));

mpTrackMouseButton = new QToolButton(mypWidget);
mpTrackMouseButton->setToolTip(tr("Click to enable mouse tracking. Click the canvas to stop"));

mypLayout->addWidget(mypGeoLabel, 0,0);
mypLayout->addWidget(mpGeoEdit, 0,1);
mypLayout->addWidget(mypCRSLabel, 1,0);
mypLayout->addWidget(mpTransformedEdit, 1,1);
mypLayout->addWidget(mpTrackMouseButton, 2,0);
mypLayout->addWidget(mypCopyButton, 2,1);

Expand All @@ -130,14 +143,29 @@ void CoordinateCapture::initGui()
// now add our custom widget to the dock - ownership of the widget is passed to the dock


//method defined in interface
void CoordinateCapture::help()
//implement me!

void CoordinateCapture::mouseClicked(QgsPoint thePoint)
//clicking on the canvas will update the widgets and then disable
//tracking so the user can copy the click point coords
void CoordinateCapture::mouseMoved(QgsPoint thePoint)
//mouse movements will only update the widgets if the
//tracking button is checked
void CoordinateCapture::update(QgsPoint thePoint)
//this is the coordinate resolved back to lat / lon
Expand Down
9 changes: 9 additions & 0 deletions src/plugins/coordinate_capture/coordinatecapture.h
Expand Up @@ -47,6 +47,7 @@
//forward declarations
class QAction;
class QToolBar;
class QToolButton;
class QDockWidget;
class QLineEdit;

Expand Down Expand Up @@ -87,6 +88,11 @@ public slots:
void unload();
//! show the help document
void help();
//! Called when mouse clicks on the canvas. Will populate text box with coords.
void mouseClicked(QgsPoint thePoint);
/** Called when mouse moved over the canvas. If the tracking button is toggled,
* the text box coords will be updated. */
void mouseMoved(QgsPoint thePoint);
//! Called when mouse is clicked on the canvas
void update(QgsPoint thePoint);
//! Called when user clicks the copy button
Expand All @@ -106,6 +112,9 @@ public slots:
//!Our custom map tool to capture clicks
CoordinateCaptureMapTool * mpMapTool;

//!A toolbutton to keep track whether mouse tracking is enabled
QToolButton * mpTrackMouseButton;

Expand Down
1 change: 1 addition & 0 deletions src/plugins/coordinate_capture/coordinatecapture.qrc
Expand Up @@ -3,5 +3,6 @@
7 changes: 5 additions & 2 deletions src/plugins/coordinate_capture/coordinatecapturemaptool.cpp
Expand Up @@ -45,8 +45,11 @@ CoordinateCaptureMapTool::~CoordinateCaptureMapTool()
delete mpRubberBand;

void CoordinateCaptureMapTool::canvasMoveEvent(QMouseEvent * e)
void CoordinateCaptureMapTool::canvasMoveEvent(QMouseEvent * thepEvent)
QgsPoint myOriginalPoint =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
emit mouseMoved(myOriginalPoint);

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

QgsPoint myOriginalPoint =
mCanvas->getCoordinateTransform()->toMapCoordinates(thepEvent->x(), thepEvent->y());
emit pointCaptured(myOriginalPoint);
emit mouseClicked(myOriginalPoint);

//make a little box for display

Expand Down
3 changes: 2 additions & 1 deletion src/plugins/coordinate_capture/coordinatecapturemaptool.h
Expand Up @@ -52,7 +52,8 @@ class CoordinateCaptureMapTool : public QgsMapTool
public slots:

void pointCaptured(QgsPoint);
void mouseMoved(QgsPoint);
void mouseClicked(QgsPoint);

//! Rubber band for highlighting identified feature
Expand Down
Binary file added src/plugins/coordinate_capture/tracking.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
199 changes: 199 additions & 0 deletions src/plugins/coordinate_capture/tracking.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4f015a3

Please sign in to comment.