QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsadvanceddigitizingdockwidget.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsadvanceddigitizingdockwidget.h - dock for CAD tools
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 #ifndef QGSADVANCEDDIGITIZINGDOCK
17 #define QGSADVANCEDDIGITIZINGDOCK
18 
19 #include "qgsdockwidget.h"
20 #include "qgsmapmouseevent.h"
21 #include "qgsmessagebaritem.h"
22 
23 #include <ui_qgsadvanceddigitizingdockwidgetbase.h>
24 
25 
27 class QgsMapCanvas;
28 class QgsMapTool;
30 class QgsPoint;
31 
32 // tolerances for soft constraints (last values, and common angles)
33 // for angles, both tolerance in pixels and degrees are used for better performance
34 static const double SoftConstraintTolerancePixel = 15;
35 static const double SoftConstraintToleranceDegrees = 10;
36 
43 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
44 {
45  Q_OBJECT
46  Q_FLAGS( CadCapacities )
47 
48  public:
49 
56  {
57  AbsoluteAngle = 1,
58  RelativeAngle = 2,
59  RelativeCoordinates = 4,
60  };
61  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
62 
63 
67  {
70  Parallel
71  };
72 
78  class GUI_EXPORT CadConstraint
79  {
80  public:
84  enum LockMode
85  {
88  HardLock
89  };
90 
97  CadConstraint( QLineEdit* lineEdit, QToolButton* lockerButton, QToolButton* relativeButton = nullptr, QToolButton* repeatingLockButton = nullptr )
98  : mLineEdit( lineEdit )
99  , mLockerButton( lockerButton )
100  , mRelativeButton( relativeButton )
101  , mRepeatingLockButton( repeatingLockButton )
102  , mLockMode( NoLock )
103  , mRepeatingLock( false )
104  , mRelative( false )
105  , mValue( 0.0 )
106  {}
107 
112  LockMode lockMode() const { return mLockMode; }
116  bool isLocked() const { return mLockMode != NoLock; }
117 
123  bool isRepeatingLock() const { return mRepeatingLock; }
124 
128  bool relative() const { return mRelative; }
132  double value() const { return mValue; }
133 
137  QLineEdit* lineEdit() const { return mLineEdit; }
138 
142  void setLockMode( LockMode mode );
143 
150  void setRepeatingLock( bool repeating );
151 
155  void setRelative( bool relative );
156 
162  void setValue( double value, bool updateWidget = true );
163 
167  void toggleLocked();
168 
172  void toggleRelative();
173 
174  private:
175  QLineEdit* mLineEdit;
176  QToolButton* mLockerButton;
177  QToolButton* mRelativeButton;
178  QToolButton* mRepeatingLockButton;
179  LockMode mLockMode;
180  bool mRepeatingLock;
181  bool mRelative;
182  double mValue;
183  };
184 
187  static bool lineCircleIntersection( const QgsPoint& center, const double radius, const QList<QgsPoint>& segment, QgsPoint& intersection );
188 
194  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas* canvas, QWidget *parent = nullptr );
195 
199  void hideEvent( QHideEvent* ) override;
200 
207  bool canvasPressEvent( QgsMapMouseEvent* e );
215  bool canvasReleaseEvent( QgsMapMouseEvent* e , bool captureSegment );
222  bool canvasMoveEvent( QgsMapMouseEvent* e );
229  bool canvasKeyPressEventFilter( QKeyEvent *e );
230 
233  virtual bool applyConstraints( QgsMapMouseEvent* e );
234 
238  void clear();
239 
244  QgsMapMouseEvent::SnappingMode snappingMode() { return mSnappingMode; }
245 
247  void keyPressEvent( QKeyEvent* e ) override;
248 
250  bool cadEnabled() const { return mCadEnabled; }
251 
253  bool constructionMode() const { return mConstructionMode; }
254 
256  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
258  const CadConstraint* constraintAngle() const { return mAngleConstraint.data(); }
260  const CadConstraint* constraintDistance() const { return mDistanceConstraint.data(); }
262  const CadConstraint* constraintX() const { return mXConstraint.data(); }
264  const CadConstraint* constraintY() const { return mYConstraint.data(); }
266  bool commonAngleConstraint() const { return mCommonAngleConstraint; }
267 
273  QgsPoint currentPoint( bool* exists = nullptr ) const;
274 
280  QgsPoint previousPoint( bool* exists = nullptr ) const;
281 
287  QgsPoint penultimatePoint( bool* exists = nullptr ) const;
288 
292  inline int pointsCount() const { return mCadPointList.count(); }
293 
297  inline bool snappedToVertex() const { return mSnappedToVertex; }
298 
302  const QList<QgsPoint>& snappedSegment() const { return mSnappedSegment; }
303 
305  QAction* enableAction() { return mEnableAction; }
306 
313  void enable();
314 
318  void disable();
319 
320  signals:
326  void pushWarning( const QString& message );
327 
331  void popWarning();
332 
339  void pointChanged( const QgsPoint& point );
340 
341  private slots:
343  void addtionalConstraintClicked( bool activated );
344 
346  void lockConstraint( bool activate = true );
347 
350  void constraintTextEdited( const QString& textValue );
351 
354  void constraintFocusOut();
355 
358  void releaseLocks( bool releaseRepeatingLocks = true );
359 
361  void setConstraintRelative( bool activate );
362 
364  void setConstraintRepeatingLock( bool activate );
365 
368  void activateCad( bool enabled );
369 
371  void setConstructionMode( bool enabled );
372 
374  void settingsButtonTriggered( QAction* action );
375 
376  private:
378  void setCadEnabled( bool enabled );
379 
384  void updateCapacity( bool updateUIwithoutChange = false );
385 
387  void lockAdditionalConstraint( AdditionalConstraint constraint );
388 
389  QList<QgsPoint> snapSegment( const QgsPointLocator::Match& snapMatch );
390 
393  bool alignToSegment( QgsMapMouseEvent* e, CadConstraint::LockMode lockMode = CadConstraint::HardLock );
394 
396  void addPoint( const QgsPoint& point );
398  void updateCurrentPoint( const QgsPoint& point );
400  void removePreviousPoint();
402  void clearPoints();
403 
406  bool filterKeyPress( QKeyEvent* e );
407 
409  bool eventFilter( QObject *obj, QEvent *event ) override;
410 
412  void triggerMouseMoveEvent();
413 
415  CadConstraint* objectToConstraint( const QObject* obj ) const;
416 
418  double parseUserInput( const QString& inputValue, bool& ok ) const;
419 
425  void updateConstraintValue( CadConstraint* constraint, const QString& textValue, bool convertExpression = false );
426 
427  QgsMapCanvas* mMapCanvas;
428  QgsAdvancedDigitizingCanvasItem* mCadPaintItem;
429 
430  CadCapacities mCapacities;
431 
432  bool mCurrentMapToolSupportsCad;
433 
434  // CAD properties
436  bool mCadEnabled;
437  bool mConstructionMode;
438  QgsMapMouseEvent::SnappingMode mSnappingMode;
439 
440  // constraints
441  QScopedPointer< CadConstraint > mAngleConstraint;
442  QScopedPointer< CadConstraint > mDistanceConstraint;
443  QScopedPointer< CadConstraint > mXConstraint;
444  QScopedPointer< CadConstraint > mYConstraint;
445  AdditionalConstraint mAdditionalConstraint;
446  int mCommonAngleConstraint; // if 0: do not snap to common angles
447 
448  // point list and current snap point / segment
449  QList<QgsPoint> mCadPointList;
450  QList<QgsPoint> mSnappedSegment;
451  bool mSnappedToVertex;
452 
453  bool mSessionActive;
454 
455  // error message
456  QScopedPointer<QgsMessageBarItem> mErrorMessage;
457 
458  // UI
459  QAction* mEnableAction;
460  QMap< QAction*, int > mCommonAngleActions; // map the common angle actions with their angle values
461  QMap< QAction*, QgsMapMouseEvent::SnappingMode > mSnappingActions; // map the snapping mode actions with their values
462 
463 };
464 
465 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
466 
467 #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.
CadConstraint(QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton=nullptr, QToolButton *repeatingLockButton=nullptr)
Constructor for CadConstraint.
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:109
LockMode lockMode() const
The current lock mode of this constraint.
double value() const
The value of the constraint.
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened...
Definition: qgsdockwidget.h:28
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:117
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 isRepeatingLock() const
Returns true if a repeating lock is set for the constraint.
bool snappedToVertex() const
Is it snapped to a vertex.
static const double SoftConstraintTolerancePixel
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
AdditionalConstraint
Additional constraints which can be enabled.
The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (...