File tree 2 files changed +30
-0
lines changed
2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 15
15
/* $Id$ */
16
16
17
17
#include " qgsmaptool.h"
18
+ #include " qgsmaplayer.h"
18
19
#include " qgsmapcanvas.h"
19
20
#include " qgsmaptopixel.h"
21
+ #include " qgsproject.h"
20
22
#include < QAction>
21
23
22
24
QgsMapTool::QgsMapTool (QgsMapCanvas* canvas)
@@ -36,6 +38,30 @@ QgsPoint QgsMapTool::toMapCoords(const QPoint& point)
36
38
}
37
39
38
40
41
+ QgsPoint QgsMapTool::toLayerCoords (QgsMapLayer* layer, const QPoint& point)
42
+ {
43
+ // FIXME: this information should be accessible elsewhere without accessing QgsProject!
44
+ bool projectionsEnabled = (QgsProject::instance ()->readNumEntry (" SpatialRefSys" ," /ProjectionsEnabled" ,0 )!=0 );
45
+
46
+ if (projectionsEnabled)
47
+ {
48
+
49
+ if (!layer || !layer->coordinateTransform ())
50
+ return QgsPoint (0 ,0 );
51
+
52
+ // first transform from canvas coords to map coordinates
53
+ QgsPoint pnt = toMapCoords (point);
54
+
55
+ // then convert from
56
+ return layer->coordinateTransform ()->transform (pnt, QgsCoordinateTransform::INVERSE);
57
+ }
58
+ else
59
+ {
60
+ return toMapCoords (point);
61
+ }
62
+ }
63
+
64
+
39
65
QPoint QgsMapTool::toCanvasCoords (const QgsPoint& point)
40
66
{
41
67
double x = point.x (), y = point.y ();
Original file line number Diff line number Diff line change 20
20
#include < QCursor>
21
21
#include < QString>
22
22
23
+ class QgsMapLayer ;
23
24
class QgsMapCanvas ;
24
25
class QMouseEvent ;
25
26
class QgsPoint ;
@@ -74,6 +75,9 @@ class QgsMapTool
74
75
// ! transformation from screen coordinates to map coordinates
75
76
QgsPoint toMapCoords (const QPoint& point);
76
77
78
+ // ! transformation from screen coordinates to layer's coordinates
79
+ QgsPoint toLayerCoords (QgsMapLayer* layer, const QPoint& point);
80
+
77
81
// ! transformation from map coordinates to screen coordinates
78
82
QPoint toCanvasCoords (const QgsPoint& point);
79
83
You can’t perform that action at this time.
0 commit comments