Skip to content

Commit 2f8afc0

Browse files
committed
Remove some workarounds for advanced digitizing from node tool
1 parent a2b2567 commit 2f8afc0

5 files changed

+35
-40
lines changed

python/gui/qgsadvanceddigitizingdockwidget.sip

+9
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ Constraint on a common angle
273273
:rtype: bool
274274
%End
275275

276+
void setPoints( const QList<QgsPointXY> &points );
277+
%Docstring
278+
Configures list of current CAD points
279+
280+
Some map tools may find it useful to override list of CAD points that is otherwise
281+
automatically populated when user clicks with left mouse button on map canvas.
282+
.. versionadded:: 3.0
283+
%End
284+
276285
QgsPointXY currentPoint( bool *exists = 0 ) const;
277286
%Docstring
278287
The last point.

src/app/nodetool/qgsnodetool.cpp

+6-31
Original file line numberDiff line numberDiff line change
@@ -474,22 +474,6 @@ void QgsNodeTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
474474
}
475475

476476
mSelectionRectStartPos.reset();
477-
478-
// there may be a temporary list of points (up to two) that need to be injected
479-
// into CAD dock widget in order to make it behave as we need
480-
if ( !mOverrideCadPoints.isEmpty() )
481-
{
482-
for ( const QgsPointXY &pt : qgsAsConst( mOverrideCadPoints ) )
483-
{
484-
QMouseEvent mouseEvent( QEvent::MouseButtonRelease,
485-
toCanvasCoordinates( pt ),
486-
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
487-
QgsMapMouseEvent me( canvas(), &mouseEvent );
488-
cadDockWidget()->canvasReleaseEvent( &me, QgsAdvancedDigitizingDockWidget::ManyPoints );
489-
}
490-
491-
mOverrideCadPoints.clear();
492-
}
493477
}
494478

495479
void QgsNodeTool::cadCanvasMoveEvent( QgsMapMouseEvent *e )
@@ -1082,8 +1066,7 @@ void QgsNodeTool::startDraggingMoveVertex( const QgsPointXY &mapPoint, const Qgs
10821066
}
10831067
}
10841068

1085-
mOverrideCadPoints.clear();
1086-
mOverrideCadPoints << m.point() << m.point();
1069+
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );
10871070

10881071
if ( QgsProject::instance()->topologicalEditing() )
10891072
{
@@ -1283,8 +1266,7 @@ void QgsNodeTool::startDraggingAddVertex( const QgsPointLocator::Match &m )
12831266
if ( v1.x() != 0 || v1.y() != 0 )
12841267
addDragBand( map_v1, m.point() );
12851268

1286-
mOverrideCadPoints.clear();
1287-
mOverrideCadPoints << m.point() << m.point();
1269+
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );
12881270
}
12891271

12901272
void QgsNodeTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint )
@@ -1308,8 +1290,8 @@ void QgsNodeTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint )
13081290
// setup CAD dock previous points to endpoint and the previous point
13091291
QgsPointXY pt0 = geom.vertexAt( adjacentVertexIndexToEndpoint( geom, mMouseAtEndpoint->vertexId ) );
13101292
QgsPointXY pt1 = geom.vertexAt( mMouseAtEndpoint->vertexId );
1311-
mOverrideCadPoints.clear();
1312-
mOverrideCadPoints << pt0 << pt1;
1293+
1294+
cadDockWidget()->setPoints( QList<QgsPointXY>() << pt0 << pt1 );
13131295
}
13141296

13151297
void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsPointXY &mapPoint )
@@ -1349,21 +1331,14 @@ void QgsNodeTool::startDraggingEdge( const QgsPointLocator::Match &m, const QgsP
13491331
mDraggingExtraVerticesOffset << ( geom.vertexAt( v.vertexId ) - QgsPoint( layerPoint ) );
13501332
}
13511333

1352-
mOverrideCadPoints.clear();
1353-
mOverrideCadPoints << m.point() << m.point();
1334+
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );
13541335
}
13551336

13561337
void QgsNodeTool::stopDragging()
13571338
{
13581339
// deactivate advanced digitizing
13591340
setAdvancedDigitizingAllowed( false );
1360-
1361-
// stop adv digitizing
1362-
QMouseEvent mouseEvent( QEvent::MouseButtonRelease,
1363-
QPoint(),
1364-
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
1365-
QgsMapMouseEvent me( canvas(), &mouseEvent );
1366-
cadDockWidget()->canvasReleaseEvent( &me, QgsAdvancedDigitizingDockWidget::SinglePoint );
1341+
cadDockWidget()->clear(); // clear cad points and release locks
13671342

13681343
mDraggingVertex.reset();
13691344
mDraggingVertexType = NotDragging;

src/app/nodetool/qgsnodetool.h

-5
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,6 @@ class APP_EXPORT QgsNodeTool : public QgsMapToolAdvancedDigitizing
299299
//! to stick with the same highlighted feature next time if there are more options
300300
std::unique_ptr<QgsPointLocator::Match> mLastSnap;
301301

302-
//! List of two points that will be forced into CAD dock with fake mouse events
303-
//! to allow correct functioning of node tool with CAD dock.
304-
//! (CAD dock does various assumptions that work with simple capture tools, but not with node tool)
305-
QList<QgsPointXY> mOverrideCadPoints;
306-
307302
//! When double-clicking to add a new vertex, this member keeps the snap
308303
//! match from "press" event used to be used in following "release" event
309304
std::unique_ptr<QgsPointLocator::Match> mNewVertexFromDoubleClick;

src/gui/qgsadvanceddigitizingdockwidget.cpp

+11-4
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
222222
mCadButtons->setEnabled( enabled );
223223
mInputWidgets->setEnabled( enabled );
224224

225-
clearPoints();
226-
releaseLocks();
225+
clear();
227226
setConstructionMode( false );
228227
}
229228

@@ -921,8 +920,7 @@ bool QgsAdvancedDigitizingDockWidget::canvasReleaseEvent( QgsMapMouseEvent *e, A
921920

922921
if ( e->button() == Qt::RightButton )
923922
{
924-
clearPoints();
925-
releaseLocks();
923+
clear();
926924
return false;
927925
}
928926

@@ -1041,6 +1039,15 @@ void QgsAdvancedDigitizingDockWidget::keyPressEvent( QKeyEvent *e )
10411039
}
10421040
}
10431041

1042+
void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points )
1043+
{
1044+
clearPoints();
1045+
Q_FOREACH ( const QgsPointXY &pt, points )
1046+
{
1047+
addPoint( pt );
1048+
}
1049+
}
1050+
10441051
bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
10451052
{
10461053
// event for line edits

src/gui/qgsadvanceddigitizingdockwidget.h

+9
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
277277
//! Constraint on a common angle
278278
bool commonAngleConstraint() const { return mCommonAngleConstraint; }
279279

280+
/**
281+
* Configures list of current CAD points
282+
*
283+
* Some map tools may find it useful to override list of CAD points that is otherwise
284+
* automatically populated when user clicks with left mouse button on map canvas.
285+
* \since QGIS 3.0
286+
*/
287+
void setPoints( const QList<QgsPointXY> &points );
288+
280289
/**
281290
* The last point.
282291
* Helper for the CAD point list. The CAD point list is the list of points

0 commit comments

Comments
 (0)