Skip to content

Commit 1b588c8

Browse files
authored
Merge pull request #5148 from wonder-sk/adv-digitizing-cleanup-2
Advanced digitizing cleanup - part 2
2 parents cea7eb8 + f938b60 commit 1b588c8

24 files changed

+369
-395
lines changed

doc/api_break.dox

+10-2
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ QgsAction {#qgis_api_break_3_0_QgsAction}
474474
QgsAdvancedDigitizingDockWidget {#qgis_api_break_3_0_QgsAdvancedDigitizingDockWidget}
475475
-------------------------------
476476

477-
- canvasReleaseEvent takes now QgsAdvancedDigitizingDockWidget::CaptureMode as second argument.
477+
- canvasPressEvent(), canvasReleaseEvent(), canvasMoveEvent() were removed. Handling of events is done in QgsMapToolAdvancedDigitizing.
478478
- snappingMode() was removed. Advanced digitizing now always uses project's snapping configuration.
479479

480480

@@ -1577,7 +1577,8 @@ QgsMapMouseEvent {#qgis_api_break_3_0_QgsMapMouseEvent}
15771577
----------------
15781578

15791579
- SnappingMode enum was removed.
1580-
- snapPoint() and snapSegment() do not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
1580+
- snapPoint() does not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
1581+
- snapSegment() was removed.
15811582

15821583

15831584
QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
@@ -1624,6 +1625,13 @@ QgsMapTool {#qgis_api_break_3_0_QgsMapTool}
16241625
- isTransient() and isEditTool() were removed. Use flags() instead.
16251626

16261627

1628+
QgsMapToolAdvancedDigitizing {#qgis_api_break_3_0_QgsMapToolAdvancedDigitizing}
1629+
----------------------------
1630+
1631+
- setMode() was replaced by setAdvancedDigitizingAllowed() and setAutoSnapEnabled()
1632+
- mode() and CaptureMode enum have been moved to QgsMapToolCapture subclass
1633+
1634+
16271635
QgsMapToolCapture {#qgis_api_break_3_0_QgsMapToolCapture}
16281636
-----------------
16291637

python/gui/qgsadvanceddigitizingdockwidget.sip

+34-32
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
4242
Parallel
4343
};
4444

45-
enum AdvancedDigitizingMode
46-
{
47-
SinglePoint,
48-
TwoPoints,
49-
ManyPoints
50-
};
51-
5245
class CadConstraint
5346
{
5447
%Docstring
@@ -179,47 +172,30 @@ class QgsAdvancedDigitizingDockWidget : QgsDockWidget
179172
Disables the CAD tools when hiding the dock
180173
%End
181174

182-
bool canvasPressEvent( QgsMapMouseEvent *e );
183-
%Docstring
184-
Will react on a canvas press event
185-
186-
\param e A mouse event (may be modified)
187-
:return: If the event is hidden (construction mode hides events from the maptool)
188-
:rtype: bool
189-
%End
190-
191-
bool canvasReleaseEvent( QgsMapMouseEvent *e, AdvancedDigitizingMode mode );
175+
bool canvasKeyPressEventFilter( QKeyEvent *e );
192176
%Docstring
193-
Will react on a canvas release event
177+
Filter key events to e.g. toggle construction mode or adapt constraints
194178

195179
\param e A mouse event (may be modified)
196-
\param mode determines if the dock has to record one, two or many points.
197180
:return: If the event is hidden (construction mode hides events from the maptool)
198181
:rtype: bool
199182
%End
200183

201-
bool canvasMoveEvent( QgsMapMouseEvent *e );
184+
bool applyConstraints( QgsMapMouseEvent *e );
202185
%Docstring
203-
Will react on a canvas move event
204-
205-
\param e A mouse event (may be modified)
206-
:return: If the event is hidden (construction mode hides events from the maptool)
186+
:return: false if no solution was found (invalid constraints)
207187
:rtype: bool
208188
%End
209189

210-
bool canvasKeyPressEventFilter( QKeyEvent *e );
190+
bool alignToSegment( QgsMapMouseEvent *e, QgsAdvancedDigitizingDockWidget::CadConstraint::LockMode lockMode = QgsAdvancedDigitizingDockWidget::CadConstraint::HardLock );
211191
%Docstring
212-
Filter key events to e.g. toggle construction mode or adapt constraints
213-
214-
\param e A mouse event (may be modified)
215-
:return: If the event is hidden (construction mode hides events from the maptool)
192+
.. versionadded:: 3.0
216193
:rtype: bool
217194
%End
218195

219-
virtual bool applyConstraints( QgsMapMouseEvent *e );
196+
void releaseLocks( bool releaseRepeatingLocks = true );
220197
%Docstring
221-
:return: false if no solution was found (invalid constraints)
222-
:rtype: bool
198+
.. versionadded:: 3.0
223199
%End
224200

225201
void clear();
@@ -273,6 +249,27 @@ Constraint on a common angle
273249
:rtype: bool
274250
%End
275251

252+
void clearPoints();
253+
%Docstring
254+
Removes all points from the CAD point list
255+
.. versionadded:: 3.0
256+
%End
257+
258+
void addPoint( const QgsPointXY &point );
259+
%Docstring
260+
Adds point to the CAD point list
261+
.. versionadded:: 3.0
262+
%End
263+
264+
void setPoints( const QList<QgsPointXY> &points );
265+
%Docstring
266+
Configures list of current CAD points
267+
268+
Some map tools may find it useful to override list of CAD points that is otherwise
269+
automatically populated when user clicks with left mouse button on map canvas.
270+
.. versionadded:: 3.0
271+
%End
272+
276273
QgsPointXY currentPoint( bool *exists = 0 ) const;
277274
%Docstring
278275
The last point.
@@ -334,6 +331,11 @@ return the action used to enable/disable the tools
334331
Disable the widget. Normally done automatically from QgsMapToolAdvancedDigitizing.deactivate().
335332
%End
336333

334+
void updateCadPaintItem();
335+
%Docstring
336+
.. versionadded:: 3.0
337+
%End
338+
337339
signals:
338340

339341
void pushWarning( const QString &message );

python/gui/qgsmapmouseevent.sip

-10
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,6 @@ class QgsMapMouseEvent : QMouseEvent
6161
:rtype: QgsPointXY
6262
%End
6363

64-
QList<QgsPointXY> snapSegment( bool *snapped = 0, bool allLayers = false ) const;
65-
%Docstring
66-
Returns the first snapped segment. If the cached snapped match is a segment, it will simply return it.
67-
Otherwise it will try to snap a segment according to the event's snapping mode. In this case the cache
68-
will not be overwritten.
69-
\param snapped if given, determines if a segment has been snapped
70-
\param allLayers if true, override snapping mode
71-
:rtype: list of QgsPointXY
72-
%End
73-
7464
bool isSnapped() const;
7565
%Docstring
7666
Returns true if there is a snapped point cached.

python/gui/qgsmaptooladvanceddigitizing.sip

+42-25
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,6 @@ class QgsMapToolAdvancedDigitizing : QgsMapToolEdit
2727
#include "qgsmaptooladvanceddigitizing.h"
2828
%End
2929
public:
30-
enum CaptureMode
31-
{
32-
CaptureNone,
33-
CapturePoint,
34-
CaptureSegment,
35-
CaptureLine,
36-
CapturePolygon
37-
};
3830

3931
explicit QgsMapToolAdvancedDigitizing( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget );
4032
%Docstring
@@ -56,22 +48,6 @@ Catch the mouse release event, filters it, transforms it to map coordinates and
5648
Catch the mouse move event, filters it, transforms it to map coordinates and send it to virtual method
5749
%End
5850

59-
CaptureMode mode() const;
60-
%Docstring
61-
The capture mode
62-
63-
:return: Capture mode
64-
:rtype: CaptureMode
65-
%End
66-
67-
void setMode( CaptureMode mode );
68-
%Docstring
69-
Set capture mode. This should correspond to the layer on which the digitizing
70-
happens.
71-
72-
\param mode Capture Mode
73-
%End
74-
7551
virtual void activate();
7652
%Docstring
7753
Registers this maptool with the cad dock widget
@@ -87,9 +63,51 @@ Catch the mouse move event, filters it, transforms it to map coordinates and sen
8763
:rtype: QgsAdvancedDigitizingDockWidget
8864
%End
8965

66+
bool isAdvancedDigitizingAllowed() const;
67+
%Docstring
68+
Returns whether functionality of advanced digitizing dock widget is currently allowed.
69+
70+
Tools may decide to switch this support on/off based on the current state of the map tool.
71+
For example, in node tool before user picks a vertex to move, advanced digitizing dock
72+
widget should be disabled and only enabled once a vertex is being moved. Other map tools
73+
may keep advanced digitizing allowed all the time.
74+
75+
If true is returned, that does not mean that advanced digitizing is actually active,
76+
because it is up to the user to enable/disable it when it is allowed.
77+
\sa setAdvancedDigitizingAllowed()
78+
.. versionadded:: 3.0
79+
:rtype: bool
80+
%End
81+
82+
bool isAutoSnapEnabled() const;
83+
%Docstring
84+
Returns whether mouse events (press/move/release) should automatically try to snap mouse position
85+
(according to the snapping configuration of map canvas) before passing the mouse coordinates
86+
to the tool. This may be desirable default behavior for some map tools, but not for other map tools.
87+
It is therefore possible to configure the behavior by the map tool.
88+
\sa isAutoSnapEnabled()
89+
.. versionadded:: 3.0
90+
:rtype: bool
91+
%End
9092

9193
protected:
9294

95+
void setAdvancedDigitizingAllowed( bool allowed );
96+
%Docstring
97+
Sets whether functionality of advanced digitizing dock widget is currently allowed.
98+
This method is protected because it should be a decision of the map tool and not from elsewhere.
99+
\sa isAdvancedDigitizingAllowed()
100+
.. versionadded:: 3.0
101+
%End
102+
103+
void setAutoSnapEnabled( bool enabled );
104+
%Docstring
105+
Sets whether mouse events (press/move/release) should automatically try to snap mouse position
106+
This method is protected because it should be a decision of the map tool and not from elsewhere.
107+
\sa isAutoSnapEnabled()
108+
.. versionadded:: 3.0
109+
%End
110+
93111
virtual void cadCanvasPressEvent( QgsMapMouseEvent *e );
94112
%Docstring
95113
Override this method when subclassing this class.
@@ -122,7 +140,6 @@ Catch the mouse move event, filters it, transforms it to map coordinates and sen
122140
\param e Mouse events prepared by the cad system
123141
%End
124142

125-
126143
};
127144

128145
/************************************************************************

python/gui/qgsmaptoolcapture.sip

+18-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ class QgsMapToolCapture : QgsMapToolAdvancedDigitizing
1818
#include "qgsmaptoolcapture.h"
1919
%End
2020
public:
21-
QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = CaptureNone );
21+
22+
enum CaptureMode
23+
{
24+
CaptureNone,
25+
CapturePoint,
26+
CaptureLine,
27+
CapturePolygon
28+
};
29+
30+
QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
2231
%Docstring
2332
constructor
2433
%End
@@ -28,6 +37,14 @@ constructor
2837
virtual void activate();
2938
virtual void deactivate();
3039

40+
CaptureMode mode() const;
41+
%Docstring
42+
The capture mode
43+
44+
:return: Capture mode
45+
:rtype: CaptureMode
46+
%End
47+
3148
int addCurve( QgsCurve *c );
3249
%Docstring
3350
Adds a whole curve (e.g. circularstring) to the captured geometry. Curve must be in map CRS

0 commit comments

Comments
 (0)