Skip to content

Commit

Permalink
Final fixes for ticket #1024
Browse files Browse the repository at this point in the history
 - you can now set the display CRS to any CRS you like by selecting one from the projection selector using the button provided
 - other small cleanups to the coordinate capture plugin


git-svn-id: http://svn.osgeo.org/qgis/trunk@9012 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
timlinux committed Aug 7, 2008
1 parent aa896df commit 59be558
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 23 deletions.
6 changes: 5 additions & 1 deletion src/plugins/coordinate_capture/CMakeLists.txt
Expand Up @@ -31,7 +31,11 @@ ADD_LIBRARY (coordinatecaptureplugin MODULE ${coordinatecapture_SRCS} ${coordina

INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/raster ../../core/renderer ../../core/symbology
${CMAKE_CURRENT_BINARY_DIR}/../../ui/
../../core
../../core/raster
../../core/renderer
../../core/symbology
../../gui
..
)
Expand Down
51 changes: 32 additions & 19 deletions src/plugins/coordinate_capture/coordinatecapture.cpp
Expand Up @@ -28,6 +28,7 @@
#include <qgis.h>
#include <qgsspatialrefsys.h>
#include <qgscoordinatetransform.h>
#include <qgsgenericprojectionselector.h>

#include "coordinatecapture.h"
#include "coordinatecapturegui.h"
Expand Down Expand Up @@ -79,7 +80,7 @@ CoordinateCapture::~CoordinateCapture()
*/
void CoordinateCapture::initGui()
{

mEpsgId = GEOEPSG_ID;
// Create the action for tool
mQActionPointer = new QAction(QIcon(":/coordinatecapture/coordinate_capture.png"),tr("Coordinate Capture"), this);
// Set the what's this text
Expand All @@ -102,19 +103,20 @@ void CoordinateCapture::initGui()
mypLayout->setColumnMinimumWidth( 0, 36 );
mypWidget->setLayout(mypLayout);

QLabel * mypGeoLabel = new QLabel(mypWidget);
mypGeoLabel->setPixmap(QPixmap(":/coordinatecapture/geographic.png"));
QToolButton * mypUserCrsToolButton = new QToolButton(mypWidget);
mypUserCrsToolButton->setIcon(QIcon(":/coordinatecapture/geographic.png"));
connect(mypUserCrsToolButton , SIGNAL(clicked()), this, SLOT(setCRS()));

QLabel * mypCRSLabel = new QLabel(mypWidget);
mypCRSLabel->setPixmap(QPixmap(":/coordinatecapture/transformed.png"));

mpGeoEdit = new QLineEdit(mypWidget);
mpGeoEdit->setReadOnly(true);
mpGeoEdit->setToolTip(tr("Coordinate in lat/long WGS84"));
mpUserCrsEdit = new QLineEdit(mypWidget);
mpUserCrsEdit->setReadOnly(true);
mpUserCrsEdit->setToolTip(tr("Coordinate in your selected CRS"));

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

QPushButton * mypCopyButton = new QPushButton(mypWidget);
mypCopyButton->setText(tr("Copy to clipboard"));
Expand All @@ -126,10 +128,10 @@ void CoordinateCapture::initGui()
mpTrackMouseButton->setChecked(false);
mpTrackMouseButton->setIcon(QIcon(":/coordinatecapture/tracking.png"));

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

Expand All @@ -150,6 +152,17 @@ void CoordinateCapture::help()
{
//implement me!
}

void CoordinateCapture::setCRS()
{
QgsGenericProjectionSelector mySelector(mQGisIface->getMainWindow());
mySelector.setSelectedEpsg(mEpsgId);
if (mySelector.exec())
{
mEpsgId = mySelector.getSelectedEpsg();
}
}

void CoordinateCapture::mouseClicked(QgsPoint thePoint)
{
//clicking on the canvas will update the widgets and then disable
Expand All @@ -170,13 +183,13 @@ void CoordinateCapture::update(QgsPoint thePoint)
{
//this is the coordinate resolved back to lat / lon
QgsSpatialRefSys mySrs;
mySrs.createFromEpsg(GEOEPSG_ID); //geo lat lon
mySrs.createFromEpsg(mEpsgId); //geo lat lon
QgsCoordinateTransform myTransform(mQGisIface->getMapCanvas()->mapRenderer()->destinationSrs(),mySrs);
QgsPoint myGeoPoint = myTransform.transform(thePoint);
mpGeoEdit->setText(QString::number( myGeoPoint.x(),'f',3) + "," +
QString::number( myGeoPoint.y(),'f',3));
QgsPoint myUserCrsPoint = myTransform.transform(thePoint);
mpUserCrsEdit->setText(QString::number( myUserCrsPoint.x(),'f',3) + "," +
QString::number( myUserCrsPoint.y(),'f',3));
// This is the coordinate space of the map canvas
mpTransformedEdit->setText(QString::number( thePoint.x(),'f',3) + "," +
mpCanvasEdit->setText(QString::number( thePoint.x(),'f',3) + "," +
QString::number( thePoint.y(),'f',3));
}
void CoordinateCapture::copy()
Expand All @@ -185,14 +198,14 @@ void CoordinateCapture::copy()
//if we are on x11 system put text into selection ready for middle button pasting
if (myClipboard->supportsSelection())
{
myClipboard->setText(mpGeoEdit->text() + "," + mpTransformedEdit->text(),QClipboard::Selection);
myClipboard->setText(mpUserCrsEdit->text() + "," + mpCanvasEdit->text(),QClipboard::Selection);
//QString myMessage = tr("Clipboard contents set to: ");
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Selection));
}
else
{
//user has an inferior operating system....
myClipboard->setText(mpGeoEdit->text() + "," + mpTransformedEdit->text(),QClipboard::Clipboard );
myClipboard->setText(mpUserCrsEdit->text() + "," + mpCanvasEdit->text(),QClipboard::Clipboard );
//QString myMessage = tr("Clipboard contents set to: ");
//statusBar()->showMessage(myMessage + myClipboard->text(QClipboard::Clipboard));
}
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/coordinate_capture/coordinatecapture.h
Expand Up @@ -88,6 +88,8 @@ public slots:
void unload();
//! show the help document
void help();
//! Set the Coordinate Reference System used for displaying non canvas CRS coord
void setCRS();
//! 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,
Expand All @@ -103,18 +105,21 @@ public slots:
//! Container for the coordinate info
QPointer<QDockWidget> mpDockWidget;

//!output display for geographic lat/long coords
QPointer<QLineEdit> mpGeoEdit;
//!output display for user defined Coordinate Reference System
QPointer<QLineEdit> mpUserCrsEdit;

//!output display for CRS coord
QPointer<QLineEdit> mpTransformedEdit;
QPointer<QLineEdit> mpCanvasEdit;

//!Our custom map tool to capture clicks
CoordinateCaptureMapTool * mpMapTool;

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

//!epsg id for showin in geoedit box
long mEpsgId;

////////////////////////////////////////////////////////////////////
//
// MANDATORY PLUGIN PROPERTY DECLARATIONS .....
Expand Down

0 comments on commit 59be558

Please sign in to comment.