QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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"
25 #include "qgis_gui.h"
26 #include "qgis_sip.h"
27 #include "qgsdockwidget.h"
28 #include "qgsmessagebaritem.h"
29 #include "qgspointxy.h"
30 #include "qgspointlocator.h"
31 #include "qgssnapindicator.h"
32 
33 
36 class QgsMapCanvas;
37 class QgsMapTool;
39 class QgsMapMouseEvent;
40 
48 class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
49 {
50  Q_OBJECT
51 
52  public:
53 
60  {
61  AbsoluteAngle = 1,
62  RelativeAngle = 2,
63  RelativeCoordinates = 4,
64  Distance = 8,
65  };
66  Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
67  Q_FLAG( CadCapacities )
68 
69 
73  {
74  NoConstraint,
75  Perpendicular,
76  Parallel
77  };
78 
85  {
86  ReturnPressed, FocusOut, TextEdited
87  };
88 
89 
96  class GUI_EXPORT CadConstraint
97  {
98  public:
99 
103  enum LockMode
104  {
107  HardLock
108  };
109 
117  CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
118  : mLineEdit( lineEdit )
119  , mLockerButton( lockerButton )
120  , mRelativeButton( relativeButton )
121  , mRepeatingLockButton( repeatingLockButton )
122  , mLockMode( NoLock )
123  , mRepeatingLock( false )
124  , mRelative( false )
125  , mValue( 0.0 )
126  {}
127 
132  LockMode lockMode() const { return mLockMode; }
133 
137  bool isLocked() const { return mLockMode != NoLock; }
138 
145  bool isRepeatingLock() const { return mRepeatingLock; }
146 
150  bool relative() const { return mRelative; }
151 
155  double value() const { return mValue; }
156 
160  QLineEdit *lineEdit() const { return mLineEdit; }
161 
165  void setLockMode( LockMode mode );
166 
174  void setRepeatingLock( bool repeating );
175 
179  void setRelative( bool relative );
180 
186  void setValue( double value, bool updateWidget = true );
187 
191  void toggleLocked();
192 
196  void toggleRelative();
197 
204  int precision() const { return mPrecision; }
205 
212  void setPrecision( int precision );
213 
214  private:
215  QLineEdit *mLineEdit = nullptr;
216  QToolButton *mLockerButton = nullptr;
217  QToolButton *mRelativeButton = nullptr;
218  QToolButton *mRepeatingLockButton = nullptr;
219  LockMode mLockMode;
220  bool mRepeatingLock;
221  bool mRelative;
222  double mValue;
223  int mPrecision = 6;
224  };
225 
231  explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
232 
239  bool canvasKeyPressEventFilter( QKeyEvent *e );
240 
245  bool applyConstraints( QgsMapMouseEvent *e );
246 
253 
259  void releaseLocks( bool releaseRepeatingLocks = true );
260 
264  void clear();
265 
266  void keyPressEvent( QKeyEvent *e ) override;
267 
269  bool cadEnabled() const { return mCadEnabled; }
270 
275  void switchZM( );
276 
281  void setEnabledZ( bool enable );
282 
287  void setEnabledM( bool enable );
288 
290  bool constructionMode() const { return mConstructionMode; }
291 
296  AdditionalConstraint additionalConstraint() const { return mAdditionalConstraint; }
298  const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
300  const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
302  const CadConstraint *constraintX() const { return mXConstraint.get(); }
304  const CadConstraint *constraintY() const { return mYConstraint.get(); }
305 
310  const CadConstraint *constraintZ() const { return mZConstraint.get(); }
311 
316  const CadConstraint *constraintM() const { return mMConstraint.get(); }
318  bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
319 
324  QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
325 
330  void clearPoints();
331 
336  void addPoint( const QgsPointXY &point );
337 
342  void removePreviousPoint();
343 
351  void setPoints( const QList<QgsPointXY> &points );
352 
360  QgsPoint currentPointV2( bool *exists = nullptr ) const;
361 
367  QgsPoint currentPointLayerCoordinates( QgsMapLayer *layer ) const;
368 
375  Q_DECL_DEPRECATED QgsPointXY currentPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return currentPointV2( exists ); };
376 
382  QgsPoint previousPointV2( bool *exists = nullptr ) const;
383 
390  Q_DECL_DEPRECATED QgsPointXY previousPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return previousPointV2( exists ); };
391 
397  QgsPoint penultimatePointV2( bool *exists = nullptr ) const;
398 
405  Q_DECL_DEPRECATED QgsPointXY penultimatePoint( bool *exists = nullptr ) const SIP_DEPRECATED { return penultimatePointV2( exists ); };
406 
410  inline int pointsCount() const { return mCadPointList.count(); }
411 
415  inline bool snappedToVertex() const { return ( mSnapMatch.isValid() && ( mSnapMatch.hasVertex() || mSnapMatch.hasLineEndpoint() ) ); }
416 
420  QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
421 
423  QAction *enableAction() { return mEnableAction; }
424 
431  void enable();
432 
436  void disable();
437 
442  void updateCadPaintItem();
443 
452  void setX( const QString &value, WidgetSetMode mode );
453 
462  void setY( const QString &value, WidgetSetMode mode );
463 
472  void setZ( const QString &value, WidgetSetMode mode );
473 
482  void setM( const QString &value, WidgetSetMode mode );
483 
492  void setAngle( const QString &value, WidgetSetMode mode );
493 
502  void setDistance( const QString &value, WidgetSetMode mode );
503 
508  double getLineZ( ) const;
509 
514  double getLineM( ) const;
515 
516  signals:
517 
523  void pushWarning( const QString &message );
524 
528  void popWarning();
529 
537  void pointChangedV2( const QgsPoint &point );
538 
546  Q_DECL_DEPRECATED void pointChanged( const QgsPointXY &point ) SIP_DEPRECATED;
547 
549 
557  void cadEnabledChanged( bool enabled );
558 
565  void valueXChanged( const QString &value );
566 
573  void valueYChanged( const QString &value );
574 
581  void valueZChanged( const QString &value );
582 
589  void valueMChanged( const QString &value );
590 
597  void valueAngleChanged( const QString &value );
598 
605  void valueDistanceChanged( const QString &value );
606 
613  void lockXChanged( bool locked );
614 
621  void lockYChanged( bool locked );
622 
629  void lockZChanged( bool locked );
630 
637  void lockMChanged( bool locked );
638 
645  void lockAngleChanged( bool locked );
646 
653  void lockDistanceChanged( bool locked );
654 
663  void relativeXChanged( bool relative );
664 
673  void relativeYChanged( bool relative );
674 
683  void relativeZChanged( bool relative );
684 
693  void relativeMChanged( bool relative );
694 
703  void relativeAngleChanged( bool relative );
704 
705  // relativeDistanceChanged doesn't exist as distance is always relative
706 
716  void enabledChangedX( bool enabled );
717 
727  void enabledChangedY( bool enabled );
728 
738  void enabledChangedZ( bool enabled );
739 
749  void enabledChangedM( bool enabled );
750 
760  void enabledChangedAngle( bool enabled );
761 
771  void enabledChangedDistance( bool enabled );
772 
780 
788 
796 
804 
812 
820 
821 
822  private slots:
824  void additionalConstraintClicked( bool activated );
825 
827  void lockConstraint( bool activate = true );
828 
833  void constraintTextEdited( const QString &textValue );
834 
839  void constraintFocusOut();
840 
842  void setConstraintRelative( bool activate );
843 
845  void setConstraintRepeatingLock( bool activate );
846 
851  void activateCad( bool enabled );
852 
854  void setConstructionMode( bool enabled );
855 
857  void settingsButtonTriggered( QAction *action );
858 
859  private:
860 
864  QgsMapLayer *targetLayer();
865 
867  void setCadEnabled( bool enabled );
868 
873  void updateCapacity( bool updateUIwithoutChange = false );
874 
876  void lockAdditionalConstraint( AdditionalConstraint constraint );
877 
883  QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
884 
886  void updateCurrentPoint( const QgsPoint &point );
887 
888 
893  bool filterKeyPress( QKeyEvent *e );
894 
899  bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
900 
902  void triggerMouseMoveEvent();
903 
905  CadConstraint *objectToConstraint( const QObject *obj ) const;
906 
908  double parseUserInput( const QString &inputValue, bool &ok ) const;
909 
916  void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
917 
919  void updateUnlockedConstraintValues( const QgsPoint &point );
920 
921  QgsMapCanvas *mMapCanvas = nullptr;
922  QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
924  std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
925 
926  CadCapacities mCapacities = CadCapacities();
927 
928  bool mCurrentMapToolSupportsCad = false;
929 
930  // Pointer to the floater
931  QgsAdvancedDigitizingFloater *mFloater = nullptr;
932 
933  // CAD properties
935  bool mCadEnabled = false;
936  bool mConstructionMode = false;
937 
938  // constraints
939  std::unique_ptr< CadConstraint > mAngleConstraint;
940  std::unique_ptr< CadConstraint > mDistanceConstraint;
941  std::unique_ptr< CadConstraint > mXConstraint;
942  std::unique_ptr< CadConstraint > mYConstraint;
943  std::unique_ptr< CadConstraint > mZConstraint;
944  std::unique_ptr< CadConstraint > mMConstraint;
945  AdditionalConstraint mAdditionalConstraint;
946  double mCommonAngleConstraint; // if 0: do not snap to common angles
947 
948  // point list and current snap point / segment
949  QList<QgsPoint> mCadPointList;
950  QList<QgsPointXY> mSnappedSegment;
951 
952  bool mSessionActive = false;
953 
954  // error message
955  std::unique_ptr<QgsMessageBarItem> mErrorMessage;
956 
957  // UI
958  QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values
959 
960  // Snap indicator
961 
962  QgsPointLocator::Match mSnapMatch;
963  private:
964 #ifdef SIP_RUN
966  bool eventFilter( QObject *obj, QEvent *event );
967 #endif
969  QgsPoint pointXYToPoint( const QgsPointXY &point ) const;
970 };
971 
972 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
973 
974 #endif // QGSADVANCEDDIGITIZINGDOCK_H
The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (.
The CadConstraint is an abstract class for all basic constraints (angle/distance/x/y).
CadConstraint(QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton=nullptr, QToolButton *repeatingLockButton=nullptr)
Constructor for CadConstraint.
QLineEdit * lineEdit() const
The line edit that manages the value of the constraint.
bool isLocked() const
Is any kind of lock mode enabled.
double value() const
The value of the constraint.
bool isRepeatingLock() const
Returns true if a repeating lock is set for the constraint.
LockMode lockMode() const
The current lock mode of this constraint.
int precision() const
Returns the numeric precision (decimal places) to show in the associated widget.
bool relative() const
Is the constraint in relative mode.
The QgsAdvancedDigitizingDockWidget class is a dockable widget used to handle the CAD tools on top of...
void valueDistanceChanged(const QString &value)
Emitted whenever the distance value changes (either the mouse moved, or the user changed the input).
bool commonAngleConstraint() const
Returns true if a constraint on a common angle is active.
Q_DECL_DEPRECATED QgsPointXY currentPoint(bool *exists=nullptr) const
The last point.
void lockZChanged(bool locked)
Emitted whenever the Z parameter is locked.
const CadConstraint * constraintDistance() const
Returns the CadConstraint on the distance.
AdditionalConstraint
Additional constraints which can be enabled.
void enabledChangedY(bool enabled)
Emitted whenever the Y field is enabled or disabled.
bool cadEnabled() const
determines if CAD tools are enabled or if map tools behaves "nomally"
int pointsCount() const
The number of points in the CAD point helper list.
void relativeMChanged(bool relative)
Emitted whenever the M parameter is toggled between absolute and relative.
void lockXChanged(bool locked)
Emitted whenever the X parameter is locked.
void focusOnXRequested()
Emitted whenever the X field should get the focus using the shortcuts (X).
bool constructionMode() const
construction mode is used to draw intermediate points. These points won't be given any further (i....
const CadConstraint * constraintZ() const
Returns the CadConstraint on the Z coordinate.
void enabledChangedX(bool enabled)
Emitted whenever the X field is enabled or disabled.
void valueYChanged(const QString &value)
Emitted whenever the Y value changes (either the mouse moved, or the user changed the input).
Q_DECL_DEPRECATED QgsPointXY penultimatePoint(bool *exists=nullptr) const
The penultimate point.
const CadConstraint * constraintM() const
Returns the CadConstraint on the M coordinate.
void focusOnYRequested()
Emitted whenever the Y field should get the focus using the shortcuts (Y).
void enabledChangedDistance(bool enabled)
Emitted whenever the distance field is enabled or disabled.
bool snappedToVertex() const
Is it snapped to a vertex.
void valueZChanged(const QString &value)
Emitted whenever the Z value changes (either the mouse moved, or the user changed the input).
AdditionalConstraint additionalConstraint() const
Returns the additional constraints which are used to place perpendicular/parallel segments to snapped...
void lockAngleChanged(bool locked)
Emitted whenever the angle parameter is locked.
const CadConstraint * constraintX() const
Returns the CadConstraint on the X coordinate.
void pointChangedV2(const QgsPoint &point)
Sometimes a constraint may change the current point out of a mouse event.
void relativeXChanged(bool relative)
Emitted whenever the X parameter is toggled between absolute and relative.
void focusOnAngleRequested()
Emitted whenever the angle field should get the focus using the shortcuts (A).
WidgetSetMode
Type of interaction to simulate when editing values from external widget.
void focusOnZRequested()
Emitted whenever the Z field should get the focus using the shortcuts (Z).
void focusOnMRequested()
Emitted whenever the M field should get the focus using the shortcuts (M).
void popWarning()
Remove any previously emitted warnings (if any)
void valueXChanged(const QString &value)
Emitted whenever the X value changes (either the mouse moved, or the user changed the input).
void lockMChanged(bool locked)
Emitted whenever the M parameter is locked.
void cadEnabledChanged(bool enabled)
Signals for external widgets that need to update according to current values.
void lockYChanged(bool locked)
Emitted whenever the Y parameter is locked.
void valueAngleChanged(const QString &value)
Emitted whenever the angle value changes (either the mouse moved, or the user changed the input).
void valueMChanged(const QString &value)
Emitted whenever the M value changes (either the mouse moved, or the user changed the input).
void relativeZChanged(bool relative)
Emitted whenever the Z parameter is toggled between absolute and relative.
Q_DECL_DEPRECATED void pointChanged(const QgsPointXY &point)
Sometimes a constraint may change the current point out of a mouse event.
CadCapacity
The CadCapacity enum defines the possible constraints to be set depending on the number of points in ...
void enabledChangedAngle(bool enabled)
Emitted whenever the angle field is enabled or disabled.
Q_DECL_DEPRECATED QgsPointXY previousPoint(bool *exists=nullptr) const
The previous point.
const CadConstraint * constraintAngle() const
Returns the CadConstraint on the angle.
void enabledChangedZ(bool enabled)
Emitted whenever the Z field is enabled or disabled.
void lockDistanceChanged(bool locked)
Emitted whenever the distance parameter is locked.
void relativeAngleChanged(bool relative)
Emitted whenever the angleX parameter is toggled between absolute and relative.
void enabledChangedM(bool enabled)
Emitted whenever the M field is enabled or disabled.
QgsPointLocator::Match mapPointMatch() const
Returns the point locator match.
QAction * enableAction()
Returns the action used to enable/disable the tools.
const CadConstraint * constraintY() const
Returns the CadConstraint on the Y coordinate.
void focusOnDistanceRequested()
Emitted whenever the distance field should get the focus using the shortcuts (D).
void pushWarning(const QString &message)
Push a warning.
void relativeYChanged(bool relative)
Emitted whenever the Y parameter is toggled between absolute and relative.
QList< QgsPointXY > snappedSegment() const
Snapped to a segment.
The QgsAdvancedDigitizingFloater class is widget that floats next to the mouse pointer,...
QgsDockWidget subclass with more fine-grained control over how the widget is closed or opened.
Definition: qgsdockwidget.h:32
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:89
Base class for all map layer types.
Definition: qgsmaplayer.h:73
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 ...
Abstract base class for all map tools.
Definition: qgsmaptool.h:71
A class to represent a 2D point.
Definition: qgspointxy.h:59
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition: qgis.h:1246
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_MONKEYPATCH_SCOPEENUM
Definition: qgis_sip.h:256
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
int precision