QGIS API Documentation  3.4.3-Madeira (2f64a3c)
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 : 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 <QList>
20 
21 #include <memory>
22 
23 #include "ui_qgsadvanceddigitizingdockwidgetbase.h"
24 #include "qgis_gui.h"
25 #include "qgis.h"
26 #include "qgsdockwidget.h"
27 #include "qgsmessagebaritem.h"
28 #include "qgspointxy.h"
29 #include "qgspointlocator.h"
30 
31 
33 class QgsMapCanvas;
34 class QgsMapTool;
36 class QgsMapMouseEvent;
37 
45 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
46 {
47  Q_OBJECT
48 
49  public:
50 
57  {
58  AbsoluteAngle = 1,
59  RelativeAngle = 2,
60  RelativeCoordinates = 4,
61  };
62  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
63  Q_FLAG( CadCapacities )
64 
65 
69  {
72  Parallel
73  };
74 
81  class GUI_EXPORT CadConstraint
82  {
83  public:
84 
88  enum LockMode
89  {
92  HardLock
93  };
94 
102  CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
103  : mLineEdit( lineEdit )
104  , mLockerButton( lockerButton )
105  , mRelativeButton( relativeButton )
106  , mRepeatingLockButton( repeatingLockButton )
107  , mLockMode( NoLock )
108  , mRepeatingLock( false )
109  , mRelative( false )
110  , mValue( 0.0 )
111  {}
112 
117  LockMode lockMode() const { return mLockMode; }
118 
122  bool isLocked() const { return mLockMode != NoLock; }
123 
130  bool isRepeatingLock() const { return mRepeatingLock; }
131 
135  bool relative() const { return mRelative; }
136 
140  double value() const { return mValue; }
141 
145  QLineEdit *lineEdit() const { return mLineEdit; }
146 
150  void setLockMode( LockMode mode );
151 
159  void setRepeatingLock( bool repeating );
160 
164  void setRelative( bool relative );
165 
171  void setValue( double value, bool updateWidget = true );
172 
176  void toggleLocked();
177 
181  void toggleRelative();
182 
183  private:
184  QLineEdit *mLineEdit = nullptr;
185  QToolButton *mLockerButton = nullptr;
186  QToolButton *mRelativeButton = nullptr;
187  QToolButton *mRepeatingLockButton = nullptr;
188  LockMode mLockMode;
189  bool mRepeatingLock;
190  bool mRelative;
191  double mValue;
192  };
193 
199  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
200 
204  void hideEvent( QHideEvent * ) override;
205 
212  bool canvasKeyPressEventFilter( QKeyEvent *e );
213 
218  bool applyConstraints( QgsMapMouseEvent *e );
219 
226 
232  void releaseLocks( bool releaseRepeatingLocks = true );
233 
237  void clear();
238 
239  void keyPressEvent( QKeyEvent *e ) override;
240 
242  bool cadEnabled() const { return mCadEnabled; }
243 
245  bool constructionMode() const { return mConstructionMode; }
246 
251  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
253  const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
255  const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
257  const CadConstraint *constraintX() const { return mXConstraint.get(); }
259  const CadConstraint *constraintY() const { return mYConstraint.get(); }
261  bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
262 
267  QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
268 
273  void clearPoints();
274 
279  void addPoint( const QgsPointXY &point );
280 
288  void setPoints( const QList<QgsPointXY> &points );
289 
295  QgsPointXY currentPoint( bool *exists = nullptr ) const;
296 
302  QgsPointXY previousPoint( bool *exists = nullptr ) const;
303 
309  QgsPointXY penultimatePoint( bool *exists = nullptr ) const;
310 
314  inline int pointsCount() const { return mCadPointList.count(); }
315 
319  inline bool snappedToVertex() const { return mSnappedToVertex; }
320 
324  QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
325 
327  QAction *enableAction() { return mEnableAction; }
328 
335  void enable();
336 
340  void disable();
341 
346  void updateCadPaintItem();
347 
348  signals:
349 
355  void pushWarning( const QString &message );
356 
360  void popWarning();
361 
368  void pointChanged( const QgsPointXY &point );
369 
370  private slots:
372  void additionalConstraintClicked( bool activated );
373 
375  void lockConstraint( bool activate = true );
376 
381  void constraintTextEdited( const QString &textValue );
382 
387  void constraintFocusOut();
388 
390  void setConstraintRelative( bool activate );
391 
393  void setConstraintRepeatingLock( bool activate );
394 
399  void activateCad( bool enabled );
400 
402  void setConstructionMode( bool enabled );
403 
405  void settingsButtonTriggered( QAction *action );
406 
407  private:
409  void setCadEnabled( bool enabled );
410 
415  void updateCapacity( bool updateUIwithoutChange = false );
416 
418  void lockAdditionalConstraint( AdditionalConstraint constraint );
419 
425  QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
426 
428  void updateCurrentPoint( const QgsPointXY &point );
430  void removePreviousPoint();
431 
436  bool filterKeyPress( QKeyEvent *e );
437 
442  bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
443 
445  void triggerMouseMoveEvent();
446 
448  CadConstraint *objectToConstraint( const QObject *obj ) const;
449 
451  double parseUserInput( const QString &inputValue, bool &ok ) const;
452 
459  void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
460 
462  void updateUnlockedConstraintValues( const QgsPointXY &point );
463 
464  QgsMapCanvas *mMapCanvas = nullptr;
465  QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
466 
467  CadCapacities mCapacities = nullptr;
468 
469  bool mCurrentMapToolSupportsCad = false;
470 
471  // CAD properties
473  bool mCadEnabled = false;
474  bool mConstructionMode = false;
475 
476  // constraints
477  std::unique_ptr< CadConstraint > mAngleConstraint;
478  std::unique_ptr< CadConstraint > mDistanceConstraint;
479  std::unique_ptr< CadConstraint > mXConstraint;
480  std::unique_ptr< CadConstraint > mYConstraint;
481  AdditionalConstraint mAdditionalConstraint;
482  double mCommonAngleConstraint; // if 0: do not snap to common angles
483 
484  // point list and current snap point / segment
485  QList<QgsPointXY> mCadPointList;
486  QList<QgsPointXY> mSnappedSegment;
487  bool mSnappedToVertex = false;
488 
489  bool mSessionActive = false;
490 
491  // error message
492  std::unique_ptr<QgsMessageBarItem> mErrorMessage;
493 
494  // UI
495  QAction *mEnableAction = nullptr;
496  QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values
497 
498  // Snap indicator
499 
500  QgsPointLocator::Match mSnapMatch;
501  private:
502 #ifdef SIP_RUN
503  bool eventFilter( QObject *obj, QEvent *event );
505 #endif
506 };
507 
508 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
509 
510 #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"
The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
const CadConstraint * constraintY() const
Returns the CadConstraint on the Y coordinate.
QgsPointLocator::Match mapPointMatch() const
Returns the point locator match.
CadCapacity
The CadCapacity enum defines the possible constraints to be set depending on the number of points in ...
QAction * enableAction()
Returns the action used to enable/disable the tools.
const CadConstraint * constraintAngle() const
Returns the CadConstraint on the angle.
A class to represent a 2D point.
Definition: qgspointxy.h:43
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:278
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 which gives event directly in map coordinates ...
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
LockMode lockMode() const
The current lock mode of this constraint.
QList< QgsPointXY > snappedSegment() const
Snapped to a segment.
double value() const
The value of the constraint.
#define SIP_SKIP
Definition: qgis_sip.h:119
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened...
Definition: qgsdockwidget.h:31
bool isLocked() const
Is any kind of lock mode enabled.
const CadConstraint * constraintX() const
Returns the CadConstraint on the X coordinate.
AdditionalConstraint additionalConstraint() const
Returns the additional constraints which are used to place perpendicular/parallel segments to snapped...
Abstract base class for all map tools.
Definition: qgsmaptool.h:62
const CadConstraint * constraintDistance() const
Returns the CadConstraint 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
Returns true if a constraint on a common angle is active.
bool isRepeatingLock() const
Returns true if a repeating lock is set for the constraint.
bool snappedToVertex() const
Is it snapped to a vertex.
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 (...