QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
Loading...
Searching...
No Matches
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
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#include <QQueue>
21
22#include <memory>
23
24#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
36class QgsMapCanvas;
37class QgsMapTool;
40
48class 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
75 {
76 ReturnPressed, FocusOut, TextEdited
77 };
78
79
86 class GUI_EXPORT CadConstraint
87 {
88 public:
89
94 {
97 HardLock
98 };
99
107 CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
108 : mLineEdit( lineEdit )
109 , mLockerButton( lockerButton )
110 , mRelativeButton( relativeButton )
111 , mRepeatingLockButton( repeatingLockButton )
112 , mLockMode( NoLock )
113 , mRepeatingLock( false )
114 , mRelative( false )
115 , mValue( 0.0 )
116 {}
117
122 LockMode lockMode() const { return mLockMode; }
123
127 bool isLocked() const { return mLockMode != NoLock; }
128
135 bool isRepeatingLock() const { return mRepeatingLock; }
136
140 bool relative() const { return mRelative; }
141
145 double value() const { return mValue; }
146
150 QLineEdit *lineEdit() const { return mLineEdit; }
151
155 void setLockMode( LockMode mode );
156
164 void setRepeatingLock( bool repeating );
165
169 void setRelative( bool relative );
170
176 void setValue( double value, bool updateWidget = true );
177
182 QString displayValue() const;
183
187 void toggleLocked();
188
192 void toggleRelative();
193
200 int precision() const { return mPrecision; }
201
208 void setPrecision( int precision );
209
214 Qgis::CadConstraintType cadConstraintType() const;
215
220 void setCadConstraintType( Qgis::CadConstraintType constraintType );
221
226 void setMapCanvas( QgsMapCanvas *mapCanvas );
227
232 static QString removeSuffix( const QString &text, Qgis::CadConstraintType constraintType );
233
234
235 private:
236 QLineEdit *mLineEdit = nullptr;
237 QToolButton *mLockerButton = nullptr;
238 QToolButton *mRelativeButton = nullptr;
239 QToolButton *mRepeatingLockButton = nullptr;
240 LockMode mLockMode;
241 bool mRepeatingLock;
242 bool mRelative;
243 double mValue;
244 int mPrecision = 6;
246 QgsMapCanvas *mMapCanvas = nullptr;
247 };
248
254 explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
255
262 bool canvasKeyPressEventFilter( QKeyEvent *e );
263
268 bool applyConstraints( QgsMapMouseEvent *e );
269
276
282 void releaseLocks( bool releaseRepeatingLocks = true );
283
287 void clear();
288
289 void keyPressEvent( QKeyEvent *e ) override;
290
292 bool cadEnabled() const { return mCadEnabled; }
293
298 void switchZM( );
299
304 void setEnabledZ( bool enable );
305
310 void setEnabledM( bool enable );
311
313 bool constructionMode() const { return mConstructionMode; }
314
319 Qgis::BetweenLineConstraint betweenLineConstraint() const { return mBetweenLineConstraint; }
321 const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
323 const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
325 const CadConstraint *constraintX() const { return mXConstraint.get(); }
327 const CadConstraint *constraintY() const { return mYConstraint.get(); }
328
333 const CadConstraint *constraintZ() const { return mZConstraint.get(); }
334
339 const CadConstraint *constraintM() const { return mMConstraint.get(); }
341 bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
342
344 const CadConstraint *constraintLineExtension() const { return mLineExtensionConstraint.get(); }
345
347 Qgis::LineExtensionSide lineExtensionSide() const { return mSoftLockLineExtension; }
348
350 const CadConstraint *constraintXyVertex() const { return mXyVertexConstraint.get(); }
351
353 double softLockX() const { return mSoftLockX; }
354
356 double softLockY() const { return mSoftLockY; }
357
362 QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
363
368 QList< QgsPointLocator::Match > lockedSnapVertices() const { return mLockedSnapVertices; }
369
375 void clearLockedSnapVertices( bool force = true );
376
381 void clearPoints();
382
387 void addPoint( const QgsPointXY &point );
388
393 void removePreviousPoint();
394
399 void updateCurrentPoint( const QgsPoint &point );
400
408 void setPoints( const QList<QgsPointXY> &points );
409
417 QgsPoint currentPointV2( bool *exists = nullptr ) const;
418
424 QgsPoint currentPointLayerCoordinates( QgsMapLayer *layer ) const;
425
432 Q_DECL_DEPRECATED QgsPointXY currentPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return currentPointV2( exists ); };
433
439 QgsPoint previousPointV2( bool *exists = nullptr ) const;
440
447 Q_DECL_DEPRECATED QgsPointXY previousPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return previousPointV2( exists ); };
448
454 QgsPoint penultimatePointV2( bool *exists = nullptr ) const;
455
462 Q_DECL_DEPRECATED QgsPointXY penultimatePoint( bool *exists = nullptr ) const SIP_DEPRECATED { return penultimatePointV2( exists ); };
463
467 inline int pointsCount() const { return mCadPointList.count(); }
468
472 inline bool snappedToVertex() const { return ( mSnapMatch.isValid() && ( mSnapMatch.hasVertex() || mSnapMatch.hasLineEndpoint() ) ); }
473
477 QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
478
480 QAction *enableAction() { return mEnableAction; }
481
488 void enable();
489
493 void disable();
494
499 void updateCadPaintItem();
500
509 void setX( const QString &value, WidgetSetMode mode );
510
519 void setY( const QString &value, WidgetSetMode mode );
520
529 void setZ( const QString &value, WidgetSetMode mode );
530
539 void setM( const QString &value, WidgetSetMode mode );
540
549 void setAngle( const QString &value, WidgetSetMode mode );
550
559 void setDistance( const QString &value, WidgetSetMode mode );
560
565 double getLineZ( ) const;
566
571 double getLineM( ) const;
572
577 CadCapacities capacities() const { return mCapacities; };
578
583 QString formatCommonAngleSnapping( double angle );
584
585 signals:
586
592 void pushWarning( const QString &message );
593
598
606 void pointChangedV2( const QgsPoint &point );
607
615 Q_DECL_DEPRECATED void pointChanged( const QgsPointXY &point ) SIP_DEPRECATED;
616
618
626 void cadEnabledChanged( bool enabled );
627
634 void valueXChanged( const QString &value );
635
642 void valueYChanged( const QString &value );
643
650 void valueZChanged( const QString &value );
651
658 void valueMChanged( const QString &value );
659
666 void valueAngleChanged( const QString &value );
667
674 void valueDistanceChanged( const QString &value );
675
682 void valueBearingChanged( const QString &value );
683
690 void lockXChanged( bool locked );
691
698 void lockYChanged( bool locked );
699
706 void lockZChanged( bool locked );
707
714 void lockMChanged( bool locked );
715
722 void lockAngleChanged( bool locked );
723
730 void lockDistanceChanged( bool locked );
731
740 void relativeXChanged( bool relative );
741
750 void relativeYChanged( bool relative );
751
760 void relativeZChanged( bool relative );
761
770 void relativeMChanged( bool relative );
771
780 void relativeAngleChanged( bool relative );
781
788 void softLockLineExtensionChanged( bool locked );
789
796 void softLockXyChanged( bool locked );
797
798 // relativeDistanceChanged doesn't exist as distance is always relative
799
809 void enabledChangedX( bool enabled );
810
820 void enabledChangedY( bool enabled );
821
831 void enabledChangedZ( bool enabled );
832
842 void enabledChangedM( bool enabled );
843
853 void enabledChangedAngle( bool enabled );
854
864 void enabledChangedDistance( bool enabled );
865
873
881
889
897
905
913
919
925
926 private slots:
928 void betweenLineConstraintClicked( bool activated );
929
931 void lockConstraint( bool activate = true );
932
934 void lockParameterlessConstraint( bool activate = true );
935
940 void constraintTextEdited( const QString &textValue );
941
946 void constraintFocusOut();
947
949 void setConstraintRelative( bool activate );
950
952 void setConstraintRepeatingLock( bool activate );
953
958 void activateCad( bool enabled );
959
961 void setConstructionMode( bool enabled );
962
964 void settingsButtonTriggered( QAction *action );
965
966 private:
967
971 QgsMapLayer *targetLayer() const;
972
974 void setCadEnabled( bool enabled );
975
980 void updateCapacity( bool updateUIwithoutChange = false );
981
983 void lockBetweenLineConstraint( Qgis::BetweenLineConstraint constraint );
984
990 QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
991
996 bool filterKeyPress( QKeyEvent *e );
997
1002 bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
1003
1005 void triggerMouseMoveEvent();
1006
1008 CadConstraint *objectToConstraint( const QObject *obj ) const;
1009
1011 double parseUserInput( const QString &inputValue, const Qgis::CadConstraintType type, bool &ok ) const;
1012
1019 void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
1020
1022 void updateUnlockedConstraintValues( const QgsPoint &point );
1023
1024
1030 void toggleLockedSnapVertex( const QgsPointLocator::Match &snapMatch, QgsPointLocator::Match previouslySnap );
1031
1032 QgsMapCanvas *mMapCanvas = nullptr;
1033 QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
1035 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
1036
1037 CadCapacities mCapacities = CadCapacities();
1038
1039 bool mCurrentMapToolSupportsCad = false;
1040
1041 // Pointer to the floater
1042 QgsAdvancedDigitizingFloater *mFloater = nullptr;
1043
1044 // CAD properties
1046 bool mCadEnabled = false;
1047 bool mConstructionMode = false;
1048
1049 // constraints
1050 std::unique_ptr< CadConstraint > mAngleConstraint;
1051 std::unique_ptr< CadConstraint > mDistanceConstraint;
1052 std::unique_ptr< CadConstraint > mXConstraint;
1053 std::unique_ptr< CadConstraint > mYConstraint;
1054 std::unique_ptr< CadConstraint > mZConstraint;
1055 std::unique_ptr< CadConstraint > mMConstraint;
1056 std::unique_ptr< CadConstraint > mLineExtensionConstraint;
1057 std::unique_ptr< CadConstraint > mXyVertexConstraint;
1058 Qgis::BetweenLineConstraint mBetweenLineConstraint;
1059 double mCommonAngleConstraint; // if 0: do not snap to common angles
1060
1062 bool mSnappingPrioritizeFeatures = false;
1063
1064 // point list and current snap point / segment
1065 QList<QgsPoint> mCadPointList;
1066 QList<QgsPointXY> mSnappedSegment;
1067
1068 bool mSessionActive = false;
1069
1070 // error message
1071 std::unique_ptr<QgsMessageBarItem> mErrorMessage;
1072
1073 // UI
1074 QMap< double, QAction *> mCommonAngleActions; // map the common angle actions with their angle values
1075 QAction *mLineExtensionAction;
1076 QAction *mXyVertexAction;
1077
1078 // Snap indicator
1079 QgsPointLocator::Match mSnapMatch;
1080 QgsPointLocator::Match mLastSnapMatch;
1081
1082 // Extra constraint context
1083 Qgis::LineExtensionSide mSoftLockLineExtension;
1084 double mSoftLockX;
1085 double mSoftLockY;
1086 QQueue< QgsPointLocator::Match > mLockedSnapVertices;
1087
1088#ifdef SIP_RUN
1090 bool eventFilter( QObject *obj, QEvent *event );
1091#endif
1093 QgsPoint pointXYToPoint( const QgsPointXY &point ) const;
1094
1095 QMenu *mCommonAngleActionsMenu = nullptr;
1096 QMenu *mFloaterActionsMenu = nullptr;
1097
1098 static const QgsSettingsEntryBool *settingsCadSnappingPriorityPrioritizeFeature;
1099
1100 friend class TestQgsAdvancedDigitizing;
1101 friend class TestQgsAdvancedDigitizingDockWidget;
1102};
1103
1104Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
1105
1106#endif // QGSADVANCEDDIGITIZINGDOCK_H
CadConstraintType
Advanced digitizing constraint type.
Definition qgis.h:2739
@ Generic
Generic value.
BetweenLineConstraint
Between line constraints which can be enabled.
Definition qgis.h:2713
LineExtensionSide
Designates whether the line extension constraint is currently soft locked with the previous or next v...
Definition qgis.h:2726
The QgsAdvancedDigitizingCanvasItem class draws the graphical elements of the CAD tools (.
The CadConstraint is a class for all basic constraints (angle/distance/x/y).
CadConstraint(QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton=nullptr, QToolButton *repeatingLockButton=nullptr)
Constructor for CadConstraint.
bool isLocked() const
Is any kind of lock mode enabled.
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.
QLineEdit * lineEdit() const
The line edit that manages the value of the constraint.
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.
double softLockY() const
Returns the Y value of the Y soft lock. The value is NaN is the constraint isn't magnetized to a line...
const CadConstraint * constraintM() const
Returns the CadConstraint on the M coordinate.
void enabledChangedY(bool enabled)
Emitted whenever the Y field is enabled or disabled.
QAction * enableAction()
Returns the action used to enable/disable the tools.
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.
QList< QgsPointXY > snappedSegment() const
Snapped to a segment.
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 softLockLineExtensionChanged(bool locked)
Emitted whenever the soft line extension 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....
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 * constraintLineExtension() const
Returns the CadConstraint.
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).
QList< QgsPointLocator::Match > lockedSnapVertices() const
Returns the snap matches whose vertices have been locked.
void lockAngleChanged(bool locked)
Emitted whenever the angle parameter is locked.
void pointChangedV2(const QgsPoint &point)
Sometimes a constraint may change the current point out of a mouse event.
void commonAngleSnappingShowInFloaterChanged(bool enabled)
Emitted whenever the option to show common angle snapping in the floater changes.
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.
const CadConstraint * constraintXyVertex() const
Returns the CadConstraint.
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.
const CadConstraint * constraintY() const
Returns the CadConstraint on the Y coordinate.
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.
double softLockX() const
Returns the X value of the X soft lock. The value is NaN is the constraint isn't magnetized to a line...
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 ...
Qgis::BetweenLineConstraint betweenLineConstraint() const
Returns the between line constraints which are used to place perpendicular/parallel segments to snapp...
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.
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.
const CadConstraint * constraintX() const
Returns the CadConstraint on the X coordinate.
CadCapacities capacities() const
Returns the capacities.
void softLockXyChanged(bool locked)
Emitted whenever the soft x/y extension parameter is locked.
const CadConstraint * constraintZ() const
Returns the CadConstraint on the Z coordinate.
void valueBearingChanged(const QString &value)
Emitted whenever the bearing value changes.
void enabledChangedM(bool enabled)
Emitted whenever the M field is enabled or disabled.
QgsPointLocator::Match mapPointMatch() const
Returns the point locator match.
void focusOnDistanceRequested()
Emitted whenever the distance field should get the focus using the shortcuts (D).
const CadConstraint * constraintAngle() const
Returns the CadConstraint on the angle.
void valueCommonAngleSnappingChanged(double angle)
Emitted whenever the snapping to common angle option changes, angle = 0 means that the functionality ...
void pushWarning(const QString &message)
Push a warning.
Qgis::LineExtensionSide lineExtensionSide() const
Returns on which side of the constraint line extension point, the line was created.
const CadConstraint * constraintDistance() const
Returns the CadConstraint on the distance.
void relativeYChanged(bool relative)
Emitted whenever the Y parameter is toggled between absolute and relative.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
Base class for all map layer types.
Definition qgsmaplayer.h:74
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
A boolean settings entry.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference)
Definition qgis.h:4332
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
int precision