QGIS API Documentation  2.14.11-Essen
qgsadvanceddigitizingdockwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsadvanceddigitizingdock.h - dock for CAD tools
3  ----------------------
4  begin : October 2014
5  copyright : (C) Denis Rouzaud
6  email : denis.rouzaud@gmail.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 
16 #ifndef QGSADVANCEDDIGITIZINGDOCK
17 #define QGSADVANCEDDIGITIZINGDOCK
18 
19 #include <QDockWidget>
20 
21 #include "qgsmapmouseevent.h"
22 #include "qgsmessagebaritem.h"
23 
24 #include <ui_qgsadvanceddigitizingdockwidgetbase.h>
25 
26 
28 class QgsMapCanvas;
29 class QgsMapTool;
31 class QgsPoint;
32 
33 // tolerances for soft constraints (last values, and common angles)
34 // for angles, both tolerance in pixels and degrees are used for better performance
35 static const double SoftConstraintTolerancePixel = 15;
36 static const double SoftConstraintToleranceDegrees = 10;
37 
44 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
45 {
46  Q_OBJECT
47  Q_FLAGS( CadCapacities )
48 
49  public:
50 
57  {
58  AbsoluteAngle = 1,
59  RelativeAngle = 2,
60  RelativeCoordinates = 4,
61  };
62  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
63 
64 
68  {
71  Parallel
72  };
73 
79  class GUI_EXPORT CadConstraint
80  {
81  public:
85  enum LockMode
86  {
89  HardLock
90  };
91 
92  CadConstraint( QLineEdit* lineEdit, QToolButton* lockerButton, QToolButton* relativeButton = nullptr )
93  : mLineEdit( lineEdit )
94  , mLockerButton( lockerButton )
95  , mRelativeButton( relativeButton )
96  , mLockMode( NoLock )
97  , mRelative( false )
98  , mValue( 0.0 )
99  {}
100 
105  LockMode lockMode() const { return mLockMode; }
109  bool isLocked() const { return mLockMode != NoLock; }
113  bool relative() const { return mRelative; }
117  double value() const { return mValue; }
118 
122  QLineEdit* lineEdit() const { return mLineEdit; }
123 
127  void setLockMode( LockMode mode );
128 
132  void setRelative( bool relative );
133 
137  void setValue( double value );
138 
142  void toggleLocked();
143 
147  void toggleRelative();
148 
149  private:
150  QLineEdit* mLineEdit;
151  QToolButton* mLockerButton;
152  QToolButton* mRelativeButton;
153  LockMode mLockMode;
154  bool mRelative;
155  double mValue;
156  };
157 
160  static bool lineCircleIntersection( const QgsPoint& center, const double radius, const QList<QgsPoint>& segment, QgsPoint& intersection );
161 
167  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas* canvas, QWidget *parent = nullptr );
168 
172  void hideEvent( QHideEvent* ) override;
173 
180  bool canvasPressEvent( QgsMapMouseEvent* e );
188  bool canvasReleaseEvent( QgsMapMouseEvent* e , bool captureSegment );
195  bool canvasMoveEvent( QgsMapMouseEvent* e );
202  bool canvasKeyPressEventFilter( QKeyEvent *e );
203 
206  virtual bool applyConstraints( QgsMapMouseEvent* e );
207 
211  void clear();
212 
217  QgsMapMouseEvent::SnappingMode snappingMode() { return mSnappingMode; }
218 
220  void keyPressEvent( QKeyEvent* e ) override;
221 
223  bool cadEnabled() const { return mCadEnabled; }
224 
226  bool constructionMode() const { return mConstructionMode; }
227 
229  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
231  const CadConstraint* constraintAngle() const { return mAngleConstraint; }
233  const CadConstraint* constraintDistance() const { return mDistanceConstraint; }
235  const CadConstraint* constraintX() const { return mXConstraint; }
237  const CadConstraint* constraintY() const { return mYConstraint; }
239  bool commonAngleConstraint() const { return mCommonAngleConstraint; }
240 
246  QgsPoint currentPoint( bool* exists = nullptr ) const;
247 
253  QgsPoint previousPoint( bool* exists = nullptr ) const;
254 
260  QgsPoint penultimatePoint( bool* exists = nullptr ) const;
261 
265  inline int pointsCount() const { return mCadPointList.count(); }
266 
270  inline bool snappedToVertex() const { return mSnappedToVertex; }
271 
275  const QList<QgsPoint>& snappedSegment() const { return mSnappedSegment; }
276 
278  QAction* enableAction() { return mEnableAction; }
279 
286  void enable();
287 
291  void disable();
292 
293  signals:
299  void pushWarning( const QString& message );
300 
304  void popWarning();
305 
312  void pointChanged( const QgsPoint& point );
313 
314  private slots:
316  void addtionalConstraintClicked( bool activated );
317 
319  void lockConstraint( bool activate = true );
320 
322  void releaseLocks();
323 
325  void setConstraintRelative( bool activate );
326 
329  void activateCad( bool enabled );
330 
332  void setConstructionMode( bool enabled );
333 
335  void settingsButtonTriggered( QAction* action );
336 
337  private:
339  void setCadEnabled( bool enabled );
340 
345  void updateCapacity( bool updateUIwithoutChange = false );
346 
348  void lockAdditionalConstraint( AdditionalConstraint constraint );
349 
350  QList<QgsPoint> snapSegment( const QgsPointLocator::Match& snapMatch );
351 
354  bool alignToSegment( QgsMapMouseEvent* e, CadConstraint::LockMode lockMode = CadConstraint::HardLock );
355 
357  void addPoint( const QgsPoint& point );
359  void updateCurrentPoint( const QgsPoint& point );
361  void removePreviousPoint();
363  void clearPoints();
364 
367  bool filterKeyPress( QKeyEvent* e );
368 
370  bool eventFilter( QObject *obj, QEvent *event ) override;
371 
373  void triggerMouseMoveEvent();
374 
375 
376 
377  QgsMapCanvas* mMapCanvas;
378  QgsAdvancedDigitizingCanvasItem* mCadPaintItem;
379 
380  CadCapacities mCapacities;
381 
382  bool mCurrentMapToolSupportsCad;
383 
384  // CAD properties
386  bool mCadEnabled;
387  bool mConstructionMode;
388  QgsMapMouseEvent::SnappingMode mSnappingMode;
389 
390  // constraints
391  CadConstraint* mAngleConstraint;
392  CadConstraint* mDistanceConstraint;
393  CadConstraint* mXConstraint;
394  CadConstraint* mYConstraint;
395  AdditionalConstraint mAdditionalConstraint;
396  int mCommonAngleConstraint; // if 0: do not snap to common angles
397 
398  // point list and current snap point / segment
399  QList<QgsPoint> mCadPointList;
400  QList<QgsPoint> mSnappedSegment;
401  bool mSnappedToVertex;
402 
403  bool mSessionActive;
404 
405  // error message
406  QScopedPointer<QgsMessageBarItem> mErrorMessage;
407 
408  // UI
409  QAction* mEnableAction;
410  QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values
411  QMap< QAction*, QgsMapMouseEvent::SnappingMode > mSnappingActions; // map the snapping mode actions with their values
412 };
413 
414 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
415 
416 #endif // QGSADVANCEDDIGITIZINGDOCK_H
int pointsCount() const
The number of points in the CAD point helper list.
bool constructionMode() const
construction mode is used to draw intermediate points. These points won&#39;t be given any further (i...
bool cadEnabled() const
determines if CAD tools are enabled or if map tools behaves "nomally"
const QList< QgsPoint > & snappedSegment() const
Snapped to a segment.
The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
static const double SoftConstraintToleranceDegrees
QgsMapMouseEvent::SnappingMode snappingMode()
The snapping mode.
const CadConstraint * constraintY() const
Constraint on the Y coordinate.
CadCapacity
The CadCapacity enum defines the possible constraints to be set depending on the number of points in ...
QAction * enableAction()
return the action used to enable/disable the tools
const CadConstraint * constraintAngle() const
Constraint on the angle.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool whcih gives event directly in map coordinates ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
LockMode lockMode() const
The current lock mode of this constraint.
CadConstraint(QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton=nullptr)
double value() const
The value of the constraint.
bool isLocked() const
Is any kind of lock mode enabled.
const CadConstraint * constraintX() const
Constraint on the X coordinate.
AdditionalConstraint additionalConstraint() const
Additional constraints are used to place perpendicular/parallel segments to snapped segments on the c...
A class to represent a point.
Definition: qgspoint.h:65
Abstract base class for all map tools.
Definition: qgsmaptool.h:50
const CadConstraint * constraintDistance() const
Constraint on the distance.
bool relative() const
Is the constraint in relative mode.
QLineEdit * lineEdit() const
The line edit that manages the value of the constraint.
bool commonAngleConstraint() const
Constraint on a common angle.
bool snappedToVertex() const
Is it snapped to a vertex.
static const double SoftConstraintTolerancePixel
The QgsAdvancedDigitizingDock class is a dockable widget used to handle the CAD tools on top of a sel...
AdditionalConstraint
Additional constraints which can be enabled.
The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (...