Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgsmaptool.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptool.cpp - base class for map canvas tools
3  ----------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 /* $Id$ */
16 
17 #include "qgslogger.h"
18 #include "qgsmaptool.h"
19 #include "qgsmapcanvas.h"
20 #include "qgsmaptopixel.h"
21 #include "qgsmaprenderer.h"
22 #include <QAction>
23 #include <QAbstractButton>
24 
26  : QObject( canvas ), mCanvas( canvas ), mCursor( Qt::CrossCursor ), mAction( NULL ), mButton( NULL )
27 {
28 }
29 
30 
32 {
33  mCanvas->unsetMapTool( this );
34 }
35 
36 
37 QgsPoint QgsMapTool::toMapCoordinates( const QPoint& point )
38 {
40 }
41 
42 
43 QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QPoint& point )
44 {
45  QgsPoint pt = toMapCoordinates( point );
46  return toLayerCoordinates( layer, pt );
47 }
48 
50 {
51  return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, point );
52 }
53 
55 {
56  return mCanvas->mapRenderer()->layerToMapCoordinates( layer, point );
57 }
58 
60 {
61  return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, rect );
62 }
63 
65 {
66  double x = point.x(), y = point.y();
68  return QPoint(( int )( x + 0.5 ), ( int )( y + 0.5 ) ); // round the values
69 }
70 
71 
73 {
74  // make action and/or button active
75  if ( mAction )
76  mAction->setChecked( true );
77  if ( mButton )
78  mButton->setChecked( true );
79 
80  // set cursor (map tools usually set it in constructor)
81  mCanvas->setCursor( mCursor );
82  QgsDebugMsg( "Cursor has been set" );
83 }
84 
85 
87 {
88  if ( mAction )
89  mAction->setChecked( false );
90  if ( mButton )
91  mButton->setChecked( false );
92 }
93 
94 void QgsMapTool::setAction( QAction* action )
95 {
96  mAction = action;
97 }
98 
100 {
101  return mAction;
102 }
103 
104 void QgsMapTool::setButton( QAbstractButton* button )
105 {
106  mButton = button;
107 }
108 
109 QAbstractButton* QgsMapTool::button()
110 {
111  return mButton;
112 }
113 
114 
115 void QgsMapTool::canvasMoveEvent( QMouseEvent * )
116 {
117 }
118 
120 {
121 }
122 
123 void QgsMapTool::canvasPressEvent( QMouseEvent * )
124 {
125 }
126 
127 void QgsMapTool::canvasReleaseEvent( QMouseEvent * )
128 {
129 }
130 
131 void QgsMapTool::keyPressEvent( QKeyEvent* e )
132 {
133 }
134 
135 void QgsMapTool::keyReleaseEvent( QKeyEvent* e )
136 {
137 }
138 
140 {
141 }
142 
144 {
145  return false;
146 }
147 
149 {
150  return false;
151 }
152 
154 {
155  return mCanvas;
156 }