Skip to content
Permalink
Browse files

Fixes to the advanced digitizing

- make snapSegment() work if no segment was previously snapped
- fix highlight when a segment is snapped
- fix ghost marker at (0,0) when digitizing first point
  • Loading branch information
wonder-sk committed Feb 2, 2015
1 parent ca459ee commit d928caf68efe30a9d187d1d7e8be7d4b14a5db4c
@@ -48,7 +48,7 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter* painter )
const QgsPoint curPoint = mAdvancedDigitizingDockWidget->currentPoint( );
const QgsPoint prevPoint = mAdvancedDigitizingDockWidget->previousPoint( &previousPointExist );
const QgsPoint penulPoint = mAdvancedDigitizingDockWidget->penultimatePoint( &penulPointExist );
const bool pointSnapped = mAdvancedDigitizingDockWidget->pointSnapped();
const bool snappedToVertex = mAdvancedDigitizingDockWidget->snappedToVertex();
const QList<QgsPoint> snappedSegment = mAdvancedDigitizingDockWidget->snappedSegment();
const bool hasSnappedSegment = snappedSegment.count() == 2;

@@ -81,14 +81,14 @@ void QgsAdvancedDigitizingCanvasItem::paint( QPainter* painter )
painter->setRenderHints( QPainter::Antialiasing );

// Draw point snap
if ( curPointExist && pointSnapped )
if ( curPointExist && snappedToVertex )
{
painter->setPen( mSnapPen );
painter->drawEllipse( curPointPix, 10, 10 );
}

// Draw segment snap
if ( hasSnappedSegment && !pointSnapped )
if ( hasSnappedSegment && !snappedToVertex )
{
painter->setPen( mSnapPen );
painter->drawLine( snapSegmentPix1.x(),
@@ -90,7 +90,7 @@ QgsAdvancedDigitizingDockWidget::QgsAdvancedDigitizingDockWidget( QgsMapCanvas*
, mSnappingMode(( QgsMapMouseEvent::SnappingMode ) QSettings().value( "/Cad/SnappingMode", ( int )QgsMapMouseEvent::SnapProjectConfig ).toInt() )
, mCommonAngleConstraint( QSettings().value( "/Cad/CommonAngle", 90 ).toInt() )
, mCadPointList( QList<QgsPoint>() )
, mPointSnapped( false )
, mSnappedToVertex( false )
, mSnappedSegment( QList<QgsPoint>() )
{
setupUi( this );
@@ -520,7 +520,8 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent* e )
QgsDebugMsg( QString( "X: %1 %2 %3" ).arg( mXConstraint->isLocked() ).arg( mXConstraint->relative() ).arg( mXConstraint->value() ) );
QgsDebugMsg( QString( "Y: %1 %2 %3" ).arg( mYConstraint->isLocked() ).arg( mYConstraint->relative() ).arg( mYConstraint->value() ) );

QgsPoint point = e->mapPoint( &mPointSnapped );
QgsPoint point = e->mapPoint();
mSnappedToVertex = e->isSnappedToVertex();
mSnappedSegment = e->snapSegment();

bool previousPointExist, penulPointExist;
@@ -1136,7 +1137,7 @@ QgsPoint QgsAdvancedDigitizingDockWidget::currentPoint( bool* exist ) const
{
if ( exist )
*exist = pointsCount() > 0;
if ( pointsCount() > 1 )
if ( pointsCount() > 0 )
return mCadPointList.at( 0 );
else
return QgsPoint();
@@ -1190,7 +1191,7 @@ void QgsAdvancedDigitizingDockWidget::clearPoints()
{
mCadPointList.clear();
mSnappedSegment.clear();
mPointSnapped = false;
mSnappedToVertex = false;

updateCapacity();
}
@@ -155,7 +155,7 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U
QgsPoint previousPoint( bool *exist = 0 ) const;
QgsPoint penultimatePoint( bool *exist = 0 ) const;
int pointsCount() const {return mCadPointList.count();}
bool pointSnapped() const {return mPointSnapped;}
bool snappedToVertex() const {return mSnappedToVertex;}
const QList<QgsPoint>& snappedSegment() const {return mSnappedSegment;}

//! return the action used to enable/disable the tools
@@ -252,7 +252,7 @@ class APP_EXPORT QgsAdvancedDigitizingDockWidget : public QDockWidget, private U

// point list and current snap point / segment
QList<QgsPoint> mCadPointList;
bool mPointSnapped;
bool mSnappedToVertex;
QList<QgsPoint> mSnappedSegment;

// error message
@@ -72,7 +72,7 @@ void QgsMapMouseEvent::snapPoint()
QgsTolerance::UnitType unit;
snappingUtils->defaultSettings( type, tolerance, unit );
snappingUtils->setSnapToMapMode( QgsSnappingUtils::SnapAllLayers );
snappingUtils->setDefaultSettings( QgsPointLocator::Vertex, tolerance, unit );
snappingUtils->setDefaultSettings( QgsPointLocator::Vertex | QgsPointLocator::Edge, tolerance, unit );
mSnapMatch = snappingUtils->snapToMap( mMapPoint );
snappingUtils->setSnapToMapMode( canvasMode );
snappingUtils->setDefaultSettings( type, tolerance, unit );
@@ -94,15 +94,6 @@ QPoint QgsMapMouseEvent::mapToPixelCoordinates( QgsMapCanvas* canvas, const QgsP
return QPoint( qRound( x ), qRound( y ) );
}

QgsPoint QgsMapMouseEvent::mapPoint( bool* snappedPoint ) const
{
if ( snappedPoint )
{
*snappedPoint = mSnapMatch.isValid();
}
return mMapPoint;
}

QList<QgsPoint> QgsMapMouseEvent::snapSegment( bool* snapped, bool allLayers ) const
{
QList<QgsPoint> segment = QList<QgsPoint>();
@@ -117,12 +108,11 @@ QList<QgsPoint> QgsMapMouseEvent::snapSegment( bool* snapped, bool allLayers ) c
else if ( mSnappingMode != NoSnapping )
{
QgsPointLocator::Match match;
QgsPoint point;
if ( mSnappingMode == SnapProjectConfig && !allLayers )
{
// run snapToMap with only segments
EdgesOnlyFilter filter;
match = mMapTool->canvas()->snappingUtils()->snapToMap( point, &filter );
match = mMapTool->canvas()->snappingUtils()->snapToMap( mOriginalPoint, &filter );
}
else if ( mSnappingMode == SnapAllLayers || allLayers )
{
@@ -135,7 +125,7 @@ QList<QgsPoint> QgsMapMouseEvent::snapSegment( bool* snapped, bool allLayers ) c
snappingUtils->defaultSettings( type, tolerance, unit );
snappingUtils->setSnapToMapMode( QgsSnappingUtils::SnapAllLayers );
snappingUtils->setDefaultSettings( QgsPointLocator::Edge, tolerance, unit );
match = snappingUtils->snapToMap( point );
match = snappingUtils->snapToMap( mOriginalPoint );
snappingUtils->setSnapToMapMode( canvasMode );
snappingUtils->setDefaultSettings( type, tolerance, unit );
}
@@ -47,17 +47,23 @@ class APP_EXPORT QgsMapMouseEvent : public QMouseEvent
//! modify the point in map coordinates without changing values in pixel coordinates
void setPoint( const QgsPoint& point );

//! returns the first snapped segment
//! returns the first snapped segment. If the snapped match is a segment, it will simply return it.
//! Otherwise it will try to snap a segment according to the event's snapping mode
//! @param snapped if given, determines if a segment has been snapped
//! @param allLayers if true, override snapping mode
QList<QgsPoint> snapSegment( bool* snapped = 0, bool allLayers = false ) const;

/**
* @brief mapPoint returns the point in coordinates
* @param snappedPoint determines if the result is a snapped point or not. If snapped to a segment, will be set to false.
* @return the point in map coordinates, after snapping if requested in the event.
*/
QgsPoint mapPoint( bool* snappedPoint = 0 ) const;
QgsPoint mapPoint() const { return mMapPoint; }

//! determines if the returned mapPoint() is snapped (to a vertex or to a segment)
bool isSnapped() const { return mSnapMatch.isValid(); }

//! determines if the returned mapPoint() is snapped to a vertex. If snapped to a segment (or not snapped at all), will be set to false.
bool isSnappedToVertex() const { return mSnapMatch.hasVertex(); }

private:
/**
@@ -112,8 +112,8 @@ void QgsMapToolCapture::currentLayerChanged( QgsMapLayer *layer )

void QgsMapToolCapture::canvasMapMoveEvent( QgsMapMouseEvent * e )
{
bool snapped;
QgsPoint point = e->mapPoint( &snapped );
bool snapped = e->isSnapped();
QgsPoint point = e->mapPoint();

if ( !snapped )
{

0 comments on commit d928caf

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