Skip to content
Permalink
Browse files

Move snapSegment() from map mouse event to private area of CAD dock

  • Loading branch information
wonder-sk committed Sep 6, 2017
1 parent 22ad672 commit ae713b4c810163f591c3dcf80df1b5afa36bd408
@@ -1577,7 +1577,8 @@ QgsMapMouseEvent {#qgis_api_break_3_0_QgsMapMouseEvent}
----------------

- SnappingMode enum was removed.
- snapPoint() and snapSegment() do not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
- snapPoint() does not take SnappingMode argument anymore. Snapping is done according to project's snapping configuration.
- snapSegment() was removed.


QgsMapOverviewCanvas {#qgis_api_break_3_0_QgsMapOverviewCanvas}
@@ -61,16 +61,6 @@ class QgsMapMouseEvent : QMouseEvent
:rtype: QgsPointXY
%End

QList<QgsPointXY> snapSegment( bool *snapped = 0, bool allLayers = false ) const;
%Docstring
Returns the first snapped segment. If the cached 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. In this case the cache
will not be overwritten.
\param snapped if given, determines if a segment has been snapped
\param allLayers if true, override snapping mode
:rtype: list of QgsPointXY
%End

bool isSnapped() const;
%Docstring
Returns true if there is a snapped point cached.
@@ -30,12 +30,16 @@
#include "qgslinestring.h"
#include "qgsfocuswatcher.h"
#include "qgssettings.h"
#include "qgssnappingutils.h"
#include "qgsproject.h"

/// @cond PRIVATE
struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
{
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
};
/// @endcond


bool QgsAdvancedDigitizingDockWidget::lineCircleIntersection( const QgsPointXY &center, const double radius, const QList<QgsPointXY> &segment, QgsPointXY &intersection )
{
@@ -571,7 +575,7 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )

QgsPointXY point = e->snapPoint();

mSnappedSegment = e->snapSegment();
mSnappedSegment = snapSegment( e->originalMapPoint() );

bool previousPointExist, penulPointExist;
QgsPointXY previousPt = previousPoint( &previousPointExist );
@@ -864,6 +868,49 @@ bool QgsAdvancedDigitizingDockWidget::applyConstraints( QgsMapMouseEvent *e )
}



QList<QgsPointXY> QgsAdvancedDigitizingDockWidget::snapSegment( const QgsPointXY &originalMapPoint, bool *snapped, bool allLayers ) const
{
QList<QgsPointXY> segment;
QgsPointXY pt1, pt2;
QgsPointLocator::Match match;

if ( !allLayers )
{
// run snapToMap with only segments
EdgesOnlyFilter filter;
match = mMapCanvas->snappingUtils()->snapToMap( originalMapPoint, &filter );
}
else
{
// run snapToMap with only edges on all layers
QgsSnappingUtils *snappingUtils = mMapCanvas->snappingUtils();

QgsSnappingConfig canvasConfig = snappingUtils->config();
QgsSnappingConfig localConfig = snappingUtils->config();

localConfig.setMode( QgsSnappingConfig::AllLayers );
localConfig.setType( QgsSnappingConfig::Segment );
snappingUtils->setConfig( localConfig );

match = snappingUtils->snapToMap( originalMapPoint );

snappingUtils->setConfig( canvasConfig );
}
if ( match.isValid() && match.hasEdge() )
{
match.edgePoints( pt1, pt2 );
segment << pt1 << pt2;
}

if ( snapped )
{
*snapped = segment.count() == 2;
}

return segment;
}

bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode )
{
if ( mAdditionalConstraint == NoConstraint )
@@ -874,7 +921,7 @@ bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadCo
bool previousPointExist, penulPointExist, snappedSegmentExist;
QgsPointXY previousPt = previousPoint( &previousPointExist );
QgsPointXY penultimatePt = penultimatePoint( &penulPointExist );
mSnappedSegment = e->snapSegment( &snappedSegmentExist, true );
mSnappedSegment = snapSegment( e->originalMapPoint(), &snappedSegmentExist, true );

if ( !previousPointExist || !snappedSegmentExist )
{
@@ -408,6 +408,14 @@ class GUI_EXPORT QgsAdvancedDigitizingDockWidget : public QgsDockWidget, private
//! If additional constraints are used, this will determine the angle to be locked depending on the snapped segment.
bool alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode = CadConstraint::HardLock );

/**
* Returns the first snapped segment. Will try to snap a segment according to the event's snapping mode.
* \param originalMapPoint point to be snapped (in map coordinates)
* \param snapped if given, determines if a segment has been snapped
* \param allLayers if true, override snapping mode
*/
QList<QgsPointXY> snapSegment( const QgsPointXY &originalMapPoint, bool *snapped = nullptr, bool allLayers = false ) const;

//! add point to the CAD point list
void addPoint( const QgsPointXY &point );
//! update the current point in the CAD point list
@@ -20,13 +20,6 @@
#include "qgssnappingutils.h"
#include "qgssnappingconfig.h"

/// @cond PRIVATE
struct EdgesOnlyFilter : public QgsPointLocator::MatchFilter
{
bool acceptMatch( const QgsPointLocator::Match &m ) override { return m.hasEdge(); }
};
/// @endcond

QgsMapMouseEvent::QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QMouseEvent *event )
: QMouseEvent( event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
, mHasCachedSnapResult( false )
@@ -72,57 +65,6 @@ QgsPointXY QgsMapMouseEvent::snapPoint()
return mMapPoint;
}

QList<QgsPointXY> QgsMapMouseEvent::snapSegment( bool *snapped, bool allLayers ) const
{
QList<QgsPointXY> segment;
QgsPointXY pt1, pt2;

// If there's a cached snapping result we use it
if ( mHasCachedSnapResult && mSnapMatch.hasEdge() )
{
mSnapMatch.edgePoints( pt1, pt2 );
segment << pt1 << pt2;
}
else
{
QgsPointLocator::Match match;
if ( !allLayers )
{
// run snapToMap with only segments
EdgesOnlyFilter filter;
match = mMapCanvas->snappingUtils()->snapToMap( mOriginalMapPoint, &filter );
}
else
{
// run snapToMap with only edges on all layers
QgsSnappingUtils *snappingUtils = mMapCanvas->snappingUtils();

QgsSnappingConfig canvasConfig = snappingUtils->config();
QgsSnappingConfig localConfig = snappingUtils->config();

localConfig.setMode( QgsSnappingConfig::AllLayers );
localConfig.setType( QgsSnappingConfig::Segment );
snappingUtils->setConfig( localConfig );

match = snappingUtils->snapToMap( mOriginalMapPoint );

snappingUtils->setConfig( canvasConfig );
}
if ( match.isValid() && match.hasEdge() )
{
match.edgePoints( pt1, pt2 );
segment << pt1 << pt2;
}
}

if ( snapped )
{
*snapped = segment.count() == 2;
}

return segment;
}

void QgsMapMouseEvent::setMapPoint( const QgsPointXY &point )
{
mMapPoint = point;
@@ -72,15 +72,6 @@ class GUI_EXPORT QgsMapMouseEvent : public QMouseEvent
*/
QgsPointXY snapPoint();

/**
* Returns the first snapped segment. If the cached 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. In this case the cache
* will not be overwritten.
* \param snapped if given, determines if a segment has been snapped
* \param allLayers if true, override snapping mode
*/
QList<QgsPointXY> snapSegment( bool *snapped = nullptr, bool allLayers = false ) const;

/**
* Returns true if there is a snapped point cached.
* Will only be useful after snapPoint has previously been called.

0 comments on commit ae713b4

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