00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "qgslogger.h"
00018 #include "qgsmaptool.h"
00019 #include "qgsmapcanvas.h"
00020 #include "qgsmaptopixel.h"
00021 #include "qgsmaprenderer.h"
00022 #include <QAction>
00023 #include <QAbstractButton>
00024
00025 QgsMapTool::QgsMapTool( QgsMapCanvas* canvas )
00026 : QObject( canvas ), mCanvas( canvas ), mCursor( Qt::CrossCursor ), mAction( NULL ), mButton( NULL )
00027 {
00028 }
00029
00030
00031 QgsMapTool::~QgsMapTool()
00032 {
00033 mCanvas->unsetMapTool( this );
00034 }
00035
00036
00037 QgsPoint QgsMapTool::toMapCoordinates( const QPoint& point )
00038 {
00039 return mCanvas->getCoordinateTransform()->toMapCoordinates( point );
00040 }
00041
00042
00043 QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QPoint& point )
00044 {
00045 QgsPoint pt = toMapCoordinates( point );
00046 return toLayerCoordinates( layer, pt );
00047 }
00048
00049 QgsPoint QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsPoint& point )
00050 {
00051 return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, point );
00052 }
00053
00054 QgsPoint QgsMapTool::toMapCoordinates( QgsMapLayer* layer, const QgsPoint& point )
00055 {
00056 return mCanvas->mapRenderer()->layerToMapCoordinates( layer, point );
00057 }
00058
00059 QgsRectangle QgsMapTool::toLayerCoordinates( QgsMapLayer* layer, const QgsRectangle& rect )
00060 {
00061 return mCanvas->mapRenderer()->mapToLayerCoordinates( layer, rect );
00062 }
00063
00064 QPoint QgsMapTool::toCanvasCoordinates( const QgsPoint& point )
00065 {
00066 double x = point.x(), y = point.y();
00067 mCanvas->getCoordinateTransform()->transformInPlace( x, y );
00068 return QPoint(( int )( x + 0.5 ), ( int )( y + 0.5 ) );
00069 }
00070
00071
00072 void QgsMapTool::activate()
00073 {
00074
00075 if ( mAction )
00076 mAction->setChecked( true );
00077 if ( mButton )
00078 mButton->setChecked( true );
00079
00080
00081 mCanvas->setCursor( mCursor );
00082 QgsDebugMsg( "Cursor has been set" );
00083 }
00084
00085
00086 void QgsMapTool::deactivate()
00087 {
00088 if ( mAction )
00089 mAction->setChecked( false );
00090 if ( mButton )
00091 mButton->setChecked( false );
00092 }
00093
00094 void QgsMapTool::setAction( QAction* action )
00095 {
00096 mAction = action;
00097 }
00098
00099 QAction* QgsMapTool::action()
00100 {
00101 return mAction;
00102 }
00103
00104 void QgsMapTool::setButton( QAbstractButton* button )
00105 {
00106 mButton = button;
00107 }
00108
00109 QAbstractButton* QgsMapTool::button()
00110 {
00111 return mButton;
00112 }
00113
00114
00115 void QgsMapTool::canvasMoveEvent( QMouseEvent * )
00116 {
00117 }
00118
00119 void QgsMapTool::canvasDoubleClickEvent( QMouseEvent * )
00120 {
00121 }
00122
00123 void QgsMapTool::canvasPressEvent( QMouseEvent * )
00124 {
00125 }
00126
00127 void QgsMapTool::canvasReleaseEvent( QMouseEvent * )
00128 {
00129 }
00130
00131 void QgsMapTool::keyPressEvent( QKeyEvent* e )
00132 {
00133 }
00134
00135 void QgsMapTool::keyReleaseEvent( QKeyEvent* e )
00136 {
00137 }
00138
00139 void QgsMapTool::renderComplete()
00140 {
00141 }
00142
00143 bool QgsMapTool::isTransient()
00144 {
00145 return false;
00146 }
00147
00148 bool QgsMapTool::isEditTool()
00149 {
00150 return false;
00151 }
00152
00153 QgsMapCanvas* QgsMapTool::canvas()
00154 {
00155 return mCanvas;
00156 }