Skip to content
Permalink
Browse files

Remove some workarounds for advanced digitizing from node tool

  • Loading branch information
wonder-sk committed Aug 29, 2017
1 parent a2b2567 commit 2f8afc02ab9e5f517c7355e336a7023d1a64233c
@@ -273,6 +273,15 @@ Constraint on a common angle
:rtype: bool
%End

void setPoints( const QList<QgsPointXY> &points );
%Docstring
Configures list of current CAD points

Some map tools may find it useful to override list of CAD points that is otherwise
automatically populated when user clicks with left mouse button on map canvas.
.. versionadded:: 3.0
%End

QgsPointXY currentPoint( bool *exists = 0 ) const;
%Docstring
The last point.
@@ -474,22 +474,6 @@ void QgsNodeTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}

mSelectionRectStartPos.reset();

// there may be a temporary list of points (up to two) that need to be injected
// into CAD dock widget in order to make it behave as we need
if ( !mOverrideCadPoints.isEmpty() )
{
for ( const QgsPointXY &pt : qgsAsConst( mOverrideCadPoints ) )
{
QMouseEvent mouseEvent( QEvent::MouseButtonRelease,
toCanvasCoordinates( pt ),
Qt::LeftButton, Qt::LeftButton, Qt::NoModifier );
QgsMapMouseEvent me( canvas(), &mouseEvent );
cadDockWidget()->canvasReleaseEvent( &me, QgsAdvancedDigitizingDockWidget::ManyPoints );
}

mOverrideCadPoints.clear();
}
}

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

mOverrideCadPoints.clear();
mOverrideCadPoints << m.point() << m.point();
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );

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

mOverrideCadPoints.clear();
mOverrideCadPoints << m.point() << m.point();
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );
}

void QgsNodeTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint )
@@ -1308,8 +1290,8 @@ void QgsNodeTool::startDraggingAddVertexAtEndpoint( const QgsPointXY &mapPoint )
// setup CAD dock previous points to endpoint and the previous point
QgsPointXY pt0 = geom.vertexAt( adjacentVertexIndexToEndpoint( geom, mMouseAtEndpoint->vertexId ) );
QgsPointXY pt1 = geom.vertexAt( mMouseAtEndpoint->vertexId );
mOverrideCadPoints.clear();
mOverrideCadPoints << pt0 << pt1;

cadDockWidget()->setPoints( QList<QgsPointXY>() << pt0 << pt1 );
}

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

mOverrideCadPoints.clear();
mOverrideCadPoints << m.point() << m.point();
cadDockWidget()->setPoints( QList<QgsPointXY>() << m.point() << m.point() );
}

void QgsNodeTool::stopDragging()
{
// deactivate advanced digitizing
setAdvancedDigitizingAllowed( false );

// stop adv digitizing
QMouseEvent mouseEvent( QEvent::MouseButtonRelease,
QPoint(),
Qt::RightButton, Qt::RightButton, Qt::NoModifier );
QgsMapMouseEvent me( canvas(), &mouseEvent );
cadDockWidget()->canvasReleaseEvent( &me, QgsAdvancedDigitizingDockWidget::SinglePoint );
cadDockWidget()->clear(); // clear cad points and release locks

mDraggingVertex.reset();
mDraggingVertexType = NotDragging;
@@ -299,11 +299,6 @@ class APP_EXPORT QgsNodeTool : public QgsMapToolAdvancedDigitizing
//! to stick with the same highlighted feature next time if there are more options
std::unique_ptr<QgsPointLocator::Match> mLastSnap;

//! List of two points that will be forced into CAD dock with fake mouse events
//! to allow correct functioning of node tool with CAD dock.
//! (CAD dock does various assumptions that work with simple capture tools, but not with node tool)
QList<QgsPointXY> mOverrideCadPoints;

//! When double-clicking to add a new vertex, this member keeps the snap
//! match from "press" event used to be used in following "release" event
std::unique_ptr<QgsPointLocator::Match> mNewVertexFromDoubleClick;
@@ -222,8 +222,7 @@ void QgsAdvancedDigitizingDockWidget::setCadEnabled( bool enabled )
mCadButtons->setEnabled( enabled );
mInputWidgets->setEnabled( enabled );

clearPoints();
releaseLocks();
clear();
setConstructionMode( false );
}

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

if ( e->button() == Qt::RightButton )
{
clearPoints();
releaseLocks();
clear();
return false;
}

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

void QgsAdvancedDigitizingDockWidget::setPoints( const QList<QgsPointXY> &points )
{
clearPoints();
Q_FOREACH ( const QgsPointXY &pt, points )
{
addPoint( pt );
}
}

bool QgsAdvancedDigitizingDockWidget::eventFilter( QObject *obj, QEvent *event )
{
// event for line edits
@@ -277,6 +277,15 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! Constraint on a common angle
bool commonAngleConstraint() const { return mCommonAngleConstraint; }

/**
* Configures list of current CAD points
*
* Some map tools may find it useful to override list of CAD points that is otherwise
* automatically populated when user clicks with left mouse button on map canvas.
* \since QGIS 3.0
*/
void setPoints( const QList<QgsPointXY> &points );

/**
* The last point.
* Helper for the CAD point list. The CAD point list is the list of points

0 comments on commit 2f8afc0

Please sign in to comment.
You can’t perform that action at this time.