Skip to content

Commit a2b2567

Browse files
committed
Better control of CAD dock widget operation from map tools
1 parent cea7eb8 commit a2b2567

15 files changed

+147
-68
lines changed

doc/api_break.dox

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,6 +1624,12 @@ QgsMapTool {#qgis_api_break_3_0_QgsMapTool}
16241624
- isTransient() and isEditTool() were removed. Use flags() instead.
16251625

16261626

1627+
QgsMapToolAdvancedDigitizing {#qgis_api_break_3_0_QgsMapToolAdvancedDigitizing}
1628+
----------------------------
1629+
1630+
- setMode() was replaced by setAdvancedDigitizingAllowed() and setAutoSnapEnabled()
1631+
1632+
16271633
QgsMapToolCapture {#qgis_api_break_3_0_QgsMapToolCapture}
16281634
-----------------
16291635

python/gui/qgsmaptooladvanceddigitizing.sip

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ Catch the mouse move event, filters it, transforms it to map coordinates and sen
6464
:rtype: CaptureMode
6565
%End
6666

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-
7567
virtual void activate();
7668
%Docstring
7769
Registers this maptool with the cad dock widget
@@ -87,9 +79,51 @@ Catch the mouse move event, filters it, transforms it to map coordinates and sen
8779
:rtype: QgsAdvancedDigitizingDockWidget
8880
%End
8981

82+
bool isAdvancedDigitizingAllowed() const;
83+
%Docstring
84+
Returns whether functionality of advanced digitizing dock widget is currently allowed.
85+
86+
Tools may decide to switch this support on/off based on the current state of the map tool.
87+
For example, in node tool before user picks a vertex to move, advanced digitizing dock
88+
widget should be disabled and only enabled once a vertex is being moved. Other map tools
89+
may keep advanced digitizing allowed all the time.
90+
91+
If true is returned, that does not mean that advanced digitizing is actually active,
92+
because it is up to the user to enable/disable it when it is allowed.
93+
\sa setAdvancedDigitizingAllowed()
94+
.. versionadded:: 3.0
95+
:rtype: bool
96+
%End
97+
98+
bool isAutoSnapEnabled() const;
99+
%Docstring
100+
Returns whether mouse events (press/move/release) should automatically try to snap mouse position
101+
(according to the snapping configuration of map canvas) before passing the mouse coordinates
102+
to the tool. This may be desirable default behavior for some map tools, but not for other map tools.
103+
It is therefore possible to configure the behavior by the map tool.
104+
\sa isAutoSnapEnabled()
105+
.. versionadded:: 3.0
106+
:rtype: bool
107+
%End
90108

91109
protected:
92110

111+
void setAdvancedDigitizingAllowed( bool allowed );
112+
%Docstring
113+
Sets whether functionality of advanced digitizing dock widget is currently allowed.
114+
This method is protected because it should be a decision of the map tool and not from elsewhere.
115+
\sa isAdvancedDigitizingAllowed()
116+
.. versionadded:: 3.0
117+
%End
118+
119+
void setAutoSnapEnabled( bool enabled );
120+
%Docstring
121+
Sets whether mouse events (press/move/release) should automatically try to snap mouse position
122+
This method is protected because it should be a decision of the map tool and not from elsewhere.
123+
\sa isAutoSnapEnabled()
124+
.. versionadded:: 3.0
125+
%End
126+
93127
virtual void cadCanvasPressEvent( QgsMapMouseEvent *e );
94128
%Docstring
95129
Override this method when subclassing this class.

python/gui/qgsmaptoolcapture.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class QgsMapToolCapture : QgsMapToolAdvancedDigitizing
1818
#include "qgsmaptoolcapture.h"
1919
%End
2020
public:
21-
QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode = CaptureNone );
21+
QgsMapToolCapture( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget, CaptureMode mode );
2222
%Docstring
2323
constructor
2424
%End

src/app/nodetool/qgsnodetool.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ class MatchCollectingFilter : public QgsPointLocator::MatchFilter
200200
QgsNodeTool::QgsNodeTool( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDock )
201201
: QgsMapToolAdvancedDigitizing( canvas, cadDock )
202202
{
203+
setAdvancedDigitizingAllowed( false );
204+
203205
mSnapMarker = new QgsVertexMarker( canvas );
204206
mSnapMarker->setIconType( QgsVertexMarker::ICON_CROSS );
205207
mSnapMarker->setColor( Qt::magenta );
@@ -1029,7 +1031,7 @@ void QgsNodeTool::startDragging( QgsMapMouseEvent *e )
10291031
return;
10301032

10311033
// activate advanced digitizing dock
1032-
setMode( CaptureLine );
1034+
setAdvancedDigitizingAllowed( true );
10331035

10341036
// adding a new vertex instead of moving a vertex
10351037
if ( m.hasEdge() )
@@ -1260,7 +1262,7 @@ void QgsNodeTool::startDraggingAddVertex( const QgsPointLocator::Match &m )
12601262
Q_ASSERT( m.hasEdge() );
12611263

12621264
// activate advanced digitizing dock
1263-
setMode( CaptureLine );
1265+
setAdvancedDigitizingAllowed( true );
12641266

12651267
mDraggingVertex.reset( new Vertex( m.layer(), m.featureId(), m.vertexIndex() + 1 ) );
12661268
mDraggingVertexType = AddingVertex;
@@ -1290,7 +1292,7 @@ void QgsNodeTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint )
12901292
Q_ASSERT( mMouseAtEndpoint );
12911293

12921294
// activate advanced digitizing dock
1293-
setMode( CaptureLine );
1295+
setAdvancedDigitizingAllowed( true );
12941296

12951297
mDraggingVertex.reset( new Vertex( mMouseAtEndpoint->layer, mMouseAtEndpoint->fid, mMouseAtEndpoint->vertexId ) );
12961298
mDraggingVertexType = AddingEndpoint;
@@ -1315,7 +1317,7 @@ void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsP
13151317
Q_ASSERT( m.hasEdge() );
13161318

13171319
// activate advanced digitizing
1318-
setMode( CaptureLine );
1320+
setAdvancedDigitizingAllowed( true );
13191321

13201322
mDraggingEdge = true;
13211323
mDraggingExtraVertices.clear();
@@ -1354,7 +1356,7 @@ void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsP
13541356
void QgsNodeTool::stopDragging()
13551357
{
13561358
// deactivate advanced digitizing
1357-
setMode( CaptureNone );
1359+
setAdvancedDigitizingAllowed( false );
13581360

13591361
// stop adv digitizing
13601362
QMouseEvent mouseEvent( QEvent::MouseButtonRelease,
@@ -1399,7 +1401,7 @@ void QgsNodeTool::moveEdge( const QgsPointXY &mapPoint )
13991401
void QgsNodeTool::moveVertex( const QgsPointXY &mapPoint, const QgsPointLocator::Match *mapPointMatch )
14001402
{
14011403
// deactivate advanced digitizing
1402-
setMode( CaptureNone );
1404+
setAdvancedDigitizingAllowed( false );
14031405

14041406
QgsVectorLayer *dragLayer = mDraggingVertex->layer;
14051407
QgsFeatureId dragFid = mDraggingVertex->fid;

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3178,7 +3178,7 @@ void QgisApp::createCanvasTools()
31783178
mMapTools.mSvgAnnotation->setAction( mActionSvgAnnotation );
31793179
mMapTools.mAnnotation = new QgsMapToolAnnotation( mMapCanvas );
31803180
mMapTools.mAnnotation->setAction( mActionAnnotation );
3181-
mMapTools.mAddFeature = new QgsMapToolAddFeature( mMapCanvas );
3181+
mMapTools.mAddFeature = new QgsMapToolAddFeature( mMapCanvas, QgsMapToolCapture::CaptureNone );
31823182
mMapTools.mAddFeature->setAction( mActionAddFeature );
31833183
mMapTools.mCircularStringCurvePoint = new QgsMapToolCircularStringCurvePoint( dynamic_cast<QgsMapToolAddFeature *>( mMapTools.mAddFeature ), mMapCanvas );
31843184
mMapTools.mCircularStringCurvePoint->setAction( mActionCircularStringCurvePoint );

src/app/qgsmaptooladdcircularstring.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,6 @@ QgsMapToolAddCircularString::QgsMapToolAddCircularString( QgsMapToolCapture *par
4040
connect( QgisApp::instance(), &QgisApp::projectRead, this, &QgsMapToolAddCircularString::stopCapturing );
4141
}
4242

43-
QgsMapToolAddCircularString::QgsMapToolAddCircularString( QgsMapCanvas *canvas )
44-
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget() )
45-
, mParentTool( nullptr )
46-
, mRubberBand( nullptr )
47-
, mTempRubberBand( nullptr )
48-
, mShowCenterPointRubberBand( false )
49-
, mCenterPointRubberBand( nullptr )
50-
{
51-
if ( mCanvas )
52-
{
53-
connect( mCanvas, &QgsMapCanvas::mapToolSet, this, &QgsMapToolAddCircularString::setParentTool );
54-
}
55-
}
56-
5743
QgsMapToolAddCircularString::~QgsMapToolAddCircularString()
5844
{
5945
delete mRubberBand;

src/app/qgsmaptooladdcircularstring.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class QgsMapToolAddCircularString: public QgsMapToolCapture
3838
void setParentTool( QgsMapTool *newTool, QgsMapTool *oldTool );
3939

4040
protected:
41-
explicit QgsMapToolAddCircularString( QgsMapCanvas *canvas ); //forbidden
4241

4342
/** The parent map tool, e.g. the add feature tool.
4443
* Completed circular strings will be added to this tool by calling its addCurve() method.

src/app/qgsmaptooladdfeature.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class APP_EXPORT QgsMapToolAddFeature : public QgsMapToolCapture
2222
Q_OBJECT
2323
public:
2424
//! \since QGIS 2.12
25-
QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mode = CaptureNone );
25+
QgsMapToolAddFeature( QgsMapCanvas *canvas, CaptureMode mode );
2626
virtual ~QgsMapToolAddFeature();
2727
void cadCanvasReleaseEvent( QgsMapMouseEvent *e ) override;
2828

src/app/qgsmaptooladdpart.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include <QMouseEvent>
2929

3030
QgsMapToolAddPart::QgsMapToolAddPart( QgsMapCanvas *canvas )
31-
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget() )
31+
: QgsMapToolCapture( canvas, QgisApp::instance()->cadDockWidget(), CaptureNone )
3232
{
3333
mToolName = tr( "Add part" );
3434
connect( QgisApp::instance(), &QgisApp::newProject, this, &QgsMapToolAddPart::stopCapturing );

src/gui/qgsadvanceddigitizingdockwidget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,12 +872,12 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadCo
872872
return false;
873873
}
874874

875-
bool previousPointExist, penulPointExist, mSnappedSegmentExist;
875+
bool previousPointExist, penulPointExist, snappedSegmentExist;
876876
QgsPointXY previousPt = previousPoint( &previousPointExist );
877877
QgsPointXY penultimatePt = penultimatePoint( &penulPointExist );
878-
QList<QgsPointXY> mSnappedSegment = e->snapSegment( &mSnappedSegmentExist, true );
878+
mSnappedSegment = e->snapSegment( &snappedSegmentExist, true );
879879

880-
if ( !previousPointExist || !mSnappedSegmentExist )
880+
if ( !previousPointExist || !snappedSegmentExist )
881881
{
882882
return false;
883883
}

0 commit comments

Comments
 (0)