QGIS API Documentation  3.0.2-Girona (307d082)
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 #include "qgis_gui.h"
25 #include "qgis.h"
26 #include <memory>
27 
28 
30 class QgsMapCanvas;
31 class QgsMapTool;
33 class QgsPointXY;
34 
42 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
43 {
44  Q_OBJECT
45 
46  public:
47 
54  {
55  AbsoluteAngle = 1,
56  RelativeAngle = 2,
57  RelativeCoordinates = 4,
58  };
59  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
60  Q_FLAG( CadCapacities )
61 
62 
66  {
69  Parallel
70  };
71 
78  class GUI_EXPORT CadConstraint
79  {
80  public:
81 
85  enum LockMode
86  {
89  HardLock
90  };
91 
99  CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
100  : mLineEdit( lineEdit )
101  , mLockerButton( lockerButton )
102  , mRelativeButton( relativeButton )
103  , mRepeatingLockButton( repeatingLockButton )
104  , mLockMode( NoLock )
105  , mRepeatingLock( false )
106  , mRelative( false )
107  , mValue( 0.0 )
108  {}
109 
114  LockMode lockMode() const { return mLockMode; }
115 
119  bool isLocked() const { return mLockMode != NoLock; }
120 
127  bool isRepeatingLock() const { return mRepeatingLock; }
128 
132  bool relative() const { return mRelative; }
133 
137  double value() const { return mValue; }
138 
142  QLineEdit *lineEdit() const { return mLineEdit; }
143 
147  void setLockMode( LockMode mode );
148 
156  void setRepeatingLock( bool repeating );
157 
161  void setRelative( bool relative );
162 
168  void setValue( double value, bool updateWidget = true );
169 
173  void toggleLocked();
174 
178  void toggleRelative();
179 
180  private:
181  QLineEdit *mLineEdit = nullptr;
182  QToolButton *mLockerButton = nullptr;
183  QToolButton *mRelativeButton = nullptr;
184  QToolButton *mRepeatingLockButton = nullptr;
185  LockMode mLockMode;
186  bool mRepeatingLock;
187  bool mRelative;
188  double mValue;
189  };
190 
196  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
197 
201  void hideEvent( QHideEvent * ) override;
202 
209  bool canvasKeyPressEventFilter( QKeyEvent *e );
210 
215  bool applyConstraints( QgsMapMouseEvent *e );
216 
223 
229  void releaseLocks( bool releaseRepeatingLocks = true );
230 
234  void clear();
235 
236  void keyPressEvent( QKeyEvent *e ) override;
237 
239  bool cadEnabled() const { return mCadEnabled; }
240 
242  bool constructionMode() const { return mConstructionMode; }
243 
245  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
247  const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
249  const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
251  const CadConstraint *constraintX() const { return mXConstraint.get(); }
253  const CadConstraint *constraintY() const { return mYConstraint.get(); }
255  bool commonAngleConstraint() const { return mCommonAngleConstraint; }
256 
261  void clearPoints();
262 
267  void addPoint( const QgsPointXY &point );
268 
276  void setPoints( const QList<QgsPointXY> &points );
277 
283  QgsPointXY currentPoint( bool *exists = nullptr ) const;
284 
290  QgsPointXY previousPoint( bool *exists = nullptr ) const;
291 
297  QgsPointXY penultimatePoint( bool *exists = nullptr ) const;
298 
302  inline int pointsCount() const { return mCadPointList.count(); }
303 
307  inline bool snappedToVertex() const { return mSnappedToVertex; }
308 
312  QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
313 
315  QAction *enableAction() { return mEnableAction; }
316 
323  void enable();
324 
328  void disable();
329 
334  void updateCadPaintItem();
335 
336  signals:
337 
343  void pushWarning( const QString &message );
344 
348  void popWarning();
349 
356  void pointChanged( const QgsPointXY &point );
357 
358  private slots:
360  void additionalConstraintClicked( bool activated );
361 
363  void lockConstraint( bool activate = true );
364 
369  void constraintTextEdited( const QString &textValue );
370 
375  void constraintFocusOut();
376 
378  void setConstraintRelative( bool activate );
379 
381  void setConstraintRepeatingLock( bool activate );
382 
387  void activateCad( bool enabled );
388 
390  void setConstructionMode( bool enabled );
391 
393  void settingsButtonTriggered( QAction *action );
394 
395  private:
397  void setCadEnabled( bool enabled );
398 
403  void updateCapacity( bool updateUIwithoutChange = false );
404 
406  void lockAdditionalConstraint( AdditionalConstraint constraint );
407 
413  QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
414 
416  void updateCurrentPoint( const QgsPointXY &point );
418  void removePreviousPoint();
419 
424  bool filterKeyPress( QKeyEvent *e );
425 
430  bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
431 
433  void triggerMouseMoveEvent();
434 
436  CadConstraint *objectToConstraint( const QObject *obj ) const;
437 
439  double parseUserInput( const QString &inputValue, bool &ok ) const;
440 
447  void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
448 
450  void updateUnlockedConstraintValues( const QgsPointXY &point );
451 
452  QgsMapCanvas *mMapCanvas = nullptr;
453  QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
454 
455  CadCapacities mCapacities;
456 
457  bool mCurrentMapToolSupportsCad;
458 
459  // CAD properties
461  bool mCadEnabled;
462  bool mConstructionMode;
463 
464  // constraints
465  std::unique_ptr< CadConstraint > mAngleConstraint;
466  std::unique_ptr< CadConstraint > mDistanceConstraint;
467  std::unique_ptr< CadConstraint > mXConstraint;
468  std::unique_ptr< CadConstraint > mYConstraint;
469  AdditionalConstraint mAdditionalConstraint;
470  int mCommonAngleConstraint; // if 0: do not snap to common angles
471 
472  // point list and current snap point / segment
473  QList<QgsPointXY> mCadPointList;
474  QList<QgsPointXY> mSnappedSegment;
475  bool mSnappedToVertex;
476 
477  bool mSessionActive;
478 
479  // error message
480  std::unique_ptr<QgsMessageBarItem> mErrorMessage;
481 
482  // UI
483  QAction *mEnableAction = nullptr;
484  QMap< QAction *, int > mCommonAngleActions; // map the common angle actions with their angle values
485 
486  private:
487 #ifdef SIP_RUN
488  bool eventFilter( QObject *obj, QEvent *event );
490 #endif
491 };
492 
493 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
494 
495 #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
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 class to represent a 2D point.
Definition: qgspointxy.h:43
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
Constraint on the X coordinate.
AdditionalConstraint additionalConstraint() const
Additional constraints are used to place perpendicular/parallel segments to snapped segments on the c...
Abstract base class for all map tools.
Definition: qgsmaptool.h:63
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.
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 (...