Skip to content
Permalink
Browse files

fix snapping indicator when advance digitizing tools is enabled

  • Loading branch information
lbartoletti authored and 3nids committed Oct 24, 2018
1 parent 443afcd commit f002a9c43d3c8a999fbff995cc41fdc06dcb8d91
@@ -242,6 +242,10 @@ Constraint on the Y coordinate
bool commonAngleConstraint() const;
%Docstring
Constraint on a common angle
%End
QgsPointLocator::Match mapPointMatch() const;
%Docstring
SnapMatch for indicator
%End

void clearPoints();
@@ -28,6 +28,7 @@ QgsAdvancedDigitizingCanvasItem::QgsAdvancedDigitizingCanvasItem( QgsMapCanvas *
, mSnapPen( QPen( QColor( 127, 0, 0, 150 ), 1 ) )
, mSnapLinePen( QPen( QColor( 127, 0, 0, 150 ), 1, Qt::DashLine ) )
, mCursorPen( QPen( QColor( 127, 127, 127, 255 ), 1 ) )
, mSnapIndicator( qgis::make_unique< QgsSnapIndicator>( canvas ) )
, mAdvancedDigitizingDockWidget( cadDockWidget )
{
}
@@ -236,7 +237,16 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter *painter )
curPointPix + QPointF( +5, +5 ) );
painter->drawLine( curPointPix + QPointF( -5, +5 ),
curPointPix + QPointF( +5, -5 ) );
}


QgsPointLocator::Match match = mAdvancedDigitizingDockWidget->mapPointMatch();
if ( match.isValid() )
{
mSnapIndicator->setMatch( match );
mSnapIndicator->setVisible( true );
}
else
mSnapIndicator->setVisible( false );

}
@@ -20,6 +20,7 @@

#include "qgsmapcanvasitem.h"
#include "qgis_gui.h"
#include "qgssnapindicator.h"

class QgsAdvancedDigitizingDockWidget;

@@ -41,6 +42,8 @@ class GUI_EXPORT QgsAdvancedDigitizingCanvasItem : public QgsMapCanvasItem
QPen mSnapPen;
QPen mSnapLinePen;
QPen mCursorPen;
//! Snapping indicators
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;

private:
QgsAdvancedDigitizingDockWidget *mAdvancedDigitizingDockWidget = nullptr;
@@ -557,6 +557,8 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
// set the point coordinates in the map event
e->setMapPoint( point );

mSnapMatch = context.snappingUtils->snapToMap( point );

// update the point list
updateCurrentPoint( point );

@@ -26,6 +26,7 @@
#include "qgsdockwidget.h"
#include "qgsmessagebaritem.h"
#include "qgspointxy.h"
#include "qgspointlocator.h"


class QgsAdvancedDigitizingCanvasItem;
@@ -255,6 +256,8 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
const CadConstraint *constraintY() const { return mYConstraint.get(); }
//! Constraint on a common angle
bool commonAngleConstraint() const { return !qgsDoubleNear( mCommonAngleConstraint, 0.0 ); }
//! SnapMatch for indicator
QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }

/**
* Removes all points from the CAD point list
@@ -485,6 +488,9 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
QAction *mEnableAction = nullptr;
QMap< QAction *, double > mCommonAngleActions; // map the common angle actions with their angle values

// Snap indicator

QgsPointLocator::Match mSnapMatch;
private:
#ifdef SIP_RUN
//! event filter for line edits in the dock UI (angle/distance/x/y line edits)
@@ -30,7 +30,6 @@ QgsSnapIndicator::QgsSnapIndicator( QgsMapCanvas *canvas )

QgsSnapIndicator::~QgsSnapIndicator() = default;


void QgsSnapIndicator::setMatch( const QgsPointLocator::Match &match )
{
mMatch = match;
@@ -65,6 +64,7 @@ void QgsSnapIndicator::setMatch( const QgsPointLocator::Match &match )
{
iconType = QgsVertexMarker::ICON_DOUBLE_TRIANGLE;
}

mSnappingMarker->setIconType( iconType );

mSnappingMarker->setCenter( match.point() );
@@ -83,10 +83,14 @@ void QgsSnapIndicator::setMatch( const QgsPointLocator::Match &match )

void QgsSnapIndicator::setVisible( bool visible )
{
mSnappingMarker->setVisible( visible );
if ( mSnappingMarker )
mSnappingMarker->setVisible( visible );
}

bool QgsSnapIndicator::isVisible() const
{
return mSnappingMarker->isVisible();
if ( mSnappingMarker )
return mSnappingMarker->isVisible();

return false;
}

0 comments on commit f002a9c

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