QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsmaptooladvanceddigitizing.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaptooladvanceddigitizing.cpp - map tool with event in map coordinates
3  ----------------------
4  begin : October 2014
5  copyright : (C) Denis Rouzaud
6  email : [email protected]
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 
16 #include "qgsmapmouseevent.h"
18 
19 
21  : QgsMapToolEdit( canvas )
22  , mCaptureMode( CapturePoint )
23  , mSnapOnPress( false )
24  , mSnapOnRelease( false )
25  , mSnapOnMove( false )
26  , mSnapOnDoubleClick( false )
27  , mCadDockWidget( cadDockWidget )
28 {
29 }
30 
32 {
33 }
34 
36 {
37  snap( e );
38  if ( !mCadDockWidget->canvasPressEvent( e ) )
40 }
41 
43 {
44  snap( e );
45  if ( !mCadDockWidget->canvasReleaseEvent( e, mCaptureMode == CaptureLine || mCaptureMode == CapturePolygon ) )
47 }
48 
50 {
51  snap( e );
52  if ( !mCadDockWidget->canvasMoveEvent( e ) )
53  cadCanvasMoveEvent( e );
54 }
55 
57 {
59  connect( mCadDockWidget, SIGNAL( pointChanged( QgsPoint ) ), this, SLOT( cadPointChanged( QgsPoint ) ) );
60  mCadDockWidget->enable();
61 }
62 
64 {
66  disconnect( mCadDockWidget, SIGNAL( pointChanged( QgsPoint ) ), this, SLOT( cadPointChanged( QgsPoint ) ) );
67  mCadDockWidget->disable();
68 }
69 
70 void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPoint& point )
71 {
72  QgsMapMouseEvent fakeEvent( mCanvas, QMouseEvent::Move, QPoint( 0, 0 ) );
73  fakeEvent.setMapPoint( point );
74  canvasMoveEvent( &fakeEvent );
75 }
76 
77 void QgsMapToolAdvancedDigitizing::snap( QgsMapMouseEvent* e )
78 {
79  if ( !mCadDockWidget->cadEnabled() )
81 }
bool cadEnabled() const
determines if CAD tools are enabled or if map tools behaves "nomally"
QgsMapToolAdvancedDigitizing(QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget)
Creates an advanced digitizing maptool.
bool canvasReleaseEvent(QgsMapMouseEvent *e, bool captureSegment)
Will react on a canvas release event.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
virtual void activate() override
Registers this maptool with the cad dock widget.
virtual void canvasMoveEvent(QgsMapMouseEvent *e) override
catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual metho...
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
Base class for map tools that edit vector geometry.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:109
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:83
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:213
virtual void canvasPressEvent(QgsMapMouseEvent *e) override
catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual meth...
snap according to the configuration set in the snapping settings
virtual void canvasReleaseEvent(QgsMapMouseEvent *e) override
catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual me...
CaptureMode mCaptureMode
The capture mode in which this tool operates.
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:99
void enable()
Enables the tool (call this when an appropriate map tool is set and in the condition to make use of c...
A class to represent a point.
Definition: qgspoint.h:117
void setMapPoint(const QgsPoint &point)
Set the (snapped) point this event points to in map coordinates.
bool canvasMoveEvent(QgsMapMouseEvent *e)
Will react on a canvas move event.
virtual void cadCanvasPressEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
bool canvasPressEvent(QgsMapMouseEvent *e)
Will react on a canvas press event.
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
virtual void cadCanvasReleaseEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
QgsPoint snapPoint(SnappingMode snappingMode)
snapPoint will snap the points using the map canvas snapping utils configuration
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
virtual void deactivate() override
Unregisters this maptool from the cad dock widget.