Skip to content
Permalink
Browse files

Added utility function toLayerCoords

git-svn-id: http://svn.osgeo.org/qgis/trunk@5192 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Apr 6, 2006
1 parent 50ced72 commit 534abc87bf549080ed7432cbea0d69c95320e692
Showing with 30 additions and 0 deletions.
  1. +26 −0 src/gui/qgsmaptool.cpp
  2. +4 −0 src/gui/qgsmaptool.h
@@ -15,8 +15,10 @@
/* $Id$ */

#include "qgsmaptool.h"
#include "qgsmaplayer.h"
#include "qgsmapcanvas.h"
#include "qgsmaptopixel.h"
#include "qgsproject.h"
#include <QAction>

QgsMapTool::QgsMapTool(QgsMapCanvas* canvas)
@@ -36,6 +38,30 @@ QgsPoint QgsMapTool::toMapCoords(const QPoint& point)
}


QgsPoint QgsMapTool::toLayerCoords(QgsMapLayer* layer, const QPoint& point)
{
// FIXME: this information should be accessible elsewhere without accessing QgsProject!
bool projectionsEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);

if (projectionsEnabled)
{

if (!layer || !layer->coordinateTransform())
return QgsPoint(0,0);

// first transform from canvas coords to map coordinates
QgsPoint pnt = toMapCoords(point);

// then convert from
return layer->coordinateTransform()->transform(pnt, QgsCoordinateTransform::INVERSE);
}
else
{
return toMapCoords(point);
}
}


QPoint QgsMapTool::toCanvasCoords(const QgsPoint& point)
{
double x = point.x(), y = point.y();
@@ -20,6 +20,7 @@
#include <QCursor>
#include <QString>

class QgsMapLayer;
class QgsMapCanvas;
class QMouseEvent;
class QgsPoint;
@@ -74,6 +75,9 @@ class QgsMapTool
//! transformation from screen coordinates to map coordinates
QgsPoint toMapCoords(const QPoint& point);

//! transformation from screen coordinates to layer's coordinates
QgsPoint toLayerCoords(QgsMapLayer* layer, const QPoint& point);

//! transformation from map coordinates to screen coordinates
QPoint toCanvasCoords(const QgsPoint& point);

0 comments on commit 534abc8

Please sign in to comment.
You can’t perform that action at this time.