QGIS API Documentation  3.0.2-Girona (307d082)
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 #include "qgsmapcanvas.h"
20 
22  : QgsMapToolEdit( canvas )
23  , mCadDockWidget( cadDockWidget )
24 {
25 }
26 
28 {
29  if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() )
30  {
31  mCadDockWidget->applyConstraints( e ); // updates event's map point
32 
33  if ( mCadDockWidget->constructionMode() )
34  return; // decided to eat the event and not pass it to the map tool (construction mode)
35  }
36  else if ( isAutoSnapEnabled() )
37  {
38  e->snapPoint();
39  }
40 
42 }
43 
45 {
46  if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() )
47  {
48  if ( e->button() == Qt::RightButton )
49  {
50  mCadDockWidget->clear();
51  }
52  else
53  {
54  mCadDockWidget->applyConstraints( e ); // updates event's map point
55 
56  if ( mCadDockWidget->alignToSegment( e ) )
57  {
58  // Parallel or perpendicular mode and snapped to segment: do not pass the event to map tool
59  return;
60  }
61 
62  mCadDockWidget->addPoint( e->mapPoint() );
63 
64  mCadDockWidget->releaseLocks( false );
65 
66  if ( mCadDockWidget->constructionMode() )
67  return; // decided to eat the event and not pass it to the map tool (construction mode)
68  }
69  }
70  else if ( isAutoSnapEnabled() )
71  {
72  e->snapPoint();
73  }
74 
76 }
77 
79 {
80  if ( isAdvancedDigitizingAllowed() && mCadDockWidget->cadEnabled() )
81  {
82  mCadDockWidget->applyConstraints( e ); // updates event's map point
83 
84  // perpendicular/parallel constraint
85  // do a soft lock when snapping to a segment
87  mCadDockWidget->updateCadPaintItem();
88  }
89  else if ( isAutoSnapEnabled() )
90  {
91  e->snapPoint();
92  }
93 
94  cadCanvasMoveEvent( e );
95 }
96 
98 {
100  connect( mCadDockWidget, &QgsAdvancedDigitizingDockWidget::pointChanged, this, &QgsMapToolAdvancedDigitizing::cadPointChanged );
101  mCadDockWidget->enable();
102 }
103 
105 {
107  disconnect( mCadDockWidget, &QgsAdvancedDigitizingDockWidget::pointChanged, this, &QgsMapToolAdvancedDigitizing::cadPointChanged );
108  mCadDockWidget->disable();
109 }
110 
111 void QgsMapToolAdvancedDigitizing::cadPointChanged( const QgsPointXY &point )
112 {
113  Q_UNUSED( point );
114  QMouseEvent *ev = new QMouseEvent( QEvent::MouseMove, mCanvas->mouseLastXY(), Qt::NoButton, Qt::NoButton, Qt::NoModifier );
115  qApp->postEvent( mCanvas->viewport(), ev ); // event queue will delete the event when processed
116 }
bool constructionMode() const
construction mode is used to draw intermediate points. These points won't be given any further (i...
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.
A class to represent a 2D point.
Definition: qgspointxy.h:43
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
bool isAutoSnapEnabled() const
Returns whether mouse events (press/move/release) should automatically try to snap mouse position (ac...
void activate() override
Registers this maptool with the cad dock widget.
bool applyConstraints(QgsMapMouseEvent *e)
apply the CAD constraints.
void canvasMoveEvent(QgsMapMouseEvent *e) override
Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual metho...
bool isAdvancedDigitizingAllowed() const
Returns whether functionality of advanced digitizing dock widget is currently allowed.
void clear()
Clear any cached previous clicks and helper lines.
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:74
void releaseLocks(bool releaseRepeatingLocks=true)
unlock all constraints
virtual void activate()
called when set as currently active map tool
Definition: qgsmaptool.cpp:81
QgsMapCanvas * mCanvas
pointer to map canvas
Definition: qgsmaptool.h:236
void canvasPressEvent(QgsMapMouseEvent *e) override
Catch the mouse press event, filters it, transforms it to map coordinates and send it to virtual meth...
void updateCadPaintItem()
Updates canvas item that displays constraints on the ma.
void canvasReleaseEvent(QgsMapMouseEvent *e) override
Catch the mouse release event, filters it, transforms it to map coordinates and send it to virtual me...
void addPoint(const QgsPointXY &point)
Adds point to the CAD point list.
virtual void deactivate()
called when map tool is being deactivated
Definition: qgsmaptool.cpp:97
void enable()
Enables the tool (call this when an appropriate map tool is set and in the condition to make use of c...
void pointChanged(const QgsPointXY &point)
Sometimes a constraint may change the current point out of a mouse event.
QPoint mouseLastXY()
returns last position of mouse cursor
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
virtual void cadCanvasPressEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
virtual void cadCanvasMoveEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
virtual void cadCanvasReleaseEvent(QgsMapMouseEvent *e)
Override this method when subclassing this class.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
bool alignToSegment(QgsMapMouseEvent *e, QgsAdvancedDigitizingDockWidget::CadConstraint::LockMode lockMode=QgsAdvancedDigitizingDockWidget::CadConstraint::HardLock)
align to segment for additional constraint.
void deactivate() override
Unregisters this maptool from the cad dock widget.