QGIS API Documentation 3.28.14-Firenze (exported)
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
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#include <QQueue>
21
22#include <memory>
23
24#include "ui_qgsadvanceddigitizingdockwidgetbase.h"
26#include "qgis_gui.h"
27#include "qgis_sip.h"
28#include "qgsdockwidget.h"
29#include "qgsmessagebaritem.h"
30#include "qgspointxy.h"
31#include "qgspointlocator.h"
32#include "qgssnapindicator.h"
33#include "qgscadutils.h"
34
35
38class QgsMapCanvas;
39class QgsMapTool;
42
50class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private Ui::QgsAdvancedDigitizingDockWidgetBase
51{
52 Q_OBJECT
53
54 public:
55
62 {
63 AbsoluteAngle = 1,
64 RelativeAngle = 2,
65 RelativeCoordinates = 4,
66 Distance = 8,
67 };
68 Q_DECLARE_FLAGS( CadCapacities, CadCapacity )
69 Q_FLAG( CadCapacities )
70
71
77 {
78 ReturnPressed, FocusOut, TextEdited
79 };
80
81
88 class GUI_EXPORT CadConstraint
89 {
90 public:
91
96 {
99 HardLock
100 };
101
109 CadConstraint( QLineEdit *lineEdit, QToolButton *lockerButton, QToolButton *relativeButton = nullptr, QToolButton *repeatingLockButton = nullptr )
110 : mLineEdit( lineEdit )
111 , mLockerButton( lockerButton )
112 , mRelativeButton( relativeButton )
113 , mRepeatingLockButton( repeatingLockButton )
114 , mLockMode( NoLock )
115 , mRepeatingLock( false )
116 , mRelative( false )
117 , mValue( 0.0 )
118 {}
119
124 LockMode lockMode() const { return mLockMode; }
125
129 bool isLocked() const { return mLockMode != NoLock; }
130
137 bool isRepeatingLock() const { return mRepeatingLock; }
138
142 bool relative() const { return mRelative; }
143
147 double value() const { return mValue; }
148
152 QLineEdit *lineEdit() const { return mLineEdit; }
153
157 void setLockMode( LockMode mode );
158
166 void setRepeatingLock( bool repeating );
167
171 void setRelative( bool relative );
172
178 void setValue( double value, bool updateWidget = true );
179
183 void toggleLocked();
184
188 void toggleRelative();
189
196 int precision() const { return mPrecision; }
197
204 void setPrecision( int precision );
205
206 private:
207 QLineEdit *mLineEdit = nullptr;
208 QToolButton *mLockerButton = nullptr;
209 QToolButton *mRelativeButton = nullptr;
210 QToolButton *mRepeatingLockButton = nullptr;
211 LockMode mLockMode;
212 bool mRepeatingLock;
213 bool mRelative;
214 double mValue;
215 int mPrecision = 6;
216 };
217
223 explicit QgsAdvancedDigitizingDockWidget( QgsMapCanvas *canvas, QWidget *parent = nullptr );
224
231 bool canvasKeyPressEventFilter( QKeyEvent *e );
232
237 bool applyConstraints( QgsMapMouseEvent *e );
238
245
251 void releaseLocks( bool releaseRepeatingLocks = true );
252
256 void clear();
257
258 void keyPressEvent( QKeyEvent *e ) override;
259
261 bool cadEnabled() const { return mCadEnabled; }
262
267 void switchZM( );
268
273 void setEnabledZ( bool enable );
274
279 void setEnabledM( bool enable );
280
282 bool constructionMode() const { return mConstructionMode; }
283
288 Qgis::BetweenLineConstraint betweenLineConstraint() const { return mBetweenLineConstraint; }
290 const CadConstraint *constraintAngle() const { return mAngleConstraint.get(); }
292 const CadConstraint *constraintDistance() const { return mDistanceConstraint.get(); }
294 const CadConstraint *constraintX() const { return mXConstraint.get(); }
296 const CadConstraint *constraintY() const { return mYConstraint.get(); }
297
302 const CadConstraint *constraintZ() const { return mZConstraint.get(); }
303
308 const CadConstraint *constraintM() const { return mMConstraint.get(); }
310 bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
311
313 const CadConstraint *constraintLineExtension() const { return mLineExtensionConstraint.get(); }
314
316 Qgis::LineExtensionSide lineExtensionSide() const { return mSoftLockLineExtension; }
317
319 const CadConstraint *constraintXyVertex() const { return mXyVertexConstraint.get(); }
320
322 double softLockX() const { return mSoftLockX; }
323
325 double softLockY() const { return mSoftLockY; }
326
331 QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
332
337 QList< QgsPointLocator::Match > lockedSnapVertices() const { return mLockedSnapVertices; }
338
344 void clearLockedSnapVertices( bool force = true );
345
350 void clearPoints();
351
356 void addPoint( const QgsPointXY &point );
357
362 void removePreviousPoint();
363
368 void updateCurrentPoint( const QgsPoint &point );
369
377 void setPoints( const QList<QgsPointXY> &points );
378
386 QgsPoint currentPointV2( bool *exists = nullptr ) const;
387
393 QgsPoint currentPointLayerCoordinates( QgsMapLayer *layer ) const;
394
401 Q_DECL_DEPRECATED QgsPointXY currentPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return currentPointV2( exists ); };
402
408 QgsPoint previousPointV2( bool *exists = nullptr ) const;
409
416 Q_DECL_DEPRECATED QgsPointXY previousPoint( bool *exists = nullptr ) const SIP_DEPRECATED { return previousPointV2( exists ); };
417
423 QgsPoint penultimatePointV2( bool *exists = nullptr ) const;
424
431 Q_DECL_DEPRECATED QgsPointXY penultimatePoint( bool *exists = nullptr ) const SIP_DEPRECATED { return penultimatePointV2( exists ); };
432
436 inline int pointsCount() const { return mCadPointList.count(); }
437
441 inline bool snappedToVertex() const { return ( mSnapMatch.isValid() && ( mSnapMatch.hasVertex() || mSnapMatch.hasLineEndpoint() ) ); }
442
446 QList<QgsPointXY> snappedSegment() const { return mSnappedSegment; }
447
449 QAction *enableAction() { return mEnableAction; }
450
457 void enable();
458
462 void disable();
463
468 void updateCadPaintItem();
469
478 void setX( const QString &value, WidgetSetMode mode );
479
488 void setY( const QString &value, WidgetSetMode mode );
489
498 void setZ( const QString &value, WidgetSetMode mode );
499
508 void setM( const QString &value, WidgetSetMode mode );
509
518 void setAngle( const QString &value, WidgetSetMode mode );
519
528 void setDistance( const QString &value, WidgetSetMode mode );
529
534 double getLineZ( ) const;
535
540 double getLineM( ) const;
541
546 CadCapacities capacities() const { return mCapacities; };
547
548 signals:
549
555 void pushWarning( const QString &message );
556
561
569 void pointChangedV2( const QgsPoint &point );
570
578 Q_DECL_DEPRECATED void pointChanged( const QgsPointXY &point ) SIP_DEPRECATED;
579
581
589 void cadEnabledChanged( bool enabled );
590
597 void valueXChanged( const QString &value );
598
605 void valueYChanged( const QString &value );
606
613 void valueZChanged( const QString &value );
614
621 void valueMChanged( const QString &value );
622
629 void valueAngleChanged( const QString &value );
630
637 void valueDistanceChanged( const QString &value );
638
645 void lockXChanged( bool locked );
646
653 void lockYChanged( bool locked );
654
661 void lockZChanged( bool locked );
662
669 void lockMChanged( bool locked );
670
677 void lockAngleChanged( bool locked );
678
685 void lockDistanceChanged( bool locked );
686
695 void relativeXChanged( bool relative );
696
705 void relativeYChanged( bool relative );
706
715 void relativeZChanged( bool relative );
716
725 void relativeMChanged( bool relative );
726
735 void relativeAngleChanged( bool relative );
736
743 void softLockLineExtensionChanged( bool locked );
744
751 void softLockXyChanged( bool locked );
752
753 // relativeDistanceChanged doesn't exist as distance is always relative
754
764 void enabledChangedX( bool enabled );
765
775 void enabledChangedY( bool enabled );
776
786 void enabledChangedZ( bool enabled );
787
797 void enabledChangedM( bool enabled );
798
808 void enabledChangedAngle( bool enabled );
809
819 void enabledChangedDistance( bool enabled );
820
828
836
844
852
860
868
869
870 private slots:
872 void betweenLineConstraintClicked( bool activated );
873
875 void lockConstraint( bool activate = true );
876
878 void lockParameterlessConstraint( bool activate = true );
879
884 void constraintTextEdited( const QString &textValue );
885
890 void constraintFocusOut();
891
893 void setConstraintRelative( bool activate );
894
896 void setConstraintRepeatingLock( bool activate );
897
902 void activateCad( bool enabled );
903
905 void setConstructionMode( bool enabled );
906
908 void settingsButtonTriggered( QAction *action );
909
910 private:
911
915 QgsMapLayer *targetLayer() const;
916
918 void setCadEnabled( bool enabled );
919
924 void updateCapacity( bool updateUIwithoutChange = false );
925
927 void lockBetweenLineConstraint( Qgis::BetweenLineConstraint constraint );
928
934 QList<QgsPointXY> snapSegmentToAllLayers( const QgsPointXY &originalMapPoint, bool *snapped = nullptr ) const;
935
940 bool filterKeyPress( QKeyEvent *e );
941
946 bool eventFilter( QObject *obj, QEvent *event ) override SIP_SKIP;
947
949 void triggerMouseMoveEvent();
950
952 CadConstraint *objectToConstraint( const QObject *obj ) const;
953
955 double parseUserInput( const QString &inputValue, bool &ok ) const;
956
963 void updateConstraintValue( CadConstraint *constraint, const QString &textValue, bool convertExpression = false );
964
966 void updateUnlockedConstraintValues( const QgsPoint &point );
967
968
974 void toggleLockedSnapVertex( const QgsPointLocator::Match &snapMatch, QgsPointLocator::Match previouslySnap );
975
976 QgsMapCanvas *mMapCanvas = nullptr;
977 QgsAdvancedDigitizingCanvasItem *mCadPaintItem = nullptr;
979 std::unique_ptr<QgsSnapIndicator> mSnapIndicator;
980
981 CadCapacities mCapacities = CadCapacities();
982
983 bool mCurrentMapToolSupportsCad = false;
984
985 // Pointer to the floater
986 QgsAdvancedDigitizingFloater *mFloater = nullptr;
987
988 // CAD properties
990 bool mCadEnabled = false;
991 bool mConstructionMode = false;
992
993 // constraints
994 std::unique_ptr< CadConstraint > mAngleConstraint;
995 std::unique_ptr< CadConstraint > mDistanceConstraint;
996 std::unique_ptr< CadConstraint > mXConstraint;
997 std::unique_ptr< CadConstraint > mYConstraint;
998 std::unique_ptr< CadConstraint > mZConstraint;
999 std::unique_ptr< CadConstraint > mMConstraint;
1000 std::unique_ptr< CadConstraint > mLineExtensionConstraint;
1001 std::unique_ptr< CadConstraint > mXyVertexConstraint;
1002 Qgis::BetweenLineConstraint mBetweenLineConstraint;
1003 double mCommonAngleConstraint; // if 0: do not snap to common angles
1004
1005 // point list and current snap point / segment
1006 QList<QgsPoint> mCadPointList;
1007 QList<QgsPointXY> mSnappedSegment;
1008
1009 bool mSessionActive = false;
1010
1011 // error message
1012 std::unique_ptr<QgsMessageBarItem> mErrorMessage;
1013
1014 // UI
1015 QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values
1016 QAction *mLineExtensionAction;
1017 QAction *mXyVertexAction;
1018
1019 // Snap indicator
1020 QgsPointLocator::Match mSnapMatch;
1021 QgsPointLocator::Match mLastSnapMatch;
1022
1023 // Extra constraint context
1024 Qgis::LineExtensionSide mSoftLockLineExtension;
1025 double mSoftLockX;
1026 double mSoftLockY;
1027 QQueue< QgsPointLocator::Match > mLockedSnapVertices;
1028
1029#ifdef SIP_RUN
1031 bool eventFilter( QObject *obj, QEvent *event );
1032#endif
1034 QgsPoint pointXYToPoint( const QgsPointXY &point ) const;
1035
1036 friend class TestQgsAdvancedDigitizing;
1037 friend class TestQgsAdvancedDigitizingDockWidget;
1038};
1039
1040Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAdvancedDigitizingDockWidget::CadCapacities )
1041
1042#endif // QGSADVANCEDDIGITIZINGDOCK_H
BetweenLineConstraint
Between line constraints which can be enabled.
Definition qgis.h:1952
LineExtensionSide
Designates whether the line extension constraint is currently soft locked with the previous or next v...
Definition qgis.h:1965
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.
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 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 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 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: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:2527
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_SKIP
Definition qgis_sip.h:126
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