QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 <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 #include "qgssnapindicator.h"
31 
32 
34 class QgsMapCanvas;
35 class QgsMapTool;
37 class QgsMapMouseEvent;
38 
46 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
47 {
48  Q_OBJECT
49 
50  public:
51 
58  {
59  AbsoluteAngle = 1,
60  RelativeAngle = 2,
61  RelativeCoordinates = 4,
62  };
63  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
64  Q_FLAG( CadCapacities )
65 
70  {
73  Parallel
74  };
75 
82  class GUI_EXPORT CadConstraint
83  {
84  public:
85 
89  enum LockMode
90  {
93  HardLock
94  };
95 
103  CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
104  : mLineEdit( lineEdit )
105  , mLockerButton( lockerButton )
106  , mRelativeButton( relativeButton )
107  , mRepeatingLockButton( repeatingLockButton )
108  , mLockMode( NoLock )
109  , mRepeatingLock( false )
110  , mRelative( false )
111  , mValue( 0.0 )
112  {}
113 
118  LockMode lockMode() const { return mLockMode; }
119 
123  bool isLocked() const { return mLockMode != NoLock; }
124 
131  bool isRepeatingLock() const { return mRepeatingLock; }
132 
136  bool relative() const { return mRelative; }
137 
141  double value() const { return mValue; }
142 
146  QLineEdit *lineEdit() const { return mLineEdit; }
147 
151  void setLockMode( LockMode mode );
152 
160  void setRepeatingLock( bool repeating );
161 
165  void setRelative( bool relative );
166 
172  void setValue( double value, bool updateWidget = true );
173 
177  void toggleLocked();
178 
182  void toggleRelative();
183 
184  private:
185  QLineEdit *mLineEdit = nullptr;
186  QToolButton *mLockerButton = nullptr;
187  QToolButton *mRelativeButton = nullptr;
188  QToolButton *mRepeatingLockButton = nullptr;
189  LockMode mLockMode;
190  bool mRepeatingLock;
191  bool mRelative;
192  double mValue;
193  };
194 
200  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
201 
205  void hideEvent( QHideEvent * ) override;
206 
213  bool canvasKeyPressEventFilter( QKeyEvent *e );
214 
219  bool applyConstraints( QgsMapMouseEvent *e );
220 
227 
233  void releaseLocks( bool releaseRepeatingLocks = true );
234 
238  void clear();
239 
240  void keyPressEvent( QKeyEvent *e ) override;
241 
243  bool cadEnabled() const { return mCadEnabled; }
244 
246  bool constructionMode() const { return mConstructionMode; }
247 
252  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
254  const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
256  const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
258  const CadConstraint *constraintX() const { return mXConstraint.get(); }
260  const CadConstraint *constraintY() const { return mYConstraint.get(); }
262  bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
263 
268  QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
269 
274  void clearPoints();
275 
280  void addPoint( const QgsPointXY &point );
281 
286  void removePreviousPoint();
287 
295  void setPoints( const QList<QgsPointXY> &points );
296 
302  QgsPointXY currentPoint( bool *exists = nullptr ) const;
303 
309  QgsPointXY previousPoint( bool *exists = nullptr ) const;
310 
316  QgsPointXY penultimatePoint( bool *exists = nullptr ) const;
317 
321  inline int pointsCount() const { return mCadPointList.count(); }
322 
326  inline bool snappedToVertex() const { return ( mSnapMatch.isValid() && mSnapMatch.hasVertex() ); }
327 
331  QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
332 
334  QAction *enableAction() { return mEnableAction; }
335 
342  void enable();
343 
347  void disable();
348 
353  void updateCadPaintItem();
354 
355  signals:
356 
362  void pushWarning( const QString &message );
363 
367  void popWarning();
368 
375  void pointChanged( const QgsPointXY &point );
376 
377  private slots:
379  void additionalConstraintClicked( bool activated );
380 
382  void lockConstraint( bool activate = true );
383 
388  void constraintTextEdited( const QString &textValue );
389 
394  void constraintFocusOut();
395 
397  void setConstraintRelative( bool activate );
398 
400  void setConstraintRepeatingLock( bool activate );
401 
406  void activateCad( bool enabled );
407 
409  void setConstructionMode( bool enabled );
410 
412  void settingsButtonTriggered( QAction *action );
413 
414  private:
416  void setCadEnabled( bool enabled );
417 
422  void updateCapacity( bool updateUIwithoutChange = false );
423 
425  void lockAdditionalConstraint( AdditionalConstraint constraint );
426 
432  QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
433 
435  void updateCurrentPoint( const QgsPointXY &point );
436 
437 
442  bool filterKeyPress( QKeyEvent *e );
443 
448  bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
449 
451  void triggerMouseMoveEvent();
452 
454  CadConstraint *objectToConstraint( const QObject *obj ) const;
455 
457  double parseUserInput( const QString &inputValue, bool &ok ) const;
458 
465  void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
466 
468  void updateUnlockedConstraintValues( const QgsPointXY &point );
469 
470  QgsMapCanvas *mMapCanvas = nullptr;
471  QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
473  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
474 
475  CadCapacities mCapacities = nullptr;
476 
477  bool mCurrentMapToolSupportsCad = false;
478 
479  // CAD properties
481  bool mCadEnabled = false;
482  bool mConstructionMode = false;
483 
484  // constraints
485  std::unique_ptr< CadConstraint > mAngleConstraint;
486  std::unique_ptr< CadConstraint > mDistanceConstraint;
487  std::unique_ptr< CadConstraint > mXConstraint;
488  std::unique_ptr< CadConstraint > mYConstraint;
489  AdditionalConstraint mAdditionalConstraint;
490  double mCommonAngleConstraint; // if 0: do not snap to common angles
491 
492  // point list and current snap point / segment
493  QList<QgsPointXY> mCadPointList;
494  QList<QgsPointXY> mSnappedSegment;
495 
496  bool mSessionActive = false;
497 
498  // error message
499  std::unique_ptr<QgsMessageBarItem> mErrorMessage;
500 
501  // UI
502  QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values
503 
504  // Snap indicator
505 
506  QgsPointLocator::Match mSnapMatch;
507  private:
508 #ifdef SIP_RUN
509  bool eventFilter( QObject *obj, QEvent *event );
511 #endif
512 };
513 
514 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
515 
516 #endif // QGSADVANCEDDIGITIZINGDOCK_H
bool isLocked() const
Is any kind of lock mode enabled.
The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
LockMode lockMode() const
The current lock mode of this constraint.
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.
bool relative() const
Is the constraint in relative mode.
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 ...
bool commonAngleConstraint() const
Returns true if a constraint on a common angle is active.
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:74
int pointsCount() const
The number of points in the CAD point helper list.
const CadConstraint * constraintDistance() const
Returns the CadConstraint on the distance.
QLineEdit * lineEdit() const
The line edit that manages the value of the constraint.
#define SIP_SKIP
Definition: qgis_sip.h:119
bool snappedToVertex() const
Is it snapped to a vertex.
const CadConstraint * constraintY() const
Returns the CadConstraint on the Y coordinate.
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened...
Definition: qgsdockwidget.h:31
bool isRepeatingLock() const
Returns true if a repeating lock is set for the constraint.
AdditionalConstraint additionalConstraint() const
Returns the additional constraints which are used to place perpendicular/parallel segments to snapped...
QgsPointLocator::Match mapPointMatch() const
Returns the point locator match.
Abstract base class for all map tools.
Definition: qgsmaptool.h:62
const CadConstraint * constraintX() const
Returns the CadConstraint on the X coordinate.
QList< QgsPointXY > snappedSegment() const
Snapped to a segment.
bool constructionMode() const
construction mode is used to draw intermediate points. These points won&#39;t be given any further (i...
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
const CadConstraint * constraintAngle() const
Returns the CadConstraint on the angle.
AdditionalConstraint
Additional constraints which can be enabled.
double value() const
The value of the constraint.
The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (...
bool cadEnabled() const
determines if CAD tools are enabled or if map tools behaves "nomally"